diff mbox series

[v3,08/10] cxl: add an optional pid check to event parsing

Message ID 166742404957.2654617.13465219167688999810.stgit@djiang5-desk3.ch.intel.com
State Superseded
Headers show
Series cxl: add monitor support for trace events | expand

Commit Message

Dave Jiang Nov. 2, 2022, 9:20 p.m. UTC
From: Alison Schofield <alison.schofield@intel.com>

When parsing CXL events, callers may only be interested in events
that originate from the current process. Introduce an optional
argument to the event trace context: event_pid. When event_pid is
present, only include events with a matching pid in the returned
JSON list. It is not a failure to see other, non matching results.
Simply skip those.

The initial use case for this is the listing of media errors,
where only the media-errors requested by this process are wanted.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 cxl/event_trace.c |   18 ++++++++++++++++++
 cxl/event_trace.h |    1 +
 2 files changed, 19 insertions(+)

Comments

Steven Rostedt Nov. 3, 2022, 6:08 a.m. UTC | #1
On Wed, 02 Nov 2022 14:20:49 -0700
Dave Jiang <dave.jiang@intel.com> wrote:

> From: Alison Schofield <alison.schofield@intel.com>
> 
> When parsing CXL events, callers may only be interested in events
> that originate from the current process. Introduce an optional
> argument to the event trace context: event_pid. When event_pid is
> present, only include events with a matching pid in the returned
> JSON list. It is not a failure to see other, non matching results.
> Simply skip those.
> 
> The initial use case for this is the listing of media errors,
> where only the media-errors requested by this process are wanted.
> 
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  cxl/event_trace.c |   18 ++++++++++++++++++
>  cxl/event_trace.h |    1 +
>  2 files changed, 19 insertions(+)
> 
> diff --git a/cxl/event_trace.c b/cxl/event_trace.c
> index bcd4f8b2968e..0be6317e6ada 100644
> --- a/cxl/event_trace.c
> +++ b/cxl/event_trace.c
> @@ -166,6 +166,19 @@ err_jevent:
>  	return rc;
>  }
>  
> +static bool cxl_match_pid(struct tep_event *event, struct tep_record *record,
> +			  int pid)
> +{
> +	unsigned long long val;
> +
> +	if (tep_get_common_field_val(NULL, event, "common_pid", record, &val, 0))

There's also a way to get the pid directly:

   pid = tep_data_pid(tep, record);

-- Steve

> +		return false;
> +	if (pid != (int)val)
> +		return false;
> +
> +	return true;
> +}
> +
>  static int cxl_event_parse_cb(struct tep_event *event, struct tep_record *record,
>  		int cpu, void *ctx)
>  {
> @@ -180,6 +193,11 @@ static int cxl_event_parse_cb(struct tep_event *event, struct tep_record *record
>  			return 0;
>  	}
>  
> +	if (event_ctx->event_pid) {
> +		if (!cxl_match_pid(event, record, event_ctx->event_pid))
> +			return 0;
> +	}
> +
>  	if (event_ctx->parse_event)
>  		return event_ctx->parse_event(event, record, &event_ctx->jlist_head);
>  
> diff --git a/cxl/event_trace.h b/cxl/event_trace.h
> index 17d922f922c1..64f07854b91b 100644
> --- a/cxl/event_trace.h
> +++ b/cxl/event_trace.h
> @@ -15,6 +15,7 @@ struct event_ctx {
>  	const char *system;
>  	struct list_head jlist_head;
>  	const char *event_name;					/* optional */
> +	int event_pid;						/* optional */
>  	int (*parse_event)(struct tep_event *event, struct tep_record *record,
>  			   struct list_head *jlist_head);	/* optional */
>  };
>
Alison Schofield Nov. 3, 2022, 3:57 p.m. UTC | #2
On Thu, Nov 03, 2022 at 02:08:19AM -0400, Steven Rostedt wrote:
> On Wed, 02 Nov 2022 14:20:49 -0700
> Dave Jiang <dave.jiang@intel.com> wrote:
> 
> > From: Alison Schofield <alison.schofield@intel.com>
> > 
> > When parsing CXL events, callers may only be interested in events
> > that originate from the current process. Introduce an optional
> > argument to the event trace context: event_pid. When event_pid is
> > present, only include events with a matching pid in the returned
> > JSON list. It is not a failure to see other, non matching results.
> > Simply skip those.
> > 
> > The initial use case for this is the listing of media errors,
> > where only the media-errors requested by this process are wanted.
> > 
> > Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> > Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> > ---
> >  cxl/event_trace.c |   18 ++++++++++++++++++
> >  cxl/event_trace.h |    1 +
> >  2 files changed, 19 insertions(+)
> > 
> > diff --git a/cxl/event_trace.c b/cxl/event_trace.c
> > index bcd4f8b2968e..0be6317e6ada 100644
> > --- a/cxl/event_trace.c
> > +++ b/cxl/event_trace.c
> > @@ -166,6 +166,19 @@ err_jevent:
> >  	return rc;
> >  }
> >  
> > +static bool cxl_match_pid(struct tep_event *event, struct tep_record *record,
> > +			  int pid)
> > +{
> > +	unsigned long long val;
> > +
> > +	if (tep_get_common_field_val(NULL, event, "common_pid", record, &val, 0))
> 
> There's also a way to get the pid directly:
> 
>    pid = tep_data_pid(tep, record);

I saw that and thought I'd lost the required tep_handle a couple of
layers back. Of course, it's in the tep_event too!
Will do, Thanks!

> 
> -- Steve
> 
> > +		return false;
> > +	if (pid != (int)val)
> > +		return false;
> > +
> > +	return true;
> > +}
> > +
> >  static int cxl_event_parse_cb(struct tep_event *event, struct tep_record *record,
> >  		int cpu, void *ctx)
> >  {
> > @@ -180,6 +193,11 @@ static int cxl_event_parse_cb(struct tep_event *event, struct tep_record *record
> >  			return 0;
> >  	}
> >  
> > +	if (event_ctx->event_pid) {
> > +		if (!cxl_match_pid(event, record, event_ctx->event_pid))
> > +			return 0;
> > +	}
> > +
> >  	if (event_ctx->parse_event)
> >  		return event_ctx->parse_event(event, record, &event_ctx->jlist_head);
> >  
> > diff --git a/cxl/event_trace.h b/cxl/event_trace.h
> > index 17d922f922c1..64f07854b91b 100644
> > --- a/cxl/event_trace.h
> > +++ b/cxl/event_trace.h
> > @@ -15,6 +15,7 @@ struct event_ctx {
> >  	const char *system;
> >  	struct list_head jlist_head;
> >  	const char *event_name;					/* optional */
> > +	int event_pid;						/* optional */
> >  	int (*parse_event)(struct tep_event *event, struct tep_record *record,
> >  			   struct list_head *jlist_head);	/* optional */
> >  };
> > 
>
diff mbox series

Patch

diff --git a/cxl/event_trace.c b/cxl/event_trace.c
index bcd4f8b2968e..0be6317e6ada 100644
--- a/cxl/event_trace.c
+++ b/cxl/event_trace.c
@@ -166,6 +166,19 @@  err_jevent:
 	return rc;
 }
 
