[v2,2/4] trace: remove size limit on CTF event description
Checks
Commit Message
Rework registration so that it uses dynamic allocations and has no size
limit.
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Jerin Jacob <jerinj@marvell.com>
---
lib/librte_eal/common/eal_common_trace.c | 39 +++++++++-----------
lib/librte_eal/common/eal_common_trace_ctf.c | 3 +-
lib/librte_eal/common/eal_trace.h | 3 +-
3 files changed, 20 insertions(+), 25 deletions(-)
Comments
>-----Original Message-----
>From: David Marchand <david.marchand@redhat.com>
>Sent: Thursday, October 29, 2020 2:33 AM
>To: dev@dpdk.org
>Cc: Jerin Jacob Kollanukkaran <jerinj@marvell.com>; Sunil Kumar Kori
><skori@marvell.com>
>Subject: [EXT] [PATCH v2 2/4] trace: remove size limit on CTF event description
>
>External Email
>
>----------------------------------------------------------------------
>Rework registration so that it uses dynamic allocations and has no size limit.
>
>Signed-off-by: David Marchand <david.marchand@redhat.com>
>Reviewed-by: Jerin Jacob <jerinj@marvell.com>
>---
> lib/librte_eal/common/eal_common_trace.c | 39 +++++++++-----------
> lib/librte_eal/common/eal_common_trace_ctf.c | 3 +-
> lib/librte_eal/common/eal_trace.h | 3 +-
> 3 files changed, 20 insertions(+), 25 deletions(-)
>
>diff --git a/lib/librte_eal/common/eal_common_trace.c
>b/lib/librte_eal/common/eal_common_trace.c
>index 80b458edb6..bc031ca719 100644
>--- a/lib/librte_eal/common/eal_common_trace.c
>+++ b/lib/librte_eal/common/eal_common_trace.c
>@@ -17,8 +17,7 @@
>
> RTE_DEFINE_PER_LCORE(volatile int, trace_point_sz);
>RTE_DEFINE_PER_LCORE(void *, trace_mem); -static
>RTE_DEFINE_PER_LCORE(char, ctf_field[TRACE_CTF_FIELD_SIZE]); -static
>RTE_DEFINE_PER_LCORE(int, ctf_count);
>+static RTE_DEFINE_PER_LCORE(char *, ctf_field);
>
> static struct trace_point_head tp_list = STAILQ_HEAD_INITIALIZER(tp_list);
>static struct trace trace = { .args = STAILQ_HEAD_INITIALIZER(trace.args), };
>@@ -429,32 +428,33 @@ trace_mem_free(void) void
>__rte_trace_point_emit_field(size_t sz, const char *in, const char *datatype) {
>- char *field = RTE_PER_LCORE(ctf_field);
>- int count = RTE_PER_LCORE(ctf_count);
>- size_t size;
>+ char *field;
> char *fixup;
> int rc;
>
>- size = RTE_MAX(0, TRACE_CTF_FIELD_SIZE - 1 - count);
>- RTE_PER_LCORE(trace_point_sz) += sz;
> fixup = trace_metadata_fixup_field(in);
> if (fixup != NULL)
> in = fixup;
>- rc = snprintf(RTE_PTR_ADD(field, count), size, "%s %s;", datatype, in);
>+ rc = asprintf(&field, "%s%s %s;",
>+ RTE_PER_LCORE(ctf_field) != NULL ?
>+ RTE_PER_LCORE(ctf_field) : "",
>+ datatype, in);
>+ free(RTE_PER_LCORE(ctf_field));
> free(fixup);
>- if (rc <= 0 || (size_t)rc >= size) {
>+ if (rc == -1) {
> RTE_PER_LCORE(trace_point_sz) = 0;
>- trace_crit("CTF field is too long");
>+ RTE_PER_LCORE(ctf_field) = NULL;
>+ trace_crit("could not allocate CTF field");
> return;
> }
>- RTE_PER_LCORE(ctf_count) += rc;
>+ RTE_PER_LCORE(trace_point_sz) += sz;
>+ RTE_PER_LCORE(ctf_field) = field;
> }
>
> int
> __rte_trace_point_register(rte_trace_point_t *handle, const char *name,
> void (*register_fn)(void))
> {
>- char *field = RTE_PER_LCORE(ctf_field);
> struct trace_point *tp;
> uint16_t sz;
>
>@@ -467,7 +467,6 @@ __rte_trace_point_register(rte_trace_point_t *handle,
>const char *name,
>
> /* Check the size of the trace point object */
> RTE_PER_LCORE(trace_point_sz) = 0;
>- RTE_PER_LCORE(ctf_count) = 0;
> register_fn();
> if (RTE_PER_LCORE(trace_point_sz) == 0) {
> trace_err("missing rte_trace_emit_header() in register fn");
>@@ -505,15 +504,11 @@ __rte_trace_point_register(rte_trace_point_t
>*handle, const char *name,
> goto free;
> }
>
>- /* Copy the field data for future use */
>- if (rte_strscpy(tp->ctf_field, field, TRACE_CTF_FIELD_SIZE) < 0) {
>- trace_err("CTF field size is too long");
>- rte_errno = E2BIG;
>- goto free;
>- }
>-
>- /* Clear field memory for the next event */
>- memset(field, 0, TRACE_CTF_FIELD_SIZE);
>+ /* Copy the accumulated fields description and clear it for the next
>+ * trace point.
>+ */
>+ tp->ctf_field = RTE_PER_LCORE(ctf_field);
>+ RTE_PER_LCORE(ctf_field) = NULL;
Although patch looks okay but I have one that how "tp->ctf_field" is populated because during
registration time RTE_PER_LCORE(ctf_field) will be NULL. So "tp->ctf_field" will always be NULL.
>
> /* Form the trace handle */
> *handle = sz;
>diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c
>b/lib/librte_eal/common/eal_common_trace_ctf.c
>index 174cdac1b0..ac1f64d04b 100644
>--- a/lib/librte_eal/common/eal_common_trace_ctf.c
>+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
>@@ -233,7 +233,8 @@ meta_event_emit(char **meta, int *offset, struct
>trace_point *tp)
> " fields := struct {\n"
> " %s\n"
> " };\n"
>- "};\n\n", trace_id_get(tp->handle), tp->name, tp->ctf_field);
>+ "};\n\n", trace_id_get(tp->handle), tp->name,
>+ tp->ctf_field != NULL ? tp->ctf_field : "");
> return meta_copy(meta, offset, str, rc); }
>
>diff --git a/lib/librte_eal/common/eal_trace.h
>b/lib/librte_eal/common/eal_trace.h
>index 8a3f6c5359..06751eb23a 100644
>--- a/lib/librte_eal/common/eal_trace.h
>+++ b/lib/librte_eal/common/eal_trace.h
>@@ -24,7 +24,6 @@
>
> #define TRACE_PREFIX_LEN 12
> #define TRACE_DIR_STR_LEN (sizeof("YYYY-mm-dd-AM-HH-MM-SS") +
>TRACE_PREFIX_LEN) -#define TRACE_CTF_FIELD_SIZE 448 #define
>TRACE_POINT_NAME_SIZE 64 #define TRACE_CTF_MAGIC 0xC1FC1FC1
> #define TRACE_MAX_ARGS 32
>@@ -33,7 +32,7 @@ struct trace_point {
> STAILQ_ENTRY(trace_point) next;
> rte_trace_point_t *handle;
> char name[TRACE_POINT_NAME_SIZE];
>- char ctf_field[TRACE_CTF_FIELD_SIZE];
>+ char *ctf_field;
> };
>
> enum trace_area_e {
>--
>2.23.0
On Thu, Oct 29, 2020 at 9:41 AM Sunil Kumar Kori <skori@marvell.com> wrote:
> >@@ -505,15 +504,11 @@ __rte_trace_point_register(rte_trace_point_t
> >*handle, const char *name,
> > goto free;
> > }
> >
> >- /* Copy the field data for future use */
> >- if (rte_strscpy(tp->ctf_field, field, TRACE_CTF_FIELD_SIZE) < 0) {
> >- trace_err("CTF field size is too long");
> >- rte_errno = E2BIG;
> >- goto free;
> >- }
> >-
> >- /* Clear field memory for the next event */
> >- memset(field, 0, TRACE_CTF_FIELD_SIZE);
> >+ /* Copy the accumulated fields description and clear it for the next
> >+ * trace point.
> >+ */
> >+ tp->ctf_field = RTE_PER_LCORE(ctf_field);
> >+ RTE_PER_LCORE(ctf_field) = NULL;
>
> Although patch looks okay but I have one that how "tp->ctf_field" is populated because during
> registration time RTE_PER_LCORE(ctf_field) will be NULL. So "tp->ctf_field" will always be NULL.
Sorry, I don't understand your comment.
RTE_PER_LCORE(ctf_field) is filled at __rte_trace_point_emit_field.
>-----Original Message-----
>From: David Marchand <david.marchand@redhat.com>
>Sent: Thursday, October 29, 2020 2:22 PM
>To: Sunil Kumar Kori <skori@marvell.com>
>Cc: dev@dpdk.org; Jerin Jacob Kollanukkaran <jerinj@marvell.com>
>Subject: Re: [EXT] [PATCH v2 2/4] trace: remove size limit on CTF event
>description
>
>On Thu, Oct 29, 2020 at 9:41 AM Sunil Kumar Kori <skori@marvell.com>
>wrote:
>> >@@ -505,15 +504,11 @@ __rte_trace_point_register(rte_trace_point_t
>> >*handle, const char *name,
>> > goto free;
>> > }
>> >
>> >- /* Copy the field data for future use */
>> >- if (rte_strscpy(tp->ctf_field, field, TRACE_CTF_FIELD_SIZE) < 0) {
>> >- trace_err("CTF field size is too long");
>> >- rte_errno = E2BIG;
>> >- goto free;
>> >- }
>> >-
>> >- /* Clear field memory for the next event */
>> >- memset(field, 0, TRACE_CTF_FIELD_SIZE);
>> >+ /* Copy the accumulated fields description and clear it for the next
>> >+ * trace point.
>> >+ */
>> >+ tp->ctf_field = RTE_PER_LCORE(ctf_field);
>> >+ RTE_PER_LCORE(ctf_field) = NULL;
>>
>> Although patch looks okay but I have one that how "tp->ctf_field" is
>> populated because during registration time RTE_PER_LCORE(ctf_field) will
>be NULL. So "tp->ctf_field" will always be NULL.
>
>Sorry, I don't understand your comment.
>RTE_PER_LCORE(ctf_field) is filled at __rte_trace_point_emit_field.
Yes but I am not able to understand that how tp->ctf_field will be populated with latest memory
because RTE_PER_LCORE(ctf_field) is being free and re-allocated at runtime.
>
>
>--
>David Marchand
On Thu, Oct 29, 2020 at 10:36 AM Sunil Kumar Kori <skori@marvell.com> wrote:
> Yes but I am not able to understand that how tp->ctf_field will be populated with latest memory
> because RTE_PER_LCORE(ctf_field) is being free and re-allocated at runtime.
Initially, RTE_PER_LCORE(ctf_field) is NULL.
Then registration for a trace point happens:
__rte_trace_point_register() calls register_fn() which for each field
in the trace point calls __rte_trace_point_emit_field().
Each call to __rte_trace_point_emit_field accumulates the previous
ctf_field with the new field.
rc = asprintf(&field, "%s %s %s;\n",
RTE_PER_LCORE(ctf_field) != NULL ?
RTE_PER_LCORE(ctf_field) : "",
datatype, in);
free(RTE_PER_LCORE(ctf_field));
RTE_PER_LCORE(ctf_field) = field;
Here, RTE_PER_LCORE(ctf_field) is != NULL.
Back to __rte_trace_point_register:
/* Copy the accumulated fields description and clear it for the next
* trace point.
*/
tp->ctf_field = RTE_PER_LCORE(ctf_field);
Once stored, RTE_PER_LCORE(ctf_field) is cleared again for the next
trace point registration.
RTE_PER_LCORE(ctf_field) = NULL;
>-----Original Message-----
>From: David Marchand <david.marchand@redhat.com>
>Sent: Thursday, October 29, 2020 3:33 PM
>To: Sunil Kumar Kori <skori@marvell.com>
>Cc: dev@dpdk.org; Jerin Jacob Kollanukkaran <jerinj@marvell.com>
>Subject: Re: [EXT] [PATCH v2 2/4] trace: remove size limit on CTF event
>description
>
>On Thu, Oct 29, 2020 at 10:36 AM Sunil Kumar Kori <skori@marvell.com>
>wrote:
>> Yes but I am not able to understand that how tp->ctf_field will be
>> populated with latest memory because RTE_PER_LCORE(ctf_field) is being
>free and re-allocated at runtime.
>
>Initially, RTE_PER_LCORE(ctf_field) is NULL.
>
>Then registration for a trace point happens:
>
>__rte_trace_point_register() calls register_fn() which for each field in the trace
>point calls __rte_trace_point_emit_field().
>
>Each call to __rte_trace_point_emit_field accumulates the previous ctf_field
>with the new field.
>
> rc = asprintf(&field, "%s %s %s;\n",
> RTE_PER_LCORE(ctf_field) != NULL ?
> RTE_PER_LCORE(ctf_field) : "",
> datatype, in);
> free(RTE_PER_LCORE(ctf_field));
> RTE_PER_LCORE(ctf_field) = field;
>
>Here, RTE_PER_LCORE(ctf_field) is != NULL.
>
>Back to __rte_trace_point_register:
>
> /* Copy the accumulated fields description and clear it for the next
> * trace point.
> */
> tp->ctf_field = RTE_PER_LCORE(ctf_field);
>
>Once stored, RTE_PER_LCORE(ctf_field) is cleared again for the next trace
>point registration.
>
> RTE_PER_LCORE(ctf_field) = NULL;
>
>
>
Acked-by: Sunil Kumar Kori <skori@mavell.com>
>--
>David Marchand
@@ -17,8 +17,7 @@
RTE_DEFINE_PER_LCORE(volatile int, trace_point_sz);
RTE_DEFINE_PER_LCORE(void *, trace_mem);
-static RTE_DEFINE_PER_LCORE(char, ctf_field[TRACE_CTF_FIELD_SIZE]);
-static RTE_DEFINE_PER_LCORE(int, ctf_count);
+static RTE_DEFINE_PER_LCORE(char *, ctf_field);
static struct trace_point_head tp_list = STAILQ_HEAD_INITIALIZER(tp_list);
static struct trace trace = { .args = STAILQ_HEAD_INITIALIZER(trace.args), };
@@ -429,32 +428,33 @@ trace_mem_free(void)
void
__rte_trace_point_emit_field(size_t sz, const char *in, const char *datatype)
{
- char *field = RTE_PER_LCORE(ctf_field);
- int count = RTE_PER_LCORE(ctf_count);
- size_t size;
+ char *field;
char *fixup;
int rc;
- size = RTE_MAX(0, TRACE_CTF_FIELD_SIZE - 1 - count);
- RTE_PER_LCORE(trace_point_sz) += sz;
fixup = trace_metadata_fixup_field(in);
if (fixup != NULL)
in = fixup;
- rc = snprintf(RTE_PTR_ADD(field, count), size, "%s %s;", datatype, in);
+ rc = asprintf(&field, "%s%s %s;",
+ RTE_PER_LCORE(ctf_field) != NULL ?
+ RTE_PER_LCORE(ctf_field) : "",
+ datatype, in);
+ free(RTE_PER_LCORE(ctf_field));
free(fixup);
- if (rc <= 0 || (size_t)rc >= size) {
+ if (rc == -1) {
RTE_PER_LCORE(trace_point_sz) = 0;
- trace_crit("CTF field is too long");
+ RTE_PER_LCORE(ctf_field) = NULL;
+ trace_crit("could not allocate CTF field");
return;
}
- RTE_PER_LCORE(ctf_count) += rc;
+ RTE_PER_LCORE(trace_point_sz) += sz;
+ RTE_PER_LCORE(ctf_field) = field;
}
int
__rte_trace_point_register(rte_trace_point_t *handle, const char *name,
void (*register_fn)(void))
{
- char *field = RTE_PER_LCORE(ctf_field);
struct trace_point *tp;
uint16_t sz;
@@ -467,7 +467,6 @@ __rte_trace_point_register(rte_trace_point_t *handle, const char *name,
/* Check the size of the trace point object */
RTE_PER_LCORE(trace_point_sz) = 0;
- RTE_PER_LCORE(ctf_count) = 0;
register_fn();
if (RTE_PER_LCORE(trace_point_sz) == 0) {
trace_err("missing rte_trace_emit_header() in register fn");
@@ -505,15 +504,11 @@ __rte_trace_point_register(rte_trace_point_t *handle, const char *name,
goto free;
}
- /* Copy the field data for future use */
- if (rte_strscpy(tp->ctf_field, field, TRACE_CTF_FIELD_SIZE) < 0) {
- trace_err("CTF field size is too long");
- rte_errno = E2BIG;
- goto free;
- }
-
- /* Clear field memory for the next event */
- memset(field, 0, TRACE_CTF_FIELD_SIZE);
+ /* Copy the accumulated fields description and clear it for the next
+ * trace point.
+ */
+ tp->ctf_field = RTE_PER_LCORE(ctf_field);
+ RTE_PER_LCORE(ctf_field) = NULL;
/* Form the trace handle */
*handle = sz;
@@ -233,7 +233,8 @@ meta_event_emit(char **meta, int *offset, struct trace_point *tp)
" fields := struct {\n"
" %s\n"
" };\n"
- "};\n\n", trace_id_get(tp->handle), tp->name, tp->ctf_field);
+ "};\n\n", trace_id_get(tp->handle), tp->name,
+ tp->ctf_field != NULL ? tp->ctf_field : "");
return meta_copy(meta, offset, str, rc);
}
@@ -24,7 +24,6 @@
#define TRACE_PREFIX_LEN 12
#define TRACE_DIR_STR_LEN (sizeof("YYYY-mm-dd-AM-HH-MM-SS") + TRACE_PREFIX_LEN)
-#define TRACE_CTF_FIELD_SIZE 448
#define TRACE_POINT_NAME_SIZE 64
#define TRACE_CTF_MAGIC 0xC1FC1FC1
#define TRACE_MAX_ARGS 32
@@ -33,7 +32,7 @@ struct trace_point {
STAILQ_ENTRY(trace_point) next;
rte_trace_point_t *handle;
char name[TRACE_POINT_NAME_SIZE];
- char ctf_field[TRACE_CTF_FIELD_SIZE];
+ char *ctf_field;
};
enum trace_area_e {