update · OSDI/linux_kernel_driver@3b862b1 · GitHub
Skip to content

Commit 3b862b1

Browse files
author
gigi
committed
update
1 parent d7ee11c commit 3b862b1

342 files changed

Lines changed: 14303 additions & 3641 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

example/LDDP_JP/TW-samples/chap10/atomic/main.c

Lines changed: 11 additions & 11 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* main.c
3+
*
4+
*/
5+
#include <linux/init.h>
6+
#include <linux/module.h>
7+
8+
MODULE_LICENSE("Dual BSD/GPL");
9+
10+
atomic_t counter = ATOMIC_INIT(0);
11+
12+
static int sample_init(void)
13+
{
14+
int n;
15+
16+
atomic_inc(&counter);
17+
n = atomic_read(&counter);
18+
19+
printk("n %d\n", n);
20+
21+
if (atomic_dec_and_test(&counter)) {
22+
printk("atomic_dec_and_test() TRUE\n");
23+
} else {
24+
printk("atomic_dec_and_test() FALSE\n");
25+
}
26+
27+
return 0;
28+
}
29+
30+
static void sample_exit(void)
31+
{
32+
printk("sample driver removed.\n");
33+
}
34+
35+
module_init(sample_init);
36+
module_exit(sample_exit);
37+

example/LDDP_JP/TW-samples/chap10/completion/main.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,47 @@ static pid_t thr_pid;
1515

1616
static int sample_thread(void *num)
1717
{
18-
printk("%s called\n", __func__);
18+
printk("%s called\n", __func__);
1919

20-
daemonize("sample_thread");
21-
allow_signal(SIGTERM);
20+
daemonize("sample_thread");
21+
allow_signal(SIGTERM);
2222

23-
for (;;) {
24-
sleep_on_timeout(&wait, 3 * HZ);
23+
for (;;) {
24+
sleep_on_timeout(&wait, 3 * HZ);
2525

26-
if (signal_pending(current))
27-
break;
28-
}
26+
if (signal_pending(current))
27+
break;
28+
}
2929

30-
printk("%s leaved\n", __func__);
30+
printk("%s leaved\n", __func__);
3131

32-
complete_and_exit(&comp, 0);
32+
complete_and_exit(&comp, 0);
3333

34-
return 0;
34+
return 0;
3535
}
3636

3737
static int sample_init(void)
3838
{
39-
printk("sample driver installed.\n");
39+
printk("sample driver installed.\n");
4040

41-
init_completion(&comp);
42-
init_waitqueue_head(&wait);
41+
init_completion(&comp);
42+
init_waitqueue_head(&wait);
4343

44-
thr_pid = kernel_thread(sample_thread, NULL, CLONE_FS | CLONE_FILES);
45-
if (thr_pid < 0) {
46-
return -EINVAL;
47-
}
48-
printk("kernel_thread %d PID\n", thr_pid);
44+
thr_pid = kernel_thread(sample_thread, NULL, CLONE_FS | CLONE_FILES);
45+
if (thr_pid < 0) {
46+
return -EINVAL;
47+
}
48+
printk("kernel_thread %d PID\n", thr_pid);
4949

50-
return 0;
50+
return 0;
5151
}
5252

5353
static void sample_exit(void)
5454
{
55-
printk("sample driver removed.\n");
55+
printk("sample driver removed.\n");
5656

57-
kill_proc(thr_pid, SIGTERM, 1);
58-
wait_for_completion(&comp);
57+
kill_proc(thr_pid, SIGTERM, 1);
58+
wait_for_completion(&comp);
5959
}
6060

6161
module_init(sample_init);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* main.c
3+
*
4+
*/
5+
#include <linux/init.h>
6+
#include <linux/module.h>
7+
#include <linux/sched.h>
8+
#include <linux/completion.h>
9+
10+
MODULE_LICENSE("Dual BSD/GPL");
11+
12+
static wait_queue_head_t wait;
13+
static struct completion comp;
14+
static pid_t thr_pid;
15+
16+
static int sample_thread(void *num)
17+
{
18+
printk("%s called\n", __func__);
19+
20+
daemonize("sample_thread");
21+
allow_signal(SIGTERM);
22+
23+
for (;;) {
24+
sleep_on_timeout(&wait, 3 * HZ);
25+
26+
if (signal_pending(current))
27+
break;
28+
}
29+
30+
printk("%s leaved\n", __func__);
31+
32+
complete_and_exit(&comp, 0);
33+
34+
return 0;
35+
}
36+
37+
static int sample_init(void)
38+
{
39+
printk("sample driver installed.\n");
40+
41+
init_completion(&comp);
42+
init_waitqueue_head(&wait);
43+
44+
thr_pid = kernel_thread(sample_thread, NULL, CLONE_FS | CLONE_FILES);
45+
if (thr_pid < 0) {
46+
return -EINVAL;
47+
}
48+
printk("kernel_thread %d PID\n", thr_pid);
49+
50+
return 0;
51+
}
52+
53+
static void sample_exit(void)
54+
{
55+
printk("sample driver removed.\n");
56+
57+
kill_proc(thr_pid, SIGTERM, 1);
58+
wait_for_completion(&comp);
59+
}
60+
61+
module_init(sample_init);
62+
module_exit(sample_exit);
63+

