From patchwork Wed May 22 16:12:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 140272 X-Patchwork-Delegate: thomas@monjalon.net 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 4A1C144099; Wed, 22 May 2024 18:14:44 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6B3F94064A; Wed, 22 May 2024 18:14:41 +0200 (CEST) Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by mails.dpdk.org (Postfix) with ESMTP id 26D3E402EF for ; Wed, 22 May 2024 18:14:39 +0200 (CEST) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f335e8d493so1354395ad.1 for ; Wed, 22 May 2024 09:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716394478; x=1716999278; 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=hVCKCmUDHLN6MQuTC3Jka0cV7oRhFSKBefcQ7wfVJqM=; b=xYcpDqINMAy2dReXbD5DGcMiE8D2qN1zc/m7QQbij7hj6OlXh1Vl84cMct1msmlLKg PsQR1EKqxNuCXkmPwM+FlIUkhYgy5UGQ3Wb/ZzNbBo/Fe6XjXxPoMYKbS0jTqFDogH9G lW71uC8WGx6Qw4gTYC2u13xMiwUb1epfVayK50GXhGPJFHn9/o/hX3Ep5+S046F8NZXv AZa9OCaCOg+Uooa4OtmBWgKKwhEt3zjtSVg0nMUkPMGRI2Nb4izCPR1Wkxk1EqdVZ23D 54HYaXggHnvYwFMPKW08x4lwj+sf6FOmvgD2TakcDfJT1gfkrpW4eSO7LFPgMoxMd45g EHug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716394478; x=1716999278; 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=hVCKCmUDHLN6MQuTC3Jka0cV7oRhFSKBefcQ7wfVJqM=; b=mzNAB946LvlTSte+1W1iJ7AHZHbdGELa9wpUW+w3pxV6dTeRxnhyVMyBD255qi6bog AvCf/RV7B7K/J+Qc8Jpm+E0PZ25ZQZ7ETQMzgWkNm5eHDpQCm5Uk4ELS2aPYJ62RR2kf O6iCGOZaIPabRTYojX2CHFxj9AERl3q8AlEgwsvlGeGFwLxhEfZu2tDa3f94/mH8kqbt df+RPpndJMrhbclZQJAH4Sp3Y7AahQAnsWxT/weP0aDcLy8kCuEicpSuwgt4EE/fN6lD M4DwmzjO0ScpUAmwHAI1ZDILARqCV+f3ZpDgtBoDdfNTI2lhmc+Clk8WkpY+o1TemYxE 7Txw== X-Gm-Message-State: AOJu0YyQYiZOLpsoOkgeKWgpWSSrq8Dl2S52bMLHjWxXgnEzFm+T9mvJ C2nsty7tUbnyffyVAdGCtrVRTkwsdloqX+FBCHE8M8DYmo4T3uva3VodG2a1dekIPiKVz+G3IZw 71eg= X-Google-Smtp-Source: AGHT+IGYamnBLHfIWD8Xr0Q0rlYAxyCPlTDvfjXWuqUOssdlZCSE/VqU7Mayj9Ll9NaKnJDfUsTqEA== X-Received: by 2002:a17:902:f712:b0:1f3:360f:8947 with SMTP id d9443c01a7336-1f3360f89c0mr3379745ad.68.1716394478141; Wed, 22 May 2024 09:14:38 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f327ae4647sm13684175ad.224.2024.05.22.09.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 09:14:37 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Tyler Retzlaff Subject: [PATCH v10 1/8] eal: generic 64 bit counter Date: Wed, 22 May 2024 09:12:25 -0700 Message-ID: <20240522161427.64568-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522161427.64568-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240522161427.64568-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 This header implements 64 bit counters that can be reset. The counter increment in the fast path requires no locked operations. Reading and resetting the counter is handled by keeping track of a zero offset. Signed-off-by: Stephen Hemminger Acked-by: Morten Brørup --- lib/eal/include/meson.build | 1 + lib/eal/include/rte_counter.h | 141 ++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 lib/eal/include/rte_counter.h diff --git a/lib/eal/include/meson.build b/lib/eal/include/meson.build index e94b056d46..c070dd0079 100644 --- a/lib/eal/include/meson.build +++ b/lib/eal/include/meson.build @@ -12,6 +12,7 @@ headers += files( 'rte_class.h', 'rte_common.h', 'rte_compat.h', + 'rte_counter.h', 'rte_debug.h', 'rte_dev.h', 'rte_devargs.h', diff --git a/lib/eal/include/rte_counter.h b/lib/eal/include/rte_counter.h new file mode 100644 index 0000000000..7a90a328fd --- /dev/null +++ b/lib/eal/include/rte_counter.h @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) Stephen Hemminger + */ + +#ifndef _RTE_COUNTER_H_ +#define _RTE_COUNTER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +/** + * @file + * RTE Counter + * + * A counter is 64 bit value that is safe from split read/write. + * It assumes that only one CPU at a time will update the counter, + * and another CPU may want to read it. + * + * This is a weaker subset of full atomic variables. + * + * The counters are subject to the restrictions of atomic variables + * in packed structures or unaligned. + */ + +#ifndef RTE_ARCH_I686 + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * On platforms where 64 bit values are not split by compiler, the counter + * is implemented as basic 64 bit unsigned integer that only increases. + * The counter is reset by changing zero offset. + */ +typedef struct { + uint64_t current; /**< Monotonically increasing value. */ + uint64_t offset; /**< Offset of zero value. */ +} rte_counter64_t; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Add value to counter. + * Assumes this operation is only done by one thread on the object. + * + * @param counter + * A pointer to the counter. + * @param val + * The value to add to the counter. + */ +static inline void +rte_counter64_add(rte_counter64_t *counter, uint32_t val) +{ + counter->current += val; +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Reads the value of the current which is current value adjusted by the zero offset. + * This operation can be done by any thread. + * + * @param counter + * A pointer to the counter. + * @return + * The value of the counter. + */ +__rte_experimental +static inline uint64_t +rte_counter64_read(const rte_counter64_t *counter) +{ + uint64_t cur, offs; + + cur = rte_atomic_load_explicit(&counter->current, rte_memory_order_consume); + offs = rte_atomic_load_explicit(&counter->offset, rte_memory_order_relaxed); + + return cur - offs; +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Reset a counter to zero by recording current value and making it the new zero offset. + * This operation can be done by any thread. + * + * @param counter + * A pointer to the counter. + */ +__rte_experimental +static inline void +rte_counter64_reset(rte_counter64_t *counter) +{ + uint64_t cur; + + cur = rte_atomic_load_explicit(&counter->current, rte_memory_order_consume); + rte_atomic_store_explicit(&counter->offset, cur, rte_memory_order_relaxed); +} + +#else + +/* On x86 32 bit need to use atomic to avoid load/store tearing */ +typedef RTE_ATOMIC(uint64_t) rte_counter64_t; + +__rte_experimental +static inline void +rte_counter64_add(rte_counter64_t *counter, uint32_t val) +{ + rte_atomic_fetch_add_explicit(counter, val, rte_memory_order_relaxed); +} + +__rte_experimental +static inline uint64_t +rte_counter64_read(const rte_counter64_t *counter) +{ + return rte_atomic_load_explicit(counter, rte_memory_order_relaxed); +} + +__rte_experimental +static inline void +rte_counter64_reset(rte_counter64_t *counter) +{ + rte_atomic_store_explicit(counter, 0, rte_memory_order_relaxed); +} + +#endif /* RTE_ARCH_64 */ + + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_COUNTER_H_ */ From patchwork Wed May 22 16:12:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 140273 X-Patchwork-Delegate: thomas@monjalon.net 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 7F42D44099; Wed, 22 May 2024 18:14:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CCB744067D; Wed, 22 May 2024 18:14:42 +0200 (CEST) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id CB6BA402F0 for ; Wed, 22 May 2024 18:14:39 +0200 (CEST) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1eb0e08bfd2so117284555ad.1 for ; Wed, 22 May 2024 09:14:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716394479; x=1716999279; 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=Hh2GgCFnjmWS/JKm3016dHJykAAeX+Xf3AD2vvEYbf8=; b=Vifs2xWVhGnhqU40lK2Mrc+nfiDFmNYCiD25aqJQ5PvwGERv3GyCbxjESe8OOwYbtk V2pM7le7Zr5FyrTGds5jadPd0pS6H5glC2Evt44/7CEvbFhLCAXZcnyTJFtz8JLf2vVd Wk3sUMd39wJf/f3mHtt5xxG3y0UGO4dhjqXYQPXP4E8a4bHeP24H+AmQjbkp0QRmgK4x YFtWUrVf0veXcXYiVYE4yZ8ry2I2VfEf9BhPXrqi063GQP9LrtbulNYs8PZHfMXQIs3m JUEtE+8dL/ehgBqOy0vbRZrqDzSXPA0+JdMZWuixzJOm0UdmCfdBsR2kXq3ZPyjZfa6w TXoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716394479; x=1716999279; 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=Hh2GgCFnjmWS/JKm3016dHJykAAeX+Xf3AD2vvEYbf8=; b=apaBVHEW3nvZ+/XClOe9thmEaSzxDy3bwknOtN2eUGAbXVbqqcx4vUjUNBmNDavRvu kGarrTF6Y/36XpoRdxd76RFlRgnJto+9URlBwEKUfVAw+uvduyspxHVhcjC4WfMO3TJ1 ZAQoA6wrFqAlR7kPji/dpdKhQzhDxyzDt+W+KXZJ22xFGmsQGDQITyyuqUBaeFBGgLKe 58mgTkYDrbMLS3MJaLf8217MqsrBQt+3M8zAfnTrMaK58dnOTkm9MmwHVhzQS+ZP8/nD SGPOQ9HCYuM11TyS79n5w7Yf/3N2Vzb1Ky9kaqR1l2ML9t5BEBYzb0BxwRzDSBgPBfse 8gdQ== X-Gm-Message-State: AOJu0Yyr/LOZSXxKnPXwZUQpwr5fCIppHDoUEP6o63CfOgm8zBkGt3R/ vrzCuXzH1eioPP166JJUISXlvHnUVtKZlmUmayjRLqSrj9jupBxEfrvexHAF30e0getXZeCOy0P 17Uo= X-Google-Smtp-Source: AGHT+IFw5Cvev70dkDKFgDoGmuSEHxiOIO1TfFmzRKuCkxSi3jC3dtosEqdJi66fH5s3TfTJkc6aHg== X-Received: by 2002:a17:902:f0cd:b0:1f3:121e:e3cd with SMTP id d9443c01a7336-1f31c97a591mr20697345ad.15.1716394478977; Wed, 22 May 2024 09:14:38 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f327ae4647sm13684175ad.224.2024.05.22.09.14.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 09:14:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko Subject: [PATCH v10 2/8] ethdev: add common counters for statistics Date: Wed, 22 May 2024 09:12:26 -0700 Message-ID: <20240522161427.64568-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522161427.64568-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240522161427.64568-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 Introduce common helper routines for keeping track of per-queue statistics in SW PMD's. The code in several drivers had copy/pasted the same code for this, but had common issues with 64 bit counters on 32 bit platforms. Signed-off-by: Stephen Hemminger --- lib/ethdev/ethdev_swstats.c | 102 +++++++++++++++++++++++++++++++ lib/ethdev/ethdev_swstats.h | 117 ++++++++++++++++++++++++++++++++++++ lib/ethdev/meson.build | 2 + lib/ethdev/version.map | 3 + 4 files changed, 224 insertions(+) create mode 100644 lib/ethdev/ethdev_swstats.c create mode 100644 lib/ethdev/ethdev_swstats.h diff --git a/lib/ethdev/ethdev_swstats.c b/lib/ethdev/ethdev_swstats.c new file mode 100644 index 0000000000..e5560d2310 --- /dev/null +++ b/lib/ethdev/ethdev_swstats.c @@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) Stephen Hemminger + */ + +#include +#include + +#include +#include +#include + +#include "ethdev_driver.h" +#include "ethdev_swstats.h" + +int +rte_eth_counters_stats_get(const struct rte_eth_dev *dev, + size_t tx_offset, size_t rx_offset, + struct rte_eth_stats *stats) +{ + uint64_t packets, bytes, errors; + unsigned int i; + + for (i = 0; i < dev->data->nb_tx_queues; i++) { + const void *txq = dev->data->tx_queues[i]; + const struct rte_eth_counters *counters; + + if (txq == NULL) + continue; + + counters = (const struct rte_eth_counters *)((const char *)txq + tx_offset); + packets = rte_counter64_read(&counters->packets); + bytes = rte_counter64_read(&counters->bytes); + errors = rte_counter64_read(&counters->errors); + + stats->opackets += packets; + stats->obytes += bytes; + stats->oerrors += errors; + + if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_opackets[i] = packets; + stats->q_obytes[i] = bytes; + } + } + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + const void *rxq = dev->data->rx_queues[i]; + const struct rte_eth_counters *counters; + + if (rxq == NULL) + continue; + + counters = (const struct rte_eth_counters *)((const char *)rxq + rx_offset); + packets = rte_counter64_read(&counters->packets); + bytes = rte_counter64_read(&counters->bytes); + errors = rte_counter64_read(&counters->errors); + + stats->ipackets += packets; + stats->ibytes += bytes; + stats->ierrors += errors; + + if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_ipackets[i] = packets; + stats->q_ibytes[i] = bytes; + } + } + + stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed; + return 0; +} + +int +rte_eth_counters_reset(struct rte_eth_dev *dev, size_t tx_offset, size_t rx_offset) +{ + struct rte_eth_counters *counters; + unsigned int i; + + for (i = 0; i < dev->data->nb_tx_queues; i++) { + void *txq = dev->data->tx_queues[i]; + + if (txq == NULL) + continue; + + counters = (struct rte_eth_counters *)((char *)txq + tx_offset); + rte_counter64_reset(&counters->packets); + rte_counter64_reset(&counters->bytes); + rte_counter64_reset(&counters->errors); + } + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + void *rxq = dev->data->rx_queues[i]; + + if (rxq == NULL) + continue; + + counters = (struct rte_eth_counters *)((char *)rxq + rx_offset); + rte_counter64_reset(&counters->packets); + rte_counter64_reset(&counters->bytes); + rte_counter64_reset(&counters->errors); + } + + return 0; +} diff --git a/lib/ethdev/ethdev_swstats.h b/lib/ethdev/ethdev_swstats.h new file mode 100644 index 0000000000..c149b7697e --- /dev/null +++ b/lib/ethdev/ethdev_swstats.h @@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) Stephen Hemminger + */ + +#ifndef _RTE_ETHDEV_SWSTATS_H_ +#define _RTE_ETHDEV_SWSTATS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * + * Internal statistics counters for software based devices. + * Hardware PMD's should use the hardware counters instead. + * + * This provides a library for PMD's to keep track of packets and bytes. + * It is assumed that this will be used per queue and queues are not + * shared by lcores. + */ +#include +#include + +#include +#include + +struct rte_eth_dev; +struct rte_eth_stats; + +/** + * A structure to be embedded in the device driver per-queue data. + */ +struct rte_eth_counters { + rte_counter64_t packets; /**< Total number of packets. */ + rte_counter64_t bytes; /**< Total number of bytes. */ + rte_counter64_t errors; /**< Total number of packets with errors. */ +}; + +/** + * @internal + * Increment counters for a single packet. + * + * @param counters + * Pointer to queue structure containing counters. + * @param packets + * Number of packets to count + * @param bytes + * Total size of all packet in bytes. + */ +__rte_internal +static inline void +rte_eth_count_packets(struct rte_eth_counters *counters, + uint16_t packets, uint32_t bytes) +{ + rte_counter64_add(&counters->packets, packets); + rte_counter64_add(&counters->bytes, bytes); +} + +/** + * @internal + * Increment error counter. + * + * @param counters + * Pointer to queue structure containing counters. + */ +__rte_internal +static inline void +rte_eth_count_error(struct rte_eth_counters *counters) +{ + rte_counter64_add(&counters->errors, 1); +} + +/** + * @internal + * Retrieve the general statistics for all queues. + * @see rte_eth_stats_get. + * + * @param dev + * Pointer to the Ethernet device structure. + * @param tx_offset + * Offset from the tx_queue structure where stats are located. + * @param rx_offset + * Offset from the rx_queue structure where stats are located. + * @param stats + * A pointer to a structure of type *rte_eth_stats* to be filled + * @return + * Zero if successful. Non-zero otherwise. + */ +__rte_internal +int rte_eth_counters_stats_get(const struct rte_eth_dev *dev, + size_t tx_offset, size_t rx_offset, + struct rte_eth_stats *stats); + +/** + * @internal + * Reset the statistics for all queues. + * @see rte_eth_stats_reset. + * + * @param dev + * Pointer to the Ethernet device structure. + * @param tx_offset + * Offset from the tx_queue structure where stats are located. + * @param rx_offset + * Offset from the rx_queue structure where stats are located. + * @return + * Zero if successful. Non-zero otherwise. + */ +__rte_internal +int rte_eth_counters_reset(struct rte_eth_dev *dev, + size_t tx_offset, size_t rx_offset); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_ETHDEV_SWSTATS_H_ */ diff --git a/lib/ethdev/meson.build b/lib/ethdev/meson.build index f1d2586591..7ce29a46d4 100644 --- a/lib/ethdev/meson.build +++ b/lib/ethdev/meson.build @@ -3,6 +3,7 @@ sources = files( 'ethdev_driver.c', + 'ethdev_swstats.c', 'ethdev_private.c', 'ethdev_profile.c', 'ethdev_trace_points.c', @@ -42,6 +43,7 @@ driver_sdk_headers += files( 'ethdev_driver.h', 'ethdev_pci.h', 'ethdev_vdev.h', + 'ethdev_swstats.h', ) if is_linux diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index 79f6f5293b..fc595be278 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -358,4 +358,7 @@ INTERNAL { rte_eth_switch_domain_alloc; rte_eth_switch_domain_free; rte_flow_fp_default_ops; + + rte_eth_counters_reset; + rte_eth_counters_stats_get; }; From patchwork Wed May 22 16:12:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 140274 X-Patchwork-Delegate: thomas@monjalon.net 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 87B7144099; Wed, 22 May 2024 18:14:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2385540689; Wed, 22 May 2024 18:14:44 +0200 (CEST) Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mails.dpdk.org (Postfix) with ESMTP id 7BA66402F0 for ; Wed, 22 May 2024 18:14:40 +0200 (CEST) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1f32b1b5429so4219415ad.2 for ; Wed, 22 May 2024 09:14:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716394480; x=1716999280; 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=MjalrBySr7qzjIIpZNrJKVRuPrkLUZnmMi1fl292L1w=; b=OCRDTfaGW0nggCeJjF6jY8kImgV1PElFScx3A6y85LTy4MFW0SKQM39pWdss0hZ5x7 LSpYwTuMOK/SHvvV2qrT0V1vInxEMDPj8N3S0DRooTr7HasNhrg1QoYi4DEITVNlkuJW keHnsUkdA2mSea6aj7JFZzEDGAacPdQTk1zNKfRWkHCS22+Mnly7b6Z045CSn+sknwkF YWOhpdGDxX5w6CaP1xJg7FDuV4JY+B7EASPkBSVEdUx9xa8YNRVPv/64Qye2gzvfXLMw ugPuJW3MZ7ZUVrRGsGigKyTYKa0JnBLO0y+79TdjMkQXiSWupiGVSgzlyU7QvURHxzAQ hXqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716394480; x=1716999280; 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=MjalrBySr7qzjIIpZNrJKVRuPrkLUZnmMi1fl292L1w=; b=tLrxpo818WD78xBdT2GHBrAJaP1ugJ60b3ZwBcWJuJ7oOm6CDoUrB1HGr7rc11YNrv PeFamQPLmAidnQ2AZvMxFCQEfxNTx3qQJIizhMmkCsAQGyS7qDGwUmtdBbMBcC+I88OZ revFI0D5bee86sPx5itc3tXaVqFan5jr9YpNH4or7UzfGzLoJNKogUyVT9orLDmTPZZ7 bEowELK9ib7lIGizCJ5EgKmkhgw2MjhEKbpqvPgDuc4W6x9GjUH3Q1UmW3gfilk28vZq 0Uj3/5mYYy6BiM9eRPG9tc+nRV40fK7NI5EpGIbgjYOBcOXIQBFr7R9rHAu0NC2RvJST Yasg== X-Gm-Message-State: AOJu0Yz32+YZQ5PiRW5WM/0134/FjvS2KsY6AoRWuQtVDADA1i/kNthj CDhjGrg2Th9n1fkoYd3nTaQ2AOlEWTvvsj5EzkQu7jFdLrp1TSb8HVPTllbymx2AfsZzKY2f6To xxy8= X-Google-Smtp-Source: AGHT+IFNit6aBiLKbnz1BjBg6uWVvFlncVNZCNg0unThPHXhCi6kQTPNM6tM7xm833mWRHV08oTuHw== X-Received: by 2002:a17:902:ccc8:b0:1f0:98f2:7cc6 with SMTP id d9443c01a7336-1f31c9e6117mr40275815ad.45.1716394479731; Wed, 22 May 2024 09:14:39 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f327ae4647sm13684175ad.224.2024.05.22.09.14.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 09:14:39 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , "John W. Linville" Subject: [PATCH v10 3/8] net/af_packet: use generic SW stats Date: Wed, 22 May 2024 09:12:27 -0700 Message-ID: <20240522161427.64568-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522161427.64568-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240522161427.64568-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 Use the new generic SW stats. Add a note about how errors and kernel full should be handled. Signed-off-by: Stephen Hemminger --- drivers/net/af_packet/rte_eth_af_packet.c | 78 +++++------------------ 1 file changed, 17 insertions(+), 61 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 397a32db58..64fa519812 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -51,8 +52,7 @@ struct pkt_rx_queue { uint16_t in_port; uint8_t vlan_strip; - volatile unsigned long rx_pkts; - volatile unsigned long rx_bytes; + struct rte_eth_counters stats; }; struct pkt_tx_queue { @@ -64,11 +64,10 @@ struct pkt_tx_queue { unsigned int framecount; unsigned int framenum; - volatile unsigned long tx_pkts; - volatile unsigned long err_pkts; - volatile unsigned long tx_bytes; + struct rte_eth_counters stats; }; + struct pmd_internals { unsigned nb_queues; @@ -168,9 +167,10 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) num_rx_bytes += mbuf->pkt_len; } pkt_q->framenum = framenum; - pkt_q->rx_pkts += num_rx; - pkt_q->rx_bytes += num_rx_bytes; - return num_rx; + + rte_eth_count_packets(&pkt_q->stats, num_rx, num_rx_bytes); + + return i; } /* @@ -294,19 +294,16 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) if (sendto(pkt_q->sockfd, NULL, 0, MSG_DONTWAIT, NULL, 0) == -1 && errno != ENOBUFS && errno != EAGAIN) { /* - * In case of a ENOBUFS/EAGAIN error all of the enqueued - * packets will be considered successful even though only some - * are sent. + * FIXME: if sendto fails kernel is busy should return 0 + * and not free the mbufs. Other errors should free the + * buts and increment the tx error count. */ - num_tx = 0; num_tx_bytes = 0; } pkt_q->framenum = framenum; - pkt_q->tx_pkts += num_tx; - pkt_q->err_pkts += i - num_tx; - pkt_q->tx_bytes += num_tx_bytes; + rte_eth_count_packets(&pkt_q->stats, num_tx, num_tx_bytes); return i; } @@ -386,58 +383,17 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) } static int -eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats) +eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { - unsigned i, imax; - unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0; - unsigned long rx_bytes_total = 0, tx_bytes_total = 0; - const struct pmd_internals *internal = dev->data->dev_private; - - imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ? - internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS); - for (i = 0; i < imax; i++) { - igb_stats->q_ipackets[i] = internal->rx_queue[i].rx_pkts; - igb_stats->q_ibytes[i] = internal->rx_queue[i].rx_bytes; - rx_total += igb_stats->q_ipackets[i]; - rx_bytes_total += igb_stats->q_ibytes[i]; - } - - imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ? - internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS); - for (i = 0; i < imax; i++) { - igb_stats->q_opackets[i] = internal->tx_queue[i].tx_pkts; - igb_stats->q_obytes[i] = internal->tx_queue[i].tx_bytes; - tx_total += igb_stats->q_opackets[i]; - tx_err_total += internal->tx_queue[i].err_pkts; - tx_bytes_total += igb_stats->q_obytes[i]; - } - - igb_stats->ipackets = rx_total; - igb_stats->ibytes = rx_bytes_total; - igb_stats->opackets = tx_total; - igb_stats->oerrors = tx_err_total; - igb_stats->obytes = tx_bytes_total; - return 0; + return rte_eth_counters_stats_get(dev, offsetof(struct pkt_tx_queue, stats), + offsetof(struct pkt_rx_queue, stats), stats); } static int eth_stats_reset(struct rte_eth_dev *dev) { - unsigned i; - struct pmd_internals *internal = dev->data->dev_private; - - for (i = 0; i < internal->nb_queues; i++) { - internal->rx_queue[i].rx_pkts = 0; - internal->rx_queue[i].rx_bytes = 0; - } - - for (i = 0; i < internal->nb_queues; i++) { - internal->tx_queue[i].tx_pkts = 0; - internal->tx_queue[i].err_pkts = 0; - internal->tx_queue[i].tx_bytes = 0; - } - - return 0; + return rte_eth_counters_reset(dev, offsetof(struct pkt_tx_queue, stats), + offsetof(struct pkt_rx_queue, stats)); } static int From patchwork Wed May 22 16:12:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 140275 X-Patchwork-Delegate: thomas@monjalon.net 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 B4A3844099; Wed, 22 May 2024 18:15:09 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CD59B406A2; Wed, 22 May 2024 18:14:45 +0200 (CEST) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id 5F1AB40648 for ; Wed, 22 May 2024 18:14:41 +0200 (CEST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1f332528c1aso2720795ad.2 for ; Wed, 22 May 2024 09:14:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716394480; x=1716999280; 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=mBzpjYE8DoSG3Siz752I1pLevMRX7Gd2+d2mJF6DBuM=; b=eslbSjchNGDUh7jAlzBJ0BxepbURwdyN9OfhYMefiy5wWCskdoNKHw4K3YBUAyImKd NMgEwfPXRkl5qp0XDw+h/dmyoOsokqcpWapMBW9OWvGvaweWPCBkqIj8P0kI/ChHG/km IQDe9eyeDk3w7KXoxtDTA1JJJXFiLDoUi8V26pyIhEyRs0HQCc2FLbelOQn9anC0kHzv 7NeaTI6q1kUEnm1bXVTBS1lHW17O1mywO5APW35YddHTr6DF01mxsQEENp1uDbnszzfz w8c5psU2mlX7PvxLAHFNEdq/JNhWm5i1too+jsEJNJMv6vSsjMWjXyTisVWIXy7Oz5B5 M3cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716394480; x=1716999280; 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=mBzpjYE8DoSG3Siz752I1pLevMRX7Gd2+d2mJF6DBuM=; b=FGdXzUq5Bg9qfCHuFvWjxPrihPQcUJTQo+kUMcymJpr5oMFjPqEvZrh6j0xBVfdrMS jd8InPZSdkZqIC+OJXU1nsHy86K4QHuCdGyZtsZqCfcgNTemopY2IW9q3GPfk72mTYfp COsaoysXwGuW3ryENhvvDbsLYgdg0FVC9sfcaGA0iLDaeSNpExCFql1gO2zz8fQILQN6 F+/alXNos5hQt5dYHmptkOmv9tf2AFu8Lpei0IdPmPMRSuHJ76jV7CFNn8BRfA/edZ+p RcmEtED2MfEK2sT7VJGgk3clQg9uy7q2LM0hqEiENJfIxa+ernX7CR3sZ+QJOHheN3l/ isgQ== X-Gm-Message-State: AOJu0Yxy0/iW1TzXCv2d/e4PEXwzDagfIFK0sQ0Fbd5garJfKTgCxPRu lTC8tW/lpqB8CNDydbSAs9C7+/FqzsINX/B7doIq6zaDBX/fYIjT9nvfMRLyeIzW6lGxxwpvlFV cyJg= X-Google-Smtp-Source: AGHT+IGbogStXS/RrvYFlbr0Gwtitr4i4haxDuIk/gb858ojXqk4hUCf4qSoXzJ/ed3V7QGYDJsDyw== X-Received: by 2002:a17:902:6506:b0:1f3:453:2ca0 with SMTP id d9443c01a7336-1f31c9effd4mr20977695ad.42.1716394480463; Wed, 22 May 2024 09:14:40 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f327ae4647sm13684175ad.224.2024.05.22.09.14.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 09:14:40 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Ciara Loftus Subject: [PATCH v10 4/8] net/af_xdp: use generic SW stats Date: Wed, 22 May 2024 09:12:28 -0700 Message-ID: <20240522161427.64568-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522161427.64568-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240522161427.64568-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 Use common code for all SW stats. Signed-off-by: Stephen Hemminger --- drivers/net/af_xdp/rte_eth_af_xdp.c | 85 ++++++++--------------------- 1 file changed, 22 insertions(+), 63 deletions(-) diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c index 6ba455bb9b..c563621798 100644 --- a/drivers/net/af_xdp/rte_eth_af_xdp.c +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -120,19 +121,13 @@ struct xsk_umem_info { uint32_t max_xsks; }; -struct rx_stats { - uint64_t rx_pkts; - uint64_t rx_bytes; - uint64_t rx_dropped; -}; - struct pkt_rx_queue { struct xsk_ring_cons rx; struct xsk_umem_info *umem; struct xsk_socket *xsk; struct rte_mempool *mb_pool; - struct rx_stats stats; + struct rte_eth_counters stats; struct xsk_ring_prod fq; struct xsk_ring_cons cq; @@ -143,17 +138,11 @@ struct pkt_rx_queue { int busy_budget; }; -struct tx_stats { - uint64_t tx_pkts; - uint64_t tx_bytes; - uint64_t tx_dropped; -}; - struct pkt_tx_queue { struct xsk_ring_prod tx; struct xsk_umem_info *umem; - struct tx_stats stats; + struct rte_eth_counters stats; struct pkt_rx_queue *pair; int xsk_queue_idx; @@ -369,9 +358,7 @@ af_xdp_rx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) xsk_ring_cons__release(rx, nb_pkts); (void)reserve_fill_queue(umem, nb_pkts, fq_bufs, fq); - /* statistics */ - rxq->stats.rx_pkts += nb_pkts; - rxq->stats.rx_bytes += rx_bytes; + rte_eth_count_packets(&rxq->stats, nb_pkts, rx_bytes); return nb_pkts; } @@ -429,10 +416,7 @@ af_xdp_rx_cp(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) } xsk_ring_cons__release(rx, nb_pkts); - - /* statistics */ - rxq->stats.rx_pkts += nb_pkts; - rxq->stats.rx_bytes += rx_bytes; + rte_eth_count_packets(&rxq->stats, nb_pkts, rx_bytes); return nb_pkts; } @@ -558,6 +542,7 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) umem->mb_pool->header_size; offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT; desc->addr = addr | offset; + tx_bytes += mbuf->pkt_len; count++; } else { struct rte_mbuf *local_mbuf = @@ -585,20 +570,17 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) desc->addr = addr | offset; rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *), desc->len); + tx_bytes += mbuf->pkt_len; rte_pktmbuf_free(mbuf); count++; } - - tx_bytes += mbuf->pkt_len; } out: xsk_ring_prod__submit(&txq->tx, count); kick_tx(txq, cq); - txq->stats.tx_pkts += count; - txq->stats.tx_bytes += tx_bytes; - txq->stats.tx_dropped += nb_pkts - count; + rte_eth_count_packets(&txq->stats, count, tx_bytes); return count; } @@ -648,8 +630,7 @@ af_xdp_tx_cp(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) kick_tx(txq, cq); - txq->stats.tx_pkts += nb_pkts; - txq->stats.tx_bytes += tx_bytes; + rte_eth_count_packets(&txq->stats, nb_pkts, tx_bytes); return nb_pkts; } @@ -847,39 +828,26 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) static int eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { - struct pmd_internals *internals = dev->data->dev_private; struct pmd_process_private *process_private = dev->process_private; - struct xdp_statistics xdp_stats; - struct pkt_rx_queue *rxq; - struct pkt_tx_queue *txq; - socklen_t optlen; - int i, ret, fd; + unsigned int i; - for (i = 0; i < dev->data->nb_rx_queues; i++) { - optlen = sizeof(struct xdp_statistics); - rxq = &internals->rx_queues[i]; - txq = rxq->pair; - stats->q_ipackets[i] = rxq->stats.rx_pkts; - stats->q_ibytes[i] = rxq->stats.rx_bytes; + rte_eth_counters_stats_get(dev, offsetof(struct pkt_tx_queue, stats), + offsetof(struct pkt_rx_queue, stats), stats); - stats->q_opackets[i] = txq->stats.tx_pkts; - stats->q_obytes[i] = txq->stats.tx_bytes; + for (i = 0; i < dev->data->nb_rx_queues; i++) { + struct xdp_statistics xdp_stats; + socklen_t optlen = sizeof(xdp_stats); + int fd; - stats->ipackets += stats->q_ipackets[i]; - stats->ibytes += stats->q_ibytes[i]; - stats->imissed += rxq->stats.rx_dropped; - stats->oerrors += txq->stats.tx_dropped; fd = process_private->rxq_xsk_fds[i]; - ret = fd >= 0 ? getsockopt(fd, SOL_XDP, XDP_STATISTICS, - &xdp_stats, &optlen) : -1; - if (ret != 0) { + if (fd < 0) + continue; + if (getsockopt(fd, SOL_XDP, XDP_STATISTICS, + &xdp_stats, &optlen) < 0) { AF_XDP_LOG(ERR, "getsockopt() failed for XDP_STATISTICS.\n"); return -1; } stats->imissed += xdp_stats.rx_dropped; - - stats->opackets += stats->q_opackets[i]; - stats->obytes += stats->q_obytes[i]; } return 0; @@ -888,17 +856,8 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) static int eth_stats_reset(struct rte_eth_dev *dev) { - struct pmd_internals *internals = dev->data->dev_private; - int i; - - for (i = 0; i < internals->queue_cnt; i++) { - memset(&internals->rx_queues[i].stats, 0, - sizeof(struct rx_stats)); - memset(&internals->tx_queues[i].stats, 0, - sizeof(struct tx_stats)); - } - - return 0; + return rte_eth_counters_reset(dev, offsetof(struct pkt_tx_queue, stats), + offsetof(struct pkt_rx_queue, stats)); } #ifdef RTE_NET_AF_XDP_LIBBPF_XDP_ATTACH From patchwork Wed May 22 16:12:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 140276 X-Patchwork-Delegate: thomas@monjalon.net 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 0D48444099; Wed, 22 May 2024 18:15:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 20CBB406BA; Wed, 22 May 2024 18:14:47 +0200 (CEST) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mails.dpdk.org (Postfix) with ESMTP id 252F54067C for ; Wed, 22 May 2024 18:14:42 +0200 (CEST) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1eeabda8590so10990655ad.0 for ; Wed, 22 May 2024 09:14:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716394481; x=1716999281; 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=+EszQcYtvxNgZfYaRAS4ls3d9SF5yFMlXdQa2iCOZGQ=; b=RY1P/NjIZXpM/cCH1HaXUrhqNBPoX8wR5Hxgwzj44RuZ9oSbGZwY+uAV9jOYkTKGnM WnrskeFYrVXHqXlM5PkZHd+GOXqgd7QuQrLYJOVNj4zw149BR4EHvoeftiTOorqs9lOD Ye/BknrGlXa/l3QU7h0w7k5zi11lDNlHm73xSil24sVLwvWftPVTtv4kbeD4emys7Rco lVzDPVsQv/8eWMKcCf/IyRSily4dp8T5So3Vb/IdmnS1zGoeUbpCjiwxSET3JUGTOeIp 6/mScL+3eTEXmk1gJf6DRMSwxY7gtb0sg8t7w6roAP2bxsdiQeIz0Vn0Hgju+OV7AGVi XnAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716394481; x=1716999281; 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=+EszQcYtvxNgZfYaRAS4ls3d9SF5yFMlXdQa2iCOZGQ=; b=BuV5ZJyaMkOSdrNT295WiaijqROav5tuNngMXteWaLsIMbCii1xriv9O/ktSbj5rig Hdz8P/j5UDzO7aWIPAhhlX9Mp2oaff1SMlOqEfCuj6uP1A9O28WkZxv91+wdNmr+2p9T WAWsgePggyB73anP9esMLt9bnop65kWMDLjl+hblyVhpbkiMUVcGZYxuoKhTLA7J2v65 wE03vgKNkz70SmLDkJ/ExnZtheAiNGj0VT54zMn3UlYnOeSjLMqNaDzMf5io9YBCqEgp PyTxijs4AKXG/gSRxiX19rZVsqUvy/pNWU/T1kZPhrc4jltQsiiurRmXkteP8Cs92sa6 mmAA== X-Gm-Message-State: AOJu0YwGWrEr2RHQHHu/C5j58r54jIyhzrBpNdUKB0DsuDK4I/c/OLv+ wyNkkvrlOaml05phwwHnj4+lRdw0SP6b3f1SlDun4Xsk9mVO8mqjV8WQzbl2rduywrYK2in0xsh 1VSo= X-Google-Smtp-Source: AGHT+IF6+Vc9FeyI2MNgwYRz5GDyKRMzY25tUofshFb/bXs3mC12QJmKqJg4MUA3XwzxGDTTxqWo4w== X-Received: by 2002:a17:903:4303:b0:1e9:a0ce:f618 with SMTP id d9443c01a7336-1f31ca351a0mr20577435ad.69.1716394481324; Wed, 22 May 2024 09:14:41 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f327ae4647sm13684175ad.224.2024.05.22.09.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 09:14:40 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v10 5/8] net/pcap: use generic SW stats Date: Wed, 22 May 2024 09:12:29 -0700 Message-ID: <20240522161427.64568-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522161427.64568-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240522161427.64568-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 Use common statistics for SW drivers. Signed-off-by: Stephen Hemminger --- drivers/net/pcap/pcap_ethdev.c | 100 ++++++++------------------------- 1 file changed, 22 insertions(+), 78 deletions(-) diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c index bfec085045..4689359527 100644 --- a/drivers/net/pcap/pcap_ethdev.c +++ b/drivers/net/pcap/pcap_ethdev.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -48,13 +49,6 @@ static uint8_t iface_idx; static uint64_t timestamp_rx_dynflag; static int timestamp_dynfield_offset = -1; -struct queue_stat { - volatile unsigned long pkts; - volatile unsigned long bytes; - volatile unsigned long err_pkts; - volatile unsigned long rx_nombuf; -}; - struct queue_missed_stat { /* last value retrieved from pcap */ unsigned int pcap; @@ -68,7 +62,7 @@ struct pcap_rx_queue { uint16_t port_id; uint16_t queue_id; struct rte_mempool *mb_pool; - struct queue_stat rx_stat; + struct rte_eth_counters rx_stat; struct queue_missed_stat missed_stat; char name[PATH_MAX]; char type[ETH_PCAP_ARG_MAXLEN]; @@ -80,7 +74,7 @@ struct pcap_rx_queue { struct pcap_tx_queue { uint16_t port_id; uint16_t queue_id; - struct queue_stat tx_stat; + struct rte_eth_counters tx_stat; char name[PATH_MAX]; char type[ETH_PCAP_ARG_MAXLEN]; }; @@ -258,14 +252,13 @@ eth_pcap_rx_infinite(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) bufs[i]->data_len = pcap_buf->data_len; bufs[i]->pkt_len = pcap_buf->pkt_len; bufs[i]->port = pcap_q->port_id; - rx_bytes += pcap_buf->data_len; + rx_bytes += pcap_buf->pkt_len; /* Enqueue packet back on ring to allow infinite rx. */ rte_ring_enqueue(pcap_q->pkts, pcap_buf); } - pcap_q->rx_stat.pkts += i; - pcap_q->rx_stat.bytes += rx_bytes; + rte_eth_count_packets(&pcap_q->rx_stat, i, rx_bytes); return i; } @@ -300,7 +293,9 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) mbuf = rte_pktmbuf_alloc(pcap_q->mb_pool); if (unlikely(mbuf == NULL)) { - pcap_q->rx_stat.rx_nombuf++; + struct rte_eth_dev *dev = &rte_eth_devices[pcap_q->port_id]; + + ++dev->data->rx_mbuf_alloc_failed; break; } @@ -315,7 +310,7 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) mbuf, packet, header.caplen) == -1)) { - pcap_q->rx_stat.err_pkts++; + rte_eth_count_error(&pcap_q->rx_stat); rte_pktmbuf_free(mbuf); break; } @@ -332,9 +327,8 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) num_rx++; rx_bytes += header.caplen; } - pcap_q->rx_stat.pkts += num_rx; - pcap_q->rx_stat.bytes += rx_bytes; + rte_eth_count_packets(&pcap_q->rx_stat, num_rx, rx_bytes); return num_rx; } @@ -423,9 +417,8 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) * we flush the pcap dumper within each burst. */ pcap_dump_flush(dumper); - dumper_q->tx_stat.pkts += num_tx; - dumper_q->tx_stat.bytes += tx_bytes; - dumper_q->tx_stat.err_pkts += nb_pkts - num_tx; + + rte_eth_count_packets(&dumper_q->tx_stat, num_tx, tx_bytes); return nb_pkts; } @@ -448,9 +441,7 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) rte_pktmbuf_free(bufs[i]); } - tx_queue->tx_stat.pkts += nb_pkts; - tx_queue->tx_stat.bytes += tx_bytes; - + rte_eth_count_packets(&tx_queue->tx_stat, nb_pkts, tx_bytes); return i; } @@ -502,9 +493,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) rte_pktmbuf_free(mbuf); } - tx_queue->tx_stat.pkts += num_tx; - tx_queue->tx_stat.bytes += tx_bytes; - tx_queue->tx_stat.err_pkts += i - num_tx; + rte_eth_count_packets(&tx_queue->tx_stat, num_tx, tx_bytes); return i; } @@ -746,41 +735,12 @@ static int eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { unsigned int i; - unsigned long rx_packets_total = 0, rx_bytes_total = 0; - unsigned long rx_missed_total = 0; - unsigned long rx_nombuf_total = 0, rx_err_total = 0; - unsigned long tx_packets_total = 0, tx_bytes_total = 0; - unsigned long tx_packets_err_total = 0; - const struct pmd_internals *internal = dev->data->dev_private; - - for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && - i < dev->data->nb_rx_queues; i++) { - stats->q_ipackets[i] = internal->rx_queue[i].rx_stat.pkts; - stats->q_ibytes[i] = internal->rx_queue[i].rx_stat.bytes; - rx_nombuf_total += internal->rx_queue[i].rx_stat.rx_nombuf; - rx_err_total += internal->rx_queue[i].rx_stat.err_pkts; - rx_packets_total += stats->q_ipackets[i]; - rx_bytes_total += stats->q_ibytes[i]; - rx_missed_total += queue_missed_stat_get(dev, i); - } - for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && - i < dev->data->nb_tx_queues; i++) { - stats->q_opackets[i] = internal->tx_queue[i].tx_stat.pkts; - stats->q_obytes[i] = internal->tx_queue[i].tx_stat.bytes; - tx_packets_total += stats->q_opackets[i]; - tx_bytes_total += stats->q_obytes[i]; - tx_packets_err_total += internal->tx_queue[i].tx_stat.err_pkts; - } + rte_eth_counters_stats_get(dev, offsetof(struct pcap_tx_queue, tx_stat), + offsetof(struct pcap_rx_queue, rx_stat), stats); - stats->ipackets = rx_packets_total; - stats->ibytes = rx_bytes_total; - stats->imissed = rx_missed_total; - stats->ierrors = rx_err_total; - stats->rx_nombuf = rx_nombuf_total; - stats->opackets = tx_packets_total; - stats->obytes = tx_bytes_total; - stats->oerrors = tx_packets_err_total; + for (i = 0; i < dev->data->nb_rx_queues; i++) + stats->imissed += queue_missed_stat_get(dev, i); return 0; } @@ -789,21 +749,12 @@ static int eth_stats_reset(struct rte_eth_dev *dev) { unsigned int i; - struct pmd_internals *internal = dev->data->dev_private; - for (i = 0; i < dev->data->nb_rx_queues; i++) { - internal->rx_queue[i].rx_stat.pkts = 0; - internal->rx_queue[i].rx_stat.bytes = 0; - internal->rx_queue[i].rx_stat.err_pkts = 0; - internal->rx_queue[i].rx_stat.rx_nombuf = 0; - queue_missed_stat_reset(dev, i); - } + rte_eth_counters_reset(dev, offsetof(struct pcap_tx_queue, tx_stat), + offsetof(struct pcap_rx_queue, rx_stat)); - for (i = 0; i < dev->data->nb_tx_queues; i++) { - internal->tx_queue[i].tx_stat.pkts = 0; - internal->tx_queue[i].tx_stat.bytes = 0; - internal->tx_queue[i].tx_stat.err_pkts = 0; - } + for (i = 0; i < dev->data->nb_rx_queues; i++) + queue_missed_stat_reset(dev, i); return 0; } @@ -929,13 +880,6 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, pcap_pkt_count); return -EINVAL; } - - /* - * Reset the stats for this queue since eth_pcap_rx calls above - * didn't result in the application receiving packets. - */ - pcap_q->rx_stat.pkts = 0; - pcap_q->rx_stat.bytes = 0; } return 0; From patchwork Wed May 22 16:12:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 140277 X-Patchwork-Delegate: thomas@monjalon.net 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 5434F44099; Wed, 22 May 2024 18:15:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7994A40693; Wed, 22 May 2024 18:14:48 +0200 (CEST) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by mails.dpdk.org (Postfix) with ESMTP id 5B63340685 for ; Wed, 22 May 2024 18:14:43 +0200 (CEST) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1f333c7e702so2733785ad.3 for ; Wed, 22 May 2024 09:14:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716394482; x=1716999282; 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=bN+U3MlFvHBy6Y5Ch8EA2M37+2VY2m8EGSXVGyhuBX4=; b=ekPx9/GEBtWA2PFIz5jsI9rSmpG0Tpo1ZXgR014YskVUEfPMq6x63U7dzgyUx72gtQ Q57tm+WrDVFHGR+GjaPLuD95LfPR7huiska2J4aREBcAfzIQkFrmAnMq0y2hPapPgZ1k irxrJeHMc6d8mekwX+AJfqiK+Lxu6Pz8MkclQxDIWJnkB9cIkhTg8ZQoBG1DctQ7alDP D5ZbTbjMEJEUaHjxKhFQohqJZ7VO3t+vdK3Zl9X/FREb7oy2kXrPwvu0NMzX04jIvtcS 5QKGALGJb94P+12If4g3bk09yKO9btMxU2Lcv2rp2a/PgYMYcVTcuCtZGRyd7PpNHt4P fp6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716394482; x=1716999282; 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=bN+U3MlFvHBy6Y5Ch8EA2M37+2VY2m8EGSXVGyhuBX4=; b=pptMG/L0PXJ5x7K+35PwE8VOjod+s3CDrr8T3ruNYLSJIp9ByAhUihBe4C9DK2cDoC ceeeeizc3a5P2bb8CES6Yj7Fep8QSiGNSG4OhEQga85x9/FpQKTniHICPszmb9OurTT6 1ltZb++4PQ+YsNgV0g4Pkem6yCUJW5qOyWNXr/CF3o4jNLP/K+3ZbgQqzCWhPlulcitp q5vOggMXHK39pJOmJg04bVlr98uRCfxWeuqMmPv2t9WtvZC+KYo0lEMKrvVKqzCtO5cJ ru8zPbOYxDWCV6bkWcntpPUdGL+WjOPau5EN9CR7o6+Y/V1gcSIo1vzwXLHhL9vJ3gt5 1rUQ== X-Gm-Message-State: AOJu0Yy8BFdIu7sHE8/qO4vKLy0QExoBddBrNMY4vlzBSjpovZheQ+8N quC1ENmFNf6myyLcIVPTpRO72MtJZSEPA88k+pG65zLQeidw/kaqs/6W1sPzDhbC0OuM1Okrgkx rvUA= X-Google-Smtp-Source: AGHT+IHLFwn9eHnm4HxQgrT5hP8vo5rbWylW66Y6zMJ64z4iFXFVhHyCtsCJd2xRx4KKU5WFRmFVMQ== X-Received: by 2002:a17:902:e80d:b0:1ea:5aff:c8ce with SMTP id d9443c01a7336-1f31c992575mr25717805ad.29.1716394482536; Wed, 22 May 2024 09:14:42 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f327ae4647sm13684175ad.224.2024.05.22.09.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 09:14:41 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v10 6/8] net/ring: use generic SW stats Date: Wed, 22 May 2024 09:12:30 -0700 Message-ID: <20240522161427.64568-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522161427.64568-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240522161427.64568-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 Use generic per-queue infrastructure. Signed-off-by: Stephen Hemminger --- drivers/net/ring/rte_eth_ring.c | 63 +++++++++++---------------------- 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c index b16f5d55f2..36053e4038 100644 --- a/drivers/net/ring/rte_eth_ring.c +++ b/drivers/net/ring/rte_eth_ring.c @@ -7,6 +7,7 @@ #include "rte_eth_ring.h" #include #include +#include #include #include #include @@ -44,8 +45,8 @@ enum dev_action { struct ring_queue { struct rte_ring *rng; - RTE_ATOMIC(uint64_t) rx_pkts; - RTE_ATOMIC(uint64_t) tx_pkts; + + struct rte_eth_counters stats; }; struct pmd_internals { @@ -77,12 +78,12 @@ eth_ring_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { void **ptrs = (void *)&bufs[0]; struct ring_queue *r = q; - const uint16_t nb_rx = (uint16_t)rte_ring_dequeue_burst(r->rng, - ptrs, nb_bufs, NULL); - if (r->rng->flags & RING_F_SC_DEQ) - r->rx_pkts += nb_rx; - else - rte_atomic_fetch_add_explicit(&r->rx_pkts, nb_rx, rte_memory_order_relaxed); + uint16_t nb_rx; + + nb_rx = (uint16_t)rte_ring_dequeue_burst(r->rng, ptrs, nb_bufs, NULL); + + rte_counter64_add(&r->stats.packets, nb_rx); + return nb_rx; } @@ -91,12 +92,12 @@ eth_ring_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { void **ptrs = (void *)&bufs[0]; struct ring_queue *r = q; - const uint16_t nb_tx = (uint16_t)rte_ring_enqueue_burst(r->rng, - ptrs, nb_bufs, NULL); - if (r->rng->flags & RING_F_SP_ENQ) - r->tx_pkts += nb_tx; - else - rte_atomic_fetch_add_explicit(&r->tx_pkts, nb_tx, rte_memory_order_relaxed); + uint16_t nb_tx; + + nb_tx = (uint16_t)rte_ring_enqueue_burst(r->rng, ptrs, nb_bufs, NULL); + + rte_counter64_add(&r->stats.packets, nb_tx); + return nb_tx; } @@ -193,40 +194,16 @@ eth_dev_info(struct rte_eth_dev *dev, static int eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { - unsigned int i; - unsigned long rx_total = 0, tx_total = 0; - const struct pmd_internals *internal = dev->data->dev_private; - - for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && - i < dev->data->nb_rx_queues; i++) { - stats->q_ipackets[i] = internal->rx_ring_queues[i].rx_pkts; - rx_total += stats->q_ipackets[i]; - } - - for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && - i < dev->data->nb_tx_queues; i++) { - stats->q_opackets[i] = internal->tx_ring_queues[i].tx_pkts; - tx_total += stats->q_opackets[i]; - } - - stats->ipackets = rx_total; - stats->opackets = tx_total; - - return 0; + return rte_eth_counters_stats_get(dev, offsetof(struct ring_queue, stats), + offsetof(struct ring_queue, stats), + stats); } static int eth_stats_reset(struct rte_eth_dev *dev) { - unsigned int i; - struct pmd_internals *internal = dev->data->dev_private; - - for (i = 0; i < dev->data->nb_rx_queues; i++) - internal->rx_ring_queues[i].rx_pkts = 0; - for (i = 0; i < dev->data->nb_tx_queues; i++) - internal->tx_ring_queues[i].tx_pkts = 0; - - return 0; + return rte_eth_counters_reset(dev, offsetof(struct ring_queue, stats), + offsetof(struct ring_queue, stats)); } static void From patchwork Wed May 22 16:12:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 140278 X-Patchwork-Delegate: thomas@monjalon.net 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 EEF3744099; Wed, 22 May 2024 18:15:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BD91E40A6C; Wed, 22 May 2024 18:14:49 +0200 (CEST) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id 26C204068A for ; Wed, 22 May 2024 18:14:44 +0200 (CEST) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1ec4dc64c6cso10401665ad.0 for ; Wed, 22 May 2024 09:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716394483; x=1716999283; 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=yy8YDZY/MRPSLR7fI/dVHNGEOfgFcJ9MlJeosQDKby0=; b=W5KQOstp4IXQNAe1GdorAvQZF8bd/igGg3UGdVdhrwuUvJPhhD+Ix0CBph8bdJg4LM ZBWZpcstkc/9lb+2Iib+RzQKAzqyA1WTL56uB3t8ho+G5fveBJyn8tP1fKQZLO38vwvu hHZbOju/sW+U+cgCypvfDAmUD7zHZYf7k5Z0Q7GSN1ntan+ynlPTPFlo6FRUNFyC/Zxn K3dPbo89f3vE1W/e9udUhSmBDCKHaZBEQpZZ62bqrhtAoPFe8Kg97MLC//AjqNPTErxa ozN6NYkf0/AQV8QRS9bO089jtvkrcIrR40qSCga+8fsruULsi/bGQonuGNzUD4d2vUPd DxhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716394483; x=1716999283; 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=yy8YDZY/MRPSLR7fI/dVHNGEOfgFcJ9MlJeosQDKby0=; b=kTZZKwbe+GvbLmM8PM4fubg7SVcHYFPmUtOGPs3qaqcNT64KA+PXQOqTeAXqDRbiYM vJIhWaFtNZItncMrwhWKGR6c+bwjLNDBuSMdgnYkcDk3aesGPaM4sxvmJvusMkZaNyWv rwtnN3n19ilhqMFh5AQcWiahwpiE2NtY0TqB0wZiGMaSkSncnbHz0eBqrFZmcplqNUDI soBZZwkGSRdtEOcUXQIKxKOudSrnXfmnhjfdU+mdd8nzA0B0BdZ2aGg0rjPjY6zWX/sL o3POhWClnbTUK25NAEtKCOjQSnQqcr0JIVRSkMup1lkyoZy61Ums1WYdlomMdVb9kWiQ 9PcQ== X-Gm-Message-State: AOJu0Yy5N28y7O0N93NedqVOAtfRnr59AmQFF2nSAaAnLkTi6zkpYeDO qpIZGt0XFp3tvI4r6ymqh4K+1uV00BdD9JmlA6D/i0xwcQDZV9EkXKax3wsbnhRxSbsLfUB5kF4 /ObM= X-Google-Smtp-Source: AGHT+IHMwB/n5RLJzoik9DS9M1jUSG2Youq9KAPazwjPccCsQE9mYKialjQOBrIqeAfr3WMqXWGg3Q== X-Received: by 2002:a17:902:f78f:b0:1f3:2f8c:8f7b with SMTP id d9443c01a7336-1f32f8c9677mr10526795ad.15.1716394483322; Wed, 22 May 2024 09:14:43 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f327ae4647sm13684175ad.224.2024.05.22.09.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 09:14:42 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v10 7/8] net/tap: use generic SW stats Date: Wed, 22 May 2024 09:12:31 -0700 Message-ID: <20240522161427.64568-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522161427.64568-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240522161427.64568-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 Use new common sw statistics. Signed-off-by: Stephen Hemminger --- drivers/net/tap/rte_eth_tap.c | 75 ++++++----------------------------- drivers/net/tap/rte_eth_tap.h | 15 ++----- 2 files changed, 16 insertions(+), 74 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 69d9da695b..9cc923fd0c 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -455,7 +455,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) /* Packet couldn't fit in the provided mbuf */ if (unlikely(rxq->pi.flags & TUN_PKT_STRIP)) { - rxq->stats.ierrors++; + rte_eth_count_error(&rxq->stats); continue; } @@ -467,7 +467,9 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp); if (unlikely(!buf)) { - rxq->stats.rx_nombuf++; + struct rte_eth_dev *dev = &rte_eth_devices[rxq->in_port]; + ++dev->data->rx_mbuf_alloc_failed; + /* No new buf has been allocated: do nothing */ if (!new_tail || !seg) goto end; @@ -512,8 +514,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) num_rx_bytes += mbuf->pkt_len; } end: - rxq->stats.ipackets += num_rx; - rxq->stats.ibytes += num_rx_bytes; + rte_eth_count_packets(&rxq->stats, num_rx, num_rx_bytes); if (trigger && num_rx < nb_pkts) rxq->trigger_seen = trigger; @@ -693,7 +694,7 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) tso_segsz = mbuf_in->tso_segsz + hdrs_len; if (unlikely(tso_segsz == hdrs_len) || tso_segsz > *txq->mtu) { - txq->stats.errs++; + rte_eth_count_error(&txq->stats); break; } gso_ctx->gso_size = tso_segsz; @@ -731,7 +732,8 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) ret = tap_write_mbufs(txq, num_mbufs, mbuf, &num_packets, &num_tx_bytes); if (ret == -1) { - txq->stats.errs++; + rte_eth_count_error(&txq->stats); + /* free tso mbufs */ if (num_tso_mbufs > 0) rte_pktmbuf_free_bulk(mbuf, num_tso_mbufs); @@ -749,9 +751,7 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) } } - txq->stats.opackets += num_packets; - txq->stats.errs += nb_pkts - num_tx; - txq->stats.obytes += num_tx_bytes; + rte_eth_count_packets(&txq->stats, num_packets, num_tx_bytes); return num_tx; } @@ -1055,64 +1055,15 @@ tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) static int tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats) { - unsigned int i, imax; - unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0; - unsigned long rx_bytes_total = 0, tx_bytes_total = 0; - unsigned long rx_nombuf = 0, ierrors = 0; - const struct pmd_internals *pmd = dev->data->dev_private; - - /* rx queue statistics */ - imax = (dev->data->nb_rx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? - dev->data->nb_rx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS; - for (i = 0; i < imax; i++) { - tap_stats->q_ipackets[i] = pmd->rxq[i].stats.ipackets; - tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes; - rx_total += tap_stats->q_ipackets[i]; - rx_bytes_total += tap_stats->q_ibytes[i]; - rx_nombuf += pmd->rxq[i].stats.rx_nombuf; - ierrors += pmd->rxq[i].stats.ierrors; - } - - /* tx queue statistics */ - imax = (dev->data->nb_tx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? - dev->data->nb_tx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS; - - for (i = 0; i < imax; i++) { - tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets; - tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes; - tx_total += tap_stats->q_opackets[i]; - tx_err_total += pmd->txq[i].stats.errs; - tx_bytes_total += tap_stats->q_obytes[i]; - } - - tap_stats->ipackets = rx_total; - tap_stats->ibytes = rx_bytes_total; - tap_stats->ierrors = ierrors; - tap_stats->rx_nombuf = rx_nombuf; - tap_stats->opackets = tx_total; - tap_stats->oerrors = tx_err_total; - tap_stats->obytes = tx_bytes_total; - return 0; + return rte_eth_counters_stats_get(dev, offsetof(struct tx_queue, stats), + offsetof(struct rx_queue, stats), tap_stats); } static int tap_stats_reset(struct rte_eth_dev *dev) { - int i; - struct pmd_internals *pmd = dev->data->dev_private; - - for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) { - pmd->rxq[i].stats.ipackets = 0; - pmd->rxq[i].stats.ibytes = 0; - pmd->rxq[i].stats.ierrors = 0; - pmd->rxq[i].stats.rx_nombuf = 0; - - pmd->txq[i].stats.opackets = 0; - pmd->txq[i].stats.errs = 0; - pmd->txq[i].stats.obytes = 0; - } - - return 0; + return rte_eth_counters_reset(dev, offsetof(struct tx_queue, stats), + offsetof(struct rx_queue, stats)); } static int diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index 5ac93f93e9..8cba9ea410 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include "tap_log.h" @@ -32,23 +33,13 @@ enum rte_tuntap_type { ETH_TUNTAP_TYPE_MAX, }; -struct pkt_stats { - uint64_t opackets; /* Number of output packets */ - uint64_t ipackets; /* Number of input packets */ - uint64_t obytes; /* Number of bytes on output */ - uint64_t ibytes; /* Number of bytes on input */ - uint64_t errs; /* Number of TX error packets */ - uint64_t ierrors; /* Number of RX error packets */ - uint64_t rx_nombuf; /* Nb of RX mbuf alloc failures */ -}; - struct rx_queue { struct rte_mempool *mp; /* Mempool for RX packets */ uint32_t trigger_seen; /* Last seen Rx trigger value */ uint16_t in_port; /* Port ID */ uint16_t queue_id; /* queue ID*/ - struct pkt_stats stats; /* Stats for this RX queue */ uint16_t nb_rx_desc; /* max number of mbufs available */ + struct rte_eth_counters stats; /* Stats for this RX queue */ struct rte_eth_rxmode *rxmode; /* RX features */ struct rte_mbuf *pool; /* mbufs pool for this queue */ struct iovec (*iovecs)[]; /* descriptors for this queue */ @@ -59,7 +50,7 @@ struct tx_queue { int type; /* Type field - TUN|TAP */ uint16_t *mtu; /* Pointer to MTU from dev_data */ uint16_t csum:1; /* Enable checksum offloading */ - struct pkt_stats stats; /* Stats for this TX queue */ + struct rte_eth_counters stats; /* Stats for this TX queue */ struct rte_gso_ctx gso_ctx; /* GSO context */ uint16_t out_port; /* Port ID */ uint16_t queue_id; /* queue ID*/ From patchwork Wed May 22 16:12:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 140279 X-Patchwork-Delegate: thomas@monjalon.net 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 9890244099; Wed, 22 May 2024 18:15:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 751AA40A7A; Wed, 22 May 2024 18:14:51 +0200 (CEST) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mails.dpdk.org (Postfix) with ESMTP id 003C640693 for ; Wed, 22 May 2024 18:14:44 +0200 (CEST) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1ee12baa01cso11490415ad.0 for ; Wed, 22 May 2024 09:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716394484; x=1716999284; 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=x5UrdrHW9F6pfrhHclD4PQZwg1NEIRxD5Iursp/d81w=; b=Q0dWzEjXlpPzP1zJXrDPcoPquHdlFT6FgPlsUxLZxfDEK0/o2Up857AWjA9Wqv1w6x Jaxqmsa5ViArWicCWwFbH7ONYkAv7AMdK/z+F/v02B2GIIF00b6MVmaZwIBqWBmFmMAu hrU5XwnfCkLZVn8awDtBQxiXq9lriWCkoyj5XECr9nh3USUXGSAPkNGIkrFsPFbSNsAa ZFdyly+E9HQYTPQFtqoCwsxEoiDuhEOBXY7uP1D1wJ1jEtDPWhNi5/tpDPM6ndx/StFI 5tk54p2rQ7RN4OSya/5d0oZk+AaEojYyz/rAcmm7Dpghq6vsbdmzxi3IoI2yKWcv0HJ2 mbtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716394484; x=1716999284; 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=x5UrdrHW9F6pfrhHclD4PQZwg1NEIRxD5Iursp/d81w=; b=SrA6XDq5hjjXJq6le73+55gnAl4c6tn2LAF0YpRqkwJ+xpvddaq1zB3T777MPHRf6U KMW/3kTe/1EdFLHLQRVj7kdnAyfJUPGLF7kFJnm9+2bEfHiPsfxXUdPnmEL0oOitc0QQ 9fgJSKE6w4F+qU5EmBhdZNDE6Y4f4Ih9JOWupQVtnFa7wVEuzF7kp5atYQPMrKRVt5+o x8IE9pHgqRycF5zcNCqceZMtEDIGpR7ljU2Q5c3DRkLbKzvQwB91mL5PQ0m0bwpJCXS0 Uj1ogrce13mZCyqZEXJM/+RO8687rVuedtQxvOb6dksyl5dSljy4wfqSHMqizHUGJoJq gCeQ== X-Gm-Message-State: AOJu0YzLueiqig8gJKBmkVl8495rRbc50lGmqgnbyGx1yE5oOJ0Lj8Ge CqUX01qJkDWhi9VG8UT7ZL+Xosghs8I3aEMikAMGArmYwe9E7giv+yRItv0g60KoTS0kWeBGmO2 rGiw= X-Google-Smtp-Source: AGHT+IHzkMXCm6fErkqLmzk6hYSE6BZlWnFdpCyDGaIogsRhGwRzS7F0H5OxKmJOqrU5sqb7Z54HtQ== X-Received: by 2002:a17:903:2311:b0:1e3:c419:35c2 with SMTP id d9443c01a7336-1f31c9a55f5mr26141365ad.34.1716394484135; Wed, 22 May 2024 09:14:44 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f327ae4647sm13684175ad.224.2024.05.22.09.14.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 09:14:43 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tetsuya Mukawa Subject: [PATCH v10 8/8] net/null: use generic SW stats Date: Wed, 22 May 2024 09:12:32 -0700 Message-ID: <20240522161427.64568-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240522161427.64568-1-stephen@networkplumber.org> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240522161427.64568-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 Use the new common code for statistics. This also fixes the bug that this driver was not accounting for bytes. Signed-off-by: Stephen Hemminger --- drivers/net/null/rte_eth_null.c | 83 +++++++++------------------------ 1 file changed, 21 insertions(+), 62 deletions(-) diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c index f4ed3b8a7f..83add9c819 100644 --- a/drivers/net/null/rte_eth_null.c +++ b/drivers/net/null/rte_eth_null.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -37,8 +38,8 @@ struct null_queue { struct rte_mempool *mb_pool; struct rte_mbuf *dummy_packet; - RTE_ATOMIC(uint64_t) rx_pkts; - RTE_ATOMIC(uint64_t) tx_pkts; + struct rte_eth_counters tx_stats; + struct rte_eth_counters rx_stats; }; struct pmd_options { @@ -101,9 +102,7 @@ eth_null_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) bufs[i]->port = h->internals->port_id; } - /* NOTE: review for potential ordering optimization */ - rte_atomic_fetch_add_explicit(&h->rx_pkts, i, rte_memory_order_seq_cst); - + rte_eth_count_packets(&h->rx_stats, i, i * packet_size); return i; } @@ -129,8 +128,7 @@ eth_null_copy_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) bufs[i]->port = h->internals->port_id; } - /* NOTE: review for potential ordering optimization */ - rte_atomic_fetch_add_explicit(&h->rx_pkts, i, rte_memory_order_seq_cst); + rte_eth_count_packets(&h->rx_stats, i, i * packet_size); return i; } @@ -147,16 +145,17 @@ eth_null_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { int i; struct null_queue *h = q; + uint32_t tx_bytes = 0; if ((q == NULL) || (bufs == NULL)) return 0; - for (i = 0; i < nb_bufs; i++) + for (i = 0; i < nb_bufs; i++) { + tx_bytes += rte_pktmbuf_pkt_len(bufs[i]); rte_pktmbuf_free(bufs[i]); + } - /* NOTE: review for potential ordering optimization */ - rte_atomic_fetch_add_explicit(&h->tx_pkts, i, rte_memory_order_seq_cst); - + rte_eth_count_packets(&h->tx_stats, i, tx_bytes); return i; } @@ -166,20 +165,20 @@ eth_null_copy_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) int i; struct null_queue *h = q; unsigned int packet_size; + uint32_t tx_bytes = 0; if ((q == NULL) || (bufs == NULL)) return 0; packet_size = h->internals->packet_size; for (i = 0; i < nb_bufs; i++) { + tx_bytes += rte_pktmbuf_pkt_len(bufs[i]); rte_memcpy(h->dummy_packet, rte_pktmbuf_mtod(bufs[i], void *), packet_size); rte_pktmbuf_free(bufs[i]); } - /* NOTE: review for potential ordering optimization */ - rte_atomic_fetch_add_explicit(&h->tx_pkts, i, rte_memory_order_seq_cst); - + rte_eth_count_packets(&h->tx_stats, i, tx_bytes); return i; } @@ -322,60 +321,20 @@ eth_dev_info(struct rte_eth_dev *dev, } static int -eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats) +eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { - unsigned int i, num_stats; - unsigned long rx_total = 0, tx_total = 0; - const struct pmd_internals *internal; - - if ((dev == NULL) || (igb_stats == NULL)) - return -EINVAL; - - internal = dev->data->dev_private; - num_stats = RTE_MIN((unsigned int)RTE_ETHDEV_QUEUE_STAT_CNTRS, - RTE_MIN(dev->data->nb_rx_queues, - RTE_DIM(internal->rx_null_queues))); - for (i = 0; i < num_stats; i++) { - /* NOTE: review for atomic access */ - igb_stats->q_ipackets[i] = - internal->rx_null_queues[i].rx_pkts; - rx_total += igb_stats->q_ipackets[i]; - } - - num_stats = RTE_MIN((unsigned int)RTE_ETHDEV_QUEUE_STAT_CNTRS, - RTE_MIN(dev->data->nb_tx_queues, - RTE_DIM(internal->tx_null_queues))); - for (i = 0; i < num_stats; i++) { - /* NOTE: review for atomic access */ - igb_stats->q_opackets[i] = - internal->tx_null_queues[i].tx_pkts; - tx_total += igb_stats->q_opackets[i]; - } - - igb_stats->ipackets = rx_total; - igb_stats->opackets = tx_total; - - return 0; + return rte_eth_counters_stats_get(dev, + offsetof(struct null_queue, tx_stats), + offsetof(struct null_queue, rx_stats), + stats); } static int eth_stats_reset(struct rte_eth_dev *dev) { - unsigned int i; - struct pmd_internals *internal; - - if (dev == NULL) - return -EINVAL; - - internal = dev->data->dev_private; - for (i = 0; i < RTE_DIM(internal->rx_null_queues); i++) - /* NOTE: review for atomic access */ - internal->rx_null_queues[i].rx_pkts = 0; - for (i = 0; i < RTE_DIM(internal->tx_null_queues); i++) - /* NOTE: review for atomic access */ - internal->tx_null_queues[i].tx_pkts = 0; - - return 0; + return rte_eth_counters_reset(dev, + offsetof(struct null_queue, tx_stats), + offsetof(struct null_queue, rx_stats)); } static void