perf: arm-spe: Fix addresses of synthesized Arm SPE events
Subsystems (5)
cover perf: arm-spe: Fix addresses of synthesized Arm SPE events
This patch set fixes problems related to address in synthesized events from SPE.
Committer testing:
perf record --no-bpf-event -e arm_spe_0/pa_enable=1/ -- sleep 1 perf inject -i perf.data -o perf-inj.data --itrace --strip perf script -i perf-inj.data --fields hw:+addr,+phys_addr
Before:
sleep 49337 [004] 20133.731889: 1 l1d-access: ffffcbebcde1d5b8 [unknown] ([unknown]) sleep 49337 [004] 20133.731889: 1 tlb-access: ffffcbebcde1d5b8 [unknown] ([unknown]) sleep 49337 [004] 20133.731889: 1 memory: ffffcbebcde1d5b8 [unknown] ([unknown])
After:
sleep 49337 [004] 20133.731889: 1 l1d-access: ffff800034123970 ffffcbebcde1d5b8 [unknown] ([unknown]) 153d19970 sleep 49337 [004] 20133.731889: 1 tlb-access: ffff800034123970 ffffcbebcde1d5b8 [unknown] ([unknown]) 153d19970 sleep 49337 [004] 20133.731889: 1 memory: ffff800034123970 ffffcbebcde1d5b8 [unknown] ([unknown]) 153d19970
tools/perf/arch/arm64/util/arm-spe.c | 10 ++++++++++ tools/perf/tests/attr/README | 1 + tools/perf/tests/attr/test-record-spe-physical-address | 12 ++++++++++++ tools/perf/util/arm-spe.c | 5 +++-- 4 files changed, 26 insertions(+), 2 deletions(-)
PATCH 1/3 perf: arm-spe: Fix addresses of synthesized SPE events
This patch corrects a bug whereby synthesized events from SPE samples are missing virtual addresses.
--- tools/perf/util/arm-spe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/arm-spe.c +1 -1
@@ -1036,7 +1036,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session) 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_DATA_SRC | -PERF_SAMPLE_WEIGHT ; +PERF_SAMPLE_WEIGHT |PERF_SAMPLE_ADDR ;if (spe->timeless_decoding) attr.sample_type &= ~(u64 )PERF_SAMPLE_TIME ;else
Signature · 1 line
2.25.1
Re: [PATCH 1/3] perf: arm-spe: Fix addresses of synthesized SPE events
Quoted 4 lines · Timothy Hayes
This patch corrects a bug whereby synthesized events from SPE samples are missing virtual addresses.
Signed-off-by Timothy Hayes <[email protected]>
Quoted 20 lines
--- tools/perf/util/arm-spe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/util/arm-spe.c +1
-1@@ -1036,7 +1036,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session) 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_DATA_SRC | -PERF_SAMPLE_WEIGHT ; +PERF_SAMPLE_WEIGHT |PERF_SAMPLE_ADDR ;if (spe->timeless_decoding) attr.sample_type &= ~(u64 )PERF_SAMPLE_TIME ;else Signature · 1 line
2.25.1
Re: [PATCH 1/3] perf: arm-spe: Fix addresses of synthesized SPE events
Quoted 7 lines · Leo Yan
Quoted 4 lines · Timothy Hayes
This patch corrects a bug whereby synthesized events from SPE samples are missing virtual addresses.
Signed-off-by Timothy Hayes <[email protected]>Reviewed-by Leo Yan <[email protected]>
Supplement for fixed tag:
Since patches 01, 02 are fixing bugs, please add fixed tag [1]:
Thanks,
Leo
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 2/3 perf: arm-spe: Fix SPE events with phys addresses
In reply to Timothy HayesThis patch corrects a bug whereby SPE collection is invoked with pa_enable=1 but synthesized events fail to show physical addresses.
--- tools/perf/arch/arm64/util/arm-spe.c | 10 ++++++++++ tools/perf/util/arm-spe.c | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-)
tools/perf/arch/arm64/util/arm-spe.c +10 -0
@@ -148,6 +148,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,bool privileged =perf_event_paranoid_check (-1 );struct evsel *tracking_evsel;int err; +u64 bit; sper->evlist = evlist;
@@ -245,6 +246,15 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,*/ evsel__set_sample_bit (arm_spe_evsel,DATA_SRC ); +/* +* The PHYS_ADDR flag does not affect the driver behaviour, it is used to +* inform that the resulting output's SPE samples contain physical addresses +* where applicable. +*/ + bit =perf_pmu__format_bits (&arm_spe_pmu->format,"pa_enable" ); +if (arm_spe_evsel->core.attr.config & bit) +evsel__set_sample_bit (arm_spe_evsel,PHYS_ADDR ); +/* Add dummy event to keep tracking */ err =parse_events (evlist,"dummy:u" ,NULL );if (err)
tools/perf/util/arm-spe.c +2 -1
@@ -1033,7 +1033,8 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)memset (&attr,0 ,sizeof (struct perf_event_attr )); attr.size =sizeof (struct perf_event_attr ); attr.type =PERF_TYPE_HARDWARE ; - attr.sample_type = evsel->core.attr.sample_type &PERF_SAMPLE_MASK ; + attr.sample_type = evsel->core.attr.sample_type & + (PERF_SAMPLE_MASK |PERF_SAMPLE_PHYS_ADDR ); attr.sample_type |=PERF_SAMPLE_IP |PERF_SAMPLE_TID |PERF_SAMPLE_PERIOD |PERF_SAMPLE_DATA_SRC |PERF_SAMPLE_WEIGHT |PERF_SAMPLE_ADDR ;
Signature · 1 line
2.25.1
Re: [PATCH 2/3] perf: arm-spe: Fix SPE events with phys addresses
Hi Timothy,
Quoted 42 lines · Timothy Hayes
This patch corrects a bug whereby SPE collection is invoked with pa_enable=1 but synthesized events fail to show physical addresses.
Signed-off-by Timothy Hayes <[email protected]>--- tools/perf/arch/arm64/util/arm-spe.c | 10 ++++++++++ tools/perf/util/arm-spe.c | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-)tools/perf/arch/arm64/util/arm-spe.c +10
-0@@ -148,6 +148,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,bool privileged =perf_event_paranoid_check (-1 );struct evsel *tracking_evsel;int err; +u64 bit; sper->evlist = evlist;@@ -245,6 +246,15 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,*/ evsel__set_sample_bit (arm_spe_evsel,DATA_SRC ); +/* +* The PHYS_ADDR flag does not affect the driver behaviour, it is used to +* inform that the resulting output's SPE samples contain physical addresses +* where applicable. +*/ + bit =perf_pmu__format_bits (&arm_spe_pmu->format,"pa_enable" ); +if (arm_spe_evsel->core.attr.config & bit) +evsel__set_sample_bit (arm_spe_evsel,PHYS_ADDR ); +/* Add dummy event to keep tracking */ err =parse_events (evlist,"dummy:u" ,NULL );if (err)tools/perf/util/arm-spe.c +0
-0
tools/perf/util/arm-spe.c arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session) · line 1037
Quoted 6 lines
tools/perf/util/arm-spe.c +2
-1@@ -1033,7 +1033,8 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)memset (&attr,0 ,sizeof (struct perf_event_attr )); attr.size =sizeof (struct perf_event_attr ); attr.type =PERF_TYPE_HARDWARE ; - attr.sample_type = evsel->core.attr.sample_type &PERF_SAMPLE_MASK ; + attr.sample_type = evsel->core.attr.sample_type & + (PERF_SAMPLE_MASK |PERF_SAMPLE_PHYS_ADDR );
I verified this patch and I can confirm the physical address can be dumped successfully.
I have a more general question, seems to me, we need to change the macro PERF_SAMPLE_MASK in the file util/event.h as below, so here doesn't need to 'or' the flag PERF_SAMPLE_PHYS_ADDR anymore.
@Arnaldo, @Jiri, could you confirm if this is the right way to move forward? I am not sure why PERF_SAMPLE_MASK doesn't contain the bit PERF_SAMPLE_PHYS_ADDR in current code.
tools/perf/util/event.h +1 -1
@@ -39,7 +39,7 @@ struct perf_event_attr;PERF_SAMPLE_TIME |PERF_SAMPLE_ADDR | \PERF_SAMPLE_ID |PERF_SAMPLE_STREAM_ID | \PERF_SAMPLE_CPU |PERF_SAMPLE_PERIOD | \ - PERF_SAMPLE_IDENTIFIER) + PERF_SAMPLE_IDENTIFIER | PERF_SAMPLE_PHYS_ADDR)
Thanks,
Leo
Quoted 6 lines
tools/perf/util/arm-spe.c +0
-0attr.sample_type |=PERF_SAMPLE_IP |PERF_SAMPLE_TID |PERF_SAMPLE_PERIOD |PERF_SAMPLE_DATA_SRC |PERF_SAMPLE_WEIGHT |PERF_SAMPLE_ADDR ;Signature · 1 line
2.25.1
Re: [PATCH 2/3] perf: arm-spe: Fix SPE events with phys addresses
Quoted 55 lines · Leo Yan
Hi Timothy,
Quoted 42 lines · Timothy Hayes
This patch corrects a bug whereby SPE collection is invoked with pa_enable=1 but synthesized events fail to show physical addresses.
Signed-off-by Timothy Hayes <[email protected]>--- tools/perf/arch/arm64/util/arm-spe.c | 10 ++++++++++ tools/perf/util/arm-spe.c | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-)tools/perf/arch/arm64/util/arm-spe.c +10
-0@@ -148,6 +148,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,bool privileged =perf_event_paranoid_check (-1 );struct evsel *tracking_evsel;int err; +u64 bit; sper->evlist = evlist;@@ -245,6 +246,15 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,*/ evsel__set_sample_bit (arm_spe_evsel,DATA_SRC ); +/* +* The PHYS_ADDR flag does not affect the driver behaviour, it is used to +* inform that the resulting output's SPE samples contain physical addresses +* where applicable. +*/ + bit =perf_pmu__format_bits (&arm_spe_pmu->format,"pa_enable" ); +if (arm_spe_evsel->core.attr.config & bit) +evsel__set_sample_bit (arm_spe_evsel,PHYS_ADDR ); +/* Add dummy event to keep tracking */ err =parse_events (evlist,"dummy:u" ,NULL );if (err)tools/perf/util/arm-spe.c +0
-0tools/perf/util/arm-spe.c arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session) · line 1037
Quoted 6 lines
tools/perf/util/arm-spe.c +2
-1@@ -1033,7 +1033,8 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)memset (&attr,0 ,sizeof (struct perf_event_attr )); attr.size =sizeof (struct perf_event_attr ); attr.type =PERF_TYPE_HARDWARE ; - attr.sample_type = evsel->core.attr.sample_type &PERF_SAMPLE_MASK ; + attr.sample_type = evsel->core.attr.sample_type & + (PERF_SAMPLE_MASK |PERF_SAMPLE_PHYS_ADDR );I verified this patch and I can confirm the physical address can be dumped successfully.
Quoted 7 lines
I have a more general question, seems to me, we need to change the macro
PERF_SAMPLE_MASKin the fileutil/event.has below, so here doesn't need to 'or' the flagPERF_SAMPLE_PHYS_ADDRanymore.@Arnaldo, @Jiri, could you confirm if this is the right way to move forward? I am not sure why
PERF_SAMPLE_MASKdoesn't contain the bitPERF_SAMPLE_PHYS_ADDRin current code.
I think there is a reason that PERF_SAMPLE_MASK is a subset of all the bits. This comment below suggests it. Is it so the mask only includes fields that are 64bits? That makes the __evsel__sample_size() function a simple multiplication of a count of all the fields that are 64bits.
static int
perf_event__check_size(union perf_event *event, unsigned int sample_size)
{
/*
* The evsel's sample_size is based on PERF_SAMPLE_MASK which includes
* up to PERF_SAMPLE_PERIOD. After that overflow() must be used to
* check the format does not go past the end of the event.
*/
if (sample_size + sizeof(event->header) > event->header.size)
return -EFAULT;
return 0;}
Having said that, the mask was updated once to add PERF_SAMPLE_IDENTIFIER to it, so that comment is slightly out of date now.
Quoted 21 lines
tools/perf/util/event.h +1
-1@@ -39,7 +39,7 @@ struct perf_event_attr;PERF_SAMPLE_TIME |PERF_SAMPLE_ADDR | \PERF_SAMPLE_ID |PERF_SAMPLE_STREAM_ID | \PERF_SAMPLE_CPU |PERF_SAMPLE_PERIOD | \ - PERF_SAMPLE_IDENTIFIER) + PERF_SAMPLE_IDENTIFIER | PERF_SAMPLE_PHYS_ADDR) Thanks,Leo
Quoted 6 lines
tools/perf/util/arm-spe.c +0
-0attr.sample_type |=PERF_SAMPLE_IP |PERF_SAMPLE_TID |PERF_SAMPLE_PERIOD |PERF_SAMPLE_DATA_SRC |PERF_SAMPLE_WEIGHT |PERF_SAMPLE_ADDR ;Signature · 1 line
2.25.1
Leo Yan
Reviewed-byRe: [PATCH 2/3] perf: arm-spe: Fix SPE events with phys addresses
On Mon, Apr 25, 2022 at 10:12:36AM +0100, James Clark wrote:
[...]
Quoted 19 lines
Quoted 19 lines
tools/perf/util/arm-spe.c arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session) · line 1037
Quoted 11 lines
tools/perf/util/arm-spe.c +2
-1@@ -1033,7 +1033,8 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)memset (&attr,0 ,sizeof (struct perf_event_attr )); attr.size =sizeof (struct perf_event_attr ); attr.type =PERF_TYPE_HARDWARE ; - attr.sample_type = evsel->core.attr.sample_type &PERF_SAMPLE_MASK ; + attr.sample_type = evsel->core.attr.sample_type & + (PERF_SAMPLE_MASK |PERF_SAMPLE_PHYS_ADDR );I verified this patch and I can confirm the physical address can be dumped successfully.
I have a more general question, seems to me, we need to change the macro
PERF_SAMPLE_MASKin the fileutil/event.has below, so here doesn't need to 'or' the flagPERF_SAMPLE_PHYS_ADDRanymore.
Quoted 8 lines
Quoted 3 lines
@Arnaldo, @Jiri, could you confirm if this is the right way to move forward? I am not sure why
PERF_SAMPLE_MASKdoesn't contain the bitPERF_SAMPLE_PHYS_ADDRin current code.I think there is a reason that
PERF_SAMPLE_MASKis a subset of all the bits. This comment below suggests it. Is it so the mask only includes fields that are 64bits? That makes the__evsel__sample_size()function a simple multiplication of a count of all the fields that are 64bits.
After reading code, seems the conclusion "a count of all the fields that are 64bits" is not valid. PERF_SAMPLE_MASK contains bits PERF_SAMPLE_IP and PERF_SAMPLE_TID, the corresponding fields 'pid' and 'tid' in the structure perf_sample are u32 type.
Quoted 10 lines
static int
perf_event__check_size(union perf_event *event, unsigned int sample_size){ /* * The evsel's sample_size is based on PERF_SAMPLE_MASK which includes * up to PERF_SAMPLE_PERIOD. After that overflow() must be used to * check the format does not go past the end of the event. */ if (sample_size + sizeof(event->header) > event->header.size) return -EFAULT;
Okay, thanks for sharing the info, it does show that it's deliberately to not contain all fields in PERF_SAMPLE_MASK. If so, this patch is fine for me:
Quoted 28 lines
return 0;}
Having said that, the mask was updated once to add
PERF_SAMPLE_IDENTIFIERto it, so that comment is slightly out of date now.Quoted 21 lines
tools/perf/util/event.h +1
-1@@ -39,7 +39,7 @@ struct perf_event_attr;PERF_SAMPLE_TIME |PERF_SAMPLE_ADDR | \PERF_SAMPLE_ID |PERF_SAMPLE_STREAM_ID | \PERF_SAMPLE_CPU |PERF_SAMPLE_PERIOD | \ - PERF_SAMPLE_IDENTIFIER) + PERF_SAMPLE_IDENTIFIER | PERF_SAMPLE_PHYS_ADDR) Thanks,Leo
Quoted 6 lines
tools/perf/util/arm-spe.c +0
-0attr.sample_type |=PERF_SAMPLE_IP |PERF_SAMPLE_TID |PERF_SAMPLE_PERIOD |PERF_SAMPLE_DATA_SRC |PERF_SAMPLE_WEIGHT |PERF_SAMPLE_ADDR ;Signature · 1 line
2.25.1
PATCH 3/3 perf test: Add perf_event_attr test for Arm SPE
In reply to Timothy HayesAdds a perf_event_attr test for Arm SPE in which the presence of physical addresses are checked when SPE unit is run with pa_enable=1.
--- tools/perf/tests/attr/README | 1 + .../perf/tests/attr/test-record-spe-physical-address | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tools/perf/tests/attr/test-record-spe-physical-address
tools/perf/tests/attr/README +1 -0
@@ -60,6 +60,7 @@ Following tests are defined (with perf commands): perf record -R kill (test-record-raw) perf record -c 2 -e arm_spe_0// -- kill (test-record-spe-period) perf record -e arm_spe_0/period=3/ -- kill (test-record-spe-period-term) + perf record -e arm_spe_0/pa_enable=1/ -- kill (test-record-spe-physical-address) perf stat -e cycles kill (test-stat-basic) perf stat kill (test-stat-default) perf stat -d kill (test-stat-detailed-1)
tools/perf/tests/attr/test-record-spe-physical-address new file +12 -0
@@ -0,0 +1,12 @@ +[config] +command = record +args = --no-bpf-event -e arm_spe_0/pa_enable=1/ -- kill >/dev/null 2>&1 +ret = 1 +arch = aarch64 + +[event-10:base-record-spe] +# 622727 is the decimal of IP|TID|TIME|CPU|IDENTIFIER|DATA_SRC|PHYS_ADDR +sample_type=622727 + +# dummy event +[event-1:base-record-spe]
Signature · 1 line
2.25.1
Re: [PATCH 3/3] perf test: Add perf_event_attr test for Arm SPE
Quoted 4 lines · Timothy Hayes
Adds a
perf_event_attrtest for Arm SPE in which the presence of physical addresses are checked when SPE unit is run with pa_enable=1.Signed-off-by Timothy Hayes <[email protected]>
Quoted 40 lines
--- tools/perf/tests/attr/README | 1 + .../perf/tests/attr/test-record-spe-physical-address | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tools/perf/tests/attr/test-record-spe-physical-addresstools/perf/tests/attr/README +1
-0@@ -60,6 +60,7 @@ Following tests are defined (with perf commands): perf record -R kill (test-record-raw) perf record -c 2 -e arm_spe_0// -- kill (test-record-spe-period) perf record -e arm_spe_0/period=3/ -- kill (test-record-spe-period-term) + perf record -e arm_spe_0/pa_enable=1/ -- kill (test-record-spe-physical-address) perf stat -e cycles kill (test-stat-basic) perf stat kill (test-stat-default) perf stat -d kill (test-stat-detailed-1)tools/perf/tests/attr/test-record-spe-physical-address new file +12
-0@@ -0,0 +1,12 @@ +[config] +command = record +args = --no-bpf-event -e arm_spe_0/pa_enable=1/ -- kill >/dev/null 2>&1 +ret = 1 +arch = aarch64 + +[event-10:base-record-spe] +# 622727 is the decimal of IP|TID|TIME|CPU|IDENTIFIER|DATA_SRC|PHYS_ADDR +sample_type=622727 + +# dummy event +[event-1:base-record-spe]Signature · 1 line
2.25.1
Re: [PATCH 3/3] perf test: Add perf_event_attr test for Arm SPE
Em Sun, Apr 24, 2022 at 10:53:07PM +0800, Leo Yan escreveu:
Quoted 8 lines · Timothy Hayes
Quoted 4 lines
Adds a
perf_event_attrtest for Arm SPE in which the presence of physical addresses are checked when SPE unit is run with pa_enable=1.Signed-off-by Timothy Hayes <[email protected]>Reviewed-by Leo Yan <[email protected]>Tested-by Leo Yan <[email protected]>
Thanks, applied the set to perf/urgent.
- Arnaldo
Quoted 40 lines
Quoted 40 lines
--- tools/perf/tests/attr/README | 1 + .../perf/tests/attr/test-record-spe-physical-address | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tools/perf/tests/attr/test-record-spe-physical-addresstools/perf/tests/attr/README +1
-0@@ -60,6 +60,7 @@ Following tests are defined (with perf commands): perf record -R kill (test-record-raw) perf record -c 2 -e arm_spe_0// -- kill (test-record-spe-period) perf record -e arm_spe_0/period=3/ -- kill (test-record-spe-period-term) + perf record -e arm_spe_0/pa_enable=1/ -- kill (test-record-spe-physical-address) perf stat -e cycles kill (test-stat-basic) perf stat kill (test-stat-default) perf stat -d kill (test-stat-detailed-1)tools/perf/tests/attr/test-record-spe-physical-address new file +12
-0@@ -0,0 +1,12 @@ +[config] +command = record +args = --no-bpf-event -e arm_spe_0/pa_enable=1/ -- kill >/dev/null 2>&1 +ret = 1 +arch = aarch64 + +[event-10:base-record-spe] +# 622727 is the decimal of IP|TID|TIME|CPU|IDENTIFIER|DATA_SRC|PHYS_ADDR +sample_type=622727 + +# dummy event +[event-1:base-record-spe]Signature · 1 line
2.25.1
Signature · 1 line
- Arnaldo