perf arm-spe: Enable sample type PERF_SAMPLE_DATA_SRC
Subsystems (2)
PATCH v2 1/6 perf arm-spe: Enable sample type PERF_SAMPLE_DATA_SRC
From: Leo Yan <[email protected]>
This patch is to enable sample type PERF_SAMPLE_DATA_SRC for Arm SPE in the perf data, when output the tracing data, it tells tools that it contains data source in the memory event.
--- tools/perf/util/arm-spe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/arm-spe.c +1 -1
@@ -803,7 +803,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session) attr.type =PERF_TYPE_HARDWARE ; attr.sample_type = evsel->core.attr.sample_type &PERF_SAMPLE_MASK ; attr.sample_type |=PERF_SAMPLE_IP |PERF_SAMPLE_TID | -PERF_SAMPLE_PERIOD ; +PERF_SAMPLE_PERIOD |PERF_SAMPLE_DATA_SRC ;if (spe->timeless_decoding) attr.sample_type &= ~(u64 )PERF_SAMPLE_TIME ;else
Signature · 1 line
2.28.0
PATCH v2 2/6 perf arm-spe: Store memory address in packet
From: Leo Yan <[email protected]>
This patch is to store virtual and physical memory addresses in packet, which will be used for memory samples.
--- tools/perf/util/arm-spe-decoder/arm-spe-decoder.c | 4 ++++ tools/perf/util/arm-spe-decoder/arm-spe-decoder.h | 2 ++ 2 files changed, 6 insertions(+)
tools/perf/util/arm-spe-decoder/arm-spe-decoder.c +4 -0
@@ -172,6 +172,10 @@ static int arm_spe_read_record(struct arm_spe_decoder *decoder) decoder->record.from_ip = ip; else if (idx == SPE_ADDR_PKT_HDR_INDEX_BRANCH) decoder->record.to_ip = ip; + else if (idx == SPE_ADDR_PKT_HDR_INDEX_DATA_VIRT) + decoder->record.virt_addr = ip; + else if (idx == SPE_ADDR_PKT_HDR_INDEX_DATA_PHYS) + decoder->record.phys_addr = ip;break ;case ARM_SPE_COUNTER :break ;
tools/perf/util/arm-spe-decoder/arm-spe-decoder.h +2 -0
@@ -30,6 +30,8 @@ struct arm_spe_record {u64 from_ip;u64 to_ip;u64 timestamp; +u64 virt_addr; +u64 phys_addr; };struct arm_spe_insn ;
Signature · 1 line
2.28.0
PATCH v2 3/6 perf arm-spe: Store operation type in packet
In reply to James ClarkFrom: Leo Yan <[email protected]>
This patch is to store operation type in packet structure.
--- tools/perf/util/arm-spe-decoder/arm-spe-decoder.c | 6 ++++++ tools/perf/util/arm-spe-decoder/arm-spe-decoder.h | 6 ++++++ 2 files changed, 12 insertions(+)
tools/perf/util/arm-spe-decoder/arm-spe-decoder.c +6 -0
@@ -182,6 +182,12 @@ static int arm_spe_read_record(struct arm_spe_decoder *decoder)case ARM_SPE_CONTEXT :break ;case ARM_SPE_OP_TYPE : +if (idx ==SPE_OP_PKT_HDR_CLASS_LD_ST_ATOMIC ) { +if (payload &0x1 ) + decoder->record.op =ARM_SPE_ST ; +else + decoder->record.op =ARM_SPE_LD ; + }break ;case ARM_SPE_EVENTS :if (payload &BIT (EV_L1D_REFILL ))
tools/perf/util/arm-spe-decoder/arm-spe-decoder.h +6 -0
@@ -24,9 +24,15 @@ enum arm_spe_sample_type { ARM_SPE_REMOTE_ACCESS = 1 << 7, }; +enum arm_spe_op_type { +ARM_SPE_LD =1 <<0 , +ARM_SPE_ST =1 <<1 , +}; +struct arm_spe_record {enum arm_spe_sample_type type;int err; +u32 op;u64 from_ip;u64 to_ip;u64 timestamp;
Signature · 1 line
2.28.0
PATCH v2 4/6 perf arm-spe: Fill address info for samples
In reply to James ClarkFrom: Leo Yan <[email protected]>
To properly handle memory and branch samples, this patch divides into two functions for generating samples: arm_spe__synth_mem_sample() is for synthesizing memory and TLB samples; arm_spe__synth_branch_sample() is to synthesize branch samples.
Arm SPE backend decoder has passed virtual and physical address through packets, the address info is stored into the synthesize samples in the function arm_spe__synth_mem_sample().
--- tools/perf/util/arm-spe.c | 52 +++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 21 deletions(-)
tools/perf/util/arm-spe.c +31 -21
@@ -235,7 +235,6 @@ static void arm_spe_prep_sample(struct arm_spe *spe, sample->cpumode =arm_spe_cpumode (spe, sample->ip); sample->pid = speq->pid; sample->tid = speq->tid; - sample->addr = record->to_ip; sample->period =1 ; sample->cpu = speq->cpu;
@@ -259,18 +258,37 @@ arm_spe_deliver_synth_event(struct arm_spe *spe,return ret; } -static int -arm_spe_synth_spe_events_sample (struct arm_spe_queue *speq, -u64 spe_events_id) +static int arm_spe__synth_mem_sample (struct arm_spe_queue *speq, +u64 spe_events_id) {struct arm_spe *spe = speq->spe; +struct arm_spe_record *record = &speq->decoder->record; +union perf_event *event = speq->event_buf; +struct perf_sample sample = {0 }; + +arm_spe_prep_sample (spe, speq, event, &sample); + + sample.id = spe_events_id; + sample.stream_id = spe_events_id; + sample.addr = record->virt_addr; + sample.phys_addr = record->phys_addr; + +return arm_spe_deliver_synth_event (spe, speq, event, &sample); +} + +static int arm_spe__synth_branch_sample (struct arm_spe_queue *speq, +u64 spe_events_id) +{ +struct arm_spe *spe = speq->spe; +struct arm_spe_record *record = &speq->decoder->record;union perf_event *event = speq->event_buf; -struct perf_sample sample = { .ip =0 , }; +struct perf_sample sample = {0 };arm_spe_prep_sample (spe, speq, event, &sample); sample.id = spe_events_id; sample.stream_id = spe_events_id; + sample.addr = record->to_ip;return arm_spe_deliver_synth_event (spe, speq, event, &sample); }
@@ -283,15 +301,13 @@ static int arm_spe_sample(struct arm_spe_queue *speq)if (spe->sample_flc) {if (record->type &ARM_SPE_L1D_MISS ) { - err =arm_spe_synth_spe_events_sample ( - speq, spe->l1d_miss_id); + err =arm_spe__synth_mem_sample (speq, spe->l1d_miss_id);if (err)return err; }if (record->type &ARM_SPE_L1D_ACCESS ) { - err =arm_spe_synth_spe_events_sample ( - speq, spe->l1d_access_id); + err =arm_spe__synth_mem_sample (speq, spe->l1d_access_id);if (err)return err; }
@@ -299,15 +315,13 @@ static int arm_spe_sample(struct arm_spe_queue *speq)if (spe->sample_llc) {if (record->type &ARM_SPE_LLC_MISS ) { - err =arm_spe_synth_spe_events_sample ( - speq, spe->llc_miss_id); + err =arm_spe__synth_mem_sample (speq, spe->llc_miss_id);if (err)return err; }if (record->type &ARM_SPE_LLC_ACCESS ) { - err =arm_spe_synth_spe_events_sample ( - speq, spe->llc_access_id); + err =arm_spe__synth_mem_sample (speq, spe->llc_access_id);if (err)return err; }
@@ -315,31 +329,27 @@ static int arm_spe_sample(struct arm_spe_queue *speq)if (spe->sample_tlb) {if (record->type &ARM_SPE_TLB_MISS ) { - err =arm_spe_synth_spe_events_sample ( - speq, spe->tlb_miss_id); + err =arm_spe__synth_mem_sample (speq, spe->tlb_miss_id);if (err)return err; }if (record->type &ARM_SPE_TLB_ACCESS ) { - err =arm_spe_synth_spe_events_sample ( - speq, spe->tlb_access_id); + err =arm_spe__synth_mem_sample (speq, spe->tlb_access_id);if (err)return err; } }if (spe->sample_branch && (record->type &ARM_SPE_BRANCH_MISS )) { - err =arm_spe_synth_spe_events_sample (speq, - spe->branch_miss_id); + err =arm_spe__synth_branch_sample (speq, spe->branch_miss_id);if (err)return err; }if (spe->sample_remote_access && (record->type &ARM_SPE_REMOTE_ACCESS )) { - err =arm_spe_synth_spe_events_sample (speq, - spe->remote_access_id); + err =arm_spe__synth_mem_sample (speq, spe->remote_access_id);if (err)return err; }
Signature · 1 line
2.28.0
PATCH v2 5/6 perf arm-spe: Synthesize memory event
In reply to James ClarkFrom: Leo Yan <[email protected]>
The memory event can deliver two benefits:
- The first benefit is the memory event can give out global view for memory accessing, rather than organizing events with scatter mode (e.g. uses separate event for L1 cache, last level cache, etc) which which can only display a event for single memory type, memory events include all memory accessing so it can display the data accessing cross memory levels in the same view;
- The second benefit is the sample generation might introduce a big overhead and need to wait for long time for Perf reporting, we can specify itrace option '--itrace=M' to filter out other events and only output memory events, this can significantly reduce the overhead caused by generating samples.
This patch is to enable memory event for Arm SPE.
--- tools/perf/util/arm-spe.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
tools/perf/util/arm-spe.c +30 -0
@@ -53,6 +53,7 @@ struct arm_spe {u8 sample_tlb;u8 sample_branch;u8 sample_remote_access; +u8 sample_memory;u64 l1d_miss_id;u64 l1d_access_id;
@@ -62,6 +63,7 @@ struct arm_spe {u64 tlb_access_id;u64 branch_miss_id;u64 remote_access_id; +u64 memory_id;u64 kernel_start;
@@ -293,6 +295,18 @@ static int arm_spe__synth_branch_sample(struct arm_spe_queue *speq,return arm_spe_deliver_synth_event (spe, speq, event, &sample); } +#define SPE_MEM_TYPE (ARM_SPE_L1D_ACCESS | ARM_SPE_L1D_MISS | \ + ARM_SPE_LLC_ACCESS | ARM_SPE_LLC_MISS | \ + ARM_SPE_REMOTE_ACCESS) + +static bool arm_spe__is_memory_event (enum arm_spe_sample_type type) +{ +if (type &SPE_MEM_TYPE ) +return true; + +return false; +} +static int arm_spe_sample (struct arm_spe_queue *speq) {const struct arm_spe_record *record = &speq->decoder->record;
@@ -354,6 +368,12 @@ static int arm_spe_sample(struct arm_spe_queue *speq)return err; } +if (spe->sample_memory &&arm_spe__is_memory_event (record->type)) { + err =arm_spe__synth_mem_sample (speq, spe->memory_id); +if (err) +return err; + } +return 0 ; }
@@ -917,6 +937,16 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session) id +=1 ; } +if (spe->synth_opts.mem) { + spe->sample_memory = true; + + err =arm_spe_synth_event (session, &attr, id); +if (err) +return err; + spe->memory_id = id; +arm_spe_set_event_name (evlist, id,"memory" ); + } +return 0 ; }
Signature · 1 line
2.28.0
PATCH v2 6/6 perf arm-spe: Set sample's data source field
In reply to James ClarkFrom: Leo Yan <[email protected]>
The sample structure contains the field 'data_src' which is used to tell the data operation attributions, e.g. operation type is loading or storing, cache level, it's snooping or remote accessing, etc. At the end, the 'data_src' will be parsed by perf mem/c2c tools to display human readable strings.
This patch is to fill the 'data_src' field in the synthesized samples base on different types. Currently perf tool can display statistics for L1/L2/L3 caches but it doesn't support the 'last level cache'. To fit to current implementation, 'data_src' field uses L3 cache for last level cache.
Before this commit, perf mem report looks like this:
# Samples: 75K of event 'l1d-miss'
# Total weight : 75951
# Sort order : local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked
#
# Overhead Samples Local Weight Memory access Symbol Shared Object Data Symbol Data Object Snoop TLB access
# ........ ............ ............ ........................ ...................... ................ ...................... ................ ............ ...................
#
81.56% 61945 0 N/A [.] 0x00000000000009d8 serial_c [.] 0000000000000000 [unknown] N/A N/A
18.44% 14003 0 N/A [.] 0x0000000000000828 serial_c [.] 0000000000000000 [unknown] N/A N/ANow on a system with Arm SPE, addresses and access types are displayed:
# Samples: 75K of event 'l1d-miss'
# Total weight : 75951
# Sort order : local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked
#
# Overhead Samples Local Weight Memory access Symbol Shared Object Data Symbol Data Object Snoop TLB access
# ........ ............ ............ ........................ ...................... ................ ...................... ........... ............ ......................
#
0.43% 324 0 L1 miss [.] 0x00000000000009d8 serial_c [.] 0x0000ffff80794e00 anon N/A Walker hit
0.42% 322 0 L1 miss [.] 0x00000000000009d8 serial_c [.] 0x0000ffff80794580 anon N/A Walker hit--- tools/perf/util/arm-spe.c | 69 ++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 9 deletions(-)
tools/perf/util/arm-spe.c +60 -9
@@ -261,7 +261,7 @@ arm_spe_deliver_synth_event(struct arm_spe *spe, }static int arm_spe__synth_mem_sample (struct arm_spe_queue *speq, -u64 spe_events_id) +u64 spe_events_id,u64 data_src) {struct arm_spe *spe = speq->spe;struct arm_spe_record *record = &speq->decoder->record;
@@ -274,6 +274,7 @@ static int arm_spe__synth_mem_sample(struct arm_spe_queue *speq, sample.stream_id = spe_events_id; sample.addr = record->virt_addr; sample.phys_addr = record->phys_addr; + sample.data_src = data_src;return arm_spe_deliver_synth_event (spe, speq, event, &sample); }
@@ -307,21 +308,66 @@ static bool arm_spe__is_memory_event(enum arm_spe_sample_type type)return false; } +static u64 arm_spe__synth_data_source (const struct arm_spe_record *record) +{ +union perf_mem_data_src data_src = {0 }; + +if (record->op ==ARM_SPE_LD ) + data_src.mem_op =PERF_MEM_OP_LOAD ; +else + data_src.mem_op =PERF_MEM_OP_STORE ; + +if (record->type & (ARM_SPE_LLC_ACCESS |ARM_SPE_LLC_MISS )) { + data_src.mem_lvl =PERF_MEM_LVL_L3 ; + +if (record->type &ARM_SPE_LLC_MISS ) + data_src.mem_lvl |=PERF_MEM_LVL_MISS ; +else + data_src.mem_lvl |=PERF_MEM_LVL_HIT ; + }else if (record->type & (ARM_SPE_L1D_ACCESS |ARM_SPE_L1D_MISS )) { + data_src.mem_lvl =PERF_MEM_LVL_L1 ; + +if (record->type &ARM_SPE_L1D_MISS ) + data_src.mem_lvl |=PERF_MEM_LVL_MISS ; +else + data_src.mem_lvl |=PERF_MEM_LVL_HIT ; + } + +if (record->type &ARM_SPE_REMOTE_ACCESS ) + data_src.mem_lvl |=PERF_MEM_LVL_REM_CCE1 ; + +if (record->type & (ARM_SPE_TLB_ACCESS |ARM_SPE_TLB_MISS )) { + data_src.mem_dtlb =PERF_MEM_TLB_WK ; + +if (record->type &ARM_SPE_TLB_MISS ) + data_src.mem_dtlb |=PERF_MEM_TLB_MISS ; +else + data_src.mem_dtlb |=PERF_MEM_TLB_HIT ; + } + +return data_src.val; +} +static int arm_spe_sample (struct arm_spe_queue *speq) {const struct arm_spe_record *record = &speq->decoder->record;struct arm_spe *spe = speq->spe; +u64 data_src;int err; + data_src =arm_spe__synth_data_source (record); +if (spe->sample_flc) {if (record->type &ARM_SPE_L1D_MISS ) { - err =arm_spe__synth_mem_sample (speq, spe->l1d_miss_id); + err =arm_spe__synth_mem_sample (speq, spe->l1d_miss_id, + data_src);if (err)return err; }if (record->type &ARM_SPE_L1D_ACCESS ) { - err =arm_spe__synth_mem_sample (speq, spe->l1d_access_id); + err =arm_spe__synth_mem_sample (speq, spe->l1d_access_id, + data_src);if (err)return err; }
@@ -329,13 +375,15 @@ static int arm_spe_sample(struct arm_spe_queue *speq)if (spe->sample_llc) {if (record->type &ARM_SPE_LLC_MISS ) { - err =arm_spe__synth_mem_sample (speq, spe->llc_miss_id); + err =arm_spe__synth_mem_sample (speq, spe->llc_miss_id, + data_src);if (err)return err; }if (record->type &ARM_SPE_LLC_ACCESS ) { - err =arm_spe__synth_mem_sample (speq, spe->llc_access_id); + err =arm_spe__synth_mem_sample (speq, spe->llc_access_id, + data_src);if (err)return err; }
@@ -343,13 +391,15 @@ static int arm_spe_sample(struct arm_spe_queue *speq)if (spe->sample_tlb) {if (record->type &ARM_SPE_TLB_MISS ) { - err =arm_spe__synth_mem_sample (speq, spe->tlb_miss_id); + err =arm_spe__synth_mem_sample (speq, spe->tlb_miss_id, + data_src);if (err)return err; }if (record->type &ARM_SPE_TLB_ACCESS ) { - err =arm_spe__synth_mem_sample (speq, spe->tlb_access_id); + err =arm_spe__synth_mem_sample (speq, spe->tlb_access_id, + data_src);if (err)return err; }
@@ -363,13 +413,14 @@ static int arm_spe_sample(struct arm_spe_queue *speq)if (spe->sample_remote_access && (record->type &ARM_SPE_REMOTE_ACCESS )) { - err =arm_spe__synth_mem_sample (speq, spe->remote_access_id); + err =arm_spe__synth_mem_sample (speq, spe->remote_access_id, + data_src);if (err)return err; }if (spe->sample_memory &&arm_spe__is_memory_event (record->type)) { - err =arm_spe__synth_mem_sample (speq, spe->memory_id); + err =arm_spe__synth_mem_sample (speq, spe->memory_id, data_src);if (err)return err; }
Signature · 1 line
2.28.0
Arnaldo Carvalho de Melo
maintainerEm Thu, Feb 11, 2021 at 03:38:51PM +0200, James Clark escreveu:
Quoted 5 lines
From: Leo Yan <[email protected]>
This patch is to enable sample type
PERF_SAMPLE_DATA_SRCfor Arm SPE in the perf data, when output the tracing data, it tells tools that it contains data source in the memory event.
Thanks, series applied.
- Arnaldo
Quoted 8 lines · Arnaldo Carvalho de Melo
Em Thu, Feb 11, 2021 at 03:38:51PM +0200, James Clark escreveu:
Quoted 5 lines
From: Leo Yan <[email protected]>
This patch is to enable sample type
PERF_SAMPLE_DATA_SRCfor Arm SPE in the perf data, when output the tracing data, it tells tools that it contains data source in the memory event.Thanks, series applied.
Thanks a lot, James and Arnaldo.