perf/urgent fixes
Subsystems (2)
Arnaldo Carvalho de Melo
maintainerPATCH 7/10 tools lib traceevent: Do not reassign parg after collapse_tree()
In reply to Arnaldo Carvalho de MeloFrom: Steven Rostedt <[email protected]>
At the end of process_filter(), collapse_tree() was changed to update the parg parameter, but the reassignment after the call wasn't removed.
What happens is that the "current_op" gets modified and freed and parg is assigned to the new allocated argument. But after the call to collapse_tree(), parg is assigned again to the just freed "current_op", and this causes the tool to crash.
The current_op variable must also be assigned to NULL in case of error, otherwise it will cause it to be free()ed twice.
--- tools/lib/traceevent/parse-filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/traceevent/parse-filter.c +2 -2
@@ -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 ;
Signature · 1 line
2.5.5
Arnaldo Carvalho de Melo
maintainerPATCH 3/10 perf thread_map: Use readdir() instead of deprecated readdir_r()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The readdir() function is thread safe as long as just one thread uses a DIR, which is the case in thread_map, so, to avoid breaking the build with glibc-2.23.90 (upcoming 2.24), use it instead of readdir_r().
See: http://man7.org/linux/man-pages/man3/readdir.3.html
"However, in modern implementations (including the glibc implementation), concurrent calls to readdir() that specify different directory streams are thread-safe. In cases where multiple threads must read from the same directory stream, using readdir() with external synchronization is still preferable to the use of the deprecated readdir_r(3) function."
Noticed while building on a Fedora Rawhide docker container.
--- tools/perf/util/thread_map.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/thread_map.c +4 -4
@@ -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 ;
Signature · 1 line
2.5.5
Arnaldo Carvalho de Melo
maintainerPATCH 5/10 perf dwarf: Guard !x86_64 definitions under #ifdef else clause
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
To fix the build on Fedora Rawhide (gcc 6.0.0 20160311 (Red Hat 6.0.0-0.17):
CC /tmp/build/perf/arch/x86/util/dwarf-regs.o
arch/x86/util/dwarf-regs.c:66:36: error: 'x86_32_regoffset_table' defined but not used [-Werror=unused-const-variable=]
static const struct pt_regs_offset x86_32_regoffset_table[] = {
^~~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
--- tools/perf/arch/x86/util/dwarf-regs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/arch/x86/util/dwarf-regs.c +4 -4
@@ -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 */
Signature · 1 line
2.5.5
Arnaldo Carvalho de Melo
maintainerHi Ingo,
Please consider pulling, test built on:
alldeps-fedora-rawhide: Ok
alldeps-ubuntu-14.04: Ok
alldeps-ubuntu-16.04: Ok
alldeps-fedora-20: Ok
alldeps-ubuntu-12.04: Ok
minimal-debian-experimental-x-mips64: Ok
minimal-debian-experimental-x-mips64el: Ok
minimal-debian-experimental-x-mipsel: Ok
minimal-ubuntu-x-arm: Ok
minimal-ubuntu-x-arm64: Ok
minimal-ubuntu-x-ppc64: Ok
minimal-ubuntu-x-ppc64el: Ok
alldeps-debian: Ok
alldeps-mageia: Ok
alldeps-rhel7: Ok
alldeps-centos: Ok
alldeps-opensuse: Ok
- Arnaldo
The following changes since commit 9f448cd3cbcec8995935e60b27802ae56aac8cc0:
perf/core: Disable the event on a truncated AUX record (2016-05-12 14:46:11 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-urgent-for-mingo-20160512
for you to fetch changes up to 42ef8a78c1f49f53f29f0f3a6f9a5bcbc653233e:
perf stat: Fallback to user only counters when perf_event_paranoid > 1 (2016-05-12 16:25:18 -0300)
----------------------------------------------------------------
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)
----------------------------------------------------------------
Arnaldo Carvalho de Melo (9):
perf tools: Use readdir() instead of deprecated readdir_r() perf script: Use readdir() instead of deprecated readdir_r() perf thread_map: Use readdir() instead of deprecated readdir_r() perf tools: Use readdir() instead of deprecated readdir_r() perf dwarf: Guard !x86_64 definitions under #ifdef else clause perf probe: Check if dwarf_getlocations() is available perf evsel: Improve EPERM error handling in open_strerror() perf evsel: Handle EACCESS + perf_event_paranoid=2 in fallback() perf stat: Fallback to user only counters when perf_event_paranoid > 1
Steven Rostedt (1):
tools lib traceevent: Do not reassign parg after collapse_tree()
tools/build/Makefile.feature | 2 + tools/build/feature/Makefile | 4 ++ tools/build/feature/test-all.c | 5 ++ tools/build/feature/test-dwarf_getlocations.c | 12 +++++ tools/lib/traceevent/parse-filter.c | 4 +- tools/perf/arch/x86/util/dwarf-regs.c | 8 +-- tools/perf/builtin-script.c | 70 +++++++++++++-------------- tools/perf/builtin-stat.c | 7 ++- tools/perf/config/Makefile | 6 +++ tools/perf/util/dwarf-aux.c | 9 ++++ tools/perf/util/event.c | 12 ++--- tools/perf/util/evsel.c | 23 ++++++++- tools/perf/util/parse-events.c | 60 +++++++++++------------ tools/perf/util/thread_map.c | 8 +-- 14 files changed, 145 insertions(+), 85 deletions(-) create mode 100644 tools/build/feature/test-dwarf_getlocations.c
Arnaldo Carvalho de Melo
maintainerPATCH 8/10 perf evsel: Improve EPERM error handling in open_strerror()
From: Arnaldo Carvalho de Melo <[email protected]>
We were showing a hardcoded default value for the kernel.perf_event_paranoid sysctl, now that it became more paranoid (1 -> 2 [1]), this would need to be updated, instead show the current value:
[acme@jouet linux]$ perf record ls
Error:
You may not have permission to collect stats.
Consider tweaking /proc/sys/kernel/perf_event_paranoid, which controls use of the performance events system by unprivileged users (without CAP_SYS_ADMIN).
The current value is 2:
-1: Allow use of (almost) all events by all users
Quoted 3 lines
= 0: Disallow raw tracepoint access by users without
CAP_IOC_LOCK= 1: Disallow CPU event access by users withoutCAP_SYS_ADMIN= 2: Disallow kernel profiling by users withoutCAP_SYS_ADMIN
[acme@jouet linux]$
[1] 0161028b7c8a ("perf/core: Change the default paranoia level to 2")
--- tools/perf/util/evsel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/evsel.c +3 -2
@@ -2382,12 +2382,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));
Signature · 1 line
2.5.5
Arnaldo Carvalho de Melo
maintainerPATCH 9/10 perf evsel: Handle EACCESS + perf_event_paranoid=2 in fallback()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Now with the default for the kernel.perf_event_paranoid sysctl being 2 [1] we need to fall back to :u, i.e. to set perf_event_attr.exclude_kernel to 1.
Before:
[acme@jouet linux]$ perf record usleep 1
Error:
You may not have permission to collect stats.
Consider tweaking /proc/sys/kernel/perf_event_paranoid, which controls use of the performance events system by unprivileged users (without CAP_SYS_ADMIN).
The current value is 2:
-1: Allow use of (almost) all events by all users
Quoted 3 lines
= 0: Disallow raw tracepoint access by users without
CAP_IOC_LOCK= 1: Disallow CPU event access by users withoutCAP_SYS_ADMIN= 2: Disallow kernel profiling by users withoutCAP_SYS_ADMIN
[acme@jouet linux]$
After:
[acme@jouet linux]$ perf record usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.016 MB perf.data (7 samples) ]
[acme@jouet linux]$ perf evlist
cycles:u
[acme@jouet linux]$ perf evlist -v
cycles:u: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, exclude_kernel: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 [acme@jouet linux]$
And if the user turns on verbose mode, an explanation will appear:
[acme@jouet linux]$ perf record -v usleep 1
Warning:
kernel.perf_event_paranoid=2, trying to fall back to excluding kernel samples mmap size 528384B
[ perf record: Woken up 1 times to write data ]
Looking at the vmlinux_path (8 entries long)
Using /lib/modules/4.6.0-rc7+/build/vmlinux for symbols
[ perf record: Captured and wrote 0.016 MB perf.data (7 samples) ] [acme@jouet linux]$
[1] 0161028b7c8a ("perf/core: Change the default paranoia level to 2")
--- tools/perf/util/evsel.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
tools/perf/util/evsel.c +18 -0
@@ -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 ) {
@@ -2364,6 +2366,22 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err,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; }return false;
Signature · 1 line
2.5.5
Arnaldo Carvalho de Melo
maintainerPATCH 10/10 perf stat: Fallback to user only counters when perf_event_paranoid > 1
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
After 0161028b7c8a ("perf/core: Change the default paranoia level to 2") 'perf stat' fails for users without CAP_SYS_ADMIN, so just use 'perf_evsel__fallback()' to have the same behaviour as 'perf record', i.e. set perf_event_attr.exclude_kernel to 1.
Now:
[acme@jouet linux]$ perf stat usleep 1
Performance counter stats for 'usleep 1':
0.352536 task-clock:u (msec) # 0.423 CPUs utilized
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
49 page-faults:u # 0.139 M/sec
309,407 cycles:u # 0.878 GHz
243,791 instructions:u # 0.79 insn per cycle
49,622 branches:u # 140.757 M/sec
3,884 branch-misses:u # 7.83% of all branches0.000834174 seconds time elapsed
[acme@jouet linux]$
--- tools/perf/builtin-stat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +6 -1
@@ -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));
Signature · 1 line
2.5.5
Arnaldo Carvalho de Melo
maintainerPATCH 1/10 perf tools: Use readdir() instead of deprecated readdir_r()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The readdir() function is thread safe as long as just one thread uses a DIR, which is the case when synthesizing events for pre-existing threads by traversing /proc, so, to avoid breaking the build with glibc-2.23.90 (upcoming 2.24), use it instead of readdir_r().
See: http://man7.org/linux/man-pages/man3/readdir.3.html
"However, in modern implementations (including the glibc implementation), concurrent calls to readdir() that specify different directory streams are thread-safe. In cases where multiple threads must read from the same directory stream, using readdir() with external synchronization is still preferable to the use of the deprecated readdir_r(3) function."
Noticed while building on a Fedora Rawhide docker container.
CC /tmp/build/perf/util/event.o
util/event.c: In function '__event__synthesize_thread':
util/event.c:466:2: error: 'readdir_r' is deprecated [-Werror=deprecated-declarations]
while (!readdir_r(tasks, &dirent, &next) && next) {
^~~~~
In file included from /usr/include/features.h:368:0,
from /usr/include/stdint.h:25,
from /usr/lib/gcc/x86_64-redhat-linux/6.0.0/include/stdint.h:9,
from /git/linux/tools/include/linux/types.h:6,
from util/event.c:1: /usr/include/dirent.h:189:12: note: declared here
--- tools/perf/util/event.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/util/event.c +6 -6
@@ -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 ;
Signature · 1 line
2.5.5
Arnaldo Carvalho de Melo
maintainerPATCH 2/10 perf script: Use readdir() instead of deprecated readdir_r()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The readdir() function is thread safe as long as just one thread uses a DIR, which is the case in 'perf script', so, to avoid breaking the build with glibc-2.23.90 (upcoming 2.24), use it instead of readdir_r().
See: http://man7.org/linux/man-pages/man3/readdir.3.html
"However, in modern implementations (including the glibc implementation), concurrent calls to readdir() that specify different directory streams are thread-safe. In cases where multiple threads must read from the same directory stream, using readdir() with external synchronization is still preferable to the use of the deprecated readdir_r(3) function."
Noticed while building on a Fedora Rawhide docker container.
--- tools/perf/builtin-script.c | 70 ++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 36 deletions(-)
tools/perf/builtin-script.c +34 -36
@@ -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_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_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) \ + 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);
Signature · 1 line
2.5.5
Arnaldo Carvalho de Melo
maintainerPATCH 4/10 perf tools: Use readdir() instead of deprecated readdir_r()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The readdir() function is thread safe as long as just one thread uses a DIR, which is the case when parsing tracepoint event definitions, to avoid breaking the build with glibc-2.23.90 (upcoming 2.24), use it instead of readdir_r().
See: http://man7.org/linux/man-pages/man3/readdir.3.html
"However, in modern implementations (including the glibc implementation), concurrent calls to readdir() that specify different directory streams are thread-safe. In cases where multiple threads must read from the same directory stream, using readdir() with external synchronization is still preferable to the use of the deprecated readdir_r(3) function."
Noticed while building on a Fedora Rawhide docker container.
--- tools/perf/util/parse-events.c | 60 +++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 30 deletions(-)
tools/perf/util/parse-events.c +30 -30
@@ -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);
Signature · 1 line
2.5.5
Arnaldo Carvalho de Melo
maintainerPATCH 6/10 perf probe: Check if dwarf_getlocations() is available
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
If not, tell the user that:
config/Makefile:273: Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157
And return -ENOTSUPP in die_get_var_range(), failing features that need it, like the one pointed out above.
This fixes the build on older systems, such as Ubuntu 12.04.5.
--- tools/build/Makefile.feature | 2 ++ tools/build/feature/Makefile | 4 ++++ tools/build/feature/test-all.c | 5 +++++ tools/build/feature/test-dwarf_getlocations.c | 12 ++++++++++++ tools/perf/config/Makefile | 6 ++++++ tools/perf/util/dwarf-aux.c | 9 +++++++++ 6 files changed, 38 insertions(+) create mode 100644 tools/build/feature/test-dwarf_getlocations.c
tools/build/Makefile.feature +2 -0
@@ -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 \
tools/build/feature/Makefile +4 -0
@@ -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
tools/build/feature/test-all.c +5 -0
@@ -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 ();
tools/build/feature/test-dwarf_getlocations.c new file +12 -0
@@ -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); +}
tools/perf/config/Makefile +6 -0
@@ -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
tools/perf/util/dwarf-aux.c +9 -0
@@ -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
Signature · 1 line
2.5.5
Re: [PATCH 05/10] perf dwarf: Guard !x86_64 definitions under #ifdef else clause
In reply to Arnaldo Carvalho de MeloQuoted 9 lines · On Thu, 12 May 2016 17:03:50 -0300 Arnaldo Carvalho de Melo <[email protected]>…
From: Arnaldo Carvalho de Melo <[email protected]>
To fix the build on Fedora Rawhide (gcc 6.0.0 20160311 (Red Hat 6.0.0-0.17):
CC
/tmp/build/perf/arch/x86/util/dwarf-regs.o
arch/x86/util/dwarf-regs.c:66:36: error: 'x86_32_regoffset_table' defined but not used [-Werror=unused-const-variable=]static const struct pt_regs_offset x86_32_regoffset_table[] = { ^~~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
Looks good to me too.
Thanks!
Quoted 49 lines
Cc Adrian Hunter <[email protected]>Cc David Ahern <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Cc Wang Nan <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/arch/x86/util/dwarf-regs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)tools/perf/arch/x86/util/dwarf-regs.c +4
-4@@ -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 */ Signature · 1 line
2.5.5
Signature · 1 line
Masami Hiramatsu <[email protected]>
Re: [PATCH 06/10] perf probe: Check if dwarf_getlocations() is available
In reply to Arnaldo Carvalho de MeloQuoted 11 lines · On Thu, 12 May 2016 17:03:51 -0300 Arnaldo Carvalho de Melo <[email protected]>…
From: Arnaldo Carvalho de Melo <[email protected]>
If not, tell the user that:
config/Makefile:273: Old
libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157And return
-ENOTSUPPindie_get_var_range(), failing features that need it, like the one pointed out above.This fixes the build on older systems, such as Ubuntu 12.04.5.
Hmm, would we better to use similar technique for dwarf_cfi_addrframe? the commit 7752f1b096e1
("perf probe: Don't compile CFI related code if elfutils is old") uses _ELFUTILS_PREREQ() macro for checking the elfutils version directly.
Anyway, this looks good to me.
Quoted 145 lines
Cc Adrian Hunter <[email protected]>Cc David Ahern <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Cc Vinson Lee <[email protected]>Cc Wang Nan <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/build/Makefile.feature | 2 ++ tools/build/feature/Makefile | 4 ++++ tools/build/feature/test-all.c | 5 +++++ tools/build/feature/test-dwarf_getlocations.c | 12 ++++++++++++ tools/perf/config/Makefile | 6 ++++++ tools/perf/util/dwarf-aux.c | 9 +++++++++ 6 files changed, 38 insertions(+) create mode 100644 tools/build/feature/test-dwarf_getlocations.ctools/build/Makefile.feature +2
-0@@ -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 \tools/build/feature/Makefile +4
-0@@ -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) -lelftools/build/feature/test-all.c +5
-0@@ -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 ();tools/build/feature/test-dwarf_getlocations.c new file +12
-0@@ -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); +}tools/perf/config/Makefile +6
-0@@ -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_LIBELFtools/perf/util/dwarf-aux.c +9
-0@@ -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 Signature · 1 line
2.5.5
Signature · 1 line
Masami Hiramatsu <[email protected]>
Quoted 73 lines · Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling, test built on:
alldeps-fedora-rawhide: Ok
alldeps-ubuntu-14.04: Ok
alldeps-ubuntu-16.04: Ok
alldeps-fedora-20: Ok
alldeps-ubuntu-12.04: Ok
minimal-debian-experimental-x-mips64: Ok
minimal-debian-experimental-x-mips64el: Ok
minimal-debian-experimental-x-mipsel: Ok
minimal-ubuntu-x-arm: Ok
minimal-ubuntu-x-arm64: Ok
minimal-ubuntu-x-ppc64: Ok
minimal-ubuntu-x-ppc64el: Ok
alldeps-debian: Ok
alldeps-mageia: Ok
alldeps-rhel7: Ok
alldeps-centos: Ok
alldeps-opensuse: Ok- Arnaldo
The following changes since commit
9f448cd3cbcec8995935e60b27802ae56aac8cc0:perf/core: Disable the event on a truncated AUX record (2016-05-12 14:46:11 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-urgent-for-mingo-20160512for you to fetch changes up to
42ef8a78c1f49f53f29f0f3a6f9a5bcbc653233e:perf stat: Fallback to user only counters when
perf_event_paranoid> 1 (2016-05-12 16:25:18 -0300)----------------------------------------------------------------
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_tableon !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 <[email protected]>----------------------------------------------------------------
Arnaldo Carvalho de Melo (9):
perf tools: Usereaddir()instead of deprecatedreaddir_r()perf script: Usereaddir()instead of deprecatedreaddir_r()perfthread_map: Usereaddir()instead of deprecatedreaddir_r()perf tools: Usereaddir()instead of deprecatedreaddir_r()perf dwarf: Guard !x86_64 definitions under #ifdef else clause perf probe: Check ifdwarf_getlocations()is available perf evsel: Improve EPERM error handling inopen_strerror()perf evsel: Handle EACCESS + perf_event_paranoid=2 infallback()perf stat: Fallback to user only counters whenperf_event_paranoid> 1Steven Rostedt (1):
tools lib traceevent: Do not reassign parg aftercollapse_tree()
Quoted 16 lines
tools/build/Makefile.feature | 2 + tools/build/feature/Makefile | 4 ++ tools/build/feature/test-all.c | 5 ++ tools/build/feature/test-dwarf_getlocations.c | 12 +++++ tools/lib/traceevent/parse-filter.c | 4 +- tools/perf/arch/x86/util/dwarf-regs.c | 8 +-- tools/perf/builtin-script.c | 70 +++++++++++++-------------- tools/perf/builtin-stat.c | 7 ++- tools/perf/config/Makefile | 6 +++ tools/perf/util/dwarf-aux.c | 9 ++++ tools/perf/util/event.c | 12 ++--- tools/perf/util/evsel.c | 23 ++++++++- tools/perf/util/parse-events.c | 60 +++++++++++------------ tools/perf/util/thread_map.c | 8 +-- 14 files changed, 145 insertions(+), 85 deletions(-) create mode 100644 tools/build/feature/test-dwarf_getlocations.c
Pulled, thanks a lot Arnaldo!
Ingo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 06/10] perf probe: Check if dwarf_getlocations() is available
In reply to Masami HiramatsuEm Fri, May 13, 2016 at 11:38:52AM +0900, Masami Hiramatsu escreveu:
Quoted 12 lines
Quoted 9 lines · On Thu, 12 May 2016 17:03:51 -0300 Arnaldo Carvalho de Melo <[email protected]>…
From: Arnaldo Carvalho de Melo <[email protected]>
If not, tell the user that:
config/Makefile:273: Old
libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157And return
-ENOTSUPPindie_get_var_range(), failing features that need it, like the one pointed out above.
Quoted 7 lines
Quoted 2 lines
This fixes the build on older systems, such as Ubuntu 12.04.5.
Hmm, would we better to use similar technique for
dwarf_cfi_addrframe? the commit7752f1b096e1
("perf probe: Don't compile CFI related code if elfutils is old") uses_ELFUTILS_PREREQ()macro for checking the elfutils version directly.
I'll take a look at this.
Quoted 3 lines
Anyway, this looks good to me.
Acked-by Masami Hiramatsu <[email protected]>
Thanks for verifying this and the other one!
- Arnaldo
Quoted 149 lines
Quoted 145 lines
Cc Adrian Hunter <[email protected]>Cc David Ahern <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Cc Vinson Lee <[email protected]>Cc Wang Nan <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/build/Makefile.feature | 2 ++ tools/build/feature/Makefile | 4 ++++ tools/build/feature/test-all.c | 5 +++++ tools/build/feature/test-dwarf_getlocations.c | 12 ++++++++++++ tools/perf/config/Makefile | 6 ++++++ tools/perf/util/dwarf-aux.c | 9 +++++++++ 6 files changed, 38 insertions(+) create mode 100644 tools/build/feature/test-dwarf_getlocations.ctools/build/Makefile.feature +2
-0@@ -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 \tools/build/feature/Makefile +4
-0@@ -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) -lelftools/build/feature/test-all.c +5
-0@@ -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 ();tools/build/feature/test-dwarf_getlocations.c new file +12
-0@@ -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); +}tools/perf/config/Makefile +6
-0@@ -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_LIBELFtools/perf/util/dwarf-aux.c +9
-0@@ -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 Signature · 1 line
2.5.5Signature · 1 line
Masami Hiramatsu <[email protected]>