Skip to contentSkip to conversation

librte_eal: add APIs to speedup virt2iova/phys

PATCH In review Li Feng 5 participants 9 messages Apr 20, 2020 – Apr 7, 2021

lore
Share & tools
lore

Li Feng

author
#0 lore raw

PATCH 1/1 librte_eal: add APIs to speedup virt2iova/phys

Using pread to replace lseek + read.
And add new APIs to reduce open/close/lseek system call frequency when the user needs to convert a large range of virtual address space.
- rte_mem_virt2iova_with_fd
- rte_mem_virt2phy_with_fd

Currently it will be used by spdk in spdk_mem_register.

---
 lib/librte_eal/freebsd/eal_memory.c | 18 ++++++++++++++
 lib/librte_eal/include/rte_memory.h | 36 +++++++++++++++++++++++++++
 lib/librte_eal/linux/eal_memory.c   | 49 +++++++++++++++++++++++--------------
 lib/librte_eal/rte_eal_version.map  |  3 +++
 4 files changed, 88 insertions(+), 18 deletions(-)
lib/librte_eal/freebsd/eal_memory.c +18 -0
index a97d8f0f0..fc0debf23 100644
@@ -44,12 +44,30 @@ rte_mem_virt2phy(const void *virtaddr)
 	(void)virtaddr;
 	return RTE_BAD_IOVA;
 }
+
 rte_iova_t
 rte_mem_virt2iova(const void *virtaddr)
 {
 	return rte_mem_virt2phy(virtaddr);
 }
 
