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 7FFB8A0C45; Tue, 19 Oct 2021 00:44:28 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 02526410F1; Tue, 19 Oct 2021 00:44:19 +0200 (CEST) Received: from AZHDRRW-EX02.NVIDIA.COM (azhdrrw-ex02.nvidia.com [20.64.145.131]) by mails.dpdk.org (Postfix) with ESMTP id 54A89410EE for ; Tue, 19 Oct 2021 00:44:16 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.101) by mxs.oss.nvidia.com (10.13.234.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.15; Mon, 18 Oct 2021 15:44:15 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SX9gywkFUVe0iF6fg2yfmDpYzrdtEgH2WT/BHt4cS+cg/OkogTTO7FzxNSqTS/y8KplLcVSslAtSmo9zejytIyZ7uX9dw5Yqoly5EjbQDKP7jTT812bvB7dT5QJZ4f1H4mWJ8Txp29RSl3kpuTZ2BeGA9iaP/Z9nbJ1zKT4dhdvJKMiFOUVYSbYh59Z6rydqJccmf4rIEizV8Z1G4S8y/vYGDUPQIii7z+Gob8oQ4Wp/EpXitwjQ4iJxu+pDkXp/TtMDzfSzDKHITS4/nhNsg7GyBR0D6AhxlKQFZiHdDUMDc6L/pgxf6f3D2ajhrax4mMhhz1/Gi8dWvUWV/IsYqA== 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=qRQ2QiynoYpjyUmcPtAf4JDTcZgZwFjK+PxH2r54IeU=; b=VROFk2xk3XQMSfzXrfNS1Kd/3hmxYw9CKnNuHBgDYPKUu6Clp5PssgwPFuSu+5ARD0lp9NVrOx/be94yxq6++w9jQ/7gdoRCut8QKfx1oqxJnL6AtFGXDGCieRh9vtbGAji5IGrnYH4cdbhNGFMrChSW9s8Vml2Yu273Uu0808K7P+eeRq5QEOlv8oCErN/MFfCggas+p96tO01kjgwpksKhRkDH4GvzDAFZgJuyEGjG54Xkj1qTFhBJvXlTjmzCxjVaAetwJkHLE68i3NUzm7QnlK4sOXkY5svibAkn999V/Wu7Rg7r4bxe5Ou8DNhLJf2x6dXFcxLAPMEdeA1eCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qRQ2QiynoYpjyUmcPtAf4JDTcZgZwFjK+PxH2r54IeU=; b=awQGusqogDy//qCtFpl5/9cWuDvr4nYGksrbYyJUQgq6vrwl2F+d07Ey52mjdRz32jt1/wbjAtuRANCbJTEc6pNQ341FaBm7aRq6eTtkRUiieYY2jmBkCjdEsiWSFtEEdg3zZXzps5cTyDGT7kNsA11cQyzQY9kmqWDYlr+szggDEviXTvbe4wOOyYsbM87SYLdcLMWHKrmwXeY7ZGd4nCDyGB9TAnBixRY7NrWSC5r2+7Hr10Ik73BTEpf9Rggdg+mORVODXzRzJeRUFAer+YLGFmRhUWTnZJGE9z46g28JBaFnwsxGypd218XVOJ3pcXsy5vTsVMD6vBtdSBmMNQ== Received: from DM3PR08CA0018.namprd08.prod.outlook.com (2603:10b6:0:52::28) by BN8PR12MB3283.namprd12.prod.outlook.com (2603:10b6:408:9f::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15; Mon, 18 Oct 2021 22:44:14 +0000 Received: from DM6NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:0:52:cafe::f6) by DM3PR08CA0018.outlook.office365.com (2603:10b6:0:52::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Mon, 18 Oct 2021 22:44:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT056.mail.protection.outlook.com (10.13.173.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Mon, 18 Oct 2021 22:44:13 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 18 Oct 2021 22:44:10 +0000 From: Dmitry Kozlyuk To: CC: David Marchand , Matan Azrad , Andrew Rybchenko , "Maryam Tahhan" , Reshma Pattan , Olivier Matz Date: Tue, 19 Oct 2021 01:43:51 +0300 Message-ID: <20211018224353.3362537-3-dkozlyuk@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018224353.3362537-1-dkozlyuk@nvidia.com> References: <20211018144059.3303406-1-dkozlyuk@nvidia.com> <20211018224353.3362537-1-dkozlyuk@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f06ae43d-070a-4a8b-91ad-08d99288cf68 X-MS-TrafficTypeDiagnostic: BN8PR12MB3283: X-Microsoft-Antispam-PRVS: X-MS-Exchange-Transport-Forked: True X-MS-Oob-TLC-OOBClassifiers: OLM:1443; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z0ZzkYEtAmhOWcFuNVkVDawTU/Eu9HcBzB1AcihtqLtSa5MwhA8AU6C4tmeBuo8C2p/uz9fQN+wiFTcnTfahsmWFLETtNXtIYcBi67YLsUBPotXCseL/j2Bnxb8jpN8a8gOQcrgk/zgm4pYYJd844yKiyBVuxRC/aD3N4Cq8C+oInFi8VmdX3FZn2QbmE1deuHVI3mfrJNSfK+neePAst3pcvHTMEKK56Qqc4s7Gb3EU8nZahT0TCNcio5LrwrDL9bPzQLQbBSOYTb427YYiiZPwc7ouwNUEFIELeWB9xWX68Z62/6DGYNQ+1a5xKiqBHSNqDo18NxFWJRm2BTqfLf5MFSR+LQoz1WCIJ6pl2emMTMwJDky8UuyBotE1q8mHbxUoW/uq98glMSHSgcX6itPWzVDU8Wifojxrqb9I81V7iXG9xNowRFu2xSMpgCN6l0Z/12QV/wpZ4znzaAAQbW0Fc9po6suRPe/7N2CRRy2vSMw1t5aw1CPnq3MqYRX/MATFg33jbntk7+EsqvlTdjFzODANg7ZI0xamWvuwxF3SwAJOPHzGkp4Yedg5Buh3xDVyngESb/0nfjhrk+x5pSAlPkm+4lK+EZljNohfTtBjEhzcnkeUdYr8rHUVAkQFGOzNzjx8Jd3PuffVA9BcVlJxhqFC5WZ9pvqm2f98mhWFSj9PtJaEThQfvUZz7eeTtqV0V1WRbpoZ9mTxpDSJ/ixHp0A/Zicj2b2psKgz92/GnIAP0FVJvhCAaHiCAt0d93I/zksPO69qLq1euir1Xbxpq7Mhd0+bxDCSSaFxcUI= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(7636003)(36756003)(7696005)(8936002)(26005)(5660300002)(6916009)(55016002)(83380400001)(8676002)(2616005)(47076005)(86362001)(36860700001)(107886003)(356005)(336012)(4326008)(2906002)(6666004)(426003)(16526019)(508600001)(1076003)(54906003)(6286002)(966005)(70206006)(36906005)(316002)(70586007)(186003)(82310400003); DIR:OUT; SFP:1101; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2021 22:44:13.7593 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f06ae43d-070a-4a8b-91ad-08d99288cf68 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3283 Subject: [dpdk-dev] [PATCH v9 2/4] mempool: add non-IO flag 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 Sender: "dev" Mempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add MEMPOOL_F_NON_IO flag to mark such mempools automatically a) if their objects are not contiguous; b) if IOVA is not available for any object. Other components can inspect this flag in order to optimize their memory management. Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.html Signed-off-by: Dmitry Kozlyuk Acked-by: Matan Azrad Reviewed-by: Andrew Rybchenko --- app/proc-info/main.c | 6 +- app/test/test_mempool.c | 115 +++++++++++++++++++++++++ doc/guides/rel_notes/release_21_11.rst | 3 + lib/mempool/rte_mempool.c | 10 +++ lib/mempool/rte_mempool.h | 2 + 5 files changed, 134 insertions(+), 2 deletions(-) diff --git a/app/proc-info/main.c b/app/proc-info/main.c index a8e928fa9f..8ec9cadd79 100644 --- a/app/proc-info/main.c +++ b/app/proc-info/main.c @@ -1295,7 +1295,8 @@ show_mempool(char *name) "\t -- No cache align (%c)\n" "\t -- SP put (%c), SC get (%c)\n" "\t -- Pool created (%c)\n" - "\t -- No IOVA config (%c)\n", + "\t -- No IOVA config (%c)\n" + "\t -- Not used for IO (%c)\n", ptr->name, ptr->socket_id, (flags & MEMPOOL_F_NO_SPREAD) ? 'y' : 'n', @@ -1303,7 +1304,8 @@ show_mempool(char *name) (flags & MEMPOOL_F_SP_PUT) ? 'y' : 'n', (flags & MEMPOOL_F_SC_GET) ? 'y' : 'n', (flags & MEMPOOL_F_POOL_CREATED) ? 'y' : 'n', - (flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n'); + (flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n', + (flags & MEMPOOL_F_NON_IO) ? 'y' : 'n'); printf(" - Size %u Cache %u element %u\n" " - header %u trailer %u\n" " - private data size %u\n", diff --git a/app/test/test_mempool.c b/app/test/test_mempool.c index 5339a4cbd8..f4947680bc 100644 --- a/app/test/test_mempool.c +++ b/app/test/test_mempool.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -729,6 +730,112 @@ test_mempool_events_safety(void) #pragma pop_macro("RTE_TEST_TRACE_FAILURE") } +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE(...) do { \ + ret = TEST_FAILED; \ + goto exit; \ + } while (0) + +static int +test_mempool_flag_non_io_set_when_no_iova_contig_set(void) +{ + struct rte_mempool *mp = NULL; + int ret; + + mp = rte_mempool_create_empty("empty", MEMPOOL_SIZE, + MEMPOOL_ELT_SIZE, 0, 0, + SOCKET_ID_ANY, MEMPOOL_F_NO_IOVA_CONTIG); + RTE_TEST_ASSERT_NOT_NULL(mp, "Cannot create mempool: %s", + rte_strerror(rte_errno)); + rte_mempool_set_ops_byname(mp, rte_mbuf_best_mempool_ops(), NULL); + ret = rte_mempool_populate_default(mp); + RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s", + rte_strerror(-ret)); + RTE_TEST_ASSERT(mp->flags & MEMPOOL_F_NON_IO, + "NON_IO flag is not set when NO_IOVA_CONTIG is set"); + ret = TEST_SUCCESS; +exit: + rte_mempool_free(mp); + return ret; +} + +static int +test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void) +{ + void *virt = NULL; + rte_iova_t iova; + size_t total_size = MEMPOOL_ELT_SIZE * MEMPOOL_SIZE; + size_t block_size = total_size / 3; + struct rte_mempool *mp = NULL; + int ret; + + /* + * Since objects from the pool are never used in the test, + * we don't care for contiguous IOVA, on the other hand, + * reiuring it could cause spurious test failures. + */ + virt = rte_malloc("test_mempool", total_size, rte_mem_page_size()); + RTE_TEST_ASSERT_NOT_NULL(virt, "Cannot allocate memory"); + iova = rte_mem_virt2iova(virt); + RTE_TEST_ASSERT_NOT_EQUAL(iova, RTE_BAD_IOVA, "Cannot get IOVA"); + mp = rte_mempool_create_empty("empty", MEMPOOL_SIZE, + MEMPOOL_ELT_SIZE, 0, 0, + SOCKET_ID_ANY, 0); + RTE_TEST_ASSERT_NOT_NULL(mp, "Cannot create mempool: %s", + rte_strerror(rte_errno)); + + ret = rte_mempool_populate_iova(mp, RTE_PTR_ADD(virt, 1 * block_size), + RTE_BAD_IOVA, block_size, NULL, NULL); + RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s", + rte_strerror(-ret)); + RTE_TEST_ASSERT(mp->flags & MEMPOOL_F_NON_IO, + "NON_IO flag is not set when mempool is populated with only RTE_BAD_IOVA"); + + ret = rte_mempool_populate_iova(mp, virt, iova, block_size, NULL, NULL); + RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s", + rte_strerror(-ret)); + RTE_TEST_ASSERT(!(mp->flags & MEMPOOL_F_NON_IO), + "NON_IO flag is not unset when mempool is populated with valid IOVA"); + + ret = rte_mempool_populate_iova(mp, RTE_PTR_ADD(virt, 2 * block_size), + RTE_BAD_IOVA, block_size, NULL, NULL); + RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s", + rte_strerror(-ret)); + RTE_TEST_ASSERT(!(mp->flags & MEMPOOL_F_NON_IO), + "NON_IO flag is set even when some objects have valid IOVA"); + ret = TEST_SUCCESS; + +exit: + rte_mempool_free(mp); + rte_free(virt); + return ret; +} + +static int +test_mempool_flag_non_io_unset_by_default(void) +{ + struct rte_mempool *mp; + int ret; + + mp = rte_mempool_create_empty("empty", MEMPOOL_SIZE, + MEMPOOL_ELT_SIZE, 0, 0, + SOCKET_ID_ANY, 0); + RTE_TEST_ASSERT_NOT_NULL(mp, "Cannot create mempool: %s", + rte_strerror(rte_errno)); + ret = rte_mempool_populate_default(mp); + RTE_TEST_ASSERT_EQUAL(ret, (int)mp->size, "Failed to populate mempool: %s", + rte_strerror(-ret)); + RTE_TEST_ASSERT(!(mp->flags & MEMPOOL_F_NON_IO), + "NON_IO flag is set by default"); + ret = TEST_SUCCESS; +exit: + rte_mempool_free(mp); + return ret; +} + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") + static int test_mempool(void) { @@ -914,6 +1021,14 @@ test_mempool(void) if (test_mempool_events_safety() < 0) GOTO_ERR(ret, err); + /* test NON_IO flag inference */ + if (test_mempool_flag_non_io_unset_by_default() < 0) + GOTO_ERR(ret, err); + if (test_mempool_flag_non_io_set_when_no_iova_contig_set() < 0) + GOTO_ERR(ret, err); + if (test_mempool_flag_non_io_unset_when_populated_with_valid_iova() < 0) + GOTO_ERR(ret, err); + rte_mempool_list_dump(stdout); ret = 0; diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index d5435a64aa..f6bb5adeff 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -237,6 +237,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes ----------- diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c index 8810d08ab5..7d7d97d85d 100644 --- a/lib/mempool/rte_mempool.c +++ b/lib/mempool/rte_mempool.c @@ -372,6 +372,10 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, STAILQ_INSERT_TAIL(&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; + /* At least some objects in the pool can now be used for IO. */ + if (iova != RTE_BAD_IOVA) + mp->flags &= ~MEMPOOL_F_NON_IO; + /* Report the mempool as ready only when fully populated. */ if (mp->populated_size >= mp->size) mempool_event_callback_invoke(RTE_MEMPOOL_EVENT_READY, mp); @@ -851,6 +855,12 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, return NULL; } + /* + * No objects in the pool can be used for IO until it's populated + * with at least some objects with valid IOVA. + */ + flags |= MEMPOOL_F_NON_IO; + /* "no cache align" imply "no spread" */ if (flags & MEMPOOL_F_NO_CACHE_ALIGN) flags |= MEMPOOL_F_NO_SPREAD; diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h index 5799d4a705..b2e20c8855 100644 --- a/lib/mempool/rte_mempool.h +++ b/lib/mempool/rte_mempool.h @@ -257,6 +257,8 @@ struct rte_mempool { #define MEMPOOL_F_SC_GET 0x0008 /**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010 /**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020 /**< Don't need IOVA contiguous objs. */ +/** Internal: no object from the pool can be used for device IO (DMA). */ +#define MEMPOOL_F_NON_IO 0x0040 /** * @internal When debug is enabled, store some statistics. -- 2.25.1