Skip to contentSkip to conversation

pci/uio: enable prefetchable resources mapping

PATCH In review Changpeng Liu 3 participants 3 messages Feb 1, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci/uio: enable prefetchable resources mapping

For PCI prefetchable resources, Linux will create a write combined file as well, the library will try to map resourceX_wc file first, if the file does not exist, then it will map resourceX as usual.

---
 drivers/bus/pci/linux/pci_uio.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/bus/pci/linux/pci_uio.c +14 -5
index d423e4b..2957a5f 100644
@@ -293,7 +293,7 @@
 
 	/* update devname for mmap  */
 	snprintf(devname, sizeof(devname),
-			"%s/" PCI_PRI_FMT "/resource%d",
+			"%s/" PCI_PRI_FMT "/resource%d_wc",
 			rte_pci_get_sysfs_path(),
 			loc->domain, loc->bus, loc->devid,
 			loc->function, res_idx);
@@ -307,13 +307,22 @@
 	}
 
 	/*
-	 * open resource file, to mmap it
+	 * open prefetchable resource file first, try to mmap it
 	 */
 	fd = open(devname, O_RDWR);
 	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-				devname, strerror(errno));
-		goto error;
+		snprintf(devname, sizeof(devname),
+				"%s/" PCI_PRI_FMT "/resource%d",
+				rte_pci_get_sysfs_path(),
+				loc->domain, loc->bus, loc->devid,
+				loc->function, res_idx);
+		/* then try to map resource file */
+		fd = open(devname, O_RDWR);
+		if (fd < 0) {
+			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					devname, strerror(errno));
+			goto error;
+		}
 	}
 
 	/* try mapping somewhere close to the end of hugepages */
Signature · 1 line
1.9.3
#1 lore raw
Quoted 10 lines · Changpeng Liu

For PCI prefetchable resources, Linux will create a write combined file as well, the library will try to map resourceX_wc file first, if the file does not exist, then it will map resourceX as usual.

---
 drivers/bus/pci/linux/pci_uio.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

Hi,

Given the lack of ordering guarantees with write-combined memory, I would have thought that this is very risky to do without a complete set of changes inside the PMDs to add in the necessary memory barriers to ensure ordering of operations to the BARs. Therefore, instead of mapping one file or another, I think the change should be made to map *both* in DPDK if available. Then each driver can chose whether to write a given device register using uncacheable memory type or write-combining memory type + any appropriate barriers.

For example, with many NICs the initialization of the device involves many register writes in a pretty defined order, so wc operations are probably to suitable as performance is not a concern. However, for data path operations, a driver may chose to use wc memory for the occasional device writes there, for performance reasons.

Regards,
/Bruce

#2 lore raw
Quoted 22 lines · Bruce Richardson
Quoted 10 lines · Changpeng Liu

For PCI prefetchable resources, Linux will create a write combined file as well, the library will try to map resourceX_wc file first, if the file does not exist, then it will map resourceX as usual.

---
  drivers/bus/pci/linux/pci_uio.c | 19 ++++++++++++++-----
  1 file changed, 14 insertions(+), 5 deletions(-)

Hi,

Given the lack of ordering guarantees with write-combined memory, I would have thought that this is very risky to do without a complete set of changes inside the PMDs to add in the necessary memory barriers to ensure ordering of operations to the BARs. Therefore, instead of mapping one file or another, I think the change should be made to map *both* in DPDK if available. Then each driver can chose whether to write a given device register using uncacheable memory type or write-combining memory type + any appropriate barriers.

Quoted 5 lines

For example, with many NICs the initialization of the device involves many register writes in a pretty defined order, so wc operations are probably to suitable as performance is not a concern. However, for data path operations, a driver may chose to use wc memory for the occasional device writes there, for performance reasons.

+1

I think so too that it would be useful to have both mappings available and allow driver to choose which one to use.