Skip to contentSkip to conversation

cxl/event_trace: parse arrays separately from strings

PATCH In review [email protected] 3 participants 4 messages Feb 16, 2024 – Feb 28, 2024 libnvdimm: non-volatile memory device

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 cxl/event_trace: parse arrays separately from strings

From: Alison Schofield <[email protected]>

Arrays are being parsed as strings based on a flag that seems like it would be the differentiator, ARRAY and STRING, but it is not.

libtraceevent sets the flags for arrays and strings like this:

array:  TEP_FIELD_IS_[ARRAY | STRING]
string: TEP_FIELD_IS_[ARRAY | STRING | DYNAMIC]

Use TEP_FIELD_IS_DYNAMIC to discover the field type, otherwise arrays get parsed as strings and 'cxl monitor' returns gobbledygook in the array type fields.

This fixes the "data" field of cxl_generic_events and the "uuid" field of cxl_poison.

Before:
{"system":"cxl","event":"cxl_generic_event","timestamp":3469041387470,"memdev":"mem0","host":"cxl_mem.0","log":0,"hdr_uuid":"ba5eba11-abcd-efeb-a55a-a55aa5a55aa5","serial":0,"hdr_flags":8,"hdr_handle":1,"hdr_related_handle":42422,"hdr_timestamp":0,"hdr_length":128,"hdr_maint_op_class":0,"data":"Þ­¾ï"}

