内核定时器:
2015-11-21 18:14
344 查看
内核定时器:
未来的某个时间点执行提前设置的某个任务函数。
涉及到的核心头文件:
#include <linux/timer.h>
涉及到的结构体:
struct timer_list {
/*
* All fields that change during normal runtime grouped to the
* same cacheline
*/
struct list_head entry;
unsigned long expires; //未来的定时时间点,参考时间是jiffies
struct tvec_base *base;
void (*function)(unsigned long); //定时到达时要执行的处理函数
unsigned long data; //定时处理函数需要的参数
int slack;
#ifdef CONFIG_TIMER_STATS
int start_pid;
void *start_site;
char start_comm[16];
#endif
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
};
使用步骤:
1. 实例化定时器对象
方法1,
struct timer_list timer;
init_timer(&timer);
timer.expires = jiffies + xxx;
timer.function = service_timer;
timer.data = (unsigned long)dev;
方法2,
struct timer_list timer;
setup_timer(&timer, service_timer, (unsigned long)dev);
timer.expires = jiffies + xxx;
方法3,
DEFINE_TIMER(timer, service_timer, jiffies + xxx, (unsigned long)dev);
2. 向内核注册定时器并启动
add_timer(&timer);
3. 如果需要(周期性的来定时)
mod_timer(&timer, jiffies + xx);
4. 在驱动模块的出口移除定时器
//在对称多处理器对应的系统中使用
del_timer_sync(&timer);
//单核使用
del_timer(&timer);
内核定时器:
未来的某个时间点执行提前设置的某个任务函数。
涉及到的核心头文件:
#include <linux/timer.h>
涉及到的结构体:
struct timer_list {
/*
* All fields that change during normal runtime grouped to the
* same cacheline
*/
struct list_head entry;
unsigned long expires; //未来的定时时间点,参考时间是jiffies
struct tvec_base *base;
void (*function)(unsigned long); //定时到达时要执行的处理函数
unsigned long data; //定时处理函数需要的参数
int slack;
#ifdef CONFIG_TIMER_STATS
int start_pid;
void *start_site;
char start_comm[16];
#endif
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
};
使用步骤:
1. 实例化定时器对象
方法1,
struct timer_list timer;
init_timer(&timer);
timer.expires = jiffies + xxx;
timer.function = service_timer;
timer.data = (unsigned long)dev;
方法2,
struct timer_list timer;
setup_timer(&timer, service_timer, (unsigned long)dev);
timer.expires = jiffies + xxx;
方法3,
DEFINE_TIMER(timer, service_timer, jiffies + xxx, (unsigned long)dev);
2. 向内核注册定时器并启动
add_timer(&timer);
3. 如果需要(周期性的来定时)
mod_timer(&timer, jiffies + xx);
4. 在驱动模块的出口移除定时器
//在对称多处理器对应的系统中使用
del_timer_sync(&timer);
//单核使用
del_timer(&timer);
相关文章推荐
- js table
- BigTale
- Windows Server 2008 R2入门之FTP服务器
- 此诊断出现在编译器生成的函数“CList<TYPE,ARG_TYPE> &CList<TYPE,ARG_TYPE>::operator =(const CList<TYPE,ARG_TYPE> &)”
- GFS Google File System(中文翻译)
- 单例对象
- C语言扫雷
- 二分查找
- HMC创建AIX
- Windows Server 2008 R2入门之文件服务器
- [笔记-架构探险]框架优化与功能扩展3.2.安全框架shiro、提供安全控制特性2-jsp页面标签和框架aop启用权限控制
- linux 命令 多一个窗口
- 并发和竞态
- UVA - 253 Cube painting(骰子涂色)
- MapReduce
- 利用linux 内核所提供的input子系统编写字符设备驱动的步骤
- 【Android】Android插件开发 —— 打开插件的Activity(预注册方式)
- AFN监测网络状态
- ls- 查看linux 文件的大小
- 驱动模型