From patchwork Tue Oct 18 13:26:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118416 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 35F15A0560; Tue, 18 Oct 2022 15:27:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 03A52410E8; Tue, 18 Oct 2022 15:27:21 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 08202410E8 for ; Tue, 18 Oct 2022 15:27:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099639; 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=2ACJOkmzuDX1UJ+c22UtILM8RNz9OT1aGtEDQTYJmrw=; b=g12wnddvDTXkG8zDLuuvyz7W6YTalI/NzjBJQZDrhWkFbXDfABPxPxMT8RngDcVc8SWhRd QADap2AbIDaSVwBxlLTP0WuF+NIXqZqcEyHfn0O/Y0Rc1uBZJG20RNmNxpuVFRvpytxAd4 IinQKB1Lj2mvHgzYZe42wBJQ0Fu4P84= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-KDQoyKJzMjGgrnduA0qUBw-1; Tue, 18 Oct 2022 09:27:15 -0400 X-MC-Unique: KDQoyKJzMjGgrnduA0qUBw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0EB593C0218C; Tue, 18 Oct 2022 13:27:15 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CBD7C1908A; Tue, 18 Oct 2022 13:27:13 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com, stable@dpdk.org Subject: [PATCH v4 01/11] trace: fix mode for new trace point Date: Tue, 18 Oct 2022 15:26:44 +0200 Message-Id: <20221018132654.3760561-2-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org If an application registers trace points later than rte_eal_init(), changes in the trace point mode were not applied. Fixes: 84c4fae4628f ("trace: implement operation APIs") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Jerin Jacob Acked-by: Sunil Kumar Kori --- lib/eal/common/eal_common_trace.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index f9b187d15f..d5dbc7d667 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -512,6 +512,7 @@ __rte_trace_point_register(rte_trace_point_t *handle, const char *name, /* Form the trace handle */ *handle = sz; *handle |= trace.nb_trace_points << __RTE_TRACE_FIELD_ID_SHIFT; + trace_mode_set(handle, trace.mode); trace.nb_trace_points++; tp->handle = handle; From patchwork Tue Oct 18 13:26:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118418 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 50C76A0560; Tue, 18 Oct 2022 15:27:32 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 01EF04114E; Tue, 18 Oct 2022 15:27:27 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 9457E4114E for ; Tue, 18 Oct 2022 15:27:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099645; 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=EX6bedBJRMIFWwVTXxurdlnS3wy6PWSviCKn1ubkE7Y=; b=XhqHh5v89l0EfKaCGhF1do2PbP/EOl+c/HznVbzap/FpDz3asqrbWpYKoNblE+WkzEdTiq Vav3VC9X4qjNKRFep4iOSL3HHfsJG0tfbbmCTyX+QXYFtJA5NrGUnQN5Th5F2ciT2tehg5 +pjz5EuLXlEUWaIEpWA8WrjGJBBNgYs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-455-f19Nyf9FNraDjtxvJhDGxQ-1; Tue, 18 Oct 2022 09:27:18 -0400 X-MC-Unique: f19Nyf9FNraDjtxvJhDGxQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 20B6429AA38B; Tue, 18 Oct 2022 13:27:18 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 302BF9D48F; Tue, 18 Oct 2022 13:27:17 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com, stable@dpdk.org Subject: [PATCH v4 02/11] trace: fix mode change Date: Tue, 18 Oct 2022 15:26:45 +0200 Message-Id: <20221018132654.3760561-3-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The API does not state that changing mode should be refused if no trace point is enabled. Remove this limitation. Fixes: 84c4fae4628f ("trace: implement operation APIs") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Sunil Kumar Kori --- app/test/test_trace.c | 3 --- lib/eal/common/eal_common_trace.c | 3 --- 2 files changed, 6 deletions(-) diff --git a/app/test/test_trace.c b/app/test/test_trace.c index 76af79162b..44ac38a4fa 100644 --- a/app/test/test_trace.c +++ b/app/test/test_trace.c @@ -126,9 +126,6 @@ test_trace_mode(void) current = rte_trace_mode_get(); - if (!rte_trace_is_enabled()) - return TEST_SKIPPED; - rte_trace_mode_set(RTE_TRACE_MODE_DISCARD); if (rte_trace_mode_get() != RTE_TRACE_MODE_DISCARD) goto failed; diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index d5dbc7d667..1b86f5d2d2 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -127,9 +127,6 @@ rte_trace_mode_set(enum rte_trace_mode mode) { struct trace_point *tp; - if (!rte_trace_is_enabled()) - return; - STAILQ_FOREACH(tp, &tp_list, next) trace_mode_set(tp->handle, mode); From patchwork Tue Oct 18 13:26:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118417 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2CE3CA0560; Tue, 18 Oct 2022 15:27:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0B22441145; Tue, 18 Oct 2022 15:27:24 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 0E2344021D for ; Tue, 18 Oct 2022 15:27:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099642; 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=yOkTsOKYyNlfTK4EpoU48NsbftkjFdAzGjwW/BaAsG0=; b=PAU76BRGACI9U3O7UEfRpxqXCWaZPfK/Bmkb8UNeaP0Re6L70p8USzpGlBn3/bfU0q9Ghu kZpu8xT9M04QHabbYu16qdcIW70KZnHMAUPZ0WaAcFPLcBgM2GoRhAequ0BsyWv2tTe58y LTeqVz/j9H+rASM2uIkLS0QWDMaVuN0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-346-h7pI91uIP_uRaf8-WjGFSQ-1; Tue, 18 Oct 2022 09:27:21 -0400 X-MC-Unique: h7pI91uIP_uRaf8-WjGFSQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0DDF13C0218C; Tue, 18 Oct 2022 13:27:21 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A55D4081B63; Tue, 18 Oct 2022 13:27:19 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com, stable@dpdk.org Subject: [PATCH v4 03/11] trace: fix leak with regexp Date: Tue, 18 Oct 2022 15:26:46 +0200 Message-Id: <20221018132654.3760561-4-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The precompiled buffer initialised in regcomp must be freed before leaving rte_trace_regexp. Fixes: 84c4fae4628f ("trace: implement operation APIs") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Jerin Jacob Acked-by: Sunil Kumar Kori --- Changes since v1: - split patch in two, keeping only the backportable fix as patch 3, --- lib/eal/common/eal_common_trace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index 1b86f5d2d2..1db11e3e14 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -218,8 +218,10 @@ rte_trace_regexp(const char *regex, bool enable) rc = rte_trace_point_disable(tp->handle); found = 1; } - if (rc < 0) - return rc; + if (rc < 0) { + found = 0; + break; + } } regfree(&r); From patchwork Tue Oct 18 13:26:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118419 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 38789A0560; Tue, 18 Oct 2022 15:27:38 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 002AC41181; Tue, 18 Oct 2022 15:27:29 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id B2ADC41181 for ; Tue, 18 Oct 2022 15:27:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099647; 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=5+vZBZbVbMe7Op4DbBhH7C8wiKZG00hQHiQCcH8cNms=; b=Qw+imnOPOK7LkaLw+EwrastA2O2H7s2tkAz6mlz1vwuY6cQ66E40oooCpzRirFwgB4TVNF nzUGVs04G8FwPZWIfTWU9kelv+pMQx9i7CPVbO3beqJc5BHeNVQyhpGFFIKM2PYViVVERf qA0X4zBH/WDu9a8UvTPkMGOZczwndnU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-186-qxm1DB1pPqqCp1cEeKjVCw-1; Tue, 18 Oct 2022 09:27:24 -0400 X-MC-Unique: qxm1DB1pPqqCp1cEeKjVCw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF81F811E87; Tue, 18 Oct 2022 13:27:23 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 312E3C1908A; Tue, 18 Oct 2022 13:27:23 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com Subject: [PATCH v4 04/11] trace: rework loop on trace points Date: Tue, 18 Oct 2022 15:26:47 +0200 Message-Id: <20221018132654.3760561-5-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Directly skip the block when a trace point does not match the user criteria. Signed-off-by: David Marchand Acked-by: Jerin Jacob Acked-by: Sunil Kumar Kori --- lib/eal/common/eal_common_trace.c | 34 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index 1db11e3e14..6b8660c318 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -186,15 +186,18 @@ rte_trace_pattern(const char *pattern, bool enable) int rc = 0, found = 0; STAILQ_FOREACH(tp, &tp_list, next) { - if (fnmatch(pattern, tp->name, 0) == 0) { - if (enable) - rc = rte_trace_point_enable(tp->handle); - else - rc = rte_trace_point_disable(tp->handle); - found = 1; + if (fnmatch(pattern, tp->name, 0) != 0) + continue; + + if (enable) + rc = rte_trace_point_enable(tp->handle); + else + rc = rte_trace_point_disable(tp->handle); + if (rc < 0) { + found = 0; + break; } - if (rc < 0) - return rc; + found = 1; } return rc | found; @@ -211,17 +214,18 @@ rte_trace_regexp(const char *regex, bool enable) return -EINVAL; STAILQ_FOREACH(tp, &tp_list, next) { - if (regexec(&r, tp->name, 0, NULL, 0) == 0) { - if (enable) - rc = rte_trace_point_enable(tp->handle); - else - rc = rte_trace_point_disable(tp->handle); - found = 1; - } + if (regexec(&r, tp->name, 0, NULL, 0) != 0) + continue; + + if (enable) + rc = rte_trace_point_enable(tp->handle); + else + rc = rte_trace_point_disable(tp->handle); if (rc < 0) { found = 0; break; } + found = 1; } regfree(&r); From patchwork Tue Oct 18 13:26:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118420 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 591C7A0560; Tue, 18 Oct 2022 15:27:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D0E78427EA; Tue, 18 Oct 2022 15:27:32 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 57FFE40E03 for ; Tue, 18 Oct 2022 15:27:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099650; 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=e4Tygx5p9+Fa4LrCghuMiU/eNiplWQc4UBewimcT8+Y=; b=PxRvrcNlPVjQ9kCuL38jT7xSlDBSZ6nTxhsskGWmU1G8H1PksAgkEKE0yfqbdCbf7EBWbR /m0JrFZQrnfbpKfOzC5foyrs9aaEQO/gn/pVis2y2RMRCZHMzqp60dtSWMPE0XfxFmWUqO zO9RrWtCHvH9fMNAIqqjFDsGce3KaSk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-228--xWQKE1tPoKJihLaedwexw-1; Tue, 18 Oct 2022 09:27:27 -0400 X-MC-Unique: -xWQKE1tPoKJihLaedwexw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 840961C05AC1; Tue, 18 Oct 2022 13:27:27 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68F92492B0A; Tue, 18 Oct 2022 13:27:26 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com, stable@dpdk.org Subject: [PATCH v4 05/11] trace: fix dynamically enabling trace points Date: Tue, 18 Oct 2022 15:26:48 +0200 Message-Id: <20221018132654.3760561-6-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Enabling trace points at runtime was not working if no trace point had been enabled first at rte_eal_init() time. The reason was that trace.args reflected the arguments passed to --trace= EAL option. To fix this: - the trace subsystem initialisation is updated: trace directory creation is deferred to when traces are dumped (to avoid creating directories that may not be used), - per lcore memory allocation still relies on rte_trace_is_enabled() but this helper now tracks if any trace point is enabled. The documentation is updated accordingly, - cleanup helpers must always be called in rte_eal_cleanup() since some trace points might have been enabled and disabled in the lifetime of the DPDK application, With this fix, we can update the unit test and check that a trace point callback is invoked when expected. Note: - the 'trace' global variable might be shadowed with the argument passed to the functions dealing with trace point handles. 'tp' has been used for referring to trace_point object. Prefer 't' for referring to handles, Fixes: 84c4fae4628f ("trace: implement operation APIs") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Sunil Kumar Kori --- Changes since v1: - restored level to INFO for trace directory log message, - moved trace_mkdir() to rte_trace_save, --- app/test/test_trace.c | 20 ++++++++++ app/test/test_trace.h | 2 + doc/guides/prog_guide/trace_lib.rst | 14 +++++-- lib/eal/common/eal_common_trace.c | 53 ++++++++++--------------- lib/eal/common/eal_common_trace_utils.c | 11 ++++- lib/eal/common/eal_trace.h | 3 +- 6 files changed, 65 insertions(+), 38 deletions(-) diff --git a/app/test/test_trace.c b/app/test/test_trace.c index 44ac38a4fa..2660f52f1d 100644 --- a/app/test/test_trace.c +++ b/app/test/test_trace.c @@ -9,6 +9,8 @@ #include "test.h" #include "test_trace.h" +int app_dpdk_test_tp_count; + #ifdef RTE_EXEC_ENV_WINDOWS static int @@ -95,8 +97,15 @@ test_trace_point_regex(void) static int32_t test_trace_point_disable_enable(void) { + int expected; int rc; + /* At tp registration, the associated counter increases once. */ + expected = 1; + TEST_ASSERT_EQUAL(app_dpdk_test_tp_count, expected, + "Expecting %d, but got %d for app_dpdk_test_tp_count", + expected, app_dpdk_test_tp_count); + rc = rte_trace_point_disable(&__app_dpdk_test_tp); if (rc < 0) goto failed; @@ -104,6 +113,12 @@ test_trace_point_disable_enable(void) if (rte_trace_point_is_enabled(&__app_dpdk_test_tp)) goto failed; + /* No emission expected */ + app_dpdk_test_tp("app.dpdk.test.tp"); + TEST_ASSERT_EQUAL(app_dpdk_test_tp_count, expected, + "Expecting %d, but got %d for app_dpdk_test_tp_count", + expected, app_dpdk_test_tp_count); + rc = rte_trace_point_enable(&__app_dpdk_test_tp); if (rc < 0) goto failed; @@ -113,6 +128,11 @@ test_trace_point_disable_enable(void) /* Emit the trace */ app_dpdk_test_tp("app.dpdk.test.tp"); + expected++; + TEST_ASSERT_EQUAL(app_dpdk_test_tp_count, expected, + "Expecting %d, but got %d for app_dpdk_test_tp_count", + expected, app_dpdk_test_tp_count); + return TEST_SUCCESS; failed: diff --git a/app/test/test_trace.h b/app/test/test_trace.h index 413842f60d..4ad44e2bea 100644 --- a/app/test/test_trace.h +++ b/app/test/test_trace.h @@ -3,10 +3,12 @@ */ #include +extern int app_dpdk_test_tp_count; RTE_TRACE_POINT( app_dpdk_test_tp, RTE_TRACE_POINT_ARGS(const char *str), rte_trace_point_emit_string(str); + app_dpdk_test_tp_count++; ) RTE_TRACE_POINT_FP( diff --git a/doc/guides/prog_guide/trace_lib.rst b/doc/guides/prog_guide/trace_lib.rst index fbadf9fde9..9a8f38073d 100644 --- a/doc/guides/prog_guide/trace_lib.rst +++ b/doc/guides/prog_guide/trace_lib.rst @@ -271,10 +271,16 @@ Trace memory The trace memory will be allocated through an internal function ``__rte_trace_mem_per_thread_alloc()``. The trace memory will be allocated per thread to enable lock less trace-emit function. -The memory for the trace memory for DPDK lcores will be allocated on -``rte_eal_init()`` if the trace is enabled through a EAL option. -For non DPDK threads, on the first trace emission, the memory will be -allocated. + +For non lcore threads, the trace memory is allocated on the first trace +emission. + +For lcore threads, if trace points are enabled through a EAL option, the trace +memory is allocated when the threads are known of DPDK +(``rte_eal_init`` for EAL lcores, ``rte_thread_register`` for non-EAL lcores). +Otherwise, when trace points are enabled later in the life of the application, +the behavior is the same as non lcore threads and the trace memory is allocated +on the first trace emission. Trace memory layout ~~~~~~~~~~~~~~~~~~~ diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index 6b8660c318..6aa11a3b50 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -48,12 +48,6 @@ eal_trace_init(void) goto fail; } - if (!STAILQ_EMPTY(&trace.args)) - trace.status = true; - - if (!rte_trace_is_enabled()) - return 0; - rte_spinlock_init(&trace.lock); /* Is duplicate trace name registered */ @@ -72,13 +66,9 @@ eal_trace_init(void) if (trace_metadata_create() < 0) goto fail; - /* Create trace directory */ - if (trace_mkdir()) - goto free_meta; - /* Save current epoch timestamp for future use */ if (trace_epoch_time_save() < 0) - goto fail; + goto free_meta; /* Apply global configurations */ STAILQ_FOREACH(arg, &trace.args, next) @@ -98,8 +88,6 @@ eal_trace_init(void) void eal_trace_fini(void) { - if (!rte_trace_is_enabled()) - return; trace_mem_free(); trace_metadata_destroy(); eal_trace_args_free(); @@ -108,17 +96,17 @@ eal_trace_fini(void) bool rte_trace_is_enabled(void) { - return trace.status; + return __atomic_load_n(&trace.status, __ATOMIC_ACQUIRE) != 0; } static void -trace_mode_set(rte_trace_point_t *trace, enum rte_trace_mode mode) +trace_mode_set(rte_trace_point_t *t, enum rte_trace_mode mode) { if (mode == RTE_TRACE_MODE_OVERWRITE) - __atomic_and_fetch(trace, ~__RTE_TRACE_FIELD_ENABLE_DISCARD, + __atomic_and_fetch(t, ~__RTE_TRACE_FIELD_ENABLE_DISCARD, __ATOMIC_RELEASE); else - __atomic_or_fetch(trace, __RTE_TRACE_FIELD_ENABLE_DISCARD, + __atomic_or_fetch(t, __RTE_TRACE_FIELD_ENABLE_DISCARD, __ATOMIC_RELEASE); } @@ -146,36 +134,42 @@ trace_point_is_invalid(rte_trace_point_t *t) } bool -rte_trace_point_is_enabled(rte_trace_point_t *trace) +rte_trace_point_is_enabled(rte_trace_point_t *t) { uint64_t val; - if (trace_point_is_invalid(trace)) + if (trace_point_is_invalid(t)) return false; - val = __atomic_load_n(trace, __ATOMIC_ACQUIRE); + val = __atomic_load_n(t, __ATOMIC_ACQUIRE); return (val & __RTE_TRACE_FIELD_ENABLE_MASK) != 0; } int -rte_trace_point_enable(rte_trace_point_t *trace) +rte_trace_point_enable(rte_trace_point_t *t) { - if (trace_point_is_invalid(trace)) + uint64_t prev; + + if (trace_point_is_invalid(t)) return -ERANGE; - __atomic_or_fetch(trace, __RTE_TRACE_FIELD_ENABLE_MASK, - __ATOMIC_RELEASE); + prev = __atomic_fetch_or(t, __RTE_TRACE_FIELD_ENABLE_MASK, __ATOMIC_RELEASE); + if ((prev & __RTE_TRACE_FIELD_ENABLE_MASK) == 0) + __atomic_add_fetch(&trace.status, 1, __ATOMIC_RELEASE); return 0; } int -rte_trace_point_disable(rte_trace_point_t *trace) +rte_trace_point_disable(rte_trace_point_t *t) { - if (trace_point_is_invalid(trace)) + uint64_t prev; + + if (trace_point_is_invalid(t)) return -ERANGE; - __atomic_and_fetch(trace, ~__RTE_TRACE_FIELD_ENABLE_MASK, - __ATOMIC_RELEASE); + prev = __atomic_fetch_and(t, ~__RTE_TRACE_FIELD_ENABLE_MASK, __ATOMIC_RELEASE); + if ((prev & __RTE_TRACE_FIELD_ENABLE_MASK) != 0) + __atomic_sub_fetch(&trace.status, 1, __ATOMIC_RELEASE); return 0; } @@ -417,9 +411,6 @@ trace_mem_free(void) struct trace *trace = trace_obj_get(); uint32_t count; - if (!rte_trace_is_enabled()) - return; - rte_spinlock_lock(&trace->lock); for (count = 0; count < trace->nb_trace_mem_list; count++) { trace_mem_per_thread_free_unlocked(&trace->lcore_meta[count]); diff --git a/lib/eal/common/eal_common_trace_utils.c b/lib/eal/common/eal_common_trace_utils.c index 2b55dbec65..7bf1c05e12 100644 --- a/lib/eal/common/eal_common_trace_utils.c +++ b/lib/eal/common/eal_common_trace_utils.c @@ -314,14 +314,18 @@ trace_dir_default_path_get(char *dir_path) return 0; } -int +static int trace_mkdir(void) { struct trace *trace = trace_obj_get(); char session[TRACE_DIR_STR_LEN]; + static bool already_done; char *dir_path; int rc; + if (already_done) + return 0; + if (!trace->dir_offset) { dir_path = calloc(1, sizeof(trace->dir)); if (dir_path == NULL) { @@ -365,6 +369,7 @@ trace_mkdir(void) } RTE_LOG(INFO, EAL, "Trace dir: %s\n", trace->dir); + already_done = true; return 0; } @@ -434,6 +439,10 @@ rte_trace_save(void) if (trace->nb_trace_mem_list == 0) return rc; + rc = trace_mkdir(); + if (rc < 0) + return rc; + rc = trace_meta_save(trace); if (rc) return rc; diff --git a/lib/eal/common/eal_trace.h b/lib/eal/common/eal_trace.h index 06751eb23a..72a5a461ae 100644 --- a/lib/eal/common/eal_trace.h +++ b/lib/eal/common/eal_trace.h @@ -54,7 +54,7 @@ struct trace { char dir[PATH_MAX]; int dir_offset; int register_errno; - bool status; + uint32_t status; enum rte_trace_mode mode; rte_uuid_t uuid; uint32_t buff_len; @@ -104,7 +104,6 @@ void trace_uuid_generate(void); int trace_metadata_create(void); void trace_metadata_destroy(void); char *trace_metadata_fixup_field(const char *field); -int trace_mkdir(void); int trace_epoch_time_save(void); void trace_mem_free(void); void trace_mem_per_thread_free(void); From patchwork Tue Oct 18 13:26:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118421 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EF921A0560; Tue, 18 Oct 2022 15:27:52 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5F358427F1; Tue, 18 Oct 2022 15:27:36 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id AFEBD4021D for ; Tue, 18 Oct 2022 15:27:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099655; 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=5ynMAnByq7XDX62C4ZyybGA61qKzHf/nii7efk5nEvc=; b=GhO4vGAwkyzlADXJOmfgYbab96wvRkWtib71QHU8n+Zjgqbb0atXvqB3dO0QBFrUlht+aI ZxakDjaOiSQg5aDAIowain/S3X+OTmoSPvw8Dk3DaV8PA7I6dFujNRsL5jdduy9FvIq7Lq fV8llVnoK8u1o40GX6Xh/1OD1kRTpwY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-C2ogG44NP3iOaC1AHFjrUw-1; Tue, 18 Oct 2022 09:27:31 -0400 X-MC-Unique: C2ogG44NP3iOaC1AHFjrUw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4136811E81; Tue, 18 Oct 2022 13:27:30 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1F5B2166B41; Tue, 18 Oct 2022 13:27:29 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com, stable@dpdk.org Subject: [PATCH v4 06/11] trace: fix race in debug dump Date: Tue, 18 Oct 2022 15:26:49 +0200 Message-Id: <20221018132654.3760561-7-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org trace->nb_trace_mem_list access must be under trace->lock to avoid races with threads allocating/freeing their trace buffers. Fixes: f6b2d65dcd5d ("trace: implement debug dump") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Jerin Jacob Acked-by: Sunil Kumar Kori --- lib/eal/common/eal_common_trace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index 6aa11a3b50..ec168e37b3 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -259,10 +259,9 @@ trace_lcore_mem_dump(FILE *f) struct __rte_trace_header *header; uint32_t count; - if (trace->nb_trace_mem_list == 0) - return; - rte_spinlock_lock(&trace->lock); + if (trace->nb_trace_mem_list == 0) + goto out; fprintf(f, "nb_trace_mem_list = %d\n", trace->nb_trace_mem_list); fprintf(f, "\nTrace mem info\n--------------\n"); for (count = 0; count < trace->nb_trace_mem_list; count++) { @@ -273,6 +272,7 @@ trace_lcore_mem_dump(FILE *f) header->stream_header.lcore_id, header->stream_header.thread_name); } +out: rte_spinlock_unlock(&trace->lock); } From patchwork Tue Oct 18 13:26:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118422 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D8000A0560; Tue, 18 Oct 2022 15:27:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 975494280E; Tue, 18 Oct 2022 15:27:39 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id E27D14282F for ; Tue, 18 Oct 2022 15:27:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099657; 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=yAnb8nAy0I8jLxTXVVkYpc9Z3EH50hkfLpL1EZ5BU+w=; b=RcO2F250OIisv3pTxZPLmuqyUH34a7vWhBqpfLF11oSpJO0sqlaZrKCyUNizY9P4lnlghc wPJCBg8HKvUu26NCLpGOrZ7c9aMEtL9F02A3Ub1GBlSWJGyY/0C8rk8Z9SXPkabupW/gwM 20PRb81ycLDshkG842VTVXgKrhLsOrA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-625-l5riyRABOfK5EBjp2fAnlg-1; Tue, 18 Oct 2022 09:27:34 -0400 X-MC-Unique: l5riyRABOfK5EBjp2fAnlg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8AF973C0218E; Tue, 18 Oct 2022 13:27:33 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C93C49BB62; Tue, 18 Oct 2022 13:27:32 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com, stable@dpdk.org Subject: [PATCH v4 07/11] trace: fix metadata dump Date: Tue, 18 Oct 2022 15:26:50 +0200 Message-Id: <20221018132654.3760561-8-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The API does not describe that metadata dump is conditioned to enabling any trace points. While at it, merge dump unit tests into the generic trace_autotest to enhance coverage. Fixes: f6b2d65dcd5d ("trace: implement debug dump") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Sunil Kumar Kori --- app/test/test_trace.c | 44 +++++++++------------------ lib/eal/common/eal_common_trace_ctf.c | 3 -- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/app/test/test_trace.c b/app/test/test_trace.c index 2660f52f1d..6bedf14024 100644 --- a/app/test/test_trace.c +++ b/app/test/test_trace.c @@ -20,20 +20,6 @@ test_trace(void) return TEST_SKIPPED; } -static int -test_trace_dump(void) -{ - printf("trace_dump not supported on Windows, skipping test\n"); - return TEST_SKIPPED; -} - -static int -test_trace_metadata_dump(void) -{ - printf("trace_metadata_dump not supported on Windows, skipping test\n"); - return TEST_SKIPPED; -} - #else static int32_t @@ -214,6 +200,19 @@ test_generic_trace_points(void) return TEST_SUCCESS; } +static int +test_trace_dump(void) +{ + rte_trace_dump(stdout); + return 0; +} + +static int +test_trace_metadata_dump(void) +{ + return rte_trace_metadata_dump(stdout); +} + static struct unit_test_suite trace_tests = { .suite_name = "trace autotest", .setup = NULL, @@ -226,6 +225,8 @@ static struct unit_test_suite trace_tests = { TEST_CASE(test_trace_point_globbing), TEST_CASE(test_trace_point_regex), TEST_CASE(test_trace_points_lookup), + TEST_CASE(test_trace_dump), + TEST_CASE(test_trace_metadata_dump), TEST_CASES_END() } }; @@ -236,21 +237,6 @@ test_trace(void) return unit_test_suite_runner(&trace_tests); } -static int -test_trace_dump(void) -{ - rte_trace_dump(stdout); - return 0; -} - -static int -test_trace_metadata_dump(void) -{ - return rte_trace_metadata_dump(stdout); -} - #endif /* !RTE_EXEC_ENV_WINDOWS */ REGISTER_TEST_COMMAND(trace_autotest, test_trace); -REGISTER_TEST_COMMAND(trace_dump, test_trace_dump); -REGISTER_TEST_COMMAND(trace_metadata_dump, test_trace_metadata_dump); diff --git a/lib/eal/common/eal_common_trace_ctf.c b/lib/eal/common/eal_common_trace_ctf.c index 335932a271..c6775c3b4d 100644 --- a/lib/eal/common/eal_common_trace_ctf.c +++ b/lib/eal/common/eal_common_trace_ctf.c @@ -358,9 +358,6 @@ rte_trace_metadata_dump(FILE *f) char *ctf_meta = trace->ctf_meta; int rc; - if (!rte_trace_is_enabled()) - return 0; - if (ctf_meta == NULL) return -EINVAL; From patchwork Tue Oct 18 13:26:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118423 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2830BA0560; Tue, 18 Oct 2022 15:28:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8C59E42B6D; Tue, 18 Oct 2022 15:27:40 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 68CD24282F for ; Tue, 18 Oct 2022 15:27:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099657; 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=pHG1F4tApwHwoNoWmHSx8adeLcq4BMh6DkIW7dJ/E2Q=; b=a+VS4SWrgFnDjK/MexPTCyybYJ2MBA62rBCJUSipVS1CocwKsk5CfANjd2rmZ7pA4bsyGT 1YGWWMt08SNo7Cc9t4+OsDTxFbgkh+5IHqG4eZTadDjCxHf3fzBAoujgprxVdMTCGOQcx6 vEoxujilLgimmpZVGfZQafYS0KhplAE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-606-waqZaFcbOGWiOL_2ZdFZ7g-1; Tue, 18 Oct 2022 09:27:36 -0400 X-MC-Unique: waqZaFcbOGWiOL_2ZdFZ7g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 838A5882823; Tue, 18 Oct 2022 13:27:36 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id B79CE4081B61; Tue, 18 Oct 2022 13:27:35 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com Subject: [PATCH v4 08/11] trace: remove limitation on trace point name Date: Tue, 18 Oct 2022 15:26:51 +0200 Message-Id: <20221018132654.3760561-9-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The name of a trace point is provided as a constant string via the RTE_TRACE_POINT_REGISTER macro. We can rely on an explicit 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 Acked-by: Jerin Jacob --- Changes since v2: - stored trace point name in a static variable to make sure the string is put in .data, --- lib/eal/common/eal_common_trace.c | 10 +++------- lib/eal/common/eal_common_trace_utils.c | 2 +- lib/eal/common/eal_trace.h | 3 +-- lib/eal/include/rte_trace_point_register.h | 3 ++- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index ec168e37b3..5caaac8e59 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -235,7 +235,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; @@ -492,10 +492,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. @@ -517,8 +514,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 7bf1c05e12..72108d36a6 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; }; diff --git a/lib/eal/include/rte_trace_point_register.h b/lib/eal/include/rte_trace_point_register.h index 2e61439940..a32f4d731b 100644 --- a/lib/eal/include/rte_trace_point_register.h +++ b/lib/eal/include/rte_trace_point_register.h @@ -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); \ } From patchwork Tue Oct 18 13:26:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118424 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A38D0A0560; Tue, 18 Oct 2022 15:28:09 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AF85E427FF; Tue, 18 Oct 2022 15:27:44 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 5561D41148 for ; Tue, 18 Oct 2022 15:27:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099662; 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=Z2QaB9ADAv5547IoLWyJC+0AJHp9QNfZSozJ/OEGY/U=; b=cmI69rmMYyvhnA/G7Cj/ow9rQ9wr+xK3rC1u+eRjHDSLG/7mdOVvYf/XEvTC6osBKl/0EI +nB6fkQaL3e9RQi51NfUwMqaiDOx5mkcd1rA2hu2mM/9VTqlJSp4UzICzrEccdv4wXAHPu myuL8oeDO2FOyOBWthHPMh7mAXIbbGY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-nK-fO98ON2mGwSYscajLsA-1; Tue, 18 Oct 2022 09:27:39 -0400 X-MC-Unique: nK-fO98ON2mGwSYscajLsA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58812811E81; Tue, 18 Oct 2022 13:27:39 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89090404787; Tue, 18 Oct 2022 13:27:38 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com Subject: [PATCH v4 09/11] trace: remove limitation on directory Date: Tue, 18 Oct 2022 15:26:52 +0200 Message-Id: <20221018132654.3760561-10-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Remove arbitrary limit on 12 characters of the file prefix used for the directory where to store the traces. Simplify the code by relying on dynamic allocations. Signed-off-by: David Marchand Acked-by: Jerin Jacob Acked-by: Sunil Kumar Kori --- lib/eal/common/eal_common_trace_utils.c | 68 +++++++++---------------- lib/eal/common/eal_trace.h | 5 +- 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/lib/eal/common/eal_common_trace_utils.c b/lib/eal/common/eal_common_trace_utils.c index 72108d36a6..8561a0e198 100644 --- a/lib/eal/common/eal_common_trace_utils.c +++ b/lib/eal/common/eal_common_trace_utils.c @@ -87,11 +87,11 @@ trace_uuid_generate(void) } static int -trace_session_name_generate(char *trace_dir) +trace_session_name_generate(char **trace_dir) { + char date[sizeof("YYYY-mm-dd-AM-HH-MM-SS")]; struct tm *tm_result; time_t tm; - int rc; tm = time(NULL); if ((int)tm == -1) @@ -101,38 +101,32 @@ trace_session_name_generate(char *trace_dir) if (tm_result == NULL) goto fail; - rc = rte_strscpy(trace_dir, eal_get_hugefile_prefix(), - TRACE_PREFIX_LEN); - if (rc == -E2BIG) - rc = TRACE_PREFIX_LEN - 1; - trace_dir[rc++] = '-'; - - rc = strftime(trace_dir + rc, TRACE_DIR_STR_LEN - rc, - "%Y-%m-%d-%p-%I-%M-%S", tm_result); - if (rc == 0) { + if (strftime(date, sizeof(date), "%Y-%m-%d-%p-%I-%M-%S", tm_result) == 0) { errno = ENOSPC; goto fail; } - return rc; + if (asprintf(trace_dir, "%s-%s", eal_get_hugefile_prefix(), date) == -1) + goto fail; + + return 0; fail: rte_errno = errno; - return -rte_errno; + return -1; } static int trace_dir_update(const char *str) { struct trace *trace = trace_obj_get(); - int rc, remaining; - - remaining = sizeof(trace->dir) - trace->dir_offset; - rc = rte_strscpy(&trace->dir[0] + trace->dir_offset, str, remaining); - if (rc < 0) - goto fail; + char *dir; + int rc; - trace->dir_offset += rc; -fail: + rc = asprintf(&dir, "%s%s", trace->dir != NULL ? trace->dir : "", str); + if (rc != -1) { + free(trace->dir); + trace->dir = dir; + } return rc; } @@ -246,22 +240,15 @@ eal_trace_mode_args_save(const char *val) int eal_trace_dir_args_save(char const *val) { - struct trace *trace = trace_obj_get(); char *dir_path; int rc; - if (strlen(val) >= sizeof(trace->dir) - 1) { - trace_err("input string is too big"); - return -ENAMETOOLONG; - } - if (asprintf(&dir_path, "%s/", val) == -1) { trace_err("failed to copy directory: %s", strerror(errno)); return -ENOMEM; } rc = trace_dir_update(dir_path); - free(dir_path); return rc; } @@ -289,10 +276,8 @@ trace_epoch_time_save(void) } static int -trace_dir_default_path_get(char *dir_path) +trace_dir_default_path_get(char **dir_path) { - struct trace *trace = trace_obj_get(); - uint32_t size = sizeof(trace->dir); struct passwd *pwd; char *home_dir; @@ -308,8 +293,8 @@ trace_dir_default_path_get(char *dir_path) } /* Append dpdk-traces to directory */ - if (snprintf(dir_path, size, "%s/dpdk-traces/", home_dir) < 0) - return -ENAMETOOLONG; + if (asprintf(dir_path, "%s/dpdk-traces/", home_dir) == -1) + return -ENOMEM; return 0; } @@ -318,25 +303,19 @@ static int trace_mkdir(void) { struct trace *trace = trace_obj_get(); - char session[TRACE_DIR_STR_LEN]; static bool already_done; - char *dir_path; + char *session; int rc; if (already_done) return 0; - if (!trace->dir_offset) { - dir_path = calloc(1, sizeof(trace->dir)); - if (dir_path == NULL) { - trace_err("fail to allocate memory"); - return -ENOMEM; - } + if (trace->dir == NULL) { + char *dir_path; - rc = trace_dir_default_path_get(dir_path); + rc = trace_dir_default_path_get(&dir_path); if (rc < 0) { trace_err("fail to get default path"); - free(dir_path); return rc; } @@ -354,10 +333,11 @@ trace_mkdir(void) return -rte_errno; } - rc = trace_session_name_generate(session); + rc = trace_session_name_generate(&session); if (rc < 0) return rc; rc = trace_dir_update(session); + free(session); if (rc < 0) return rc; diff --git a/lib/eal/common/eal_trace.h b/lib/eal/common/eal_trace.h index 26a18a2c48..d66bcfe198 100644 --- a/lib/eal/common/eal_trace.h +++ b/lib/eal/common/eal_trace.h @@ -22,8 +22,6 @@ #define trace_crit(fmt, args...) \ RTE_LOG(CRIT, EAL, "%s():%u " fmt "\n", __func__, __LINE__, ## args) -#define TRACE_PREFIX_LEN 12 -#define TRACE_DIR_STR_LEN (sizeof("YYYY-mm-dd-AM-HH-MM-SS") + TRACE_PREFIX_LEN) #define TRACE_CTF_MAGIC 0xC1FC1FC1 #define TRACE_MAX_ARGS 32 @@ -50,8 +48,7 @@ struct trace_arg { }; struct trace { - char dir[PATH_MAX]; - int dir_offset; + char *dir; int register_errno; uint32_t status; enum rte_trace_mode mode; From patchwork Tue Oct 18 13:26:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118425 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id ED970A0560; Tue, 18 Oct 2022 15:28:14 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3B7254282F; Tue, 18 Oct 2022 15:27:49 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 31D214282F for ; Tue, 18 Oct 2022 15:27:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099665; 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=X5KLhqXv8gZhoFg28Qbw1pIOMpKFEJP80YBRww2FGDU=; b=OeM781TGquPq9PtP6fZenFVUL8FnuCV7pQVpEMfvekGPPwgNBs4TOttL5fhWCayjo79qbR P0cg8CuV1CvUN0lD7qTGG0D51yc3wTzKv8Nog9DMuaVNYWq9wRdBmzcMVPB3qIpcvmE8KD YYmLbi7FeDbHC1ldWDkA8LapZRdzeEY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-480-zEGTqSL2OgqI6Q3N3FXXBw-1; Tue, 18 Oct 2022 09:27:42 -0400 X-MC-Unique: zEGTqSL2OgqI6Q3N3FXXBw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 503B2882820; Tue, 18 Oct 2022 13:27:42 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EA35492B0A; Tue, 18 Oct 2022 13:27:41 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com Subject: [PATCH v4 10/11] trace: create new directory for each trace dump Date: Tue, 18 Oct 2022 15:26:53 +0200 Message-Id: <20221018132654.3760561-11-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Rather than always overwrite the content of the trace directory, create new directories for each call to rte_trace_save(). In the unlikely event that multiple rte_trace_save() gets called many times in a single second, try to suffix the name with a digit. Signed-off-by: David Marchand --- lib/eal/common/eal_common_trace.c | 7 ++ lib/eal/common/eal_common_trace_utils.c | 101 ++++++++++-------------- lib/eal/common/eal_trace.h | 2 + 3 files changed, 50 insertions(+), 60 deletions(-) diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index 5caaac8e59..42f2c28c23 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -66,6 +66,9 @@ eal_trace_init(void) if (trace_metadata_create() < 0) goto fail; + if (trace.rootdir == NULL && trace_dir_default_path_get() < 0) + goto free_meta; + /* Save current epoch timestamp for future use */ if (trace_epoch_time_save() < 0) goto free_meta; @@ -91,6 +94,10 @@ eal_trace_fini(void) trace_mem_free(); trace_metadata_destroy(); eal_trace_args_free(); + free(trace.rootdir); + trace.rootdir = NULL; + free(trace.dir); + trace.dir = NULL; } bool diff --git a/lib/eal/common/eal_common_trace_utils.c b/lib/eal/common/eal_common_trace_utils.c index 8561a0e198..c226313d61 100644 --- a/lib/eal/common/eal_common_trace_utils.c +++ b/lib/eal/common/eal_common_trace_utils.c @@ -87,9 +87,10 @@ trace_uuid_generate(void) } static int -trace_session_name_generate(char **trace_dir) +trace_dir_name_generate(char **trace_dir) { char date[sizeof("YYYY-mm-dd-AM-HH-MM-SS")]; + struct trace *trace = trace_obj_get(); struct tm *tm_result; time_t tm; @@ -106,7 +107,8 @@ trace_session_name_generate(char **trace_dir) goto fail; } - if (asprintf(trace_dir, "%s-%s", eal_get_hugefile_prefix(), date) == -1) + if (asprintf(trace_dir, "%s/%s-%s", trace->rootdir, + eal_get_hugefile_prefix(), date) == -1) goto fail; return 0; @@ -115,21 +117,6 @@ trace_session_name_generate(char **trace_dir) return -1; } -static int -trace_dir_update(const char *str) -{ - struct trace *trace = trace_obj_get(); - char *dir; - int rc; - - rc = asprintf(&dir, "%s%s", trace->dir != NULL ? trace->dir : "", str); - if (rc != -1) { - free(trace->dir); - trace->dir = dir; - } - return rc; -} - int eal_trace_args_save(const char *val) { @@ -240,17 +227,16 @@ eal_trace_mode_args_save(const char *val) int eal_trace_dir_args_save(char const *val) { - char *dir_path; - int rc; + struct trace *trace = trace_obj_get(); - if (asprintf(&dir_path, "%s/", val) == -1) { + free(trace->rootdir); + trace->rootdir = strdup(val); + if (trace->rootdir == NULL) { trace_err("failed to copy directory: %s", strerror(errno)); return -ENOMEM; } - rc = trace_dir_update(dir_path); - free(dir_path); - return rc; + return 0; } int @@ -275,9 +261,10 @@ trace_epoch_time_save(void) return 0; } -static int -trace_dir_default_path_get(char **dir_path) +int +trace_dir_default_path_get(void) { + struct trace *trace = trace_obj_get(); struct passwd *pwd; char *home_dir; @@ -293,7 +280,7 @@ trace_dir_default_path_get(char **dir_path) } /* Append dpdk-traces to directory */ - if (asprintf(dir_path, "%s/dpdk-traces/", home_dir) == -1) + if (asprintf(&trace->rootdir, "%s/dpdk-traces", home_dir) == -1) return -ENOMEM; return 0; @@ -303,53 +290,47 @@ static int trace_mkdir(void) { struct trace *trace = trace_obj_get(); - static bool already_done; - char *session; + unsigned int try; + char *trace_dir; int rc; - if (already_done) - return 0; - - if (trace->dir == NULL) { - char *dir_path; - - rc = trace_dir_default_path_get(&dir_path); - if (rc < 0) { - trace_err("fail to get default path"); - return rc; - } - - rc = trace_dir_update(dir_path); - free(dir_path); - if (rc < 0) - return rc; - } - /* Create the path if it t exist, no "mkdir -p" available here */ - rc = mkdir(trace->dir, 0700); + rc = mkdir(trace->rootdir, 0700); if (rc < 0 && errno != EEXIST) { - trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno)); + trace_err("mkdir %s failed [%s]", trace->rootdir, strerror(errno)); rte_errno = errno; return -rte_errno; } - rc = trace_session_name_generate(&session); + rc = trace_dir_name_generate(&trace_dir); if (rc < 0) return rc; - rc = trace_dir_update(session); - free(session); - if (rc < 0) - return rc; - - rc = mkdir(trace->dir, 0700); - if (rc < 0) { - trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno)); - rte_errno = errno; - return -rte_errno; + rc = mkdir(trace_dir, 0700); + if (rc == 0) + goto out; + + /* 1000 tries are definitely enough :-) */ + for (try = 1; try < 1000; try++) { + char *trace_dir_suffix; + + if (asprintf(&trace_dir_suffix, "%s.%u", trace_dir, try) == -1) + continue; + rc = mkdir(trace_dir_suffix, 0700); + if (rc == 0) { + free(trace_dir); + trace_dir = trace_dir_suffix; + goto out; + } + free(trace_dir_suffix); } + trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno)); + rte_errno = errno; + return -rte_errno; +out: + free(trace->dir); + trace->dir = trace_dir; RTE_LOG(INFO, EAL, "Trace dir: %s\n", trace->dir); - already_done = true; return 0; } diff --git a/lib/eal/common/eal_trace.h b/lib/eal/common/eal_trace.h index d66bcfe198..be9e1645a3 100644 --- a/lib/eal/common/eal_trace.h +++ b/lib/eal/common/eal_trace.h @@ -48,6 +48,7 @@ struct trace_arg { }; struct trace { + char *rootdir; char *dir; int register_errno; uint32_t status; @@ -100,6 +101,7 @@ void trace_uuid_generate(void); int trace_metadata_create(void); void trace_metadata_destroy(void); char *trace_metadata_fixup_field(const char *field); +int trace_dir_default_path_get(void); int trace_epoch_time_save(void); void trace_mem_free(void); void trace_mem_per_thread_free(void); From patchwork Tue Oct 18 13:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 118426 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 09375A0560; Tue, 18 Oct 2022 15:28:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6274D42B75; Tue, 18 Oct 2022 15:27:50 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 627F04282E for ; Tue, 18 Oct 2022 15:27:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666099666; 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=G/wH18kNG/C0vGROSlBhbSbOZYAY7/iDQo0HgegVbLI=; b=EhakHhqcFhiF3QXVJmtbLAz9/GU4hYX2P85r9M5+XA6cxrnqHR0Puj85B5zVbnTe1que0b caTSwr0LnJ8RHykrVfaBEppTQSqkogojqJyHY9wiNUTUK9I/LajLIyA9LD1KY1SpkXnBUE chEepf3u14aW3+D6Dzp3U4r3WQQgIOI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-615-vfc9uaO_OMe3Xe_IHCOpkw-1; Tue, 18 Oct 2022 09:27:45 -0400 X-MC-Unique: vfc9uaO_OMe3Xe_IHCOpkw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 69CE2882822; Tue, 18 Oct 2022 13:27:45 +0000 (UTC) Received: from localhost.localdomain (ovpn-192-244.brq.redhat.com [10.40.192.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BF912022C30; Tue, 18 Oct 2022 13:27:44 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: jerinj@marvell.com, skori@marvell.com, Bruce Richardson , Ciara Power Subject: [PATCH v4 11/11] trace: enable trace operations via telemetry Date: Tue, 18 Oct 2022 15:26:54 +0200 Message-Id: <20221018132654.3760561-12-david.marchand@redhat.com> In-Reply-To: <20221018132654.3760561-1-david.marchand@redhat.com> References: <20220921120359.2201131-1-david.marchand@redhat.com> <20221018132654.3760561-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Register telemetry commands to list and configure trace points and later save traces for a running DPDK application. Note: trace point names contain a '.', so the list of valid characters used in telemetry commands and dictionary keys has been extended. Example with testpmd running with two net/null ports (startup command from devtools/test-null.sh): --> /trace/list,lib.ethdev.* {"/trace/list": {"lib.ethdev.configure": "Disabled", "lib.ethdev.rxq.setup": "Disabled", "lib.ethdev.txq.setup": "Disabled", "lib.ethdev.start": "Disabled", "lib.ethdev.stop": "Disabled", "lib.ethdev.close": "Disabled", "lib.ethdev.rx.burst": "Disabled", "lib.ethdev.tx.burst": "Disabled"}} --> /trace/enable,lib.ethdev.st* {"/trace/enable": {"Count": 2}} --> /trace/enable,lib.ethdev.st* {"/trace/enable": {"Count": 0}} --> /trace/list,lib.ethdev.* {"/trace/list": {"lib.ethdev.configure": "Disabled", "lib.ethdev.rxq.setup": "Disabled", "lib.ethdev.txq.setup": "Disabled", "lib.ethdev.start": "Enabled", "lib.ethdev.stop": "Enabled", "lib.ethdev.close": "Disabled", "lib.ethdev.rx.burst": "Disabled", "lib.ethdev.tx.burst": "Disabled"}} testpmd> stop ... testpmd> port stop all ... testpmd> port start all ... testpmd> start ... --> /trace/save {"/trace/save": {"Status": "OK", "Path": ".../dpdk-traces/rte-2022-10-12-AM-10-51-48"}} $ babeltrace .../dpdk-traces/rte-2022-10-12-AM-10-51-48 [10:51:36.229878723] (+?.?????????) lib.ethdev.stop: { cpu_id = 0x0, name = "dpdk-testpmd" }, { port_id = 0x0, ret = 0 } [10:51:36.229880251] (+0.000001528) lib.ethdev.stop: { cpu_id = 0x0, name = "dpdk-testpmd" }, { port_id = 0x1, ret = 0 } [10:51:40.449359774] (+4.219479523) lib.ethdev.start: { cpu_id = 0x0, name = "dpdk-testpmd" }, { port_id = 0x0 } [10:51:40.449377877] (+0.000018103) lib.ethdev.start: { cpu_id = 0x0, name = "dpdk-testpmd" }, { port_id = 0x1 } --> /trace/disable,* {"/trace/disable": {"Count": 2}} Signed-off-by: David Marchand Acked-by: Jerin Jacob Acked-by: Bruce Richardson --- Changes since v1: - added a note in the documentation, --- doc/guides/prog_guide/trace_lib.rst | 39 +++++++++++++++ lib/eal/common/eal_common_trace.c | 78 +++++++++++++++++++++++++++++ lib/telemetry/telemetry_data.c | 1 + 3 files changed, 118 insertions(+) diff --git a/doc/guides/prog_guide/trace_lib.rst b/doc/guides/prog_guide/trace_lib.rst index 9a8f38073d..b7abf8e640 100644 --- a/doc/guides/prog_guide/trace_lib.rst +++ b/doc/guides/prog_guide/trace_lib.rst @@ -233,6 +233,45 @@ This section steps you through the details of generating trace and viewing it. babeltrace $HOME/dpdk-traces/rte-yyyy-mm-dd-[AP]M-hh-mm-ss/ +Configuring traces on a running DPDK application +------------------------------------------------ + +The DPDK trace library can be configured using the Telemetry interface. + +Examples:: + + --> /trace/list,lib.ethdev.* + {"/trace/list": {"lib.ethdev.configure": "Disabled", + "lib.ethdev.rxq.setup": "Disabled", + "lib.ethdev.txq.setup": "Disabled", + "lib.ethdev.start": "Disabled", + "lib.ethdev.stop": "Disabled", + "lib.ethdev.close": "Disabled", + "lib.ethdev.rx.burst": "Disabled", + "lib.ethdev.tx.burst": "Disabled"}} + + --> /trace/enable,lib.ethdev.st* + {"/trace/enable": {"Count": 2}} + --> /trace/enable,lib.ethdev.st* + {"/trace/enable": {"Count": 0}} + + --> /trace/list,lib.ethdev.* + {"/trace/list": {"lib.ethdev.configure": "Disabled", + "lib.ethdev.rxq.setup": "Disabled", + "lib.ethdev.txq.setup": "Disabled", + "lib.ethdev.start": "Enabled", + "lib.ethdev.stop": "Enabled", + "lib.ethdev.close": "Disabled", + "lib.ethdev.rx.burst": "Disabled", + "lib.ethdev.tx.burst": "Disabled"}} + + --> /trace/save + {"/trace/save": {"Status": "OK", + "Path": ".../dpdk-traces/rte-2022-10-12-AM-10-51-48"}} + +For more information on how to use the Telemetry interface, see +the :doc:`../howto/telemetry`. + Implementation details ---------------------- diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index 42f2c28c23..3c7c666269 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "eal_trace.h" @@ -528,3 +529,80 @@ __rte_trace_point_register(rte_trace_point_t *handle, const char *name, return -rte_errno; } + +static int +trace_telemetry_enable(const char *cmd __rte_unused, + const char *params, struct rte_tel_data *d) +{ + unsigned int count; + + if (params == NULL || strlen(params) == 0) + return -1; + rte_tel_data_start_dict(d); + count = __atomic_load_n(&trace.status, __ATOMIC_RELAXED); + rte_trace_pattern(params, true); + rte_tel_data_add_dict_int(d, "Count", + __atomic_load_n(&trace.status, __ATOMIC_RELAXED) - count); + return 0; + +} + +static int +trace_telemetry_disable(const char *cmd __rte_unused, + const char *params, struct rte_tel_data *d) +{ + unsigned int count; + + if (params == NULL || strlen(params) == 0) + return -1; + rte_tel_data_start_dict(d); + count = __atomic_load_n(&trace.status, __ATOMIC_RELAXED); + rte_trace_pattern(params, false); + rte_tel_data_add_dict_int(d, "Count", + count - __atomic_load_n(&trace.status, __ATOMIC_RELAXED)); + return 0; + +} + +static int +trace_telemetry_list(const char *cmd __rte_unused, + const char *params, struct rte_tel_data *d) +{ + struct trace_point *tp; + + rte_tel_data_start_dict(d); + STAILQ_FOREACH(tp, &tp_list, next) { + if (params != NULL && fnmatch(params, tp->name, 0) != 0) + continue; + + rte_tel_data_add_dict_string(d, tp->name, + rte_trace_point_is_enabled(tp->handle) ? "Enabled" : "Disabled"); + } + + return 0; +} + +static int +trace_telemetry_save(const char *cmd __rte_unused, + const char *params __rte_unused, struct rte_tel_data *d) +{ + struct trace *trace = trace_obj_get(); + + rte_tel_data_start_dict(d); + rte_tel_data_add_dict_string(d, "Status", rte_trace_save() == 0 ? "OK" : "KO"); + rte_tel_data_add_dict_string(d, "Path", trace->dir); + + return 0; +} + +RTE_INIT(trace_telemetry) +{ + rte_telemetry_register_cmd("/trace/enable", trace_telemetry_enable, + "Enable trace points matching the provided pattern. Parameters: string pattern."); + rte_telemetry_register_cmd("/trace/disable", trace_telemetry_disable, + "Disable trace points matching the provided pattern. Parameters: string pattern."); + rte_telemetry_register_cmd("/trace/list", trace_telemetry_list, + "List trace points. Parameters: string pattern."); + rte_telemetry_register_cmd("/trace/save", trace_telemetry_save, + "Save current traces. Takes no parameter."); +} diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c index 34366ecee3..5b319c18fb 100644 --- a/lib/telemetry/telemetry_data.c +++ b/lib/telemetry/telemetry_data.c @@ -106,6 +106,7 @@ valid_name(const char *name) ['a' ... 'z'] = 1, ['_'] = 1, ['/'] = 1, + ['.'] = 1, }; while (*name != '\0') { if ((size_t)*name >= RTE_DIM(allowed) || allowed[(int)*name] == 0)