Skip to contentSkip to conversation

Linux Kernel generic question (procedure queue)

DISCUSSION None Atall 3 participants 3 messages May 6, 2003

lore
Share & tools
lore

None Atall

author
#0 lore raw

Hello everybody,
Is it possible to insert
a specific procedure (among with it's args) to the kernel scheduler? I know that we can just call schedule(); when we wait for an asychronus input or we can even insert an interrupt to the kernel queue, but is it possible to queue a procedure?
Just for understanding the problem better, I have
a function write_buff that calls write_byte. Write_byte
function uses PPC gpio for implementing something like an SPI interface. When we write a big file (e.x 1M), the system will not respond to anything until the transfer is done. I inserted "schedule();" every time the write_byte is called so that the system will accually perform some other tasks. So my question is if I could insert write_byte function to the scheduler queue in such a way to prevent this problem.

Thanks in advance
Dimitrios.

=====
------------------------------------------------------------
-Dhmhtrios Meidanis
-Degree in Mathematics, University of the Aegean. -Master in Computer Architecture and Digital
Systems, University of Crete.
Greece.
------------------------------------------------------------

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#1 lore raw
Quoted 9 lines

Hello everybody,
Is it possible to insert
a specific procedure (among with it's args) to the kernel scheduler? I know that we can just call schedule(); when we wait for an asychronus input or we can even insert an interrupt to the kernel queue, but is it possible to queue a procedure?

not realy the same effect but you could use a tasklet and call tasklet_schedule(&write_byte_tasklet);
where the write_bytee tasklet is nothing else but your write_byte function.

Quoted 11 lines

Just for understanding the problem better, I have
a function write_buff that calls write_byte. Write_byte
function uses PPC gpio for implementing something like an SPI interface. When we write a big file (e.x 1M), the system will not respond to anything until the transfer is done. I inserted "schedule();" every time the write_byte is called so that the system will accually perform some other tasks. So my question is if I could insert write_byte function to the scheduler queue in such a way to prevent this problem.

hofrat

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#2 lore raw
In reply to None Atall

Hello Dimitrios,

There are a number of mechanisms in the Linux kernel that allow you to schedule execution of some code at a later time as well as to wait for something to happen. Wait queues, tasklets, kernel timers are the most important ones.

The problem is that to choose and to use them properly you need to know how they work, how they differ from each other and how they are supposed to be used (because they can easily be misused and this usually leads to disasters). It is definitely not possible to go over it in an email, so I'd refer you to the excellent book by Rubini and Corbet that discusses all these (and many other) issues.

As for your question goes, there are two main mechanisms you should look at:
-- wait queues are usually used in drivers to
return the control to the scheduler until the HW operation is finished. Look for interruptible_sleep_on() and wake_up_interruptible()

-- I don't know exactly how do you plan to use your GPIOs
to implement SPI, but if you plan to use interrupts you might be better of by using the write_buff() function to fill your driver's buffer, submit the first byte to the device via write_byte() and then go to sleep on a wait queue. Then use the interrupt handler to drain the buffer and wake up the process after you have finished sending data (you can also use kernel timers to wake it up in case there was a timeout).

But my main advise will be to get yourself a copy of "Linux Device Drivers" by Rubini and Corbet first.

Happy hacking,
Vladimir Gurevich

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/