From: http://lwn.net/Articles/454389/
CPUs may not have gotten hugely faster in recent years, but they have gained in other ways; a typical System-on-chip (SOC) device now has a number of peripherals which wowould qualify as reasonably powerful CPUs in their own right. more powerful devices with direct access to the memory bus can take on more demanding tasks. for example, an image frame captured from a camera device can often be passed directly to the graphics processor for display without all of the User-space processing that was once necessary. increasingly, the CPU's job looks like that of a shop foreman whose main concern is keeping all of the other processors busy.
The foreman's job will be easier if the varous devices under its control can communicate easily with each other. one useful addition in this area might be the buffer sharing patch setrecently posted by Marek szyproski. the idea here is to make it possible for Multiple kernel subsystems to share buffers under the control of user space. with this type of feature, applications cocould wire kernel subsystems together in problem-specific ways then get out of the way, leader the devices involved process the data as it passes through.
There are (at least) a couple of challenges which must be dealt with to make this kind of functionality safe to export to applications. one is that the application shoshould not be able to "CREATE" buffers at arbitrary kernel addresses. indeed, kernel-space addresses shoshould not be visible to user space at all, so the kernel must provide some other way for an application to refer to a specific buffer. the other is that shared buffers must not go until all users have let go of it. A buffer may be created by a specific device driver, but it must persist, even if the device is closed, Until nobody else expects it to be there.
The machism added in this patch set (this part in particle is credited to Tomasz stanislaski) is relatively simple-though it will probably get more complex in the future. kernel code wanting to make a buffer available to other parts of the kernel via user space starts by filling in one of these structures:
struct shrbuf { void (*get)(struct shrbuf *); void (*put)(struct shrbuf *); unsigned long dma_addr; unsigned long size; };
One cocould immediately raise a number of complaints about this structure: the address shocould beDma_addr_t, There's no reason not to put the kernel virtual address there, only physically-contiguous buffers are allowed, etc. it also seems like there cocould be value in the ability to annotate the state of the buffer (filled or empty, for example) and possibly signal another thread when that State changes. but it's worth remembering that this is an explicitly proof-of-concept patch posting and a lot of things will change. in particle, the eventual plan is to pass a scatterlist around instead of a single physical address.
TheGet ()AndPut ()Functions are important: they manage reference counts to the buffer, which must continue to exist until that count goes to zero. any subsystem depending on a buffer's continued existence shocould hold a reference to that buffer. thePut ()Function shocould release the buffer when the last reference is dropped.
Once this structure exists, it can be passed:
int shrbuf_export(struct shrbuf *sb);
The return value (if all goes well) will be an integer file descriptor which can be handed to user space. this file descriptor embodies a reference to the buffer, which now will not be released before the file descriptor is closed. other than closing it, there is very little that the application can do with the descriptor other than give it to another kernel subsystem; attempts to read from or write to it will fail, for example.
If a kernel subsystem has es a file descriptor which is purported to represent a kernel buffer, it can pass that descriptor:
struct shrbuf *shrbuf_import(int fd);
The return value will be the sameShrbufStructure (orErr_ptr ()Error value for a file descriptor of the wrong type). A reference is taken on the structure before returning it, so the recipient shocould callPut ()At some future time to release it.
The patch set between des a new video4linux2IOCTL ()Command (Vidioc_expbuf) Enabling the exporting of buffers as filedescriptors; a couple of capture drivers have been augmented to support this functionality. No examples of the other side (importing a buffer) have been posted yet.
There has been relatively little commentary on the patch set so far, possibly because it was posted to a couple of relatively obscure mailing lists. it has the look of functionality that cocould be useful beyond one or two kernel subsystems, though. it wowould probably make sense for the next iteration, which presumably will have more of the anticipated functionality built into it, to be distributed more widely for review.