+phys_addr_t
+rte_mem_virt2phy_with_fd(int fd, const void *virtaddr)
+{
+	/*
+	 * XXX not implemented. This function is only used by
+	 * rte_mempool_virt2iova_with_fd() when hugepages are disabled.
+	 */
+	(void)virtaddr;
+	return RTE_BAD_IOVA;
+}
+
+rte_iova_t
+rte_mem_virt2iova_with_fd(int fd, const void *virtaddr)
+{
+	return rte_mem_virt2phy_with_fd(fd, virtaddr);
+}
+
 int
 rte_eal_hugepage_init(void)
 {
lib/librte_eal/include/rte_memory.h +36 -0
index 3d8d0bd69..c75782fa7 100644
@@ -108,6 +108,23 @@ int rte_mem_lock_page(const void *virt);
 phys_addr_t rte_mem_virt2phy(const void *virt);
 
 /**
+ * Get physical address of any mapped virtual address in the current process.
+ * It is found by reading fd which is the opened /proc/self/pagemap special file
+ * descriptor. This is a optimization of rte_mem_virt2phy when the
+ * rte_mem_virt2phy is needed to be called many times.
+ * The page must be locked.
+ *
+ * @param fd
+ *   The opened fd of /proc/self/pagemap.
+ * @param virt
+ *   The virtual address.
+ * @return
+ *   The physical address or RTE_BAD_IOVA on error.
+ */
+__rte_experimental
+phys_addr_t rte_mem_virt2phy_with_fd(int fd, const void *virt);
+
+/**
  * Get IO virtual address of any mapped virtual address in the current process.
  *
  * @note This function will not check internal page table. Instead, in IOVA as
@@ -123,6 +140,25 @@ phys_addr_t rte_mem_virt2phy(const void *virt);
 rte_iova_t rte_mem_virt2iova(const void *virt);
 
 /**
+ * Get IO virtual address of any mapped virtual address in the current process.
+ *
+ * @note This function will not check internal page table. Instead, in IOVA as
+ *       PA mode, it will fall back to getting real physical address (which may
+ *       not match the expected IOVA, such as what was specified for external
+ *       memory).
+ *
+ * @param virt
+ *   The virtual address.
+ * @param fd
+ *   The opened fd of /proc/self/pagemap.
+ * @return
+ *   The IO address or RTE_BAD_IOVA on error.
+ */
+__rte_experimental
+rte_iova_t rte_mem_virt2iova_with_fd(int fd, const void *virt);
+
+
+/**
  * Get virtual memory address corresponding to iova address.
  *
  * @note This function read-locks the memory hotplug subsystem, and thus cannot
lib/librte_eal/linux/eal_memory.c +31 -18

72 lines not on this page · raw message

lib/librte_eal/rte_eal_version.map +3 -0
index f9ede5b41..fc3a436e7 100644
@@ -338,4 +338,7 @@ EXPERIMENTAL {
 
 	# added in 20.05
 	rte_log_can_log;
+
+	rte_mem_virt2iova_with_fd;
+	rte_mem_virt2phy_with_fd;
 };
Signature · 8 lines
2.11.0


-- 
The SmartX email address is only for business purpose. Any sent message 
that is not related to the business is not authorized or permitted by 
SmartX.
本邮箱为北京志凌海纳科技有限公司(SmartX)工作邮箱. 如本邮箱发出的邮件与工作无关,该邮件未得到本公司任何的明示或默示的授权.
#1 lore raw
Quoted 10 lines · Li Feng

Using pread to replace lseek + read.
And add new APIs to reduce open/close/lseek system call frequency when the user needs to convert a large range of virtual address space.
- rte_mem_virt2iova_with_fd
- rte_mem_virt2phy_with_fd

Currently it will be used by spdk in spdk_mem_register.

---

These API's are IMO already on the verge of what's acceptable because of the differences between PA, DPDK IOVA and external memory IOVA. I'm not sure building on top of them is a good idea. It's also quite platform specific - rte_mem_virt2phy could potentially work with Windows (and in fact there was an RFC for it), but would this API work with Windows, given that Windows doesn't have fd's? Should we perhaps replace fd's with an opaque structure pointer, so that each platform-specific implementation could dereference it the way it needs to, without exposing internal details of the platform?

Signature · 2 lines
Thanks,
Anatoly
#2 lore raw
Quoted 12 lines · Li Feng
Quoted 10 lines

Using pread to replace lseek + read.
And add new APIs to reduce open/close/lseek system call frequency when the user needs to convert a large range of virtual address space.
- rte_mem_virt2iova_with_fd
- rte_mem_virt2phy_with_fd

Currently it will be used by spdk in spdk_mem_register.

---

Quoted 9 lines

These API's are IMO already on the verge of what's acceptable because of the differences between PA, DPDK IOVA and external memory IOVA. I'm not sure building on top of them is a good idea. It's also quite platform specific - rte_mem_virt2phy could potentially work with Windows (and in fact there was an RFC for it), but would this API work with Windows, given that Windows doesn't have fd's? Should we perhaps replace fd's with an opaque structure pointer, so that each platform-specific implementation could dereference it the way it needs to, without exposing internal details of the platform?

These new APIs are, in fact, Linux-specific. Doubtfully will Windows ever benefit from it even with fd abstracted, though I can't say for FreeBSD. Given the linked suggestion to move rte_vfio_container_dma_map/unmap to some include/linux header, maybe these APIs could land there too?

	http://mails.dpdk.org/archives/dev/2020-April/164404.html
Signature · 1 line
Dmitry Kozlyuk
author
#3 lore raw

Cool, thank you, Anatoly and Kozlyuk.

I haven't found how Windows implements the rte_mem_virt2phy.

Using an opaque structure pointer as the first argument is a good idea.

Thanks,

Feng Li

Quoted 32 lines · Dmitry Kozlyuk <[email protected]> 于2020年4月20日周一 下午9:07写道:
Quoted 13 lines · Li Feng
Quoted 10 lines

Using pread to replace lseek + read.
And add new APIs to reduce open/close/lseek system call frequency when the user needs to convert a large range of virtual address space.
- rte_mem_virt2iova_with_fd
- rte_mem_virt2phy_with_fd

Currently it will be used by spdk in spdk_mem_register.

---

Quoted 9 lines

These API's are IMO already on the verge of what's acceptable because of the differences between PA, DPDK IOVA and external memory IOVA. I'm not sure building on top of them is a good idea. It's also quite platform specific - rte_mem_virt2phy could potentially work with Windows (and in fact there was an RFC for it), but would this API work with Windows, given that Windows doesn't have fd's? Should we perhaps replace fd's with an opaque structure pointer, so that each platform-specific implementation could dereference it the way it needs to, without exposing internal details of the platform?

These new APIs are, in fact, Linux-specific. Doubtfully will Windows ever benefit from it even with fd abstracted, though I can't say for FreeBSD. Given the linked suggestion to move rte_vfio_container_dma_map/unmap to some include/linux header, maybe these APIs could land there too?

        http://mails.dpdk.org/archives/dev/2020-April/164404.html

--
Dmitry Kozlyuk

Signature · 4 lines
The SmartX email address is only for business purpose. Any sent message 
that is not related to the business is not authorized or permitted by 
SmartX.
本邮箱为北京志凌海纳科技有限公司(SmartX)工作邮箱. 如本邮箱发出的邮件与工作无关,该邮件未得到本公司任何的明示或默示的授权.
#4 lore raw

Hello,

Quoted 6 lines · Li Feng

Cool, thank you, Anatoly and Kozlyuk.

I haven't found how Windows implements the rte_mem_virt2phy.

Using an opaque structure pointer as the first argument is a good idea.

I pinged about this patch status 6 months ago but got no reply. Trying again in public.

From the thread, I understand that at best it would have to be done differently.

Signature · 1 line
David Marchand
author
#5 lore raw

PATCH 1/1 librte_eal: add APIs to speedup virt2iova/phys

Hi david,

Sorry for late response.
I just see your mail on my trip.

I will update this patch, if anyone has interest in this feature. Currently it's in my own repo.

Quoted 21 lines · 在 2021年3月25日星期四,David Marchand <[email protected]> 写道:

Hello,

Quoted 6 lines · Li Feng

Cool, thank you, Anatoly and Kozlyuk.

I haven't found how Windows implements the rte_mem_virt2phy.

Using an opaque structure pointer as the first argument is a good idea.

I pinged about this patch status 6 months ago but got no reply. Trying again in public.

From the thread, I understand that at best it would have to be done differently.

--
David Marchand

Signature · 2 lines
Thanks,
Feng Li
#6 lore raw
In reply to David Marchand
Quoted 6 lines · David Marchand

Hello,

Quoted 3 lines · Li Feng

Cool, thank you, Anatoly and Kozlyuk.

Quoted 9 lines
Quoted 3 lines

I haven't found how Windows implements the rte_mem_virt2phy.

Using an opaque structure pointer as the first argument is a good idea.

I pinged about this patch status 6 months ago but got no reply. Trying again in public.

From the thread, I understand that at best it would have to be done differently.

I would agree with the latter. Like i said in my original response, the fd-less API's are already on the very of what's acceptable and in the perfect world we wouldn't have them in the first place, and i don't like the fact that they exist and would wholly discourage their use, mainly because of very confusing semantics of real physical address vs. DPDK's IOVA vs. user IOVA, and potential for errors due to trying to resolve an IOVA address of something that doesn't even have it.

Given the above, I certainly don't like the idea of building on top of these API's.

Signature · 2 lines
Thanks,
Anatoly
#7 lore raw
Quoted 26 lines · Anatoly
Quoted 6 lines · David Marchand

Hello,

Quoted 3 lines · Li Feng

Cool, thank you, Anatoly and Kozlyuk.

Quoted 9 lines
Quoted 3 lines

I haven't found how Windows implements the rte_mem_virt2phy.

Using an opaque structure pointer as the first argument is a good idea.

I pinged about this patch status 6 months ago but got no reply. Trying again in public.

From the thread, I understand that at best it would have to be done differently.

I would agree with the latter. Like i said in my original response, the fd-less API's are already on the very of what's acceptable and in the perfect world we wouldn't have them in the first place, and i don't like the fact that they exist and would wholly discourage their use, mainly because of very confusing semantics of real physical address vs. DPDK's IOVA vs. user IOVA, and potential for errors due to trying to resolve an IOVA address of something that doesn't even have it.

Quoted 2 lines

Given the above, I certainly don't like the idea of building on top of these API's.

Got it. Let's drop it.

Quoted 4 lines

--
Thanks,
Anatoly

#8 lore raw
Quoted 29 lines · Feng Li
Quoted 26 lines · Anatoly
Quoted 6 lines · David Marchand

Hello,

Quoted 3 lines · Li Feng

Cool, thank you, Anatoly and Kozlyuk.

Quoted 9 lines
Quoted 3 lines

I haven't found how Windows implements the rte_mem_virt2phy.

Using an opaque structure pointer as the first argument is a good idea.

I pinged about this patch status 6 months ago but got no reply. Trying again in public.

From the thread, I understand that at best it would have to be done differently.

I would agree with the latter. Like i said in my original response, the fd-less API's are already on the very of what's acceptable and in the perfect world we wouldn't have them in the first place, and i don't like the fact that they exist and would wholly discourage their use, mainly because of very confusing semantics of real physical address vs. DPDK's IOVA vs. user IOVA, and potential for errors due to trying to resolve an IOVA address of something that doesn't even have it.

Quoted 4 lines
Quoted 2 lines

Given the above, I certainly don't like the idea of building on top of these API's.

Got it. Let's drop it.

I marked it as rejected in patchwork.
Thanks.

Signature · 1 line
David Marchand