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 4BCF8A0C45; Fri, 15 Oct 2021 18:03:51 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 32AA7410E0; Fri, 15 Oct 2021 18:03:51 +0200 (CEST) Received: from AZHDRRW-EX01.nvidia.com (azhdrrw-ex01.nvidia.com [20.51.104.162]) by mails.dpdk.org (Postfix) with ESMTP id 117FA4067C for ; Fri, 15 Oct 2021 18:03:49 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.174) by mxs.oss.nvidia.com (10.13.234.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.15; Fri, 15 Oct 2021 09:03:48 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Abz/4yAYUjvF/NJre5mwK93L1gTLtkcrkPfnYmVphEuTmLdUFupqTmac0JbuAukYtwQ00glBUDAsgyWhfzn2X5cU/VxXk98A/yMNXP0/DQ0l+0Anp+cj8FHZLm3nRgnVH3w9d1p/fy6/bHJXLPCALz3fKBpmpbcH2U5eK7cAOErmht3Rj3oj5CsCoaQjAFP0vOMFWo53A71k6lma6dAYi1PKGJBMVGahww9/eV84RCk6Uds+xBCErcmayjT3XdP7zIFqYXvjtvz1FypCEOaRfn8CwR9REH7iDs7PpvYVxiNTlEAs+Fv/YQ5Fb271+PLcIwTMyYmFW+YCdRQ1uclQhg== 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=aghPX2aWb6XLXP2fcioSfK3JPNaMphDfZ62F8zkadeM=; b=Kowsi0nq3sun1C2Lh8uzEj1O3xMZeffTTDPQRLQdzAAQSVyCM/71CZRDxc8vaxKSoZV7Nt0pfRrZ49lRzu472meB5r6k00+j1/rfUXqTOpYa/wDCNZGsaoenJ6ljcWftpG1J111Gk8F4QPORu0PFXfKBh9CNG2XeG5pruaH83jIyAJ2N/fUxjzqHXZ4DopxXaSZEfp6pmtU5xsuY53vDfBUXyKVMKBTVAOnslhBqUZqss8WTDrFC8TlZqkn36GugoTunkQ0fbbTweruthqF1Jfy6SrQKFR8o0pFGEW4sZobCNPFlJWp80deTFWJPBWgL9cb28TYbpiMNuI6bHIWWkw== 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=aghPX2aWb6XLXP2fcioSfK3JPNaMphDfZ62F8zkadeM=; b=BJegQLNL70jolwyzdeQ3GT7/WvNhu8mxn3RIfghNMNtq8auapgPG0+lfWGX2lX+22S9N5YSkUxhh/D+56+6UIkd8aX+EIl3XCcJ3S2vQtxlDk6zH0fJlYA0vduCJj+bCBs99qTUOqWjm2FfKNJBdFq5AM8m864OTHDR3BWuk1+PvjekOY2//RJ4iG5HsZN8K2mdPzoCIRtPgeqW8zNwVw+rxH7HPxA6R5G5ttGetJTc/6PZ2okzm9zmid1Ecq+2zBWN2X0CRPWWV7lgwJ3K4DVYDmffCUIcMxRRPHqoS6RyTUAAjAKHeOv9vTP0ZpjWHYFx7QgfsKT//pztEVG3hcw== Received: from DM5PR10CA0004.namprd10.prod.outlook.com (2603:10b6:4:2::14) by BYAPR12MB3480.namprd12.prod.outlook.com (2603:10b6:a03:aa::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15; Fri, 15 Oct 2021 16:03:46 +0000 Received: from DM6NAM11FT033.eop-nam11.prod.protection.outlook.com (2603:10b6:4:2:cafe::a3) by DM5PR10CA0004.outlook.office365.com (2603:10b6:4:2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Fri, 15 Oct 2021 16:03:46 +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 DM6NAM11FT033.mail.protection.outlook.com (10.13.172.221) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Fri, 15 Oct 2021 16:03:45 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 15 Oct 2021 16:03:03 +0000 From: Dmitry Kozlyuk To: CC: Matan Azrad , Andrew Rybchenko , Maryam Tahhan , Reshma Pattan , Olivier Matz Date: Fri, 15 Oct 2021 19:02:42 +0300 Message-ID: <20211015160244.3097758-3-dkozlyuk@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015160244.3097758-1-dkozlyuk@nvidia.com> References: <20211013110131.2909604-1-dkozlyuk@nvidia.com> <20211015160244.3097758-1-dkozlyuk@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6cfbf301-2326-4fbd-919f-08d98ff55e23 X-MS-TrafficTypeDiagnostic: BYAPR12MB3480: X-Microsoft-Antispam-PRVS: X-MS-Exchange-Transport-Forked: True X-MS-Oob-TLC-OOBClassifiers: OLM:741; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: whf6FshhtI9x1BUxcD9aI0DmfTarbQTvszrHRl5XU4NSeVofXfaXHbxAJ75ohMZkVTvqu8JS98VhZB/LF5TNx6hViGlmYlOmRiHQWddOW6DeL56mnHruDG3E7CNim4uYvGPl+5FqXmNX7snDDBT6LEQghh8iFfR/RJX4Zi7nyNUb4y6wL7artdBkwT39arUkugOWiNBgEjtWD8RLAuLcwPo6H8mpygv7c1Hth9814E/hk/WgccPRjKKmg1Whd6MzJkZx3fcCMyDNWcvUI3ObhNBKaL8f1i/Mdq7nfKA8XhqhP2btVr4n/YpAuvihRJndYnLqQMXfJWTQBsHHAu5FClhsq7/r+fW5qtDIwkCr+oyvO8OpFJnO9XDJKCpibR8smnWnqX/v8oForc5vgD/i/zKgqJ088oFg/HRG6xIINbXCnlFTdgFswdOqJbIhReJ1DjRUVJ2TYk5Q8hF+iglI5DdKvW5HOWAsdWoEkMBNZbF22eXeCoIwv5auWrHgB44bCXGRIHuCu43asux+tDr2z2hQcBdCbe0tgIwsaRtYTGsYdjeOfjG7sqqL8uvAu6/ScDO7zJWZeJKwy3zSBYBSOfHiGw2pAzzATH/1ME0Ifph8s6UBwiurdEbJ2aoGcWfo/NcwuY93KmW6mmfchDnYB8JMUpdhS+HiJv3e8l3NQpUDgRIzMWDC/wR8t7hg2HaEahObmN632GUCOcXEl9Y7VExh481GFPB+K8QgJ41cly3ZMalb/vT4V/nZqrdhj8r0VM04iHW2WJhg+07h1VrpVwY9EDYz4OxAzvNsm/nBNGc= 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)(70586007)(36756003)(966005)(336012)(16526019)(186003)(2616005)(107886003)(54906003)(426003)(508600001)(5660300002)(7636003)(8676002)(6916009)(8936002)(1076003)(6666004)(4326008)(2906002)(36860700001)(70206006)(47076005)(6286002)(55016002)(26005)(316002)(86362001)(82310400003)(83380400001)(7696005)(356005); DIR:OUT; SFP:1101; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2021 16:03:45.7165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6cfbf301-2326-4fbd-919f-08d98ff55e23 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: DM6NAM11FT033.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3480 Subject: [dpdk-dev] [PATCH v5 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 | 4 +- app/test/test_mempool.c | 112 +++++++++++++++++++++++++ doc/guides/rel_notes/release_21_11.rst | 3 + lib/mempool/rte_mempool.c | 10 +++ lib/mempool/rte_mempool.h | 2 + 5 files changed, 130 insertions(+), 1 deletion(-) diff --git a/app/proc-info/main.c b/app/proc-info/main.c index a8e928fa9f..6054cb3d88 100644 --- a/app/proc-info/main.c +++ b/app/proc-info/main.c @@ -1296,6 +1296,7 @@ show_mempool(char *name) "\t -- SP put (%c), SC get (%c)\n" "\t -- Pool created (%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 c39c83256e..caf9c46a29 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,109 @@ 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(rte_errno)); + 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) +{ + const struct rte_memzone *mz; + void *virt; + rte_iova_t iova; + size_t page_size = RTE_PGSIZE_2M; + struct rte_mempool *mp; + int ret; + + mz = rte_memzone_reserve("test_mempool", 3 * page_size, SOCKET_ID_ANY, + RTE_MEMZONE_IOVA_CONTIG); + RTE_TEST_ASSERT_NOT_NULL(mz, "Cannot allocate memory"); + virt = mz->addr; + 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 * page_size), + RTE_BAD_IOVA, page_size, NULL, NULL); + RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s", + rte_strerror(rte_errno)); + 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, page_size, NULL, NULL); + RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s", + rte_strerror(rte_errno)); + 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 * page_size), + RTE_BAD_IOVA, page_size, NULL, NULL); + RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s", + rte_strerror(rte_errno)); + 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_memzone_free(mz); + 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(rte_errno)); + 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 +1018,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 4c56cdfeaa..39a8a3d950 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -229,6 +229,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 3285626712..408d916a9c 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