[6/8] trace: remove limitation on patterns number

Message ID 20200503203135.6493-7-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series Traces cleanup for rc2 |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

David Marchand May 3, 2020, 8:31 p.m. UTC
  There is nothing performance sensitive in this list, use dynamic
allocations and remove the arbitrary limit on the number of trace
patterns a user can pass.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/librte_eal/common/eal_common_trace.c      | 10 +++---
 .../common/eal_common_trace_utils.c           | 33 ++++++++-----------
 lib/librte_eal/common/eal_trace.h             |  8 ++---
 3 files changed, 23 insertions(+), 28 deletions(-)
  

Comments

Sunil Kumar Kori May 4, 2020, 8:48 a.m. UTC | #1
>-----Original Message-----
>From: David Marchand <david.marchand@redhat.com>
>Sent: Monday, May 4, 2020 2:02 AM
>To: dev@dpdk.org
>Cc: thomas@monjalon.net; Jerin Jacob Kollanukkaran <jerinj@marvell.com>;
>Sunil Kumar Kori <skori@marvell.com>
>Subject: [EXT] [PATCH 6/8] trace: remove limitation on patterns number
>
>External Email
>
>----------------------------------------------------------------------
>There is nothing performance sensitive in this list, use dynamic allocations and
>remove the arbitrary limit on the number of trace patterns a user can pass.
>
>Signed-off-by: David Marchand <david.marchand@redhat.com>
>---
> lib/librte_eal/common/eal_common_trace.c      | 10 +++---
> .../common/eal_common_trace_utils.c           | 33 ++++++++-----------
> lib/librte_eal/common/eal_trace.h             |  8 ++---
> 3 files changed, 23 insertions(+), 28 deletions(-)
>
>diff --git a/lib/librte_eal/common/eal_common_trace.c
>b/lib/librte_eal/common/eal_common_trace.c
>index 5a365c61da..875553d7e5 100644
>--- a/lib/librte_eal/common/eal_common_trace.c
>+++ b/lib/librte_eal/common/eal_common_trace.c
>@@ -21,7 +21,7 @@ static RTE_DEFINE_PER_LCORE(char,
>ctf_field[TRACE_CTF_FIELD_SIZE]);  static RTE_DEFINE_PER_LCORE(int,
>ctf_count);
>
> static struct trace_point_head tp_list = STAILQ_HEAD_INITIALIZER(tp_list); -
>static struct trace trace;
>+static struct trace trace = { .args =
>+STAILQ_HEAD_INITIALIZER(trace.args), };
>
> struct trace *
> trace_obj_get(void)
>@@ -38,7 +38,7 @@ trace_list_head_get(void)  int
> eal_trace_init(void)
> {
>-	uint8_t i;
>+	struct trace_arg *arg;
>
> 	/* Trace memory should start with 8B aligned for natural alignment */
> 	RTE_BUILD_BUG_ON((offsetof(struct __rte_trace_header, mem) % 8)
>!= 0); @@ -49,7 +49,7 @@ eal_trace_init(void)
> 		goto fail;
> 	}
>
>-	if (trace.args.nb_args)
>+	if (!STAILQ_EMPTY(&trace.args))
> 		trace.status = true;
>
> 	if (!rte_trace_is_enabled())
>@@ -82,8 +82,8 @@ eal_trace_init(void)
> 		goto fail;
>
> 	/* Apply global configurations */
>-	for (i = 0; i < trace.args.nb_args; i++)
>-		trace_args_apply(trace.args.args[i]);
>+	STAILQ_FOREACH(arg, &trace.args, next)
>+		trace_args_apply(arg->val);
>
> 	rte_trace_mode_set(trace.mode);
>
>diff --git a/lib/librte_eal/common/eal_common_trace_utils.c
>b/lib/librte_eal/common/eal_common_trace_utils.c
>index 4077acf428..15384ce4f1 100644
>--- a/lib/librte_eal/common/eal_common_trace_utils.c
>+++ b/lib/librte_eal/common/eal_common_trace_utils.c
>@@ -138,25 +138,20 @@ int
> eal_trace_args_save(const char *val)
> {
> 	struct trace *trace = trace_obj_get();
>-	char *trace_args;
>-	uint8_t nb_args;
>+	struct trace_arg *arg = malloc(sizeof(*arg));
Won't "malloc(sizeof(struct trace_arg))" be more readable ?

>
>-	nb_args = trace->args.nb_args;
>-
>-	if (nb_args >= TRACE_MAX_ARGS) {
>-		trace_err("ignoring trace %s as limit exceeds", val);
>-		return 0;
>+	if (arg == NULL) {
>+		trace_err("failed to allocate memory for %s", val);
>+		return -ENOMEM;
> 	}
>
>-	trace_args = calloc(1, (strlen(val) + 1));
>-	if (trace_args == NULL) {
>-		trace_err("fail to allocate memory for %s", val);
>+	arg->val = strdup(val);
>+	if (arg->val == NULL) {
>+		trace_err("failed to allocate memory for %s", val);
"arg" needs to be freed here.

> 		return -ENOMEM;
> 	}
>
>-	memcpy(trace_args, val, strlen(val));
>-	trace->args.args[nb_args++] = trace_args;
>-	trace->args.nb_args = nb_args;
>+	STAILQ_INSERT_TAIL(&trace->args, arg, next);
> 	return 0;
> }
>
>@@ -164,13 +159,13 @@ void
> eal_trace_args_free(void)
> {
> 	struct trace *trace = trace_obj_get();
>-	int i;
>+	struct trace_arg *arg;
>
>-	for (i = 0; i < trace->args.nb_args; i++) {
>-		if (trace->args.args[i]) {
>-			free((void *)trace->args.args[i]);
>-			trace->args.args[i] = NULL;
>-		}
>+	while (!STAILQ_EMPTY(&trace->args)) {
>+		arg = STAILQ_FIRST(&trace->args);
>+		STAILQ_REMOVE_HEAD(&trace->args, next);
>+		free(arg->val);
>+		free(arg);
> 	}
> }
>
>diff --git a/lib/librte_eal/common/eal_trace.h
>b/lib/librte_eal/common/eal_trace.h
>index 7d95bd2aa9..943b5ecbc5 100644
>--- a/lib/librte_eal/common/eal_trace.h
>+++ b/lib/librte_eal/common/eal_trace.h
>@@ -46,9 +46,9 @@ struct thread_mem_meta {
> 	enum trace_area_e area;
> };
>
>-struct trace_args {
>-	uint8_t nb_args;
>-	char *args[TRACE_MAX_ARGS];
>+struct trace_arg {
>+	STAILQ_ENTRY(trace_arg) next;
>+	char *val;
> };
>
> struct trace {
>@@ -59,7 +59,7 @@ struct trace {
> 	enum rte_trace_mode mode;
> 	rte_uuid_t uuid;
> 	uint32_t buff_len;
>-	struct trace_args args;
>+	STAILQ_HEAD(trace_arg_head, trace_arg) args;
"trace_arg_head" is not required. It can be removed.

> 	uint32_t nb_trace_points;
> 	uint32_t nb_trace_mem_list;
> 	struct thread_mem_meta *lcore_meta;
>--
>2.23.0
  
David Marchand May 4, 2020, 2:14 p.m. UTC | #2
On Mon, May 4, 2020 at 10:48 AM Sunil Kumar Kori <skori@marvell.com> wrote:
> >diff --git a/lib/librte_eal/common/eal_common_trace_utils.c
> >b/lib/librte_eal/common/eal_common_trace_utils.c
> >index 4077acf428..15384ce4f1 100644
> >--- a/lib/librte_eal/common/eal_common_trace_utils.c
> >+++ b/lib/librte_eal/common/eal_common_trace_utils.c
> >@@ -138,25 +138,20 @@ int
> > eal_trace_args_save(const char *val)
> > {
> >       struct trace *trace = trace_obj_get();
> >-      char *trace_args;
> >-      uint8_t nb_args;
> >+      struct trace_arg *arg = malloc(sizeof(*arg));
> Won't "malloc(sizeof(struct trace_arg))" be more readable ?

ptr = malloc(sizeof(*ptr)); is more common in EAL code.
I prefer this form.


>
> >
> >-      nb_args = trace->args.nb_args;
> >-
> >-      if (nb_args >= TRACE_MAX_ARGS) {
> >-              trace_err("ignoring trace %s as limit exceeds", val);
> >-              return 0;
> >+      if (arg == NULL) {
> >+              trace_err("failed to allocate memory for %s", val);
> >+              return -ENOMEM;
> >       }
> >
> >-      trace_args = calloc(1, (strlen(val) + 1));
> >-      if (trace_args == NULL) {
> >-              trace_err("fail to allocate memory for %s", val);
> >+      arg->val = strdup(val);
> >+      if (arg->val == NULL) {
> >+              trace_err("failed to allocate memory for %s", val);
> "arg" needs to be freed here.

argh, indeed.


>
> >               return -ENOMEM;
> >       }
> >
> >-      memcpy(trace_args, val, strlen(val));
> >-      trace->args.args[nb_args++] = trace_args;
> >-      trace->args.nb_args = nb_args;
> >+      STAILQ_INSERT_TAIL(&trace->args, arg, next);
> >       return 0;
> > }
> >

> >diff --git a/lib/librte_eal/common/eal_trace.h
> >b/lib/librte_eal/common/eal_trace.h
> >index 7d95bd2aa9..943b5ecbc5 100644
> >--- a/lib/librte_eal/common/eal_trace.h
> >+++ b/lib/librte_eal/common/eal_trace.h
> >@@ -46,9 +46,9 @@ struct thread_mem_meta {
> >       enum trace_area_e area;
> > };
> >
> >-struct trace_args {
> >-      uint8_t nb_args;
> >-      char *args[TRACE_MAX_ARGS];
> >+struct trace_arg {
> >+      STAILQ_ENTRY(trace_arg) next;
> >+      char *val;
> > };
> >
> > struct trace {
> >@@ -59,7 +59,7 @@ struct trace {
> >       enum rte_trace_mode mode;
> >       rte_uuid_t uuid;
> >       uint32_t buff_len;
> >-      struct trace_args args;
> >+      STAILQ_HEAD(trace_arg_head, trace_arg) args;
> "trace_arg_head" is not required. It can be removed.

Ack.


>
> >       uint32_t nb_trace_points;
> >       uint32_t nb_trace_mem_list;
> >       struct thread_mem_meta *lcore_meta;
> >--
> >2.23.0
>
  
Sunil Kumar Kori May 5, 2020, 5:54 a.m. UTC | #3
>-----Original Message-----
>From: David Marchand <david.marchand@redhat.com>
>Sent: Monday, May 4, 2020 7:44 PM
>To: Sunil Kumar Kori <skori@marvell.com>
>Cc: dev@dpdk.org; thomas@monjalon.net; Jerin Jacob Kollanukkaran
><jerinj@marvell.com>
>Subject: Re: [EXT] [PATCH 6/8] trace: remove limitation on patterns number
>
>On Mon, May 4, 2020 at 10:48 AM Sunil Kumar Kori <skori@marvell.com>
>wrote:
>> >diff --git a/lib/librte_eal/common/eal_common_trace_utils.c
>> >b/lib/librte_eal/common/eal_common_trace_utils.c
>> >index 4077acf428..15384ce4f1 100644
>> >--- a/lib/librte_eal/common/eal_common_trace_utils.c
>> >+++ b/lib/librte_eal/common/eal_common_trace_utils.c
>> >@@ -138,25 +138,20 @@ int
>> > eal_trace_args_save(const char *val)  {
>> >       struct trace *trace = trace_obj_get();
>> >-      char *trace_args;
>> >-      uint8_t nb_args;
>> >+      struct trace_arg *arg = malloc(sizeof(*arg));
>> Won't "malloc(sizeof(struct trace_arg))" be more readable ?
>
>ptr = malloc(sizeof(*ptr)); is more common in EAL code.
>I prefer this form.
>
>
Ack

>>
>> >
>> >-      nb_args = trace->args.nb_args;
>> >-
>> >-      if (nb_args >= TRACE_MAX_ARGS) {
>> >-              trace_err("ignoring trace %s as limit exceeds", val);
>> >-              return 0;
>> >+      if (arg == NULL) {
>> >+              trace_err("failed to allocate memory for %s", val);
>> >+              return -ENOMEM;
>> >       }
>> >
>> >-      trace_args = calloc(1, (strlen(val) + 1));
>> >-      if (trace_args == NULL) {
>> >-              trace_err("fail to allocate memory for %s", val);
>> >+      arg->val = strdup(val);
>> >+      if (arg->val == NULL) {
>> >+              trace_err("failed to allocate memory for %s", val);
>> "arg" needs to be freed here.
>
>argh, indeed.
>
>
Sorry, I didn't understand "argh" but assuming that you are agreed. 

>>
>> >               return -ENOMEM;
>> >       }
>> >
>> >-      memcpy(trace_args, val, strlen(val));
>> >-      trace->args.args[nb_args++] = trace_args;
>> >-      trace->args.nb_args = nb_args;
>> >+      STAILQ_INSERT_TAIL(&trace->args, arg, next);
>> >       return 0;
>> > }
>> >
>
>> >diff --git a/lib/librte_eal/common/eal_trace.h
>> >b/lib/librte_eal/common/eal_trace.h
>> >index 7d95bd2aa9..943b5ecbc5 100644
>> >--- a/lib/librte_eal/common/eal_trace.h
>> >+++ b/lib/librte_eal/common/eal_trace.h
>> >@@ -46,9 +46,9 @@ struct thread_mem_meta {
>> >       enum trace_area_e area;
>> > };
>> >
>> >-struct trace_args {
>> >-      uint8_t nb_args;
>> >-      char *args[TRACE_MAX_ARGS];
>> >+struct trace_arg {
>> >+      STAILQ_ENTRY(trace_arg) next;
>> >+      char *val;
>> > };
>> >
>> > struct trace {
>> >@@ -59,7 +59,7 @@ struct trace {
>> >       enum rte_trace_mode mode;
>> >       rte_uuid_t uuid;
>> >       uint32_t buff_len;
>> >-      struct trace_args args;
>> >+      STAILQ_HEAD(trace_arg_head, trace_arg) args;
>> "trace_arg_head" is not required. It can be removed.
>
>Ack.
>
>
>>
>> >       uint32_t nb_trace_points;
>> >       uint32_t nb_trace_mem_list;
>> >       struct thread_mem_meta *lcore_meta;
>> >--
>> >2.23.0
>>
>
>
>--
>David Marchand
  

Patch

diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c
index 5a365c61da..875553d7e5 100644
--- a/lib/librte_eal/common/eal_common_trace.c
+++ b/lib/librte_eal/common/eal_common_trace.c
@@ -21,7 +21,7 @@  static RTE_DEFINE_PER_LCORE(char, ctf_field[TRACE_CTF_FIELD_SIZE]);
 static RTE_DEFINE_PER_LCORE(int, ctf_count);
 
 static struct trace_point_head tp_list = STAILQ_HEAD_INITIALIZER(tp_list);
-static struct trace trace;
+static struct trace trace = { .args = STAILQ_HEAD_INITIALIZER(trace.args), };
 
 struct trace *
 trace_obj_get(void)
@@ -38,7 +38,7 @@  trace_list_head_get(void)
 int
 eal_trace_init(void)
 {
-	uint8_t i;
+	struct trace_arg *arg;
 
 	/* Trace memory should start with 8B aligned for natural alignment */
 	RTE_BUILD_BUG_ON((offsetof(struct __rte_trace_header, mem) % 8) != 0);
@@ -49,7 +49,7 @@  eal_trace_init(void)
 		goto fail;
 	}
 
-	if (trace.args.nb_args)
+	if (!STAILQ_EMPTY(&trace.args))
 		trace.status = true;
 
 	if (!rte_trace_is_enabled())
@@ -82,8 +82,8 @@  eal_trace_init(void)
 		goto fail;
 
 	/* Apply global configurations */
-	for (i = 0; i < trace.args.nb_args; i++)
-		trace_args_apply(trace.args.args[i]);
+	STAILQ_FOREACH(arg, &trace.args, next)
+		trace_args_apply(arg->val);
 
 	rte_trace_mode_set(trace.mode);
 
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index 4077acf428..15384ce4f1 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -138,25 +138,20 @@  int
 eal_trace_args_save(const char *val)
 {
 	struct trace *trace = trace_obj_get();
-	char *trace_args;
-	uint8_t nb_args;
+	struct trace_arg *arg = malloc(sizeof(*arg));
 
-	nb_args = trace->args.nb_args;
-
-	if (nb_args >= TRACE_MAX_ARGS) {
-		trace_err("ignoring trace %s as limit exceeds", val);
-		return 0;
+	if (arg == NULL) {
+		trace_err("failed to allocate memory for %s", val);
+		return -ENOMEM;
 	}
 
-	trace_args = calloc(1, (strlen(val) + 1));
-	if (trace_args == NULL) {
-		trace_err("fail to allocate memory for %s", val);
+	arg->val = strdup(val);
+	if (arg->val == NULL) {
+		trace_err("failed to allocate memory for %s", val);
 		return -ENOMEM;
 	}
 
-	memcpy(trace_args, val, strlen(val));
-	trace->args.args[nb_args++] = trace_args;
-	trace->args.nb_args = nb_args;
+	STAILQ_INSERT_TAIL(&trace->args, arg, next);
 	return 0;
 }
 
@@ -164,13 +159,13 @@  void
 eal_trace_args_free(void)
 {
 	struct trace *trace = trace_obj_get();
-	int i;
+	struct trace_arg *arg;
 
-	for (i = 0; i < trace->args.nb_args; i++) {
-		if (trace->args.args[i]) {
-			free((void *)trace->args.args[i]);
-			trace->args.args[i] = NULL;
-		}
+	while (!STAILQ_EMPTY(&trace->args)) {
+		arg = STAILQ_FIRST(&trace->args);
+		STAILQ_REMOVE_HEAD(&trace->args, next);
+		free(arg->val);
+		free(arg);
 	}
 }
 
diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h
index 7d95bd2aa9..943b5ecbc5 100644
--- a/lib/librte_eal/common/eal_trace.h
+++ b/lib/librte_eal/common/eal_trace.h
@@ -46,9 +46,9 @@  struct thread_mem_meta {
 	enum trace_area_e area;
 };
 
-struct trace_args {
-	uint8_t nb_args;
-	char *args[TRACE_MAX_ARGS];
+struct trace_arg {
+	STAILQ_ENTRY(trace_arg) next;
+	char *val;
 };
 
 struct trace {
@@ -59,7 +59,7 @@  struct trace {
 	enum rte_trace_mode mode;
 	rte_uuid_t uuid;
 	uint32_t buff_len;
-	struct trace_args args;
+	STAILQ_HEAD(trace_arg_head, trace_arg) args;
 	uint32_t nb_trace_points;
 	uint32_t nb_trace_mem_list;
 	struct thread_mem_meta *lcore_meta;