I am trying to stream data from a USB device to a python3 shared memory array with as little overhead as possible. Currently I am reading a 128KB packet from a usb device using pyusb. I have created a 2D (1024 x 128Kb) shared memory block from the multiprocessing.shared_memory library. I would like to store this packet into the shared memory block, flush the packet, and read another packet before the hardware buffer overflows (we're going at approximately 40MB/s).
My current issue is that pyusb returns data in an array.array type and the destination is a memoryview object. Is there an efficient way to copy this data over the the shm block?
Related
I'm working on a zynq 7000 SOC. I wrote an ALSA driver. Inside the FPGA, I implemented all the circuitery (FIFO, clocks generator, I2S dac output). From the Linux kernel point of view, there is an address to feed sample in the FPGA FIFO, one address to read the hardware pointer and an interrupt for the "snd_pcm_period_elapsed" function call.
In the "pcm_copy" callback, i copy samples from userspace to kernel space previously allocaded buffer, and then, i use a loop to push data in the FPGA from the kernel buffer.
I would like to USE an AXI dma to be able to copy directly from the pcm buffer to the FPGA FIFO. The DMA works perfectly (i used something very simple and not the linux DMA api witch is for me very difficult to understand...)
To test my DMA, i allocate a coherent buffer "dma_alloc_coherent" and i copy the samples in the coherent buffer and then i launch the transfert.
My issue is: I don't undersand how to get the physical address of the PCM buffer to be able to use the DMA transfert directly without copy in the coherent buffer. I read a lot of documents and i looked a lot of devices drivers, most of them are using PCI DMA witch is an other story ...
I founded somewhere that i have to implement the mmap callback in my alsa driver, but i didn't understand well, i also looked arround the "dma_area" field in the substream data structure witch contain an address, but if i use it, i have a dma error...
I really want to well understand how the pcm ring buffer is allocated and so on, does anybody can help me ?
Best regards,
Nicolas
I am writing a driver for a device that generates a bunch of data and stores its in a memory buffer. Driver should read this buffer and store data to a nvme storage. Device and memory buffer are implemented in fpga logic. The buffer size is about 1G. CPU sees it like a regular ram but linux know nothing about it and this is a problem. When I use bio layer in order to save the data I need a strust* page pointer but I don’t have one.
The question is:
Is there any way to save the data from the buffer using just a physical address and size?
Or I have to use pages so I need to add this buffer to linux memory pool somehow.
I have a code that write data to a I2C-EEPROM. The i2c-driver is config to use DMA. But is there anyway I can check that data is transfered by i2c using DMA from my program in user-space?
Thanks!
Running linux kernel 3.14.43, I am reading from a CDC ACM device (implemented on an LPC4330). The device appears at /dev/ttyACM0, and I can open it and read from it in the normal way.
The device appears to be buffering about 4096 bytes (I get reads of 4095 bytes, typically, after a period of mostly 12 byte reads during the early phase of operation). When running on a fancy schmancy workstation, all goes smoothly. However, when running on an embedded device (AM3352), occasionally data goes missing if I go for a high data rate. I suspect the read buffer is being over-filled - the high data rate is fast enough to fill a 4k buffer in not much more than 1msec (3.8MB/s), and it seems very possible that I'm not coming back to the read() call fast enough to keep up, given that the device is doing a bunch of other stuff in other threads and I'm using SCHED_OTHER across the board.
So - first - is there a way to increase the buffer size of the device? As a supplementary, is there any way to detect that the buffers here have overflowed? I guess I have another option of using real-time scheduling for the read() thread but I'd rather not get into that if possible.
Thanks.
I was going through the process of packet transmission and packet reception in latest linux kernel. I can see that, there is a framework in skb where it supports "linear" data as well as "paged" data.
It has a separate structure called skb_shared_info to represent page fragments.
Now my doubt is, how will the device DMA the entire contents of the packet? Is it not going to be scattered across the memory?
Thanks
CHID
It depends on the capability of the networking hardware. Most “modern” NICs can do gather/scatter DMA and handle tranferring a packet into multiple, non-contiguous buffers, but the Linux kernel networking stack will only give an skb with nonlinear data to a driver/netdev if NETIF_F_SG is set (indicating the device can handle scatter/gather). If the device driver sets NETIF_F_SG then it is telling the stack that it can handle multiple physical buffers per packet.