linux时间管理 之 内核定时器
2012-09-28 15:26
288 查看
1、内核定时器的定义
struct timer_list {
/*
* All fields that change during normal runtime grouped to the
* same cacheline
*/
struct list_head entry;
unsigned long expires;
struct tvec_base *base;
void (*function)(unsigned long);
unsigned long data;
int slack;
#ifdef CONFIG_TIMER_STATS
void *start_site;
char start_comm[16];
int start_pid;
#endif
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
};
unsigned long expires :指定定时器的到期时间,用jiffies表示。
void (*function)(unsigned long):定时器到期后调用的定时器函数。
unsigned long data:定时器对象中携带的数据。通常当成实际参数传递给定时器函数function。
2、init_timer
初始化定时器结构题timer_list中与内核相关的部分。不包括expires,function,data。
3、add_timer
将定时器对象加入到系统中,这样在定时器到期后,定时器函数被调用。
系统通过一个PER_CPU型的数据结构来管理驱动程序中向系统提交的定时器。
struct tvec_base {
spinlock_t lock;
struct timer_list *running_timer;
unsigned long timer_jiffies;
unsigned long next_timer;
struct tvec_root tv1;
struct tvec tv2;
struct tvec tv3;
struct tvec tv4;
struct tvec tv5;
} ____cacheline_aligned;
tv1,tv2,tv3,tv4,tv5是数组,每个数组中代表一个到时的jiffies值。
每次时钟中断的中断处理例程的下半部,TIMER_SOFTIRQ,都会扫描tvec_base,如果定时器到期,则调用其定时器函数。
4、del_timer del_timer_sync
用来删除定时器
区别:在但处理器系统上二者等同。
在多处理器系统中,del_timer_sync除了像del_timer一样将定时器从系统中删除外,可以保证在函数返回的时候,没有任何处理器正在执行该定时器函数。
struct timer_list {
/*
* All fields that change during normal runtime grouped to the
* same cacheline
*/
struct list_head entry;
unsigned long expires;
struct tvec_base *base;
void (*function)(unsigned long);
unsigned long data;
int slack;
#ifdef CONFIG_TIMER_STATS
void *start_site;
char start_comm[16];
int start_pid;
#endif
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
};
unsigned long expires :指定定时器的到期时间,用jiffies表示。
void (*function)(unsigned long):定时器到期后调用的定时器函数。
unsigned long data:定时器对象中携带的数据。通常当成实际参数传递给定时器函数function。
2、init_timer
初始化定时器结构题timer_list中与内核相关的部分。不包括expires,function,data。
3、add_timer
将定时器对象加入到系统中,这样在定时器到期后,定时器函数被调用。
系统通过一个PER_CPU型的数据结构来管理驱动程序中向系统提交的定时器。
struct tvec_base {
spinlock_t lock;
struct timer_list *running_timer;
unsigned long timer_jiffies;
unsigned long next_timer;
struct tvec_root tv1;
struct tvec tv2;
struct tvec tv3;
struct tvec tv4;
struct tvec tv5;
} ____cacheline_aligned;
tv1,tv2,tv3,tv4,tv5是数组,每个数组中代表一个到时的jiffies值。
每次时钟中断的中断处理例程的下半部,TIMER_SOFTIRQ,都会扫描tvec_base,如果定时器到期,则调用其定时器函数。
4、del_timer del_timer_sync
用来删除定时器
区别:在但处理器系统上二者等同。
在多处理器系统中,del_timer_sync除了像del_timer一样将定时器从系统中删除外,可以保证在函数返回的时候,没有任何处理器正在执行该定时器函数。
相关文章推荐
- LINUX内核设计思想之定时器和时间管理
- linux 内核学习之—定时器和时间管理
- 读薄《Linux 内核设计与实现》(5) - 定时器、时间管理和内存管理
- Linux内核学习笔记八——定时器和时间管理
- linux 定时器和时间管理 自学笔记
- 内核定时器和时间管理学习笔记
- 【Linux开发】linux设备驱动归纳总结(七):1.时间管理与内核延时
- linux驱动之定时器的介绍和内核时间的学习
- Linux内核架构 Linux设备驱动 Linux电源管理 Linux音频子系统 Linux中断子系统 Linux时间管理系统 Linux输入子系统
- Linux Kernel Development——定时器和时间管理
- Linux之定时器与时间管理
- 解析Linux内核的基本的模块管理与时间管理操作
- 读深入理解Linux内核 (第6章 时间管理)
- Linux基础系列-定时器与时间管理
- linux的时间管理(与驱动程序相关,非应用程序使用)内核和普通系统函数和使用c语言库的区别
- Linux之定时器与时间管理 【转】
- linux ------ 时间管理、内存使用及内核与用户间的数据传递
- linux 内核笔记之时间管理(三) : 高精度timer
- 【转】linux内核时钟处理机制-定时器管理接口数据结构
- linux内核分析笔记----定时器和时间管理