[dpdk-dev] [EXT] [PATCH 6/8] trace: remove limitation on patterns number

David Marchand david.marchand at redhat.com
Mon May 4 16:14:04 CEST 2020


On Mon, May 4, 2020 at 10:48 AM Sunil Kumar Kori <skori at 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
>


-- 
David Marchand



More information about the dev mailing list