linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Axel Rasmussen <axelrasmussen@google.com>
To: Steven Rostedt <rostedt@goodmis.org>, Tom Zanussi <zanussi@kernel.org>
Cc: linux-kernel@vger.kernel.org, Axel Rasmussen <axelrasmussen@google.com>
Subject: [RFC PATCH 1/1] tracing: support dynamic string field types for synthetic events
Date: Fri, 25 Sep 2020 12:08:06 -0700	[thread overview]
Message-ID: <20200925190806.1870935-2-axelrasmussen@google.com> (raw)
In-Reply-To: <20200925190806.1870935-1-axelrasmussen@google.com>

It's typical [1] to define tracepoint string fields as "const char *",
using the __string, __assign_str, and __get_str helpers. For synthetic
event definitions, the only available mechanism to define a string type
is a fixed-size char array ("char[]") [2].

Without this patch, since the type strings aren't identical, and the
sizes don't match (since one is an array, and the other is a "dynamic
string" integer), they are considered incompatible [3].

This patch modifies that check, so as to let us setup synthetic events,
and plumb through string values from typical tracepoints. It turns out
this is already handled correctly, as long as the check during
definition parsing doesn't prevent it.

[1] grep -r "__string" include/trace/events/
[2] See synth_field_is_string in kernel/trace/trace_events_synth.c
[3] See check_synth_field in kernel/trace/trace_events_hist.c

Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
---
 kernel/trace/trace_events_hist.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 0b933546142e..e064feb3cc65 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -3280,9 +3280,18 @@ static int check_synth_field(struct synth_event *event,
 	field = event->fields[field_pos];
 
 	if (strcmp(field->type, hist_field->type) != 0) {
-		if (field->size != hist_field->size ||
-		    field->is_signed != hist_field->is_signed)
-			return -EINVAL;
+		/*
+		 * If both are kinds of strings, they match. We can't use
+		 * is_string_field for the hist_field, as it's only sort of
+		 * partially initialized at this point.
+		 */
+		if (strstr(field->type, "char[") == NULL ||
+		    strstr(hist_field->type, "char[") == NULL) {
+			/* They still match if size and signedness match. */
+			if (field->size != hist_field->size ||
+			    field->is_signed != hist_field->is_signed)
+				return -EINVAL;
+		}
 	}
 
 	return 0;
-- 
2.28.0.681.g6f77f65b4e-goog


  reply	other threads:[~2020-09-25 20:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-25 19:08 [RFC PATCH 0/1] tracing: support dynamic string field types for synthetic events Axel Rasmussen
2020-09-25 19:08 ` Axel Rasmussen [this message]
2020-09-25 19:53   ` [RFC PATCH 1/1] " Tom Zanussi
2020-09-25 19:27 ` [RFC PATCH 0/1] " Steven Rostedt
2020-09-25 19:48 ` Tom Zanussi
2020-09-25 20:57   ` Axel Rasmussen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200925190806.1870935-2-axelrasmussen@google.com \
    --to=axelrasmussen@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=zanussi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).