Re: async i/o question



anatolik schrieb:
There could be several application working with same kernel
module at the same time.

Then you just misuderstood how the kernel works when processing read(),
write() etc.: In process context, the kernel isn't like an application,
it's like a library.

Second, there are interrupt routines.

Usually a driver has both things implemented. A part which works in process
context and a interrupt routine part which does all the work with the
hardware, both communicating through command/data queues.


In process context, your kernel driver has to ensure it does not use single
global resources, but take them from a pool instead. Each time your device
file is being opened by an application, your driver module has to allocate
and initialize some memory for your buffers and control variables which
belong to the file descriptor of open(). On close(), your driver has to
free that ressources. Inbetween, all the read(), write() etc. calls the
application makes are passing the file descriptor to your driver module,
which can look up the data structure from it. Voila, concurrency enabled by
design.


If you have some single ressource which cannot be shared (e.g. a physical
port), you have to *lock* it some way. Usual way is to implement either a
lock on the device node itself, so the device node cannot be opened more
that *once*, or (better) to implement two command/data buffer queues, which
are filled by write() and emptied by an interrupt routine on sending from
the first queue and vice versa on receiving from the second queue. The
actual port operation is done by the interrupt routine alone.


Kind regards

Jan



.



Relevant Pages

  • RE: schedule_work returns FAILURE (0)
    ... In 2.4 series there were three different kind of task queues: ... Scheduler and Immediate. ... driver has a very heavy / time intensive bottom half function? ... > is to be called as bottom half) run at process context OR Interrupt ...
    (Linux-Kernel)
  • Re: How to avoid data copies in a driver ?
    ... You cannot use a user-mode file-descriptor in the kernel. ... The kernel itself doesn't have a process context. ... Using memory mapping as previously advised, lets you DMA ...
    (Linux-Kernel)
  • Re: Spinlock query
    ... > In my driver, I have written the following code: ... interrupt handler tries to grab the spinlock, ... Why will it "BOOM"? ... You need to use spin_lock_irqsavefrom process context. ...
    (Linux-Kernel)
  • Re: NDIS/Networking Newbie
    ... process context is not available ... at driver level. ... Some thoughts on NDIS: ... An NDIS Filter intermediate driver implements a 1:1 relation ...
    (microsoft.public.development.device.drivers)
  • [-mm patch 2/8] more s/fucn/func/ typo fixes
    ... * Use the following fucntions to pin gameport's driver in process context ... + * Use the following functions to pin gameport's driver in process context ... static inline void serio_pause_rx(struct serio *serio) ...
    (Linux-Kernel)