Blame SOURCES/0002-extensions-trace-Rename-trace_buffer-to-array_buffer.patch

6adb17
From c4cdbe3c18bca496dc6b4af17e2637379528ad02 Mon Sep 17 00:00:00 2001
6adb17
From: Valentin Schneider <valentin.schneider@arm.com>
6adb17
Date: Thu, 3 Sep 2020 21:28:46 +0100
6adb17
Subject: [PATCH 2/3] extensions/trace: Rename trace_buffer to array_buffer
6adb17
6adb17
This renaming is present from Linux v5.6 upwards, and was introduced by
6adb17
commit:
6adb17
6adb17
  1c5eb4481e01 ("tracing: Rename trace_buffer to array_buffer")
6adb17
6adb17
Rename the internal references from trace_buffer to array_buffer. Backwards
6adb17
compatibility with older kernels is provided by checking whether struct
6adb17
trace_array has an array_buffer field - should that not be the case, the
6adb17
old naming scheme is used instead.
6adb17
6adb17
Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
6adb17
---
6adb17
 trace.c | 53 +++++++++++++++++++++++++++++++++++------------------
6adb17
 1 file changed, 35 insertions(+), 18 deletions(-)
6adb17
6adb17
diff --git a/trace.c b/trace.c
6adb17
index c26b6c7ec475..2cea5b2d650a 100644
6adb17
--- a/trace.c
6adb17
+++ b/trace.c
6adb17
@@ -31,9 +31,9 @@ static int per_cpu_buffer_sizes;
6adb17
  */
6adb17
 static int encapsulated_current_trace;
6adb17
 /*
6adb17
- * trace_buffer is supported
6adb17
+ * array_buffer (trace_buffer pre v5.6) is supported
6adb17
  */
6adb17
-static int trace_buffer_available;
6adb17
+static int array_buffer_available;
6adb17
 /*
6adb17
  * max_buffer is supported
6adb17
  */
6adb17
@@ -51,9 +51,9 @@ static int buffer_page_real_end_available;
6adb17
 #define koffset(struct, member) struct##_##member##_offset
6adb17
 
6adb17
 static int koffset(trace_array, current_trace);
6adb17
-static int koffset(trace_array, trace_buffer);
6adb17
+static int koffset(trace_array, array_buffer);
6adb17
 static int koffset(trace_array, max_buffer);
6adb17
-static int koffset(trace_buffer, buffer);
6adb17
+static int koffset(array_buffer, buffer);
6adb17
 static int koffset(trace_array, buffer);
6adb17
 static int koffset(tracer, name);
6adb17
 
6adb17
@@ -117,7 +117,7 @@ static ulong max_tr_trace;
6adb17
 
6adb17
 struct trace_instance {
6adb17
 	char name[NAME_MAX + 1];
6adb17
-	ulong trace_buffer;
6adb17
+	ulong array_buffer;
6adb17
 	ulong max_buffer;
6adb17
 	ulong ring_buffer;
6adb17
 	unsigned pages;
6adb17
@@ -174,8 +174,7 @@ static int write_and_check(int fd, void *data, size_t size)
6adb17
 
6adb17
 static int init_offsets(void)
6adb17
 {
6adb17
-#define init_offset(struct, member) do {				\
6adb17
-		koffset(struct, member) = MEMBER_OFFSET(#struct, #member);\
6adb17
+#define check_offset(struct, member) do { \
6adb17
 		if (koffset(struct, member) < 0) {			\
6adb17
 			fprintf(fp, "failed to init the offset, struct:"\
6adb17
 				#struct ", member:" #member);		\
6adb17
@@ -184,12 +183,29 @@ static int init_offsets(void)
6adb17
 		}							\
6adb17
 	} while (0)
6adb17
 
6adb17
+#define init_offset(struct, member) do {				\
6adb17
+		koffset(struct, member) = MEMBER_OFFSET(#struct, #member); \
6adb17
+		check_offset(struct, member);				\
6adb17
+	} while (0)
6adb17
+
6adb17
+#define init_offset_alternative(struct, member, alt_struct, alt_member) do {	\
6adb17
+		koffset(struct, member) = MEMBER_OFFSET(#alt_struct, #alt_member); \
6adb17
+		check_offset(struct, member);				\
6adb17
+	} while (0)
6adb17
+
6adb17
 	if (encapsulated_current_trace)
6adb17
 		init_offset(trace_array, current_trace);
6adb17
 
6adb17
-	if (trace_buffer_available) {
6adb17
-		init_offset(trace_array, trace_buffer);
6adb17
-		init_offset(trace_buffer, buffer);
6adb17
+	if (array_buffer_available) {
6adb17
+		if (MEMBER_EXISTS("trace_array", "array_buffer")) {
6adb17
+			init_offset(trace_array, array_buffer);
6adb17
+			init_offset(array_buffer, buffer);
6adb17
+		} else {
6adb17
+			init_offset_alternative(trace_array, array_buffer,
6adb17
+						trace_array, trace_buffer);
6adb17
+			init_offset_alternative(array_buffer, buffer,
6adb17
+						trace_buffer, buffer);
6adb17
+		}
6adb17
 
6adb17
 		if (max_buffer_available)
6adb17
 			init_offset(trace_array, max_buffer);
6adb17
@@ -486,17 +502,17 @@ out_fail:
6adb17
 
6adb17
 static int ftrace_init_trace(struct trace_instance *ti, ulong instance_addr)
6adb17
 {
6adb17
-	if (trace_buffer_available) {
6adb17
-		ti->trace_buffer = instance_addr +
6adb17
-				koffset(trace_array, trace_buffer);
6adb17
-		read_value(ti->ring_buffer, ti->trace_buffer,
6adb17
-				trace_buffer, buffer);
6adb17
+	if (array_buffer_available) {
6adb17
+		ti->array_buffer = instance_addr +
6adb17
+				koffset(trace_array, array_buffer);
6adb17
+		read_value(ti->ring_buffer, ti->array_buffer,
6adb17
+			   array_buffer, buffer);
6adb17
 
6adb17
 		if (max_buffer_available) {
6adb17
 			ti->max_buffer = instance_addr +
6adb17
 					koffset(trace_array, max_buffer);
6adb17
 			read_value(ti->max_tr_ring_buffer, ti->max_buffer,
6adb17
-					trace_buffer, buffer);
6adb17
+					array_buffer, buffer);
6adb17
 		}
6adb17
 	} else {
6adb17
 		read_value(ti->ring_buffer, instance_addr, trace_array, buffer);
6adb17
@@ -683,8 +699,9 @@ static int ftrace_init(void)
6adb17
 		current_trace = sym_current_trace->value;
6adb17
 	}
6adb17
 
6adb17
-	if (MEMBER_EXISTS("trace_array", "trace_buffer")) {
6adb17
-		trace_buffer_available = 1;
6adb17
+	if (MEMBER_EXISTS("trace_array", "array_buffer") ||
6adb17
+	    MEMBER_EXISTS("trace_array", "trace_buffer")) {
6adb17
+		array_buffer_available = 1;
6adb17
 
6adb17
 		if (MEMBER_EXISTS("trace_array", "max_buffer"))
6adb17
 			max_buffer_available = 1;
6adb17
-- 
6adb17
2.17.1
6adb17