From patchwork Fri Jul 21 16:04:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ferruh Yigit X-Patchwork-Id: 129689 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2472842EDC; Fri, 21 Jul 2023 18:07:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A383840E2D; Fri, 21 Jul 2023 18:07:58 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by mails.dpdk.org (Postfix) with ESMTP id 8A87340DDC for ; Fri, 21 Jul 2023 18:07:57 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qj6AOhjHTgJgEC5aZHrgqb6+NcfNX5+4PwpfH06twXLNKKIR+Kc65lU2U0DtkDH6YVqenW0LBXAUo8KnoBfZJBo1l5g47zEXw+tlyRhpU5r3rn7PdiqyPsT+q7jvAsp/pXLDAdIm31eqOQ/MQY+VJFc8PZ2rPyH8JneVxfhFR8KkDF9OA693uBAzPXGjxmSnd8r/FHlQvdHPaTJA3TkVdxgEwH/rPg671SQ31ci9WkCSYlocLN8URbob25CfPcEsg07Y4cZ96rVIElXOrJ/GqbA5mnpBXKN7RqgnhPugbtAywQHp5r+pUB+Lkc6GnZsUjyGgu2Mk61x+eRGk1fG92g== 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=VXlRs+61+kTSEbjLKuNWTvNa3on9ljFSiISdQ3HC81c=; b=Pd/jzVVPsIo+xyob3eckxoma/SGjExl+6r24mVYFnVF5RK9cqTcAnj4KJGAiW5IU1mT3+5CqRGG1wVDwdpsrVGn29VmLDJWBnUIKpI1Hg0QnCOqO2vq89mR7nwBumxhK0z7zAY3wevzPHXXwe0HQuNUIq2+8ukIEtFavKaqS73DlDKqBzK4A/WuNg0b1S3ZrR+eB9op83wPrv38+cz+HrYWa5a2BaYP0ATfysi4BkfL3FVnsOHp0P/rt2xHaTFPNqmlf4bI4tDO/p7HY6qZTVpa2LZjMtiHSZuhwQpnR8kzTsBzfioaiUfaaygEFaXMj6WDJ0mL7yepLk5r8V+lBfg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=monjalon.net 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 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=VXlRs+61+kTSEbjLKuNWTvNa3on9ljFSiISdQ3HC81c=; b=n4T4wZ0BfCTRj0baM5d4qLCXdgMsW7mPLFWO7KjplfaW5kvEWEGpwjPBDsuBPNxmxmHD32weG4T82/h8myW8dZdSqQZjvK+mSsCWx94UC+Jy6RUFjpaistfY8FXGv2iXy6otTjJJ2DwGGeL1nNGhrGCKF28xMdvbeFFWDLue0kA= Received: from BN9PR03CA0677.namprd03.prod.outlook.com (2603:10b6:408:10e::22) by DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.22; Fri, 21 Jul 2023 16:07:51 +0000 Received: from BN8NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10e:cafe::cd) by BN9PR03CA0677.outlook.office365.com (2603:10b6:408:10e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.28 via Frontend Transport; Fri, 21 Jul 2023 16:07:51 +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 BN8NAM11FT013.mail.protection.outlook.com (10.13.176.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6609.28 via Frontend Transport; Fri, 21 Jul 2023 16:07:50 +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.27; Fri, 21 Jul 2023 11:07:49 -0500 From: Ferruh Yigit To: Thomas Monjalon , Andrew Rybchenko CC: , David Marchand , Jie Hai , Song Jiale , Yuan Peng , Raslan Darawsheh , Qiming Yang Subject: [RFC] ethdev: clarify device queue state after start and stop Date: Fri, 21 Jul 2023 17:04:22 +0100 Message-ID: <20230721160422.3848154-1-ferruh.yigit@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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: BN8NAM11FT013:EE_|DM6PR12MB4092:EE_ X-MS-Office365-Filtering-Correlation-Id: ed086d24-c2b2-41f7-8b9f-08db8a04a232 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O7AHrqaUIg5HuD3zOLs3b+WbunVPWAMxrFyF2/R/Jt2gsGrE8+k8l3mnrFvVSgJBpaJoU+e/Gmtjiu0ctG5nykWonjPlieex63arOiVIaw3EoiM8m2LFqa8hvz3nRU/Hi9i4UDMo2rHIN0BoYqQW/ZxO7aJdT2u2F2W7BfvE2RtOVj7jen0lvAef5fg1uGOrUHJ/kf2CGCpAN0pfXQIA8QA3Y1NNCmPojwfC7eMzZUfwoszNraDIURSIxeqKsJYrmtEs7tXnPrBLhLaGI4Hb274yhXHA6IHa6J2ZaxMNPt80nn6qwC1/zM/EETR897GWeooPx7CfTp3SP2IREMmenoQz7dg4FrAE4sn0AkdTiLCnd+g8qVJqHd/RoY/cnqdh+wijCA8DEFGejGkzPQzQpLBVqm6mLehl1/Fxoi/dPpbKyjNIETLXaG2p3ato2y1Q/uuDnPJvpKdDkInzjOD2e0VRPt/ariy6HesLtxvcNzOAwBdTfbExi/eVGVHvsUYm1g/obXeihwrYDEOmeHDoUKzuN4xzbW4vWXZWGJSdIOLTOueS/8ZJ+czpsMU4DiRpX+fmiAolr0j/VqgR1MWmOs5Eb2FATlkH7whQH6UcsQ6k0aRCgwm4fFfjE0LE9DIPRi/OuWYkt40LuRcJGFLv8vEn/9bLAEYDpte1CkCfUJUY3EgllF0FHGDIwLiIS1IzvUZXNFWL4tiEPO0GV8iF77YP/0xTnITXgg4Nd/HZx2mV9im2It0hHJdQ1JreqR6yehumobVNnC7V9Oix1pNgfW3gj2cJ1O4aGYN1zToK8MeWDuVbTc9PI6RChp5032ze 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:(13230028)(4636009)(396003)(346002)(136003)(376002)(39860400002)(82310400008)(451199021)(40470700004)(46966006)(36840700001)(478600001)(81166007)(70206006)(54906003)(86362001)(6666004)(110136005)(7696005)(4326008)(356005)(70586007)(82740400003)(316002)(83380400001)(36860700001)(41300700001)(8676002)(47076005)(8936002)(2616005)(336012)(186003)(426003)(36756003)(2906002)(40460700003)(44832011)(16526019)(1076003)(5660300002)(26005)(40480700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2023 16:07:50.8312 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed086d24-c2b2-41f7-8b9f-08db8a04a232 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: BN8NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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 Drivers start/stop device queues on port start/stop, but not all drivers update queue state accordingly. This becomes more visible if a specific queue stopped explicitly and port stopped/started later, in this case although all queues are started, the state of that specific queue is stopped and it is misleading. Misrepresentation of queue state became a defect with commit [1] that does forwarding decision based on queue state and commit [2] that gets up to date queue state from ethdev/device before forwarding. This patch documents that status of all queues of a device should be `RTE_ETH_QUEUE_STATE_STOPPED` after port stop and their status should be`RTE_ETH_QUEUE_STATE_STARTED` after port start. Also an unit test added to verify drivers. Signed-off-by: Ferruh Yigit --- Cc: Jie Hai Cc: Song Jiale Cc: Yuan Peng Cc: Raslan Darawsheh Cc: Qiming Yang --- app/test/meson.build | 2 + app/test/test_ethdev_api.c | 169 +++++++++++++++++++++++++++++++++++++ lib/ethdev/rte_ethdev.h | 5 ++ 3 files changed, 176 insertions(+) create mode 100644 app/test/test_ethdev_api.c diff --git a/app/test/meson.build b/app/test/meson.build index b89cf0368fb5..8e409cf59c35 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -49,6 +49,7 @@ test_sources = files( 'test_efd_perf.c', 'test_errno.c', 'test_ethdev_link.c', + 'test_ethdev_api.c', 'test_event_crypto_adapter.c', 'test_event_eth_rx_adapter.c', 'test_event_ring.c', @@ -187,6 +188,7 @@ fast_tests = [ ['eal_fs_autotest', true, true], ['errno_autotest', true, true], ['ethdev_link_status', true, true], + ['ethdev_api', true, true], ['event_ring_autotest', true, true], ['fib_autotest', true, true], ['fib6_autotest', true, true], diff --git a/app/test/test_ethdev_api.c b/app/test/test_ethdev_api.c new file mode 100644 index 000000000000..1b4569396dda --- /dev/null +++ b/app/test/test_ethdev_api.c @@ -0,0 +1,169 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (C) 2023, Advanced Micro Devices, Inc. + */ + +#include +#include + +#include +#include "test.h" + +#define NUM_RXQ 2 +#define NUM_TXQ 2 +#define NUM_RXD 512 +#define NUM_TXD 512 +#define NUM_MBUF 1024 +#define MBUF_CACHE_SIZE 256 + +static int32_t +ethdev_api_queue_status(void) +{ + struct rte_eth_dev_info dev_info; + struct rte_eth_rxq_info rx_qinfo; + struct rte_eth_txq_info tx_qinfo; + struct rte_mempool *mbuf_pool; + /*struct rte_eth_rxconf rx_conf;*/ + /*struct rte_eth_txconf tx_conf;*/ + struct rte_eth_conf eth_conf; + uint16_t port_id; + int ret; + + mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUF, MBUF_CACHE_SIZE, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + + RTE_ETH_FOREACH_DEV(port_id) { + memset(ð_conf, 0, sizeof(dev_info)); + ret = rte_eth_dev_configure(port_id, NUM_RXQ, NUM_TXQ, ð_conf); + TEST_ASSERT(ret == 0, + "Port(%u) failed to configure.\n", port_id); + + /* RxQ setup */ + /*memset(&rx_conf, 0, sizeof(rx_conf));*/ + for (uint16_t queue_id = 0; queue_id < NUM_RXQ; queue_id++) { + ret = rte_eth_rx_queue_setup(port_id, queue_id, NUM_RXD, + rte_socket_id(), NULL, mbuf_pool); + TEST_ASSERT(ret == 0, + "Port(%u), queue(%u) failed to setup RxQ.\n", + port_id, queue_id); + } + + /* TxQ setup */ + /*memset(&tx_conf, 0, sizeof(tx_conf));*/ + for (uint16_t queue_id = 0; queue_id < NUM_TXQ; queue_id++) { + ret = rte_eth_tx_queue_setup(port_id, queue_id, NUM_TXD, + rte_socket_id(), NULL); + TEST_ASSERT(ret == 0, + "Port(%u), queue(%u) failed to setup TxQ.\n", + port_id, queue_id); + } + + ret = rte_eth_dev_info_get(port_id, &dev_info); + TEST_ASSERT(ret == 0, + "Port(%u) failed to get dev info.\n", port_id); + + /* Initial RxQ */ + for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) { + ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo); + TEST_ASSERT(ret == 0, + "Port(%u), queue(%u) failed to get RxQ info.\n", + port_id, queue_id); + + TEST_ASSERT(rx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED, + "Wrong initial Rx queue(%u) state(%d)\n", + queue_id, rx_qinfo.queue_state); + } + + /* Initial TxQ */ + for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) { + ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo); + TEST_ASSERT(ret == 0, + "Port(%u), queue(%u) failed to get TxQ info.\n", + port_id, queue_id); + + TEST_ASSERT(tx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED, + "Wrong initial Tx queue(%u) state(%d)\n", + queue_id, tx_qinfo.queue_state); + } + + + ret = rte_eth_dev_start(port_id); + TEST_ASSERT(ret == 0, + "Port(%u) failed to start.\n", port_id); + + /* Started RxQ */ + for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) { + ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo); + TEST_ASSERT(ret == 0, + "Port(%u), queue(%u) failed to get RxQ info.\n", + port_id, queue_id); + + TEST_ASSERT(rx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STARTED, + "Wrong started Rx queue(%u) state(%d)\n", + queue_id, rx_qinfo.queue_state); + } + + /* Started TxQ */ + for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) { + ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo); + TEST_ASSERT(ret == 0, + "Port(%u), queue(%u) failed to get TxQ info.\n", + port_id, queue_id); + + TEST_ASSERT(tx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STARTED, + "Wrong started Tx queue(%u) state(%d)\n", + queue_id, tx_qinfo.queue_state); + } + + + ret = rte_eth_dev_stop(port_id); + TEST_ASSERT(ret == 0, + "Port(%u) failed to stop.\n", port_id); + + /* Stopped RxQ */ + for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) { + ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo); + TEST_ASSERT(ret == 0, + "Port(%u), queue(%u) failed to get RxQ info.\n", + port_id, queue_id); + + TEST_ASSERT(rx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED, + "Wrong stopped Rx queue(%u) state(%d)\n", + queue_id, rx_qinfo.queue_state); + } + + /* Stopped TxQ */ + for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) { + ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo); + TEST_ASSERT(ret == 0, + "Port(%u), queue(%u) failed to get TxQ info.\n", + port_id, queue_id); + + TEST_ASSERT(tx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED, + "Wrong stopped Tx queue(%u) state(%d)\n", + queue_id, tx_qinfo.queue_state); + } + } + + return TEST_SUCCESS; +} + +static struct unit_test_suite ethdev_api_testsuite = { + .suite_name = "ethdev API tests", + .setup = NULL, + .teardown = NULL, + .unit_test_cases = { + TEST_CASE(ethdev_api_queue_status), + TEST_CASES_END() /**< NULL terminate unit test array */ + } +}; + +static int +test_ethdev_api(void) +{ + rte_log_set_global_level(RTE_LOG_DEBUG); + rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG); + + return unit_test_suite_runner(ðdev_api_testsuite); +} + +REGISTER_TEST_COMMAND(ethdev_api, test_ethdev_api); diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 3d44979b44f7..8f2e0f158cc4 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -2788,6 +2788,9 @@ int rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id); * Device RTE_ETH_DEV_NOLIVE_MAC_ADDR flag causes MAC address to be set before * PMD port start callback function is invoked. * + * All device queues (except form deferred queues) status should be + * `RTE_ETH_QUEUE_STATE_STARTED` after start. + * * On success, all basic functions exported by the Ethernet API (link status, * receive/transmit, and so on) can be invoked. * @@ -2804,6 +2807,8 @@ int rte_eth_dev_start(uint16_t port_id); * Stop an Ethernet device. The device can be restarted with a call to * rte_eth_dev_start() * + * All device queues status should be `RTE_ETH_QUEUE_STATE_STOPPED` after stop. + * * @param port_id * The port identifier of the Ethernet device. * @return