From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 33782A09D3; Thu, 12 Nov 2020 17:45:14 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DF4BA569B; Thu, 12 Nov 2020 17:45:11 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 5647A4CA6 for ; Thu, 12 Nov 2020 17:45:10 +0100 (CET) IronPort-SDR: G23/uSTLGUK6mYrFQ0M1q8ocwyGohASsVuAcNjlVrUCFAFQG1C/2az/040PtYJ/SxtE1Iw+18y k8Jkj+jqvqXQ== X-IronPort-AV: E=McAfee;i="6000,8403,9803"; a="149611101" X-IronPort-AV: E=Sophos;i="5.77,472,1596524400"; d="scan'208";a="149611101" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Nov 2020 08:45:04 -0800 IronPort-SDR: Ju44MpBRuWl2ea3g9J3evTsUcmIebrRJkwuyc/Ie/nT7XKuI4ovrEMM3ZecspR96rqX4hmzun+ Grz1Pj9lj2aw== X-IronPort-AV: E=Sophos;i="5.77,472,1596524400"; d="scan'208";a="542323742" Received: from fyigit-mobl1.ger.corp.intel.com (HELO [10.213.194.206]) ([10.213.194.206]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Nov 2020 08:45:02 -0800 To: Jiawei Wang , wenzhuo.lu@intel.com, beilei.xing@intel.com, bernard.iremonger@intel.com, orika@nvidia.com, thomas@monjalon.net, rasland@nvidia.com Cc: dev@dpdk.org References: <1605170202-293829-1-git-send-email-jiaweiw@nvidia.com> From: Ferruh Yigit Message-ID: <1c967e7c-d929-2126-6efe-48c905588e65@intel.com> Date: Thu, 12 Nov 2020 16:44:58 +0000 MIME-Version: 1.0 In-Reply-To: <1605170202-293829-1-git-send-email-jiaweiw@nvidia.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] [PATCH] app/testpmd: fix testpmd packets dump overlapping 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" On 11/12/2020 8:36 AM, Jiawei Wang wrote: > When testpmd enabled the verbosity for the received packets, if two packets > was received at the same time, for example, sampling packet and normal > packet, the dump output of these packets may be overlapping due to multiple > core handled the multiple queues simultaneously. > Hi Jiawei, Is the problem observer only when having sampling? Do you observe the problem when multiple cores Rx? > The patch uses one string buffer that collects all the packet dump output > into this buffer and then printout it at last, that guarantee to printout > separately the dump output per packet. > > Fixes: d862c45 ("app/testpmd: move dumping packets to a separate function") > > Signed-off-by: Jiawei Wang > --- > app/test-pmd/util.c | 238 ++++++++++++++++++++++++++++++++++++++-------------- > 1 file changed, 177 insertions(+), 61 deletions(-) > > diff --git a/app/test-pmd/util.c b/app/test-pmd/util.c > index 649bf8f..47b75b0 100644 > --- a/app/test-pmd/util.c > +++ b/app/test-pmd/util.c > @@ -12,15 +12,20 @@ > #include > #include > #include > +#include > > #include "testpmd.h" > > -static inline void > -print_ether_addr(const char *what, const struct rte_ether_addr *eth_addr) > +#define MAX_STRING_LEN 8192 > + > +static inline int > +print_ether_addr(const char *what, const struct rte_ether_addr *eth_addr, > + char print_buf[], int buf_size) > { > char buf[RTE_ETHER_ADDR_FMT_SIZE]; > + > rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr); > - printf("%s%s", what, buf); > + return snprintf(print_buf, buf_size, "%s%s", what, buf); > } > > static inline bool > @@ -74,13 +79,18 @@ > uint32_t vx_vni; > const char *reason; > int dynf_index; > + int buf_size = MAX_STRING_LEN * nb_pkts; > + char print_buf[buf_size]; This is a large value to allocate from stack, specially with larger burst size. Allocating from heap is an option but it has a cost. So what do you think print per packet, instead of print per burst? This also prevents display latency of the packet log. > + int cur_len = 0; > > + memset(print_buf, 0, sizeof(print_buf)); > if (!nb_pkts) > return; > - printf("port %u/queue %u: %s %u packets\n", > - port_id, queue, > - is_rx ? "received" : "sent", > - (unsigned int) nb_pkts); > + cur_len += snprintf(print_buf + cur_len, buf_size - cur_len, > + "port %u/queue %u: %s %u packets\n", > + port_id, queue, > + is_rx ? "received" : "sent", > + (unsigned int) nb_pkts); > for (i = 0; i < nb_pkts; i++) { > int ret; > struct rte_flow_error error; > @@ -93,95 +103,183 @@ > is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type); > ret = rte_flow_get_restore_info(port_id, mb, &info, &error); > if (!ret) { > - printf("restore info:"); > + cur_len += snprintf(print_buf + cur_len, > + buf_size - cur_len, > + "restore info:"); This is not safe. 'snprintf' returns size of the required buffer size, not written chars, this can make "buf_size - cur_len" a negative value at some point, and since 'size' type is unsigned negative value will be converted into a very large number and this will corrupt the stack. <...> > + if (cur_len >= buf_size) > + TESTPMD_LOG(ERR, "no enough buffer (size: %d) to store " > + "the current dump output (size: %d)\n", > + buf_size, cur_len); Instead of this error log, which I believe not very useful, why not append some chars at the end of the actual buffer to say it is truncated, something like if (truncated) TESTPMD_LOG(INFO, "%s ...", print_buf); else TESTPMD_LOG(INFO, "%s", print_buf);