【Linux设备驱动程序(第三版)】----获取当前时间
来源:互联网 发布:郝斌c语言自学教程视频 编辑:程序博客网 时间:2024/06/06 12:43
【Linux设备驱动程序(第三版)】----获取当前时间
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 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){printk(KERN_DEBUG "jit_init......");create_proc_read_entry("jit_currentime", 0, NULL, jit_currentime, NULL);return 0;}void __exit jit_exit(void){remove_proc_entry("jit_currentime", 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
测试
cat /proc/jit_currentime
输出结果:
0x000d52fd 0x00000001000d52fd 1310097626.455468 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455470 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455472 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455474 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455476 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455478 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455481 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455483 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455485 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455487 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455489 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455491 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455493 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455495 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455497 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455499 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455502 1310097626.4545165480x000d52fd 0x00000001000d52fd 1310097626.455504 1310097626.454516548
卸载
rmmod jit
- 【Linux设备驱动程序(第三版)】----获取当前时间
- Linux设备驱动程序(第三版)学习
- 【Linux设备驱动程序(第三版)】----HelloWorld
- 【Linux设备驱动程序(第三版)】----Scull
- 【Linux设备驱动程序(第三版)】----ioctl
- 【Linux设备驱动程序(第三版)】----tasklet
- 【Linux设备驱动程序(第三版)】----高速缓存
- Linux设备驱动程序(第三版)
- 《linux设备驱动程序》第三版
- Linux 设备驱动程序 第三版
- Linux设备驱动程序第三版学习(10)- 时间、延迟及延缓操作
- Linux设备驱动程序第三版学习(10)- 时间、延迟及延缓操作
- Linux设备驱动程序第三版之块设备驱动程序
- Linux设备驱动程序第三版学习(1)(2)-字符设备驱动程序源码分析
- Linux设备驱动程序第三版学习(1)-字符设备驱动程序源码分析
- Linux设备驱动程序第三版学习(2)-字符设备驱动程序源码分析(续)
- Linux设备驱动程序第三版学习(1)-字符设备驱动程序源码分析
- Linux设备驱动程序第三版学习(2)-字符设备驱动程序源码分析(续) .
- Hibernate 查询语句HQL基本语法
- Convention Plugin
- linux 下apche无法监听端口解决办法(Permission denied: make_sock: could not bind to address)
- Flex & Android开发环境搭建
- Linux下svn的常用工作流程
- 【Linux设备驱动程序(第三版)】----获取当前时间
- Features
- SWF文件格式
- Select模型原理
- Jdom学习笔记
- 数据结构-迪克特斯拉算法(最短路径)
- [SQL Server]在32位操作系统上,使用AWE访问4GB以上的内存。
- 数据结构-排序算法
- js调用java后台方法(ajax回调函数)