Linux内核设备驱动程序中的散集列表

时间:2022-12-31 00:26:24

I am working on a device driver that has access to a scatter-gather list (sg) element. I am able to extract the data out of it and store it in an allocated buffer using sg_copy_to_buffer. Now, my idea is to create a new scatterlist and copy from this buffer into the new scatterlist I create (ofcourse this is done later) and return this new scatterlist back to the kernel. (This is for performance metrics, etc.) I tried searching online for documentation to use scatterlist, etc. but to no avail. What I typically am doing:

我正在开发一个设备驱动程序,它可以访问散集列表(sg)元素。我能够从其中提取数据,并使用sg_copy_to_buffer将其存储在一个分配的缓冲区中。现在,我的想法是创建一个新的散列表,并从这个缓冲区复制到我创建的新散列表中(当然这将在后面完成),并将这个新的散列表返回到内核。(这是针对性能度量等)我尝试在网上搜索文档来使用散列表等,但是没有任何效果。我通常做的是:

char *buffer = kmalloc (***);
struct scatterlist *sglist = kmalloc (sizeof (struct scatterlist)...);
sg_init_one(sglist, buffer, BUFFER_SIZE);

sg_copy_to_buffer (inp_sglist, inp_sglist_len, buffer);

*** Later ***
sg_copy_from_buffer (sglist, 1, buffer);

Is there a good documentation to help me map my scatterlist to a virtual buffer? I tried looking at http://lwn.net/Articles/256368/ http://www.linuxjournal.com/article/7104 etc.

是否有好的文档可以帮助我将散列表映射到虚拟缓冲区?我尝试查看http://lwn.net/Articles/256368/ http://www.linuxjournal.com/article/7104等。

Any help or pointers would be appreciated!

如有任何帮助或建议,我们将不胜感激!

1 个解决方案

#1


1  

Typically the user allocates a buffer in their virtual memory and then calls the device driver. When the user issues a write, you get the sglist for the buffer with the write data and use it in the sg_copy_to_buffer(). When the user issues a read, you get the sglist for the read data buffer and use it in the sg_copy_from_buffer().

通常,用户在其虚拟内存中分配缓冲区,然后调用设备驱动程序。当用户发出写操作时,您将获得带有写数据的缓冲区的sglist,并在sg_copy_to_buffer()中使用它。当用户发出读取时,您将获得读取数据缓冲区的sglist,并在sg_copy_from_buffer()中使用它。

The call to get the sglist from the I/O request is described in the article. It is a good article, but almost 10 years old. Many x86 systems now have an IOMMU to support hardware virtualization.

本文描述了从I/O请求获取sglist的调用。这是一篇很好的文章,但差不多有10年了。许多x86系统现在都有一个IOMMU来支持硬件虚拟化。

Usually device drivers use the sglist to generate a list of device I/O operations, one for each disjoint block of data in a sglist entry, not to copy the data into a local buffer.

通常,设备驱动程序使用sglist来生成设备I/O操作的列表,一个用于sglist条目中每个互不相交的数据块,而不是将数据复制到本地缓冲区。

#1


1  

Typically the user allocates a buffer in their virtual memory and then calls the device driver. When the user issues a write, you get the sglist for the buffer with the write data and use it in the sg_copy_to_buffer(). When the user issues a read, you get the sglist for the read data buffer and use it in the sg_copy_from_buffer().

通常,用户在其虚拟内存中分配缓冲区,然后调用设备驱动程序。当用户发出写操作时,您将获得带有写数据的缓冲区的sglist,并在sg_copy_to_buffer()中使用它。当用户发出读取时,您将获得读取数据缓冲区的sglist,并在sg_copy_from_buffer()中使用它。

The call to get the sglist from the I/O request is described in the article. It is a good article, but almost 10 years old. Many x86 systems now have an IOMMU to support hardware virtualization.

本文描述了从I/O请求获取sglist的调用。这是一篇很好的文章,但差不多有10年了。许多x86系统现在都有一个IOMMU来支持硬件虚拟化。

Usually device drivers use the sglist to generate a list of device I/O operations, one for each disjoint block of data in a sglist entry, not to copy the data into a local buffer.

通常,设备驱动程序使用sglist来生成设备I/O操作的列表,一个用于sglist条目中每个互不相交的数据块,而不是将数据复制到本地缓冲区。