[7/8] trace: remove limitation on trace point name
Checks
Commit Message
The name of a trace point is provided as a constant string via the
RTE_TRACE_POINT_REGISTER macro.
We can rely on the constant string in the binary and simply point at it.
There is then no need for a (fixed size) copy.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
lib/eal/common/eal_common_trace.c | 10 +++-------
lib/eal/common/eal_common_trace_utils.c | 2 +-
lib/eal/common/eal_trace.h | 3 +--
3 files changed, 5 insertions(+), 10 deletions(-)
Comments
On Wed, Sep 21, 2022 at 5:35 PM David Marchand
<david.marchand@redhat.com> wrote:
>
> The name of a trace point is provided as a constant string via the
> RTE_TRACE_POINT_REGISTER macro.
> We can rely on the constant string in the binary and simply point at it.
I am not sure about this. If we compile with -Os (optimized for space)
compiler may decide to use stack instead of rodata.
If so, we will have segfaults with specific compiler or compiler build options.
Thoughts?
> There is then no need for a (fixed size) copy.
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
> lib/eal/common/eal_common_trace.c | 10 +++-------
> lib/eal/common/eal_common_trace_utils.c | 2 +-
> lib/eal/common/eal_trace.h | 3 +--
> 3 files changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
> index 5280aa7d62..a2c5a72735 100644
> --- a/lib/eal/common/eal_common_trace.c
> +++ b/lib/eal/common/eal_common_trace.c
> @@ -231,7 +231,7 @@ rte_trace_point_lookup(const char *name)
> return NULL;
>
> STAILQ_FOREACH(tp, &tp_list, next)
> - if (strncmp(tp->name, name, TRACE_POINT_NAME_SIZE) == 0)
> + if (strcmp(tp->name, name) == 0)
> return tp->handle;
>
> return NULL;
> @@ -488,10 +488,7 @@ __rte_trace_point_register(rte_trace_point_t *handle, const char *name,
> }
>
> /* Initialize the trace point */
> - if (rte_strscpy(tp->name, name, TRACE_POINT_NAME_SIZE) < 0) {
> - trace_err("name is too long");
> - goto free;
> - }
> + tp->name = name;
>
> /* Copy the accumulated fields description and clear it for the next
> * trace point.
> @@ -513,8 +510,7 @@ __rte_trace_point_register(rte_trace_point_t *handle, const char *name,
>
> /* All Good !!! */
> return 0;
> -free:
> - free(tp);
> +
> fail:
> if (trace.register_errno == 0)
> trace.register_errno = rte_errno;
> diff --git a/lib/eal/common/eal_common_trace_utils.c b/lib/eal/common/eal_common_trace_utils.c
> index 6340caabbf..9b5a41ca12 100644
> --- a/lib/eal/common/eal_common_trace_utils.c
> +++ b/lib/eal/common/eal_common_trace_utils.c
> @@ -42,7 +42,7 @@ trace_entry_compare(const char *name)
> int count = 0;
>
> STAILQ_FOREACH(tp, tp_list, next) {
> - if (strncmp(tp->name, name, TRACE_POINT_NAME_SIZE) == 0)
> + if (strcmp(tp->name, name) == 0)
> count++;
> if (count > 1) {
> trace_err("found duplicate entry %s", name);
> diff --git a/lib/eal/common/eal_trace.h b/lib/eal/common/eal_trace.h
> index 72a5a461ae..26a18a2c48 100644
> --- a/lib/eal/common/eal_trace.h
> +++ b/lib/eal/common/eal_trace.h
> @@ -24,14 +24,13 @@
>
> #define TRACE_PREFIX_LEN 12
> #define TRACE_DIR_STR_LEN (sizeof("YYYY-mm-dd-AM-HH-MM-SS") + TRACE_PREFIX_LEN)
> -#define TRACE_POINT_NAME_SIZE 64
> #define TRACE_CTF_MAGIC 0xC1FC1FC1
> #define TRACE_MAX_ARGS 32
>
> struct trace_point {
> STAILQ_ENTRY(trace_point) next;
> rte_trace_point_t *handle;
> - char name[TRACE_POINT_NAME_SIZE];
> + const char *name;
> char *ctf_field;
> };
>
> --
> 2.37.3
>
On Tue, Oct 11, 2022 at 4:49 PM Jerin Jacob <jerinjacobk@gmail.com> wrote:
>
> On Wed, Sep 21, 2022 at 5:35 PM David Marchand
> <david.marchand@redhat.com> wrote:
> >
> > The name of a trace point is provided as a constant string via the
> > RTE_TRACE_POINT_REGISTER macro.
> > We can rely on the constant string in the binary and simply point at it.
>
> I am not sure about this. If we compile with -Os (optimized for space)
> compiler may decide to use stack instead of rodata.
> If so, we will have segfaults with specific compiler or compiler build options.
> Thoughts?
Good point.
We need an explicit storage for the string.
What do you think of:
@@ -20,9 +20,10 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);
#define RTE_TRACE_POINT_REGISTER(trace, name) \
rte_trace_point_t __attribute__((section("__rte_trace_point"))) __##trace; \
+static const char __##trace##_name[] = RTE_STR(name); \
RTE_INIT(trace##_init) \
{ \
- __rte_trace_point_register(&__##trace, RTE_STR(name), \
+ __rte_trace_point_register(&__##trace, __##trace##_name, \
(void (*)(void)) trace); \
}
On Wed, Oct 12, 2022 at 1:18 PM David Marchand
<david.marchand@redhat.com> wrote:
>
> On Tue, Oct 11, 2022 at 4:49 PM Jerin Jacob <jerinjacobk@gmail.com> wrote:
> >
> > On Wed, Sep 21, 2022 at 5:35 PM David Marchand
> > <david.marchand@redhat.com> wrote:
> > >
> > > The name of a trace point is provided as a constant string via the
> > > RTE_TRACE_POINT_REGISTER macro.
> > > We can rely on the constant string in the binary and simply point at it.
> >
> > I am not sure about this. If we compile with -Os (optimized for space)
> > compiler may decide to use stack instead of rodata.
> > If so, we will have segfaults with specific compiler or compiler build options.
> > Thoughts?
>
> Good point.
>
> We need an explicit storage for the string.
> What do you think of:
This is OK.
> @@ -20,9 +20,10 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);
>
> #define RTE_TRACE_POINT_REGISTER(trace, name) \
> rte_trace_point_t __attribute__((section("__rte_trace_point"))) __##trace; \
> +static const char __##trace##_name[] = RTE_STR(name); \
> RTE_INIT(trace##_init) \
> { \
> - __rte_trace_point_register(&__##trace, RTE_STR(name), \
> + __rte_trace_point_register(&__##trace, __##trace##_name, \
> (void (*)(void)) trace); \
> }
>
>
>
> --
> David Marchand
>
@@ -231,7 +231,7 @@ rte_trace_point_lookup(const char *name)
return NULL;
STAILQ_FOREACH(tp, &tp_list, next)
- if (strncmp(tp->name, name, TRACE_POINT_NAME_SIZE) == 0)
+ if (strcmp(tp->name, name) == 0)
return tp->handle;
return NULL;
@@ -488,10 +488,7 @@ __rte_trace_point_register(rte_trace_point_t *handle, const char *name,
}
/* Initialize the trace point */
- if (rte_strscpy(tp->name, name, TRACE_POINT_NAME_SIZE) < 0) {
- trace_err("name is too long");
- goto free;
- }
+ tp->name = name;
/* Copy the accumulated fields description and clear it for the next
* trace point.
@@ -513,8 +510,7 @@ __rte_trace_point_register(rte_trace_point_t *handle, const char *name,
/* All Good !!! */
return 0;
-free:
- free(tp);
+
fail:
if (trace.register_errno == 0)
trace.register_errno = rte_errno;
@@ -42,7 +42,7 @@ trace_entry_compare(const char *name)
int count = 0;
STAILQ_FOREACH(tp, tp_list, next) {
- if (strncmp(tp->name, name, TRACE_POINT_NAME_SIZE) == 0)
+ if (strcmp(tp->name, name) == 0)
count++;
if (count > 1) {
trace_err("found duplicate entry %s", name);
@@ -24,14 +24,13 @@
#define TRACE_PREFIX_LEN 12
#define TRACE_DIR_STR_LEN (sizeof("YYYY-mm-dd-AM-HH-MM-SS") + TRACE_PREFIX_LEN)
-#define TRACE_POINT_NAME_SIZE 64
#define TRACE_CTF_MAGIC 0xC1FC1FC1
#define TRACE_MAX_ARGS 32
struct trace_point {
STAILQ_ENTRY(trace_point) next;
rte_trace_point_t *handle;
- char name[TRACE_POINT_NAME_SIZE];
+ const char *name;
char *ctf_field;
};