我是靠谱客的博主 野性大地,这篇文章主要介绍【Linux设备驱动程序(第三版)】----延迟:让出处理器,现在分享给大家,希望可以做个参考。

  【Linux设备驱动程序(第三版)】----延迟:让出处理器

jit.c

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> #include <linux/time.h> #include <linux/timer.h> #include <linux/proc_fs.h> #include <linux/spinlock.h> #include <linux/interrupt.h> #include <asm/hardirq.h> #include <linux/sched.h>//jiffies #include <linux/kernel.h> #include <linux/types.h>//u64 #include <linux/fs.h>//file_operations, file #include <linux/completion.h> #include <asm/uaccess.h>//copy_to_user & copy_from_user int delay = HZ; enum jit_files { JIT_BUSY, JIT_SCHED, JIT_QUEUE, JIT_SCHEDTO }; int jit_fn(char *buf, char **start, off_t offset, int len, int *eof, void *data) { unsigned long j0, j1; wait_queue_head_t wait; init_waitqueue_head(&wait); j0 = jiffies; j1 = j0 + delay; switch((long)data){ case JIT_BUSY: while(time_before(jiffies, j1)) cpu_relax(); break; case JIT_SCHED: while(time_before(jiffies, j1)) schedule(); break; } j1 = jiffies; len = sprintf(buf, "%9li %9lin", j0, j1); *start = buf; return len; } int jit_currentime(char *buf, char **start, off_t offset, int len, int *eof, void *data) { struct timeval tv1; struct timespec tv2; unsigned long j1; u64 j2; j1 = jiffies; j2 = get_jiffies_64(); do_gettimeofday(&tv1); tv2 = current_kernel_time(); len = 0; len += sprintf(buf,"0x%08lx 0x%016Lx %10i.%06in" "%40i.%09in", j1, j2, (int) tv1.tv_sec, (int) tv1.tv_usec, (int) tv2.tv_sec, (int) tv2.tv_nsec); *start = buf; return len; } int __init jit_init(void) { create_proc_read_entry("jit_currentime", 0, NULL, jit_currentime, NULL); create_proc_read_entry("jitbusy", 0, NULL, jit_fn, (void *)JIT_BUSY); create_proc_read_entry("jitsched", 0, NULL, jit_fn, (void *)JIT_SCHED); return 0; } void __exit jit_exit(void) { remove_proc_entry("jit_currentime", NULL); remove_proc_entry("jitbusy", NULL); remove_proc_entry("jitsched", NULL); } MODULE_LICENSE("Dual BSD/GPL"); module_init(jit_init); module_exit(jit_exit);


Makefile

复制代码
1
2
3
4
5
6
7
8
9
10
11
obj-m:= jit.o modules-objs:= jit.o KDIR:= /usr/src/linux-headers-2.6.31-14-generic/ PWD:= $(shell pwd) default: make -C $(KDIR) M=$(PWD) modules clean: rm -rf *.ko *.mod.c *.mod.o *.o *.markers *.symvers *.order


装载

复制代码
1
insmod jit.ko


测试

复制代码
1
dd bs=20 count=5 < /proc/jitsched


卸载

复制代码
1
rmmod jit


 

最后

以上就是野性大地最近收集整理的关于【Linux设备驱动程序(第三版)】----延迟:让出处理器的全部内容,更多相关【Linux设备驱动程序(第三版)】----延迟内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部