On Tue, Jul 16, 2002, Muli Ben-Yehuda wrote about "device files implementing mmap":
>...
> My question: how does the kernel "notify" the user space process that
> there's new data to be read, 'n' bytes, starting from offset 'foo' in
> the buffer? Is there a standard way to do it?
> 
> The little research I've just done indicates that there's no standard
> way. The drivers I've looked at use a combination of poll/select and
> ioctl (yuck) to implement it. Does anyone know of a standard (or at
> least well accepted) way to accomplish this feat? I don't mind

Well, you want your driver to give the user two features: a way to sleep
until data in in the buffer, and then a way to know which part of the
buffer is new data (offset+length). Obviously, you can have the sleeping
part done with select() and then the fetching-offset-and-length part done
with ioctl(), but you called this "yuck".

If the "yucky" part is that you need two system calls, well, you can put
current offset in the buffer inside the buffer itself, in a fixed position.
But I'm not sure how you'd protect this offset from concurrent access (if
you at all need such protection). Some drivers (e.g., /dev/epoll) don't
need such protection, and only use a double-buffer to protect the kernel
and the user-space from reading and writing at the same spot concurrently.

Another alternative I can think of is to have the read() system call on your
device always return 8 bytes (say), two integers specifying the offset and
size of the new data (which the user will need to fetch using the mapped
memory). In this case, one system call - read() - will both block until new
data arrives and fetch the location of that data. You can select() and then
read() - but I don't see how this would be better than the select() and then
ioctl() which you called "yuck".

-- 
Nadav Har'El                        |          Tuesday, Jul 16 2002, 7 Av 5762
[EMAIL PROTECTED]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Cigarette: tobacco wrapped in paper, fire
http://nadav.harel.org.il           |at one end, and a fool at the other.

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to