linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE
@ 2023-09-29 10:00 Steven Rostedt
  2023-09-29 10:00 ` [PATCH 1/2] libtraceeval: Remove need to use TRACEEVAL_TYPE_NONE in keys and vals Steven Rostedt
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Steven Rostedt @ 2023-09-29 10:00 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Ross Zwisler, Stevie Alvarez, Steven Rostedt (Google)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The use of macros to determine the size of the keys and vals arrays made
me think a bit more about how we initialize the traceeval. The more I'm
using the library, the less I like having to add the TRACEEVAL_TYPE_NONE
to the end of the keys and vals array.

Instead, use the same macro trick of TRACEEVAL_ARRAY_SIZE() to determine
the number of elements. Still allow the use of using the
TRACEEVAL_TYPE_NONE to determine the size (if the number passed in is
still bigger), so that most applications that still use that still work.

I made the change separate than updating the sample code to test that
the old way still works. Then I updated the sample to make sure the new
way works. Perhaps when we add unit tests back in, we'll test both
cases.

Steven Rostedt (Google) (2):
  libtraceeval: Remove need to use TRACEEVAL_TYPE_NONE in keys and vals
  libtraceeval samples: Remove adding TRACEEVAL_TYPE_NONE to keys and
    vals

 include/traceeval-hist.h | 11 +++++++++--
 samples/task-eval.c      | 18 ------------------
 src/histograms.c         | 11 +++++++----
 3 files changed, 16 insertions(+), 24 deletions(-)

-- 
2.40.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] libtraceeval: Remove need to use TRACEEVAL_TYPE_NONE in keys and vals
  2023-09-29 10:00 [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE Steven Rostedt
@ 2023-09-29 10:00 ` Steven Rostedt
  2023-09-29 10:00 ` [PATCH 2/2] libtraceeval samples: Remove adding TRACEEVAL_TYPE_NONE to " Steven Rostedt
  2023-10-02 21:07 ` [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE Ross Zwisler
  2 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2023-09-29 10:00 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Ross Zwisler, Stevie Alvarez, Steven Rostedt (Google)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Currently, the size of the keys and vals are determined by the
requirement that the traceeval_type array end with an empty element of
type TRACEEVAL_TYPE_NONE.

To make the API be able to handle changes of the size of that structure,
the traceeval_init() was converted to a macro to pass in the sizeof of
that structure. This also means it can calculate the size of the array
with the TRACEEVAL_ARRAY_SIZE() macro.

Remove the need to have the initialization of traceeval keys and vals
have to add the NONE element at the end. It can still do so and this
will work just the same (the size will be determined by either the size
passed in or the first NONE element, which ever is smaller).

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 include/traceeval-hist.h | 11 +++++++++--
 src/histograms.c         | 11 +++++++----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/include/traceeval-hist.h b/include/traceeval-hist.h
index 65a905034773..cd089b28b852 100644
--- a/include/traceeval-hist.h
+++ b/include/traceeval-hist.h
@@ -171,12 +171,19 @@ struct traceeval;
 
 /* Histogram interfaces */
 
-#define traceeval_init(keys, vals) \
-	traceeval_init_data_size(keys, vals, sizeof(struct traceeval_type), \
+#define traceeval_init(keys, vals)					\
+	traceeval_init_size(keys, vals,					\
+			    TRACEEVAL_ARRAY_SIZE(keys),			\
+			    (void *)vals == NULL ?  0 : TRACEEVAL_ARRAY_SIZE(vals))
+
+#define traceeval_init_size(keys, vals, nr_keys, nr_vals)		\
+	traceeval_init_data_size(keys, vals, nr_keys, nr_vals,		\
+				 sizeof(struct traceeval_type),		\
 				 sizeof(struct traceeval_data))
 
 struct traceeval *traceeval_init_data_size(struct traceeval_type *keys,
 					   struct traceeval_type *vals,
+					   size_t nr_keys, size_t nr_vals,
 					   size_t sizeof_type, size_t sizeof_data);
 
 void traceeval_release(struct traceeval *teval);
diff --git a/src/histograms.c b/src/histograms.c
index ac3f7f7c76cc..5a98473c91c6 100644
--- a/src/histograms.c
+++ b/src/histograms.c
@@ -151,7 +151,8 @@ static void type_release(struct traceeval_type *defs, size_t len)
  * Returns the size of the array pointed to by @copy, or -1 on error.
  */
 static size_t type_alloc(const struct traceeval_type *defs,
-			 struct traceeval_type **copy)
+			 struct traceeval_type **copy,
+			 size_t cnt)
 {
 	struct traceeval_type *new_defs = NULL;
 	size_t size;
@@ -162,7 +163,8 @@ static size_t type_alloc(const struct traceeval_type *defs,
 	if (!defs)
 		return 0;
 
-	for (size = 0; defs && defs[size].type != TRACEEVAL_TYPE_NONE; size++)
+	for (size = 0; defs && size < cnt &&
+		     defs[size].type != TRACEEVAL_TYPE_NONE; size++)
 		;
 
 	if (!size)
@@ -269,6 +271,7 @@ static int check_vals(struct traceeval_type *vals)
  */
 struct traceeval *traceeval_init_data_size(struct traceeval_type *keys,
 					   struct traceeval_type *vals,
+					   size_t nr_keys, size_t nr_vals,
 					   size_t sizeof_type, size_t sizeof_data)
 {
 	struct traceeval *teval;
@@ -301,14 +304,14 @@ struct traceeval *traceeval_init_data_size(struct traceeval_type *keys,
 	}
 
 	/* alloc key types */
-	teval->nr_key_types = type_alloc(keys, &teval->key_types);
+	teval->nr_key_types = type_alloc(keys, &teval->key_types, nr_keys);
 	if ((ssize_t)teval->nr_key_types <= 0) {
 		err_msg = "Failed to allocate user defined keys";
 		goto fail_release;
 	}
 
 	/* alloc val types */
-	teval->nr_val_types = type_alloc(vals, &teval->val_types);
+	teval->nr_val_types = type_alloc(vals, &teval->val_types, nr_vals);
 	if ((ssize_t)teval->nr_val_types < 0) {
 		err_msg = "Failed to allocate user defined values";
 		goto fail_release;
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] libtraceeval samples: Remove adding TRACEEVAL_TYPE_NONE to keys and vals
  2023-09-29 10:00 [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE Steven Rostedt
  2023-09-29 10:00 ` [PATCH 1/2] libtraceeval: Remove need to use TRACEEVAL_TYPE_NONE in keys and vals Steven Rostedt
@ 2023-09-29 10:00 ` Steven Rostedt
  2023-10-02 21:07 ` [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE Ross Zwisler
  2 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2023-09-29 10:00 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Ross Zwisler, Stevie Alvarez, Steven Rostedt (Google)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Remove the TRACEEVAL_TYPE_NONE in the initialization of keys and vals in
the sample code as it is no longer needed.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 samples/task-eval.c | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/samples/task-eval.c b/samples/task-eval.c
index 6b01b8d076f2..361c4a835f06 100644
--- a/samples/task-eval.c
+++ b/samples/task-eval.c
@@ -89,9 +89,6 @@ static struct traceeval_type cpu_keys[] = {
 		.type = TRACEEVAL_TYPE_NUMBER,
 		.name = "Schedule state",
 	},
-	{
-		.type = TRACEEVAL_TYPE_NONE
-	}
 };
 
 static struct traceeval_type process_keys[] = {
@@ -103,9 +100,6 @@ static struct traceeval_type process_keys[] = {
 		.type = TRACEEVAL_TYPE_NUMBER,
 		.name = "Schedule state"
 	},
-	{
-		.type	= TRACEEVAL_TYPE_NONE,
-	}
 };
 
 static struct traceeval_type process_data_vals[] = {
@@ -113,9 +107,6 @@ static struct traceeval_type process_data_vals[] = {
 		.type = TRACEEVAL_TYPE_POINTER,
 		.name = "data",
 	},
-	{
-		.type = TRACEEVAL_TYPE_NONE
-	}
 };
 
 static struct traceeval_type thread_keys[] = {
@@ -127,9 +118,6 @@ static struct traceeval_type thread_keys[] = {
 		.type = TRACEEVAL_TYPE_NUMBER,
 		.name = "Schedule state",
 	},
-	{
-		.type = TRACEEVAL_TYPE_NONE,
-	}
 };
 
 static struct traceeval_type timestamp_vals[] = {
@@ -138,9 +126,6 @@ static struct traceeval_type timestamp_vals[] = {
 		.name = "Timestamp",
 		.flags = TRACEEVAL_FL_TIMESTAMP,
 	},
-	{
-		.type = TRACEEVAL_TYPE_NONE
-	}
 };
 
 static struct traceeval_type delta_vals[] = {
@@ -149,9 +134,6 @@ static struct traceeval_type delta_vals[] = {
 		.name	= "delta",
 		.flags = TRACEEVAL_FL_STAT,
 	},
-	{
-		.type	= TRACEEVAL_TYPE_NONE,
-	},
 };
 
 enum sched_state {
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE
  2023-09-29 10:00 [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE Steven Rostedt
  2023-09-29 10:00 ` [PATCH 1/2] libtraceeval: Remove need to use TRACEEVAL_TYPE_NONE in keys and vals Steven Rostedt
  2023-09-29 10:00 ` [PATCH 2/2] libtraceeval samples: Remove adding TRACEEVAL_TYPE_NONE to " Steven Rostedt
@ 2023-10-02 21:07 ` Ross Zwisler
  2023-10-02 21:18   ` Ross Zwisler
  2 siblings, 1 reply; 6+ messages in thread
From: Ross Zwisler @ 2023-10-02 21:07 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-trace-devel, Stevie Alvarez

On Fri, Sep 29, 2023 at 06:00:23AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> The use of macros to determine the size of the keys and vals arrays made
> me think a bit more about how we initialize the traceeval. The more I'm
> using the library, the less I like having to add the TRACEEVAL_TYPE_NONE
> to the end of the keys and vals array.
> 
> Instead, use the same macro trick of TRACEEVAL_ARRAY_SIZE() to determine
> the number of elements. Still allow the use of using the
> TRACEEVAL_TYPE_NONE to determine the size (if the number passed in is
> still bigger), so that most applications that still use that still work.
> 
> I made the change separate than updating the sample code to test that
> the old way still works. Then I updated the sample to make sure the new
> way works. Perhaps when we add unit tests back in, we'll test both
> cases.

Looks good, you can add:
Reviewed-by: Ross Zwisler <zwisler@google.com>

> Steven Rostedt (Google) (2):
>   libtraceeval: Remove need to use TRACEEVAL_TYPE_NONE in keys and vals
>   libtraceeval samples: Remove adding TRACEEVAL_TYPE_NONE to keys and
>     vals
> 
>  include/traceeval-hist.h | 11 +++++++++--
>  samples/task-eval.c      | 18 ------------------
>  src/histograms.c         | 11 +++++++----
>  3 files changed, 16 insertions(+), 24 deletions(-)
> 
> -- 
> 2.40.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE
  2023-10-02 21:07 ` [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE Ross Zwisler
@ 2023-10-02 21:18   ` Ross Zwisler
  2023-10-03 13:48     ` Steven Rostedt
  0 siblings, 1 reply; 6+ messages in thread
From: Ross Zwisler @ 2023-10-02 21:18 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-trace-devel, Stevie Alvarez

On Mon, Oct 02, 2023 at 03:07:49PM -0600, Ross Zwisler wrote:
> On Fri, Sep 29, 2023 at 06:00:23AM -0400, Steven Rostedt wrote:
> > From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> > 
> > The use of macros to determine the size of the keys and vals arrays made
> > me think a bit more about how we initialize the traceeval. The more I'm
> > using the library, the less I like having to add the TRACEEVAL_TYPE_NONE
> > to the end of the keys and vals array.
> > 
> > Instead, use the same macro trick of TRACEEVAL_ARRAY_SIZE() to determine
> > the number of elements. Still allow the use of using the
> > TRACEEVAL_TYPE_NONE to determine the size (if the number passed in is
> > still bigger), so that most applications that still use that still work.
> > 
> > I made the change separate than updating the sample code to test that
> > the old way still works. Then I updated the sample to make sure the new
> > way works. Perhaps when we add unit tests back in, we'll test both
> > cases.
> 
> Looks good, you can add:
> Reviewed-by: Ross Zwisler <zwisler@google.com>

Actually, I think we need to make similar updates in check_keys() and
check_vals(), else calls to traceeval_init_data_size() will walk off the end
of those respective arrays.

> 
> > Steven Rostedt (Google) (2):
> >   libtraceeval: Remove need to use TRACEEVAL_TYPE_NONE in keys and vals
> >   libtraceeval samples: Remove adding TRACEEVAL_TYPE_NONE to keys and
> >     vals
> > 
> >  include/traceeval-hist.h | 11 +++++++++--
> >  samples/task-eval.c      | 18 ------------------
> >  src/histograms.c         | 11 +++++++----
> >  3 files changed, 16 insertions(+), 24 deletions(-)
> > 
> > -- 
> > 2.40.1
> > 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE
  2023-10-02 21:18   ` Ross Zwisler
@ 2023-10-03 13:48     ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2023-10-03 13:48 UTC (permalink / raw)
  To: Ross Zwisler; +Cc: linux-trace-devel, Stevie Alvarez

On Mon, 2 Oct 2023 15:18:26 -0600
Ross Zwisler <zwisler@google.com> wrote:

> > Looks good, you can add:
> > Reviewed-by: Ross Zwisler <zwisler@google.com>  
> 
> Actually, I think we need to make similar updates in check_keys() and
> check_vals(), else calls to traceeval_init_data_size() will walk off the end
> of those respective arrays.

Good catch! I'm surprised this didn't crash it my testing. Maybe it as just
aligned in a way that there was a NULL after it.

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-10-03 13:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-29 10:00 [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE Steven Rostedt
2023-09-29 10:00 ` [PATCH 1/2] libtraceeval: Remove need to use TRACEEVAL_TYPE_NONE in keys and vals Steven Rostedt
2023-09-29 10:00 ` [PATCH 2/2] libtraceeval samples: Remove adding TRACEEVAL_TYPE_NONE to " Steven Rostedt
2023-10-02 21:07 ` [PATCH 0/2] libtraceeval: Remove the need of TRACEEVAL_TYPE_NONE Ross Zwisler
2023-10-02 21:18   ` Ross Zwisler
2023-10-03 13:48     ` Steven Rostedt

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).