perf: Expand perf_branch_entry
Subsystems (2)
v4 cover perf: Expand perf_branch_entry
Branch Record Buffer Extension (BRBE) implementation on arm64 captures more branch type classification which cannot be accommodated in the current perf branch record format via perf_branch_entry.type element (4 bit field). Also it captures privilege information which does not have a corresponding slot in perf_branch_entry. This series expands struct perf_branch_entry, to meet both these requirements without breaking the existing user space ABI for perf tools.
All architecture specific branch types added via perf_branch_entry.new_type field in [PATCH 3/4] will be used in BRBE implementation on arm64 platform later on with the following map.
#ifdef CONFIG_ARM64
#define PERF_BR_FIQ PERF_BR_NEW_ARCH_1
#define PERF_BR_DEBUG_HALT PERF_BR_NEW_ARCH_2
#define PERF_BR_DEBUG_EXIT PERF_BR_NEW_ARCH_3
#define PERF_BR_DEBUG_INST PERF_BR_NEW_ARCH_4
#define PERF_BR_DEBUG_DATA PERF_BR_NEW_ARCH_5
#endif
This actually combines following patches and series into a single series.
- https://lore.kernel.org/all/[email protected]/
- https://lore.kernel.org/all/[email protected]/
- https://lore.kernel.org/all/[email protected]/
This series applies on v5.17-rc8
perf API
The series being applied
- Clean : tools/perf/check-headers.sh
- Clean : diff -u tools/include/uapi/linux/perf_event.h include/uapi/linux/perf_event.h
Todo
- Update perf report tool to process PERF_BR_EXTEND_ABI (when available), then fetch and report branch types from perf_branch_entry.new_type field.
References
- BRBE captured branch record information
- BRBE based perf branch stack implementation on arm64 platform
https://lore.kernel.org/all/[email protected]/
Changes in V4:
- Modified the struct branch_flags as required
- Dropped CONFIG_ARM64 from perf header file to avoid build problem
- Renamed PERF_BR_NEW_<BRANCH_TYPE> as PERF_BR_ARM64_<BRANCH_TYPE>
Changes in V3:
https://lore.kernel.org/all/[email protected]/
- Fixed small typo s/privillege/privilege in include/uapi/linux/perf_event.h
- Added PRIV_SHIFT in __p_branch_sample_type()
- Added arm64 platform override of the new arch specific branch types
- Renamed s/PERF_BR_XXX/PERF_BR_PRIV_XXX/ for privilege level branch types
- Added PERF_BR_PRIV_UNKNOWN as the starting value
- Expanded perf_branch_entry.priv into a 3 bits field
Changes in V2:
https://lore.kernel.org/all/[email protected]/
Anshuman Khandual (10):
perf: Add irq and exception return branch types
perf: Add system error and not in transaction branch types
perf: Extend branch type classification
perf: Capture branch privilege information
perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform perf/tools: Add irq and exception return branch types perf/tools: Add system error and not in transaction branch types perf/tools: Extend branch type classification perf/tools: Add branch privilege information request flag perf/tools: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
arch/x86/events/intel/lbr.c | 6 ++-- include/uapi/linux/perf_event.h | 38 ++++++++++++++++++++++- tools/include/uapi/linux/perf_event.h | 38 ++++++++++++++++++++++- tools/perf/Documentation/perf-record.txt | 1 + tools/perf/util/branch.c | 7 ++++- tools/perf/util/branch.h | 4 ++- tools/perf/util/parse-branch-options.c | 1 + tools/perf/util/perf_event_attr_fprintf.c | 2 +- 8 files changed, 89 insertions(+), 8 deletions(-)
Signature · 1 line
2.25.1
PATCH v4 1/10 perf: Add irq and exception return branch types
This expands generic branch type classification by adding two more entries there in i.e irq and exception return. Also updates the x86 implementation to process X86_BR_IRET and X86_BR_IRQ records as appropriate. This changes branch types reported to user space on x86 platform but it should not be a problem. The possible scenarios and impacts are enumerated here.
--------------------------------------------------------------------------
| kernel | perf tool | Impact |
--------------------------------------------------------------------------
| old | old | Works as before |
--------------------------------------------------------------------------
| old | new | PERF_BR_UNKNOWN is processed |
--------------------------------------------------------------------------
| new | old | PERF_BR_ERET/IRQ are blocked via old PERF_BR_MAX |
--------------------------------------------------------------------------
| new | new | PERF_BR_ERET/IRQ are recognized |
--------------------------------------------------------------------------
When PERF_BR_ERET/IRQ are blocked via old PERF_BR_MAX (new kernel with old perf tool) the user space might throw up an warning complaining about some unrecognized branch types being reported, but it is expected. PERF_BR_ERET and PERF_BR_IRQ branch types will be used for BRBE implementation on arm64 platform.
--- arch/x86/events/intel/lbr.c | 4 ++-- include/uapi/linux/perf_event.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/events/intel/lbr.c +2 -2
@@ -1329,10 +1329,10 @@ static int branch_map[X86_BR_TYPE_MAP_MAX] = {PERF_BR_SYSCALL ,/* X86_BR_SYSCALL */ PERF_BR_SYSRET ,/* X86_BR_SYSRET */ PERF_BR_UNKNOWN ,/* X86_BR_INT */ -PERF_BR_UNKNOWN ,/* X86_BR_IRET */ +PERF_BR_ERET ,/* X86_BR_IRET */ PERF_BR_COND ,/* X86_BR_JCC */ PERF_BR_UNCOND ,/* X86_BR_JMP */ -PERF_BR_UNKNOWN ,/* X86_BR_IRQ */ +PERF_BR_IRQ ,/* X86_BR_IRQ */ PERF_BR_IND_CALL ,/* X86_BR_IND_CALL */ PERF_BR_UNKNOWN ,/* X86_BR_ABORT */ PERF_BR_UNKNOWN, /* X86_BR_IN_TX */
include/uapi/linux/perf_event.h +2 -0
@@ -251,6 +251,8 @@ enum {PERF_BR_SYSRET =8 ,/* syscall return */ PERF_BR_COND_CALL =9 ,/* conditional function call */ PERF_BR_COND_RET =10 ,/* conditional function return */ +PERF_BR_ERET =11 ,/* exception return */ +PERF_BR_IRQ =12 ,/* irq */ PERF_BR_MAX, };
Signature · 1 line
2.25.1
PATCH v4 2/10 perf: Add system error and not in transaction branch types
In reply to Anshuman KhandualThis expands generic branch type classification by adding two more entries there in i.e system error and not in transaction. This also updates the x86 implementation to process X86_BR_NO_TX records as appropriate. This changes branch types reported to user space on x86 platform but it should not be a problem. The possible scenarios and impacts are enumerated here.
--------------------------------------------------------------------------
| kernel | perf tool | Impact |
--------------------------------------------------------------------------
| old | old | Works as before |
--------------------------------------------------------------------------
| old | new | PERF_BR_UNKNOWN is processed |
--------------------------------------------------------------------------
| new | old | PERF_BR_NO_TX are blocked via old PERF_BR_MAX |
--------------------------------------------------------------------------
| new | new | NO_TX are recognized |
--------------------------------------------------------------------------
When PERF_BR_NO_TX is blocked via old PERF_BR_MAX (new kernel with old perf tool) the user space might throw up an warning complaining about an unrecognized branch types being reported, but it's expected. PERF_BR_SERROR & PERF_BR_NO_TX branch types will be used for BRBE implementation on arm64 platform.
PERF_BR_NO_TX complements 'abort' and 'in_tx' elements in perf_branch_entry which represent other transaction states for a given branch record. Because this completes the transaction state classification.
--- arch/x86/events/intel/lbr.c | 2 +- include/uapi/linux/perf_event.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/events/intel/lbr.c +1 -1
@@ -1336,7 +1336,7 @@ static int branch_map[X86_BR_TYPE_MAP_MAX] = {PERF_BR_IND_CALL ,/* X86_BR_IND_CALL */ PERF_BR_UNKNOWN ,/* X86_BR_ABORT */ PERF_BR_UNKNOWN ,/* X86_BR_IN_TX */ -PERF_BR_UNKNOWN ,/* X86_BR_NO_TX */ +PERF_BR_NO_TX ,/* X86_BR_NO_TX */ PERF_BR_CALL ,/* X86_BR_ZERO_CALL */ PERF_BR_UNKNOWN ,/* X86_BR_CALL_STACK */ PERF_BR_IND, /* X86_BR_IND_JMP */
include/uapi/linux/perf_event.h +2 -0
@@ -253,6 +253,8 @@ enum {PERF_BR_COND_RET =10 ,/* conditional function return */ PERF_BR_ERET =11 ,/* exception return */ PERF_BR_IRQ =12 ,/* irq */ +PERF_BR_SERROR =13 ,/* system error */ +PERF_BR_NO_TX =14 ,/* not in transaction */ PERF_BR_MAX, };
Signature · 1 line
2.25.1
PATCH v4 3/10 perf: Extend branch type classification
In reply to Anshuman Khandualbranch_entry.type now has ran out of space to accommodate more branch types classification. This will prevent perf branch stack implementation on arm64 (via BRBE) to capture all available branch types. Extending this bit field i.e branch_entry.type [4 bits] is not an option as it will break user space ABI both for little and big endian perf tools.
Extend branch classification with a new field branch_entry.new_type via a new branch type PERF_BR_EXTEND_ABI in branch_entry.type. Perf tools which could decode PERF_BR_EXTEND_ABI, will then parse branch_entry.new_type as well.
branch_entry.new_type is a 4 bit field which can hold upto 16 branch types. The first three branch types will hold various generic page faults followed by five architecture specific branch types, which can be overridden by the platform for specific use cases. These architecture specific branch types gets overridden on arm64 platform for BRBE implementation.
New generic branch types
- PERF_BR_NEW_FAULT_ALGN
- PERF_BR_NEW_FAULT_DATA
- PERF_BR_NEW_FAULT_INST
New arch specific branch types
- PERF_BR_NEW_ARCH_1
- PERF_BR_NEW_ARCH_2
- PERF_BR_NEW_ARCH_3
- PERF_BR_NEW_ARCH_4
- PERF_BR_NEW_ARCH_5
--- include/uapi/linux/perf_event.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
include/uapi/linux/perf_event.h +15 -1
@@ -255,9 +255,22 @@ enum {PERF_BR_IRQ =12 ,/* irq */ PERF_BR_SERROR =13 ,/* system error */ PERF_BR_NO_TX =14 ,/* not in transaction */ +PERF_BR_EXTEND_ABI =15 ,/* extend ABI */ PERF_BR_MAX, }; +enum { +PERF_BR_NEW_FAULT_ALGN =0 ,/* Alignment fault */ +PERF_BR_NEW_FAULT_DATA =1 ,/* Data fault */ +PERF_BR_NEW_FAULT_INST =2 ,/* Inst fault */ +PERF_BR_NEW_ARCH_1 =3 ,/* Architecture specific */ +PERF_BR_NEW_ARCH_2 =4 ,/* Architecture specific */ +PERF_BR_NEW_ARCH_3 =5 ,/* Architecture specific */ +PERF_BR_NEW_ARCH_4 =6 ,/* Architecture specific */ +PERF_BR_NEW_ARCH_5 =7 ,/* Architecture specific */ +PERF_BR_NEW_MAX , +}; +#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1372,7 +1385,8 @@ struct perf_branch_entry { abort:1, /* transaction abort */ cycles:16, /* cycle count to last branch */ type:4, /* branch type */ - reserved:40; + new_type:4, /* additional branch type */ + reserved:36; };union perf_sample_weight {
Signature · 1 line
2.25.1
Peter Zijlstra
maintainerRe: [PATCH V4 03/10] perf: Extend branch type classification
Quoted 34 lines · Anshuman Khandual
branch_entry.type now has ran out of space to accommodate more branch types classification. This will prevent perf branch stack implementation on arm64 (via BRBE) to capture all available branch types. Extending this bit field i.e branch_entry.type [4 bits] is not an option as it will break user space ABI both for little and big endian perf tools.
Extend branch classification with a new field branch_entry.new_type via a new branch type
PERF_BR_EXTEND_ABIin branch_entry.type. Perf tools which could decodePERF_BR_EXTEND_ABI, will then parse branch_entry.new_type as well.branch_entry.new_type is a 4 bit field which can hold upto 16 branch types. The first three branch types will hold various generic page faults followed by five architecture specific branch types, which can be overridden by the platform for specific use cases. These architecture specific branch types gets overridden on arm64 platform for BRBE implementation.
include/uapi/linux/perf_event.h +1
-0@@ -255,9 +255,22 @@ enum {PERF_BR_IRQ =12 ,/* irq */ PERF_BR_SERROR =13 ,/* system error */ PERF_BR_NO_TX =14 ,/* not in transaction */ +PERF_BR_EXTEND_ABI =15 ,/* extend ABI */ PERF_BR_MAX, };#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\
include/uapi/linux/perf_event.h struct perf_branch_entry { · line 1390
Quoted 7 lines
include/uapi/linux/perf_event.h +2
-1@@ -1372,7 +1385,8 @@ struct perf_branch_entry { abort:1, /* transaction abort */ cycles:16, /* cycle count to last branch */ type:4, /* branch type */ - reserved:40; + new_type:4, /* additional branch type */ + reserved:36; };
Hurmpf... this will effectively give us 5 bits of space for the cost of 8, that seems... unfortunate.
Would something like:
type:4, ext_type:4, reserved:36;
and have all software do:
type = pbe->type | (pbe->ext_type << 4);
Then old software will only know about the old types. New software on old kernels will add 4 0's, which is harmless, while new software on new kernels will get 8 bytes of type.
Would that work?
Re: [PATCH V4 03/10] perf: Extend branch type classification
Quoted 54 lines · Peter Zijlstra
Quoted 34 lines · Anshuman Khandual
branch_entry.type now has ran out of space to accommodate more branch types classification. This will prevent perf branch stack implementation on arm64 (via BRBE) to capture all available branch types. Extending this bit field i.e branch_entry.type [4 bits] is not an option as it will break user space ABI both for little and big endian perf tools.
Extend branch classification with a new field branch_entry.new_type via a new branch type
PERF_BR_EXTEND_ABIin branch_entry.type. Perf tools which could decodePERF_BR_EXTEND_ABI, will then parse branch_entry.new_type as well.branch_entry.new_type is a 4 bit field which can hold upto 16 branch types. The first three branch types will hold various generic page faults followed by five architecture specific branch types, which can be overridden by the platform for specific use cases. These architecture specific branch types gets overridden on arm64 platform for BRBE implementation.
include/uapi/linux/perf_event.h +1
-0@@ -255,9 +255,22 @@ enum {PERF_BR_IRQ =12 ,/* irq */ PERF_BR_SERROR =13 ,/* system error */ PERF_BR_NO_TX =14 ,/* not in transaction */ +PERF_BR_EXTEND_ABI =15 ,/* extend ABI */ PERF_BR_MAX, };#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\include/uapi/linux/perf_event.h struct perf_branch_entry { · line 1390
Quoted 7 lines
include/uapi/linux/perf_event.h +2
-1@@ -1372,7 +1385,8 @@ struct perf_branch_entry { abort:1, /* transaction abort */ cycles:16, /* cycle count to last branch */ type:4, /* branch type */ - reserved:40; + new_type:4, /* additional branch type */ + reserved:36; };Hurmpf... this will effectively give us 5 bits of space for the cost of 8, that seems... unfortunate.
Would something like:
type:4, ext_type:4, reserved:36;and have all software do:
Quoted 7 lines
type = pbe->type | (pbe->ext_type << 4);Then old software will only know about the old types. New software on old kernels will add 4 0's, which is harmless, while new software on new kernels will get 8 bytes of type.
Would that work?
Depends how bad the effects of aliasing in existing software would be, I guess - e.g. new kernel outputs type 0x23 which software then interprets as 0x3 since it doesn't know about the extended bits. I'm guessing that's more likely "confusing to the user" than "catastrophically fatal", but it might still matter.
If software had an explicit opt-in to receiving extended types when requesting branch sampling in the first place we could avoid that worry, but then we'd need some additional complexity to sanitise records depending on that option :/
Robin.
Peter Zijlstra
maintainerRe: [PATCH V4 03/10] perf: Extend branch type classification
Quoted 69 lines · Robin Murphy
Quoted 54 lines · Peter Zijlstra
Quoted 34 lines · Anshuman Khandual
branch_entry.type now has ran out of space to accommodate more branch types classification. This will prevent perf branch stack implementation on arm64 (via BRBE) to capture all available branch types. Extending this bit field i.e branch_entry.type [4 bits] is not an option as it will break user space ABI both for little and big endian perf tools.
Extend branch classification with a new field branch_entry.new_type via a new branch type
PERF_BR_EXTEND_ABIin branch_entry.type. Perf tools which could decodePERF_BR_EXTEND_ABI, will then parse branch_entry.new_type as well.branch_entry.new_type is a 4 bit field which can hold upto 16 branch types. The first three branch types will hold various generic page faults followed by five architecture specific branch types, which can be overridden by the platform for specific use cases. These architecture specific branch types gets overridden on arm64 platform for BRBE implementation.
include/uapi/linux/perf_event.h +1
-0@@ -255,9 +255,22 @@ enum {PERF_BR_IRQ =12 ,/* irq */ PERF_BR_SERROR =13 ,/* system error */ PERF_BR_NO_TX =14 ,/* not in transaction */ +PERF_BR_EXTEND_ABI =15 ,/* extend ABI */ PERF_BR_MAX, };#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\include/uapi/linux/perf_event.h struct perf_branch_entry { · line 1390
Quoted 7 lines
include/uapi/linux/perf_event.h +2
-1@@ -1372,7 +1385,8 @@ struct perf_branch_entry { abort:1, /* transaction abort */ cycles:16, /* cycle count to last branch */ type:4, /* branch type */ - reserved:40; + new_type:4, /* additional branch type */ + reserved:36; };Hurmpf... this will effectively give us 5 bits of space for the cost of 8, that seems... unfortunate.
Would something like:
type:4, ext_type:4, reserved:36;and have all software do:
Quoted 7 lines
type = pbe->type | (pbe->ext_type << 4);Then old software will only know about the old types. New software on old kernels will add 4 0's, which is harmless, while new software on new kernels will get 8 bytes of type.
Would that work?
Depends how bad the effects of aliasing in existing software would be, I guess - e.g. new kernel outputs type
0x23which software then interprets as0x3since it doesn't know about the extended bits. I'm guessing that's more likely "confusing to the user" than "catastrophically fatal", but it might still matter.
Quoted 4 lines
If software had an explicit opt-in to receiving extended types when requesting branch sampling in the first place we could avoid that worry, but then we'd need some additional complexity to sanitise records depending on that option :/
Bah.. I see.. One option is PERF_SAMPLE_BRANCH_STACK2, but yes, yuck.
Re: [PATCH V4 03/10] perf: Extend branch type classification
Quoted 70 lines · Peter Zijlstra
Quoted 69 lines · Robin Murphy
Quoted 54 lines · Peter Zijlstra
Quoted 34 lines · Anshuman Khandual
branch_entry.type now has ran out of space to accommodate more branch types classification. This will prevent perf branch stack implementation on arm64 (via BRBE) to capture all available branch types. Extending this bit field i.e branch_entry.type [4 bits] is not an option as it will break user space ABI both for little and big endian perf tools.
Extend branch classification with a new field branch_entry.new_type via a new branch type
PERF_BR_EXTEND_ABIin branch_entry.type. Perf tools which could decodePERF_BR_EXTEND_ABI, will then parse branch_entry.new_type as well.branch_entry.new_type is a 4 bit field which can hold upto 16 branch types. The first three branch types will hold various generic page faults followed by five architecture specific branch types, which can be overridden by the platform for specific use cases. These architecture specific branch types gets overridden on arm64 platform for BRBE implementation.
include/uapi/linux/perf_event.h +1
-0@@ -255,9 +255,22 @@ enum {PERF_BR_IRQ =12 ,/* irq */ PERF_BR_SERROR =13 ,/* system error */ PERF_BR_NO_TX =14 ,/* not in transaction */ +PERF_BR_EXTEND_ABI =15 ,/* extend ABI */ PERF_BR_MAX, };#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\include/uapi/linux/perf_event.h struct perf_branch_entry { · line 1390
Quoted 7 lines
include/uapi/linux/perf_event.h +2
-1@@ -1372,7 +1385,8 @@ struct perf_branch_entry { abort:1, /* transaction abort */ cycles:16, /* cycle count to last branch */ type:4, /* branch type */ - reserved:40; + new_type:4, /* additional branch type */ + reserved:36; };Hurmpf... this will effectively give us 5 bits of space for the cost of 8, that seems... unfortunate.
Would something like:
type:4, ext_type:4, reserved:36;and have all software do:
Quoted 7 lines
type = pbe->type | (pbe->ext_type << 4);Then old software will only know about the old types. New software on old kernels will add 4 0's, which is harmless, while new software on new kernels will get 8 bytes of type.
Would that work?
Depends how bad the effects of aliasing in existing software would be, I guess - e.g. new kernel outputs type
0x23which software then interprets as0x3since it doesn't know about the extended bits. I'm guessing that's more likely "confusing to the user" than "catastrophically fatal", but it might still matter.
Quoted 6 lines
Quoted 4 lines
If software had an explicit opt-in to receiving extended types when requesting branch sampling in the first place we could avoid that worry, but then we'd need some additional complexity to sanitise records depending on that option :/
Bah.. I see.. One option is
PERF_SAMPLE_BRANCH_STACK2, but yes, yuck.
Could you please elaborate on this ? Are you suggesting to add another perf sample flag i.e PERF_SAMPLE_BRANCH_STACK2 just to capture and process these new branch types ?
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v4 4/10 perf: Capture branch privilege information
In reply to Anshuman KhandualPlatforms like arm64 could capture privilege level information for all the branch records. Hence this adds a new element in the struct branch_entry to record the privilege level information, which could be requested through a new event.attr.branch_sample_type based flag PERF_SAMPLE_BRANCH_PRIV_SAVE. This flag helps user choose whether privilege information is captured.
--- include/uapi/linux/perf_event.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
include/uapi/linux/perf_event.h +13 -1
@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift {PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT =17 ,/* save low level index of raw branch records */ +PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT =18 ,/* save privilege mode */ + PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */ };
@@ -233,6 +235,8 @@ enum perf_branch_sample_type {PERF_SAMPLE_BRANCH_HW_INDEX =1U <<PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT , +PERF_SAMPLE_BRANCH_PRIV_SAVE =1U <<PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT , + PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT, };
@@ -271,6 +275,13 @@ enum { PERF_BR_NEW_MAX, }; +enum { +PERF_BR_PRIV_UNKNOWN =0 , +PERF_BR_PRIV_USER =1 , +PERF_BR_PRIV_KERNEL =2 , +PERF_BR_PRIV_HV =3 , +}; +#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1386,7 +1397,8 @@ struct perf_branch_entry { cycles:16, /* cycle count to last branch */ type:4, /* branch type */ new_type:4, /* additional branch type */ - reserved:36; + priv:3, /* privilege level */ + reserved:33; };union perf_sample_weight {
Signature · 1 line
2.25.1
Re: [PATCH V4 04/10] perf: Capture branch privilege information
Quoted 6 lines · Anshuman Khandual
Platforms like arm64 could capture privilege level information for all the branch records. Hence this adds a new element in the struct
branch_entryto record the privilege level information, which could be requested through a new event.attr.branch_sample_type based flagPERF_SAMPLE_BRANCH_PRIV_SAVE. This flag helps user choose whether privilege information is captured.
Quoted 63 lines
Cc Peter Zijlstra <[email protected]>Cc Ingo Molnar <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Mark Rutland <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>--- include/uapi/linux/perf_event.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)include/uapi/linux/perf_event.h +13
-1@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift {PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT =17 ,/* save low level index of raw branch records */ +PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT =18 ,/* save privilege mode */ + PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */ };@@ -233,6 +235,8 @@ enum perf_branch_sample_type {PERF_SAMPLE_BRANCH_HW_INDEX =1U <<PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT , +PERF_SAMPLE_BRANCH_PRIV_SAVE =1U <<PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT , + PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT, };@@ -271,6 +275,13 @@ enum { PERF_BR_NEW_MAX, }; +enum { +PERF_BR_PRIV_UNKNOWN =0 , +PERF_BR_PRIV_USER =1 , +PERF_BR_PRIV_KERNEL =2 , +PERF_BR_PRIV_HV =3 , +}; +#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\@@ -1386,7 +1397,8 @@ struct perf_branch_entry { cycles:16, /* cycle count to last branch */ type:4, /* branch type */ new_type:4, /* additional branch type */ - reserved:36; + priv:3, /* privilege level */ + reserved:33; };union perf_sample_weight {
PATCH v4 5/10 perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
In reply to Anshuman KhandualBRBE captured branch types will overflow perf_branch_entry.type and generic branch types in perf_branch_entry.new_type. So override each available arch specific branch type in the following manner to comprehensively process all reported branch types in BRBE.
PERF_BR_ARM64_FIQ PERF_BR_NEW_ARCH_1 PERF_BR_ARM64_DEBUG_HALT PERF_BR_NEW_ARCH_2 PERF_BR_ARM64_DEBUG_EXIT PERF_BR_NEW_ARCH_3 PERF_BR_ARM64_DEBUG_INST PERF_BR_NEW_ARCH_4 PERF_BR_ARM64_DEBUG_DATA PERF_BR_NEW_ARCH_5
--- include/uapi/linux/perf_event.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/uapi/linux/perf_event.h +6 -0
@@ -282,6 +282,12 @@ enum { PERF_BR_PRIV_HV = 3, }; +#define PERF_BR_ARM64_FIQ PERF_BR_NEW_ARCH_1 +#define PERF_BR_ARM64_DEBUG_HALT PERF_BR_NEW_ARCH_2 +#define PERF_BR_ARM64_DEBUG_EXIT PERF_BR_NEW_ARCH_3 +#define PERF_BR_ARM64_DEBUG_INST PERF_BR_NEW_ARCH_4 +#define PERF_BR_ARM64_DEBUG_DATA PERF_BR_NEW_ARCH_5 +#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\
Signature · 1 line
2.25.1
PATCH v4 6/10 perf/tools: Add irq and exception return branch types
In reply to Anshuman KhandualThis updates the perf tool with generic branch type classification with two new branch types i.e irq (PERF_BR_IRQ) and exception return (PERF_BR_ERET) which got updated earlier in the kernel. This also updates corresponding branch type strings in branch_type_name().
--- tools/include/uapi/linux/perf_event.h | 2 ++ tools/perf/util/branch.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
tools/include/uapi/linux/perf_event.h +2 -0
@@ -251,6 +251,8 @@ enum {PERF_BR_SYSRET =8 ,/* syscall return */ PERF_BR_COND_CALL =9 ,/* conditional function call */ PERF_BR_COND_RET =10 ,/* conditional function return */ +PERF_BR_ERET =11 ,/* exception return */ +PERF_BR_IRQ =12 ,/* irq */ PERF_BR_MAX, };
tools/perf/util/branch.c +3 -1
@@ -49,7 +49,9 @@ const char *branch_type_name(int type)"SYSCALL" ,"SYSRET" ,"COND_CALL" , - "COND_RET" +"COND_RET" , +"ERET" , + "IRQ" };if (type >=0 && type <PERF_BR_MAX )
Signature · 1 line
2.25.1
PATCH v4 7/10 perf/tools: Add system error and not in transaction branch types
In reply to Anshuman KhandualThis updates the perf tool with generic branch type classification with two new branch types i.e system error (PERF_BR_SERROR) and not in transaction (PERF_BR_NO_TX) which got updated earlier in the kernel. This also updates corresponding branch type strings in branch_type_name().
--- tools/include/uapi/linux/perf_event.h | 2 ++ tools/perf/util/branch.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
tools/include/uapi/linux/perf_event.h +2 -0
@@ -253,6 +253,8 @@ enum {PERF_BR_COND_RET =10 ,/* conditional function return */ PERF_BR_ERET =11 ,/* exception return */ PERF_BR_IRQ =12 ,/* irq */ +PERF_BR_SERROR =13 ,/* system error */ +PERF_BR_NO_TX =14 ,/* not in transaction */ PERF_BR_MAX, };
tools/perf/util/branch.c +3 -1
@@ -51,7 +51,9 @@ const char *branch_type_name(int type)"COND_CALL" ,"COND_RET" ,"ERET" , - "IRQ" +"IRQ" , +"SERROR" , + "NO_TX" };if (type >=0 && type <PERF_BR_MAX )
Signature · 1 line
2.25.1
PATCH v4 8/10 perf/tools: Extend branch type classification
In reply to Anshuman KhandualThis updates the perf tool with generic branch type classification with new ABI extender place holder i.e PERF_BR_EXTEND_ABI, the new 4 bit branch type field i.e perf_branch_entry.new_type, new generic page fault related branch types and some arch specific branch types as added earlier in the kernel.
--- tools/include/uapi/linux/perf_event.h | 16 +++++++++++++++- tools/perf/util/branch.c | 3 ++- tools/perf/util/branch.h | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-)
tools/include/uapi/linux/perf_event.h +15 -1
@@ -255,9 +255,22 @@ enum {PERF_BR_IRQ =12 ,/* irq */ PERF_BR_SERROR =13 ,/* system error */ PERF_BR_NO_TX =14 ,/* not in transaction */ +PERF_BR_EXTEND_ABI =15 ,/* extend ABI */ PERF_BR_MAX, }; +enum { +PERF_BR_NEW_FAULT_ALGN =0 ,/* Alignment fault */ +PERF_BR_NEW_FAULT_DATA =1 ,/* Data fault */ +PERF_BR_NEW_FAULT_INST =2 ,/* Inst fault */ +PERF_BR_NEW_ARCH_1 =3 ,/* Architecture specific */ +PERF_BR_NEW_ARCH_2 =4 ,/* Architecture specific */ +PERF_BR_NEW_ARCH_3 =5 ,/* Architecture specific */ +PERF_BR_NEW_ARCH_4 =6 ,/* Architecture specific */ +PERF_BR_NEW_ARCH_5 =7 ,/* Architecture specific */ +PERF_BR_NEW_MAX , +}; +#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1372,7 +1385,8 @@ struct perf_branch_entry { abort:1, /* transaction abort */ cycles:16, /* cycle count to last branch */ type:4, /* branch type */ - reserved:40; + new_type:4, /* additional branch type */ + reserved:36; };union perf_sample_weight {
tools/perf/util/branch.c +2 -1
@@ -53,7 +53,8 @@ const char *branch_type_name(int type)"ERET" ,"IRQ" ,"SERROR" , - "NO_TX" +"NO_TX" , + "EXTEND_ABI" };if (type >=0 && type <PERF_BR_MAX )
tools/perf/util/branch.h +2 -1
@@ -24,7 +24,8 @@ struct branch_flags { u64 abort:1; u64 cycles:16; u64 type:4; - u64 reserved:40; + u64 new_type:4; + u64 reserved:36; }; }; };
Signature · 1 line
2.25.1
PATCH v4 9/10 perf/tools: Add branch privilege information request flag
In reply to Anshuman KhandualThis updates the perf tools with branch privilege information request flag i.e PERF_SAMPLE_BRANCH_PRIV_SAVE that has been added earlier in the kernel. This also updates 'perf record' documentation, branch_modes[], and generic branch privilege level enumeration as added earlier in the kernel.
--- tools/include/uapi/linux/perf_event.h | 14 +++++++++++++- tools/perf/Documentation/perf-record.txt | 1 + tools/perf/util/branch.h | 3 ++- tools/perf/util/parse-branch-options.c | 1 + tools/perf/util/perf_event_attr_fprintf.c | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-)
tools/include/uapi/linux/perf_event.h +13 -1
@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift {PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT =17 ,/* save low level index of raw branch records */ +PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT =18 ,/* save privilege mode */ + PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */ };
@@ -233,6 +235,8 @@ enum perf_branch_sample_type {PERF_SAMPLE_BRANCH_HW_INDEX =1U <<PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT , +PERF_SAMPLE_BRANCH_PRIV_SAVE =1U <<PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT , + PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT, };
@@ -271,6 +275,13 @@ enum { PERF_BR_NEW_MAX, }; +enum { +PERF_BR_PRIV_UNKNOWN =0 , +PERF_BR_PRIV_USER =1 , +PERF_BR_PRIV_KERNEL =2 , +PERF_BR_PRIV_HV =3 , +}; +#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1386,7 +1397,8 @@ struct perf_branch_entry { cycles:16, /* cycle count to last branch */ type:4, /* branch type */ new_type:4, /* additional branch type */ - reserved:36; + priv:3, /* privilege level */ + reserved:33; };union perf_sample_weight {
tools/perf/Documentation/perf-record.txt +1 -0
@@ -387,6 +387,7 @@ following filters are defined: - abort_tx: only when the target is a hardware transaction abort - cond: conditional branches - save_type: save branch type during sampling in case binary is not available later + - priv: save privilege state during sampling in case binary is not available later + The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
tools/perf/util/branch.h +2 -1
@@ -25,7 +25,8 @@ struct branch_flags { u64 cycles:16; u64 type:4; u64 new_type:4; - u64 reserved:36; + u64 priv:3; + u64 reserved:33; }; }; };
tools/perf/util/parse-branch-options.c +1 -0
@@ -32,6 +32,7 @@ static const struct branch_mode branch_modes[] = {BRANCH_OPT ("call" ,PERF_SAMPLE_BRANCH_CALL ),BRANCH_OPT ("save_type" ,PERF_SAMPLE_BRANCH_TYPE_SAVE ),BRANCH_OPT ("stack" ,PERF_SAMPLE_BRANCH_CALL_STACK ), +BRANCH_OPT ("priv" ,PERF_SAMPLE_BRANCH_PRIV_SAVE ), BRANCH_END };
tools/perf/util/perf_event_attr_fprintf.c +1 -1
@@ -52,7 +52,7 @@ static void __p_branch_sample_type(char *buf, size_t size, u64 value)bit_name (ABORT_TX ),bit_name (IN_TX ),bit_name (NO_TX ),bit_name (COND ),bit_name (CALL_STACK ),bit_name (IND_JUMP ),bit_name (CALL ),bit_name (NO_FLAGS ),bit_name (NO_CYCLES ), -bit_name (TYPE_SAVE ),bit_name (HW_INDEX ), +bit_name (TYPE_SAVE ),bit_name (HW_INDEX ),bit_name (PRIV_SAVE ), { .name = NULL, } };#undef bit_name
Signature · 1 line
2.25.1
PATCH v4 10/10 perf/tools: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
In reply to Anshuman KhandualThis updates the perf tool with arch specific branch type classification used for BRBE on arm64 platform as added in the kernel earlier.
--- tools/include/uapi/linux/perf_event.h | 6 ++++++ 1 file changed, 6 insertions(+)
tools/include/uapi/linux/perf_event.h +6 -0
@@ -282,6 +282,12 @@ enum { PERF_BR_PRIV_HV = 3, }; +#define PERF_BR_ARM64_FIQ PERF_BR_NEW_ARCH_1 +#define PERF_BR_ARM64_DEBUG_HALT PERF_BR_NEW_ARCH_2 +#define PERF_BR_ARM64_DEBUG_EXIT PERF_BR_NEW_ARCH_3 +#define PERF_BR_ARM64_DEBUG_INST PERF_BR_NEW_ARCH_4 +#define PERF_BR_ARM64_DEBUG_DATA PERF_BR_NEW_ARCH_5 +#define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\
Signature · 1 line
2.25.1