Message ID | 0dbf9557aaf5e8047440cb74f7df84ae404c11ba.1710386468.git.alison.schofield@intel.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Support poison list retrieval | expand |
On 3/13/24 9:05 PM, alison.schofield@intel.com wrote: > From: Alison Schofield <alison.schofield@intel.com> > > Add helpers to extract the value of an event record field given the > field name. This is useful when the user knows the name and format > of the field and simply needs to get it. The helpers also return > the 'type'_MAX of the type when the field is > > Since this is in preparation for adding a cxl_poison private parser > for 'cxl list --media-errors' support those specific required > types: u8, u32, u64. > > Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> > --- > cxl/event_trace.c | 37 +++++++++++++++++++++++++++++++++++++ > cxl/event_trace.h | 8 +++++++- > 2 files changed, 44 insertions(+), 1 deletion(-) > > diff --git a/cxl/event_trace.c b/cxl/event_trace.c > index 640abdab67bf..324edb982888 100644 > --- a/cxl/event_trace.c > +++ b/cxl/event_trace.c > @@ -15,6 +15,43 @@ > #define _GNU_SOURCE > #include <string.h> > > +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, > + const char *name) > +{ > + unsigned long long val; > + > + if (tep_get_field_val(NULL, event, name, record, &val, 0)) > + return ULLONG_MAX; > + > + return val; > +} > + > +u32 cxl_get_field_u32(struct tep_event *event, struct tep_record *record, > + const char *name) > +{ > + char *val; > + int len; > + > + val = tep_get_field_raw(NULL, event, name, record, &len, 0); > + if (!val) > + return UINT_MAX; > + > + return *(u32 *)val; > +} > + > +u8 cxl_get_field_u8(struct tep_event *event, struct tep_record *record, > + const char *name) > +{ > + char *val; > + int len; > + > + val = tep_get_field_raw(NULL, event, name, record, &len, 0); > + if (!val) > + return UCHAR_MAX; > + > + return *(u8 *)val; > +} > + > static struct json_object *num_to_json(void *num, int elem_size, unsigned long flags) > { > bool sign = flags & TEP_FIELD_IS_SIGNED; > diff --git a/cxl/event_trace.h b/cxl/event_trace.h > index b77cafb410c4..7b30c3922aef 100644 > --- a/cxl/event_trace.h > +++ b/cxl/event_trace.h > @@ -5,6 +5,7 @@ > > #include <json-c/json.h> > #include <ccan/list/list.h> > +#include <ccan/short_types/short_types.h> > > struct jlist_node { > struct json_object *jobj; > @@ -32,5 +33,10 @@ int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx); > int cxl_event_tracing_enable(struct tracefs_instance *inst, const char *system, > const char *event); > int cxl_event_tracing_disable(struct tracefs_instance *inst); > - > +u8 cxl_get_field_u8(struct tep_event *event, struct tep_record *record, > + const char *name); > +u32 cxl_get_field_u32(struct tep_event *event, struct tep_record *record, > + const char *name); > +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, > + const char *name); > #endif
alison.schofield@ wrote: > From: Alison Schofield <alison.schofield@intel.com> > > Add helpers to extract the value of an event record field given the > field name. This is useful when the user knows the name and format > of the field and simply needs to get it. The helpers also return > the 'type'_MAX of the type when the field is > > Since this is in preparation for adding a cxl_poison private parser > for 'cxl list --media-errors' support those specific required > types: u8, u32, u64. > > Signed-off-by: Alison Schofield <alison.schofield@intel.com> > --- > cxl/event_trace.c | 37 +++++++++++++++++++++++++++++++++++++ > cxl/event_trace.h | 8 +++++++- > 2 files changed, 44 insertions(+), 1 deletion(-) > > diff --git a/cxl/event_trace.c b/cxl/event_trace.c > index 640abdab67bf..324edb982888 100644 > --- a/cxl/event_trace.c > +++ b/cxl/event_trace.c > @@ -15,6 +15,43 @@ > #define _GNU_SOURCE > #include <string.h> > > +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, > + const char *name) > +{ > + unsigned long long val; > + > + if (tep_get_field_val(NULL, event, name, record, &val, 0)) > + return ULLONG_MAX; > + > + return val; > +} Hm, why are these prefixed "cxl_" there is nothing cxl specific in the internals. Maybe these event trace helpers grow non-CXL users in the future. Could be "trace_" or "util_" like other generic helpers in the codebase.
On Fri, Mar 15, 2024 at 10:39:53AM -0700, Dan Williams wrote: > alison.schofield@ wrote: > > From: Alison Schofield <alison.schofield@intel.com> > > > > Add helpers to extract the value of an event record field given the > > field name. This is useful when the user knows the name and format > > of the field and simply needs to get it. The helpers also return > > the 'type'_MAX of the type when the field is > > > > Since this is in preparation for adding a cxl_poison private parser > > for 'cxl list --media-errors' support those specific required > > types: u8, u32, u64. > > > > Signed-off-by: Alison Schofield <alison.schofield@intel.com> > > --- > > cxl/event_trace.c | 37 +++++++++++++++++++++++++++++++++++++ > > cxl/event_trace.h | 8 +++++++- > > 2 files changed, 44 insertions(+), 1 deletion(-) > > > > diff --git a/cxl/event_trace.c b/cxl/event_trace.c > > index 640abdab67bf..324edb982888 100644 > > --- a/cxl/event_trace.c > > +++ b/cxl/event_trace.c > > @@ -15,6 +15,43 @@ > > #define _GNU_SOURCE > > #include <string.h> > > > > +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, > > + const char *name) > > +{ > > + unsigned long long val; > > + > > + if (tep_get_field_val(NULL, event, name, record, &val, 0)) > > + return ULLONG_MAX; > > + > > + return val; > > +} > > Hm, why are these prefixed "cxl_" there is nothing cxl specific in the > internals. Maybe these event trace helpers grow non-CXL users in the > future. Could be "trace_" or "util_" like other generic helpers in the > codebase. All the helpers in cxl/event_trace.c are prefixed "cxl_". The cxl special-ness is only that ndctl/cxl is the only user of trace events in ndctl/. cxl/monitor.c and now cxl/json.c (this usage) I can move: ndctl/cxl/event_trace.h,c to ndctl/utils/event_trace.h,c. and update cxl/monitor.c to find. Yay?
On Wed, Mar 13, 2024 at 09:05:20PM -0700, alison.schofield@intel.com wrote: > From: Alison Schofield <alison.schofield@intel.com> > > Add helpers to extract the value of an event record field given the > field name. This is useful when the user knows the name and format > of the field and simply needs to get it. The helpers also return > the 'type'_MAX of the type when the field is > > Since this is in preparation for adding a cxl_poison private parser > for 'cxl list --media-errors' support those specific required > types: u8, u32, u64. > > Signed-off-by: Alison Schofield <alison.schofield@intel.com> > --- Reviewed-by: Fan Ni <fan.ni@samsung.com> > cxl/event_trace.c | 37 +++++++++++++++++++++++++++++++++++++ > cxl/event_trace.h | 8 +++++++- > 2 files changed, 44 insertions(+), 1 deletion(-) > > diff --git a/cxl/event_trace.c b/cxl/event_trace.c > index 640abdab67bf..324edb982888 100644 > --- a/cxl/event_trace.c > +++ b/cxl/event_trace.c > @@ -15,6 +15,43 @@ > #define _GNU_SOURCE > #include <string.h> > > +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, > + const char *name) > +{ > + unsigned long long val; > + > + if (tep_get_field_val(NULL, event, name, record, &val, 0)) > + return ULLONG_MAX; > + > + return val; > +} > + > +u32 cxl_get_field_u32(struct tep_event *event, struct tep_record *record, > + const char *name) > +{ > + char *val; > + int len; > + > + val = tep_get_field_raw(NULL, event, name, record, &len, 0); > + if (!val) > + return UINT_MAX; > + > + return *(u32 *)val; > +} > + > +u8 cxl_get_field_u8(struct tep_event *event, struct tep_record *record, > + const char *name) > +{ > + char *val; > + int len; > + > + val = tep_get_field_raw(NULL, event, name, record, &len, 0); > + if (!val) > + return UCHAR_MAX; > + > + return *(u8 *)val; > +} > + > static struct json_object *num_to_json(void *num, int elem_size, unsigned long flags) > { > bool sign = flags & TEP_FIELD_IS_SIGNED; > diff --git a/cxl/event_trace.h b/cxl/event_trace.h > index b77cafb410c4..7b30c3922aef 100644 > --- a/cxl/event_trace.h > +++ b/cxl/event_trace.h > @@ -5,6 +5,7 @@ > > #include <json-c/json.h> > #include <ccan/list/list.h> > +#include <ccan/short_types/short_types.h> > > struct jlist_node { > struct json_object *jobj; > @@ -32,5 +33,10 @@ int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx); > int cxl_event_tracing_enable(struct tracefs_instance *inst, const char *system, > const char *event); > int cxl_event_tracing_disable(struct tracefs_instance *inst); > - > +u8 cxl_get_field_u8(struct tep_event *event, struct tep_record *record, > + const char *name); > +u32 cxl_get_field_u32(struct tep_event *event, struct tep_record *record, > + const char *name); > +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, > + const char *name); > #endif > -- > 2.37.3 >
diff --git a/cxl/event_trace.c b/cxl/event_trace.c index 640abdab67bf..324edb982888 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -15,6 +15,43 @@ #define _GNU_SOURCE #include <string.h> +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, + const char *name) +{ + unsigned long long val; + + if (tep_get_field_val(NULL, event, name, record, &val, 0)) + return ULLONG_MAX; + + return val; +} + +u32 cxl_get_field_u32(struct tep_event *event, struct tep_record *record, + const char *name) +{ + char *val; + int len; + + val = tep_get_field_raw(NULL, event, name, record, &len, 0); + if (!val) + return UINT_MAX; + + return *(u32 *)val; +} + +u8 cxl_get_field_u8(struct tep_event *event, struct tep_record *record, + const char *name) +{ + char *val; + int len; + + val = tep_get_field_raw(NULL, event, name, record, &len, 0); + if (!val) + return UCHAR_MAX; + + return *(u8 *)val; +} + static struct json_object *num_to_json(void *num, int elem_size, unsigned long flags) { bool sign = flags & TEP_FIELD_IS_SIGNED; diff --git a/cxl/event_trace.h b/cxl/event_trace.h index b77cafb410c4..7b30c3922aef 100644 --- a/cxl/event_trace.h +++ b/cxl/event_trace.h @@ -5,6 +5,7 @@ #include <json-c/json.h> #include <ccan/list/list.h> +#include <ccan/short_types/short_types.h> struct jlist_node { struct json_object *jobj; @@ -32,5 +33,10 @@ int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx); int cxl_event_tracing_enable(struct tracefs_instance *inst, const char *system, const char *event); int cxl_event_tracing_disable(struct tracefs_instance *inst); - +u8 cxl_get_field_u8(struct tep_event *event, struct tep_record *record, + const char *name); +u32 cxl_get_field_u32(struct tep_event *event, struct tep_record *record, + const char *name); +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, + const char *name); #endif