File tree Expand file tree Collapse file tree 3 files changed +39
-28
lines changed Expand file tree Collapse file tree 3 files changed +39
-28
lines changed Original file line number Diff line number Diff line change @@ -4032,6 +4032,41 @@ Possible very likely outcome:
4032
4032
4033
4033
The threads almost always interleaved nicely, thus confirming that they are actually running in parallel.
4034
4034
4035
+ ===== schedule
4036
+
4037
+ Let's block the entire kernel! Yay:
4038
+
4039
+ .....
4040
+ ./run -F 'dmesg -n 1;insmod /schedule.ko schedule=0'
4041
+ .....
4042
+
4043
+ Outcome: the system hangs, the only way out is to kill the VM.
4044
+
4045
+ Source: link:kernel_module/schedule.c[]
4046
+
4047
+ kthreads only allow interrupting if you call `schedule()`, and the `schedule=0` <<kernel-module-parameters,kernel module parameter>> turns it off.
4048
+
4049
+ Sleep functions like `usleep_range` also end up calling schedule.
4050
+
4051
+ If we allow `schedule()` to be called, then the system becomes responsive:
4052
+
4053
+ .....
4054
+ ./run -F 'dmesg -n 1;insmod /schedule.ko schedule=1'
4055
+ .....
4056
+
4057
+
4058
+ and we can observe the counting with:
4059
+
4060
+ ....
4061
+ dmesg -w
4062
+ ....
4063
+
4064
+ The system also responds if we <<number-of-cores,add another core>>:
4065
+
4066
+ ....
4067
+ ./run -c 2 -F 'dmesg -n 1;insmod /schedule.ko schedule=0'
4068
+ ....
4069
+
4035
4070
=== IRQ
4036
4071
4037
4072
==== irq.ko
Original file line number Diff line number Diff line change 1
1
https://github.com/cirosantilli/linux-kernel-module-cheat#directory-structure
2
2
3
3
. Asynchronous
4
- .. link:irq.c[]
5
- .. link:schedule.c[]
6
4
.. link:sleep.c[]
7
5
.. link:timer.c[]
8
6
.. link:work_from_work.c[]
Original file line number Diff line number Diff line change 1
- /*
2
- Let's block the entire kernel! Yay!
3
-
4
- kthreads only allow interrupting if you call schedule.
5
-
6
- If you don't, they just run forever, and you have to kill the VM.
7
-
8
- Sleep functions like usleep_range also end up calling schedule.
9
-
10
- Test with:
11
-
12
- dmesg -n 1
13
- insmod /schedule.ko yn=[01]
14
- dmesg | tail
15
-
16
- Then:
17
-
18
- - yn=0:
19
- - `qemu -smp 1`: everything blocks!
20
- - `qemu -smp 2`: you can still use the board, but is it noticeably slow
21
- - yn=1: all good
22
- */
1
+ /* https://github.com/cirosantilli/linux-kernel-module-cheat#schedule */
23
2
24
3
#include <linux/kernel.h>
25
4
#include <linux/kthread.h>
26
5
#include <linux/module.h>
27
6
#include <uapi/linux/stat.h> /* S_IRUSR | S_IWUSR */
28
7
29
- static int yn = 1 ;
30
- module_param (yn , int , S_IRUSR | S_IWUSR );
31
- MODULE_PARM_DESC (yn , "A short integer" );
8
+ static int do_schedule = 1 ;
9
+ module_param_named (schedule , do_schedule , int , S_IRUSR | S_IWUSR );
32
10
33
11
static struct task_struct * kthread ;
34
12
@@ -38,7 +16,7 @@ static int work_func(void *data)
38
16
while (!kthread_should_stop ()) {
39
17
pr_info ("%u\n" , i );
40
18
i ++ ;
41
- if (yn )
19
+ if (do_schedule )
42
20
schedule ();
43
21
}
44
22
return 0 ;
You can’t perform that action at this time.
0 commit comments