mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-22 12:14:01 +08:00
perf/urgent fixes:
User visible: - Fallback to usermode only counters when perf_event_paranoid > 1, which is the case now (Arnaldo Carvalho de Melo) - Do not reassign parg after collapse_tree() in libtraceevent, which may cause tool crashes (Steven Rostedt) Build fixes: - Fix the build on Fedora Rawhide, where readdir_r() is deprecated and also wrt -Werror=unused-const-variable= + x86_32_regoffset_table on !x86_64 (Arnaldo Carvalho de Melo) - Fix the build on Ubuntu 12.04.5, where dwarf_getlocations() isn't available, i.e. libdw-dev < 0.157 (Arnaldo Carvalho de Melo) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAABCAAGBQJXNOELAAoJENZQFvNTUqpAEmcQAJIZePquYNAsnTcRAPcgXjSG wdxMK1xlHW8WgPi7OoU6a2Hx04xRtEc8CUsb4mTUa1umAMe7Fp9BCuWZrX2tNAxJ y6tn95RkMSxZSbPp9SvSJDLAi7NrOafoblPnsjLw3bpdMTY+ngxhMq2Aftjpz5ai Ok3sC3deCYoibSzpxLNkoBPPR7eOhK8wzcVNAvu5mPY0EF9VPpNF+yPs6mW38wBs TQtji1X7049bAjxMLeeXcR4Z6x5hhVM6i3U1lB5XSMoqkcQMLFHJze7Fe5VLMc/3 jtZFZvV79PlAhJtYxlLeuuSjjuaZ6dCSE+87YYAmukup3SMp3sCTvba+7YhWEgEE hZEAaHe8eJbSQndhYpY82mV+AQe4dINTgdLBoV1uQ5EUh/KlOaph3MuCb2jMXtVb JLROl6wktgFJ75NzkHvix798DtOVyLqa5z0H2h27Jqm2LqrotIn+trXuz6a+0nxP aoHsKPyZYytPvZoWHjesIn86iOSCrLN8UGhaQPTIunfO0evlSvEkWtAqU1u4mX+P CqDFI4/2dZXnAVBZvk47xsrcxhkvEO63SDv3AIdXvsihYBGJLtaVKT9qfsxyxyqN fAy9MghKrPXTRRJP9Z/Fzbycbv/ioiRdnNmj+cgWkPkjqt+lr5Q1V+B9BZhqsWHF Fl0GoIr//HFjSk7gSFaN =qn4a -----END PGP SIGNATURE----- Merge tag 'perf-urgent-for-mingo-20160512' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent Pull perf/urgent fixes from Arnaldo Carvalho de Melo: - Fallback to usermode-only counters when perf_event_paranoid > 1, which is the case now (Arnaldo Carvalho de Melo) - Do not reassign parg after collapse_tree() in libtraceevent, which may cause tool crashes (Steven Rostedt) - Fix the build on Fedora Rawhide, where readdir_r() is deprecated and also wrt -Werror=unused-const-variable= + x86_32_regoffset_table on !x86_64 (Arnaldo Carvalho de Melo) - Fix the build on Ubuntu 12.04.5, where dwarf_getlocations() isn't available, i.e. libdw-dev < 0.157 (Arnaldo Carvalho de Melo) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
commit
636fa4a7b0
@ -30,6 +30,7 @@ endef
|
||||
FEATURE_TESTS_BASIC := \
|
||||
backtrace \
|
||||
dwarf \
|
||||
dwarf_getlocations \
|
||||
fortify-source \
|
||||
sync-compare-and-swap \
|
||||
glibc \
|
||||
@ -78,6 +79,7 @@ endif
|
||||
|
||||
FEATURE_DISPLAY ?= \
|
||||
dwarf \
|
||||
dwarf_getlocations \
|
||||
glibc \
|
||||
gtk2 \
|
||||
libaudit \
|
||||
|
@ -3,6 +3,7 @@ FILES= \
|
||||
test-backtrace.bin \
|
||||
test-bionic.bin \
|
||||
test-dwarf.bin \
|
||||
test-dwarf_getlocations.bin \
|
||||
test-fortify-source.bin \
|
||||
test-sync-compare-and-swap.bin \
|
||||
test-glibc.bin \
|
||||
@ -82,6 +83,9 @@ endif
|
||||
$(OUTPUT)test-dwarf.bin:
|
||||
$(BUILD) $(DWARFLIBS)
|
||||
|
||||
$(OUTPUT)test-dwarf_getlocations.bin:
|
||||
$(BUILD) $(DWARFLIBS)
|
||||
|
||||
$(OUTPUT)test-libelf-mmap.bin:
|
||||
$(BUILD) -lelf
|
||||
|
||||
|
@ -41,6 +41,10 @@
|
||||
# include "test-dwarf.c"
|
||||
#undef main
|
||||
|
||||
#define main main_test_dwarf_getlocations
|
||||
# include "test-dwarf_getlocations.c"
|
||||
#undef main
|
||||
|
||||
#define main main_test_libelf_getphdrnum
|
||||
# include "test-libelf-getphdrnum.c"
|
||||
#undef main
|
||||
@ -143,6 +147,7 @@ int main(int argc, char *argv[])
|
||||
main_test_libelf_mmap();
|
||||
main_test_glibc();
|
||||
main_test_dwarf();
|
||||
main_test_dwarf_getlocations();
|
||||
main_test_libelf_getphdrnum();
|
||||
main_test_libunwind();
|
||||
main_test_libaudit();
|
||||
|
12
tools/build/feature/test-dwarf_getlocations.c
Normal file
12
tools/build/feature/test-dwarf_getlocations.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <elfutils/libdw.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Dwarf_Addr base, start, end;
|
||||
Dwarf_Attribute attr;
|
||||
Dwarf_Op *op;
|
||||
size_t nops;
|
||||
ptrdiff_t offset = 0;
|
||||
return (int)dwarf_getlocations(&attr, offset, &base, &start, &end, &op, &nops);
|
||||
}
|
@ -1164,11 +1164,11 @@ process_filter(struct event_format *event, struct filter_arg **parg,
|
||||
current_op = current_exp;
|
||||
|
||||
ret = collapse_tree(current_op, parg, error_str);
|
||||
/* collapse_tree() may free current_op, and updates parg accordingly */
|
||||
current_op = NULL;
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
|
||||
*parg = current_op;
|
||||
|
||||
free(token);
|
||||
return 0;
|
||||
|
||||
|
@ -63,6 +63,8 @@ struct pt_regs_offset {
|
||||
# define REG_OFFSET_NAME_32(n, r) {.name = n, .offset = offsetof(struct pt_regs, r)}
|
||||
#endif
|
||||
|
||||
/* TODO: switching by dwarf address size */
|
||||
#ifndef __x86_64__
|
||||
static const struct pt_regs_offset x86_32_regoffset_table[] = {
|
||||
REG_OFFSET_NAME_32("%ax", eax),
|
||||
REG_OFFSET_NAME_32("%cx", ecx),
|
||||
@ -75,6 +77,8 @@ static const struct pt_regs_offset x86_32_regoffset_table[] = {
|
||||
REG_OFFSET_END,
|
||||
};
|
||||
|
||||
#define regoffset_table x86_32_regoffset_table
|
||||
#else
|
||||
static const struct pt_regs_offset x86_64_regoffset_table[] = {
|
||||
REG_OFFSET_NAME_64("%ax", rax),
|
||||
REG_OFFSET_NAME_64("%dx", rdx),
|
||||
@ -95,11 +99,7 @@ static const struct pt_regs_offset x86_64_regoffset_table[] = {
|
||||
REG_OFFSET_END,
|
||||
};
|
||||
|
||||
/* TODO: switching by dwarf address size */
|
||||
#ifdef __x86_64__
|
||||
#define regoffset_table x86_64_regoffset_table
|
||||
#else
|
||||
#define regoffset_table x86_32_regoffset_table
|
||||
#endif
|
||||
|
||||
/* Minus 1 for the ending REG_OFFSET_END */
|
||||
|
@ -1415,21 +1415,19 @@ static int is_directory(const char *base_path, const struct dirent *dent)
|
||||
return S_ISDIR(st.st_mode);
|
||||
}
|
||||
|
||||
#define for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next)\
|
||||
while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \
|
||||
lang_next) \
|
||||
if ((lang_dirent.d_type == DT_DIR || \
|
||||
(lang_dirent.d_type == DT_UNKNOWN && \
|
||||
is_directory(scripts_path, &lang_dirent))) && \
|
||||
(strcmp(lang_dirent.d_name, ".")) && \
|
||||
(strcmp(lang_dirent.d_name, "..")))
|
||||
#define for_each_lang(scripts_path, scripts_dir, lang_dirent) \
|
||||
while ((lang_dirent = readdir(scripts_dir)) != NULL) \
|
||||
if ((lang_dirent->d_type == DT_DIR || \
|
||||
(lang_dirent->d_type == DT_UNKNOWN && \
|
||||
is_directory(scripts_path, lang_dirent))) && \
|
||||
(strcmp(lang_dirent->d_name, ".")) && \
|
||||
(strcmp(lang_dirent->d_name, "..")))
|
||||
|
||||
#define for_each_script(lang_path, lang_dir, script_dirent, script_next)\
|
||||
while (!readdir_r(lang_dir, &script_dirent, &script_next) && \
|
||||
script_next) \
|
||||
if (script_dirent.d_type != DT_DIR && \
|
||||
(script_dirent.d_type != DT_UNKNOWN || \
|
||||
!is_directory(lang_path, &script_dirent)))
|
||||
#define for_each_script(lang_path, lang_dir, script_dirent) \
|
||||
while ((script_dirent = readdir(lang_dir)) != NULL) \
|
||||
if (script_dirent->d_type != DT_DIR && \
|
||||
(script_dirent->d_type != DT_UNKNOWN || \
|
||||
!is_directory(lang_path, script_dirent)))
|
||||
|
||||
|
||||
#define RECORD_SUFFIX "-record"
|
||||
@ -1575,7 +1573,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
|
||||
const char *s __maybe_unused,
|
||||
int unset __maybe_unused)
|
||||
{
|
||||
struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
|
||||
struct dirent *script_dirent, *lang_dirent;
|
||||
char scripts_path[MAXPATHLEN];
|
||||
DIR *scripts_dir, *lang_dir;
|
||||
char script_path[MAXPATHLEN];
|
||||
@ -1590,19 +1588,19 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
|
||||
if (!scripts_dir)
|
||||
return -1;
|
||||
|
||||
for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
|
||||
for_each_lang(scripts_path, scripts_dir, lang_dirent) {
|
||||
snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
|
||||
lang_dirent.d_name);
|
||||
lang_dirent->d_name);
|
||||
lang_dir = opendir(lang_path);
|
||||
if (!lang_dir)
|
||||
continue;
|
||||
|
||||
for_each_script(lang_path, lang_dir, script_dirent, script_next) {
|
||||
script_root = get_script_root(&script_dirent, REPORT_SUFFIX);
|
||||
for_each_script(lang_path, lang_dir, script_dirent) {
|
||||
script_root = get_script_root(script_dirent, REPORT_SUFFIX);
|
||||
if (script_root) {
|
||||
desc = script_desc__findnew(script_root);
|
||||
snprintf(script_path, MAXPATHLEN, "%s/%s",
|
||||
lang_path, script_dirent.d_name);
|
||||
lang_path, script_dirent->d_name);
|
||||
read_script_info(desc, script_path);
|
||||
free(script_root);
|
||||
}
|
||||
@ -1690,7 +1688,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
|
||||
*/
|
||||
int find_scripts(char **scripts_array, char **scripts_path_array)
|
||||
{
|
||||
struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
|
||||
struct dirent *script_dirent, *lang_dirent;
|
||||
char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
|
||||
DIR *scripts_dir, *lang_dir;
|
||||
struct perf_session *session;
|
||||
@ -1713,9 +1711,9 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
|
||||
return -1;
|
||||
}
|
||||
|
||||
for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
|
||||
for_each_lang(scripts_path, scripts_dir, lang_dirent) {
|
||||
snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
|
||||
lang_dirent.d_name);
|
||||
lang_dirent->d_name);
|
||||
#ifdef NO_LIBPERL
|
||||
if (strstr(lang_path, "perl"))
|
||||
continue;
|
||||
@ -1729,16 +1727,16 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
|
||||
if (!lang_dir)
|
||||
continue;
|
||||
|
||||
for_each_script(lang_path, lang_dir, script_dirent, script_next) {
|
||||
for_each_script(lang_path, lang_dir, script_dirent) {
|
||||
/* Skip those real time scripts: xxxtop.p[yl] */
|
||||
if (strstr(script_dirent.d_name, "top."))
|
||||
if (strstr(script_dirent->d_name, "top."))
|
||||
continue;
|
||||
sprintf(scripts_path_array[i], "%s/%s", lang_path,
|
||||
script_dirent.d_name);
|
||||
temp = strchr(script_dirent.d_name, '.');
|
||||
script_dirent->d_name);
|
||||
temp = strchr(script_dirent->d_name, '.');
|
||||
snprintf(scripts_array[i],
|
||||
(temp - script_dirent.d_name) + 1,
|
||||
"%s", script_dirent.d_name);
|
||||
(temp - script_dirent->d_name) + 1,
|
||||
"%s", script_dirent->d_name);
|
||||
|
||||
if (check_ev_match(lang_path,
|
||||
scripts_array[i], session))
|
||||
@ -1756,7 +1754,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
|
||||
|
||||
static char *get_script_path(const char *script_root, const char *suffix)
|
||||
{
|
||||
struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
|
||||
struct dirent *script_dirent, *lang_dirent;
|
||||
char scripts_path[MAXPATHLEN];
|
||||
char script_path[MAXPATHLEN];
|
||||
DIR *scripts_dir, *lang_dir;
|
||||
@ -1769,21 +1767,21 @@ static char *get_script_path(const char *script_root, const char *suffix)
|
||||
if (!scripts_dir)
|
||||
return NULL;
|
||||
|
||||
for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
|
||||
for_each_lang(scripts_path, scripts_dir, lang_dirent) {
|
||||
snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
|
||||
lang_dirent.d_name);
|
||||
lang_dirent->d_name);
|
||||
lang_dir = opendir(lang_path);
|
||||
if (!lang_dir)
|
||||
continue;
|
||||
|
||||
for_each_script(lang_path, lang_dir, script_dirent, script_next) {
|
||||
__script_root = get_script_root(&script_dirent, suffix);
|
||||
for_each_script(lang_path, lang_dir, script_dirent) {
|
||||
__script_root = get_script_root(script_dirent, suffix);
|
||||
if (__script_root && !strcmp(script_root, __script_root)) {
|
||||
free(__script_root);
|
||||
closedir(lang_dir);
|
||||
closedir(scripts_dir);
|
||||
snprintf(script_path, MAXPATHLEN, "%s/%s",
|
||||
lang_path, script_dirent.d_name);
|
||||
lang_path, script_dirent->d_name);
|
||||
return strdup(script_path);
|
||||
}
|
||||
free(__script_root);
|
||||
|
@ -528,6 +528,7 @@ static int __run_perf_stat(int argc, const char **argv)
|
||||
perf_evlist__set_leader(evsel_list);
|
||||
|
||||
evlist__for_each(evsel_list, counter) {
|
||||
try_again:
|
||||
if (create_perf_stat_counter(counter) < 0) {
|
||||
/*
|
||||
* PPC returns ENXIO for HW counters until 2.6.37
|
||||
@ -544,7 +545,11 @@ static int __run_perf_stat(int argc, const char **argv)
|
||||
if ((counter->leader != counter) ||
|
||||
!(counter->leader->nr_members > 1))
|
||||
continue;
|
||||
}
|
||||
} else if (perf_evsel__fallback(counter, errno, msg, sizeof(msg))) {
|
||||
if (verbose)
|
||||
ui__warning("%s\n", msg);
|
||||
goto try_again;
|
||||
}
|
||||
|
||||
perf_evsel__open_strerror(counter, &target,
|
||||
errno, msg, sizeof(msg));
|
||||
|
@ -268,6 +268,12 @@ else
|
||||
ifneq ($(feature-dwarf), 1)
|
||||
msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
|
||||
NO_DWARF := 1
|
||||
else
|
||||
ifneq ($(feature-dwarf_getlocations), 1)
|
||||
msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
|
||||
else
|
||||
CFLAGS += -DHAVE_DWARF_GETLOCATIONS
|
||||
endif # dwarf_getlocations
|
||||
endif # Dwarf support
|
||||
endif # libelf support
|
||||
endif # NO_LIBELF
|
||||
|
@ -959,6 +959,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_DWARF_GETLOCATIONS
|
||||
/**
|
||||
* die_get_var_innermost_scope - Get innermost scope range of given variable DIE
|
||||
* @sp_die: a subprogram DIE
|
||||
@ -1080,3 +1081,11 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
int die_get_var_range(Dwarf_Die *sp_die __maybe_unused,
|
||||
Dwarf_Die *vr_die __maybe_unused,
|
||||
struct strbuf *buf __maybe_unused)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
#endif
|
||||
|
@ -433,7 +433,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
|
||||
{
|
||||
char filename[PATH_MAX];
|
||||
DIR *tasks;
|
||||
struct dirent dirent, *next;
|
||||
struct dirent *dirent;
|
||||
pid_t tgid, ppid;
|
||||
int rc = 0;
|
||||
|
||||
@ -462,11 +462,11 @@ static int __event__synthesize_thread(union perf_event *comm_event,
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (!readdir_r(tasks, &dirent, &next) && next) {
|
||||
while ((dirent = readdir(tasks)) != NULL) {
|
||||
char *end;
|
||||
pid_t _pid;
|
||||
|
||||
_pid = strtol(dirent.d_name, &end, 10);
|
||||
_pid = strtol(dirent->d_name, &end, 10);
|
||||
if (*end)
|
||||
continue;
|
||||
|
||||
@ -575,7 +575,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
|
||||
{
|
||||
DIR *proc;
|
||||
char proc_path[PATH_MAX];
|
||||
struct dirent dirent, *next;
|
||||
struct dirent *dirent;
|
||||
union perf_event *comm_event, *mmap_event, *fork_event;
|
||||
int err = -1;
|
||||
|
||||
@ -600,9 +600,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
|
||||
if (proc == NULL)
|
||||
goto out_free_fork;
|
||||
|
||||
while (!readdir_r(proc, &dirent, &next) && next) {
|
||||
while ((dirent = readdir(proc)) != NULL) {
|
||||
char *end;
|
||||
pid_t pid = strtol(dirent.d_name, &end, 10);
|
||||
pid_t pid = strtol(dirent->d_name, &end, 10);
|
||||
|
||||
if (*end) /* only interested in proper numerical dirents */
|
||||
continue;
|
||||
|
@ -2345,6 +2345,8 @@ out:
|
||||
bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
|
||||
char *msg, size_t msgsize)
|
||||
{
|
||||
int paranoid;
|
||||
|
||||
if ((err == ENOENT || err == ENXIO || err == ENODEV) &&
|
||||
evsel->attr.type == PERF_TYPE_HARDWARE &&
|
||||
evsel->attr.config == PERF_COUNT_HW_CPU_CYCLES) {
|
||||
@ -2363,6 +2365,22 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
|
||||
evsel->attr.config = PERF_COUNT_SW_CPU_CLOCK;
|
||||
|
||||
zfree(&evsel->name);
|
||||
return true;
|
||||
} else if (err == EACCES && !evsel->attr.exclude_kernel &&
|
||||
(paranoid = perf_event_paranoid()) > 1) {
|
||||
const char *name = perf_evsel__name(evsel);
|
||||
char *new_name;
|
||||
|
||||
if (asprintf(&new_name, "%s%su", name, strchr(name, ':') ? "" : ":") < 0)
|
||||
return false;
|
||||
|
||||
if (evsel->name)
|
||||
free(evsel->name);
|
||||
evsel->name = new_name;
|
||||
scnprintf(msg, msgsize,
|
||||
"kernel.perf_event_paranoid=%d, trying to fall back to excluding kernel samples", paranoid);
|
||||
evsel->attr.exclude_kernel = 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2382,12 +2400,13 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
|
||||
"Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n"
|
||||
"which controls use of the performance events system by\n"
|
||||
"unprivileged users (without CAP_SYS_ADMIN).\n\n"
|
||||
"The default value is 1:\n\n"
|
||||
"The current value is %d:\n\n"
|
||||
" -1: Allow use of (almost) all events by all users\n"
|
||||
">= 0: Disallow raw tracepoint access by users without CAP_IOC_LOCK\n"
|
||||
">= 1: Disallow CPU event access by users without CAP_SYS_ADMIN\n"
|
||||
">= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN",
|
||||
target->system_wide ? "system-wide " : "");
|
||||
target->system_wide ? "system-wide " : "",
|
||||
perf_event_paranoid());
|
||||
case ENOENT:
|
||||
return scnprintf(msg, size, "The %s event is not supported.",
|
||||
perf_evsel__name(evsel));
|
||||
|
@ -138,11 +138,11 @@ struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = {
|
||||
#define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE)
|
||||
#define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT)
|
||||
|
||||
#define for_each_subsystem(sys_dir, sys_dirent, sys_next) \
|
||||
while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \
|
||||
if (sys_dirent.d_type == DT_DIR && \
|
||||
(strcmp(sys_dirent.d_name, ".")) && \
|
||||
(strcmp(sys_dirent.d_name, "..")))
|
||||
#define for_each_subsystem(sys_dir, sys_dirent) \
|
||||
while ((sys_dirent = readdir(sys_dir)) != NULL) \
|
||||
if (sys_dirent->d_type == DT_DIR && \
|
||||
(strcmp(sys_dirent->d_name, ".")) && \
|
||||
(strcmp(sys_dirent->d_name, "..")))
|
||||
|
||||
static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
|
||||
{
|
||||
@ -159,12 +159,12 @@ static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \
|
||||
while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \
|
||||
if (evt_dirent.d_type == DT_DIR && \
|
||||
(strcmp(evt_dirent.d_name, ".")) && \
|
||||
(strcmp(evt_dirent.d_name, "..")) && \
|
||||
(!tp_event_has_id(&sys_dirent, &evt_dirent)))
|
||||
#define for_each_event(sys_dirent, evt_dir, evt_dirent) \
|
||||
while ((evt_dirent = readdir(evt_dir)) != NULL) \
|
||||
if (evt_dirent->d_type == DT_DIR && \
|
||||
(strcmp(evt_dirent->d_name, ".")) && \
|
||||
(strcmp(evt_dirent->d_name, "..")) && \
|
||||
(!tp_event_has_id(sys_dirent, evt_dirent)))
|
||||
|
||||
#define MAX_EVENT_LENGTH 512
|
||||
|
||||
@ -173,7 +173,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
|
||||
{
|
||||
struct tracepoint_path *path = NULL;
|
||||
DIR *sys_dir, *evt_dir;
|
||||
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
|
||||
struct dirent *sys_dirent, *evt_dirent;
|
||||
char id_buf[24];
|
||||
int fd;
|
||||
u64 id;
|
||||
@ -184,18 +184,18 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
|
||||
if (!sys_dir)
|
||||
return NULL;
|
||||
|
||||
for_each_subsystem(sys_dir, sys_dirent, sys_next) {
|
||||
for_each_subsystem(sys_dir, sys_dirent) {
|
||||
|
||||
snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
|
||||
sys_dirent.d_name);
|
||||
sys_dirent->d_name);
|
||||
evt_dir = opendir(dir_path);
|
||||
if (!evt_dir)
|
||||
continue;
|
||||
|
||||
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
|
||||
for_each_event(sys_dirent, evt_dir, evt_dirent) {
|
||||
|
||||
snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
|
||||
evt_dirent.d_name);
|
||||
evt_dirent->d_name);
|
||||
fd = open(evt_path, O_RDONLY);
|
||||
if (fd < 0)
|
||||
continue;
|
||||
@ -220,9 +220,9 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
|
||||
free(path);
|
||||
return NULL;
|
||||
}
|
||||
strncpy(path->system, sys_dirent.d_name,
|
||||
strncpy(path->system, sys_dirent->d_name,
|
||||
MAX_EVENT_LENGTH);
|
||||
strncpy(path->name, evt_dirent.d_name,
|
||||
strncpy(path->name, evt_dirent->d_name,
|
||||
MAX_EVENT_LENGTH);
|
||||
return path;
|
||||
}
|
||||
@ -1812,7 +1812,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
|
||||
bool name_only)
|
||||
{
|
||||
DIR *sys_dir, *evt_dir;
|
||||
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
|
||||
struct dirent *sys_dirent, *evt_dirent;
|
||||
char evt_path[MAXPATHLEN];
|
||||
char dir_path[MAXPATHLEN];
|
||||
char **evt_list = NULL;
|
||||
@ -1830,20 +1830,20 @@ restart:
|
||||
goto out_close_sys_dir;
|
||||
}
|
||||
|
||||
for_each_subsystem(sys_dir, sys_dirent, sys_next) {
|
||||
for_each_subsystem(sys_dir, sys_dirent) {
|
||||
if (subsys_glob != NULL &&
|
||||
!strglobmatch(sys_dirent.d_name, subsys_glob))
|
||||
!strglobmatch(sys_dirent->d_name, subsys_glob))
|
||||
continue;
|
||||
|
||||
snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
|
||||
sys_dirent.d_name);
|
||||
sys_dirent->d_name);
|
||||
evt_dir = opendir(dir_path);
|
||||
if (!evt_dir)
|
||||
continue;
|
||||
|
||||
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
|
||||
for_each_event(sys_dirent, evt_dir, evt_dirent) {
|
||||
if (event_glob != NULL &&
|
||||
!strglobmatch(evt_dirent.d_name, event_glob))
|
||||
!strglobmatch(evt_dirent->d_name, event_glob))
|
||||
continue;
|
||||
|
||||
if (!evt_num_known) {
|
||||
@ -1852,7 +1852,7 @@ restart:
|
||||
}
|
||||
|
||||
snprintf(evt_path, MAXPATHLEN, "%s:%s",
|
||||
sys_dirent.d_name, evt_dirent.d_name);
|
||||
sys_dirent->d_name, evt_dirent->d_name);
|
||||
|
||||
evt_list[evt_i] = strdup(evt_path);
|
||||
if (evt_list[evt_i] == NULL)
|
||||
@ -1905,7 +1905,7 @@ out_close_sys_dir:
|
||||
int is_valid_tracepoint(const char *event_string)
|
||||
{
|
||||
DIR *sys_dir, *evt_dir;
|
||||
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
|
||||
struct dirent *sys_dirent, *evt_dirent;
|
||||
char evt_path[MAXPATHLEN];
|
||||
char dir_path[MAXPATHLEN];
|
||||
|
||||
@ -1913,17 +1913,17 @@ int is_valid_tracepoint(const char *event_string)
|
||||
if (!sys_dir)
|
||||
return 0;
|
||||
|
||||
for_each_subsystem(sys_dir, sys_dirent, sys_next) {
|
||||
for_each_subsystem(sys_dir, sys_dirent) {
|
||||
|
||||
snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
|
||||
sys_dirent.d_name);
|
||||
sys_dirent->d_name);
|
||||
evt_dir = opendir(dir_path);
|
||||
if (!evt_dir)
|
||||
continue;
|
||||
|
||||
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
|
||||
for_each_event(sys_dirent, evt_dir, evt_dirent) {
|
||||
snprintf(evt_path, MAXPATHLEN, "%s:%s",
|
||||
sys_dirent.d_name, evt_dirent.d_name);
|
||||
sys_dirent->d_name, evt_dirent->d_name);
|
||||
if (!strcmp(evt_path, event_string)) {
|
||||
closedir(evt_dir);
|
||||
closedir(sys_dir);
|
||||
|
@ -94,7 +94,7 @@ struct thread_map *thread_map__new_by_uid(uid_t uid)
|
||||
DIR *proc;
|
||||
int max_threads = 32, items, i;
|
||||
char path[256];
|
||||
struct dirent dirent, *next, **namelist = NULL;
|
||||
struct dirent *dirent, **namelist = NULL;
|
||||
struct thread_map *threads = thread_map__alloc(max_threads);
|
||||
|
||||
if (threads == NULL)
|
||||
@ -107,16 +107,16 @@ struct thread_map *thread_map__new_by_uid(uid_t uid)
|
||||
threads->nr = 0;
|
||||
atomic_set(&threads->refcnt, 1);
|
||||
|
||||
while (!readdir_r(proc, &dirent, &next) && next) {
|
||||
while ((dirent = readdir(proc)) != NULL) {
|
||||
char *end;
|
||||
bool grow = false;
|
||||
struct stat st;
|
||||
pid_t pid = strtol(dirent.d_name, &end, 10);
|
||||
pid_t pid = strtol(dirent->d_name, &end, 10);
|
||||
|
||||
if (*end) /* only interested in proper numerical dirents */
|
||||
continue;
|
||||
|
||||
snprintf(path, sizeof(path), "/proc/%s", dirent.d_name);
|
||||
snprintf(path, sizeof(path), "/proc/%s", dirent->d_name);
|
||||
|
||||
if (stat(path, &st) != 0)
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user