Work queues, tasklets, completions and wait queues.
[cascardo/kernel/slides/.git] / 08time / time
1 %Time Management
2 %Thadeu Cascardo
3
4 # Tickes, Jiffies
5
6 * The timer ticks with a frequency, interrupting the system
7 * Necessary for preemptive scheduling, using a time slice
8 * Linux counts the number of ticks in the *jiffies* variable
9 * It's interrupted *HZ* times in a second
10
11 # Busy waiting
12
13 * time\\_after
14 * time\\_before
15 * cpu\\_relax
16 * udelay
17
18 # Scheduling
19
20 * schedule
21 * set\\_current\\_state
22 * TASK\\_INTERRUPTIBLE
23 * TASK\\_UNINTERRUPTIBLE
24 * TASK\\_RUNNING
25 * schedule\\_timeout
26 * schedule\\_timeout\\_interruptible
27 * msleep
28 * msleep\\_interruptible
29
30 # Timers
31
32 * linux/timer.h
33 * struct timer\\_list
34         - unsigned long expires
35         - void function(unsigned long)
36         - unsigned long data
37 * init\\_timer
38 * TIMER\\_INITIALIZER
39 * add\\_timer
40 * del\\_timer
41 * mod\\_timer
42 * del\\_timer\\_sync
43
44 # Work queues
45
46 * Queues of functions to be called in a kernel thread
47 * They execute in process context, so they may sleep
48 * However, accessing user space memory does not make sense here
49 * Works should not take long or they will delay other works execution
50 * There's a default workqueue, keventd or events
51
52 # Works
53
54 * include linux/workqueue.h
55 * struct work\\_struct
56 * DECLARE\\_WORK(name, func)
57 * INIT\\_WORK(work, func)
58 * queue\\_work(wq, work)
59 * schedule\\_work(work)
60 * flush\\_work(work)
61 * cancel\\_work\\_sync(work)
62
63 # Delayed work
64
65 * struct delayed\\_work
66 * DECLARE\\_DELAYED\\_WORK(name, func)
67 * INIT\\_DELAYED\\_WORK(dwork, func)
68 * queue\\_delayed\\_work(wq, dwork, delay)
69 * schedule\\_delayed\\_work(dwork, delay)
70 * flush\\_delayed\\_work(dwork)
71 * cancel\\_delayed\\_work(dwork)
72 * cancel\\_delayed\\_work\\_sync(dwork)
73
74 # Workqueue
75
76 * create\\_workqueue(name)
77 * create\\_singlethread\\_workqueue(name)
78 * destroy\\_workqueue(wq)
79 * flush\\_workqueue(wq)
80 * flush\\_scheduled\\_work()
81
82 # Tasklets
83
84 * include linux/interrupt.h
85 * struct tasklet\\_struct
86 * DECLARE\\_TASKLET(name, func, data)
87 * tasklet\\_init(tsk, func, data)
88 * tasklet\\_schedule
89 * tasklet\\_hi\\_schedule
90 * tasklet\\_enable
91 * tasklet\\_disable
92 * tasklet\\_kill
93
94 # Completion
95
96 * include linux/completion.h
97 * struct completion
98 * DECLARE\\_COMPLETION(name)
99 * init\\_completion(comp)
100 * wait\\_for\\_completion(comp)
101 * wait\\_for\\_completion\\_interruptible
102 * wait\\_for\\_completion\\_timeout
103 * complete
104
105 # Wait queue
106
107 * include linux/wait.h
108 * wait\\_queue\\_head\\_t
109 * DECLARE\\_WAIT\\_QUEUE\\_HEAD(name)
110 * init\\_waitqueue\\_head(wqh)
111 * wake\\_up(wqh)
112 * wait\\_event(wqh, cond)
113 * wait\\_event\\_timeout(wqh, cond, timeout)
114 * wait\\_event\\_interruptible(wqh, cond)