-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux…
…/kernel/git/jolsa/perf into perf/core Pull perf/core improvements and fixes from Jiri Olsa: . Update attr test with PERF_FLAG_FD_CLOEXEC flag (Jiri Olsa) . Enable close-on-exec flag on perf file descriptor (Yann Droneaud) Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org>
- Loading branch information
Showing
13 changed files
with
101 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
[event] | ||
fd=1 | ||
group_fd=-1 | ||
flags=0 | ||
# 0 or PERF_FLAG_FD_CLOEXEC flag | ||
flags=0|8 | ||
cpu=* | ||
type=0|1 | ||
size=96 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
[event] | ||
fd=1 | ||
group_fd=-1 | ||
flags=0 | ||
# 0 or PERF_FLAG_FD_CLOEXEC flag | ||
flags=0|8 | ||
cpu=* | ||
type=0 | ||
size=96 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "util.h" | ||
#include "../perf.h" | ||
#include "cloexec.h" | ||
#include "asm/bug.h" | ||
|
||
static unsigned long flag = PERF_FLAG_FD_CLOEXEC; | ||
|
||
static int perf_flag_probe(void) | ||
{ | ||
/* use 'safest' configuration as used in perf_evsel__fallback() */ | ||
struct perf_event_attr attr = { | ||
.type = PERF_COUNT_SW_CPU_CLOCK, | ||
.config = PERF_COUNT_SW_CPU_CLOCK, | ||
}; | ||
int fd; | ||
int err; | ||
|
||
/* check cloexec flag */ | ||
fd = sys_perf_event_open(&attr, 0, -1, -1, | ||
PERF_FLAG_FD_CLOEXEC); | ||
err = errno; | ||
|
||
if (fd >= 0) { | ||
close(fd); | ||
return 1; | ||
} | ||
|
||
WARN_ONCE(err != EINVAL, | ||
"perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n", | ||
err, strerror(err)); | ||
|
||
/* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */ | ||
fd = sys_perf_event_open(&attr, 0, -1, -1, 0); | ||
err = errno; | ||
|
||
if (WARN_ONCE(fd < 0, | ||
"perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n", | ||
err, strerror(err))) | ||
return -1; | ||
|
||
close(fd); | ||
|
||
return 0; | ||
} | ||
|
||
unsigned long perf_event_open_cloexec_flag(void) | ||
{ | ||
static bool probed; | ||
|
||
if (!probed) { | ||
if (perf_flag_probe() <= 0) | ||
flag = 0; | ||
probed = true; | ||
} | ||
|
||
return flag; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef __PERF_CLOEXEC_H | ||
#define __PERF_CLOEXEC_H | ||
|
||
unsigned long perf_event_open_cloexec_flag(void); | ||
|
||
#endif /* __PERF_CLOEXEC_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters