* [PATCH] perf callchain: Return directly when use '--call-graph dwarf' under !CONFIG_DWARF
@ 2020-12-14 12:56 Tiezhu Yang
2020-12-14 13:39 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 3+ messages in thread
From: Tiezhu Yang @ 2020-12-14 12:56 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim
Cc: linux-kernel, Xuefeng Li
DWARF register mappings have not been defined for some architectures,
at least for mips, so we can print an error message and then return
directly when use '--call-graph dwarf'.
E.g. without this patch:
[root@linux perf]# ./perf record --call-graph dwarf cd
Error:
The sys_perf_event_open() syscall returned with 89 (Function not implemented) for event (cycles).
/bin/dmesg | grep -i perf may provide additional information.
With this patch:
[root@linux perf]# ./perf record --call-graph dwarf cd
DWARF is not supported for architecture mips64
Usage: perf record [<options>] [<command>]
or: perf record [<options>] -- <command> [<options>]
--call-graph <record_mode[,record_size]>
setup and enables call-graph (stack chain/backtrace):
record_mode: call graph recording mode (fp|dwarf|lbr)
record_size: if record_mode is 'dwarf', max size of stack recording (<bytes>)
default: 8192 (bytes)
Default: fp
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
tools/perf/util/callchain.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 1b60985..a8cf456 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -18,6 +18,7 @@
#include <math.h>
#include <linux/string.h>
#include <linux/zalloc.h>
+#include <sys/utsname.h>
#include "asm/bug.h"
@@ -278,6 +279,16 @@ int parse_callchain_record(const char *arg, struct callchain_param *param)
} else if (!strncmp(name, "dwarf", sizeof("dwarf"))) {
const unsigned long default_stack_dump_size = 8192;
+ if (system("grep -q 'CONFIG_DWARF=y' .config-detected") != 0) {
+ struct utsname uts;
+
+ ret = uname(&uts);
+ pr_err("DWARF is not supported for architecture %s\n",
+ ret ? "unknown" : uts.machine);
+
+ return -ENOTSUP;
+ }
+
ret = 0;
param->record_mode = CALLCHAIN_DWARF;
param->dump_size = default_stack_dump_size;
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] perf callchain: Return directly when use '--call-graph dwarf' under !CONFIG_DWARF 2020-12-14 12:56 [PATCH] perf callchain: Return directly when use '--call-graph dwarf' under !CONFIG_DWARF Tiezhu Yang @ 2020-12-14 13:39 ` Arnaldo Carvalho de Melo 2020-12-15 1:25 ` Tiezhu Yang 0 siblings, 1 reply; 3+ messages in thread From: Arnaldo Carvalho de Melo @ 2020-12-14 13:39 UTC (permalink / raw) To: Tiezhu Yang Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim, linux-kernel, Xuefeng Li Em Mon, Dec 14, 2020 at 08:56:55PM +0800, Tiezhu Yang escreveu: > DWARF register mappings have not been defined for some architectures, > at least for mips, so we can print an error message and then return > directly when use '--call-graph dwarf'. > > E.g. without this patch: > > [root@linux perf]# ./perf record --call-graph dwarf cd > Error: > The sys_perf_event_open() syscall returned with 89 (Function not implemented) for event (cycles). > /bin/dmesg | grep -i perf may provide additional information. > > With this patch: > > [root@linux perf]# ./perf record --call-graph dwarf cd > DWARF is not supported for architecture mips64 Good improvement on the message! But that .config-detected file isn't available at run time, take a look if this isn't a better alternative: diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 1b60985690bba313..125178fd17482513 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -276,6 +276,7 @@ int parse_callchain_record(const char *arg, struct callchain_param *param) /* Dwarf style */ } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { +#ifdef HAVE_DWARF_SUPPORT const unsigned long default_stack_dump_size = 8192; ret = 0; @@ -290,6 +291,15 @@ int parse_callchain_record(const char *arg, struct callchain_param *param) ret = get_stack_size(tok, &size); param->dump_size = size; } +#else + struct utsname uts; + + ret = uname(&uts); + pr_err("DWARF is not supported for architecture %s\n", + ret ? "unknown" : uts.machine); + + return -ENOTSUP; +#endif } else if (!strncmp(name, "lbr", sizeof("lbr"))) { if (!strtok_r(NULL, ",", &saveptr)) { param->record_mode = CALLCHAIN_LBR; > Usage: perf record [<options>] [<command>] > or: perf record [<options>] -- <command> [<options>] > > --call-graph <record_mode[,record_size]> > setup and enables call-graph (stack chain/backtrace): > > record_mode: call graph recording mode (fp|dwarf|lbr) > record_size: if record_mode is 'dwarf', max size of stack recording (<bytes>) > default: 8192 (bytes) > > Default: fp > > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > --- > tools/perf/util/callchain.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c > index 1b60985..a8cf456 100644 > --- a/tools/perf/util/callchain.c > +++ b/tools/perf/util/callchain.c > @@ -18,6 +18,7 @@ > #include <math.h> > #include <linux/string.h> > #include <linux/zalloc.h> > +#include <sys/utsname.h> > > #include "asm/bug.h" > > @@ -278,6 +279,16 @@ int parse_callchain_record(const char *arg, struct callchain_param *param) > } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { > const unsigned long default_stack_dump_size = 8192; > > + if (system("grep -q 'CONFIG_DWARF=y' .config-detected") != 0) { > + struct utsname uts; > + > + ret = uname(&uts); > + pr_err("DWARF is not supported for architecture %s\n", > + ret ? "unknown" : uts.machine); > + > + return -ENOTSUP; > + } > + > ret = 0; > param->record_mode = CALLCHAIN_DWARF; > param->dump_size = default_stack_dump_size; > -- > 2.1.0 > -- - Arnaldo ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf callchain: Return directly when use '--call-graph dwarf' under !CONFIG_DWARF 2020-12-14 13:39 ` Arnaldo Carvalho de Melo @ 2020-12-15 1:25 ` Tiezhu Yang 0 siblings, 0 replies; 3+ messages in thread From: Tiezhu Yang @ 2020-12-15 1:25 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim, linux-kernel, Xuefeng Li On 12/14/2020 09:39 PM, Arnaldo Carvalho de Melo wrote: > Em Mon, Dec 14, 2020 at 08:56:55PM +0800, Tiezhu Yang escreveu: >> DWARF register mappings have not been defined for some architectures, >> at least for mips, so we can print an error message and then return >> directly when use '--call-graph dwarf'. >> >> E.g. without this patch: >> >> [root@linux perf]# ./perf record --call-graph dwarf cd >> Error: >> The sys_perf_event_open() syscall returned with 89 (Function not implemented) for event (cycles). >> /bin/dmesg | grep -i perf may provide additional information. >> >> With this patch: >> >> [root@linux perf]# ./perf record --call-graph dwarf cd >> DWARF is not supported for architecture mips64 > Good improvement on the message! But that .config-detected file isn't > available at run time, take a look if this isn't a better alternative: Hi Arnaldo, Thank you very much, the following code with #ifdef HAVE_DWARF_SUPPORT looks good and it works well on the x86 and mips arch. So I will send a v2 patch as soon as possible. Thanks, Tiezhu > > diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c > index 1b60985690bba313..125178fd17482513 100644 > --- a/tools/perf/util/callchain.c > +++ b/tools/perf/util/callchain.c > @@ -276,6 +276,7 @@ int parse_callchain_record(const char *arg, struct callchain_param *param) > > /* Dwarf style */ > } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { > +#ifdef HAVE_DWARF_SUPPORT > const unsigned long default_stack_dump_size = 8192; > > ret = 0; > @@ -290,6 +291,15 @@ int parse_callchain_record(const char *arg, struct callchain_param *param) > ret = get_stack_size(tok, &size); > param->dump_size = size; > } > +#else > + struct utsname uts; > + > + ret = uname(&uts); > + pr_err("DWARF is not supported for architecture %s\n", > + ret ? "unknown" : uts.machine); > + > + return -ENOTSUP; > +#endif > } else if (!strncmp(name, "lbr", sizeof("lbr"))) { > if (!strtok_r(NULL, ",", &saveptr)) { > param->record_mode = CALLCHAIN_LBR; > > >> Usage: perf record [<options>] [<command>] >> or: perf record [<options>] -- <command> [<options>] >> >> --call-graph <record_mode[,record_size]> >> setup and enables call-graph (stack chain/backtrace): >> >> record_mode: call graph recording mode (fp|dwarf|lbr) >> record_size: if record_mode is 'dwarf', max size of stack recording (<bytes>) >> default: 8192 (bytes) >> >> Default: fp >> >> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> >> --- >> tools/perf/util/callchain.c | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c >> index 1b60985..a8cf456 100644 >> --- a/tools/perf/util/callchain.c >> +++ b/tools/perf/util/callchain.c >> @@ -18,6 +18,7 @@ >> #include <math.h> >> #include <linux/string.h> >> #include <linux/zalloc.h> >> +#include <sys/utsname.h> >> >> #include "asm/bug.h" >> >> @@ -278,6 +279,16 @@ int parse_callchain_record(const char *arg, struct callchain_param *param) >> } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { >> const unsigned long default_stack_dump_size = 8192; >> >> + if (system("grep -q 'CONFIG_DWARF=y' .config-detected") != 0) { >> + struct utsname uts; >> + >> + ret = uname(&uts); >> + pr_err("DWARF is not supported for architecture %s\n", >> + ret ? "unknown" : uts.machine); >> + >> + return -ENOTSUP; >> + } >> + >> ret = 0; >> param->record_mode = CALLCHAIN_DWARF; >> param->dump_size = default_stack_dump_size; >> -- >> 2.1.0 >> ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-15 1:26 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-12-14 12:56 [PATCH] perf callchain: Return directly when use '--call-graph dwarf' under !CONFIG_DWARF Tiezhu Yang 2020-12-14 13:39 ` Arnaldo Carvalho de Melo 2020-12-15 1:25 ` Tiezhu Yang
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.