Import course "ementa" as a content index.
[cascardo/kernel/notes/.git] / 06.process / text
1 Process context:
2 Pode fazer:
3         current
4         copy_to_user
5         copy_from_user
6         GFP_KERNEL
7 Onde:
8         contexto de processo (chamada de sistema)
9         workqueue
10
11 NOTA: work da wq executa em uma kthread e pode fazer copy_to_user e
12 copy_from_user, segundo esse comentário em kernel/kmod.c:
13                 /*
14                  * Normally it is bogus to call wait4() from in-kernel because
15                  * wait4() wants to write the exit code to a userspace address.
16                  * But wait_for_helper() always runs as keventd, and put_user()
17                  * to a kernel address works OK for kernel threads, due to their
18                  * having an mm_segment_t which spans the entire address space.
19                  *
20                  * Thus the __user pointer cast is valid here.
21                  */
22
23 Atomic context:
24 Pode fazer:
25         GFP_ATOMIC
26 Não pode fazer:
27         copy_{to,from}_user
28         GFP_KERNEL
29         "dormir"
30         schedule
31         mutex
32         wait
33 Onde:
34         interrupção
35         spinlock
36         timers
37         tasklet
38
39
40
41 NOTES:
42 scalable SMP: that's what's important (for most people, anyway)
43 BKL: not scalable
44 Bottom Half: after handling interrupts, Linux executes the bottom half
45         (TODO: Check this)
46         Bottom Halves were "single-threaded": only one bottom half could
47         execute at a time (only one or only one NET_BH?).
48                 UPDATE: only one. tasklets allow a single tasklet to run
49                 on only one CPU at a time. But other tasklets may run on
50                 other CPUs.
51         Bottom Half now is softirq and tasklet (which is a softirq
52         itself).
53 spin_lock_irqsave
54         Disables interrupts in the local CPU
55         Why? Explanation: CPU 1 grabs spinlock, CPU 1 is interrupted and
56                 handler grabs same spinlock: spins forever (code will not
57                 migrate? TODO). Second scenario: CPU 2 is interrupted and
58                 grabs the same lock, CPU 1 has the chance to release the
59                 lock and CPU 2 will go on.
60 spin_lock_bh
61         If used only in process context and BHs
62 local_irq_disable() or local_irq_save(flags)
63         It's enough when data is per-CPU. That is, there will not be
64         concurrency between CPUs, but only between interrupt handler
65         and process code.
66 CPU affinity: softirq runs on the same CPU it was raised on.
67
68
69
70 --
71
72 CONFIG_DEBUG_PREEMPT
73 Preemption.
74
75 preempt_disable - disable preemption in current CPU TODO: check "current"
76 preempt_enable - enable preemption in current CPU
77
78
79 --
80 SMP
81
82 Trabalhando com CPUs.
83 smp_processor_id() retorna ID do processador corrente: só pode ser utilizado se
84         a tarefa estiver amarrada a um processador ou em um contexto não
85         preemptível (preempt off)
86 get_cpu - desabilita preempção e retorna ID da CPU
87 put_cpu - reabilita preempção
88
89
90 Referências:
91 "I'll Do It Later: Softirqs, Tasklets, Bottom Halves, Task Queues, Work Queues
92 and Timers" by Matthew Wilcox
93
94
95 TODO:
96 Zoombie
97 Defunct
98 Uninterruptible
99 Unkillable
100
101
102
103