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 9917B43F06; Thu, 25 Apr 2024 19:46:35 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 64C65438F3; Thu, 25 Apr 2024 19:46:35 +0200 (CEST) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2082.outbound.protection.outlook.com [40.107.102.82]) by mails.dpdk.org (Postfix) with ESMTP id C4EB1438DA for ; Thu, 25 Apr 2024 19:46:33 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VFKSprRAs3TtSOed193LBScUKWK8xotZBA3CLhJCr2XRH/ZU5eu6g3DJFvz82icolJx+IiKIVLjOwNKayh9YjN32FzOI81G5TIHgfOnGc2cjIkMJK2vCz7/bo2p4hw5C+Z3NRHye3D75ZqW9QgkNYM9fkfiG/WECCGF/l5pM0FN14g7LKGvoblHtMSgSipJqFEwHseldOs97eq09oyGijp2z1n1odNqhZZtwK1TXFp7X29818xWOq2sawkgchygkhAmUF8CsR6abmJQUQ4gEFQ71WQRQ834zYiUefhv1OGoleRjDGvEQ2mHj7hMxfIrPs8NYrHVB4UhqsLUUhRkzng== 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=Q+TYHv5kzrPngSwDrYcDAuJDAWJgNRvF5eIYJuFYzQ0=; b=RQhvZmFdv+iW7O6qO34m5RUhEAgMgLkC5ur4lGolN7nH4Fmskw/waHzl7xCMRm6SWCwfQUE2IpbVSS7VSG1b0XngDRaGltPcYXESe2Ic95gD3snKKFipk09yAhwELi9K0t5W3qaS61pL/V/xuqYERmc4WLwOe2uovvJujoJN4NnxR/s8aV5mKXQXnLG3MRVms0QCwHwlEqqXDi8YxqEKm91M2AtyHmpMt8F5OeMu2j2WJIFNvTEhqq3MpU0zuFcHOfnoUXcCIjRMx6n9stF3V3sCcyltg6oUO5PQT17pFrVKwtGTYjn/65gTwtYIO20juAIaRwk25euXu7096uXKcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=temperror (sender ip is 165.204.84.17) smtp.rcpttodomain=tuxdriver.com smtp.mailfrom=amd.com; dmarc=temperror 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=Q+TYHv5kzrPngSwDrYcDAuJDAWJgNRvF5eIYJuFYzQ0=; b=37IRbcvqmzRCuHVM6Mj6+bEqp9eq8ASZAOZxTgWZWA7/SYmTu2ffYx1SXC3Y/D+NF/ZzurePXsteFVNeBcdya3lLQIL8ZJBNhqDmADbVy0ZTDzrupDWq+G3NlvmgBDvPJsD5YeZPGWq1iMa96cC3qqux8ddwAJgfx6JcW8TfSw8= Received: from CH0PR04CA0045.namprd04.prod.outlook.com (2603:10b6:610:77::20) by CH3PR12MB8305.namprd12.prod.outlook.com (2603:10b6:610:12e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Thu, 25 Apr 2024 17:46:29 +0000 Received: from CH3PEPF00000011.namprd21.prod.outlook.com (2603:10b6:610:77:cafe::50) by CH0PR04CA0045.outlook.office365.com (2603:10b6:610:77::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.27 via Frontend Transport; Thu, 25 Apr 2024 17:46:29 +0000 X-MS-Exchange-Authentication-Results: spf=temperror (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=temperror action=none header.from=amd.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of amd.com: DNS Timeout) Received: from SATLEXMB04.amd.com (165.204.84.17) by CH3PEPF00000011.mail.protection.outlook.com (10.167.244.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.0 via Frontend Transport; Thu, 25 Apr 2024 17:46:27 +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; Thu, 25 Apr 2024 12:46:26 -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] net/af_packet: make stats reset reliable Date: Thu, 25 Apr 2024 18:46:17 +0100 Message-ID: <20240425174617.2126159-1-ferruh.yigit@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF00000011:EE_|CH3PR12MB8305:EE_ X-MS-Office365-Filtering-Correlation-Id: bb4bd61c-a07b-459d-d93a-08dc654fa258 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?utf-8?B?QzZSeHlHWEZLMkpmYzlKeVE0akpkbnZnb3N0TUx2bkl3ak1Td2UyemtWVjBm?= =?ut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H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(82310400014)(1800799015)(376005)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2024 17:46:27.9696 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb4bd61c-a07b-459d-d93a-08dc654fa258 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: CH3PEPF00000011.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8305 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/ --- drivers/net/af_packet/rte_eth_af_packet.c | 69 +++++++++++++++-------- 1 file changed, 44 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..2061cdab4997 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,18 @@ 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) +{ + if (stats >= offset) + return stats - offset; + /* unlikely wraparound case */ + return UINT64_MAX + 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 +411,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 +444,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