example/LDDP_JP/TW-samples/chap10/kthread/main.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,40 @@ static wait_queue_head_t wait;
1414

1515
static int sample_thread(void *num)
1616
{
17-
printk("%s called\n", __func__);
17+
printk("%s called\n", __func__);
1818

19-
for (;;) {
20-
sleep_on_timeout(&wait, 3 * HZ);
19+
for (;;) {
20+
sleep_on_timeout(&wait, 3 * HZ);
2121

22-
if (kthread_should_stop())
23-
break;
24-
}
22+
if (kthread_should_stop())
23+
break;
24+
}
2525

26-
printk("%s leaved\n", __func__);
26+
printk("%s leaved\n", __func__);
2727

28-
return 0;
28+
return 0;
2929
}
3030

3131
static int sample_init(void)
3232
{
33-
printk("sample driver installed.\n");
33+
printk("sample driver installed.\n");
3434

35-
init_waitqueue_head(&wait);
35+
init_waitqueue_head(&wait);
3636

37-
kmain_task = kthread_create(sample_thread, NULL, "sample_kthread");
38-
if (IS_ERR(kmain_task)) {
39-
return PTR_ERR(kmain_task);
40-
}
41-
wake_up_process(kmain_task);
37+
kmain_task = kthread_create(sample_thread, NULL, "sample_kthread");
38+
if (IS_ERR(kmain_task)) {
39+
return PTR_ERR(kmain_task);
40+
}
41+
wake_up_process(kmain_task);
4242

43-
return 0;
43+
return 0;
4444
}
4545

4646
static void sample_exit(void)
4747
{
48-
printk("sample driver removed.\n");
48+
printk("sample driver removed.\n");
4949

50-
kthread_stop(kmain_task);
50+
kthread_stop(kmain_task);
5151
}
5252

5353
module_init(sample_init);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* main.c
3+
*
4+
*/
5+
#include <linux/init.h>
6+
#include <linux/module.h>
7+
#include <linux/kthread.h>
8+
#include <linux/sched.h>
9+
10+
MODULE_LICENSE("Dual BSD/GPL");
11+
12+
static struct task_struct *kmain_task = NULL;
13+
static wait_queue_head_t wait;
14+
15+
static int sample_thread(void *num)
16+
{
17+
printk("%s called\n", __func__);
18+
19+
for (;;) {
20+
sleep_on_timeout(&wait, 3 * HZ);
21+
22+
if (kthread_should_stop())
23+
break;
24+
}
25+
26+
printk("%s leaved\n", __func__);
27+
28+
return 0;
29+
}
30+
31+
static int sample_init(void)
32+
{
33+
printk("sample driver installed.\n");
34+
35+
init_waitqueue_head(&wait);
36+
37+
kmain_task = kthread_create(sample_thread, NULL, "sample_kthread");
38+
if (IS_ERR(kmain_task)) {
39+
return PTR_ERR(kmain_task);
40+
}
41+
wake_up_process(kmain_task);
42+
43+
return 0;
44+
}
45+
46+
static void sample_exit(void)
47+
{
48+
printk("sample driver removed.\n");
49+
50+
kthread_stop(kmain_task);
51+
}
52+
53+
module_init(sample_init);
54+
module_exit(sample_exit);
55+

example/LDDP_JP/TW-samples/chap10/rmw/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ MODULE_LICENSE("Dual BSD/GPL");
99

1010
static int sample_init(void)
1111
{
12-
volatile int n = 0;
12+
volatile int n = 0;
1313

14-
n++;
15-
printk("n %d\n", n);
14+
n++;
15+
printk("n %d\n", n);
1616

17-
return 0;
17+
return 0;
1818
}
1919

2020
static void sample_exit(void)
2121
{
22-
printk("sample driver removed.\n");
22+
printk("sample driver removed.\n");
2323
}
2424

2525
module_init(sample_init);
Lines changed: 27 additions & 0 deletions

0 commit comments

Comments
 (0)