perf/core improvements and fixes
Arnaldo Carvalho de Melo
maintainerHi Ingo,
Please consider pulling,
- Arnaldo
The following changes since commit 2336ebc32676df5b794acfe0c980583ec6c05f34:
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf into perf/core (2014-07-18 12:19:20 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo
for you to fetch changes up to dcabb507fd3a2b19aed6b4068e2a954f5fd8de45:
perf record: Store PERF_RECORD_FINISHED_ROUND only for nonempty rounds (2014-07-25 12:17:36 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
Developer stuff:
o More prep work to support Intel PT: (Adrian Hunter)
- Polishing 'script' BTS output
- 'inject' can specify --kallsym
- VDSO is per machine, not a global var
- Expose data addr lookup functions previously private to 'script'
- Large mmap fixes in events processing
o Fix build on gcc 4.4.7 (Arnaldo Carvalho de Melo)
o Event ordering fixes (Jiri Olsa)
o Include standard stringify macros in power pc code (Sukadev Bhattiprolu)
----------------------------------------------------------------
Adrian Hunter (22):
perf tools: Fix incorrect fd error comparison
perf tools: Fix jump label always changing during tracing perf script: Improve srcline display for BTS
perf script: Do not print dangling '=>' for BTS
perf tools: Record whether a dso has data
perf tools: Add dso__data_status_seen()
perf tools: Add dsos__hit_all()
perf tools: Add cpu to struct thread
perf machine: Add ability to record the current tid for each cpu perf tools: Move rdtsc() function
perf tools: Add dso__data_size()
perf tools: Pass machine to vdso__dso_findnew()
perf session: Add ability to 'skip' a non-piped event stream perf session: Add ability to skip 4GiB or more
perf tools: Group VDSO global variables into a structure perf machine: Fix the lifetime of the VDSO temporary file perf tools: Add vdso__new()
perf tools: Separate the VDSO map name from the VDSO dso name perf tools: Add dso__type()
perf tools: Add thread parameter to vdso__dso_findnew() perf tools: Expose 'addr' functions so they can be reused perf inject: Add --kallsyms parameter
Arnaldo Carvalho de Melo (1):
perf tools: Fix build on gcc 4.4.7
Jiri Olsa (3):
perf session: Fix accounting of ordered samples queue
perf record: Always force PERF_RECORD_FINISHED_ROUND event perf record: Store PERF_RECORD_FINISHED_ROUND only for nonempty rounds
Sukadev Bhattiprolu (1):
perf powerpc: Include util/util.h and remove stringify macros
tools/perf/Documentation/perf-inject.txt | 3 + tools/perf/arch/powerpc/util/header.c | 4 +- tools/perf/arch/x86/util/tsc.c | 9 +++ tools/perf/builtin-inject.c | 2 + tools/perf/builtin-record.c | 7 ++- tools/perf/builtin-script.c | 60 +++++++------------- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/perf-time-to-tsc.c | 9 --- tools/perf/util/cloexec.c | 9 ++- tools/perf/util/dso.c | 70 ++++++++++++++++++++--- tools/perf/util/dso.h | 25 +++++++++ tools/perf/util/event.c | 42 ++++++++++++++ tools/perf/util/event.h | 10 ++++ tools/perf/util/header.c | 51 +++++++++++++++-- tools/perf/util/header.h | 2 + tools/perf/util/machine.c | 58 +++++++++++++++++-- tools/perf/util/machine.h | 8 +++ tools/perf/util/map.c | 9 +-- tools/perf/util/map.h | 5 +- tools/perf/util/session.c | 25 +++++---- tools/perf/util/symbol-elf.c | 35 +++++++++++- tools/perf/util/symbol-minimal.c | 21 +++++++ tools/perf/util/symbol.h | 2 + tools/perf/util/thread.c | 1 + tools/perf/util/thread.h | 1 + tools/perf/util/tsc.c | 5 ++ tools/perf/util/tsc.h | 1 + tools/perf/util/vdso.c | 96 +++++++++++++++++++++++++------- tools/perf/util/vdso.h | 13 ++++- 29 files changed, 470 insertions(+), 115 deletions(-)
Arnaldo Carvalho de Melo
maintainerPATCH 1/27 perf tools: Fix incorrect fd error comparison
From: Adrian Hunter <[email protected]>
Zero is a valid fd. Error comparison should check for negative fd.
--- tools/perf/util/dso.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/dso.c +1 -1
@@ -216,7 +216,7 @@ static int open_dso(struct dso *dso, struct machine *machine) {int fd =__open_dso (dso, machine); -if (fd >0 ) { +if (fd >=0 ) {dso__list_add (dso);/* * Check if we crossed the allowed number
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 2/27 perf tools: Fix jump label always changing during tracing
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Intel PT decoding walks the object code to reconstruct the trace. A jump label change during tracing causes decoding errors.
The "Enable close-on-exec flag on perf file descriptor" patch caused there to be always a jump label change.
It was found that using a per-cpu context instead of a per-thread context for the probe of the close-on-exec feature, made the problem go away.
--- tools/perf/util/cloexec.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/cloexec.c +7 -2
@@ -1,3 +1,4 @@ +#include <sched.h> #include "util.h" #include "../perf.h" #include "cloexec.h"
@@ -14,9 +15,13 @@ static int perf_flag_probe(void) };int fd;int err; +int cpu =sched_getcpu (); + +if (cpu <0 ) + cpu =0 ;/* check cloexec flag */ - fd =sys_perf_event_open (&attr,0 ,-1 ,-1 , + fd =sys_perf_event_open (&attr,-1 , cpu,-1 ,PERF_FLAG_FD_CLOEXEC ); err = errno;
@@ -30,7 +35,7 @@ static int perf_flag_probe(void) err, strerror(err));/* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */ - fd =sys_perf_event_open (&attr,0 ,-1 ,-1 ,0 ); + fd =sys_perf_event_open (&attr,-1 , cpu,-1 ,0 ); err = errno; if (WARN_ONCE(fd < 0,
Signature · 1 line
1.9.3
Peter Zijlstra
maintainerRe: [PATCH 02/27] perf tools: Fix jump label always changing during tracing
Quoted 11 lines · Arnaldo Carvalho de Melo
From: Adrian Hunter <[email protected]>
Intel PT decoding walks the object code to reconstruct the trace. A jump label change during tracing causes decoding errors.
The "Enable close-on-exec flag on perf file descriptor" patch caused there to be always a jump label change.
It was found that using a per-cpu context instead of a per-thread context for the probe of the close-on-exec feature, made the problem go away.
per-cpu events are privileged, wouldn't this change make CLOEXEC always undetected for normal users?
Also, the $subject doesn't related to CLOEXEC at all.
Re: [PATCH 02/27] perf tools: Fix jump label always changing during tracing
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Arnaldo Carvalho de Melo
From: Adrian Hunter <[email protected]>
Intel PT decoding walks the object code to reconstruct the trace. A jump label change during tracing causes decoding errors.
The "Enable close-on-exec flag on perf file descriptor" patch caused there to be always a jump label change.
Quoted 8 lines
Quoted 3 lines
It was found that using a per-cpu context instead of a per-thread context for the probe of the close-on-exec feature, made the problem go away.
per-cpu events are privileged, wouldn't this change make CLOEXEC always undetected for normal users?
Also, the $subject doesn't related to CLOEXEC at all.
right, it would.. Ingo, still any chance to skip this one?
[jolsa@dhcp-26-214 perf]$ ./perf record sleep 1perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 13 (Permission denied) perf_event_open(..., 0) failed unexpectedly with error 13 (Permission denied)
jirka
Re: [PATCH 02/27] perf tools: Fix jump label always changing during tracing
Quoted 19 lines · Jiri Olsa
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Arnaldo Carvalho de Melo
From: Adrian Hunter <[email protected]>
Intel PT decoding walks the object code to reconstruct the trace. A jump label change during tracing causes decoding errors.
The "Enable close-on-exec flag on perf file descriptor" patch caused there to be always a jump label change.
Quoted 8 lines
Quoted 3 lines
It was found that using a per-cpu context instead of a per-thread context for the probe of the close-on-exec feature, made the problem go away.
per-cpu events are privileged, wouldn't this change make CLOEXEC always undetected for normal users?
Also, the $subject doesn't related to CLOEXEC at all.
Quoted 7 lines
right, it would.. Ingo, still any chance to skip this one?
[jolsa@dhcp-26-214 perf]$ ./perf record sleep 1
perf_event_open(..., PERF_FLAG_FD_CLOEXEC)failed with unexpected error 13 (Permission denied)perf_event_open(..., 0)failed unexpectedly with error 13 (Permission denied)jirka
No, sorry - mind any of you please send a pull request with a fix or a revert?
Thanks,
Ingo
tip-bot for Jiri Olsa
merge bot[tip:perf/core] Revert "perf tools: Fix jump label always changing during tracing"
In reply to Peter ZijlstraRevert "perf tools: Fix jump label always changing during tracing"
Commit-ID: 8578b891ec38c39abd5d6376afd05fce78e2628c Gitweb: http://git.kernel.org/tip/8578b891ec38c39abd5d6376afd05fce78e2628c Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 28 Jul 2014 15:58:47 +0200 Committer: Jiri Olsa <[email protected]> CommitDate: Mon, 28 Jul 2014 16:39:18 +0200
Revert "perf tools: Fix jump label always changing during tracing"
This reverts commit deaff8b659cf4d34181c087b8cdf74f1eb17b02b.
This commit makes CLOEXEC feature undetected for normal users, because per-cpu events are priviledged.
--- tools/perf/util/cloexec.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
tools/perf/util/cloexec.c +2 -7
@@ -1,4 +1,3 @@ -#include <sched.h> #include "util.h" #include "../perf.h" #include "cloexec.h"
@@ -15,13 +14,9 @@ static int perf_flag_probe(void) };int fd;int err; -int cpu =sched_getcpu (); - -if (cpu <0 ) - cpu =0 ;/* check cloexec flag */ - fd =sys_perf_event_open (&attr,-1 , cpu,-1 , + fd =sys_perf_event_open (&attr,0 ,-1 ,-1 ,PERF_FLAG_FD_CLOEXEC ); err = errno;
@@ -35,7 +30,7 @@ static int perf_flag_probe(void) err, strerror(err));/* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */ - fd =sys_perf_event_open (&attr,-1 , cpu,-1 ,0 ); + fd =sys_perf_event_open (&attr,0 ,-1 ,-1 ,0 ); err = errno; if (WARN_ONCE(fd < 0,
Arnaldo Carvalho de Melo
maintainerPATCH 3/27 perf script: Improve srcline display for BTS
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Change the order of the output to put the srcline last.
It puts the branch 'from address' and 'to address' on the same line, which is how it would be without the source line reference.
So it makes it consistent and much easier to read.
E.g. old format:
4028fc main+0x2c (/bin/ls)
/build/buildd/coreutils-8.20/src/ls.c:1269 => 40d8a0 set_program_name+0x0 (/bin/ls)
new format:
4028fc main+0x2c (/bin/ls) => 40d8a0 set_program_name+0x0 (/bin/ls)
/build/buildd/coreutils-8.20/src/ls.c:1269
--- tools/perf/builtin-script.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
tools/perf/builtin-script.c +15 -5
@@ -427,15 +427,22 @@ static void print_sample_bts(union perf_event *event, struct addr_location *al) {struct perf_event_attr *attr = &evsel->attr; +bool print_srcline_last = false;/* print branch_from information */ if (PRINT_FIELD (IP )) { -if (!symbol_conf.use_callchain) -printf (" " ); -else +unsigned int print_opts = output[attr->type].print_ip_opts; + +if (symbol_conf.use_callchain && sample->callchain) {printf ("\n" ); -perf_evsel__print_ip (evsel, sample, al, - output[attr->type].print_ip_opts, + }else { +printf (" " ); +if (print_opts &PRINT_IP_OPT_SRCLINE ) { + print_srcline_last = true; + print_opts &= ~PRINT_IP_OPT_SRCLINE ; + } + } +perf_evsel__print_ip (evsel, sample, al, print_opts,PERF_MAX_STACK_DEPTH ); }
@@ -447,6 +454,9 @@ static void print_sample_bts(union perf_event *event, !output[attr->type].user_set))print_sample_addr (event, sample, al->machine, thread, attr); +if (print_srcline_last) +map__fprintf_srcline (al->map, al->addr,"\n " , stdout); +printf ("\n" ); }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 4/27 perf script: Do not print dangling '=>' for BTS
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
When using:
perf record -e branches:u -c1 usleep 1
perf script -f ip
lines are displayed like:
ffffffff813b23d5 =>
Change so that the dangling '=>' does not appear.
--- tools/perf/builtin-script.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/builtin-script.c +3 -3
@@ -446,13 +446,13 @@ static void print_sample_bts(union perf_event *event, PERF_MAX_STACK_DEPTH); } -printf (" => " ); -/* print branch_to information */ if (PRINT_FIELD (ADDR ) || ((evsel->attr.sample_type &PERF_SAMPLE_ADDR ) && - !output[attr->type].user_set)) + !output[attr->type].user_set)) { +printf (" => " );print_sample_addr (event, sample, al->machine, thread, attr); + }if (print_srcline_last)map__fprintf_srcline (al->map, al->addr,"\n " , stdout);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 5/27 perf tools: Record whether a dso has data
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add 'data.status' to record whether a dso has data (i.e. an object file). This is used to avoid repeatedly creating the file name and attempting to open a file that is not present.
--- tools/perf/util/dso.c | 23 +++++++++++++++-------- tools/perf/util/dso.h | 7 +++++++ 2 files changed, 22 insertions(+), 8 deletions(-)
tools/perf/util/dso.c +15 -8
@@ -331,26 +331,32 @@ int dso__data_fd(struct dso *dso, struct machine *machine) };int i =0 ; +if (dso->data.status ==DSO_DATA_STATUS_ERROR ) +return -1 ; +if (dso->data.fd >=0 ) -return dso->data.fd; + goto out;if (dso->binary_type !=DSO_BINARY_TYPE__NOT_FOUND ) { dso->data.fd =open_dso (dso, machine); -return dso->data.fd; + goto out; }do { -int fd; - dso->binary_type = binary_type_data[i++]; - fd =open_dso (dso, machine); -if (fd >=0 ) -return dso->data.fd = fd; + dso->data.fd =open_dso (dso, machine); +if (dso->data.fd >=0 ) + goto out; }while (dso->binary_type !=DSO_BINARY_TYPE__NOT_FOUND ); +out: +if (dso->data.fd >=0 ) + dso->data.status =DSO_DATA_STATUS_OK ; +else + dso->data.status =DSO_DATA_STATUS_ERROR ; -return -EINVAL ; +return dso->data.fd; } static void
@@ -701,6 +707,7 @@ struct dso *dso__new(const char *name) dso->symbols[i] = dso->symbol_names[i] =RB_ROOT ; dso->data.cache =RB_ROOT ; dso->data.fd =-1 ; + dso->data.status =DSO_DATA_STATUS_UNKNOWN ; dso->symtab_type =DSO_BINARY_TYPE__NOT_FOUND ; dso->binary_type =DSO_BINARY_TYPE__NOT_FOUND ; dso->is_64_bit = (sizeof (void *) ==8 );
tools/perf/util/dso.h +7 -0
@@ -40,6 +40,12 @@ enum dso_swap_type { DSO_SWAP__YES, }; +enum dso_data_status { +DSO_DATA_STATUS_ERROR =-1 , +DSO_DATA_STATUS_UNKNOWN =0 , +DSO_DATA_STATUS_OK =1 , +}; +#define DSO__SWAP (dso, type, val) \ ({ \ type ____r = val; \
@@ -104,6 +110,7 @@ struct dso {struct {struct rb_root cache;int fd; +int status;size_t file_size;struct list_head open_entry; } data;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 6/27 perf tools: Add dso__data_status_seen()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add a function to track whether a caller has seen the data status of a dso. This is needed to enable callers to report the error exactly once only per dso.
--- tools/perf/util/dso.c | 12 ++++++++++++ tools/perf/util/dso.h | 6 ++++++ 2 files changed, 18 insertions(+)
tools/perf/util/dso.c +12 -0
@@ -359,6 +359,18 @@ out:return dso->data.fd; } +bool dso__data_status_seen (struct dso *dso,enum dso_data_status_seen by) +{ +u32 flag =1 << by; + +if (dso->data.status_seen & flag) +return true; + + dso->data.status_seen |= flag; + +return false; +} +static void dso_cache__free (struct rb_root *root) {
tools/perf/util/dso.h +6 -0
@@ -46,6 +46,10 @@ enum dso_data_status { DSO_DATA_STATUS_OK = 1, }; +enum dso_data_status_seen { +DSO_DATA_STATUS_SEEN_ITRACE , +}; +#define DSO__SWAP (dso, type, val) \ ({ \ type ____r = val; \
@@ -111,6 +115,7 @@ struct dso {struct rb_root cache;int fd;int status; +u32 status_seen;size_t file_size;struct list_head open_entry; } data;
@@ -203,6 +208,7 @@ ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,ssize_t dso__data_read_addr (struct dso *dso,struct map *map,struct machine *machine,u64 addr,u8 *data,ssize_t size); +bool dso__data_status_seen (struct dso *dso,enum dso_data_status_seen by);struct map *dso__new_map (const char *name); struct dso *dso__kernel_findnew(struct machine *machine, const char *name,
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 7/27 perf tools: Add dsos__hit_all()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add ability to mark all dsos as hit.
This is needed in the case of Instruction Tracing. It takes so long to decode an Instruction Trace that it is not worth doing just to determine which dsos are hit. A later patch takes this into use.
--- tools/perf/util/header.c | 41 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/header.h | 2 ++ 2 files changed, 43 insertions(+)
tools/perf/util/header.c +41 -0
@@ -200,6 +200,47 @@ static int write_buildid(const char *name, size_t name_len, u8 *build_id,return write_padded (fd, name, name_len +1 , len); } +static int __dsos__hit_all (struct list_head *head) +{ +struct dso *pos; + +list_for_each_entry (pos, head, node) + pos->hit = true; + +return 0 ; +} + +static int machine__hit_all_dsos (struct machine *machine) +{ +int err; + + err =__dsos__hit_all (&machine->kernel_dsos); +if (err) +return err; + +return __dsos__hit_all (&machine->user_dsos); +} + +int dsos__hit_all (struct perf_session *session) +{ +struct rb_node *nd; +int err; + + err =machine__hit_all_dsos (&session->machines.host); +if (err) +return err; + +for (nd =rb_first (&session->machines.guests); nd; nd =rb_next (nd)) { + struct machine *pos = rb_entry(nd, struct machine, rb_node); + + err =machine__hit_all_dsos (pos); +if (err) +return err; + } + +return 0 ; +} +static int __dsos__write_buildid_table (struct list_head *head,struct machine *machine,pid_t pid,u16 misc,int fd)
tools/perf/util/header.h +2 -0
@@ -151,6 +151,8 @@ int perf_event__process_build_id(struct perf_tool *tool, struct perf_session *session);bool is_perf_magic (u64 magic); +int dsos__hit_all (struct perf_session *session); +/* * arch specific callback */
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 8/27 perf tools: Add cpu to struct thread
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Tools may wish to track on which cpu a thread is running. Add 'cpu' to struct thread for that purpose.
This will be used to determine the cpu when decoding a per-thread Instruction Trace.
E.g: Intel PT decoding uses sched_switch events to determine which task is running on which cpu. The Intel PT data comes straight from the hardware which doesn't know about linux threads.
--- tools/perf/util/thread.c | 1 + tools/perf/util/thread.h | 1 + 2 files changed, 2 insertions(+)
tools/perf/util/thread.c +1 -0
@@ -34,6 +34,7 @@ struct thread *thread__new(pid_t pid, pid_t tid) thread->pid_ = pid; thread->tid = tid; thread->ppid =-1 ; + thread->cpu =-1 ;INIT_LIST_HEAD (&thread->comm_list); comm_str =malloc (32 );
tools/perf/util/thread.h +1 -0
@@ -17,6 +17,7 @@ struct thread {pid_t pid_;/* Not all tools update this */ pid_t tid;pid_t ppid; +int cpu;char shortname[3 ];bool comm_set;bool dead;/* if set thread has exited */
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 9/27 perf machine: Add ability to record the current tid for each cpu
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add an array to struct machine to store the current tid running on each cpu.
Add machine functions to get / set the tid for a cpu.
This will be used to determine the tid when decoding a per-cpu Instruction Trace.
--- tools/perf/util/machine.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/machine.h | 5 +++++ 2 files changed, 51 insertions(+)
tools/perf/util/machine.c +46 -0
@@ -45,6 +45,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)thread__set_comm (thread, comm,0 ); } + machine->current_tid =NULL ; +return 0 ; }
@@ -104,6 +106,7 @@ void machine__exit(struct machine *machine)dsos__delete (&machine->user_dsos);dsos__delete (&machine->kernel_dsos);zfree (&machine->root_dir); +zfree (&machine->current_tid); }void machine__delete (struct machine *machine)
@@ -1481,3 +1484,46 @@ int __machine__synthesize_threads(struct machine *machine, struct perf_tool *too/* command specified */ return 0 ; } + +pid_t machine__get_current_tid (struct machine *machine,int cpu) +{ +if (cpu <0 || cpu >=MAX_NR_CPUS || !machine->current_tid) +return -1 ; + +return machine->current_tid[cpu]; +} + +int machine__set_current_tid (struct machine *machine,int cpu,pid_t pid, +pid_t tid) +{ +struct thread *thread; + +if (cpu <0 ) +return -EINVAL ; + +if (!machine->current_tid) { +int i; + + machine->current_tid =calloc (MAX_NR_CPUS ,sizeof (pid_t)); +if (!machine->current_tid) +return -ENOMEM ; +for (i =0 ; i <MAX_NR_CPUS ; i++) + machine->current_tid[i] =-1 ; + } + +if (cpu >=MAX_NR_CPUS ) { +pr_err ("Requested CPU %d too large. " , cpu); +pr_err ("Consider raising MAX_NR_CPUS\n" ); +return -EINVAL ; + } + + machine->current_tid[cpu] = tid; + + thread =machine__findnew_thread (machine, pid, tid); +if (!thread) +return -ENOMEM ; + + thread->cpu = cpu; + +return 0 ; +}
tools/perf/util/machine.h +5 -0
@@ -33,6 +33,7 @@ struct machine {struct map_groups kmaps;struct map *vmlinux_maps[MAP__NR_TYPES ];symbol_filter_t symbol_filter; +pid_t *current_tid; }; static inline
@@ -191,4 +192,8 @@ int machine__synthesize_threads(struct machine *machine, struct target *target, perf_event__process, data_mmap); } +pid_t machine__get_current_tid (struct machine *machine,int cpu); +int machine__set_current_tid (struct machine *machine,int cpu,pid_t pid, +pid_t tid); +#endif /* __PERF_MACHINE_H */
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 10/27 perf tools: Move rdtsc() function
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Move the rdtsc() function so it can be reusued.
--- tools/perf/arch/x86/util/tsc.c | 9 +++++++++ tools/perf/tests/perf-time-to-tsc.c | 9 --------- tools/perf/util/tsc.c | 5 +++++ tools/perf/util/tsc.h | 1 + 4 files changed, 15 insertions(+), 9 deletions(-)
tools/perf/arch/x86/util/tsc.c +9 -0
@@ -37,3 +37,12 @@ int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,return 0 ; } + +u64 rdtsc (void ) +{ +unsigned int low, high; + + asmvolatile ("rdtsc" :"=a" (low),"=d" (high)); + +return low | ((u64 )high) <<32 ; +}
tools/perf/tests/perf-time-to-tsc.c +0 -9
@@ -25,15 +25,6 @@ } \ } -static u64 rdtsc (void ) -{ -unsigned int low, high; - - asmvolatile ("rdtsc" :"=a" (low),"=d" (high)); - -return low | ((u64 )high) <<32 ; -} -/** * test__perf_time_to_tsc - test converting perf time to TSC. *
tools/perf/util/tsc.c +5 -0
@@ -23,3 +23,8 @@ u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc)return tc->time_zero + quot * tc->time_mult + ((rem * tc->time_mult) >> tc->time_shift); } + +u64 __weak rdtsc (void ) +{ +return 0 ; +}
tools/perf/util/tsc.h +1 -0
@@ -7,5 +7,6 @@u64 perf_time_to_tsc (u64 ns,struct perf_tsc_conversion *tc);u64 tsc_to_perf_time (u64 cyc,struct perf_tsc_conversion *tc); +u64 rdtsc (void );#endif
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 11/27 perf tools: Add dso__data_size()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add a function to return the dso data size, for use in estimating the size an instruction cache.
--- tools/perf/util/dso.c | 22 ++++++++++++++++++++++ tools/perf/util/dso.h | 2 ++ 2 files changed, 24 insertions(+)
tools/perf/util/dso.c +22 -0
@@ -544,6 +544,28 @@ static int data_file_size(struct dso *dso)return 0 ; } +/** +* dso__data_size - Return dso data size +* @dso: dso object +* @machine: machine object +* +* Return: dso data size +*/ +off_t dso__data_size (struct dso *dso,struct machine *machine) +{ +int fd; + + fd =dso__data_fd (dso, machine); +if (fd <0 ) +return fd; + +if (data_file_size (dso)) +return -1 ; + +/* For now just estimate dso data size is close to file size */ +return dso->data.file_size; +} +static ssize_t data_read_offset (struct dso *dso,u64 offset,u8 *data,ssize_t size) {
tools/perf/util/dso.h +2 -0
@@ -166,6 +166,7 @@ int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type t* The dso__data_* external interface provides following functions: * dso__data_fd * dso__data_close +* dso__data_size * dso__data_read_offset * dso__data_read_addr *
@@ -203,6 +204,7 @@ int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type tint dso__data_fd (struct dso *dso,struct machine *machine);void dso__data_close (struct dso *dso); +off_t dso__data_size (struct dso *dso,struct machine *machine);ssize_t dso__data_read_offset (struct dso *dso,struct machine *machine,u64 offset,u8 *data,ssize_t size); ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 12/27 perf tools: Pass machine to vdso__dso_findnew()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
This is preparation for removing the global variables used in vdso.c and thereby fixing the lifetime of the VDSO temporary file.
--- tools/perf/util/machine.c | 4 ++-- tools/perf/util/map.c | 7 ++++--- tools/perf/util/map.h | 2 +- tools/perf/util/vdso.c | 7 ++++--- tools/perf/util/vdso.h | 4 +++- 5 files changed, 14 insertions(+), 10 deletions(-)
tools/perf/util/machine.c +2 -2
@@ -1095,7 +1095,7 @@ int machine__process_mmap2_event(struct machine *machine,else type =MAP__FUNCTION ; - map = map__new(&machine->user_dsos, event->mmap2.start, + map = map__new(machine, event->mmap2.start, event->mmap2.len, event->mmap2.pgoff, event->mmap2.pid, event->mmap2.maj, event->mmap2.min, event->mmap2.ino,
@@ -1145,7 +1145,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *eventelse type =MAP__FUNCTION ; - map = map__new(&machine->user_dsos, event->mmap.start, + map = map__new(machine, event->mmap.start, event->mmap.len, event->mmap.pgoff, event->mmap.pid, 0, 0, 0, 0, 0, 0, event->mmap.filename,
tools/perf/util/map.c +4 -3
@@ -13,6 +13,7 @@#include "build-id.h" #include "util.h" #include "debug.h" +#include "machine.h" #include <linux/string.h> const char *map_type__name[MAP__NR_TYPES ] = {
@@ -137,7 +138,7 @@ void map__init(struct map *map, enum map_type type, map->erange_warned = false; } -struct map *map__new (struct list_head *dsos__list,u64 start,u64 len, +struct map *map__new (struct machine *machine,u64 start,u64 len,u64 pgoff,u32 pid,u32 d_maj,u32 d_min,u64 ino,u64 ino_gen,u32 prot,u32 flags,char *filename,enum map_type type)
@@ -173,9 +174,9 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,if (vdso) { pgoff =0 ; - dso =vdso__dso_findnew (dsos__list); + dso =vdso__dso_findnew (machine); }else - dso =__dsos__findnew (dsos__list, filename); + dso =__dsos__findnew (&machine->user_dsos, filename);if (dso ==NULL ) goto out_delete;
tools/perf/util/map.h +1 -1
@@ -119,7 +119,7 @@ typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);void map__init (struct map *map,enum map_type type,u64 start,u64 end,u64 pgoff,struct dso *dso); -struct map *map__new (struct list_head *dsos__list,u64 start,u64 len, +struct map *map__new (struct machine *machine,u64 start,u64 len,u64 pgoff,u32 pid,u32 d_maj,u32 d_min,u64 ino,u64 ino_gen,u32 prot,u32 flags,char *filename,enum map_type type);
tools/perf/util/vdso.c +4 -3
@@ -11,6 +11,7 @@#include "vdso.h" #include "util.h" #include "symbol.h" +#include "machine.h" #include "linux/string.h" #include "debug.h"
@@ -90,9 +91,9 @@ void vdso__exit(void)unlink (vdso_file); } -struct dso *vdso__dso_findnew (struct list_head *head) +struct dso *vdso__dso_findnew (struct machine *machine) { -struct dso *dso =dsos__find (head,VDSO__MAP_NAME , true); +struct dso *dso =dsos__find (&machine->user_dsos,VDSO__MAP_NAME , true);if (!dso) {char *file;
@@ -103,7 +104,7 @@ struct dso *vdso__dso_findnew(struct list_head *head) dso =dso__new (VDSO__MAP_NAME );if (dso !=NULL ) { -dsos__add (head, dso); +dsos__add (&machine->user_dsos, dso);dso__set_long_name (dso, file, false); } }
tools/perf/util/vdso.h +3 -1
@@ -12,7 +12,9 @@ static inline bool is_vdso_map(const char *filename) return !strcmp(filename, VDSO__MAP_NAME); } -struct dso *vdso__dso_findnew (struct list_head *head); +struct machine ; + +struct dso *vdso__dso_findnew (struct machine *machine);void vdso__exit (void );#endif /* __PERF_VDSO__ */
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 13/27 perf session: Add ability to 'skip' a non-piped event stream
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
A piped event stream may contain arbitary sized tracepoint information following a PERF_RECORD_HEADER_TRACING_DATA event. The position in the stream has to be 'skipped' to match the start of the next event.
Provide the same ability to a non-piped event stream to allow for Instruction Trace data that may also be in a non-piped event stream.
--- tools/perf/util/session.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/session.c +6 -1
@@ -1284,6 +1284,7 @@ int __perf_session__process_events(struct perf_session *session,union perf_event *event;uint32_t size;struct ui_progress prog; +int skip;perf_tool__fill_defaults (tool);
@@ -1344,7 +1345,8 @@ more: size = event->header.size;if (size <sizeof (struct perf_event_header ) || -perf_session__process_event (session, event, tool, file_pos) <0 ) { + (skip =perf_session__process_event (session, event, tool, file_pos)) + <0 ) {pr_err ("%#" PRIx64" [%#x]: failed to process type: %d\n" , file_offset + head, event->header.size, event->header.type);
@@ -1352,6 +1354,9 @@ more: goto out_err; } +if (skip) + size += skip; + head += size; file_pos += size;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 14/27 perf session: Add ability to skip 4GiB or more
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
A session can be made to skip portions of the input file. Do not limit that size to 32-bits.
--- tools/perf/util/session.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
tools/perf/util/session.c +8 -7
@@ -994,8 +994,10 @@ static int perf_session_deliver_event(struct perf_session *session, } } -static int perf_session__process_user_event (struct perf_session *session,union perf_event *event, -struct perf_tool *tool,u64 file_offset) +static s64 perf_session__process_user_event (struct perf_session *session, +union perf_event *event, +struct perf_tool *tool, +u64 file_offset) {int fd =perf_data_file__fd (session->file);int err;
@@ -1037,7 +1039,7 @@ static void event_swap(union perf_event *event, bool sample_id_all)swap (event, sample_id_all); } -static int perf_session__process_event (struct perf_session *session, +static s64 perf_session__process_event (struct perf_session *session,union perf_event *event,struct perf_tool *tool,u64 file_offset)
@@ -1148,7 +1150,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session,union perf_event *event;uint32_t size, cur_size =0 ;void *buf =NULL ; -int skip =0 ; +s64 skip =0 ;u64 head;ssize_t err;void *p;
@@ -1277,14 +1279,13 @@ int __perf_session__process_events(struct perf_session *session, u64 file_size, struct perf_tool *tool) { int fd = perf_data_file__fd(session->file); -u64 head, page_offset, file_offset, file_pos; +u64 head, page_offset, file_offset, file_pos, size;int err, mmap_prot, mmap_flags, map_idx =0 ;size_t mmap_size;char *buf, *mmaps[NUM_MMAPS ];union perf_event *event; -uint32_t size;struct ui_progress prog; -int skip; +s64 skip;perf_tool__fill_defaults (tool);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 15/27 perf tools: Group VDSO global variables into a structure
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
This is preparation for removing the global variables used in vdso.c and thereby fixing the lifetime of the VDSO temporary file.
Also allowance is made for the later addition of support for compat VDSOs.
--- tools/perf/util/vdso.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-)
tools/perf/util/vdso.c +32 -12
@@ -15,8 +15,27 @@#include "linux/string.h" #include "debug.h" -static bool vdso_found; -static char vdso_file[] ="/tmp/perf-vdso.so-XXXXXX" ; +#define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX" + +struct vdso_file { +bool found; +bool error; +char temp_file_name[sizeof (VDSO__TEMP_FILE_NAME )]; +const char *dso_name; +}; + +struct vdso_info { +struct vdso_file vdso; +}; + +static struct vdso_info vdso_info_ = { + .vdso = { + .temp_file_name =VDSO__TEMP_FILE_NAME , + .dso_name =VDSO__MAP_NAME , + }, +}; + +static struct vdso_info *vdso_info = &vdso_info_;static int find_vdso_map (void **start,void **end) {
@@ -49,7 +68,7 @@ static int find_vdso_map(void **start, void **end)return !found; } -static char *get_file (void ) +static char *get_file (struct vdso_file *vdso_file) {char *vdso =NULL ;char *buf =NULL ;
@@ -57,10 +76,10 @@ static char *get_file(void)size_t size;int fd; -if (vdso_found) -return vdso_file; +if (vdso_file->found) +return vdso_file->temp_file_name; -if (find_vdso_map (&start, &end)) +if (vdso_file->error ||find_vdso_map (&start, &end))return NULL ; size = end - start;
@@ -69,26 +88,27 @@ static char *get_file(void)if (!buf)return NULL ; - fd =mkstemp (vdso_file); + fd =mkstemp (vdso_file->temp_file_name);if (fd <0 ) goto out;if (size == (size_t )write (fd, buf, size)) - vdso = vdso_file; + vdso = vdso_file->temp_file_name;close (fd); out:free (buf); - vdso_found = (vdso !=NULL ); + vdso_file->found = (vdso !=NULL ); + vdso_file->error = !vdso_file->found;return vdso; }void vdso__exit (void ) { -if (vdso_found) -unlink (vdso_file); +if (vdso_info->vdso.found) +unlink (vdso_info->vdso.temp_file_name); }struct dso *vdso__dso_findnew (struct machine *machine)
@@ -98,7 +118,7 @@ struct dso *vdso__dso_findnew(struct machine *machine)if (!dso) {char *file; - file =get_file (); + file =get_file (&vdso_info->vdso);if (!file)return NULL ;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 16/27 perf machine: Fix the lifetime of the VDSO temporary file
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
The VDSO temporary file is unlinked when a session is deleted. That precludes the possibilities that there is no session or there is more than one session.
Correctly the vdso belongs to the machine so put the information on 'struct machine' and get rid of the global variables.
--- tools/perf/util/machine.c | 4 ++++ tools/perf/util/machine.h | 3 +++ tools/perf/util/session.c | 2 -- tools/perf/util/vdso.c | 39 +++++++++++++++++++++++++++++---------- tools/perf/util/vdso.h | 2 +- 5 files changed, 37 insertions(+), 13 deletions(-)
tools/perf/util/machine.c +4 -0
@@ -8,6 +8,7 @@#include "sort.h" #include "strlist.h" #include "thread.h" +#include "vdso.h" #include <stdbool.h> #include <symbol/kallsyms.h> #include "unwind.h"
@@ -23,6 +24,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)INIT_LIST_HEAD (&machine->dead_threads); machine->last_match =NULL ; + machine->vdso_info =NULL ; + machine->kmaps.machine = machine; machine->pid = pid;
@@ -105,6 +108,7 @@ void machine__exit(struct machine *machine)map_groups__exit (&machine->kmaps);dsos__delete (&machine->user_dsos);dsos__delete (&machine->kernel_dsos); +vdso__exit (machine);zfree (&machine->root_dir);zfree (&machine->current_tid); }
tools/perf/util/machine.h +3 -0
@@ -20,6 +20,8 @@ union perf_event;extern const char *ref_reloc_sym_names[]; +struct vdso_info ; +struct machine {struct rb_node rb_node;pid_t pid;
@@ -28,6 +30,7 @@ struct machine {struct rb_root threads;struct list_head dead_threads;struct thread *last_match; +struct vdso_info *vdso_info;struct list_head user_dsos;struct list_head kernel_dsos;struct map_groups kmaps;
tools/perf/util/session.c +0 -2
@@ -14,7 +14,6 @@#include "util.h" #include "cpumap.h" #include "perf_regs.h" -#include "vdso.h" static int perf_session__open (struct perf_session *session) {
@@ -156,7 +155,6 @@ void perf_session__delete(struct perf_session *session)if (session->file)perf_data_file__close (session->file);free (session); -vdso__exit (); } static int process_event_synth_tracing_data_stub(struct perf_tool *tool
tools/perf/util/vdso.c +29 -10
@@ -28,14 +28,17 @@ struct vdso_info {struct vdso_file vdso; }; -static struct vdso_info vdso_info_ = { - .vdso = { - .temp_file_name =VDSO__TEMP_FILE_NAME , - .dso_name =VDSO__MAP_NAME , - }, -}; - -static struct vdso_info *vdso_info = &vdso_info_; +static struct vdso_info *vdso_info__new (void ) +{ +static const struct vdso_info vdso_info_init = { + .vdso = { + .temp_file_name =VDSO__TEMP_FILE_NAME , + .dso_name =VDSO__MAP_NAME , + }, + }; + +return memdup (&vdso_info_init,sizeof (vdso_info_init)); +}static int find_vdso_map (void **start,void **end) {
@@ -105,16 +108,32 @@ static char *get_file(struct vdso_file *vdso_file)return vdso; } -void vdso__exit (void ) +void vdso__exit (struct machine *machine) { +struct vdso_info *vdso_info = machine->vdso_info; + +if (!vdso_info) +return ; +if (vdso_info->vdso.found)unlink (vdso_info->vdso.temp_file_name); + +zfree (&machine->vdso_info); }struct dso *vdso__dso_findnew (struct machine *machine) { -struct dso *dso =dsos__find (&machine->user_dsos,VDSO__MAP_NAME , true); +struct vdso_info *vdso_info; +struct dso *dso; + +if (!machine->vdso_info) + machine->vdso_info =vdso_info__new (); + + vdso_info = machine->vdso_info; +if (!vdso_info) +return NULL ; + dso =dsos__find (&machine->user_dsos,VDSO__MAP_NAME , true);if (!dso) {char *file;
tools/perf/util/vdso.h +1 -1
@@ -15,6 +15,6 @@ static inline bool is_vdso_map(const char *filename)struct machine ;struct dso *vdso__dso_findnew (struct machine *machine); -void vdso__exit (void ); +void vdso__exit (struct machine *machine);#endif /* __PERF_VDSO__ */
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 17/27 perf tools: Add vdso__new()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
This is preparation for adding support for compat VDSOs.
--- tools/perf/util/vdso.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
tools/perf/util/vdso.c +15 -5
@@ -121,6 +121,20 @@ void vdso__exit(struct machine *machine)zfree (&machine->vdso_info); } +static struct dso *vdso__new (struct machine *machine,const char *short_name, +const char *long_name) +{ +struct dso *dso; + + dso =dso__new (short_name); +if (dso !=NULL ) { +dsos__add (&machine->user_dsos, dso); +dso__set_long_name (dso, long_name, false); + } + +return dso; +} +struct dso *vdso__dso_findnew (struct machine *machine) {struct vdso_info *vdso_info;
@@ -141,11 +155,7 @@ struct dso *vdso__dso_findnew(struct machine *machine)if (!file)return NULL ; - dso =dso__new (VDSO__MAP_NAME ); -if (dso !=NULL ) { -dsos__add (&machine->user_dsos, dso); -dso__set_long_name (dso, file, false); - } + dso =vdso__new (machine,VDSO__MAP_NAME , file); }return dso;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 18/27 perf tools: Separate the VDSO map name from the VDSO dso name
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
This is in preparation for supporting 32-bit compatibility VDSOs.
--- tools/perf/util/header.c | 10 +++++----- tools/perf/util/symbol-elf.c | 2 +- tools/perf/util/vdso.c | 11 ++++++++--- tools/perf/util/vdso.h | 6 ++++++ 4 files changed, 20 insertions(+), 9 deletions(-)
tools/perf/util/header.c +5 -5
@@ -256,9 +256,9 @@ static int __dsos__write_buildid_table(struct list_head *head,if (!pos->hit)continue ; -if (is_vdso_map (pos->short_name)) { - name = (char *)VDSO__MAP_NAME ; - name_len =sizeof (VDSO__MAP_NAME ) +1 ; +if (dso__is_vdso (pos)) { + name = pos->short_name; + name_len = pos->short_name_len +1 ; }else if (dso__is_kcore (pos)) {machine__mmap_name (machine, nm,sizeof (nm)); name = nm;
@@ -339,7 +339,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, len =scnprintf (filename, size,"%s%s%s" , debugdir, slash ?"/" :"" , - is_vdso ?VDSO__MAP_NAME : realname); + is_vdso ?DSO__NAME_VDSO : realname);if (mkdir_p (filename,0755 )) goto out_free;
@@ -427,7 +427,7 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine, const char *debugdir) {bool is_kallsyms = dso->kernel && dso->long_name[0 ] !='/' ; -bool is_vdso =is_vdso_map (dso->short_name); +bool is_vdso =dso__is_vdso (dso);const char *name = dso->long_name;char nm[PATH_MAX ];
tools/perf/util/symbol-elf.c +1 -1
@@ -622,7 +622,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,GElf_Shdr shdr; ss->adjust_symbols = (ehdr.e_type ==ET_EXEC || ehdr.e_type ==ET_REL || -is_vdso_map (dso->short_name) || +dso__is_vdso (dso) ||elf_section_by_name (elf, &ehdr, &shdr,".gnu.prelink_undo" ,NULL ) !=NULL );
tools/perf/util/vdso.c +8 -3
@@ -33,7 +33,7 @@ static struct vdso_info *vdso_info__new(void)static const struct vdso_info vdso_info_init = { .vdso = { .temp_file_name =VDSO__TEMP_FILE_NAME , - .dso_name =VDSO__MAP_NAME , + .dso_name =DSO__NAME_VDSO , }, };
@@ -147,7 +147,7 @@ struct dso *vdso__dso_findnew(struct machine *machine)if (!vdso_info)return NULL ; - dso =dsos__find (&machine->user_dsos,VDSO__MAP_NAME , true); + dso =dsos__find (&machine->user_dsos,DSO__NAME_VDSO , true);if (!dso) {char *file;
@@ -155,8 +155,13 @@ struct dso *vdso__dso_findnew(struct machine *machine)if (!file)return NULL ; - dso =vdso__new (machine,VDSO__MAP_NAME , file); + dso =vdso__new (machine,DSO__NAME_VDSO , file); }return dso; } + +bool dso__is_vdso (struct dso *dso) +{ +return !strcmp (dso->short_name,DSO__NAME_VDSO ); +}
tools/perf/util/vdso.h +6 -0
@@ -7,11 +7,17 @@#define VDSO__MAP_NAME "[vdso]" +#define DSO__NAME_VDSO "[vdso]" +static inline bool is_vdso_map (const char *filename) {return !strcmp (filename,VDSO__MAP_NAME ); } +struct dso ; + +bool dso__is_vdso (struct dso *dso); +struct machine ;struct dso *vdso__dso_findnew (struct machine *machine);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 19/27 perf tools: Add dso__type()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
dso__type() determines wheather a dso is 32-bit, x32 (32-bit with 64-bit registers) or 64-bit.
dso__type() will be used to determine the VDSO a program maps.
--- tools/perf/util/dso.c | 11 +++++++++++ tools/perf/util/dso.h | 10 ++++++++++ tools/perf/util/symbol-elf.c | 33 +++++++++++++++++++++++++++++++++ tools/perf/util/symbol-minimal.c | 21 +++++++++++++++++++++ tools/perf/util/symbol.h | 2 ++ 5 files changed, 77 insertions(+)
tools/perf/util/dso.c +11 -0
@@ -940,3 +940,14 @@ size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp)return ret; } + +enum dso_type dso__type (struct dso *dso,struct machine *machine) +{ +int fd; + + fd =dso__data_fd (dso, machine); +if (fd <0 ) +return DSO__TYPE_UNKNOWN ; + +return dso__type_fd (fd); +}
tools/perf/util/dso.h +10 -0
@@ -5,6 +5,7 @@#include <linux/rbtree.h> #include <stdbool.h> #include <linux/types.h> +#include <linux/bitops.h> #include "map.h" #include "build-id.h"
@@ -50,6 +51,13 @@ enum dso_data_status_seen { DSO_DATA_STATUS_SEEN_ITRACE, }; +enum dso_type { +DSO__TYPE_UNKNOWN , +DSO__TYPE_64BIT , +DSO__TYPE_32BIT , +DSO__TYPE_X32BIT , +}; +#define DSO__SWAP (dso, type, val) \ ({ \ type ____r = val; \
@@ -245,4 +253,6 @@ static inline bool dso__is_kcore(struct dso *dso)void dso__free_a2l (struct dso *dso); +enum dso_type dso__type (struct dso *dso,struct machine *machine); +#endif /* __PERF_DSO */
tools/perf/util/symbol-elf.c +33 -0
@@ -1028,6 +1028,39 @@ int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,return err; } +enum dso_type dso__type_fd (int fd) +{ +enum dso_type dso_type =DSO__TYPE_UNKNOWN ; +GElf_Ehdr ehdr; +Elf_Kind ek; +Elf *elf; + + elf =elf_begin (fd,PERF_ELF_C_READ_MMAP ,NULL ); +if (elf ==NULL ) + goto out; + + ek =elf_kind (elf); +if (ek !=ELF_K_ELF ) + goto out_end; + +if (gelf_getclass (elf) ==ELFCLASS64 ) { + dso_type =DSO__TYPE_64BIT ; + goto out_end; + } + +if (gelf_getehdr (elf, &ehdr) ==NULL ) + goto out_end; + +if (ehdr.e_machine ==EM_X86_64 ) + dso_type =DSO__TYPE_X32BIT ; +else + dso_type =DSO__TYPE_32BIT ; +out_end: +elf_end (elf); +out: +return dso_type; +} +static int copy_bytes (int from,off_t from_offs,int to,off_t to_offs,u64 len) {ssize_t r;
tools/perf/util/symbol-minimal.c +21 -0
@@ -305,6 +305,27 @@ static int fd__is_64_bit(int fd)return e_ident[EI_CLASS ] ==ELFCLASS64 ; } +enum dso_type dso__type_fd (int fd) +{ +Elf64_Ehdr ehdr; +int ret; + + ret =fd__is_64_bit (fd); +if (ret <0 ) +return DSO__TYPE_UNKNOWN ; + +if (ret) +return DSO__TYPE_64BIT ; + +if (readn (fd, &ehdr,sizeof (ehdr)) !=sizeof (ehdr)) +return DSO__TYPE_UNKNOWN ; + +if (ehdr.e_machine ==EM_X86_64 ) +return DSO__TYPE_X32BIT ; + +return DSO__TYPE_32BIT ; +} + int dso__load_sym(struct dso *dso, struct map *map __maybe_unused, struct symsrc *ss, struct symsrc *runtime_ss __maybe_unused,
tools/perf/util/symbol.h +2 -0
@@ -243,6 +243,8 @@ struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,struct symbol *dso__first_symbol (struct dso *dso,enum map_type type);struct symbol *dso__next_symbol (struct symbol *sym); +enum dso_type dso__type_fd (int fd); +int filename__read_build_id (const char *filename,void *bf,size_t size);int sysfs__read_build_id (const char *filename,void *bf,size_t size); int modules__parse(const char *filename, void *arg,
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 20/27 perf tools: Add thread parameter to vdso__dso_findnew()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
The thread will be needed to determine the VDSO type.
--- tools/perf/util/machine.c | 4 ++-- tools/perf/util/map.c | 4 ++-- tools/perf/util/map.h | 3 ++- tools/perf/util/vdso.c | 3 ++- tools/perf/util/vdso.h | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-)
tools/perf/util/machine.c +2 -2
@@ -1106,7 +1106,7 @@ int machine__process_mmap2_event(struct machine *machine, event->mmap2.ino_generation, event->mmap2.prot, event->mmap2.flags, - event->mmap2.filename, type); + event->mmap2.filename, type, thread);if (map ==NULL ) goto out_problem;
@@ -1153,7 +1153,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event event->mmap.len, event->mmap.pgoff, event->mmap.pid,0 ,0 ,0 ,0 ,0 ,0 , event->mmap.filename, - type); + type, thread);if (map ==NULL ) goto out_problem;
tools/perf/util/map.c +2 -2
@@ -141,7 +141,7 @@ void map__init(struct map *map, enum map_type type,struct map *map__new (struct machine *machine,u64 start,u64 len,u64 pgoff,u32 pid,u32 d_maj,u32 d_min,u64 ino,u64 ino_gen,u32 prot,u32 flags,char *filename, -enum map_type type) +enum map_type type,struct thread *thread) {struct map *map =malloc (sizeof (*map));
@@ -174,7 +174,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,if (vdso) { pgoff =0 ; - dso =vdso__dso_findnew (machine); + dso =vdso__dso_findnew (machine, thread); }else dso =__dsos__findnew (&machine->user_dsos, filename);
tools/perf/util/map.h +2 -1
@@ -104,6 +104,7 @@ u64 map__rip_2objdump(struct map *map, u64 rip);u64 map__objdump_2mem (struct map *map,u64 ip);struct symbol ; +struct thread ;/* map__for_each_symbol - iterate over the symbols in the given map *
@@ -122,7 +123,7 @@ void map__init(struct map *map, enum map_type type,struct map *map__new (struct machine *machine,u64 start,u64 len,u64 pgoff,u32 pid,u32 d_maj,u32 d_min,u64 ino,u64 ino_gen,u32 prot,u32 flags, -char *filename,enum map_type type); +char *filename,enum map_type type,struct thread *thread);struct map *map__new2 (u64 start,struct dso *dso,enum map_type type);void map__delete (struct map *map);struct map *map__clone (struct map *map);
tools/perf/util/vdso.c +2 -1
@@ -135,7 +135,8 @@ static struct dso *vdso__new(struct machine *machine, const char *short_name,return dso; } -struct dso *vdso__dso_findnew (struct machine *machine) +struct dso *vdso__dso_findnew (struct machine *machine, +struct thread *thread__maybe_unused ) {struct vdso_info *vdso_info;struct dso *dso;
tools/perf/util/vdso.h +2 -1
@@ -19,8 +19,9 @@ struct dso;bool dso__is_vdso (struct dso *dso);struct machine ; +struct thread ; -struct dso *vdso__dso_findnew (struct machine *machine); +struct dso *vdso__dso_findnew (struct machine *machine,struct thread *thread);void vdso__exit (struct machine *machine);#endif /* __PERF_VDSO__ */
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 21/27 perf tools: Fix build on gcc 4.4.7
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
[acme@sandy linux]$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[acme@sandy linux]$ make O=/tmp/build/perf -C tools/perf install-bin <SNIP>
CC /tmp/build/perf/builtin-trace.obuiltin-trace.c: In function ‘perf_evlist__add_pgfault’:
builtin-trace.c:1997: error: unknown field ‘sample_period’ specified in initializer make[1]: *** [/tmp/build/perf/builtin-trace.o] Error 1
make: *** [install-bin] Error 2
make: Leaving directory `/home/acme/git/linux/tools/perf'
[acme@sandy linux]$ make O=/tmp/build/perf -C tools/perf install-bin make O=/tmp/build/perf -C tools/perf install-bin
make: Entering directory `/home/acme/git/linux/tools/perf'
--- tools/perf/builtin-trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-trace.c +1 -1
@@ -1994,10 +1994,10 @@ static int perf_evlist__add_pgfault(struct perf_evlist *evlist,struct perf_event_attr attr = { .type =PERF_TYPE_SOFTWARE , .mmap_data =1 , - .sample_period =1 , }; attr.config = config; + attr.sample_period =1 ;event_attr_init (&attr);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 22/27 perf powerpc: Include util/util.h and remove stringify macros
In reply to Arnaldo Carvalho de MeloFrom: Sukadev Bhattiprolu <[email protected]>
The stringify macros are defined in tools/perf/util/util.h and don't need to be redfined specfiically for powerpc.
--- tools/perf/arch/powerpc/util/header.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
tools/perf/arch/powerpc/util/header.c +1 -3
@@ -5,9 +5,7 @@#include <string.h> #include "../../util/header.h" - -#define __stringify_1 (x) #x -#define __stringify (x) __stringify_1(x) +#include "../../util/util.h" #define mfspr (rn) ({unsigned long rval; \ asm volatile("mfspr %0," __stringify(rn) \
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 23/27 perf session: Fix accounting of ordered samples queue
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Properly account flushed samples within the ordered samples queue.
--- tools/perf/util/session.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/session.c +1 -2
@@ -509,6 +509,7 @@ static int flush_sample_queue(struct perf_session *s, os->last_flush = iter->timestamp;list_del (&iter->list);list_add (&iter->list, &os->sample_cache); + os->nr_samples--;if (show_progress)ui_progress__update (&prog,1 );
@@ -521,8 +522,6 @@ static int flush_sample_queue(struct perf_session *s, list_entry(head->prev, struct sample_queue, list); } - os->nr_samples =0 ; -return 0 ; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 24/27 perf tools: Expose 'addr' functions so they can be reused
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Move some functions and functionality related to the use of 'addr' out of builtin-script so they can be reused.
The moved functions are: is_bts_event() and sample_addr_correlates_sym() and a new function perf_event__preprocess_sample_addr() is created from bits of print_sample_addr().
perf_event__preprocess_sample_addr() is the equivalent of perf_event__preprocess_sample() but for 'addr' instead of 'ip'.
--- tools/perf/builtin-script.c | 34 +--------------------------------- tools/perf/util/event.c | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/event.h | 10 ++++++++++ 3 files changed, 53 insertions(+), 33 deletions(-)
tools/perf/builtin-script.c +1 -33
@@ -358,27 +358,6 @@ static void print_sample_start(struct perf_sample *sample, } } -static bool is_bts_event (struct perf_event_attr *attr) -{ -return ((attr->type ==PERF_TYPE_HARDWARE ) && - (attr->config &PERF_COUNT_HW_BRANCH_INSTRUCTIONS ) && - (attr->sample_period ==1 )); -} - -static bool sample_addr_correlates_sym (struct perf_event_attr *attr) -{ -if ((attr->type ==PERF_TYPE_SOFTWARE ) && - ((attr->config ==PERF_COUNT_SW_PAGE_FAULTS ) || - (attr->config ==PERF_COUNT_SW_PAGE_FAULTS_MIN ) || - (attr->config ==PERF_COUNT_SW_PAGE_FAULTS_MAJ ))) -return true; - -if (is_bts_event (attr)) -return true; - -return false; -} - static void print_sample_addr(union perf_event *event, struct perf_sample *sample, struct machine *machine,
@@ -386,24 +365,13 @@ static void print_sample_addr(union perf_event *event, struct perf_event_attr *attr) {struct addr_location al; -u8 cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;printf ("%16" PRIx64, sample->addr);if (!sample_addr_correlates_sym (attr))return ; -thread__find_addr_map (thread, machine, cpumode,MAP__FUNCTION , - sample->addr, &al); -if (!al.map) -thread__find_addr_map (thread, machine, cpumode,MAP__VARIABLE , - sample->addr, &al); - - al.cpu = sample->cpu; - al.sym =NULL ; - -if (al.map) - al.sym =map__find_symbol (al.map, al.addr,NULL ); +perf_event__preprocess_sample_addr (event, sample, machine, thread, &al);if (PRINT_FIELD (SYM )) {printf (" " );
tools/perf/util/event.c +42 -0
45 lines not on this page · raw message
tools/perf/util/event.h +10 -0
@@ -288,6 +288,16 @@ int perf_event__preprocess_sample(const union perf_event *event,struct addr_location *al, struct perf_sample *sample); +struct thread ; + +bool is_bts_event (struct perf_event_attr *attr); +bool sample_addr_correlates_sym (struct perf_event_attr *attr); +void perf_event__preprocess_sample_addr (union perf_event *event, +struct perf_sample *sample, +struct machine *machine, +struct thread *thread, +struct addr_location *al); +const char *perf_event__name (unsigned int id); size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 25/27 perf inject: Add --kallsyms parameter
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Let perf inject take --kallsyms parameter the same as perf script and perf report do.
That is needed for decoding Instruction Trace data using a copy of /proc/kcore for the kernel object because the kallsyms path is used to locate that copy.
--- tools/perf/Documentation/perf-inject.txt | 3 +++ tools/perf/builtin-inject.c | 2 ++ 2 files changed, 5 insertions(+)
tools/perf/Documentation/perf-inject.txt +3 -0
@@ -41,6 +41,9 @@ OPTIONS tasks slept. sched_switch contains a callchain where a task slept and sched_stat contains a timeslice how long a task slept. +--kallsyms=<file>:: + kallsyms pathname + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-archive[1]
tools/perf/builtin-inject.c +2 -0
@@ -439,6 +439,8 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) "where and how long tasks slept"),OPT_INCR ('v' ,"verbose" , &verbose,"be more verbose (show build ids, etc)" ), +OPT_STRING (0 ,"kallsyms" , &symbol_conf.kallsyms_name,"file" , +"kallsyms pathname" ),OPT_END () }; const char * const inject_usage[] = {
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 26/27 perf record: Always force PERF_RECORD_FINISHED_ROUND event
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
The PERF_RECORD_FINISHED_ROUND synthetic record governs queue flushing in reporting, so it needs to be stored for any kind of event.
The lack of such periodic flushing made the tools use more memory than needed, as the reordering was being done only after processing all events. This was the case when no tracepoints were in the mix.
Forcing the PERF_RECORD_FINISHED_ROUND event to be stored for all event types.
--- tools/perf/builtin-record.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/builtin-record.c +1 -2
@@ -250,8 +250,7 @@ static int record__mmap_read_all(struct record *rec) } } -if (perf_header__has_feat (&rec->session->header,HEADER_TRACING_DATA )) - rc =record__write (rec, &finished_round_event,sizeof (finished_round_event)); + rc =record__write (rec, &finished_round_event,sizeof (finished_round_event)); out:return rc;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 27/27 perf record: Store PERF_RECORD_FINISHED_ROUND only for nonempty rounds
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Currently we store PERF_RECORD_FINISHED_ROUND event each time we go throught mmap buffers no matter if it contains any data, which is useless.
Forcing the PERF_RECORD_FINISHED_ROUND event to be stored any time we finished the round AND wrote at least one event.
--- tools/perf/builtin-record.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/builtin-record.c +7 -1
@@ -238,6 +238,7 @@ static struct perf_event_header finished_round_event = {static int record__mmap_read_all (struct record *rec) { +u64 bytes_written = rec->bytes_written;int i;int rc =0 ;
@@ -250,7 +251,12 @@ static int record__mmap_read_all(struct record *rec) } } - rc =record__write (rec, &finished_round_event,sizeof (finished_round_event)); +/* +* Mark the round finished in case we wrote +* at least one event. +*/ +if (bytes_written != rec->bytes_written) + rc =record__write (rec, &finished_round_event,sizeof (finished_round_event)); out:return rc;
Signature · 1 line
1.9.3
Quoted 97 lines · Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling,
- Arnaldo
The following changes since commit
2336ebc32676df5b794acfe0c980583ec6c05f34:Merge tag 'perf-core-for-mingo' of
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perfinto perf/core (2014-07-18 12:19:20 +0200)are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-core-for-mingofor you to fetch changes up to
dcabb507fd3a2b19aed6b4068e2a954f5fd8de45:perf record: Store
PERF_RECORD_FINISHED_ROUNDonly for nonempty rounds (2014-07-25 12:17:36 -0300)----------------------------------------------------------------
perf/core improvements and fixes:Developer stuff:
o More prep work to support Intel PT: (Adrian Hunter)
- Polishing 'script' BTS output
- 'inject' can specify --kallsym
- VDSO is per machine, not a global var
- Expose data addr lookup functions previously private to 'script'
- Large mmap fixes in events processingo Fix build on gcc 4.4.7 (Arnaldo Carvalho de Melo)
o Event ordering fixes (Jiri Olsa)
o Include standard stringify macros in power pc code (Sukadev Bhattiprolu)
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Adrian Hunter (22):
perf tools: Fix incorrect fd error comparison
perf tools: Fix jump label always changing during tracing perf script: Improve srcline display for BTS
perf script: Do not print dangling '=>' for BTS
perf tools: Record whether a dso has data
perf tools: Adddso__data_status_seen()
perf tools: Adddsos__hit_all()
perf tools: Add cpu to struct thread
perf machine: Add ability to record the current tid for each cpu perf tools: Moverdtsc()function
perf tools: Adddso__data_size()
perf tools: Pass machine tovdso__dso_findnew()
perf session: Add ability to 'skip' a non-piped event stream perf session: Add ability to skip 4GiB or more
perf tools: Group VDSO global variables into a structure perf machine: Fix the lifetime of the VDSO temporary file perf tools: Addvdso__new()
perf tools: Separate the VDSO map name from the VDSO dso name perf tools: Adddso__type()
perf tools: Add thread parameter tovdso__dso_findnew()perf tools: Expose 'addr' functions so they can be reused perf inject: Add --kallsyms parameterArnaldo Carvalho de Melo (1):
perf tools: Fix build on gcc 4.4.7Jiri Olsa (3):
perf session: Fix accounting of ordered samples queue
perf record: Always forcePERF_RECORD_FINISHED_ROUNDevent perf record: StorePERF_RECORD_FINISHED_ROUNDonly for nonempty roundsSukadev Bhattiprolu (1):
perf powerpc: Includeutil/util.hand remove stringify macrostools/perf/Documentation/perf-inject.txt | 3 + tools/perf/arch/powerpc/util/header.c | 4 +- tools/perf/arch/x86/util/tsc.c | 9 +++ tools/perf/builtin-inject.c | 2 + tools/perf/builtin-record.c | 7 ++- tools/perf/builtin-script.c | 60 +++++++------------- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/perf-time-to-tsc.c | 9 --- tools/perf/util/cloexec.c | 9 ++- tools/perf/util/dso.c | 70 ++++++++++++++++++++--- tools/perf/util/dso.h | 25 +++++++++ tools/perf/util/event.c | 42 ++++++++++++++ tools/perf/util/event.h | 10 ++++ tools/perf/util/header.c | 51 +++++++++++++++-- tools/perf/util/header.h | 2 + tools/perf/util/machine.c | 58 +++++++++++++++++-- tools/perf/util/machine.h | 8 +++ tools/perf/util/map.c | 9 +-- tools/perf/util/map.h | 5 +- tools/perf/util/session.c | 25 +++++---- tools/perf/util/symbol-elf.c | 35 +++++++++++- tools/perf/util/symbol-minimal.c | 21 +++++++
Quoted 8 lines
tools/perf/util/symbol.h | 2 + tools/perf/util/thread.c | 1 + tools/perf/util/thread.h | 1 + tools/perf/util/tsc.c | 5 ++ tools/perf/util/tsc.h | 1 + tools/perf/util/vdso.c | 96 +++++++++++++++++++++++++------- tools/perf/util/vdso.h | 13 ++++- 29 files changed, 470 insertions(+), 115 deletions(-)
Pulled, thanks a lot Arnaldo!
Ingo