+static bool cxl_match_pid(struct tep_event *event, struct tep_record *record,
+			  int pid)
+{
+	unsigned long long val;
+
+	if (tep_get_common_field_val(NULL, event, "common_pid", record, &val, 0))
+		return false;
+	if (pid != (int)val)
+		return false;
+
+	return true;
+}
+
 static int cxl_event_parse_cb(struct tep_event *event, struct tep_record *record,
 		int cpu, void *ctx)
 {
@@ -180,6 +193,11 @@  static int cxl_event_parse_cb(struct tep_event *event, struct tep_record *record
 			return 0;
 	}
 
+	if (event_ctx->event_pid) {
+		if (!cxl_match_pid(event, record, event_ctx->event_pid))
+			return 0;
+	}
+
 	if (event_ctx->parse_event)
 		return event_ctx->parse_event(event, record, &event_ctx->jlist_head);
 
diff --git a/cxl/event_trace.h b/cxl/event_trace.h
index 17d922f922c1..64f07854b91b 100644
--- a/cxl/event_trace.h
+++ b/cxl/event_trace.h
@@ -15,6 +15,7 @@  struct event_ctx {
 	const char *system;
 	struct list_head jlist_head;
 	const char *event_name;					/* optional */
+	int event_pid;						/* optional */
 	int (*parse_event)(struct tep_event *event, struct tep_record *record,
 			   struct list_head *jlist_head);	/* optional */
 };