After:
{"system":"cxl","event":"cxl_generic_event","timestamp":312851657810,"memdev":"mem0","host":"cxl_mem.0","log":0,"hdr_uuid":"ba5eba11-abcd-efeb-a55a-a55aa5a55aa5","serial":0,"hdr_flags":8,"hdr_handle":1,"hdr_related_handle":42422,"hdr_timestamp":0,"hdr_length":128,"hdr_maint_op_class":0,"data":[222,173,190,239,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}

Before:
{"system":"cxl","event":"cxl_poison","timestamp":3292418311609,"memdev":"mem1","host":"cxl_mem.1","serial":1,"trace_type":2,"region":"region5","overflow_ts":0,"hpa":1035355557888,"dpa":1073741824,"dpa_length":64,"uuid":"�Fe�c�CI�����2�]","source":0,"flags":0}

After:
{"system":"cxl","event":"cxl_poison","timestamp":94600531271,"memdev":"mem1","host":"cxl_mem.1","serial":1,"trace_type":2,"region":"region5","overflow_ts":0,"hpa":1035355557888,"dpa":1073741824,"dpa_length":64,"uuid":[139,200,184,22,236,103,76,121,157,243,47,110,243,11,158,62],"source":0,"flags":0}

That cxl_poison uuid format can be further improved by using the trace type (__field_struct uuid_t) in the CXL kernel driver. The parser will automatically pick up that new type, as illustrated in the "hdr_uuid" of cxl_generic_media event trace above.

---
 cxl/event_trace.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
cxl/event_trace.c +7 -1
index db8cc85f0b6f..1b5aa09de8b2 100644
@@ -109,7 +109,13 @@ static int cxl_event_to_json(struct tep_event *event, struct tep_record *record,
 		struct tep_format_field *f = fields[i];
 		int len;
 
-		if (f->flags & TEP_FIELD_IS_STRING) {
+		/*
+		 * libtraceevent differentiates arrays and strings like this:
+		 * array:  TEP_FIELD_IS_[ARRAY | STRING]
+		 * string: TEP_FIELD_IS_[ARRAY | STRING | DYNAMIC]
+		 */
+		if ((f->flags & TEP_FIELD_IS_STRING) &&
+		    ((f->flags & TEP_FIELD_IS_DYNAMIC))) {
 			char *str;
 
 			str = tep_get_field_raw(NULL, event, f->name, record, &len, 0);

base-commit: a871e6153b11fe63780b37cdcb1eb347b296095c

Signature · 1 line
2.37.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · On 2/15/24 11:06 PM, [email protected] wrote:

From: Alison Schofield <[email protected]>

Arrays are being parsed as strings based on a flag that seems like it would be the differentiator, ARRAY and STRING, but it is not.

libtraceevent sets the flags for arrays and strings like this:

array:  TEP_FIELD_IS_[ARRAY | STRING]
string: TEP_FIELD_IS_[ARRAY | STRING | DYNAMIC]

Use TEP_FIELD_IS_DYNAMIC to discover the field type, otherwise arrays get parsed as strings and 'cxl monitor' returns gobbledygook in the array type fields.

This fixes the "data" field of cxl_generic_events and the "uuid" field of cxl_poison.

Before:
{"system":"cxl","event":"cxl_generic_event","timestamp":3469041387470,"memdev":"mem0","host":"cxl_mem.0","log":0,"hdr_uuid":"ba5eba11-abcd-efeb-a55a-a55aa5a55aa5","serial":0,"hdr_flags":8,"hdr_handle":1,"hdr_related_handle":42422,"hdr_timestamp":0,"hdr_length":128,"hdr_maint_op_class":0,"data":"Þ­¾ï"}

After:
{"system":"cxl","event":"cxl_generic_event","timestamp":312851657810,"memdev":"mem0","host":"cxl_mem.0","log":0,"hdr_uuid":"ba5eba11-abcd-efeb-a55a-a55aa5a55aa5","serial":0,"hdr_flags":8,"hdr_handle":1,"hdr_related_handle":42422,"hdr_timestamp":0,"hdr_length":128,"hdr_maint_op_class":0,"data":[222,173,190,239,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}

Before:
{"system":"cxl","event":"cxl_poison","timestamp":3292418311609,"memdev":"mem1","host":"cxl_mem.1","serial":1,"trace_type":2,"region":"region5","overflow_ts":0,"hpa":1035355557888,"dpa":1073741824,"dpa_length":64,"uuid":"�Fe�c�CI�����2�]","source":0,"flags":0}

After:
{"system":"cxl","event":"cxl_poison","timestamp":94600531271,"memdev":"mem1","host":"cxl_mem.1","serial":1,"trace_type":2,"region":"region5","overflow_ts":0,"hpa":1035355557888,"dpa":1073741824,"dpa_length":64,"uuid":[139,200,184,22,236,103,76,121,157,243,47,110,243,11,158,62],"source":0,"flags":0}

Quoted 6 lines

That cxl_poison uuid format can be further improved by using the trace type (__field_struct uuid_t) in the CXL kernel driver. The parser will automatically pick up that new type, as illustrated in the "hdr_uuid" of cxl_generic_media event trace above.

Quoted 25 lines
---
 cxl/event_trace.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
cxl/event_trace.c +7 -1
index db8cc85f0b6f..1b5aa09de8b2 100644
@@ -109,7 +109,13 @@ static int cxl_event_to_json(struct tep_event *event, struct tep_record *record,
 		struct tep_format_field *f = fields[i];
 		int len;
 
-		if (f->flags & TEP_FIELD_IS_STRING) {
+		/*
+		 * libtraceevent differentiates arrays and strings like this:
+		 * array:  TEP_FIELD_IS_[ARRAY | STRING]
+		 * string: TEP_FIELD_IS_[ARRAY | STRING | DYNAMIC]
+		 */
+		if ((f->flags & TEP_FIELD_IS_STRING) &&
+		    ((f->flags & TEP_FIELD_IS_DYNAMIC))) {
 			char *str;
 
 			str = tep_get_field_raw(NULL, event, f->name, record, &len, 0);

base-commit: a871e6153b11fe63780b37cdcb1eb347b296095c

maintainer
#2 lore raw
In reply to [email protected]
Quoted 17 lines · On Thu, 2024-02-15 at 22:06 -0800, [email protected] wrote:

From: Alison Schofield <[email protected]>

Arrays are being parsed as strings based on a flag that seems like it would be the differentiator, ARRAY and STRING, but it is not.

libtraceevent sets the flags for arrays and strings like this:
array:  TEP_FIELD_IS_[ARRAY | STRING]
string: TEP_FIELD_IS_[ARRAY | STRING | DYNAMIC]

Use TEP_FIELD_IS_DYNAMIC to discover the field type, otherwise arrays get parsed as strings and 'cxl monitor' returns gobbledygook in the array type fields.

This fixes the "data" field of cxl_generic_events and the "uuid" field
of cxl_poison.

Quoted 7 lines

Before:
{"system":"cxl","event":"cxl_generic_event","timestamp":3469041387470 ,"memdev":"mem0","host":"cxl_mem.0","log":0,"hdr_uuid":"ba5eba11- abcd-efeb-a55a- a55aa5a55aa5","serial":0,"hdr_flags":8,"hdr_handle":1,"hdr_related_ha ndle":42422,"hdr_timestamp":0,"hdr_length":128,"hdr_maint_op_class":0 ,"data":"Þ­¾ï"}

When applying, b4 complains of these in the commit message as "suspicious unicode control characters". I'm also not a huge fan of the super long lines, perhaps we can just drop the before/after examples?

Quoted 60 lines

After:
{"system":"cxl","event":"cxl_generic_event","timestamp":312851657810, "memdev":"mem0","host":"cxl_mem.0","log":0,"hdr_uuid":"ba5eba11-abcd- efeb-a55a- a55aa5a55aa5","serial":0,"hdr_flags":8,"hdr_handle":1,"hdr_related_ha ndle":42422,"hdr_timestamp":0,"hdr_length":128,"hdr_maint_op_class":0 ,"data":[222,173,190,239,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}

Before:
{"system":"cxl","event":"cxl_poison","timestamp":3292418311609,"memde v":"mem1","host":"cxl_mem.1","serial":1,"trace_type":2,"region":"regi on5","overflow_ts":0,"hpa":1035355557888,"dpa":1073741824,"dpa_length ":64,"uuid":"�Fe�c�CI�����2�]","source":0,"flags":0}

After:
{"system":"cxl","event":"cxl_poison","timestamp":94600531271,"memdev" :"mem1","host":"cxl_mem.1","serial":1,"trace_type":2,"region":"region 5","overflow_ts":0,"hpa":1035355557888,"dpa":1073741824,"dpa_length":
64,"uuid":[139,200,184,22,236,103,76,121,157,243,47,110,243,11,158,62 ],"source":0,"flags":0}

That cxl_poison uuid format can be further improved by using the trace
type (__field_struct uuid_t) in the CXL kernel driver. The parser will
automatically pick up that new type, as illustrated in the "hdr_uuid" of cxl_generic_media event trace above.

---
 cxl/event_trace.c | 8 +++++++-

 1 file changed, 7 insertions(+), 1 deletion(-)
cxl/event_trace.c +0 -0
index db8cc85f0b6f..1b5aa09de8b2 100644
@@ -109,7 +109,13 @@ static int cxl_event_to_json(struct tep_event
 *event, struct tep_record *record,
  		struct tep_format_field *f = fields[i];
  		int len;

cxl/event_trace.c +2 -1
-		if (f->flags & TEP_FIELD_IS_STRING) {
+		/*
+		 * libtraceevent differentiates arrays and strings

like this:

cxl/event_trace.c +5 -0
+		 * array:  TEP_FIELD_IS_[ARRAY | STRING]
+		 * string: TEP_FIELD_IS_[ARRAY | STRING | DYNAMIC]
+		 */
+		if ((f->flags & TEP_FIELD_IS_STRING) &&
+		    ((f->flags & TEP_FIELD_IS_DYNAMIC))) {

  char *str;

  str = tep_get_field_raw(NULL, event, f-

Quoted 1 line

name, record, &len, 0);

base-commit: a871e6153b11fe63780b37cdcb1eb347b296095c

author maintainer
#3 lore raw
Quoted 26 lines · Vishal Verma
Quoted 17 lines · On Thu, 2024-02-15 at 22:06 -0800, [email protected] wrote:

From: Alison Schofield <[email protected]>

Arrays are being parsed as strings based on a flag that seems like it would be the differentiator, ARRAY and STRING, but it is not.

libtraceevent sets the flags for arrays and strings like this:

array:  TEP_FIELD_IS_[ARRAY | STRING]
string: TEP_FIELD_IS_[ARRAY | STRING | DYNAMIC]

Use TEP_FIELD_IS_DYNAMIC to discover the field type, otherwise arrays get parsed as strings and 'cxl monitor' returns gobbledygook in the array type fields.

This fixes the "data" field of cxl_generic_events and the "uuid" field
of cxl_poison.

Quoted 7 lines

Before:
{"system":"cxl","event":"cxl_generic_event","timestamp":3469041387470 ,"memdev":"mem0","host":"cxl_mem.0","log":0,"hdr_uuid":"ba5eba11- abcd-efeb-a55a- a55aa5a55aa5","serial":0,"hdr_flags":8,"hdr_handle":1,"hdr_related_ha ndle":42422,"hdr_timestamp":0,"hdr_length":128,"hdr_maint_op_class":0 ,"data":"Þ­¾ï"}

Quoted 3 lines

When applying, b4 complains of these in the commit message as "suspicious unicode control characters". I'm also not a huge fan of the super long lines, perhaps we can just drop the before/after examples?

Yes - that got silly long! Can you drop on applying please?

Quoted 62 lines
Quoted 61 lines

After:
{"system":"cxl","event":"cxl_generic_event","timestamp":312851657810, "memdev":"mem0","host":"cxl_mem.0","log":0,"hdr_uuid":"ba5eba11-abcd- efeb-a55a- a55aa5a55aa5","serial":0,"hdr_flags":8,"hdr_handle":1,"hdr_related_ha ndle":42422,"hdr_timestamp":0,"hdr_length":128,"hdr_maint_op_class":0 ,"data":[222,173,190,239,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}

Before:
{"system":"cxl","event":"cxl_poison","timestamp":3292418311609,"memde v":"mem1","host":"cxl_mem.1","serial":1,"trace_type":2,"region":"regi on5","overflow_ts":0,"hpa":1035355557888,"dpa":1073741824,"dpa_length ":64,"uuid":"�Fe�c�CI�����2�]","source":0,"flags":0}

After:
{"system":"cxl","event":"cxl_poison","timestamp":94600531271,"memdev" :"mem1","host":"cxl_mem.1","serial":1,"trace_type":2,"region":"region 5","overflow_ts":0,"hpa":1035355557888,"dpa":1073741824,"dpa_length":
64,"uuid":[139,200,184,22,236,103,76,121,157,243,47,110,243,11,158,62 ],"source":0,"flags":0}

That cxl_poison uuid format can be further improved by using the trace
type (__field_struct uuid_t) in the CXL kernel driver. The parser will
automatically pick up that new type, as illustrated in the "hdr_uuid" of cxl_generic_media event trace above.

---
 cxl/event_trace.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
cxl/event_trace.c +2 -1
index db8cc85f0b6f..1b5aa09de8b2 100644
@@ -109,7 +109,13 @@ static int cxl_event_to_json(struct tep_event
 *event, struct tep_record *record,
              struct tep_format_field *f = fields[i];
              int len;
 
-             if (f->flags & TEP_FIELD_IS_STRING) {
+             /*
+              * libtraceevent differentiates arrays and strings

like this:

cxl/event_trace.c +5 -0
+              * array:  TEP_FIELD_IS_[ARRAY | STRING]
+              * string: TEP_FIELD_IS_[ARRAY | STRING | DYNAMIC]
+              */
+             if ((f->flags & TEP_FIELD_IS_STRING) &&
+                 ((f->flags & TEP_FIELD_IS_DYNAMIC))) {
                      char *str;
 
                      str = tep_get_field_raw(NULL, event, f-
Quoted 1 line

name, record, &len, 0);

base-commit: a871e6153b11fe63780b37cdcb1eb347b296095c