perf intel-pt: Add support for synthesizing branch stacks for regular events
Adrian Hunter
reviewercover perf intel-pt: Add support for synthesizing branch stacks for regular events
Hi
This patchset adds Intel PT support for synthesizing branch stacks for regular events. This follows on from the patchset that did the same thing for call chains.
The first 3 patches convert Intel PT to using thread-stack to record branch stacks, which allows branch stacks to be accumulated separately for each thread.
The next 3 patches add support for synthesizing branch stacks for regular events.
The final 2 patches update some documentation.
Adrian Hunter (9):
perf thread-stack: Add branch stack support
perf intel-pt: Consolidate thread-stack use condition
perf intel-pt: Change branch stack support to use thread-stacks perf auxtrace: Add option to synthesize branch stack for regular events perf evsel: Add support for synthesized branch stack sample type perf thread-stack: Add thread_stack__br_sample_late()
perf intel-pt: Add support for synthesizing branch stacks for regular events perf intel-pt: Update documentation about itrace G and L options perf intel-pt: Update documentation about using /proc/kcore
tools/perf/Documentation/itrace.txt | 5 + tools/perf/Documentation/perf-intel-pt.txt | 53 +++++-- tools/perf/builtin-inject.c | 3 +- tools/perf/builtin-report.c | 5 +- tools/perf/util/auxtrace.c | 6 +- tools/perf/util/auxtrace.h | 2 + tools/perf/util/evsel.h | 10 ++ tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 210 ++++++++++++++-------------- tools/perf/util/s390-cpumsf.c | 3 +- tools/perf/util/session.c | 2 +- tools/perf/util/thread-stack.c | 217 +++++++++++++++++++++++++++-- tools/perf/util/thread-stack.h | 8 +- 13 files changed, 393 insertions(+), 133 deletions(-)
Regards
Adrian
Adrian Hunter
reviewerPATCH 1/9 perf thread-stack: Add branch stack support
Intel PT already has support for creating branch stacks for each context (per-cpu or per-thread). In the more common per-cpu case, the branch stack is not separated for different threads, instead being cleared in between each sample. That approach will not work very well for adding branch stacks to regular events. The branch stacks really need to be accumulated separately for each thread.
As a start to accomplishing that, this patch adds support for putting branch stack support into the thread-stack. The advantages are:
1. the branches are accumulated separately for each thread
2. the branch stack is cleared only in between continuous traces
This helps pave the way for adding branch stacks to regular events, not just synthesized events as at present.
--- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/thread-stack.c | 113 +++++++++++++++++++++++++++++---- tools/perf/util/thread-stack.h | 5 +- 4 files changed, 108 insertions(+), 14 deletions(-)
tools/perf/util/intel-bts.c +1 -1
@@ -432,7 +432,7 @@ static int intel_bts_process_buffer(struct intel_bts_queue *btsq,le64_to_cpu (branch->from),le64_to_cpu (branch->to), btsq->intel_pt_insn.length, - buffer->buffer_nr + 1); + buffer->buffer_nr + 1, true, 0, 0);if (filter && !(filter & btsq->sample_flags))continue ; err =intel_bts_synth_branch_sample (btsq, branch);
tools/perf/util/intel-pt.c +1 -1
@@ -2032,7 +2032,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) pt->synth_opts.thread_stack)thread_stack__event (ptq->thread, ptq->cpu, ptq->flags, state->from_ip, state->to_ip, ptq->insn_len, - state->trace_nr); + state->trace_nr, true,0 ,0 ); else thread_stack__set_trace_nr(ptq->thread, ptq->cpu, state->trace_nr);
tools/perf/util/thread-stack.c +102 -11
194 lines not on this page · raw message
tools/perf/util/thread-stack.h +4 -1
@@ -81,13 +81,16 @@ struct call_return_processor { };int thread_stack__event (struct thread *thread,int cpu,u32 flags,u64 from_ip, -u64 to_ip,u16 insn_len,u64 trace_nr); +u64 to_ip,u16 insn_len,u64 trace_nr,bool callstack, +unsigned int br_stack_sz,bool mispred_all);void thread_stack__set_trace_nr (struct thread *thread,int cpu,u64 trace_nr);void thread_stack__sample (struct thread *thread,int cpu,struct ip_callchain *chain,size_t sz,u64 ip,u64 kernel_start);void thread_stack__sample_late (struct thread *thread,int cpu,struct ip_callchain *chain,size_t sz,u64 ip,u64 kernel_start); +void thread_stack__br_sample (struct thread *thread,int cpu, +struct branch_stack *dst,unsigned int sz);int thread_stack__flush (struct thread *thread);void thread_stack__free (struct thread *thread);size_t thread_stack__depth (struct thread *thread,int cpu);
Signature · 1 line
2.17.1
[tip: perf/core] perf thread-stack: Add branch stack support
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 86d67180b920d178ae1c2923f50a0759d6ce1a10 Gitweb: https://git.kernel.org/tip/86d67180b920d178ae1c2923f50a0759d6ce1a10 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 29 Apr 2020 18:07:43 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf thread-stack: Add branch stack support
Intel PT already has support for creating branch stacks for each context (per-cpu or per-thread). In the more common per-cpu case, the branch stack is not separated for different threads, instead being cleared in between each sample.
That approach will not work very well for adding branch stacks to regular events. The branch stacks really need to be accumulated separately for each thread.
As a start to accomplishing that, this patch adds support for putting branch stack support into the thread-stack. The advantages are:
1. the branches are accumulated separately for each thread
2. the branch stack is cleared only in between continuous traces
This helps pave the way for adding branch stacks to regular events, not just synthesized events as at present.
--- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/thread-stack.c | 113 ++++++++++++++++++++++++++++---- tools/perf/util/thread-stack.h | 5 +- 4 files changed, 108 insertions(+), 14 deletions(-)
tools/perf/util/intel-bts.c +1 -1
@@ -432,7 +432,7 @@ static int intel_bts_process_buffer(struct intel_bts_queue *btsq,le64_to_cpu (branch->from),le64_to_cpu (branch->to), btsq->intel_pt_insn.length, - buffer->buffer_nr + 1); + buffer->buffer_nr + 1, true, 0, 0);if (filter && !(filter & btsq->sample_flags))continue ; err =intel_bts_synth_branch_sample (btsq, branch);
tools/perf/util/intel-pt.c +1 -1
@@ -2033,7 +2033,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) pt->synth_opts.thread_stack)thread_stack__event (ptq->thread, ptq->cpu, ptq->flags, state->from_ip, state->to_ip, ptq->insn_len, - state->trace_nr); + state->trace_nr, true,0 ,0 ); else thread_stack__set_trace_nr(ptq->thread, ptq->cpu, state->trace_nr);
tools/perf/util/thread-stack.c +102 -11
194 lines not on this page · raw message
tools/perf/util/thread-stack.h +4 -1
@@ -81,13 +81,16 @@ struct call_return_processor { };int thread_stack__event (struct thread *thread,int cpu,u32 flags,u64 from_ip, -u64 to_ip,u16 insn_len,u64 trace_nr); +u64 to_ip,u16 insn_len,u64 trace_nr,bool callstack, +unsigned int br_stack_sz,bool mispred_all);void thread_stack__set_trace_nr (struct thread *thread,int cpu,u64 trace_nr);void thread_stack__sample (struct thread *thread,int cpu,struct ip_callchain *chain,size_t sz,u64 ip,u64 kernel_start);void thread_stack__sample_late (struct thread *thread,int cpu,struct ip_callchain *chain,size_t sz,u64 ip,u64 kernel_start); +void thread_stack__br_sample (struct thread *thread,int cpu, +struct branch_stack *dst,unsigned int sz);int thread_stack__flush (struct thread *thread);void thread_stack__free (struct thread *thread);size_t thread_stack__depth (struct thread *thread,int cpu);
Adrian Hunter
reviewerPATCH 2/9 perf intel-pt: Consolidate thread-stack use condition
In reply to Adrian HunterThe components of the condition do not change, so consolidate them in one variable.
--- tools/perf/util/intel-pt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt.c +6 -2
@@ -68,6 +68,7 @@ struct intel_pt {bool est_tsc;bool sync_switch;bool mispred_all; +bool use_thread_stack;int have_sched_switch;u32 pmu_type;u64 kernel_start;
@@ -2028,8 +2029,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)if (!(state->type &INTEL_PT_BRANCH ))return 0 ; -if (pt->synth_opts.callchain || pt->synth_opts.add_callchain || - pt->synth_opts.thread_stack) +if (pt->use_thread_stack)thread_stack__event (ptq->thread, ptq->cpu, ptq->flags, state->from_ip, state->to_ip, ptq->insn_len, state->trace_nr, true,0 ,0 );
@@ -3440,6 +3440,10 @@ int intel_pt_process_auxtrace_info(union perf_event *event, goto err_delete_thread; } + pt->use_thread_stack = pt->synth_opts.callchain || + pt->synth_opts.add_callchain || + pt->synth_opts.thread_stack; + err =intel_pt_synth_events (pt, session);if (err) goto err_delete_thread;
Signature · 1 line
2.17.1
[tip: perf/core] perf intel-pt: Consolidate thread-stack use condition
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 1ef998ff1823c8b5b3f7d103ec3971d7baaf677b Gitweb: https://git.kernel.org/tip/1ef998ff1823c8b5b3f7d103ec3971d7baaf677b Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 29 Apr 2020 18:07:44 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf intel-pt: Consolidate thread-stack use condition
The components of the condition do not change, so consolidate them in one variable.
--- tools/perf/util/intel-pt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt.c +6 -2
@@ -69,6 +69,7 @@ struct intel_pt {bool est_tsc;bool sync_switch;bool mispred_all; +bool use_thread_stack;int have_sched_switch;u32 pmu_type;u64 kernel_start;
@@ -2029,8 +2030,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)if (!(state->type &INTEL_PT_BRANCH ))return 0 ; -if (pt->synth_opts.callchain || pt->synth_opts.add_callchain || - pt->synth_opts.thread_stack) +if (pt->use_thread_stack)thread_stack__event (ptq->thread, ptq->cpu, ptq->flags, state->from_ip, state->to_ip, ptq->insn_len, state->trace_nr, true,0 ,0 );
@@ -3441,6 +3441,10 @@ int intel_pt_process_auxtrace_info(union perf_event *event, goto err_delete_thread; } + pt->use_thread_stack = pt->synth_opts.callchain || + pt->synth_opts.add_callchain || + pt->synth_opts.thread_stack; + err =intel_pt_synth_events (pt, session);if (err) goto err_delete_thread;
Adrian Hunter
reviewerPATCH 3/9 perf intel-pt: Change branch stack support to use thread-stacks
In reply to Adrian HunterChange Intel PT's branch stack support to use thread stacks. The advantages of using branch stack support from the thread-stack are:
1. the branches are accumulated separately for each thread
2. the branch stack is cleared only in between continuous traces
This helps pave the way for adding branch stacks to regular events, not just synthesized events as at present.
While the 2 approaches are not identical, in simple cases the results can be identical e.g.
Before:
# perf record --kcore -e intel_pt// uname
# perf script --itrace=i10usl -F+brstacksym,+addr,+flags > cmp1.txtAfter:
# perf script --itrace=i10usl -F+brstacksym,+addr,+flags > cmp2.txt
# diff -s cmp1.txt cmp2.txt
Files cmp1.txt and cmp2.txt are identical--- tools/perf/util/intel-pt.c | 141 ++++++++++--------------------------- 1 file changed, 39 insertions(+), 102 deletions(-)
tools/perf/util/intel-pt.c +39 -102
@@ -69,6 +69,8 @@ struct intel_pt {bool sync_switch;bool mispred_all;bool use_thread_stack; +bool callstack; +unsigned int br_stack_sz;int have_sched_switch;u32 pmu_type;u64 kernel_start;
@@ -146,8 +148,6 @@ struct intel_pt_queue {const struct intel_pt_state *state;struct ip_callchain *chain;struct branch_stack *last_branch; -struct branch_stack *last_branch_rb; -size_t last_branch_pos;union perf_event *event_buf;bool on_heap;bool stop;
@@ -930,14 +930,10 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,if (pt->synth_opts.last_branch) {size_t sz =sizeof (struct branch_stack ); - sz += pt->synth_opts.last_branch_sz * -sizeof (struct branch_entry ); + sz += pt->br_stack_sz *sizeof (struct branch_entry ); ptq->last_branch =zalloc (sz);if (!ptq->last_branch) goto out_free; - ptq->last_branch_rb =zalloc (sz); -if (!ptq->last_branch_rb) - goto out_free; } ptq->event_buf =malloc (PERF_SAMPLE_MAX_SIZE );
@@ -1006,7 +1002,6 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, out_free:zfree (&ptq->event_buf);zfree (&ptq->last_branch); -zfree (&ptq->last_branch_rb);zfree (&ptq->chain);free (ptq);return NULL ;
@@ -1022,7 +1017,6 @@ static void intel_pt_free_queue(void *priv)intel_pt_decoder_free (ptq->decoder);zfree (&ptq->event_buf);zfree (&ptq->last_branch); -zfree (&ptq->last_branch_rb);zfree (&ptq->chain);free (ptq); }
@@ -1190,58 +1184,6 @@ static int intel_pt_setup_queues(struct intel_pt *pt)return 0 ; } -static inline void intel_pt_copy_last_branch_rb (struct intel_pt_queue *ptq) -{ -struct branch_stack *bs_src = ptq->last_branch_rb; -struct branch_stack *bs_dst = ptq->last_branch; -size_t nr =0 ; - - bs_dst->nr = bs_src->nr; - -if (!bs_src->nr) -return ; - - nr = ptq->pt->synth_opts.last_branch_sz - ptq->last_branch_pos; -memcpy (&bs_dst->entries[0 ], - &bs_src->entries[ptq->last_branch_pos], -sizeof (struct branch_entry ) * nr); - -if (bs_src->nr >= ptq->pt->synth_opts.last_branch_sz) { -memcpy (&bs_dst->entries[nr], - &bs_src->entries[0 ], -sizeof (struct branch_entry ) * ptq->last_branch_pos); - } -} - -static inline void intel_pt_reset_last_branch_rb (struct intel_pt_queue *ptq) -{ - ptq->last_branch_pos =0 ; - ptq->last_branch_rb->nr =0 ; -} - -static void intel_pt_update_last_branch_rb (struct intel_pt_queue *ptq) -{ -const struct intel_pt_state *state = ptq->state; -struct branch_stack *bs = ptq->last_branch_rb; -struct branch_entry *be; - -if (!ptq->last_branch_pos) - ptq->last_branch_pos = ptq->pt->synth_opts.last_branch_sz; - - ptq->last_branch_pos -=1 ; - - be = &bs->entries[ptq->last_branch_pos]; - be->from = state->from_ip; - be->to = state->to_ip; - be->flags.abort = !!(state->flags &INTEL_PT_ABORT_TX ); - be->flags.in_tx = !!(state->flags &INTEL_PT_IN_TX ); -/* No support for mispredict */ - be->flags.mispred = ptq->pt->mispred_all; - -if (bs->nr < ptq->pt->synth_opts.last_branch_sz) - bs->nr +=1 ; -} -static inline bool intel_pt_skip_event (struct intel_pt *pt) { return pt->synth_opts.initial_skip &&
@@ -1309,9 +1251,9 @@ static inline int intel_pt_opt_inject(struct intel_pt *pt,return intel_pt_inject_event (event, sample, type); } -static int intel_pt_deliver_synth_b_event (struct intel_pt *pt, -union perf_event *event, -struct perf_sample *sample,u64 type) +static int intel_pt_deliver_synth_event (struct intel_pt *pt, +union perf_event *event, +struct perf_sample *sample,u64 type) {int ret;
@@ -1371,8 +1313,8 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq) ptq->last_br_cyc_cnt = ptq->ipc_cyc_cnt; } -return intel_pt_deliver_synth_b_event (pt, event, &sample, - pt->branches_sample_type); +return intel_pt_deliver_synth_event (pt, event, &sample, + pt->branches_sample_type); } static void intel_pt_prep_sample(struct intel_pt *pt,
@@ -1390,27 +1332,12 @@ static void intel_pt_prep_sample(struct intel_pt *pt, }if (pt->synth_opts.last_branch) { -intel_pt_copy_last_branch_rb (ptq); +thread_stack__br_sample (ptq->thread, ptq->cpu, ptq->last_branch, + pt->br_stack_sz); sample->branch_stack = ptq->last_branch; } } -static inline int intel_pt_deliver_synth_event (struct intel_pt *pt, -struct intel_pt_queue *ptq, -union perf_event *event, -struct perf_sample *sample, -u64 type) -{ -int ret; - - ret =intel_pt_deliver_synth_b_event (pt, event, sample, type); - -if (pt->synth_opts.last_branch) -intel_pt_reset_last_branch_rb (ptq); - -return ret; -} -static int intel_pt_synth_instruction_sample (struct intel_pt_queue *ptq) {struct intel_pt *pt = ptq->pt;
@@ -1435,7 +1362,7 @@ static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq) ptq->last_insn_cnt = ptq->state->tot_insn_cnt; -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->instructions_sample_type); }
@@ -1453,7 +1380,7 @@ static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq) sample.id = ptq->pt->transactions_id; sample.stream_id = ptq->pt->transactions_id; -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->transactions_sample_type); }
@@ -1494,7 +1421,7 @@ static int intel_pt_synth_ptwrite_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->ptwrites_sample_type); }
@@ -1524,7 +1451,7 @@ static int intel_pt_synth_cbr_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->pwr_events_sample_type); }
@@ -1549,7 +1476,7 @@ static int intel_pt_synth_mwait_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->pwr_events_sample_type); }
@@ -1574,7 +1501,7 @@ static int intel_pt_synth_pwre_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->pwr_events_sample_type); }
@@ -1599,7 +1526,7 @@ static int intel_pt_synth_exstop_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->pwr_events_sample_type); }
@@ -1624,7 +1551,7 @@ static int intel_pt_synth_pwrx_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->pwr_events_sample_type); }
@@ -1844,7 +1771,9 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq)intel_pt_add_lbrs (&br.br_stack, items); sample.branch_stack = &br.br_stack; }else if (pt->synth_opts.last_branch) { -intel_pt_copy_last_branch_rb (ptq); +thread_stack__br_sample (ptq->thread, ptq->cpu, + ptq->last_branch, + pt->br_stack_sz); sample.branch_stack = ptq->last_branch; }else { br.br_stack.nr =0 ;
@@ -1879,7 +1808,7 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq) sample.transaction = txn; } -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, sample_type); +return intel_pt_deliver_synth_event (pt, event, &sample, sample_type); } static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
@@ -2029,12 +1958,15 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)if (!(state->type &INTEL_PT_BRANCH ))return 0 ; -if (pt->use_thread_stack) -thread_stack__event (ptq->thread, ptq->cpu, ptq->flags, state->from_ip, - state->to_ip, ptq->insn_len, - state->trace_nr, true,0 ,0 ); -else +if (pt->use_thread_stack) { +thread_stack__event (ptq->thread, ptq->cpu, ptq->flags, + state->from_ip, state->to_ip, ptq->insn_len, + state->trace_nr, pt->callstack, + pt->br_stack_sz, + pt->mispred_all); + }else {thread_stack__set_trace_nr (ptq->thread, ptq->cpu, state->trace_nr); + }if (pt->sample_branches) { err =intel_pt_synth_branch_sample (ptq);
@@ -2042,9 +1974,6 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)return err; } -if (pt->synth_opts.last_branch) -intel_pt_update_last_branch_rb (ptq); -if (!ptq->sync_switch)return 0 ;
@@ -3440,9 +3369,17 @@ int intel_pt_process_auxtrace_info(union perf_event *event, goto err_delete_thread; } +if (pt->synth_opts.last_branch) + pt->br_stack_sz = pt->synth_opts.last_branch_sz; + pt->use_thread_stack = pt->synth_opts.callchain || pt->synth_opts.add_callchain || - pt->synth_opts.thread_stack; + pt->synth_opts.thread_stack || + pt->synth_opts.last_branch; + + pt->callstack = pt->synth_opts.callchain || + pt->synth_opts.add_callchain || + pt->synth_opts.thread_stack; err =intel_pt_synth_events (pt, session);if (err)
Signature · 1 line
2.17.1
[tip: perf/core] perf intel-pt: Change branch stack support to use thread-stacks
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: cf888e08a030b7430889d0c5c804508c09dad843 Gitweb: https://git.kernel.org/tip/cf888e08a030b7430889d0c5c804508c09dad843 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 29 Apr 2020 18:07:45 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf intel-pt: Change branch stack support to use thread-stacks
Change Intel PT's branch stack support to use thread stacks. The advantages of using branch stack support from the thread-stack are:
1. the branches are accumulated separately for each thread
2. the branch stack is cleared only in between continuous traces
This helps pave the way for adding branch stacks to regular events, not just synthesized events as at present.
While the 2 approaches are not identical, in simple cases the results can be identical e.g.
Before:
# perf record --kcore -e intel_pt// uname
# perf script --itrace=i10usl -F+brstacksym,+addr,+flags > cmp1.txtAfter:
# perf script --itrace=i10usl -F+brstacksym,+addr,+flags > cmp2.txt
# diff -s cmp1.txt cmp2.txt
Files cmp1.txt and cmp2.txt are identical--- tools/perf/util/intel-pt.c | 141 +++++++++--------------------------- 1 file changed, 39 insertions(+), 102 deletions(-)
tools/perf/util/intel-pt.c +39 -102
@@ -70,6 +70,8 @@ struct intel_pt {bool sync_switch;bool mispred_all;bool use_thread_stack; +bool callstack; +unsigned int br_stack_sz;int have_sched_switch;u32 pmu_type;u64 kernel_start;
@@ -147,8 +149,6 @@ struct intel_pt_queue {const struct intel_pt_state *state;struct ip_callchain *chain;struct branch_stack *last_branch; -struct branch_stack *last_branch_rb; -size_t last_branch_pos;union perf_event *event_buf;bool on_heap;bool stop;
@@ -931,14 +931,10 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,if (pt->synth_opts.last_branch) {size_t sz =sizeof (struct branch_stack ); - sz += pt->synth_opts.last_branch_sz * -sizeof (struct branch_entry ); + sz += pt->br_stack_sz *sizeof (struct branch_entry ); ptq->last_branch =zalloc (sz);if (!ptq->last_branch) goto out_free; - ptq->last_branch_rb =zalloc (sz); -if (!ptq->last_branch_rb) - goto out_free; } ptq->event_buf =malloc (PERF_SAMPLE_MAX_SIZE );
@@ -1007,7 +1003,6 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, out_free:zfree (&ptq->event_buf);zfree (&ptq->last_branch); -zfree (&ptq->last_branch_rb);zfree (&ptq->chain);free (ptq);return NULL ;
@@ -1023,7 +1018,6 @@ static void intel_pt_free_queue(void *priv)intel_pt_decoder_free (ptq->decoder);zfree (&ptq->event_buf);zfree (&ptq->last_branch); -zfree (&ptq->last_branch_rb);zfree (&ptq->chain);free (ptq); }
@@ -1191,58 +1185,6 @@ static int intel_pt_setup_queues(struct intel_pt *pt)return 0 ; } -static inline void intel_pt_copy_last_branch_rb (struct intel_pt_queue *ptq) -{ -struct branch_stack *bs_src = ptq->last_branch_rb; -struct branch_stack *bs_dst = ptq->last_branch; -size_t nr =0 ; - - bs_dst->nr = bs_src->nr; - -if (!bs_src->nr) -return ; - - nr = ptq->pt->synth_opts.last_branch_sz - ptq->last_branch_pos; -memcpy (&bs_dst->entries[0 ], - &bs_src->entries[ptq->last_branch_pos], -sizeof (struct branch_entry ) * nr); - -if (bs_src->nr >= ptq->pt->synth_opts.last_branch_sz) { -memcpy (&bs_dst->entries[nr], - &bs_src->entries[0 ], -sizeof (struct branch_entry ) * ptq->last_branch_pos); - } -} - -static inline void intel_pt_reset_last_branch_rb (struct intel_pt_queue *ptq) -{ - ptq->last_branch_pos =0 ; - ptq->last_branch_rb->nr =0 ; -} - -static void intel_pt_update_last_branch_rb (struct intel_pt_queue *ptq) -{ -const struct intel_pt_state *state = ptq->state; -struct branch_stack *bs = ptq->last_branch_rb; -struct branch_entry *be; - -if (!ptq->last_branch_pos) - ptq->last_branch_pos = ptq->pt->synth_opts.last_branch_sz; - - ptq->last_branch_pos -=1 ; - - be = &bs->entries[ptq->last_branch_pos]; - be->from = state->from_ip; - be->to = state->to_ip; - be->flags.abort = !!(state->flags &INTEL_PT_ABORT_TX ); - be->flags.in_tx = !!(state->flags &INTEL_PT_IN_TX ); -/* No support for mispredict */ - be->flags.mispred = ptq->pt->mispred_all; - -if (bs->nr < ptq->pt->synth_opts.last_branch_sz) - bs->nr +=1 ; -} -static inline bool intel_pt_skip_event (struct intel_pt *pt) { return pt->synth_opts.initial_skip &&
@@ -1310,9 +1252,9 @@ static inline int intel_pt_opt_inject(struct intel_pt *pt,return intel_pt_inject_event (event, sample, type); } -static int intel_pt_deliver_synth_b_event (struct intel_pt *pt, -union perf_event *event, -struct perf_sample *sample,u64 type) +static int intel_pt_deliver_synth_event (struct intel_pt *pt, +union perf_event *event, +struct perf_sample *sample,u64 type) {int ret;
@@ -1372,8 +1314,8 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq) ptq->last_br_cyc_cnt = ptq->ipc_cyc_cnt; } -return intel_pt_deliver_synth_b_event (pt, event, &sample, - pt->branches_sample_type); +return intel_pt_deliver_synth_event (pt, event, &sample, + pt->branches_sample_type); } static void intel_pt_prep_sample(struct intel_pt *pt,
@@ -1391,27 +1333,12 @@ static void intel_pt_prep_sample(struct intel_pt *pt, }if (pt->synth_opts.last_branch) { -intel_pt_copy_last_branch_rb (ptq); +thread_stack__br_sample (ptq->thread, ptq->cpu, ptq->last_branch, + pt->br_stack_sz); sample->branch_stack = ptq->last_branch; } } -static inline int intel_pt_deliver_synth_event (struct intel_pt *pt, -struct intel_pt_queue *ptq, -union perf_event *event, -struct perf_sample *sample, -u64 type) -{ -int ret; - - ret =intel_pt_deliver_synth_b_event (pt, event, sample, type); - -if (pt->synth_opts.last_branch) -intel_pt_reset_last_branch_rb (ptq); - -return ret; -} -static int intel_pt_synth_instruction_sample (struct intel_pt_queue *ptq) {struct intel_pt *pt = ptq->pt;
@@ -1436,7 +1363,7 @@ static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq) ptq->last_insn_cnt = ptq->state->tot_insn_cnt; -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->instructions_sample_type); }
@@ -1454,7 +1381,7 @@ static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq) sample.id = ptq->pt->transactions_id; sample.stream_id = ptq->pt->transactions_id; -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->transactions_sample_type); }
@@ -1495,7 +1422,7 @@ static int intel_pt_synth_ptwrite_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->ptwrites_sample_type); }
@@ -1525,7 +1452,7 @@ static int intel_pt_synth_cbr_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->pwr_events_sample_type); }
@@ -1550,7 +1477,7 @@ static int intel_pt_synth_mwait_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->pwr_events_sample_type); }
@@ -1575,7 +1502,7 @@ static int intel_pt_synth_pwre_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->pwr_events_sample_type); }
@@ -1600,7 +1527,7 @@ static int intel_pt_synth_exstop_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->pwr_events_sample_type); }
@@ -1625,7 +1552,7 @@ static int intel_pt_synth_pwrx_sample(struct intel_pt_queue *ptq) sample.raw_size =perf_synth__raw_size (raw); sample.raw_data =perf_synth__raw_data (&raw); -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, +return intel_pt_deliver_synth_event (pt, event, &sample, pt->pwr_events_sample_type); }
@@ -1845,7 +1772,9 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq)intel_pt_add_lbrs (&br.br_stack, items); sample.branch_stack = &br.br_stack; }else if (pt->synth_opts.last_branch) { -intel_pt_copy_last_branch_rb (ptq); +thread_stack__br_sample (ptq->thread, ptq->cpu, + ptq->last_branch, + pt->br_stack_sz); sample.branch_stack = ptq->last_branch; }else { br.br_stack.nr =0 ;
@@ -1880,7 +1809,7 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq) sample.transaction = txn; } -return intel_pt_deliver_synth_event (pt, ptq, event, &sample, sample_type); +return intel_pt_deliver_synth_event (pt, event, &sample, sample_type); } static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
@@ -2030,12 +1959,15 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)if (!(state->type &INTEL_PT_BRANCH ))return 0 ; -if (pt->use_thread_stack) -thread_stack__event (ptq->thread, ptq->cpu, ptq->flags, state->from_ip, - state->to_ip, ptq->insn_len, - state->trace_nr, true,0 ,0 ); -else +if (pt->use_thread_stack) { +thread_stack__event (ptq->thread, ptq->cpu, ptq->flags, + state->from_ip, state->to_ip, ptq->insn_len, + state->trace_nr, pt->callstack, + pt->br_stack_sz, + pt->mispred_all); + }else {thread_stack__set_trace_nr (ptq->thread, ptq->cpu, state->trace_nr); + }if (pt->sample_branches) { err =intel_pt_synth_branch_sample (ptq);
@@ -2043,9 +1975,6 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)return err; } -if (pt->synth_opts.last_branch) -intel_pt_update_last_branch_rb (ptq); -if (!ptq->sync_switch)return 0 ;
@@ -3441,9 +3370,17 @@ int intel_pt_process_auxtrace_info(union perf_event *event, goto err_delete_thread; } +if (pt->synth_opts.last_branch) + pt->br_stack_sz = pt->synth_opts.last_branch_sz; + pt->use_thread_stack = pt->synth_opts.callchain || pt->synth_opts.add_callchain || - pt->synth_opts.thread_stack; + pt->synth_opts.thread_stack || + pt->synth_opts.last_branch; + + pt->callstack = pt->synth_opts.callchain || + pt->synth_opts.add_callchain || + pt->synth_opts.thread_stack; err =intel_pt_synth_events (pt, session);if (err)
Adrian Hunter
reviewerPATCH 4/9 perf auxtrace: Add option to synthesize branch stack for regular events
In reply to Adrian HunterThere is an existing option to synthesize branch stacks for synthesized events. Add a new option to synthesize branch stacks for regular events.
--- tools/perf/Documentation/itrace.txt | 1 + tools/perf/builtin-inject.c | 3 ++- tools/perf/builtin-report.c | 5 +++-- tools/perf/util/auxtrace.c | 6 +++++- tools/perf/util/auxtrace.h | 2 ++ tools/perf/util/s390-cpumsf.c | 3 ++- 6 files changed, 15 insertions(+), 5 deletions(-)
tools/perf/Documentation/itrace.txt +1 -0
@@ -12,6 +12,7 @@ g synthesize a call chain (use with i or x) G synthesize a call chain on existing event records l synthesize last branch entries (use with i or x) + L synthesize last branch entries on existing event records s skip initial number of events The default is all events i.e. the same as --itrace=ibxwpe,
tools/perf/builtin-inject.c +2 -1
@@ -684,7 +684,8 @@ static int __cmd_inject(struct perf_inject *inject)perf_header__clear_feat (&session->header,HEADER_AUXTRACE ); -if (inject->itrace_synth_opts.last_branch) +if (inject->itrace_synth_opts.last_branch || + inject->itrace_synth_opts.add_last_branch)perf_header__set_feat (&session->header,HEADER_BRANCH_STACK ); evsel = perf_evlist__id2evsel_strict(session->evlist,
tools/perf/builtin-report.c +3 -2
@@ -349,7 +349,8 @@ static int report__setup_sample_type(struct report *rep) !session->itrace_synth_opts->set)) sample_type |=PERF_SAMPLE_CALLCHAIN ; -if (session->itrace_synth_opts->last_branch) +if (session->itrace_synth_opts->last_branch || + session->itrace_synth_opts->add_last_branch) sample_type |=PERF_SAMPLE_BRANCH_STACK ;if (!is_pipe && !(sample_type &PERF_SAMPLE_CALLCHAIN )) {
@@ -1393,7 +1394,7 @@ int cmd_report(int argc, const char **argv) goto error; } -if (itrace_synth_opts.last_branch) +if (itrace_synth_opts.last_branch || itrace_synth_opts.add_last_branch) has_br_stack = true;if (has_br_stack && branch_call_mode)
tools/perf/util/auxtrace.c +5 -1
@@ -1463,8 +1463,12 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str, synth_opts->callchain_sz = val; }break ; +case 'L' :case 'l' : - synth_opts->last_branch = true; +if (p[-1 ] =='L' ) + synth_opts->add_last_branch = true; +else + synth_opts->last_branch = true; synth_opts->last_branch_sz =PERF_ITRACE_DEFAULT_LAST_BRANCH_SZ ;while (*p ==' ' || *p ==',' )
tools/perf/util/auxtrace.h +2 -0
@@ -77,6 +77,7 @@ enum itrace_period_type {* @add_callchain: add callchain to existing event records * @thread_stack: feed branches to the thread_stack * @last_branch: add branch context to 'instruction' events +* @add_last_branch: add branch context to existing event records * @callchain_sz: maximum callchain size * @last_branch_sz: branch context size * @period: 'instructions' events period
@@ -105,6 +106,7 @@ struct itrace_synth_opts {bool add_callchain;bool thread_stack;bool last_branch; +bool add_last_branch;unsigned int callchain_sz;unsigned int last_branch_sz;unsigned long long period;
tools/perf/util/s390-cpumsf.c +2 -1
@@ -1079,7 +1079,8 @@ static bool check_auxtrace_itrace(struct itrace_synth_opts *itops) itops->pwr_events || itops->errors || itops->dont_decode || itops->calls || itops->returns || itops->callchain || itops->thread_stack || - itops->last_branch || itops->add_callchain; + itops->last_branch || itops->add_callchain || + itops->add_last_branch;if (!ison)return true;pr_err ("Unsupported --itrace options specified\n" );
Signature · 1 line
2.17.1
[tip: perf/core] perf auxtrace: Add option to synthesize branch stack for regular events
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: ec90e42ce5142c4ed2a0061fe23bd4495428c52b Gitweb: https://git.kernel.org/tip/ec90e42ce5142c4ed2a0061fe23bd4495428c52b Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 29 Apr 2020 18:07:46 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf auxtrace: Add option to synthesize branch stack for regular events
There is an existing option to synthesize branch stacks for synthesized events. Add a new option to synthesize branch stacks for regular events.
--- tools/perf/Documentation/itrace.txt | 1 + tools/perf/builtin-inject.c | 3 ++- tools/perf/builtin-report.c | 5 +++-- tools/perf/util/auxtrace.c | 6 +++++- tools/perf/util/auxtrace.h | 2 ++ tools/perf/util/s390-cpumsf.c | 3 ++- 6 files changed, 15 insertions(+), 5 deletions(-)
tools/perf/Documentation/itrace.txt +1 -0
@@ -12,6 +12,7 @@ g synthesize a call chain (use with i or x) G synthesize a call chain on existing event records l synthesize last branch entries (use with i or x) + L synthesize last branch entries on existing event records s skip initial number of events The default is all events i.e. the same as --itrace=ibxwpe,
tools/perf/builtin-inject.c +2 -1
@@ -684,7 +684,8 @@ static int __cmd_inject(struct perf_inject *inject)perf_header__clear_feat (&session->header,HEADER_AUXTRACE ); -if (inject->itrace_synth_opts.last_branch) +if (inject->itrace_synth_opts.last_branch || + inject->itrace_synth_opts.add_last_branch)perf_header__set_feat (&session->header,HEADER_BRANCH_STACK ); evsel = perf_evlist__id2evsel_strict(session->evlist,
tools/perf/builtin-report.c +3 -2
@@ -349,7 +349,8 @@ static int report__setup_sample_type(struct report *rep) !session->itrace_synth_opts->set)) sample_type |=PERF_SAMPLE_CALLCHAIN ; -if (session->itrace_synth_opts->last_branch) +if (session->itrace_synth_opts->last_branch || + session->itrace_synth_opts->add_last_branch) sample_type |=PERF_SAMPLE_BRANCH_STACK ;if (!is_pipe && !(sample_type &PERF_SAMPLE_CALLCHAIN )) {
@@ -1393,7 +1394,7 @@ repeat: goto error; } -if (itrace_synth_opts.last_branch) +if (itrace_synth_opts.last_branch || itrace_synth_opts.add_last_branch) has_br_stack = true;if (has_br_stack && branch_call_mode)
tools/perf/util/auxtrace.c +5 -1
@@ -1464,8 +1464,12 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str, synth_opts->callchain_sz = val; }break ; +case 'L' :case 'l' : - synth_opts->last_branch = true; +if (p[-1 ] =='L' ) + synth_opts->add_last_branch = true; +else + synth_opts->last_branch = true; synth_opts->last_branch_sz =PERF_ITRACE_DEFAULT_LAST_BRANCH_SZ ;while (*p ==' ' || *p ==',' )
tools/perf/util/auxtrace.h +2 -0
@@ -77,6 +77,7 @@ enum itrace_period_type {* @add_callchain: add callchain to existing event records * @thread_stack: feed branches to the thread_stack * @last_branch: add branch context to 'instruction' events +* @add_last_branch: add branch context to existing event records * @callchain_sz: maximum callchain size * @last_branch_sz: branch context size * @period: 'instructions' events period
@@ -105,6 +106,7 @@ struct itrace_synth_opts {bool add_callchain;bool thread_stack;bool last_branch; +bool add_last_branch;unsigned int callchain_sz;unsigned int last_branch_sz;unsigned long long period;
tools/perf/util/s390-cpumsf.c +2 -1
@@ -1079,7 +1079,8 @@ static bool check_auxtrace_itrace(struct itrace_synth_opts *itops) itops->pwr_events || itops->errors || itops->dont_decode || itops->calls || itops->returns || itops->callchain || itops->thread_stack || - itops->last_branch || itops->add_callchain; + itops->last_branch || itops->add_callchain || + itops->add_last_branch;if (!ison)return true;pr_err ("Unsupported --itrace options specified\n" );
Adrian Hunter
reviewerPATCH 5/9 perf evsel: Add support for synthesized branch stack sample type
In reply to Adrian HunterAllow for a synthesized branch stack to be added to samples. As with synthesized call chains, the sample type cannot be changed because it is needed to continue to parse events. So add and use helper function evsel__has_br_stack() to indicate a branch stack, whether original or synthesized.
--- tools/perf/util/evsel.h | 10 ++++++++++ tools/perf/util/session.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-)
tools/perf/util/evsel.h +10 -0
@@ -417,6 +417,16 @@ static inline bool evsel__has_callchain(const struct evsel *evsel) evsel->synth_sample_type &PERF_SAMPLE_CALLCHAIN ; } +static inline bool evsel__has_br_stack (const struct evsel *evsel) +{ +/* +* For reporting purposes, an evsel sample can have a recorded branch +* stack or a branch stack synthesized from AUX area data. +*/ +return evsel->core.attr.sample_type &PERF_SAMPLE_BRANCH_STACK || + evsel->synth_sample_type &PERF_SAMPLE_BRANCH_STACK ; +} +struct perf_env *perf_evsel__env (struct evsel *evsel);int perf_evsel__store_ids (struct evsel *evsel,struct evlist *evlist);
tools/perf/util/session.c +1 -1
@@ -1243,7 +1243,7 @@ static void dump_sample(struct evsel *evsel, union perf_event *event,if (evsel__has_callchain (evsel))callchain__printf (evsel, sample); -if (sample_type &PERF_SAMPLE_BRANCH_STACK ) +if (evsel__has_br_stack (evsel))branch_stack__printf (sample,perf_evsel__has_branch_callstack (evsel));if (sample_type &PERF_SAMPLE_REGS_USER )
Signature · 1 line
2.17.1
[tip: perf/core] perf evsel: Add support for synthesized branch stack sample type
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 6cd2cbfc6865589c64ac37ec48937e93725622f1 Gitweb: https://git.kernel.org/tip/6cd2cbfc6865589c64ac37ec48937e93725622f1 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 29 Apr 2020 18:07:47 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf evsel: Add support for synthesized branch stack sample type
Allow for a synthesized branch stack to be added to samples. As with synthesized call chains, the sample type cannot be changed because it is needed to continue to parse events. So add and use helper function evsel__has_br_stack() to indicate a branch stack, whether original or synthesized.
--- tools/perf/util/evsel.h | 10 ++++++++++ tools/perf/util/session.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-)
tools/perf/util/evsel.h +10 -0
@@ -417,6 +417,16 @@ static inline bool evsel__has_callchain(const struct evsel *evsel) evsel->synth_sample_type &PERF_SAMPLE_CALLCHAIN ; } +static inline bool evsel__has_br_stack (const struct evsel *evsel) +{ +/* +* For reporting purposes, an evsel sample can have a recorded branch +* stack or a branch stack synthesized from AUX area data. +*/ +return evsel->core.attr.sample_type &PERF_SAMPLE_BRANCH_STACK || + evsel->synth_sample_type &PERF_SAMPLE_BRANCH_STACK ; +} +struct perf_env *perf_evsel__env (struct evsel *evsel);int perf_evsel__store_ids (struct evsel *evsel,struct evlist *evlist);
tools/perf/util/session.c +1 -1
@@ -1243,7 +1243,7 @@ static void dump_sample(struct evsel *evsel, union perf_event *event,if (evsel__has_callchain (evsel))callchain__printf (evsel, sample); -if (sample_type &PERF_SAMPLE_BRANCH_STACK ) +if (evsel__has_br_stack (evsel))branch_stack__printf (sample,perf_evsel__has_branch_callstack (evsel));if (sample_type &PERF_SAMPLE_REGS_USER )
Adrian Hunter
reviewerPATCH 6/9 perf thread-stack: Add thread_stack__br_sample_late()
In reply to Adrian HunterAdd a thread stack function to create a branch stack for hardware events where the sample records get created some time after the event occurred.
--- tools/perf/util/thread-stack.c | 104 +++++++++++++++++++++++++++++++++ tools/perf/util/thread-stack.h | 3 + 2 files changed, 107 insertions(+)
tools/perf/util/thread-stack.c +104 -0
@@ -645,6 +645,110 @@ void thread_stack__br_sample(struct thread *thread, int cpu, } } +/* Start of user space branch entries */ +static bool us_start (struct branch_entry *be,u64 kernel_start,bool *start) +{ +if (!*start) + *start = be->to && be->to < kernel_start; + +return *start; +} + +/* +* Start of branch entries after the ip fell in between 2 branches, or user +* space branch entries. +*/ +static bool ks_start (struct branch_entry *be,u64 sample_ip,u64 kernel_start, +bool *start,struct branch_entry *nb) +{ +if (!*start) { + *start = (nb && sample_ip >= be->to && sample_ip <= nb->from) || + be->from < kernel_start || + (be->to && be->to < kernel_start); + } + +return *start; +} + +/* +* Hardware sample records, created some time after the event occurred, need to +* have subsequent addresses removed from the branch stack. +*/ +void thread_stack__br_sample_late (struct thread *thread,int cpu, +struct branch_stack *dst,unsigned int sz, +u64 ip,u64 kernel_start) +{ +struct thread_stack *ts =thread__stack (thread, cpu); +struct branch_entry *d, *s, *spos, *ssz; +struct branch_stack *src; +unsigned int nr =0 ; +bool start = false; + + dst->nr =0 ; + +if (!ts) +return ; + + src = ts->br_stack_rb; +if (!src->nr) +return ; + + spos = &src->entries[ts->br_stack_pos]; + ssz = &src->entries[ts->br_stack_sz]; + + d = &dst->entries[0 ]; + s = spos; + +if (ip < kernel_start) { +/* +* User space sample: start copying branch entries when the +* branch is in user space. +*/ +for (s = spos; s < ssz && nr < sz; s++) { +if (us_start (s, kernel_start, &start)) { + *d++ = *s; + nr +=1 ; + } + } + +if (src->nr >= ts->br_stack_sz) { +for (s = &src->entries[0 ]; s < spos && nr < sz; s++) { +if (us_start (s, kernel_start, &start)) { + *d++ = *s; + nr +=1 ; + } + } + } + }else { +struct branch_entry *nb =NULL ; + +/* +* Kernel space sample: start copying branch entries when the ip +* falls in between 2 branches (or the branch is in user space +* because then the start must have been missed). +*/ +for (s = spos; s < ssz && nr < sz; s++) { +if (ks_start (s, ip, kernel_start, &start, nb)) { + *d++ = *s; + nr +=1 ; + } + nb = s; + } + +if (src->nr >= ts->br_stack_sz) { +for (s = &src->entries[0 ]; s < spos && nr < sz; s++) { +if (ks_start (s, ip, kernel_start, &start, nb)) { + *d++ = *s; + nr +=1 ; + } + nb = s; + } + } + } + + dst->nr = nr; +} +struct call_return_processor *call_return_processor__new (int (*process)(struct call_return *cr,u64 *parent_db_id,void *data),void *data)
tools/perf/util/thread-stack.h +3 -0
@@ -91,6 +91,9 @@ void thread_stack__sample_late(struct thread *thread, int cpu, u64 kernel_start);void thread_stack__br_sample (struct thread *thread,int cpu,struct branch_stack *dst,unsigned int sz); +void thread_stack__br_sample_late (struct thread *thread,int cpu, +struct branch_stack *dst,unsigned int sz, +u64 sample_ip,u64 kernel_start);int thread_stack__flush (struct thread *thread);void thread_stack__free (struct thread *thread);size_t thread_stack__depth (struct thread *thread,int cpu);
Signature · 1 line
2.17.1
[tip: perf/core] perf thread-stack: Add thread_stack__br_sample_late()
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 3749e0bbdef24efbf1698bf0dbd9575fddb9ed22 Gitweb: https://git.kernel.org/tip/3749e0bbdef24efbf1698bf0dbd9575fddb9ed22 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 29 Apr 2020 18:07:48 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf thread-stack: Add thread_stack__br_sample_late()
Add a thread stack function to create a branch stack for hardware events where the sample records get created some time after the event occurred.
--- tools/perf/util/thread-stack.c | 104 ++++++++++++++++++++++++++++++++- tools/perf/util/thread-stack.h | 3 +- 2 files changed, 107 insertions(+)
tools/perf/util/thread-stack.c +104 -0
@@ -645,6 +645,110 @@ void thread_stack__br_sample(struct thread *thread, int cpu, } } +/* Start of user space branch entries */ +static bool us_start (struct branch_entry *be,u64 kernel_start,bool *start) +{ +if (!*start) + *start = be->to && be->to < kernel_start; + +return *start; +} + +/* +* Start of branch entries after the ip fell in between 2 branches, or user +* space branch entries. +*/ +static bool ks_start (struct branch_entry *be,u64 sample_ip,u64 kernel_start, +bool *start,struct branch_entry *nb) +{ +if (!*start) { + *start = (nb && sample_ip >= be->to && sample_ip <= nb->from) || + be->from < kernel_start || + (be->to && be->to < kernel_start); + } + +return *start; +} + +/* +* Hardware sample records, created some time after the event occurred, need to +* have subsequent addresses removed from the branch stack. +*/ +void thread_stack__br_sample_late (struct thread *thread,int cpu, +struct branch_stack *dst,unsigned int sz, +u64 ip,u64 kernel_start) +{ +struct thread_stack *ts =thread__stack (thread, cpu); +struct branch_entry *d, *s, *spos, *ssz; +struct branch_stack *src; +unsigned int nr =0 ; +bool start = false; + + dst->nr =0 ; + +if (!ts) +return ; + + src = ts->br_stack_rb; +if (!src->nr) +return ; + + spos = &src->entries[ts->br_stack_pos]; + ssz = &src->entries[ts->br_stack_sz]; + + d = &dst->entries[0 ]; + s = spos; + +if (ip < kernel_start) { +/* +* User space sample: start copying branch entries when the +* branch is in user space. +*/ +for (s = spos; s < ssz && nr < sz; s++) { +if (us_start (s, kernel_start, &start)) { + *d++ = *s; + nr +=1 ; + } + } + +if (src->nr >= ts->br_stack_sz) { +for (s = &src->entries[0 ]; s < spos && nr < sz; s++) { +if (us_start (s, kernel_start, &start)) { + *d++ = *s; + nr +=1 ; + } + } + } + }else { +struct branch_entry *nb =NULL ; + +/* +* Kernel space sample: start copying branch entries when the ip +* falls in between 2 branches (or the branch is in user space +* because then the start must have been missed). +*/ +for (s = spos; s < ssz && nr < sz; s++) { +if (ks_start (s, ip, kernel_start, &start, nb)) { + *d++ = *s; + nr +=1 ; + } + nb = s; + } + +if (src->nr >= ts->br_stack_sz) { +for (s = &src->entries[0 ]; s < spos && nr < sz; s++) { +if (ks_start (s, ip, kernel_start, &start, nb)) { + *d++ = *s; + nr +=1 ; + } + nb = s; + } + } + } + + dst->nr = nr; +} +struct call_return_processor *call_return_processor__new (int (*process)(struct call_return *cr,u64 *parent_db_id,void *data),void *data)
tools/perf/util/thread-stack.h +3 -0
@@ -91,6 +91,9 @@ void thread_stack__sample_late(struct thread *thread, int cpu, u64 kernel_start);void thread_stack__br_sample (struct thread *thread,int cpu,struct branch_stack *dst,unsigned int sz); +void thread_stack__br_sample_late (struct thread *thread,int cpu, +struct branch_stack *dst,unsigned int sz, +u64 sample_ip,u64 kernel_start);int thread_stack__flush (struct thread *thread);void thread_stack__free (struct thread *thread);size_t thread_stack__depth (struct thread *thread,int cpu);
Adrian Hunter
reviewerPATCH 7/9 perf intel-pt: Add support for synthesizing branch stacks for regular events
In reply to Adrian HunterUse the new thread_stack__br_sample_late() function to create a thread stack for regular events.
Example:
# perf record --kcore --aux-sample -e '{intel_pt//,cycles:ppp}' -c 10000 uname
Linux
[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.743 MB perf.data ]
# perf report --itrace=Le --stdio | head -30 | tail -18 # Samples: 11K of event 'cycles:ppp'
# Event count (approx.): 11648
#
# Overhead Command Source Shared Object Source Symbol Target Symbol Basic Block Cycles
# ........ ....... .................... .............................................. .............................................. ..................
#
5.49% uname libc-2.30.so [.] _dl_addr [.] _dl_addr -
2.41% uname ld-2.30.so [.] _dl_relocate_object [.] _dl_relocate_object -
2.31% uname ld-2.30.so [.] do_lookup_x [.] do_lookup_x -
2.17% uname [kernel.kallsyms] [k] unmap_page_range [k] unmap_page_range -
2.05% uname ld-2.30.so [k] _dl_start [k] _dl_start -
1.97% uname ld-2.30.so [.] _dl_lookup_symbol_x [.] _dl_lookup_symbol_x -
1.94% uname [kernel.kallsyms] [k] filemap_map_pages [k] filemap_map_pages -
1.60% uname [kernel.kallsyms] [k] __handle_mm_fault [k] __handle_mm_fault -
1.44% uname [kernel.kallsyms] [k] page_add_file_rmap [k] page_add_file_rmap -
1.12% uname [kernel.kallsyms] [k] vma_interval_tree_insert [k] vma_interval_tree_insert -
0.94% uname [kernel.kallsyms] [k] perf_iterate_ctx [k] perf_iterate_ctx ---- tools/perf/util/intel-pt.c | 73 ++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 7 deletions(-)
tools/perf/util/intel-pt.c +66 -7
@@ -71,6 +71,7 @@ struct intel_pt {bool use_thread_stack;bool callstack;unsigned int br_stack_sz; +unsigned int br_stack_sz_plus;int have_sched_switch;u32 pmu_type;u64 kernel_start;
@@ -129,6 +130,7 @@ struct intel_pt {unsigned int range_cnt;struct ip_callchain *chain; +struct branch_stack *br_stack; };enum switch_state {
@@ -910,6 +912,44 @@ static void intel_pt_add_callchain(struct intel_pt *pt, sample->callchain = pt->chain; } +static struct branch_stack *intel_pt_alloc_br_stack (struct intel_pt *pt) +{ +size_t sz =sizeof (struct branch_stack ); + + sz += pt->br_stack_sz *sizeof (struct branch_entry ); +return zalloc (sz); +} + +static int intel_pt_br_stack_init (struct intel_pt *pt) +{ +struct evsel *evsel; + +evlist__for_each_entry (pt->session->evlist, evsel) { +if (!(evsel->core.attr.sample_type &PERF_SAMPLE_BRANCH_STACK )) + evsel->synth_sample_type |=PERF_SAMPLE_BRANCH_STACK ; + } + + pt->br_stack =intel_pt_alloc_br_stack (pt); +if (!pt->br_stack) +return -ENOMEM ; + +return 0 ; +} + +static void intel_pt_add_br_stack (struct intel_pt *pt, +struct perf_sample *sample) +{ +struct thread *thread =machine__findnew_thread (pt->machine, + sample->pid, + sample->tid); + +thread_stack__br_sample_late (thread, sample->cpu, pt->br_stack, + pt->br_stack_sz, sample->ip, + pt->kernel_start); + + sample->branch_stack = pt->br_stack; +} +static struct intel_pt_queue *intel_pt_alloc_queue (struct intel_pt *pt,unsigned int queue_nr) {
@@ -928,10 +968,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, }if (pt->synth_opts.last_branch) { -size_t sz =sizeof (struct branch_stack ); - - sz += pt->br_stack_sz *sizeof (struct branch_entry ); - ptq->last_branch =zalloc (sz); + ptq->last_branch =intel_pt_alloc_br_stack (pt);if (!ptq->last_branch) goto out_free; }
@@ -1962,7 +1999,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)thread_stack__event (ptq->thread, ptq->cpu, ptq->flags, state->from_ip, state->to_ip, ptq->insn_len, state->trace_nr, pt->callstack, - pt->br_stack_sz, + pt->br_stack_sz_plus, pt->mispred_all); }else {thread_stack__set_trace_nr (ptq->thread, ptq->cpu, state->trace_nr);
@@ -2608,6 +2645,8 @@ static int intel_pt_process_event(struct perf_session *session,if (event->header.type ==PERF_RECORD_SAMPLE ) {if (pt->synth_opts.add_callchain && !sample->callchain)intel_pt_add_callchain (pt, sample); +if (pt->synth_opts.add_last_branch && !sample->branch_stack) +intel_pt_add_br_stack (pt, sample); } if (event->header.type == PERF_RECORD_AUX &&
@@ -3369,13 +3408,33 @@ int intel_pt_process_auxtrace_info(union perf_event *event, goto err_delete_thread; } -if (pt->synth_opts.last_branch) +if (pt->synth_opts.last_branch || pt->synth_opts.add_last_branch) { pt->br_stack_sz = pt->synth_opts.last_branch_sz; + pt->br_stack_sz_plus = pt->br_stack_sz; + } + +if (pt->synth_opts.add_last_branch) { + err =intel_pt_br_stack_init (pt); +if (err) + goto err_delete_thread; +/* +* Additional branch stack size to cater for tracing from the +* actual sample ip to where the sample time is recorded. +* Measured at about 200 branches, but generously set to 1024. +* If kernel space is not being traced, then add just 1 for the +* branch to kernel space. +*/ +if (intel_pt_tracing_kernel (pt)) + pt->br_stack_sz_plus +=1024 ; +else + pt->br_stack_sz_plus +=1 ; + } pt->use_thread_stack = pt->synth_opts.callchain || pt->synth_opts.add_callchain || pt->synth_opts.thread_stack || - pt->synth_opts.last_branch; + pt->synth_opts.last_branch || + pt->synth_opts.add_last_branch; pt->callstack = pt->synth_opts.callchain || pt->synth_opts.add_callchain ||
Signature · 1 line
2.17.1
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: f0a0251cee800bf90cff92ecfaf4a4d4c9c493b2 Gitweb: https://git.kernel.org/tip/f0a0251cee800bf90cff92ecfaf4a4d4c9c493b2 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 29 Apr 2020 18:07:49 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:30 -03:00
perf intel-pt: Add support for synthesizing branch stacks for regular events
Use the new thread_stack__br_sample_late() function to create a thread stack for regular events.
Example:
# perf record --kcore --aux-sample -e '{intel_pt//,cycles:ppp}' -c 10000 uname
Linux
[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.743 MB perf.data ]
# perf report --itrace=Le --stdio | head -30 | tail -18 # Samples: 11K of event 'cycles:ppp'
# Event count (approx.): 11648
#
# Overhead Command Source Shared Object Source Symbol Target Symbol Basic Block Cycles
# ........ ....... .................... ............................ ............................ ..................
#
5.49% uname libc-2.30.so [.] _dl_addr [.] _dl_addr -
2.41% uname ld-2.30.so [.] _dl_relocate_object [.] _dl_relocate_object -
2.31% uname ld-2.30.so [.] do_lookup_x [.] do_lookup_x -
2.17% uname [kernel.kallsyms] [k] unmap_page_range [k] unmap_page_range -
2.05% uname ld-2.30.so [k] _dl_start [k] _dl_start -
1.97% uname ld-2.30.so [.] _dl_lookup_symbol_x [.] _dl_lookup_symbol_x -
1.94% uname [kernel.kallsyms] [k] filemap_map_pages [k] filemap_map_pages -
1.60% uname [kernel.kallsyms] [k] __handle_mm_fault [k] __handle_mm_fault -
1.44% uname [kernel.kallsyms] [k] page_add_file_rmap [k] page_add_file_rmap -
1.12% uname [kernel.kallsyms] [k] vma_interval_tree_insert [k] vma_interval_tree_insert -
0.94% uname [kernel.kallsyms] [k] perf_iterate_ctx [k] perf_iterate_ctx ---- tools/perf/util/intel-pt.c | 73 +++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 7 deletions(-)
tools/perf/util/intel-pt.c +66 -7
@@ -72,6 +72,7 @@ struct intel_pt {bool use_thread_stack;bool callstack;unsigned int br_stack_sz; +unsigned int br_stack_sz_plus;int have_sched_switch;u32 pmu_type;u64 kernel_start;
@@ -130,6 +131,7 @@ struct intel_pt {unsigned int range_cnt;struct ip_callchain *chain; +struct branch_stack *br_stack; };enum switch_state {
@@ -911,6 +913,44 @@ static void intel_pt_add_callchain(struct intel_pt *pt, sample->callchain = pt->chain; } +static struct branch_stack *intel_pt_alloc_br_stack (struct intel_pt *pt) +{ +size_t sz =sizeof (struct branch_stack ); + + sz += pt->br_stack_sz *sizeof (struct branch_entry ); +return zalloc (sz); +} + +static int intel_pt_br_stack_init (struct intel_pt *pt) +{ +struct evsel *evsel; + +evlist__for_each_entry (pt->session->evlist, evsel) { +if (!(evsel->core.attr.sample_type &PERF_SAMPLE_BRANCH_STACK )) + evsel->synth_sample_type |=PERF_SAMPLE_BRANCH_STACK ; + } + + pt->br_stack =intel_pt_alloc_br_stack (pt); +if (!pt->br_stack) +return -ENOMEM ; + +return 0 ; +} + +static void intel_pt_add_br_stack (struct intel_pt *pt, +struct perf_sample *sample) +{ +struct thread *thread =machine__findnew_thread (pt->machine, + sample->pid, + sample->tid); + +thread_stack__br_sample_late (thread, sample->cpu, pt->br_stack, + pt->br_stack_sz, sample->ip, + pt->kernel_start); + + sample->branch_stack = pt->br_stack; +} +static struct intel_pt_queue *intel_pt_alloc_queue (struct intel_pt *pt,unsigned int queue_nr) {
@@ -929,10 +969,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, }if (pt->synth_opts.last_branch) { -size_t sz =sizeof (struct branch_stack ); - - sz += pt->br_stack_sz *sizeof (struct branch_entry ); - ptq->last_branch =zalloc (sz); + ptq->last_branch =intel_pt_alloc_br_stack (pt);if (!ptq->last_branch) goto out_free; }
@@ -1963,7 +2000,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)thread_stack__event (ptq->thread, ptq->cpu, ptq->flags, state->from_ip, state->to_ip, ptq->insn_len, state->trace_nr, pt->callstack, - pt->br_stack_sz, + pt->br_stack_sz_plus, pt->mispred_all); }else {thread_stack__set_trace_nr (ptq->thread, ptq->cpu, state->trace_nr);
@@ -2609,6 +2646,8 @@ static int intel_pt_process_event(struct perf_session *session,if (event->header.type ==PERF_RECORD_SAMPLE ) {if (pt->synth_opts.add_callchain && !sample->callchain)intel_pt_add_callchain (pt, sample); +if (pt->synth_opts.add_last_branch && !sample->branch_stack) +intel_pt_add_br_stack (pt, sample); } if (event->header.type == PERF_RECORD_AUX &&
@@ -3370,13 +3409,33 @@ int intel_pt_process_auxtrace_info(union perf_event *event, goto err_delete_thread; } -if (pt->synth_opts.last_branch) +if (pt->synth_opts.last_branch || pt->synth_opts.add_last_branch) { pt->br_stack_sz = pt->synth_opts.last_branch_sz; + pt->br_stack_sz_plus = pt->br_stack_sz; + } + +if (pt->synth_opts.add_last_branch) { + err =intel_pt_br_stack_init (pt); +if (err) + goto err_delete_thread; +/* +* Additional branch stack size to cater for tracing from the +* actual sample ip to where the sample time is recorded. +* Measured at about 200 branches, but generously set to 1024. +* If kernel space is not being traced, then add just 1 for the +* branch to kernel space. +*/ +if (intel_pt_tracing_kernel (pt)) + pt->br_stack_sz_plus +=1024 ; +else + pt->br_stack_sz_plus +=1 ; + } pt->use_thread_stack = pt->synth_opts.callchain || pt->synth_opts.add_callchain || pt->synth_opts.thread_stack || - pt->synth_opts.last_branch; + pt->synth_opts.last_branch || + pt->synth_opts.add_last_branch; pt->callstack = pt->synth_opts.callchain || pt->synth_opts.add_callchain ||
Adrian Hunter
reviewerPATCH 8/9 perf intel-pt: Update documentation about itrace G and L options
In reply to Adrian HunterProvide a little more information about the new G and L options, particularly the issue with large PEBs.
--- tools/perf/Documentation/itrace.txt | 4 +++ tools/perf/Documentation/perf-intel-pt.txt | 35 ++++++++++++++++++++++ 2 files changed, 39 insertions(+)
tools/perf/Documentation/itrace.txt +4 -0
@@ -33,6 +33,10 @@ Also the number of last branch entries (default 64, max. 1024) for instructions or transactions events can be specified. + Similar to options g and l, size may also be specified for options G and L. + On x86, note that G and L work poorly when data has been recorded with + large PEBS. Refer linkperf:perf-intel-pt[1] man page for details. + It is also possible to skip events generated (instructions, branches, transactions, ptwrite, power) at the beginning. This is useful to ignore initialization code.
tools/perf/Documentation/perf-intel-pt.txt +35 -0
@@ -821,7 +821,9 @@ The letters are: e synthesize tracing error events d create a debug log g synthesize a call chain (use with i or x) + G synthesize a call chain on existing event records l synthesize last branch entries (use with i or x) + L synthesize last branch entries on existing event records s skip initial number of events "Instructions" events look like they were recorded by "perf record -e
@@ -912,6 +914,39 @@ transactions events can be specified. e.g. Note that last branch entries are cleared for each sample, so there is no overlap from one sample to the next. +The G and L options are designed in particular for sample mode, and work much +like g and l but add call chain and branch stack to the other selected events +instead of synthesized events. For example, to record branch-misses events for +'ls' and then add a call chain derived from the Intel PT trace: + + perf record --aux-sample -e '{intel_pt//u,branch-misses:u}' -- ls + perf report --itrace=Ge + +Although in fact G is a default for perf report, so that is the same as just: + + perf report + +One caveat with the G and L options is that they work poorly with "Large PEBS". +Large PEBS means PEBS records will be accumulated by hardware and the written +into the event buffer in one go. That reduces interrupts, but can give very +late timestamps. Because the Intel PT trace is synchronized by timestamps, +the PEBS events do not match the trace. Currently, Large PEBS is used only in +certain circumstances: + - hardware supports it + - PEBS is used + - event period is specified, instead of frequency + - the sample type is limited to the following flags: + PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_ADDR | + PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_STREAM_ID | + PERF_SAMPLE_DATA_SRC | PERF_SAMPLE_IDENTIFIER | + PERF_SAMPLE_TRANSACTION | PERF_SAMPLE_PHYS_ADDR | + PERF_SAMPLE_REGS_INTR | PERF_SAMPLE_REGS_USER | + PERF_SAMPLE_PERIOD (and sometimes) | PERF_SAMPLE_TIME +Because Intel PT sample mode uses a different sample type to the list above, +Large PEBS is not used with Intel PT sample mode. To avoid Large PEBS in other +cases, avoid specifying the event period i.e. avoid the 'perf record' -c option, +--count option, or 'period' config term. + To disable trace decoding entirely, use the option --no-itrace. It is also possible to skip events generated (instructions, branches, transactions)
Signature · 1 line
2.17.1
Re: [PATCH 8/9] perf intel-pt: Update documentation about itrace G and L options
tools/perf/Documentation/perf-intel-pt.txt transactions events can be specified. e.g. · line 932
Quoted 4 lines
tools/perf/Documentation/perf-intel-pt.txt +4
-0+One caveat with the G and L options is that they work poorly with "Large PEBS". +Large PEBS means PEBS records will be accumulated by hardware and the written +into the event buffer in one go. That reduces interrupts, but can give very +late timestamps. Because the Intel PT trace is synchronized by timestamps,
Are you refering to Broadwell here?
On Skylake/Goldmont the PEBS event contains the TSC and the time stamp reported by perf should report the time the event was sampled based on that TSC. Or is that not working for some reason?
-Andi
Adrian Hunter
reviewerRe: [PATCH 8/9] perf intel-pt: Update documentation about itrace G and L options
Quoted 6 lines · Andi Kleen
tools/perf/Documentation/perf-intel-pt.txt transactions events can be specified. e.g. · line 932
Quoted 4 lines
tools/perf/Documentation/perf-intel-pt.txt +4
-0+One caveat with the G and L options is that they work poorly with "Large PEBS". +Large PEBS means PEBS records will be accumulated by hardware and the written +into the event buffer in one go. That reduces interrupts, but can give very +late timestamps. Because the Intel PT trace is synchronized by timestamps,Are you refering to Broadwell here?
I was testing on Coffee Lake
Quoted 4 lines
On Skylake/Goldmont the PEBS event contains the TSC and the time stamp reported by perf should report the time the event was sampled based on that TSC. Or is that not working for some reason?
I guess it is not working like that, but perf tools would probably need special rules to sort the events because the they would break the rules of PERF_RECORD_FINISHED_ROUND, wouldn't they?
Re: [PATCH 8/9] perf intel-pt: Update documentation about itrace G and L options
Quoted 8 lines
Quoted 4 lines
On Skylake/Goldmont the PEBS event contains the TSC and the time stamp reported by perf should report the time the event was sampled based on that TSC. Or is that not working for some reason?
I guess it is not working like that, but perf tools would probably need special rules to sort the events because the they would break the rules of
PERF_RECORD_FINISHED_ROUND, wouldn't they?
Yes it may violate finished round.
It should not be delayed longer than the next context switch though.
The documentation warning would be still correct, but only on Broadwell.
-Andi
[tip: perf/core] perf intel-pt: Update documentation about itrace G and L options
In reply to Adrian HunterThe following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 43358d9dfb250842383cddad816a7538548a5070 Gitweb: https://git.kernel.org/tip/43358d9dfb250842383cddad816a7538548a5070 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 29 Apr 2020 18:07:50 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:30 -03:00
perf intel-pt: Update documentation about itrace G and L options
Provide a little more information about the new G and L options, particularly the issue with large PEBs.
--- tools/perf/Documentation/itrace.txt | 4 ++- tools/perf/Documentation/perf-intel-pt.txt | 35 +++++++++++++++++++++- 2 files changed, 39 insertions(+)
tools/perf/Documentation/itrace.txt +4 -0
@@ -33,6 +33,10 @@ Also the number of last branch entries (default 64, max. 1024) for instructions or transactions events can be specified. + Similar to options g and l, size may also be specified for options G and L. + On x86, note that G and L work poorly when data has been recorded with + large PEBS. Refer linkperf:perf-intel-pt[1] man page for details. + It is also possible to skip events generated (instructions, branches, transactions, ptwrite, power) at the beginning. This is useful to ignore initialization code.
tools/perf/Documentation/perf-intel-pt.txt +35 -0
@@ -821,7 +821,9 @@ The letters are: e synthesize tracing error events d create a debug log g synthesize a call chain (use with i or x) + G synthesize a call chain on existing event records l synthesize last branch entries (use with i or x) + L synthesize last branch entries on existing event records s skip initial number of events "Instructions" events look like they were recorded by "perf record -e
@@ -912,6 +914,39 @@ transactions events can be specified. e.g. Note that last branch entries are cleared for each sample, so there is no overlap from one sample to the next. +The G and L options are designed in particular for sample mode, and work much +like g and l but add call chain and branch stack to the other selected events +instead of synthesized events. For example, to record branch-misses events for +'ls' and then add a call chain derived from the Intel PT trace: + + perf record --aux-sample -e '{intel_pt//u,branch-misses:u}' -- ls + perf report --itrace=Ge + +Although in fact G is a default for perf report, so that is the same as just: + + perf report + +One caveat with the G and L options is that they work poorly with "Large PEBS". +Large PEBS means PEBS records will be accumulated by hardware and the written +into the event buffer in one go. That reduces interrupts, but can give very +late timestamps. Because the Intel PT trace is synchronized by timestamps, +the PEBS events do not match the trace. Currently, Large PEBS is used only in +certain circumstances: + - hardware supports it + - PEBS is used + - event period is specified, instead of frequency + - the sample type is limited to the following flags: + PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_ADDR | + PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_STREAM_ID | + PERF_SAMPLE_DATA_SRC | PERF_SAMPLE_IDENTIFIER | + PERF_SAMPLE_TRANSACTION | PERF_SAMPLE_PHYS_ADDR | + PERF_SAMPLE_REGS_INTR | PERF_SAMPLE_REGS_USER | + PERF_SAMPLE_PERIOD (and sometimes) | PERF_SAMPLE_TIME +Because Intel PT sample mode uses a different sample type to the list above, +Large PEBS is not used with Intel PT sample mode. To avoid Large PEBS in other +cases, avoid specifying the event period i.e. avoid the 'perf record' -c option, +--count option, or 'period' config term. + To disable trace decoding entirely, use the option --no-itrace. It is also possible to skip events generated (instructions, branches, transactions)
Adrian Hunter
reviewerPATCH 9/9 perf intel-pt: Update documentation about using /proc/kcore
In reply to Adrian HunterUpdate documentation to reflect the advent of the --kcore option for 'perf record'.
--- tools/perf/Documentation/perf-intel-pt.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
tools/perf/Documentation/perf-intel-pt.txt +9 -9
@@ -69,22 +69,22 @@ And profiled with 'perf report' e.g. To also trace kernel space presents a problem, namely kernel self-modifying code. A fairly good kernel image is available in /proc/kcore but to get an accurate image a copy of /proc/kcore needs to be made under the same conditions -as the data capture. A script perf-with-kcore can do that, but beware that the -script makes use of 'sudo' to copy /proc/kcore. If you have perf installed -locally from the source tree you can do: +as the data capture. 'perf record' can make a copy of /proc/kcore if the option +--kcore is used, but access to /proc/kcore is restricted e.g. - ~/libexec/perf-core/perf-with-kcore record pt_ls -e intel_pt// -- ls + sudo perf record -o pt_ls --kcore -e intel_pt// -- ls -which will create a directory named 'pt_ls' and put the perf.data file and -copies of /proc/kcore, /proc/kallsyms and /proc/modules into it. Then to use -'perf report' becomes: +which will create a directory named 'pt_ls' and put the perf.data file (named +simply 'data') and copies of /proc/kcore, /proc/kallsyms and /proc/modules into +it. The other tools understand the directory format, so to use 'perf report' +becomes: - ~/libexec/perf-core/perf-with-kcore report pt_ls + sudo perf report -i pt_ls Because samples are synthesized after-the-fact, the sampling period can be selected for reporting. e.g. sample every microsecond - ~/libexec/perf-core/perf-with-kcore report pt_ls --itrace=i1usge + sudo perf report pt_ls --itrace=i1usge See the sections below for more information about the --itrace option.
Signature · 1 line
2.17.1
[tip: perf/core] perf intel-pt: Update documentation about using /proc/kcore
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 6dd912cbadb9f9746a525c74f09c0e36cee13ee2 Gitweb: https://git.kernel.org/tip/6dd912cbadb9f9746a525c74f09c0e36cee13ee2 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 29 Apr 2020 18:07:51 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:30 -03:00
perf intel-pt: Update documentation about using /proc/kcore
Update documentation to reflect the advent of the --kcore option for 'perf record'.
--- tools/perf/Documentation/perf-intel-pt.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
tools/perf/Documentation/perf-intel-pt.txt +9 -9
@@ -69,22 +69,22 @@ And profiled with 'perf report' e.g. To also trace kernel space presents a problem, namely kernel self-modifying code. A fairly good kernel image is available in /proc/kcore but to get an accurate image a copy of /proc/kcore needs to be made under the same conditions -as the data capture. A script perf-with-kcore can do that, but beware that the -script makes use of 'sudo' to copy /proc/kcore. If you have perf installed -locally from the source tree you can do: +as the data capture. 'perf record' can make a copy of /proc/kcore if the option +--kcore is used, but access to /proc/kcore is restricted e.g. - ~/libexec/perf-core/perf-with-kcore record pt_ls -e intel_pt// -- ls + sudo perf record -o pt_ls --kcore -e intel_pt// -- ls -which will create a directory named 'pt_ls' and put the perf.data file and -copies of /proc/kcore, /proc/kallsyms and /proc/modules into it. Then to use -'perf report' becomes: +which will create a directory named 'pt_ls' and put the perf.data file (named +simply 'data') and copies of /proc/kcore, /proc/kallsyms and /proc/modules into +it. The other tools understand the directory format, so to use 'perf report' +becomes: - ~/libexec/perf-core/perf-with-kcore report pt_ls + sudo perf report -i pt_ls Because samples are synthesized after-the-fact, the sampling period can be selected for reporting. e.g. sample every microsecond - ~/libexec/perf-core/perf-with-kcore report pt_ls --itrace=i1usge + sudo perf report pt_ls --itrace=i1usge See the sections below for more information about the --itrace option.
Arnaldo Carvalho de Melo
AppliedEm Wed, Apr 29, 2020 at 06:07:42PM +0300, Adrian Hunter escreveu:
Quoted 6 lines
Hi
This patchset adds Intel PT support for synthesizing branch stacks for regular events. This follows on from the patchset that did the same thing for call chains.
Quoted 8 lines
The first 3 patches convert Intel PT to using thread-stack to record branch stacks, which allows branch stacks to be accumulated separately for each thread.
The next 3 patches add support for synthesizing branch stacks for regular events.
The final 2 patches update some documentation.
Thanks, applied.
- Arnaldo
Quoted 30 lines
Adrian Hunter (9):
perf thread-stack: Add branch stack support
perf intel-pt: Consolidate thread-stack use condition
perf intel-pt: Change branch stack support to use thread-stacks perf auxtrace: Add option to synthesize branch stack for regular events perf evsel: Add support for synthesized branch stack sample type perf thread-stack: Addthread_stack__br_sample_late()
perf intel-pt: Add support for synthesizing branch stacks for regular events perf intel-pt: Update documentation about itrace G and L options perf intel-pt: Update documentation about using/proc/kcoretools/perf/Documentation/itrace.txt | 5 + tools/perf/Documentation/perf-intel-pt.txt | 53 +++++-- tools/perf/builtin-inject.c | 3 +- tools/perf/builtin-report.c | 5 +- tools/perf/util/auxtrace.c | 6 +- tools/perf/util/auxtrace.h | 2 + tools/perf/util/evsel.h | 10 ++ tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 210 ++++++++++++++-------------- tools/perf/util/s390-cpumsf.c | 3 +- tools/perf/util/session.c | 2 +- tools/perf/util/thread-stack.c | 217 +++++++++++++++++++++++++++-- tools/perf/util/thread-stack.h | 8 +- 13 files changed, 393 insertions(+), 133 deletions(-)Regards
Adrian
Signature · 1 line
- Arnaldo