O_DIRECT access to mmap-ed dmam_alloc_coherent() problems
1
vote
0
answers
323
views
I'm looking for ideas to get over this hurdle. I have a linux kernel module that takes in high rate data from the PL side of a Xilinx Zynq MPSOC device. The kernel module is based off dma-proxy example (https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/1027702787/Linux+DMA+From+User+Space+2.0) but i modified it slightly to to only use one buffer. Our DMA implemenation uses a single channel, Rx only, non scatter gather implementation of the IP. I am moving the data to the dmam_alloc_coherent memory space just fine within the driver. However, when i map to this same space (as in the example driver) I cannot write this data to the userspace file that has been opened with the O_DIRECT option. When i attempt to do so, the write() call perrors out with "bad address". I can however write to the file directly without the O_DIRECT option just fine. However as this data rate is far too low for the incoming data from the PL. The next thing i tried was to do a second copy from the dmam_alloc_coherent() memory area to a userspace posix_memalign(512) allocated area, then in turn write the data to the O_DIRECT opened file. This dramatically increased performand by about 5x. But its still not as fast as it could be.
Scenerio Performance Summary of my code...
(kernel)dmam_alloc_coherent() -> (userspace)file(O_DIRECT) = "bad address"
(kernel)dmam_alloc_coherent() -> (userspace)file() = 272 MB/second
(kernel)dmam_alloc_coherent() -> (userspace)posix_memalign(512) -> (userspace)file(O_DIRECT) = 1323 MB/second
(userspace)posix_memalign(512) -> (userspace)file(O_DIRECT) = 2200 MB/sec (no actual PL data, just dumping memcontents to disk)
I believe if i can find a way to get this to work without performing a second copy to posix_memalign area, I should be close to 2000 MB/sec. My actual target rate is 1600 MB/sec. Does anyone have any clue how i can perform this without the second copy? How do i set up the dma memory to allow reading from and writeing to O_DIRECT file without the intermediate copy? lol i believe this is called zero copy ....
Thanks in advance for all your help on this, i've been banging my head against the wall for a while on it....
Cheers!
PS. Other info....
MPSOC setup:
Petalinux on MPSOC development board with 2 NVME drives configured in a ext4 LVM stripe setup.
other dd testing to disk:
1.dd if=/dev/zero of=tt/test.bin bs=20M count=50
50+0 records in
50+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 4.37955 s, 239 MB/s
2.dd if=/dev/zero of=tt/test.bin bs=20M count=50 oflag=direct
50+0 records in
50+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.489777 s, 2.1 GB/s
3.dd if=/dev/zero of=tt/test.bin bs=30M count=1000 oflag=direct
1000+0 records in
1000+0 records out
31457280000 bytes (31 GB, 29 GiB) copied, 13.7039 s, 2.3 GB/s
Asked by Fraser Addison
(11 rep)
Jul 30, 2022, 08:45 PM
Last activity: Jun 7, 2023, 05:43 AM
Last activity: Jun 7, 2023, 05:43 AM