3

I want to read and write to a persistant memory(for testing now ddr is connected) in my PCIe device (FPGA) on an Intel Linux system.

The memory is exposed in a particular bar (say bar 2). How to access this persistant memory. I looked into examples in PMDK library, but I couldn't find any.

When I looked into libpmem library I did find mapping api pmem_map_file() but there is no provision to select the bars.

Is it possible to use mmap() call? Currently I am using as shown below to access my bar using the uio driver. Do I need to make any changes to mmmap pmmem memory?

mmap(NULL, 3*1024*1024, PROT_READ | PROT_WRITE, MAP_SHARED, uio_fd0, 2* 4096); 

Can anyone suggest me some ideas about this.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Rahul K V
  • 41
  • 4
  • `mmap(MAP_SYNC|MAP_SHARED_VALIDATE)` is documented in the man page for persistent memory. http://man7.org/linux/man-pages/man2/mmap.2.html – Peter Cordes May 21 '20 at 16:45
  • So , I just needs to mmap using the above flags with driver fd( I am using uio driver) – Rahul K V May 21 '20 at 17:15
  • Probably? Those `mmap` flags should be what libpmem uses under the hood. If that works for what you're doing, then great. If you're rolling your own accesses, make sure to `clflush` or `clflushopt` (or `clwb`) your stores where necessary, like libpmem would do for you if you use its helper functions. – Peter Cordes May 21 '20 at 17:42
  • got error while compiling : error: ‘MAP_SYNC’ undeclared and error: ‘MAP_SHARED_VALIDATE’ undeclared i am using kernel version 5.6.8-1.el7.elrepo.x86_64 and centos-release-7-8.2003.0.el7.centos.x86_64 – Rahul K V May 21 '20 at 17:49
  • Those were new in Linux 4.15 according to the man page. If they're not defined, you maybe forgot to include a header? Or else CentOS's user-space headers are behind the kernel version. You'll have to investigate your system; I use Arch Linux which updates everything from upstream regularly. – Peter Cordes May 21 '20 at 17:51
  • i have included header #include – Rahul K V May 21 '20 at 17:53
  • it succesfully compiled after including #include , but i am gettig an error on mmap while running mmap failed: Operation not supported, i am using my uio driver for mmap, MAP_SYNC flag is supported only for files supporting DAX – Rahul K V May 22 '20 at 03:21
  • Ok, that rules out your guess that libpmem or similar stuff could be useful. – Peter Cordes May 22 '20 at 03:26

0 Answers0