perf machine: Add machine->has_data_mmap field
Namhyung Kim
maintainerPATCH 1/3 perf machine: Add machine->has_data_mmap field
So that it can indicate the it needs to collect data mappings. This is needed especially for kernel maps.
At first, I just wanted to add it to struct machines only and to use the machine->machines to check the value. But it turned out that some of machine didn't belong to any machines (eg. some test codes), so I just copied the value to individual struct machine.
--- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/tests/vmlinux-kallsyms.c | 4 ++-- tools/perf/util/machine.c | 12 +++++++----- tools/perf/util/machine.h | 10 ++++++++-- tools/perf/util/session.c | 4 ++-- tools/perf/util/session.h | 4 ++-- 7 files changed, 23 insertions(+), 15 deletions(-)
tools/perf/builtin-inject.c +1 -1
@@ -2325,7 +2325,7 @@ int cmd_inject(int argc, const char **argv) } inject.session =__perf_session__new (&data, repipe, -output_fd (&inject), +output_fd (&inject), false, &inject.tool);if (IS_ERR (inject.session)) { ret =PTR_ERR (inject.session);
tools/perf/builtin-record.c +1 -1
@@ -2373,7 +2373,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)signal (SIGUSR2 ,SIG_IGN ); } - session =perf_session__new (data, tool); + session =__perf_session__new (data, false,-1 , rec->opts.sample_address, tool);if (IS_ERR (session)) {pr_err ("Perf session creation failed.\n" );return PTR_ERR (session);
tools/perf/tests/vmlinux-kallsyms.c +2 -2
@@ -131,8 +131,8 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused* Init the machines that will hold kernel, modules obtained from * both vmlinux + .ko files and from /proc/kallsyms split by modules. */ -machine__init (&kallsyms,"" ,HOST_KERNEL_ID ); -machine__init (&vmlinux,"" ,HOST_KERNEL_ID ); +machine__init (&kallsyms,"" ,HOST_KERNEL_ID , false); +machine__init (&vmlinux,"" ,HOST_KERNEL_ID , false); maps =machine__kernel_maps (&vmlinux);
tools/perf/util/machine.c +7 -5
@@ -110,7 +110,7 @@ static void thread__set_guest_comm(struct thread *thread, pid_t pid)thread__set_comm (thread, comm,0 ); } -int machine__init (struct machine *machine,const char *root_dir,pid_t pid) +int machine__init (struct machine *machine,const char *root_dir,pid_t pid,bool has_data_mmap) {int err = -ENOMEM ;
@@ -128,6 +128,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) machine->env =NULL ; machine->pid = pid; + machine->has_data_mmap = has_data_mmap; machine->id_hdr_size =0 ; machine->kptr_restrict_warned = false;
@@ -170,7 +171,7 @@ struct machine *machine__new_host(void)struct machine *machine =malloc (sizeof (*machine));if (machine !=NULL ) { -machine__init (machine,"" ,HOST_KERNEL_ID ); +machine__init (machine,"" ,HOST_KERNEL_ID , false);if (machine__create_kernel_maps (machine) <0 ) goto out_delete;
@@ -272,10 +273,11 @@ void machine__delete(struct machine *machine) } } -void machines__init (struct machines *machines) +void __machines__init (struct machines *machines,bool have_data_mmap) { -machine__init (&machines->host,"" ,HOST_KERNEL_ID ); +machine__init (&machines->host,"" ,HOST_KERNEL_ID , have_data_mmap); machines->guests =RB_ROOT_CACHED ; + machines->have_data_mmaps = have_data_mmap; }void machines__exit (struct machines *machines)
@@ -295,7 +297,7 @@ struct machine *machines__add(struct machines *machines, pid_t pid,if (machine ==NULL )return NULL ; -if (machine__init (machine, root_dir, pid) !=0 ) { +if (machine__init (machine, root_dir, pid, machines->have_data_mmaps) !=0 ) {free (machine);return NULL ; }
tools/perf/util/machine.h +8 -2
@@ -46,6 +46,7 @@ struct machine {bool comm_exec;bool kptr_restrict_warned;bool single_address_space; +bool has_data_mmap;char *root_dir;char *mmap_name;char *kallsyms_filename;
@@ -160,9 +161,14 @@ typedef void (*machine__process_t)(struct machine *machine, void *data);struct machines {struct machine host;struct rb_root_cached guests; +bool have_data_mmaps; }; -void machines__init (struct machines *machines); +void __machines__init (struct machines *machines,bool data_mmap); +static inline void machines__init (struct machines *machines) +{ +__machines__init (machines, false); +}void machines__exit (struct machines *machines); void machines__process_guests(struct machines *machines,
@@ -181,7 +187,7 @@ void machines__set_comm_exec(struct machines *machines, bool comm_exec);struct machine *machine__new_host (void );struct machine *machine__new_kallsyms (void ); -int machine__init (struct machine *machine,const char *root_dir,pid_t pid); +int machine__init (struct machine *machine,const char *root_dir,pid_t pid,bool has_data_mmap);void machine__exit (struct machine *machine);void machine__delete_threads (struct machine *machine);void machine__delete (struct machine *machine);
tools/perf/util/session.c +2 -2
@@ -191,7 +191,7 @@ static int ordered_events__deliver_event(struct ordered_events *oe, }struct perf_session *__perf_session__new (struct perf_data *data, -bool repipe,int repipe_fd, +bool repipe,int repipe_fd,bool data_mmap,struct perf_tool *tool) {int ret = -ENOMEM ;
@@ -205,7 +205,7 @@ struct perf_session *__perf_session__new(struct perf_data *data, session->decomp_data.zstd_decomp = &session->zstd_data; session->active_decomp = &session->decomp_data;INIT_LIST_HEAD (&session->auxtrace_index); -machines__init (&session->machines); +__machines__init (&session->machines, data_mmap);ordered_events__init (&session->ordered_events, ordered_events__deliver_event,NULL );
tools/perf/util/session.h +2 -2
@@ -64,13 +64,13 @@ struct decomp {struct perf_tool ;struct perf_session *__perf_session__new (struct perf_data *data, -bool repipe,int repipe_fd, +bool repipe,int repipe_fd,bool data_mmap,struct perf_tool *tool);static inline struct perf_session *perf_session__new (struct perf_data *data,struct perf_tool *tool) { -return __perf_session__new (data, false,-1 , tool); +return __perf_session__new (data, false,-1 , false, tool); }void perf_session__delete (struct perf_session *session);
Signature · 1 line
2.41.0.185.g7c58973941-goog
Namhyung Kim
maintainerPATCH 2/3 perf tools: Add kallsyms__get_symbol_start()
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.
--- tools/perf/util/event.c | 30 +++++++++++++++++++++++++++--- tools/perf/util/event.h | 2 ++ 2 files changed, 29 insertions(+), 3 deletions(-)
tools/perf/util/event.c +27 -3
@@ -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;
tools/perf/util/event.h +2 -0
@@ -360,6 +360,8 @@ size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FILint 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);
Signature · 1 line
2.41.0.185.g7c58973941-goog
Re: [PATCH 2/3] perf tools: Add kallsyms__get_symbol_start()
Quoted 6 lines · Namhyung Kim
The
kallsyms__get_symbol_start()to get any symbol address from kallsyms. The existingkallsyms__get_function_start()only allows text symbols so create this to allow data symbols too.Signed-off-by Namhyung Kim <[email protected]>
Thanks,
Ian
Quoted 74 lines
--- tools/perf/util/event.c | 30 +++++++++++++++++++++++++++--- tools/perf/util/event.h | 2 ++ 2 files changed, 29 insertions(+), 3 deletions(-)tools/perf/util/event.c +27
-3@@ -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;tools/perf/util/event.h +2
-1@@ -360,6 +360,8 @@ size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FILint 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.185.g7c58973941-goog
Namhyung Kim
maintainerPATCH 3/3 perf machine: Include data symbols in the kernel map
In reply to Namhyung KimWhen 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 of the 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
^^^^^^^^^--- tools/perf/util/machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/machine.c +4 -1
@@ -1218,7 +1218,10 @@ static int machine__get_running_kernel_start(struct machine *machine, *start = addr; - err =kallsyms__get_function_start (filename,"_etext" , &addr); +if (machine->has_data_mmap) + err =kallsyms__get_symbol_start (filename,"_edata" , &addr); +else + err =kallsyms__get_function_start (filename,"_etext" , &addr);if (!err) *end = addr;
Signature · 1 line
2.41.0.185.g7c58973941-goog
Re: [PATCH 3/3] perf machine: Include data symbols in the kernel map
Quoted 22 lines · Namhyung Kim
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 _edataSize of the text section is (
0x9a601ac8-0x99800000=0xe01ac8) and size of the data section is (0x9b446a00-0x99800000=0x1c46a00).
Quoted 7 lines
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
nit: should the ^^^ be under 0xe01ac8?
Quoted 4 lines
After:
$ perf report -D | grep MMAP | head -1 0 0 0x460 [0x60]: PERF_RECORD_MMAP -1/0: [0xffffffff99800000(0x1c46a00) @ 0xffffffff99800000]: x [kernel.kallsyms]_text ^^^^^^^^^
nit: and here under 0x1c46a00 ?
Quoted 2 lines
Signed-off-by Namhyung Kim <[email protected]>
Thanks,
Ian
Quoted 23 lines
--- tools/perf/util/machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/machine.c +4
-2@@ -1218,7 +1218,10 @@ static int machine__get_running_kernel_start(struct machine *machine, *start = addr; - err =kallsyms__get_function_start (filename,"_etext" , &addr); +if (machine->has_data_mmap) + err =kallsyms__get_symbol_start (filename,"_edata" , &addr); +else + err =kallsyms__get_function_start (filename,"_etext" , &addr);if (!err) *end = addr; --2.41.0.185.g7c58973941-goog
Adrian Hunter
reviewerRe: [PATCH 3/3] perf machine: Include data symbols in the kernel map
In reply to Namhyung KimQuoted 43 lines · Namhyung Kim
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 _edataSize of the text section is (
0x9a601ac8-0x99800000=0xe01ac8) and size of the 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 ^^^^^^^^^Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/machine.c +0
-0
tools/perf/util/machine.c static int machine__get_running_kernel_start(struct machine *machine, · line 1224
Quoted 8 lines
tools/perf/util/machine.c +4
-1@@ -1218,7 +1218,10 @@ static int machine__get_running_kernel_start(struct machine *machine, *start = addr; - err =kallsyms__get_function_start (filename,"_etext" , &addr); +if (machine->has_data_mmap) + err =kallsyms__get_symbol_start (filename,"_edata" , &addr); +else + err =kallsyms__get_function_start (filename,"_etext" , &addr);
What is the downside of just extending it unconditionally?
Quoted 3 lines
tools/perf/util/machine.c +0
-0if (!err) *end = addr;
Namhyung Kim
maintainerRe: [PATCH 3/3] perf machine: Include data symbols in the kernel map
Hi Adrian,
Quoted 48 lines · Adrian Hunter
Quoted 46 lines · Namhyung Kim
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 _edataSize of the text section is (
0x9a601ac8-0x99800000=0xe01ac8) and size of the 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 ^^^^^^^^^Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/machine.c +0
-0@@ -1218,7 +1218,10 @@ static int machine__get_running_kernel_start(struct machine *machine, *start = addr;
Quoted 7 lines
tools/perf/util/machine.c static int machine__get_running_kernel_start(struct machine *machine, · line 1224
Quoted 5 lines
tools/perf/util/machine.c +4
-1- err =kallsyms__get_function_start (filename,"_etext" , &addr); +if (machine->has_data_mmap) + err =kallsyms__get_symbol_start (filename,"_edata" , &addr); +else + err =kallsyms__get_function_start (filename,"_etext" , &addr);What is the downside of just extending it unconditionally?
I don't know.. maybe some people would argue it needs the proper protection bits other than 'x' but this patch also breaks it. But as I said, I'm not sure if we really want to change that now.
That said, we can make it unconditional. :)
Thanks,
Namhyung
Quoted 5 lines
Quoted 4 lines
tools/perf/util/machine.c +0
-0if (!err) *end = addr;
Adrian Hunter
reviewerRe: [PATCH 3/3] perf machine: Include data symbols in the kernel map
Quoted 59 lines · Namhyung Kim
Hi Adrian,
Quoted 48 lines · Adrian Hunter
Quoted 46 lines · Namhyung Kim
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 _edataSize of the text section is (
0x9a601ac8-0x99800000=0xe01ac8) and size of the 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 ^^^^^^^^^Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/machine.c +0
-0@@ -1218,7 +1218,10 @@ static int machine__get_running_kernel_start(struct machine *machine, *start = addr;Quoted 7 lines
tools/perf/util/machine.c static int machine__get_running_kernel_start(struct machine *machine, · line 1224
Quoted 5 lines
tools/perf/util/machine.c +4
-1- err =kallsyms__get_function_start (filename,"_etext" , &addr); +if (machine->has_data_mmap) + err =kallsyms__get_symbol_start (filename,"_edata" , &addr); +else + err =kallsyms__get_function_start (filename,"_etext" , &addr);What is the downside of just extending it unconditionally?
Quoted 5 lines
I don't know.. maybe some people would argue it needs the proper protection bits other than 'x' but this patch also breaks it. But as I said, I'm not sure if we really want to change that now.
That said, we can make it unconditional. :)
Might as well to start with. Will need a big comment.
Also do we know if all arch's do it like that? Perhaps need to fallback to _etext if _edata is not found?
Quoted 9 lines
Thanks,
NamhyungQuoted 5 lines
Quoted 4 lines
tools/perf/util/machine.c +0
-0if (!err) *end = addr;
Quoted 10 lines · Namhyung Kim
So that it can indicate the it needs to collect data mappings. This is needed especially for kernel maps.
At first, I just wanted to add it to struct machines only and to use the
machine->machinesto check the value. But it turned out that some of machine didn't belong to any machines (eg. some test codes), so I just copied the value to individual struct machine.Signed-off-by Namhyung Kim <[email protected]>
Quoted 73 lines
--- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/tests/vmlinux-kallsyms.c | 4 ++-- tools/perf/util/machine.c | 12 +++++++----- tools/perf/util/machine.h | 10 ++++++++-- tools/perf/util/session.c | 4 ++-- tools/perf/util/session.h | 4 ++-- 7 files changed, 23 insertions(+), 15 deletions(-)tools/perf/builtin-inject.c +1
-1@@ -2325,7 +2325,7 @@ int cmd_inject(int argc, const char **argv) } inject.session =__perf_session__new (&data, repipe, -output_fd (&inject), +output_fd (&inject), false, &inject.tool);if (IS_ERR (inject.session)) { ret =PTR_ERR (inject.session);tools/perf/builtin-record.c +1
-1@@ -2373,7 +2373,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)signal (SIGUSR2 ,SIG_IGN ); } - session =perf_session__new (data, tool); + session =__perf_session__new (data, false,-1 , rec->opts.sample_address, tool);if (IS_ERR (session)) {pr_err ("Perf session creation failed.\n" );return PTR_ERR (session);tools/perf/tests/vmlinux-kallsyms.c +2
-2@@ -131,8 +131,8 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused* Init the machines that will hold kernel, modules obtained from * both vmlinux + .ko files and from /proc/kallsyms split by modules. */ -machine__init (&kallsyms,"" ,HOST_KERNEL_ID ); -machine__init (&vmlinux,"" ,HOST_KERNEL_ID ); +machine__init (&kallsyms,"" ,HOST_KERNEL_ID , false); +machine__init (&vmlinux,"" ,HOST_KERNEL_ID , false); maps =machine__kernel_maps (&vmlinux);tools/perf/util/machine.c +2
-1@@ -110,7 +110,7 @@ static void thread__set_guest_comm(struct thread *thread, pid_t pid)thread__set_comm (thread, comm,0 ); } -int machine__init (struct machine *machine,const char *root_dir,pid_t pid) +int machine__init (struct machine *machine,const char *root_dir,pid_t pid,bool has_data_mmap) {int err = -ENOMEM ;@@ -128,6 +128,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) machine->env =NULL ; machine->pid = pid; + machine->has_data_mmap = has_data_mmap; machine->id_hdr_size =0 ; machine->kptr_restrict_warned = false;
tools/perf/util/machine.c struct machine *machine__new_host(void) · line 174
Quoted 5 lines
tools/perf/util/machine.c +1
-1@@ -170,7 +171,7 @@ struct machine *machine__new_host(void)struct machine *machine =malloc (sizeof (*machine));if (machine !=NULL ) { -machine__init (machine,"" ,HOST_KERNEL_ID ); +machine__init (machine,"" ,HOST_KERNEL_ID , false);
nit: when passing constants it can be nice to name the parameter, so here "/*data_mmap=*/false". There are some checkers based on this like:
https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html
Thanks,
Ian
Quoted 108 lines
tools/perf/util/machine.c +4
-3if (machine__create_kernel_maps (machine) <0 ) goto out_delete;@@ -272,10 +273,11 @@ void machine__delete(struct machine *machine) } } -void machines__init (struct machines *machines) +void __machines__init (struct machines *machines,bool have_data_mmap) { -machine__init (&machines->host,"" ,HOST_KERNEL_ID ); +machine__init (&machines->host,"" ,HOST_KERNEL_ID , have_data_mmap); machines->guests =RB_ROOT_CACHED ; + machines->have_data_mmaps = have_data_mmap; }void machines__exit (struct machines *machines)@@ -295,7 +297,7 @@ struct machine *machines__add(struct machines *machines, pid_t pid,if (machine ==NULL )return NULL ; -if (machine__init (machine, root_dir, pid) !=0 ) { +if (machine__init (machine, root_dir, pid, machines->have_data_mmaps) !=0 ) {free (machine);return NULL ; }tools/perf/util/machine.h +8
-2@@ -46,6 +46,7 @@ struct machine {bool comm_exec;bool kptr_restrict_warned;bool single_address_space; +bool has_data_mmap;char *root_dir;char *mmap_name;char *kallsyms_filename;@@ -160,9 +161,14 @@ typedef void (*machine__process_t)(struct machine *machine, void *data);struct machines {struct machine host;struct rb_root_cached guests; +bool have_data_mmaps; }; -void machines__init (struct machines *machines); +void __machines__init (struct machines *machines,bool data_mmap); +static inline void machines__init (struct machines *machines) +{ +__machines__init (machines, false); +}void machines__exit (struct machines *machines); void machines__process_guests(struct machines *machines,@@ -181,7 +187,7 @@ void machines__set_comm_exec(struct machines *machines, bool comm_exec);struct machine *machine__new_host (void );struct machine *machine__new_kallsyms (void ); -int machine__init (struct machine *machine,const char *root_dir,pid_t pid); +int machine__init (struct machine *machine,const char *root_dir,pid_t pid,bool has_data_mmap);void machine__exit (struct machine *machine);void machine__delete_threads (struct machine *machine);void machine__delete (struct machine *machine);tools/perf/util/session.c +2
-2@@ -191,7 +191,7 @@ static int ordered_events__deliver_event(struct ordered_events *oe, }struct perf_session *__perf_session__new (struct perf_data *data, -bool repipe,int repipe_fd, +bool repipe,int repipe_fd,bool data_mmap,struct perf_tool *tool) {int ret = -ENOMEM ;@@ -205,7 +205,7 @@ struct perf_session *__perf_session__new(struct perf_data *data, session->decomp_data.zstd_decomp = &session->zstd_data; session->active_decomp = &session->decomp_data;INIT_LIST_HEAD (&session->auxtrace_index); -machines__init (&session->machines); +__machines__init (&session->machines, data_mmap);ordered_events__init (&session->ordered_events, ordered_events__deliver_event,NULL );tools/perf/util/session.h +2
-3@@ -64,13 +64,13 @@ struct decomp {struct perf_tool ;struct perf_session *__perf_session__new (struct perf_data *data, -bool repipe,int repipe_fd, +bool repipe,int repipe_fd,bool data_mmap,struct perf_tool *tool);static inline struct perf_session *perf_session__new (struct perf_data *data,struct perf_tool *tool) { -return __perf_session__new (data, false,-1 , tool); +return __perf_session__new (data, false,-1 , false, tool); }void perf_session__delete (struct perf_session *session); --2.41.0.185.g7c58973941-goog