Skip to contentSkip to conversation

perf: Fix interpretation of branch records

PATCH In review James Clark 5 participants 6 messages Nov 30, 2022 – Dec 2, 2022 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: Fix interpretation of branch records

Commit 93315e46b000 ("perf/core: Add speculation info to branch entries") added a new field in between type and new_type. Perf has its own copy of this struct so update it to match the kernel side.

This doesn't currently cause any issues because new_type is only used by the Arm BRBE driver which isn't merged yet.

Fixes 93315e46b000 ("perf/core: Add speculation info to branch entries")
---
 tools/perf/util/branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/branch.h +2 -1
index d6017c9b1872..3ed792db1125 100644
@@ -22,9 +22,10 @@ struct branch_flags {
 			u64 abort:1;
 			u64 cycles:16;
 			u64 type:4;
+			u64 spec:2;
 			u64 new_type:4;
 			u64 priv:3;
-			u64 reserved:33;
+			u64 reserved:31;
 		};
 	};
 };
Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · James Clark

Commit 93315e46b000 ("perf/core: Add speculation info to branch entries") added a new field in between type and new_type. Perf has its own copy of this struct so update it to match the kernel side.

This doesn't currently cause any issues because new_type is only used by the Arm BRBE driver which isn't merged yet.

Fixes 93315e46b000 ("perf/core: Add speculation info to branch entries")

Thanks,
Namhyung

Quoted 23 lines
---
 tools/perf/util/branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/branch.h +2 -2
index d6017c9b1872..3ed792db1125 100644
@@ -22,9 +22,10 @@ struct branch_flags {
                        u64 abort:1;
                        u64 cycles:16;
                        u64 type:4;
+                       u64 spec:2;
                        u64 new_type:4;
                        u64 priv:3;
-                       u64 reserved:33;
+                       u64 reserved:31;
                };
        };
 };
--

2.25.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to James Clark
Quoted 9 lines · James Clark

Commit 93315e46b000 ("perf/core: Add speculation info to branch entries") added a new field in between type and new_type. Perf has its own copy of this struct so update it to match the kernel side.

This doesn't currently cause any issues because new_type is only used by the Arm BRBE driver which isn't merged yet.

Fixes 93315e46b000 ("perf/core: Add speculation info to branch entries")

Again, problem from having the same structure in two different places

Quoted 20 lines
---
 tools/perf/util/branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/branch.h +2 -1
index d6017c9b1872..3ed792db1125 100644
@@ -22,9 +22,10 @@ struct branch_flags {
 			u64 abort:1;
 			u64 cycles:16;
 			u64 type:4;
+			u64 spec:2;
 			u64 new_type:4;
 			u64 priv:3;
-			u64 reserved:33;
+			u64 reserved:31;
 		};
 	};
 };
#3 lore raw

Em Thu, Dec 01, 2022 at 09:46:53AM +0530, Anshuman Khandual escreveu:

Quoted 7 lines · James Clark
Quoted 4 lines

Commit 93315e46b000 ("perf/core: Add speculation info to branch entries") added a new field in between type and new_type. Perf has its own copy of this struct so update it to match the kernel side.

Quoted 7 lines
Quoted 5 lines

This doesn't currently cause any issues because new_type is only used by the Arm BRBE driver which isn't merged yet.

Fixes 93315e46b000 ("perf/core: Add speculation info to branch entries")

Again, problem from having the same structure in two different places

Indeed, this was my first reaction, how about backward compatibility, is this really an ABI?

- Arnaldo

Quoted 22 lines
Quoted 20 lines
---
 tools/perf/util/branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/branch.h +2 -1
index d6017c9b1872..3ed792db1125 100644
@@ -22,9 +22,10 @@ struct branch_flags {
 			u64 abort:1;
 			u64 cycles:16;
 			u64 type:4;
+			u64 spec:2;
 			u64 new_type:4;
 			u64 priv:3;
-			u64 reserved:33;
+			u64 reserved:31;
 		};
 	};
 };
Signature · 1 line
- Arnaldo
#4 lore raw
In reply to James Clark
Quoted 8 lines · James Clark

Commit 93315e46b000 ("perf/core: Add speculation info to branch entries") added a new field in between type and new_type. Perf has its own copy of this struct so update it to match the kernel side.

This doesn't currently cause any issues because new_type is only used by the Arm BRBE driver which isn't merged yet.

Fixes 93315e46b000 ("perf/core: Add speculation info to branch entries")

Technically, in the kernel sources, commit 93315e46b000 ("perf/core: Add speculation info to branch entries") landed before commit b190bc4ac9e6 ("perf: Extend branch type classification").

So I think the Fixes tag should instead have commit 0ddea8e2a0c2 ("perf branch: Extend branch type classification") which added the UAPI changes to the perf tool headers.

Aside from that, the patch looks good to me.

Quoted 21 lines
---
 tools/perf/util/branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/branch.h +2 -1
index d6017c9b1872..3ed792db1125 100644
@@ -22,9 +22,10 @@ struct branch_flags {
 			u64 abort:1;
 			u64 cycles:16;
 			u64 type:4;
+			u64 spec:2;
 			u64 new_type:4;
 			u64 priv:3;
-			u64 reserved:33;
+			u64 reserved:31;
 		};
 	};
 };
#5 lore raw
Quoted 10 lines · Sandipan Das
Quoted 8 lines · James Clark

Commit 93315e46b000 ("perf/core: Add speculation info to branch entries") added a new field in between type and new_type. Perf has its own copy of this struct so update it to match the kernel side.

This doesn't currently cause any issues because new_type is only used by the Arm BRBE driver which isn't merged yet.

Fixes 93315e46b000 ("perf/core: Add speculation info to branch entries")
Quoted 7 lines

Technically, in the kernel sources, commit 93315e46b000 ("perf/core: Add speculation info to branch entries") landed before commit b190bc4ac9e6 ("perf: Extend branch type classification").

So I think the Fixes tag should instead have commit 0ddea8e2a0c2 ("perf branch: Extend branch type classification") which added the UAPI changes to the perf tool headers.

Yes maybe, or 831c05a7621b ("tools headers UAPI: Sync linux/perf_event.h with the kernel sources") where spec was added to the perf copy of the headers.

It's hard to say for sure which one is best. I think that the earliest possible one is best in case anyone is debugging that kernel version with userspace Perf. And to me it seems any kernel that has the spec record should have it matching in userspace so I would still prefer 93315e46b000. Applying it on top of any other change would still lead to misleading interpretation of the records.

Quoted 2 lines

Aside from that, the patch looks good to me.

Thanks for the review.

Quoted 24 lines
Quoted 22 lines
---
 tools/perf/util/branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/branch.h +2 -1
index d6017c9b1872..3ed792db1125 100644
@@ -22,9 +22,10 @@ struct branch_flags {
 			u64 abort:1;
 			u64 cycles:16;
 			u64 type:4;
+			u64 spec:2;
 			u64 new_type:4;
 			u64 priv:3;
-			u64 reserved:33;
+			u64 reserved:31;
 		};
 	};
 };