From patchwork Sun May 3 20:31:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 69684 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8FDE2A04AF; Sun, 3 May 2020 22:33:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BABAD1D551; Sun, 3 May 2020 22:32:30 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 58DA31D54E for ; Sun, 3 May 2020 22:32:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588537948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1jnK42+XP6JFecF5s+LCfXD+UQxTRe1OlOSNrAY1a+c=; b=YYClXdZWWBNdLtohbN9rIEG/+HotzyOM9VgByHvCVuzzwLqMTrR0xVo4f/aG+fCDJn4tfg Gmebm85M5fs6dFMNlv65TGmGhGBm8WvmAA/ef5Mvq3Lz6cGLnE1AUM5nHi7IEbi7REU+Ma Nwbo5558aVuBOpRf/RqP1D5r7QdGqus= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-44-BJcW6_m3MYWLOBut-R_Cyg-1; Sun, 03 May 2020 16:32:25 -0400 X-MC-Unique: BJcW6_m3MYWLOBut-R_Cyg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4299F107ACCA; Sun, 3 May 2020 20:32:24 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.192.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9ABEA5798D; Sun, 3 May 2020 20:32:22 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, Jerin Jacob , Sunil Kumar Kori Date: Sun, 3 May 2020 22:31:33 +0200 Message-Id: <20200503203135.6493-7-david.marchand@redhat.com> In-Reply-To: <20200503203135.6493-1-david.marchand@redhat.com> References: <20200503203135.6493-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH 6/8] trace: remove limitation on patterns number X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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)); - 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;