From patchwork Thu Sep 21 04:23:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 131755 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 E974E42602; Thu, 21 Sep 2023 06:24:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 532E1402DD; Thu, 21 Sep 2023 06:24:05 +0200 (CEST) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id 9116B4014F for ; Thu, 21 Sep 2023 06:24:02 +0200 (CEST) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-691c05bc5aaso149298b3a.2 for ; Wed, 20 Sep 2023 21:24:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1695270241; x=1695875041; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LsawYgUPNSz8KCXOkCvRdkh/dufEOeHsF/JSonH5eXU=; b=oHXNGT1Xz5BwInAX08J6fOlHw5b0ti34RS11BsWPymrguO9WZ7zRUnhI3wWYCUU0qt FPX8b65rNcmvHOpHbGLCQyOJTwLU3nHE1H/d5MajnRLL7TaQJg0H2EZQPceOVleRmHEV cYJnmfxf+FMDhIoP5VrQp5xhXFVNWwccR12sQq4v4zh4Kvs7l0/n20QqnMBIam6soXkZ cM/LTFTsi8cr0tvEetKE8vaw+e8cpqYRJlrJWs8sz4QSipB7CzEzolhiYxPrDJNg8VGB L1nZlSN1AXYvkVXGlWoAV9ibOy8qiJbZtWABsUR1VCEVPifqMAVevkW57IDv+IXTQNpk edOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695270241; x=1695875041; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LsawYgUPNSz8KCXOkCvRdkh/dufEOeHsF/JSonH5eXU=; b=ApkyInYlUHgoZ8wl8JU2lJPi1moHiKAFITkfcFg6z+eWHiiebHM75Qb3BmZDTQvRXt IR3139vKaRx8o6jncXmPBd05vhnSojIEncqs4FzMfc2Cx1cUdE1nqkL79NObDYsxnWm4 DQlKWG3AeCBITigCV1tR72r+9qzx5DyQhQBV+IvABoGjdA9QpbKK61yhNMlvczzrxywN uy7LiNIoiKBDUj2r/sARC53qLkWYfNew/aYFoOKthtXLTQ348q3i91CxzaLKaVQgavWF 7ko5YsuC1d2AbSByxZoCER5DMO0FI8C5YuEVWrh7qd+V/2WBUczC0gPb1HA8goZHaU8j zvmQ== X-Gm-Message-State: AOJu0YzAh4PQclc4XjGmuIg10QHtuy5USw/gVjOuSnaeKLNdMZBVxtET HNuR62ZURdGyVVAy6fUzepMoI9lrcTWzveugVhM= X-Google-Smtp-Source: AGHT+IEIizz1mhZ0/128MZBtPPGAx6fi389FJ7slcJq4TaMDpywsk3KZhmXPSRx3GeMs1CHhbgxW5w== X-Received: by 2002:a05:6a21:3399:b0:145:47af:57d8 with SMTP id yy25-20020a056a21339900b0014547af57d8mr5068803pzb.2.1695270241257; Wed, 20 Sep 2023 21:24:01 -0700 (PDT) Received: from hermes.local (204-195-112-131.wavecable.com. [204.195.112.131]) by smtp.gmail.com with ESMTPSA id u5-20020aa78485000000b00690d1269691sm311946pfn.22.2023.09.20.21.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 21:24:00 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan , Jianfeng Tan Subject: [PATCH 1/4] pdump: fix setting rte_errno on mp error Date: Wed, 20 Sep 2023 21:23:46 -0700 Message-Id: <20230921042349.104150-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230921042349.104150-1-stephen@networkplumber.org> References: <20230921042349.104150-1-stephen@networkplumber.org> MIME-Version: 1.0 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 response from MP server sets err_value to negative on error. The convention for rte_errno is to use a positive value on error. This makes errors like duplicate registration show up with the correct error value. Fixes: 660098d61f57 ("pdump: use generic multi-process channel") Signed-off-by: Stephen Hemminger --- lib/pdump/rte_pdump.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/pdump/rte_pdump.c b/lib/pdump/rte_pdump.c index 53cca1034d41..a70085bd0211 100644 --- a/lib/pdump/rte_pdump.c +++ b/lib/pdump/rte_pdump.c @@ -564,9 +564,10 @@ pdump_prepare_client_request(const char *device, uint16_t queue, if (rte_mp_request_sync(&mp_req, &mp_reply, &ts) == 0) { mp_rep = &mp_reply.msgs[0]; resp = (struct pdump_response *)mp_rep->param; - rte_errno = resp->err_value; - if (!resp->err_value) + if (resp->err_value == 0) ret = 0; + else + rte_errno = -resp->err_value; free(mp_reply.msgs); } From patchwork Thu Sep 21 04:23:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 131756 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 BD4AB425DC; Thu, 21 Sep 2023 06:24:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9019E402E8; Thu, 21 Sep 2023 06:24:06 +0200 (CEST) Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mails.dpdk.org (Postfix) with ESMTP id 4D3BC402CE for ; Thu, 21 Sep 2023 06:24:03 +0200 (CEST) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6910ea9cddbso259637b3a.0 for ; Wed, 20 Sep 2023 21:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1695270242; x=1695875042; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=omUtTH7y7VOw30b39TLXxrqp0tKrYGDXycHE1fkYinQ=; b=rJLMBbB1H5LQO+r0wuC8nKj7od6VtOki4ZDXRBA5j10R2PGioalxdr7osn3RAt/i1v 67JyHXmU73qzanpsfY2v1FogbR5ogvEwAF9UCyYIcgy6y+b7Vhjwcn419Xo87gye4FYo ckJlEBEZGkpMR3bjBX1SN6ZvE1F0NeukSuaE0+L8GvD3y6tUmZ2oR+z/rMq9v16ctbo8 uOaFWtonZ0M+DY6hXNsVUcjH0RH/1eJ3cej6th7yU/mxuutko0z6KZiZ/1PG0H/HxZgc giYh5iwwaVD1JlqmJHCu348aFhbtEk9gd4BZj6vjGavLe9KMtP2eWsFQJH6oBGH3rQZ7 qurQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695270242; x=1695875042; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=omUtTH7y7VOw30b39TLXxrqp0tKrYGDXycHE1fkYinQ=; b=InGmFVgzlcMKimQ3eyCNm/JVG/f7n8jkc/ZDapJR+WQ2lgIvOVap6JX1wgfDSEKYRp Q8BJvfyVBsSKyPAxHDr/5vSuUDeLRxjcwO23/0pGOVdI41V3IlYS91TYaxLq9/0AqtVW IdtP/or8ltx6FiUS6nMcTa0IUvCA5bqthCcdQHHxxm1L8fxc+eW3MIbJjg+sl+/Oss5y BUumGXq5j9Y8fGXg/w9sqBegTtegBDYWYZOG8pdSPu/gB2D04fqTYXe9tUmmWbIIOBKv VieBetw4IXV2WxA6RbcgLrYLAm9VNvCNYWwO+Q7MeTLsLPyMdkWWgqVfWFrkI1riw2ND BW5g== X-Gm-Message-State: AOJu0YzW2wGHRRP5jWh67ZJAsJMQFtIq3XGOpwtD6F/2ELgSYbgokKvq 18iZpP2s6KFuW0h6ScSL1eGqqwj9XXF/a6Nle8I= X-Google-Smtp-Source: AGHT+IEKsdjJJqTAIH0JcpiyktUBnbmP1vHf6lv5a+WTawQs3rr69XJUYLUYi8eMRKjz2EteMnZysg== X-Received: by 2002:a05:6a00:3697:b0:691:2d4:23b5 with SMTP id dw23-20020a056a00369700b0069102d423b5mr880811pfb.31.1695270242215; Wed, 20 Sep 2023 21:24:02 -0700 (PDT) Received: from hermes.local (204-195-112-131.wavecable.com. [204.195.112.131]) by smtp.gmail.com with ESMTPSA id u5-20020aa78485000000b00690d1269691sm311946pfn.22.2023.09.20.21.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 21:24:01 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Isaac Boukris , Reshma Pattan Subject: [PATCH 2/4] dumpcap: allow multiple invocations Date: Wed, 20 Sep 2023 21:23:47 -0700 Message-Id: <20230921042349.104150-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230921042349.104150-1-stephen@networkplumber.org> References: <20230921042349.104150-1-stephen@networkplumber.org> MIME-Version: 1.0 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 dumpcap is run twice with each instance pointing a different interface, it would fail because of overlap in ring a pool names. Fix by putting process id in the name. Fixes: cbb44143be74 ("app/dumpcap: add new packet capture application") Reported-by: Isaac Boukris Signed-off-by: Stephen Hemminger --- app/dumpcap/main.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index 64294bbfb3e6..37754fd06f4f 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -44,7 +44,6 @@ #include #include -#define RING_NAME "capture-ring" #define MONITOR_INTERVAL (500 * 1000) #define MBUF_POOL_CACHE_SIZE 32 #define BURST_SIZE 32 @@ -647,6 +646,7 @@ static void dpdk_init(void) static struct rte_ring *create_ring(void) { struct rte_ring *ring; + char ring_name[RTE_RING_NAMESIZE]; size_t size, log2; /* Find next power of 2 >= size. */ @@ -660,28 +660,28 @@ static struct rte_ring *create_ring(void) ring_size = size; } - ring = rte_ring_lookup(RING_NAME); - if (ring == NULL) { - ring = rte_ring_create(RING_NAME, ring_size, - rte_socket_id(), 0); - if (ring == NULL) - rte_exit(EXIT_FAILURE, "Could not create ring :%s\n", - rte_strerror(rte_errno)); - } + /* Want one ring per invocation of program */ + snprintf(ring_name, sizeof(ring_name), + "dumpcap-%u", getpid()); + + ring = rte_ring_create(ring_name, ring_size, + rte_socket_id(), 0); + if (ring == NULL) + rte_exit(EXIT_FAILURE, "Could not create ring :%s\n", + rte_strerror(rte_errno)); + return ring; } static struct rte_mempool *create_mempool(void) { const struct interface *intf; - static const char pool_name[] = "capture_mbufs"; + char pool_name[RTE_MEMPOOL_NAMESIZE]; size_t num_mbufs = 2 * ring_size; struct rte_mempool *mp; uint32_t data_size = 128; - mp = rte_mempool_lookup(pool_name); - if (mp) - return mp; + snprintf(pool_name, sizeof(pool_name), "capture_%u", getpid()); /* Common pool so size mbuf for biggest snap length */ TAILQ_FOREACH(intf, &interfaces, next) { @@ -826,7 +826,7 @@ static void enable_pdump(struct rte_ring *r, struct rte_mempool *mp) rte_exit(EXIT_FAILURE, "Packet dump enable on %u:%s failed %s\n", intf->port, intf->name, - rte_strerror(-ret)); + rte_strerror(rte_errno)); } if (intf->opts.promisc_mode) { From patchwork Thu Sep 21 04:23:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 131757 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 E46A8425DC; Thu, 21 Sep 2023 06:24:21 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D9971402EF; Thu, 21 Sep 2023 06:24:07 +0200 (CEST) Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by mails.dpdk.org (Postfix) with ESMTP id 52F47402DC for ; Thu, 21 Sep 2023 06:24:04 +0200 (CEST) Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3adba522a5dso349563b6e.2 for ; Wed, 20 Sep 2023 21:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1695270243; x=1695875043; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p0NhDTyyKLT95VSp9/es7oIgnq+8lH/taVTz4Dh8fHU=; b=EprrZGYmHBYX9323Z5S1nZ/dCz59dhHNbFSsyEt6RQv5avYinyxo+Cr3GhqXlIUhIg Dl81k85lFqp5uFa8jfYfPMr3nJn1fkZCzmFw8R4YnaFmsCw3piMM6JM6tZqgnScD7P0K BXY1334E4Jgzd1k5QAF3dGpw39DCzQK03v05UM++y2CUOcR/33FF5P95Rifw7cH/pdH2 Eob1zhrHimozo9geyBzk7PMussvcMoU2NMdB51PCRS7w62T3Ct4klZu5gpYAR7uNgry/ qR5OAJZBYv6gH1D+wU/qxyBAAGLRkJ7FIVZeNycURqLve71zg/PhtLjyRy3sh9wRp03A Zkog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695270243; x=1695875043; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p0NhDTyyKLT95VSp9/es7oIgnq+8lH/taVTz4Dh8fHU=; b=pRB7q/YZKWnH4vheUbjvU6Ds1aglvkv4IMmRZ+/DLVwa0KHxmtzUhU7ATqrvJTqaOX 4dJI+8RznzRMXMr8IqNOkjkKOHmr42CzDwlh+3B4IC4UeuBv/BLYwB/G7b+pQX2i3LwV opMujmQ2/A1QW1PgNlQhh2S7ebNN/l5Yg+f/ZpEZa93NJMg7Vszd6dGu1vsA6W4jwAlu 85sDYD2z7RH2nZTDXjUuO2CIgH7UXuRObrcheke66mcWz5Hzu7mbxGAq9NAn5wbhVxgC jPvvSSHApAxAkumJXUmmf9SCd7aopnT3nb8rxQK8xJApiSoqtTyYkIIJG6izw4OEWhGx COig== X-Gm-Message-State: AOJu0YwlxfIckWNqPzlq1Hnewh9icAG+5z8JE3VcypsfLARPenobCw0i LrPErYjUK+dT/xd1R2/jmxSs8ieOZ8l8vjxjHiM= X-Google-Smtp-Source: AGHT+IGRGDos73UNISTCxdURmPpe6ERGJGUMpna5r+vUV0KDxXZQPsNJkWM7XAQFeWvPj6pI1I1CZg== X-Received: by 2002:a05:6808:182:b0:3a7:215c:e37 with SMTP id w2-20020a056808018200b003a7215c0e37mr3989356oic.59.1695270243247; Wed, 20 Sep 2023 21:24:03 -0700 (PDT) Received: from hermes.local (204-195-112-131.wavecable.com. [204.195.112.131]) by smtp.gmail.com with ESMTPSA id u5-20020aa78485000000b00690d1269691sm311946pfn.22.2023.09.20.21.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 21:24:02 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH 3/4] pcapng: change timestamp argument to write_stats Date: Wed, 20 Sep 2023 21:23:48 -0700 Message-Id: <20230921042349.104150-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230921042349.104150-1-stephen@networkplumber.org> References: <20230921042349.104150-1-stephen@networkplumber.org> MIME-Version: 1.0 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 In order to cleanup the management of time base calculation, later patch will move the calculation from pcapng to the pdump library. One of the changes necessary is to move the timestamp calculation in the write_stats call from the pcapng library into the caller. Since dumpcap already does this for other timestamps the change is rather small. Signed-off-by: Stephen Hemminger --- app/dumpcap/main.c | 3 ++- app/test/test_pcapng.c | 4 ++-- lib/pcapng/rte_pcapng.c | 8 +++----- lib/pcapng/rte_pcapng.h | 5 ++++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index 37754fd06f4f..8f6ab3396cef 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -577,6 +577,7 @@ report_packet_stats(dumpcap_out_t out) struct rte_pdump_stats pdump_stats; struct interface *intf; uint64_t ifrecv, ifdrop; + uint64_t timestamp = create_timestamp(); double percent; fputc('\n', stderr); @@ -590,7 +591,7 @@ report_packet_stats(dumpcap_out_t out) if (use_pcapng) rte_pcapng_write_stats(out.pcapng, intf->port, NULL, - start_time, end_time, + timestamp, start_time, end_time, ifrecv, ifdrop); if (ifrecv == 0) diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c index b8429a02f160..55aa2cf93666 100644 --- a/app/test/test_pcapng.c +++ b/app/test/test_pcapng.c @@ -173,8 +173,8 @@ test_write_stats(void) ssize_t len; /* write a statistics block */ - len = rte_pcapng_write_stats(pcapng, port_id, - NULL, 0, 0, + len = rte_pcapng_write_stats(pcapng, port_id, NULL, + 0, 0, 0, NUM_PACKETS, 0); if (len <= 0) { fprintf(stderr, "Write of statistics failed\n"); diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c index 3c91fc77644a..ddce7bc87141 100644 --- a/lib/pcapng/rte_pcapng.c +++ b/lib/pcapng/rte_pcapng.c @@ -368,7 +368,7 @@ rte_pcapng_add_interface(rte_pcapng_t *self, uint16_t port, */ ssize_t rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port_id, - const char *comment, + const char *comment, uint64_t sample_time, uint64_t start_time, uint64_t end_time, uint64_t ifrecv, uint64_t ifdrop) { @@ -376,7 +376,6 @@ rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port_id, struct pcapng_option *opt; uint32_t optlen, len; uint8_t *buf; - uint64_t ns; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); @@ -425,9 +424,8 @@ rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port_id, hdr->block_length = len; hdr->interface_id = self->port_index[port_id]; - ns = pcapng_tsc_to_ns(rte_get_tsc_cycles()); - hdr->timestamp_hi = ns >> 32; - hdr->timestamp_lo = (uint32_t)ns; + hdr->timestamp_hi = sample_time >> 32; + hdr->timestamp_lo = (uint32_t)sample_time; /* clone block_length after option */ memcpy(opt, &len, sizeof(uint32_t)); diff --git a/lib/pcapng/rte_pcapng.h b/lib/pcapng/rte_pcapng.h index d93cc9f73ad5..1225ed5536ff 100644 --- a/lib/pcapng/rte_pcapng.h +++ b/lib/pcapng/rte_pcapng.h @@ -189,7 +189,9 @@ rte_pcapng_write_packets(rte_pcapng_t *self, * @param port * The Ethernet port to report stats on. * @param comment - * Optional comment to add to statistics. + * Optional comment to add to statistics. + * @param timestamp + * Time this statistic sample refers to in nanoseconds. * @param start_time * The time when packet capture was started in nanoseconds. * Optional: can be zero if not known. @@ -209,6 +211,7 @@ __rte_experimental ssize_t rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port, const char *comment, + uint64_t timestamp, uint64_t start_time, uint64_t end_time, uint64_t ifrecv, uint64_t ifdrop); From patchwork Thu Sep 21 04:23:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 131758 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 ECD51425DC; Thu, 21 Sep 2023 06:24:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 820AB4067B; Thu, 21 Sep 2023 06:24:09 +0200 (CEST) Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) by mails.dpdk.org (Postfix) with ESMTP id D0C20402E0 for ; Thu, 21 Sep 2023 06:24:05 +0200 (CEST) Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3ade1011f8cso368537b6e.0 for ; Wed, 20 Sep 2023 21:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1695270245; x=1695875045; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v9D23f4qgr4f2T2Rqt+XYQxDpkW7uq0g6x8hWZbE/U4=; b=CDNbPrS4+KXx9RCONK8FY7qDcN1dYGG/fPqsViYW6GA35zvv8yVku6UMmWn1irtmGE C+if6nB3hxtku+4siknAY138nVUU/CddNjqOPd0yKpaCYaKZd+uwc1jz37QeRszB9x38 ERBzhom8I2DjP4s3u4ShjPykxqv/a8Cyc3ZnwNnmIQyjmR+9IoqeO4CgFPaK0qp+UI4z 2FEt4TchXKXGOVwTKu32UL/yLHgNurHcueJAi7zUoRf69ADP6F02DrjqDnXAwI/hLg5r w5+BlEscZ8pxuOxXs4s4XWUZdQ1p6HO6TIA98Q60KRAYjML9MOI0xgQWR6v95tDxWF8u ATmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695270245; x=1695875045; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v9D23f4qgr4f2T2Rqt+XYQxDpkW7uq0g6x8hWZbE/U4=; b=Epg0JqvrFBR9Iat2qYWrAIb+38Kb7WCrnw4MTYmkWIRuZlwf7TFOQ/lwFsW7NlI/j8 3GPSZq+r3QBT80r1us0cJ1dhanAGKnlJkhZsQ15FxNWa+DIU1z2M+mX99Ief6xVK5uWX yREpGzodurE6trFgHGxhQIz9qaAqptfsPiiLXRE5LRUX+/nu8jp2uceqciaAyLrwD14V oo4Jis6pMKPsbEaXSmXziqtsaVOtwDM90PfuBJk1Vm+CwWV0tCURHry3qp3HPkAry98k 2KkOB3hfQScofyv3CgkFaWiXpb8nIhMvoWiYQywOe8pcbSfgWyyO+DzQbQXi3U2vXEUu m8mg== X-Gm-Message-State: AOJu0Yxk+ps1igR7K/sDVk8/a3ADDtsTsI5f4To0ncqxeoYXOeWHILCJ GOrte078m5g9C/QZ1+HKb5/14OlKv0r78h8w2gc= X-Google-Smtp-Source: AGHT+IHUvMo7kH1GvKMxHvk7tq4MfVlUDqvmk18WaclEGAhNRS+IBF5+HBsTvdj5rTXazSPfS7W8WQ== X-Received: by 2002:a05:6870:9a24:b0:1d6:439d:d03e with SMTP id fo36-20020a0568709a2400b001d6439dd03emr4796780oab.18.1695270244838; Wed, 20 Sep 2023 21:24:04 -0700 (PDT) Received: from hermes.local (204-195-112-131.wavecable.com. [204.195.112.131]) by smtp.gmail.com with ESMTPSA id u5-20020aa78485000000b00690d1269691sm311946pfn.22.2023.09.20.21.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 21:24:04 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan , Quentin Armitage Subject: [PATCH 4/4] pcapng: move timestamp calculation into pdump Date: Wed, 20 Sep 2023 21:23:49 -0700 Message-Id: <20230921042349.104150-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230921042349.104150-1-stephen@networkplumber.org> References: <20230921042349.104150-1-stephen@networkplumber.org> MIME-Version: 1.0 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 computation of timestamp is more easily done in pdump than pcapng. The initialization is easier and makes the pcapng library have no global state. It also makes it easier to add HW timestamp support later. Simplify the computation of nanoseconds from TSC to a two step process which avoids numeric overflow issues. The previous code was not thread safe as well. Fixes: c882eb544842 ("pcapng: fix timestamp wrapping in output files") Signed-off-by: Stephen Hemminger --- lib/pcapng/rte_pcapng.c | 71 ++--------------------------------------- lib/pcapng/rte_pcapng.h | 2 +- lib/pdump/rte_pdump.c | 56 +++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 74 deletions(-) diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c index ddce7bc87141..f6b3bd0ca718 100644 --- a/lib/pcapng/rte_pcapng.c +++ b/lib/pcapng/rte_pcapng.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include "pcapng_proto.h" @@ -43,15 +42,6 @@ struct rte_pcapng { uint32_t port_index[RTE_MAX_ETHPORTS]; }; -/* For converting TSC cycles to PCAPNG ns format */ -static struct pcapng_time { - uint64_t ns; - uint64_t cycles; - uint64_t tsc_hz; - struct rte_reciprocal_u64 tsc_hz_inverse; -} pcapng_time; - - #ifdef RTE_EXEC_ENV_WINDOWS /* * Windows does not have writev() call. @@ -102,58 +92,6 @@ static ssize_t writev(int fd, const struct iovec *iov, int iovcnt) #define if_indextoname(ifindex, ifname) NULL #endif -static inline void -pcapng_init(void) -{ - struct timespec ts; - - pcapng_time.cycles = rte_get_tsc_cycles(); - clock_gettime(CLOCK_REALTIME, &ts); - pcapng_time.cycles = (pcapng_time.cycles + rte_get_tsc_cycles()) / 2; - pcapng_time.ns = rte_timespec_to_ns(&ts); - - pcapng_time.tsc_hz = rte_get_tsc_hz(); - pcapng_time.tsc_hz_inverse = rte_reciprocal_value_u64(pcapng_time.tsc_hz); -} - -/* PCAPNG timestamps are in nanoseconds */ -static uint64_t pcapng_tsc_to_ns(uint64_t cycles) -{ - uint64_t delta, secs; - - if (!pcapng_time.tsc_hz) - pcapng_init(); - - /* In essence the calculation is: - * delta = (cycles - pcapng_time.cycles) * NSEC_PRE_SEC / rte_get_tsc_hz() - * but this overflows within 4 to 8 seconds depending on TSC frequency. - * Instead, if delta >= pcapng_time.tsc_hz: - * Increase pcapng_time.ns and pcapng_time.cycles by the number of - * whole seconds in delta and reduce delta accordingly. - * delta will therefore always lie in the interval [0, pcapng_time.tsc_hz), - * which will not overflow when multiplied by NSEC_PER_SEC provided the - * TSC frequency < approx 18.4GHz. - * - * Currently all TSCs operate below 5GHz. - */ - delta = cycles - pcapng_time.cycles; - if (unlikely(delta >= pcapng_time.tsc_hz)) { - if (likely(delta < pcapng_time.tsc_hz * 2)) { - delta -= pcapng_time.tsc_hz; - pcapng_time.cycles += pcapng_time.tsc_hz; - pcapng_time.ns += NSEC_PER_SEC; - } else { - secs = rte_reciprocal_divide_u64(delta, &pcapng_time.tsc_hz_inverse); - delta -= secs * pcapng_time.tsc_hz; - pcapng_time.cycles += secs * pcapng_time.tsc_hz; - pcapng_time.ns += secs * NSEC_PER_SEC; - } - } - - return pcapng_time.ns + rte_reciprocal_divide_u64(delta * NSEC_PER_SEC, - &pcapng_time.tsc_hz_inverse); -} - /* length of option including padding */ static uint16_t pcapng_optlen(uint16_t len) { @@ -518,7 +456,7 @@ struct rte_mbuf * rte_pcapng_copy(uint16_t port_id, uint32_t queue, const struct rte_mbuf *md, struct rte_mempool *mp, - uint32_t length, uint64_t cycles, + uint32_t length, uint64_t timestamp, enum rte_pcapng_direction direction, const char *comment) { @@ -527,14 +465,11 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, struct pcapng_option *opt; uint16_t optlen; struct rte_mbuf *mc; - uint64_t ns; bool rss_hash; #ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL); #endif - ns = pcapng_tsc_to_ns(cycles); - orig_len = rte_pktmbuf_pkt_len(md); /* Take snapshot of the data */ @@ -639,8 +574,8 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, /* Interface index is filled in later during write */ mc->port = port_id; - epb->timestamp_hi = ns >> 32; - epb->timestamp_lo = (uint32_t)ns; + epb->timestamp_hi = timestamp >> 32; + epb->timestamp_lo = (uint32_t)timestamp; epb->capture_length = data_len; epb->original_length = orig_len; diff --git a/lib/pcapng/rte_pcapng.h b/lib/pcapng/rte_pcapng.h index 1225ed5536ff..b9a9ee23ad1d 100644 --- a/lib/pcapng/rte_pcapng.h +++ b/lib/pcapng/rte_pcapng.h @@ -122,7 +122,7 @@ enum rte_pcapng_direction { * The upper limit on bytes to copy. Passing UINT32_MAX * means all data (after offset). * @param timestamp - * The timestamp in TSC cycles. + * The timestamp in nanoseconds since 1/1/1970. * @param direction * The direction of the packer: receive, transmit or unknown. * @param comment diff --git a/lib/pdump/rte_pdump.c b/lib/pdump/rte_pdump.c index a70085bd0211..384abf5e27ad 100644 --- a/lib/pdump/rte_pdump.c +++ b/lib/pdump/rte_pdump.c @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include #include #include "rte_pdump.h" @@ -78,6 +80,33 @@ static struct { const struct rte_memzone *mz; } *pdump_stats; +/* Time conversion values */ +static struct { + uint64_t offset_ns; /* ns since 1/1/1970 when initialized */ + uint64_t tsc_base; /* TSC when initialized */ + uint64_t tsc_hz; /* copy of rte_tsc_hz() */ + struct rte_reciprocal_u64 tsc_hz_inverse; /* inverse of tsc_hz */ +} pdump_time; + +/* Convert from TSC (CPU cycles) to nanoseconds */ +static uint64_t pdump_timestamp(void) +{ + uint64_t delta, secs, ns; + + delta = rte_get_tsc_cycles() - pdump_time.tsc_base; + + /* Avoid numeric wraparound by computing seconds first */ + secs = rte_reciprocal_divide_u64(delta, &pdump_time.tsc_hz_inverse); + + /* Remove the seconds portion */ + delta -= secs * pdump_time.tsc_hz; + ns = rte_reciprocal_divide_u64(delta * NS_PER_S, + &pdump_time.tsc_hz_inverse); + + return secs * NS_PER_S + ns + pdump_time.offset_ns; +} + + /* Create a clone of mbuf to be placed into ring. */ static void pdump_copy(uint16_t port_id, uint16_t queue, @@ -90,7 +119,7 @@ pdump_copy(uint16_t port_id, uint16_t queue, int ring_enq; uint16_t d_pkts = 0; struct rte_mbuf *dup_bufs[nb_pkts]; - uint64_t ts; + uint64_t timestamp = 0; struct rte_ring *ring; struct rte_mempool *mp; struct rte_mbuf *p; @@ -99,7 +128,6 @@ pdump_copy(uint16_t port_id, uint16_t queue, if (cbs->filter) rte_bpf_exec_burst(cbs->filter, (void **)pkts, rcs, nb_pkts); - ts = rte_get_tsc_cycles(); ring = cbs->ring; mp = cbs->mp; for (i = 0; i < nb_pkts; i++) { @@ -119,12 +147,17 @@ pdump_copy(uint16_t port_id, uint16_t queue, * If using pcapng then want to wrap packets * otherwise a simple copy. */ - if (cbs->ver == V2) + if (cbs->ver == V2) { + /* calculate timestamp on first packet */ + if (timestamp == 0) + timestamp = pdump_timestamp(); + p = rte_pcapng_copy(port_id, queue, pkts[i], mp, cbs->snaplen, - ts, direction, NULL); - else + timestamp, direction, NULL); + } else { p = rte_pktmbuf_copy(pkts[i], mp, 0, cbs->snaplen); + } if (unlikely(p == NULL)) __atomic_fetch_add(&stats->nombuf, 1, __ATOMIC_RELAXED); @@ -421,8 +454,21 @@ int rte_pdump_init(void) { const struct rte_memzone *mz; + struct timespec ts; + uint64_t cycles; int ret; + /* Compute time base offsets */ + cycles = rte_get_tsc_cycles(); + clock_gettime(CLOCK_REALTIME, &ts); + + /* put initial TSC value in middle of clock_gettime() call */ + pdump_time.tsc_base = (cycles + rte_get_tsc_cycles()) / 2; + pdump_time.offset_ns = rte_timespec_to_ns(&ts); + + pdump_time.tsc_hz = rte_get_tsc_hz(); + pdump_time.tsc_hz_inverse = rte_reciprocal_value_u64(pdump_time.tsc_hz); + mz = rte_memzone_reserve(MZ_RTE_PDUMP_STATS, sizeof(*pdump_stats), rte_socket_id(), 0); if (mz == NULL) {