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 6AD2CA00C5; Thu, 15 Sep 2022 14:13:50 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 097CA4021D; Thu, 15 Sep 2022 14:13:50 +0200 (CEST) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70074.outbound.protection.outlook.com [40.107.7.74]) by mails.dpdk.org (Postfix) with ESMTP id 49DA340156 for ; Thu, 15 Sep 2022 14:13:49 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WEVbBgNSV5EIny+9OUKFQQX2z9E6XqX4pAW/Oiy7Xu5jGzHGnADgHq6vSUXCVFKoiZGQhSHkoLIODXHjDgmbogDbfzLpYPcq8KplPC/31AcEcGpgUhmDOTbJ4LOEr3Wb1G/YEK9sU9Ri6l61mrW3xFs6Abh/omQP20X4pWun3s3+zGB/09Ile2DpvEFGCmqOwkd0VeJ0UN9gYAMa5DPdOkzB68wklPhmpl66KgNF3AfC9ZrURmg+29dbMeFA/iHktbx1gEkc3ISVHL/5DToD/lw5UDPp1GpOBJg0d/LcitbqeFUI1JlS7Hho4vZ3gVRuG50gjYMmyIU1d0Z7CCMVuA== 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=vTzqogqVHJnTMDZHxPl6TxbvwgpnAZ5H3ZdKQkqQ2BA=; b=NPkr+R2FngkrrroNwnpRqNJD/+VZg46tHVwiy0ktpDohFqqgiGYQ/rWV7N2RUyU+Uk7OnoQDrlPG7lDng+Ehro1ijn44OpKkYNHthKjcfJBRpMy3ybdkOrHyXRTB9TomJHpPT9QZ4MqXdhqH2XOPFYe+S2gJXzO1zkLgQfahckGQpqVVZRaWt+hO660yMCtYuGneFTRUcQrfW1lhmvARo/iM1wrtO59PSxtdgkb4q42IdUuLFXLGHqxrvXH1x/vHMQkWXsI1JefBgUX2KEvPApsrTVPFWgXGPhdWdEcz2ci2IiEYPbslP6HQufmS9fXyQaLosf56OvRHmsP9xe1ckA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=xsightlabs.com; dmarc=pass action=none header.from=xsightlabs.com; dkim=pass header.d=xsightlabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xsightlabs.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vTzqogqVHJnTMDZHxPl6TxbvwgpnAZ5H3ZdKQkqQ2BA=; b=aaAo8x58n5AXeFPHXN+Acuo2dXQrw0ZKmLGXqqUeZDLOTYshG6Cgs8MohqUHrHfdOKVrLEr6DsRvoH9V/p6RR1aFd/Hm7F4i4EhRRR70OoMEqnPpyHTIn+UCX3yw0Z5w0DRem2Jf7lM36ZJaCGnhhtZC2H0rmCeebrlF7JU9V4A= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=xsightlabs.com; Received: from DB9P193MB1482.EURP193.PROD.OUTLOOK.COM (2603:10a6:10:2a6::7) by AS8P193MB2271.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:446::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.14; Thu, 15 Sep 2022 12:13:48 +0000 Received: from DB9P193MB1482.EURP193.PROD.OUTLOOK.COM ([fe80::600e:205f:e0e1:f828]) by DB9P193MB1482.EURP193.PROD.OUTLOOK.COM ([fe80::600e:205f:e0e1:f828%3]) with mapi id 15.20.5612.022; Thu, 15 Sep 2022 12:13:47 +0000 Message-ID: <485837b0-9e0f-f023-7dfc-170bddda26e4@xsightlabs.com> Date: Thu, 15 Sep 2022 08:13:43 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [RFC v2] eal/linux: add support for fast virt/iova translation To: =?UTF-8?Q?Morten_Br=c3=b8rup?= , dev@dpdk.org, bruce.richardson@intel.com Cc: dmitry.kozliuk@gmail.com, anatoly.burakov@intel.com References: <20220914211201.32940-1-donw@xsightlabs.com> <20220914211201.32940-2-donw@xsightlabs.com> <98CBD80474FA8B44BF855DF32C47DC35D87313@smartserver.smartshare.dk> From: Don Wallwork In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D87313@smartserver.smartshare.dk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: VI1PR09CA0160.eurprd09.prod.outlook.com (2603:10a6:800:120::14) To DB9P193MB1482.EURP193.PROD.OUTLOOK.COM (2603:10a6:10:2a6::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9P193MB1482:EE_|AS8P193MB2271:EE_ X-MS-Office365-Filtering-Correlation-Id: 768795da-5529-4acd-f343-08da9713be24 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nzEf/t34kQHgkkZDfYlUBueA2uOkHhGttmUt2+TjKw3vzAncyC2sq0TR4h/qp5JJWChEkaEj2ns8xf8+o2BA8dmKJk2Tx32LRHoPZoP4Tod7sb6oE4gV/JSFqwjXJbXD4oAhfKyj7WaKJBq/Iv4SZCHD2dsn+HCeEsbgmLIsRAmnFNGa99/sVzDtUXrqQBWcZPNuU/emuq+vMXoyzfe8EfouVj4Y/zZQZ6xaKqJSD9U6dFU5Cd5K6YDAFtPsUOX8bhmdBSIPAFe4yz5N1TUS+Xf0eS7SzgrdGLlk7Gy50q9caBWklAk8Su9UYmCUtEMHj8u32WBJVClDflFASgYu60yOksZd+iTjWyQIuPfQ3aDFvfmh5q36gRbsoAJHrxhxR0X+L6cJQHXzUoNqOj6NtaepN5MTAznwA3HlriJSlglv1Xa/pxJ0TFep0Np4bsUkBEFgVq9ZRJohx7tfqg7TC1osfWNPJFhbebJI+ewabgqZq8ii3jz0cJx8ffmr0kd7WqYY97LT80I1msqUloCf4yBZUUe2Ni2YYp/aSB4c9ZhY8qNukS6hnp0caRnrHRmnO4Ft0NnsQzLe5GiuUdTyr6UIYPOHEjGKfN4OQhkCNBZ5023jBUqrB4hEdsDQf7aW8DdDTbFPSeyGLQCblbqSW1qGqe9hEuNEgHFsMO0Lkhtq43+DIOrMaKQ1VV4DW2QvwGujRyNHNbiAL7QI3hz6hnopnLhg5tQYGQGTLMBkuF3aT9sjm9p71mGJNnmCGruPnuUu+xG/j9pWVouZSmrYzv2U6W0mSrQbHYnVnApf+bFeefJHcOo8JQ4uIPtJ8Es6vTPivpL61h/OxL1fb3kFnD9MfVoayLD9Mz2zAaOuOSY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9P193MB1482.EURP193.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230022)(4636009)(346002)(396003)(376002)(366004)(39850400004)(136003)(451199015)(6666004)(41300700001)(6506007)(53546011)(8936002)(83380400001)(52116002)(2906002)(86362001)(66574015)(5660300002)(66946007)(31696002)(66556008)(4326008)(8676002)(66476007)(36756003)(26005)(45080400002)(6512007)(186003)(31686004)(6486002)(478600001)(316002)(966005)(2616005)(38350700002)(38100700002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?d0FEc3Y3TEJIVkU1V1A4QkJqaGdTaTBMS3M4S3NJQWtnTGE2cyt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Y2IwVkdVc2hRcm8rOVVhYzlyZ1hpWm5ac3M0?= =?utf-8?B?SjVwTmlZQUJhV3pJaDVpTVkwZzhnOExLZmJIR2hmVVprNDgrc08rMmJUeUNI?= =?utf-8?B?Y0NyTjU3VjVQVitkOXI5RFdXQ3BQYkpJVHdXcnRjVnlaVTdNSzloeGNsYk9P?= =?utf-8?B?U29PT0VHam5NLzJIamVOa2MweURkbFY3a283RUpwUlVCNFFTYXJHOEpMSUtx?= =?utf-8?B?K1JVS1RvVkJLd1JZMzRHQmFseUpLeER2WkUySE9jU3A1M0VYTWdEbUx3ZGtq?= =?utf-8?Q?4tPsPPYe48sTnZk9IcpVY0Dja?= X-OriginatorOrg: xsightlabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 768795da-5529-4acd-f343-08da9713be24 X-MS-Exchange-CrossTenant-AuthSource: DB9P193MB1482.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2022 12:13:47.8174 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 646a3e34-83ea-4273-9177-ab01923abaa9 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oEAJbWKPRQE5hZoWEi9VGf5oEf2UTWk4rcy6F0nuviHpwkJPub5/RlfgQ2EAEFnch756izWrmkfHHdnP5dtnpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P193MB2271 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 On 9/15/2022 3:40 AM, Morten Brørup wrote: >> From: Don Wallwork [mailto:donw@xsightlabs.com] >> Sent: Wednesday, 14 September 2022 23.12 >> >> This patch maps hugepage memory such that address translation from >> virtual to iova or vice versa can be done by simple addition/ >> subtraction of a constant value without any page table walks. >> >> A new '--const-translate' EAL option is added to enable this mode. [...] >> diff --git a/lib/eal/include/rte_memory.h >> b/lib/eal/include/rte_memory.h >> index 68b069fd04..c87777ca01 100644 >> --- a/lib/eal/include/rte_memory.h >> +++ b/lib/eal/include/rte_memory.h >> @@ -134,6 +134,34 @@ rte_iova_t rte_mem_virt2iova(const void *virt); >> void * >> rte_mem_iova2virt(rte_iova_t iova); >> >> +/** >> + * Get IO virtual address of any mapped virtual address in the current >> process. >> + * >> + * @note This function provides a fast implementation of virtual to >> physical >> + * addresses that does not walk any page tables. Suitable for >> use in >> + * data plane threads. >> + * >> + * @param virt >> + * The virtual address. >> + * @return >> + * The IO address or RTE_BAD_IOVA on error. >> + */ >> +rte_iova_t rte_mem_fast_virt2iova(const void *virt); >> + >> +/** >> + * Get virtual memory address corresponding to iova address. >> + * >> + * @note This function provides a fast implementation of physical to >> virtual to >> + * addresses. Suitable for use in data plane threads. >> + * >> + * @param iova >> + * The iova address. >> + * @return >> + * Virtual address corresponding to iova address (or NULL if address >> does not >> + * exist within DPDK memory map). >> + */ >> +void *rte_mem_fast_iova2virt(rte_iova_t iova); >> + >> /** >> * Get memseg to which a particular virtual address belongs. >> * > rte_mem_fast_virt2iova() and rte_mem_fast_iova2virt() serve the same purpose as rte_mem_virt2iova() and rte_mem_iova2virt(). Can't this alternative algorithm be implemented in the existing functions, or is there a reason for adding separate functions? It is necessary to keep a version of the translation functions that does the page table walks since that method must be used at init time.  My intention was to add new functions that are safe for use in fast path code. > > Minor detail about names: The DPDK community has a general aversion against using "fast" in function names - because everything in DPDK is supposed to be fast. If they need to be separate, perhaps use "_fp" (for fast path) at the end of their names, like the Trace library's RTE_TRACE_POINT_FP() variant of the RTE_TRACE_POINT() macro. Thought that might be the case.. I can change to _fp. > > If these two functions need to be really fast, they could be inline instead of proper functions. In my opinion, they are short enough to allow inlining. And, if merged with the original functions, the fast code path could be inline and fall back to calling the original, slower functions (which would then need to be renamed). Others might disagree about inlining. Reusing the existing names might also probably break the ABI. Agree that this could be inlined, but probably best not to merge with the page walk version since it would not be desirable for fast path code to fall back to that mode.  Also since this patch implements support for Linux EAL only, the inline functions may need to be added to a Linux specific header. > > From a high level perspective - and referring to my previous argument about optimizations not being features [1] - I wonder if this patch should be a build time option instead of a runtime feature? > @Don: My preference for build time options is somewhat controversial, so don't waste time converting to a build time option before the community has provided feedback on the subject. > > [1]: https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Finbox.dpdk.org%2Fdev%2F98CBD80474FA8B44BF855DF32C47DC35D870EB%40smartserver.smartshare.dk%2F&data=05%7C01%7Cdonw%40xsightlabs.com%7C27c0102845d042a17bb408da96ed96f7%7C646a3e3483ea42739177ab01923abaa9%7C0%7C0%7C637988244443228274%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=bW9ZmyZ9Ap9rAG5juYGEUgvCNTCJ96Q1IwPf8ExaEGI%3D&reserved=0 > > [...] > >> diff --git a/lib/eal/linux/eal_memory.c b/lib/eal/linux/eal_memory.c >> index c890c42106..3fefb3dc9d 100644 >> --- a/lib/eal/linux/eal_memory.c >> +++ b/lib/eal/linux/eal_memory.c >> @@ -148,6 +148,47 @@ rte_mem_virt2iova(const void *virtaddr) >> return rte_mem_virt2phy(virtaddr); >> } >> >> +static void *const_va_pa_delta; > This variable is primarily used as an address offset, not a pointer, so consider making it "uintptr_t" instead of "void *". Good point. >> + >> +#ifdef RTE_MEM_SANITY_CHECK >> +#define __rte_mem_validate(v) rte_mem_validate(v) >> + >> +static int rte_mem_validate(const void *virtaddr) >> +{ >> + if (!rte_mem_virt2memseg(virt, NULL)) { >> + RTE_LOG(ERR, EAL, "Invalid virtual address %p\n", >> virtaddr); >> + return -1; >> + } >> + return 0; >> +} >> +#else >> +#define __rte_mem_validate(v) 0 >> +#endif >> + >> +rte_iova_t rte_mem_fast_virt2iova(const void *virtaddr) >> +{ >> + if (rte_eal_iova_mode() == RTE_IOVA_VA) >> + return (uintptr_t)virtaddr; >> + >> + if (__rte_mem_validate(virtaddr) != 0) >> + return RTE_BAD_IOVA; >> + >> + return (rte_iova_t)((uintptr_t)virtaddr - >> (uintptr_t)const_va_pa_delta); > You can probably use RTE_PTR_SUB() instead. Will do. > >> +} >> + >> +void *rte_mem_fast_iova2virt(rte_iova_t iova) >> +{ >> + if (rte_eal_iova_mode() == RTE_IOVA_VA) >> + return (void *)(uintptr_t)iova; >> + >> + void *virtaddr = (void *)((uintptr_t)const_va_pa_delta + iova); > You can probably use RTE_PTR_ADD() instead. Agreed. -Don > >> + >> + if (__rte_mem_validate(virtaddr) != 0) >> + return NULL; >> + >> + return virtaddr; >> +} >> +