linux process of introduction of sleep

What is the process for a "sleep" mean? When a process is put to sleep, it is identified as being in a particular state and removed from the run queue scheduler in. Until something happens that changes the state of the process will It is not scheduled on any CPU, and, therefore, will not run. a sleeping process has been shelved to the side of the system, wait for after the incident.

 

For a Linux driver to make a process sleep it is an easy thing to do. However, there are several rules must be remembered in a safe manner coding sleep.

 

The first of these rules is: can not sleep when you're running in atomic context we introduced atomic operations in Chapter 5; a context atom is just a state, where a number of steps must be without any type of concurrent access situation. under carried out. this means that for sleep, your drive can not sleep while holding a spin lock, seqlock, or RCU lock. If you turned off and you can not interrupt sleep. sleep while holding a flag is legitimate, but you should carefully review any code to do so. If the code to sleep while holding a flag, any other thread is also waiting for the flag to sleep. so occurs while holding a flag of any sleep should be brief, and you should convince yourself, because the holders of this flag, you can not block this process will eventually awaken you.

 

Another thing to keep in mind is that when you wake up, you never know your process while leaving the CPU how long or what changes have happened. You often do not know if another process has to sleep waiting for the same event ; that process might wake up and before you get the resources you're waiting for the result is that you can not state on the system after you wake up make any assumptions, and you must check to make sure you wait condition is really, really of.

 

Also a related point, of course, is your process can not sleep unless others are convinced that somewhere, it will wake up. Wake-up work to do code must also be able to find your process to do its work to ensure a wake-up occurs, is deeply consider your code and for each sleep, know exactly what series of events that will end sleep. make your processes may be found, really, by a data structure called a queue waiting for implementation. a waiting queue is that it sounds like: a list of processes, we are waiting for a particular event.

 

In Linux, a queue by a "wait queue head" to manage a wait_queue_head_t types of structures, the definition of a wait queue head may be defined and initialized at <linux / wait.h> using:

 

DECLARE_WAIT_QUEUE_HEAD(name);

 

Or dynamically, as follows:

 

wait_queue_head_t my_queue; init_waitqueue_head(&my_queue);

 

We will soon return to the queue structure, but we know enough to look at the first sleep and wake.

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11141829.html