Info

struct delayed_work {

struct work_struct work; struct timer_list timer;

queue_delayed_work is used to submit instances of delayed_work to a work queue. It ensure that at least one time interval specified (in jiffies) by delay elapses before the deferred work is performed.

kernel/workqueue.c int fastcall queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork, unsigned long delay)

This function first generates a kernel timer whose time-out occurs in delayed jiffies. The associated handler function then uses queue_work to add the work to the work queue in the normal way.

The kernel generates a standard wait queue named events. This queue can be used by all parts of the kernel for which it is not worthwhile creating a separate work queue. The two functions below, whose implementation I need not discuss in detail, must be used to place new work in this standard queue:

kernel/workqueue.c int schedule_work(struct work_struct *work)

int schedule_delayed_work(struct delay_work *dwork, unsigned long delay)

14.5 Summary

The kernel can be activated synchronously or asynchronously. While the preceeding chapter discussed how system calls are employed for synchronous activation, you have seen in this chapter that there is a second, asynchronous activation method triggered from the hardware using interrupts.

Interrupts are used when the hardware wants to notify the kernel of some condition, and there are various ways that interrupts can be implemented physically. After discussing the different possibilities, we have analyzed the generic data structures of the kernel that are employed to manage interrupts, and have seen how to implement flow handling for various IRQ types. The kernel has to provide service routines for IRQs, and some care is required to implement them properly. Most important, it is necessary to make these handlers as fast as possible, and the work is therefore often distributed into a quick top half and a slower bottom half that runs outside the interrupt context.

The kernel offers some means to defer actions until a later point in time, and I have discussed the corresponding possibilities in this chapter: SoftIRQs are the software equivalent to hardware IRQs, and tasklets are built on this mechanism. While they enable the kernel to postpone work until later, they are not allowed to go to sleep. This is, however, possible with wait queues and work queues, also examined in this chapter.

Continue reading here: Time Management

Was this article helpful?

0 0