linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] perf tools: Add kallsyms__get_symbol_start()
@ 2023-07-25  0:19 Namhyung Kim
  2023-07-25  0:19 ` [PATCH v2 2/2] perf machine: Include data symbols in the kernel map Namhyung Kim
  2023-07-25 14:07 ` [PATCH v2 1/2] perf tools: Add kallsyms__get_symbol_start() Adrian Hunter
  0 siblings, 2 replies; 5+ messages in thread
From: Namhyung Kim @ 2023-07-25  0:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ian Rogers, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
	linux-perf-users

The kallsyms__get_symbol_start() to get any symbol address from
kallsyms.  The existing kallsyms__get_function_start() only allows text
symbols so create this to allow data symbols too.

Acked-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/event.c | 30 +++++++++++++++++++++++++++---
 tools/perf/util/event.h |  2 ++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 4cbb092e0684..923c0fb15122 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -93,8 +93,8 @@ struct process_symbol_args {
 	u64	   start;
 };
 
-static int find_symbol_cb(void *arg, const char *name, char type,
-			  u64 start)
+static int find_func_symbol_cb(void *arg, const char *name, char type,
+			       u64 start)
 {
 	struct process_symbol_args *args = arg;
 
@@ -110,12 +110,36 @@ static int find_symbol_cb(void *arg, const char *name, char type,
 	return 1;
 }
 
+static int find_any_symbol_cb(void *arg, const char *name,
+			      char type __maybe_unused, u64 start)
+{
+	struct process_symbol_args *args = arg;
+
+	if (strcmp(name, args->name))
+		return 0;
+
+	args->start = start;
+	return 1;
+}
+
 int kallsyms__get_function_start(const char *kallsyms_filename,
 				 const char *symbol_name, u64 *addr)
 {
 	struct process_symbol_args args = { .name = symbol_name, };
 
-	if (kallsyms__parse(kallsyms_filename, &args, find_symbol_cb) <= 0)
+	if (kallsyms__parse(kallsyms_filename, &args, find_func_symbol_cb) <= 0)
+		return -1;
+
+	*addr = args.start;
+	return 0;
+}
+
+int kallsyms__get_symbol_start(const char *kallsyms_filename,
+			       const char *symbol_name, u64 *addr)
+{
+	struct process_symbol_args args = { .name = symbol_name, };
+
+	if (kallsyms__parse(kallsyms_filename, &args, find_any_symbol_cb) <= 0)
 		return -1;
 
 	*addr = args.start;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index de20e01c9d72..d8bcee2e9b93 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -360,6 +360,8 @@ size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FIL
 
 int kallsyms__get_function_start(const char *kallsyms_filename,
 				 const char *symbol_name, u64 *addr);
+int kallsyms__get_symbol_start(const char *kallsyms_filename,
+			       const char *symbol_name, u64 *addr);
 
 void event_attr_init(struct perf_event_attr *attr);
 
-- 
2.41.0.487.g6d72f3e995-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] perf machine: Include data symbols in the kernel map
  2023-07-25  0:19 [PATCH v2 1/2] perf tools: Add kallsyms__get_symbol_start() Namhyung Kim
@ 2023-07-25  0:19 ` Namhyung Kim
  2023-07-25 14:08   ` Adrian Hunter
  2023-07-25 14:07 ` [PATCH v2 1/2] perf tools: Add kallsyms__get_symbol_start() Adrian Hunter
  1 sibling, 1 reply; 5+ messages in thread
From: Namhyung Kim @ 2023-07-25  0:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ian Rogers, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
	linux-perf-users

When perf record -d is used, it needs data mmaps to symbolize global data.
But it missed to collect kernel data maps so it cannot symbolize them.
Instead of having a separate map, just increase the kernel map size to
include the data section.

Probably we can have a separate kernel map for data, but the current
code assumes a single kernel map.  So it'd require more changes in other
places and looks error-prone.  I decided not to go that way for now.

Also it seems the kernel module size already includes the data section.

For example, my system has the following.

  $ grep -e _stext -e _etext -e _edata /proc/kallsyms
  ffffffff99800000 T _stext
  ffffffff9a601ac8 T _etext
  ffffffff9b446a00 D _edata

Size of the text section is (0x9a601ac8 - 0x99800000 = 0xe01ac8) and
size including data section is (0x9b446a00 - 0x99800000 = 0x1c46a00).

Before:
  $ perf record -d true

  $ perf report -D | grep MMAP | head -1
  0 0 0x460 [0x60]: PERF_RECORD_MMAP -1/0: [0xffffffff99800000(0xe01ac8) @ 0xffffffff99800000]: x [kernel.kallsyms]_text
                                                               ^^^^^^^^
                                                                 here
After:
  $ perf report -D | grep MMAP | head -1
  0 0 0x460 [0x60]: PERF_RECORD_MMAP -1/0: [0xffffffff99800000(0x1c46a00) @ 0xffffffff99800000]: x [kernel.kallsyms]_text
                                                               ^^^^^^^^^

Instead of just replacing it to _edata, try _edata first and then fall
back to _etext just in case.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/machine.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 4e62843d51b7..11de3ca8d4fa 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1216,7 +1216,9 @@ static int machine__get_running_kernel_start(struct machine *machine,
 
 	*start = addr;
 
-	err = kallsyms__get_function_start(filename, "_etext", &addr);
+	err = kallsyms__get_symbol_start(filename, "_edata", &addr);
+	if (err)
+		err = kallsyms__get_function_start(filename, "_etext", &addr);
 	if (!err)
 		*end = addr;
 
-- 
2.41.0.487.g6d72f3e995-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] perf tools: Add kallsyms__get_symbol_start()
  2023-07-25  0:19 [PATCH v2 1/2] perf tools: Add kallsyms__get_symbol_start() Namhyung Kim
  2023-07-25  0:19 ` [PATCH v2 2/2] perf machine: Include data symbols in the kernel map Namhyung Kim
@ 2023-07-25 14:07 ` Adrian Hunter
  2023-07-26 19:26   ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 5+ messages in thread
From: Adrian Hunter @ 2023-07-25 14:07 UTC (permalink / raw)
  To: Namhyung Kim, Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users

On 25/07/23 03:19, Namhyung Kim wrote:
> The kallsyms__get_symbol_start() to get any symbol address from
> kallsyms.  The existing kallsyms__get_function_start() only allows text
> symbols so create this to allow data symbols too.
> 
> Acked-by: Ian Rogers <irogers@google.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/util/event.c | 30 +++++++++++++++++++++++++++---
>  tools/perf/util/event.h |  2 ++
>  2 files changed, 29 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> index 4cbb092e0684..923c0fb15122 100644
> --- a/tools/perf/util/event.c
> +++ b/tools/perf/util/event.c
> @@ -93,8 +93,8 @@ struct process_symbol_args {
>  	u64	   start;
>  };
>  
> -static int find_symbol_cb(void *arg, const char *name, char type,
> -			  u64 start)
> +static int find_func_symbol_cb(void *arg, const char *name, char type,
> +			       u64 start)
>  {
>  	struct process_symbol_args *args = arg;
>  
> @@ -110,12 +110,36 @@ static int find_symbol_cb(void *arg, const char *name, char type,
>  	return 1;
>  }
>  
> +static int find_any_symbol_cb(void *arg, const char *name,
> +			      char type __maybe_unused, u64 start)
> +{
> +	struct process_symbol_args *args = arg;
> +
> +	if (strcmp(name, args->name))
> +		return 0;
> +
> +	args->start = start;
> +	return 1;
> +}
> +
>  int kallsyms__get_function_start(const char *kallsyms_filename,
>  				 const char *symbol_name, u64 *addr)
>  {
>  	struct process_symbol_args args = { .name = symbol_name, };
>  
> -	if (kallsyms__parse(kallsyms_filename, &args, find_symbol_cb) <= 0)
> +	if (kallsyms__parse(kallsyms_filename, &args, find_func_symbol_cb) <= 0)
> +		return -1;
> +
> +	*addr = args.start;
> +	return 0;
> +}
> +
> +int kallsyms__get_symbol_start(const char *kallsyms_filename,
> +			       const char *symbol_name, u64 *addr)
> +{
> +	struct process_symbol_args args = { .name = symbol_name, };
> +
> +	if (kallsyms__parse(kallsyms_filename, &args, find_any_symbol_cb) <= 0)
>  		return -1;
>  
>  	*addr = args.start;
> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
> index de20e01c9d72..d8bcee2e9b93 100644
> --- a/tools/perf/util/event.h
> +++ b/tools/perf/util/event.h
> @@ -360,6 +360,8 @@ size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FIL
>  
>  int kallsyms__get_function_start(const char *kallsyms_filename,
>  				 const char *symbol_name, u64 *addr);
> +int kallsyms__get_symbol_start(const char *kallsyms_filename,
> +			       const char *symbol_name, u64 *addr);
>  
>  void event_attr_init(struct perf_event_attr *attr);
>  


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] perf machine: Include data symbols in the kernel map
  2023-07-25  0:19 ` [PATCH v2 2/2] perf machine: Include data symbols in the kernel map Namhyung Kim
@ 2023-07-25 14:08   ` Adrian Hunter
  0 siblings, 0 replies; 5+ messages in thread
From: Adrian Hunter @ 2023-07-25 14:08 UTC (permalink / raw)
  To: Namhyung Kim, Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users

On 25/07/23 03:19, Namhyung Kim wrote:
> When perf record -d is used, it needs data mmaps to symbolize global data.
> But it missed to collect kernel data maps so it cannot symbolize them.
> Instead of having a separate map, just increase the kernel map size to
> include the data section.
> 
> Probably we can have a separate kernel map for data, but the current
> code assumes a single kernel map.  So it'd require more changes in other
> places and looks error-prone.  I decided not to go that way for now.
> 
> Also it seems the kernel module size already includes the data section.
> 
> For example, my system has the following.
> 
>   $ grep -e _stext -e _etext -e _edata /proc/kallsyms
>   ffffffff99800000 T _stext
>   ffffffff9a601ac8 T _etext
>   ffffffff9b446a00 D _edata
> 
> Size of the text section is (0x9a601ac8 - 0x99800000 = 0xe01ac8) and
> size including data section is (0x9b446a00 - 0x99800000 = 0x1c46a00).
> 
> Before:
>   $ perf record -d true
> 
>   $ perf report -D | grep MMAP | head -1
>   0 0 0x460 [0x60]: PERF_RECORD_MMAP -1/0: [0xffffffff99800000(0xe01ac8) @ 0xffffffff99800000]: x [kernel.kallsyms]_text
>                                                                ^^^^^^^^
>                                                                  here
> After:
>   $ perf report -D | grep MMAP | head -1
>   0 0 0x460 [0x60]: PERF_RECORD_MMAP -1/0: [0xffffffff99800000(0x1c46a00) @ 0xffffffff99800000]: x [kernel.kallsyms]_text
>                                                                ^^^^^^^^^
> 
> Instead of just replacing it to _edata, try _edata first and then fall
> back to _etext just in case.
> 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/util/machine.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 4e62843d51b7..11de3ca8d4fa 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -1216,7 +1216,9 @@ static int machine__get_running_kernel_start(struct machine *machine,
>  
>  	*start = addr;
>  
> -	err = kallsyms__get_function_start(filename, "_etext", &addr);
> +	err = kallsyms__get_symbol_start(filename, "_edata", &addr);
> +	if (err)
> +		err = kallsyms__get_function_start(filename, "_etext", &addr);
>  	if (!err)
>  		*end = addr;
>  


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] perf tools: Add kallsyms__get_symbol_start()
  2023-07-25 14:07 ` [PATCH v2 1/2] perf tools: Add kallsyms__get_symbol_start() Adrian Hunter
@ 2023-07-26 19:26   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-26 19:26 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Namhyung Kim, Jiri Olsa, Ian Rogers, Peter Zijlstra, Ingo Molnar,
	LKML, linux-perf-users

Em Tue, Jul 25, 2023 at 05:07:40PM +0300, Adrian Hunter escreveu:
> On 25/07/23 03:19, Namhyung Kim wrote:
> > The kallsyms__get_symbol_start() to get any symbol address from
> > kallsyms.  The existing kallsyms__get_function_start() only allows text
> > symbols so create this to allow data symbols too.
> > 
> > Acked-by: Ian Rogers <irogers@google.com>
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> 
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>

Thanks, applied both patches.

- Arnaldo
 
> > ---
> >  tools/perf/util/event.c | 30 +++++++++++++++++++++++++++---
> >  tools/perf/util/event.h |  2 ++
> >  2 files changed, 29 insertions(+), 3 deletions(-)
> > 
> > diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> > index 4cbb092e0684..923c0fb15122 100644
> > --- a/tools/perf/util/event.c
> > +++ b/tools/perf/util/event.c
> > @@ -93,8 +93,8 @@ struct process_symbol_args {
> >  	u64	   start;
> >  };
> >  
> > -static int find_symbol_cb(void *arg, const char *name, char type,
> > -			  u64 start)
> > +static int find_func_symbol_cb(void *arg, const char *name, char type,
> > +			       u64 start)
> >  {
> >  	struct process_symbol_args *args = arg;
> >  
> > @@ -110,12 +110,36 @@ static int find_symbol_cb(void *arg, const char *name, char type,
> >  	return 1;
> >  }
> >  
> > +static int find_any_symbol_cb(void *arg, const char *name,
> > +			      char type __maybe_unused, u64 start)
> > +{
> > +	struct process_symbol_args *args = arg;
> > +
> > +	if (strcmp(name, args->name))
> > +		return 0;
> > +
> > +	args->start = start;
> > +	return 1;
> > +}
> > +
> >  int kallsyms__get_function_start(const char *kallsyms_filename,
> >  				 const char *symbol_name, u64 *addr)
> >  {
> >  	struct process_symbol_args args = { .name = symbol_name, };
> >  
> > -	if (kallsyms__parse(kallsyms_filename, &args, find_symbol_cb) <= 0)
> > +	if (kallsyms__parse(kallsyms_filename, &args, find_func_symbol_cb) <= 0)
> > +		return -1;
> > +
> > +	*addr = args.start;
> > +	return 0;
> > +}
> > +
> > +int kallsyms__get_symbol_start(const char *kallsyms_filename,
> > +			       const char *symbol_name, u64 *addr)
> > +{
> > +	struct process_symbol_args args = { .name = symbol_name, };
> > +
> > +	if (kallsyms__parse(kallsyms_filename, &args, find_any_symbol_cb) <= 0)
> >  		return -1;
> >  
> >  	*addr = args.start;
> > diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
> > index de20e01c9d72..d8bcee2e9b93 100644
> > --- a/tools/perf/util/event.h
> > +++ b/tools/perf/util/event.h
> > @@ -360,6 +360,8 @@ size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FIL
> >  
> >  int kallsyms__get_function_start(const char *kallsyms_filename,
> >  				 const char *symbol_name, u64 *addr);
> > +int kallsyms__get_symbol_start(const char *kallsyms_filename,
> > +			       const char *symbol_name, u64 *addr);
> >  
> >  void event_attr_init(struct perf_event_attr *attr);
> >  
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-26 19:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-25  0:19 [PATCH v2 1/2] perf tools: Add kallsyms__get_symbol_start() Namhyung Kim
2023-07-25  0:19 ` [PATCH v2 2/2] perf machine: Include data symbols in the kernel map Namhyung Kim
2023-07-25 14:08   ` Adrian Hunter
2023-07-25 14:07 ` [PATCH v2 1/2] perf tools: Add kallsyms__get_symbol_start() Adrian Hunter
2023-07-26 19:26   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).