perf/core: Reset remaining bits in perf_clear_branch_entry_bitfields()
PATCH 1/1 perf/core: Reset remaining bits in perf_clear_branch_entry_bitfields()
perf_clear_branch_entry_bitfields() resets all struct perf_branch_entry bit fields before capturing branch records. This resets remaining bit fields except 'new_type', which is valid only when 'type' is PERF_BR_EXTEND_ABI.
---
This applies on v6.1-rc6
'perf_branch_entry.new_type' can remain uninitialized as explained earlier. Also there is no PERF_BR_NEW_UNKNOWN to spare, because 'perf_branch_entry. new_type' enumeration starts at PERF_BR_NEW_FAULT_ALGN, to save a position for the extended branch types instead.
include/linux/perf_event.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/perf_event.h +2 -1
@@ -1110,8 +1110,9 @@ static inline void perf_clear_branch_entry_bitfields(struct perf_branch_entry *b br->in_tx =0 ; br->abort =0 ; br->cycles =0 ; - br->type =0 ; + br->type =PERF_BR_UNKNOWN ; br->spec =PERF_BR_SPEC_NA ; + br->priv =PERF_BR_PRIV_UNKNOWN ; br->reserved =0 ; }
Signature · 1 line
2.25.1
Quoted 30 lines · Anshuman Khandual
perf_clear_branch_entry_bitfields()resets all structperf_branch_entrybit fields before capturing branch records. This resets remaining bit fields except 'new_type', which is valid only when 'type' isPERF_BR_EXTEND_ABI.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]>Signed-off-by Anshuman Khandual <[email protected]>---
This applies on v6.1-rc6'perf_branch_entry.new_type' can remain uninitialized as explained earlier. Also there is no
PERF_BR_NEW_UNKNOWNto spare, because 'perf_branch_entry.new_type' enumeration starts atPERF_BR_NEW_FAULT_ALGN, to save a position for the extended branch types instead.include/linux/perf_event.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)include/linux/perf_event.h +0
-0
include/linux/perf_event.h static inline void perf_clear_branch_entry_bitfields(struct perf_branch_entry *b · line 1117
Quoted 9 lines
include/linux/perf_event.h +2
-1@@ -1110,8 +1110,9 @@ static inline void perf_clear_branch_entry_bitfields(struct perf_branch_entry *b br->in_tx =0 ; br->abort =0 ; br->cycles =0 ; - br->type =0 ; + br->type =PERF_BR_UNKNOWN ; br->spec =PERF_BR_SPEC_NA ; + br->priv =PERF_BR_PRIV_UNKNOWN ; br->reserved =0 ; }
I would vote for just memsetting the whole struct to 0 at this point and making it work by ensuring the cleared from and to values are only set after this function.
Or do the thing where it's wrapped in a union and the 'u64 value' member is assigned 0. See union perf_mem_data_src. I don't know if this would be a breaking change, but it doesn't look like it.
Currently this is a bit too fragile and the kind of bugs it will cause are almost undetectable.
But as my proposal is an extra change on top of this:
James
Quoted 1 line
Quoted 30 lines · Anshuman Khandual
perf_clear_branch_entry_bitfields()resets all structperf_branch_entrybit fields before capturing branch records. This resets remaining bit fields except 'new_type', which is valid only when 'type' isPERF_BR_EXTEND_ABI.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]>Signed-off-by Anshuman Khandual <[email protected]>---
This applies on v6.1-rc6'perf_branch_entry.new_type' can remain uninitialized as explained earlier. Also there is no
PERF_BR_NEW_UNKNOWNto spare, because 'perf_branch_entry.new_type' enumeration starts atPERF_BR_NEW_FAULT_ALGN, to save a position for the extended branch types instead.include/linux/perf_event.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)include/linux/perf_event.h +0
-0
include/linux/perf_event.h static inline void perf_clear_branch_entry_bitfields(struct perf_branch_entry *b · line 1118
Quoted 10 lines
include/linux/perf_event.h +2
-1@@ -1110,8 +1110,9 @@ static inline void perf_clear_branch_entry_bitfields(struct perf_branch_entry *b br->in_tx =0 ; br->abort =0 ; br->cycles =0 ; - br->type =0 ; + br->type =PERF_BR_UNKNOWN ; br->spec =PERF_BR_SPEC_NA ; + br->priv =PERF_BR_PRIV_UNKNOWN ; br->reserved =0 ; }
Hello Peter,
Just wondering is there a chance that this patch could make it to v6.2-rc1 ?
- Anshuman