perf tools: Assorted random updates and fixes
Namhyung Kim
maintainercover perf tools: Assorted random updates and fixes
Hello,
I found some misc updates and fixes are still remaining. Just sending out together. Please take a look!
Thanks,
Namhyung
Namhyung Kim (4):
perf report: Fix condition in sort__sym_cmp() perf symbol: Simplify kernel module checking perf tools: Fix a compiler warning of NULL pointer perf mem: Fix a segfault with NULL event->name
tools/perf/util/dsos.c | 3 +++ tools/perf/util/mem-events.c | 2 +- tools/perf/util/sort.c | 2 +- tools/perf/util/symbol.c | 5 +---- 4 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Namhyung Kim
maintainerPATCH 1/4 perf report: Fix condition in sort__sym_cmp()
It's expected that both hist entries are in the same hists when comparing two. But the current code in the function checks one without dso sort key and other with the key. This would make the condition true in any case.
I guess the intention of the original commit was to add '!' for the right side too. But as it should be the same, let's just remove it.
--- tools/perf/util/sort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/sort.c +1 -1
@@ -334,7 +334,7 @@ sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)* comparing symbol address alone is not enough since it's a * relative address within a dso. */ -if (!hists__has (left->hists, dso) ||hists__has (right->hists, dso)) { +if (!hists__has (left->hists, dso)) { ret =sort__dso_cmp (left, right);if (ret !=0 )return ret;
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Namhyung Kim
maintainerPATCH 2/4 perf symbol: Simplify kernel module checking
In reply to Namhyung KimIn dso__load(), it checks if the dso is a kernel module by looking the symtab type. Actually dso has 'is_kmod' field to check that easily and dso__set_module_info() set the symtab type and the is_kmod bit. So it should have the same result to check the is_kmod bit.
--- tools/perf/util/symbol.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
tools/perf/util/symbol.c +1 -4
@@ -1816,10 +1816,7 @@ int dso__load(struct dso *dso, struct map *map) goto out; } - kmod =dso__symtab_type (dso) ==DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE || -dso__symtab_type (dso) ==DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP || -dso__symtab_type (dso) ==DSO_BINARY_TYPE__GUEST_KMODULE || -dso__symtab_type (dso) ==DSO_BINARY_TYPE__GUEST_KMODULE_COMP ; + kmod =dso__is_kmod (dso);if (dso__kernel (dso) && !kmod) {if (dso__kernel (dso) ==DSO_SPACE__KERNEL )
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Namhyung Kim
maintainerPATCH 3/4 perf tools: Fix a compiler warning of NULL pointer
In reply to Namhyung KimA compiler warning on the second argument of bsearch() should not be NULL, but there's a case we might pass it. Let's return early if we don't have any DSOs to search in __dsos__find_by_longname_id().
util/dsos.c:184:8: runtime error: null pointer passed as argument 2, which is declared to never be null
--- tools/perf/util/dsos.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/dsos.c +3 -0
@@ -164,6 +164,9 @@ static struct dso *__dsos__find_by_longname_id(struct dsos *dsos, };struct dso **res; +if (dsos->dsos ==NULL ) +return NULL ; +if (!dsos->sorted) {if (!write_locked) {struct dso *dso;
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Namhyung Kim
maintainerPATCH 4/4 perf mem: Fix a segfault with NULL event->name
In reply to Namhyung KimGuilherme reported a crash in perf mem record. It's because the perf_mem_event->name was NULL on his machine. It should just return a NULL string when it has no format string in the name.
But I'm not sure why it returns TRUE if it doesn't have event_name in perf_pmu__mem_events_supported().
The backtrace at the crash is below:
Program received signal SIGSEGV, Segmentation fault. __strchrnul_avx2 () at ../sysdeps/x86_64/multiarch/strchr-avx2.S:67
67 vmovdqu (%rdi), %ymm2
(gdb) bt
#0 __strchrnul_avx2 () at ../sysdeps/x86_64/multiarch/strchr-avx2.S:67
#1 0x00007ffff6c982de in __find_specmb (format=0x0) at printf-parse.h:82
#2 __printf_buffer (buf=buf@entry=0x7fffffffc760, format=format@entry=0x0, ap=ap@entry=0x7fffffffc880,
mode_flags=mode_flags@entry=0) at vfprintf-internal.c:649
#3 0x00007ffff6cb7840 in __vsnprintf_internal (string=<optimized out>, maxlen=<optimized out>, format=0x0,
args=0x7fffffffc880, mode_flags=mode_flags@entry=0) at vsnprintf.c:96
#4 0x00007ffff6cb787f in ___vsnprintf (string=<optimized out>, maxlen=<optimized out>, format=<optimized out>,
args=<optimized out>) at vsnprintf.c:103
#5 0x00005555557b9391 in scnprintf (buf=0x555555fe9320 <mem_loads_name> "", size=100, fmt=0x0)
at ../lib/vsprintf.c:21
#6 0x00005555557b74c3 in perf_pmu__mem_events_name (i=0, pmu=0x555556832180) at util/mem-events.c:106
#7 0x00005555557b7ab9 in perf_mem_events__record_args (rec_argv=0x55555684c000, argv_nr=0x7fffffffca20)
at util/mem-events.c:252
#8 0x00005555555e370d in __cmd_record (argc=3, argv=0x7fffffffd760, mem=0x7fffffffcd80) at builtin-mem.c:156
#9 0x00005555555e49c4 in cmd_mem (argc=4, argv=0x7fffffffd760) at builtin-mem.c:514
#10 0x000055555569716c in run_builtin (p=0x555555fcde80 <commands+672>, argc=8, argv=0x7fffffffd760) at perf.c:349
#11 0x0000555555697402 in handle_internal_command (argc=8, argv=0x7fffffffd760) at perf.c:402
#12 0x0000555555697560 in run_argv (argcp=0x7fffffffd59c, argv=0x7fffffffd590) at perf.c:446
#13 0x00005555556978a6 in main (argc=8, argv=0x7fffffffd760) at perf.c:562--- tools/perf/util/mem-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/mem-events.c +1 -1
@@ -86,7 +86,7 @@ static const char *perf_pmu__mem_events_name(int i, struct perf_pmu *pmu)return NULL ; e = &pmu->mem_events[i]; -if (!e) +if (!e || !e->name)return NULL ;if (i ==PERF_MEM_EVENTS__LOAD || i ==PERF_MEM_EVENTS__LOAD_STORE ) {
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Re: [PATCH 4/4] perf mem: Fix a segfault with NULL event->name
Quoted 6 lines · Namhyung Kim
Guilherme reported a crash in perf mem record. It's because the
perf_mem_event->namewas NULL on his machine. It should just return a NULL string when it has no format string in the name.But I'm not sure why it returns TRUE if it doesn't have
event_nameinperf_pmu__mem_events_supported().
AMD doesn't have the event_name.
struct perf_mem_event perf_mem_events_amd[PERF_MEM_EVENTS__MAX] = {
E(NULL, NULL, NULL, false, 0),
E(NULL, NULL, NULL, false, 0),
E("mem-ldst", "%s//", NULL, false, 0),
};It looks like as long as it's a "ibs_op" PMU, the mem event is always available. The "ibs_op" check has been moved into perf_pmu__arch_init(). So the event_name is empty.
The "e->tag" in the perf_pmu__mem_events_init() can help to skip the
case E(NULL, NULL, NULL, false, 0).
So the perf_pmu__mem_events_supported() returns TRUE for the !event_name.
Thanks,
Kan
Quoted 47 lines
The backtrace at the crash is below:
Program received signal SIGSEGV, Segmentation fault.
__strchrnul_avx2() at../sysdeps/x86_64/multiarch/strchr-avx2.S:67
67 vmovdqu (%rdi), %ymm2
(gdb) bt#0 __strchrnul_avx2 () at ../sysdeps/x86_64/multiarch/strchr-avx2.S:67 #1 0x00007ffff6c982de in __find_specmb (format=0x0) at printf-parse.h:82 #2 __printf_buffer (buf=buf@entry=0x7fffffffc760, format=format@entry=0x0, ap=ap@entry=0x7fffffffc880, mode_flags=mode_flags@entry=0) at vfprintf-internal.c:649 #3 0x00007ffff6cb7840 in __vsnprintf_internal (string=<optimized out>, maxlen=<optimized out>, format=0x0, args=0x7fffffffc880, mode_flags=mode_flags@entry=0) at vsnprintf.c:96 #4 0x00007ffff6cb787f in ___vsnprintf (string=<optimized out>, maxlen=<optimized out>, format=<optimized out>, args=<optimized out>) at vsnprintf.c:103 #5 0x00005555557b9391 in scnprintf (buf=0x555555fe9320 <mem_loads_name> "", size=100, fmt=0x0) at ../lib/vsprintf.c:21 #6 0x00005555557b74c3 in perf_pmu__mem_events_name (i=0, pmu=0x555556832180) at util/mem-events.c:106 #7 0x00005555557b7ab9 in perf_mem_events__record_args (rec_argv=0x55555684c000, argv_nr=0x7fffffffca20) at util/mem-events.c:252 #8 0x00005555555e370d in __cmd_record (argc=3, argv=0x7fffffffd760, mem=0x7fffffffcd80) at builtin-mem.c:156 #9 0x00005555555e49c4 in cmd_mem (argc=4, argv=0x7fffffffd760) at builtin-mem.c:514 #10 0x000055555569716c in run_builtin (p=0x555555fcde80 <commands+672>, argc=8, argv=0x7fffffffd760) at perf.c:349 #11 0x0000555555697402 in handle_internal_command (argc=8, argv=0x7fffffffd760) at perf.c:402 #12 0x0000555555697560 in run_argv (argcp=0x7fffffffd59c, argv=0x7fffffffd590) at perf.c:446 #13 0x00005555556978a6 in main (argc=8, argv=0x7fffffffd760) at perf.c:562Reported-by Guilherme Amadio <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/mem-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/util/mem-events.c +1
-1@@ -86,7 +86,7 @@ static const char *perf_pmu__mem_events_name(int i, struct perf_pmu *pmu)return NULL ; e = &pmu->mem_events[i]; -if (!e) +if (!e || !e->name)return NULL ;if (i ==PERF_MEM_EVENTS__LOAD || i ==PERF_MEM_EVENTS__LOAD_STORE ) {
Namhyung Kim
maintainerRe: [PATCH 4/4] perf mem: Fix a segfault with NULL event->name
Hi Kan,
Quoted 19 lines · Kan
Quoted 6 lines · Namhyung Kim
Guilherme reported a crash in perf mem record. It's because the
perf_mem_event->namewas NULL on his machine. It should just return a NULL string when it has no format string in the name.But I'm not sure why it returns TRUE if it doesn't have
event_nameinperf_pmu__mem_events_supported().AMD doesn't have the
event_name.struct
perf_mem_eventperf_mem_events_amd[PERF_MEM_EVENTS__MAX] = {E(NULL, NULL, NULL, false, 0), E(NULL, NULL, NULL, false, 0), E("mem-ldst", "%s//", NULL, false, 0),};
Quoted 7 lines
It looks like as long as it's a "
ibs_op" PMU, the mem event is always available. The "ibs_op" check has been moved intoperf_pmu__arch_init(). So theevent_nameis empty.The "
e->tag" in theperf_pmu__mem_events_init()can help to skip the
caseE(NULL, NULL, NULL, false, 0).
So theperf_pmu__mem_events_supported()returns TRUE for the !event_name.
Ok, thanks for the explanation!
Namhyung
Quoted 9 lines · Namhyung Kim
Hello,
I found some misc updates and fixes are still remaining. Just sending out together. Please take a look!
Thanks,
Namhyung
Quoted 5 lines
Namhyung Kim (4):
perf report: Fix condition insort__sym_cmp()perf symbol: Simplify kernel module checking perf tools: Fix a compiler warning of NULL pointer perf mem: Fix a segfault with NULLevent->name
Looks good to me.
Thanks,
Kan
Quoted 7 lines
tools/perf/util/dsos.c | 3 +++ tools/perf/util/mem-events.c | 2 +- tools/perf/util/sort.c | 2 +- tools/perf/util/symbol.c | 5 +---- 4 files changed, 6 insertions(+), 6 deletions(-)
Quoted 8 lines · Namhyung Kim
I found some misc updates and fixes are still remaining. Just sending out together. Please take a look!
Thanks,
Namhyung[...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung