【Linux设备驱动程序(第三版)】----延迟:超时(wait_event_interruptible_timeout)
来源:互联网 发布:mac pyqt5 python2.7 编辑:程序博客网 时间:2024/06/05 03:39
【Linux设备驱动程序(第三版)】----延迟:超时(wait_event_interruptible_timeout)
jit.c
#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_userint 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;case JIT_QUEUE:wait_event_interruptible_timeout(wait, 0, delay);break;}j1 = jiffies;len = sprintf(buf, "%9li %9li\n", 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.%06i\n" "%40i.%09i\n", 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);create_proc_read_entry("jitqueue", 0, NULL, jit_fn, (void *)JIT_QUEUE);return 0;}void __exit jit_exit(void){remove_proc_entry("jit_currentime", NULL);remove_proc_entry("jitbusy", NULL);remove_proc_entry("jitsched", NULL);remove_proc_entry("jitqueue", NULL);}MODULE_LICENSE("Dual BSD/GPL");module_init(jit_init);module_exit(jit_exit);
Makefile
obj-m:= jit.omodules-objs:= jit.oKDIR:= /usr/src/linux-headers-2.6.31-14-generic/PWD:= $(shell pwd)default:make -C $(KDIR) M=$(PWD) modulesclean:rm -rf *.ko *.mod.c *.mod.o *.o *.markers *.symvers *.order
装载
insmod jit.ko
测试
dd bs=20 count=5 < /proc/jitqueue
卸载
rmmod jit
- 【Linux设备驱动程序(第三版)】----延迟:超时(wait_event_interruptible_timeout)
- 【Linux设备驱动程序(第三版)】----延迟:超时(schedule_timeout)
- 【Linux设备驱动程序(第三版)】----延迟:让出处理器
- Linux设备驱动程序第三版学习(10)- 时间、延迟及延缓操作
- Linux设备驱动程序第三版学习(10)- 时间、延迟及延缓操作
- Linux设备驱动程序(第三版)学习
- 【Linux设备驱动程序(第三版)】----HelloWorld
- 【Linux设备驱动程序(第三版)】----Scull
- 【Linux设备驱动程序(第三版)】----ioctl
- 【Linux设备驱动程序(第三版)】----tasklet
- 【Linux设备驱动程序(第三版)】----高速缓存
- Linux设备驱动程序(第三版)
- 时间、延迟(Linux设备驱动程序)
- Linux设备驱动程序第三版学习(1)(2)-字符设备驱动程序源码分析
- Linux设备驱动程序第三版学习(1)-字符设备驱动程序源码分析
- Linux设备驱动程序第三版学习(2)-字符设备驱动程序源码分析(续)
- Linux设备驱动程序第三版学习(1)-字符设备驱动程序源码分析
- Linux设备驱动程序第三版学习(2)-字符设备驱动程序源码分析(续) .
- org.apache.commons.lang.time.DateUtils
- JAVA 线程 同步 信号量
- ASP.NET动态加载Js代码到Head标签中(三种方法)
- windows下Nginx和PHP的安装与配置
- C++基础之float与double
- 【Linux设备驱动程序(第三版)】----延迟:超时(wait_event_interruptible_timeout)
- 网页中播放FLV文件的代码
- SQL Server性能监控
- Google官方的ListView Tutorial
- QQ 木马程序开源(只针对2009版)
- Ubuntu 10.10从零开始建立android 2.2 froyo开发环境
- 读取excel 的数据
- DRA音频标准在CMMB中的应用
- XML语法