Multi-threading access to device drivers.

John-Mark Gurney gurney_j at resnet.uoregon.edu
Sat Nov 6 16:38:47 PST 2004


Poul-Henning Kamp wrote this message on Sun, Nov 07, 2004 at 00:39 +0100:
> Assume a device driver which is not Giant-handicapped.
> 
> Assume an I/O path which does not need Giant to get from
> read(2) to the device driver.
> 
> Assume a SMP machine.
> 
> Assume a process with two threads on two CPUs, both
> doing read(fd, buf, len) at the same time.
> 
> Should we let both reads into the driver at the same time ?
> 
> If so, which uio_offset do we hand them ?

As was quoted POSIX, the update should be atomic..  so my reading of
that is that you lock the fd, when you read the offset from the fd,
you need to also update the offset with the number of bytes read, so
that a racing read both doesn't drop any data, nor duplicate any data..

i.e.  single file with fixed records, it should be perfectly safe to
throw five threads looping doing a read processing of the records w/o
fear of duplicate records, or dropped records...

And if we handle it in this manner, then you can allow multiple reads
into the driver...

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."


More information about the freebsd-arch mailing list