From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B31E543F17; Fri, 26 Apr 2024 16:39:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 38A4343E57; Fri, 26 Apr 2024 16:39:02 +0200 (CEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2058.outbound.protection.outlook.com [40.107.220.58]) by mails.dpdk.org (Postfix) with ESMTP id 4466943E53 for ; Fri, 26 Apr 2024 16:39:00 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=anrd63RM2vMZ/VJX7TR3bSihCyx0OSH9Te2EInqQn2t00yS86Hx3GCImEN5Z7NHBIobfra6v/iUokEZg2lYspVeUPP4ZXjZdlm8AyU2+j4VsMQAboa+WWIEu/k26ePah1vkWU+D6tweTCxNcVytu8u7C2FAG72va5pezKkbQcck7upN1hDrS7a/RovZWZnd94ExAgJfun1HgkaCd0q06gWrC1o/M0WhB3zHFyE6r4qFQtZETUxBpetoHtnh81RHw0YzmFg8HyX9hhp2/S2nSnVCSnFsddRFYVuaNC0twpy+DpqId7S2bAxz53cBoUSI+aOIYS2qw9gSEfU5jGnwXJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H9c7r1CntggnX0Qz0EHJ04o90xFFx7VzbE7QZjhgcHc=; b=cYf+9NuUSy1NCYefKBAQI8gPpkP2MSd3nNiwx0dln+D13e4yPGqAJh/YxJaQf+N5+uuJ670vTMTgoyBkGiUgCGlVHLZjdphlhFl7KyKNOhCRtdz8Vy/io/K5YoM+5gzW2aAphuwNHm6p8P/hAa58NDU8ZLFxaluS9Mh1TGH6nqehhRNDd4bO5tZuQL34imokI2+hcS8guKwnKOnFpWmQ8Rk1R8+n0DwuCXDPawUGJeEEeXBuC0Z5Ry5Fgh1IJ5t+1ADeFVuHLexQOSXMJPTkpVtzUx5VaXMpe4Eeg3vLFnGcA1O7nhoDK97sYy5B6JheHV5xvbyp6Ou49vIeDdVTtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=tuxdriver.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H9c7r1CntggnX0Qz0EHJ04o90xFFx7VzbE7QZjhgcHc=; b=FWTCUMllTgTOActdZkdKvCEmtTOnIfK+eZIHOFDCLN4FN7MCNqxvGRayWksskCM+ryHsWknTSHLC2vMyZF9MkWdIsua7qprV6ISAClD3UTlD5DL1UYNE9/EBL99Q6fGUrkjIgfM7fXZHOqjdXH4B/CzVZDVThjIrXOvruFhFqCI= Received: from DS0PR17CA0013.namprd17.prod.outlook.com (2603:10b6:8:191::11) by PH0PR12MB7791.namprd12.prod.outlook.com (2603:10b6:510:280::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22; Fri, 26 Apr 2024 14:38:57 +0000 Received: from DS1PEPF00017090.namprd03.prod.outlook.com (2603:10b6:8:191:cafe::df) by DS0PR17CA0013.outlook.office365.com (2603:10b6:8:191::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.29 via Frontend Transport; Fri, 26 Apr 2024 14:38:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017090.mail.protection.outlook.com (10.167.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Fri, 26 Apr 2024 14:38:56 +0000 Received: from telcodpdk.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 26 Apr 2024 09:38:55 -0500 From: Ferruh Yigit To: "John W. Linville" CC: Thomas Monjalon , , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= , Stephen Hemminger , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [RFC v2] net/af_packet: make stats reset reliable Date: Fri, 26 Apr 2024 15:38:48 +0100 Message-ID: <20240426143848.2280689-1-ferruh.yigit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240425174617.2126159-1-ferruh.yigit@amd.com> References: <20240425174617.2126159-1-ferruh.yigit@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017090:EE_|PH0PR12MB7791:EE_ X-MS-Office365-Filtering-Correlation-Id: d07c1b15-1684-4547-a131-08dc65fe9ab1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|1800799015|376005|36860700004|82310400014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?YmdtWERRTGQzQ1U4NHF0cXN0MXVSb2tOQ1NlV292djBVSkFoMmswcGJxNUtR?= =?utf-8?B?UGpoZjUyT2RCR3lmTjVDVFJVRk5JaXUzcGROSXBvdDJrdWxWVmFYTW5jRERF?= =?utf-8?B?YUNzY1RKU2lpMktkcU5uK1NCWEtKNFdLUGhDTllMTWpiaG5IRmdSaUhUQlQy?= =?utf-8?B?cEpqUUtTQmVKTHh4bkUyZUpGeGdZTW9YYWVJQ1BzOENOTmxycFZtUUFNdFIy?= =?utf-8?B?TjZjS0k5alBRd045aG54U3FEMitSWDhvTElTRlJxKzE5d2pQbmg0Szk3a05a?= =?utf-8?B?QW9hUTR6V0RCZlpKMnF5cysyUC9SQjFUdy8zNlJWWUptRnBLcDVuZW9xVjJB?= =?utf-8?B?QTNJMm5UYjUrcCtXeHJPTmxFYzhHOW5GSE1McU81L1IyeEdvODZ0VWtmSzYz?= =?utf-8?B?Z0pDcmZ1UFpkWHU3YU9zWkc3VTdpdEdjc3FWVEd3ZDFZdGhSU3FLS0VPS25i?= =?utf-8?B?MENESC9EdTlNZzVKZHY3dStCK3NnVmJXR2lXNS9XSHVmRmVtLzVDaWNCblFa?= =?utf-8?B?L3lGRzFCU3ppVDRocTdncHczMXlqVTRFemJFWnpiL1pEdXNzaGVTYVZkYU1s?= =?utf-8?B?clI3V1F1cDdqcEtUWnk1K3dHU2kyU2lCYndHWXdrL0pVTnBvYVlKR3ZSdEZP?= =?utf-8?B?N284NnBLL3lKYzhhVHV5Qm5GUUJlK2RqZjlubkRHaUNGd296dFpTT05xVS82?= =?utf-8?B?Yk85RzNIMVZSZWRjSzM5QWlIbkFJa2RTVkcwMTZiOURjckJoZnNVOXIvWk5Z?= =?utf-8?B?TTVnNEE0Vk14T1dnZTBKcGJiZkkvWDhzTVM0QU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SDFsRkU2UVRnSUtuWEZtUTh4bTVVNEdo?= =?utf-8?Q?Pt1UNiplnXHn1fsnw5ei83LUkdCp/U7B7Yvr8iS?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(1800799015)(376005)(36860700004)(82310400014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2024 14:38:56.9636 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d07c1b15-1684-4547-a131-08dc65fe9ab1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017090.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7791 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 For stats reset, use an offset instead of zeroing out actual stats values, get_stats() displays diff between stats and offset. This way stats only updated in datapath and offset only updated in stats reset function. This makes stats reset function more reliable. As stats only written by single thread, we can remove 'volatile' qualifier which should improve the performance in datapath. Signed-off-by: Ferruh Yigit --- Cc: Mattias Rönnblom Cc: Stephen Hemminger Cc: Morten Brørup This update triggered by mail list discussion [1]. [1] https://inbox.dpdk.org/dev/3b2cf48e-2293-4226-b6cd-5f4dd3969f99@lysator.liu.se/ v2: * Remove wrapping check for stats --- drivers/net/af_packet/rte_eth_af_packet.c | 66 ++++++++++++++--------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 397a32db5886..10c8e1e50139 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -51,8 +51,10 @@ struct pkt_rx_queue { uint16_t in_port; uint8_t vlan_strip; - volatile unsigned long rx_pkts; - volatile unsigned long rx_bytes; + uint64_t rx_pkts; + uint64_t rx_bytes; + uint64_t rx_pkts_offset; + uint64_t rx_bytes_offset; }; struct pkt_tx_queue { @@ -64,9 +66,12 @@ 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; + uint64_t tx_pkts; + uint64_t err_pkts; + uint64_t tx_bytes; + uint64_t tx_pkts_offset; + uint64_t err_pkts_offset; + uint64_t tx_bytes_offset; }; struct pmd_internals { @@ -385,8 +390,15 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) return 0; } + +static uint64_t +stats_get_diff(uint64_t stats, uint64_t offset) +{ + return stats - offset; +} + 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; @@ -396,27 +408,29 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats) 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]; + struct pkt_rx_queue *rxq = &internal->rx_queue[i]; + stats->q_ipackets[i] = stats_get_diff(rxq->rx_pkts, rxq->rx_pkts_offset); + stats->q_ibytes[i] = stats_get_diff(rxq->rx_bytes, rxq->rx_bytes_offset); + rx_total += stats->q_ipackets[i]; + rx_bytes_total += 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]; + struct pkt_tx_queue *txq = &internal->tx_queue[i]; + stats->q_opackets[i] = stats_get_diff(txq->tx_pkts, txq->tx_pkts_offset); + stats->q_obytes[i] = stats_get_diff(txq->tx_bytes, txq->tx_bytes_offset); + tx_total += stats->q_opackets[i]; + tx_err_total += stats_get_diff(txq->err_pkts, txq->err_pkts_offset); + tx_bytes_total += 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; + stats->ipackets = rx_total; + stats->ibytes = rx_bytes_total; + stats->opackets = tx_total; + stats->oerrors = tx_err_total; + stats->obytes = tx_bytes_total; return 0; } @@ -427,14 +441,16 @@ eth_stats_reset(struct rte_eth_dev *dev) 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; + struct pkt_rx_queue *rxq = &internal->rx_queue[i]; + rxq->rx_pkts_offset = rxq->rx_pkts; + rxq->rx_bytes_offset = rxq->rx_bytes; } 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; + struct pkt_tx_queue *txq = &internal->tx_queue[i]; + txq->tx_pkts_offset = txq->tx_pkts; + txq->err_pkts_offset = txq->err_pkts; + txq->tx_bytes_offset = txq->tx_bytes; } return 0; -- 2.34.1