Outline Linux的计时体系结构 ●ARM中的系统时钟system timer arm的滴答机制 o Jiffies变量 o Linux的时钟源 o xtime变量 。时钟中断处理 。软定时器 8 延迟函数 相关API和命令 小结和作业 口·942#万:至分Q0 陈香兰(xlanchene哪ustc,edu.cn)(计算Linux捧作系统分折Chapter7 Linux的时4 January14,2015 7/43
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Outline . 1. Linux的计时体系结构 ARM中的系统时钟system_timer arm的滴答机制 Jiffies变量 Linux的时钟源 xtime变量 时钟中断处理 软定时器 2. 延迟函数 3. 相关API和命令 4. 小结和作业 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 7 Linux的时钟和定时测量 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) January 14, 2015 7 / 43
ARM中的系统时钟system timer ●ARWM的系统时钟:全局量system_timer 。是一个struct sys_timer*指针 o在文件arch/arm/kernel/time.c中定义 。在Linux初始化过程中得到初始化 start_kernel()→ setup_arch()@arch/arm/kernel/setup.c: system timer mdesc->timer; 口494二,意至)Q0 陈香兰(xlanchene哪ustc,edu,cn)(计算Linux捧作系统分折Chapter7 Linux的时4 January 14,2015 8/43
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ARM中的系统时钟system_timer ARM的系统时钟:全局量system_timer 是一个struct sys_timer*指针 在文件arch/arm/kernel/time.c中定义 在Linux初始化过程中得到初始化 . start_kernel()→ setup_arch()@arch/arm/kernel/setup.c: . . ... system_timer = mdesc->timer; ... 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 7 Linux的时钟和定时测量 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) January 14, 2015 8 / 43
数据结构struct sys timer 。提供了与具体时钟中断源的接口 。注册方法:machine desc.timer include/asm-arm/mach/time.h / This is our kernel timer structure. struct sys timer struct sys_device dev; void (*init)(void); void (*suspend)(void); void (*resume)(void); #ifndef CONFIG GENERIC_TIME unsigned long (*offset)(void); #endif #ifdef CONFIG_NO_IDLE_HZ struct dyn_tick_timer *dyn_tick; #endif 陈香兰(xlanchene哪ustc.cdu,cn) (计算Linux捧作系统分折Chapter7 Linux的时 January 14,2015 9/43
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 数据结构struct sys_timer 提供了与具体时钟中断源的接口 注册方法:machine_desc.timer . include/asm-arm/mach/time.h . . /* * This is our kernel timer structure. * ... */ struct sys_timer { struct sys_device dev; void (*init)(void); void (*suspend)(void); void (*resume)(void); #ifndef CONFIG_GENERIC_TIME unsigned long (*offset)(void); #endif #ifdef CONFIG_NO_IDLE_HZ struct dyn_tick_timer *dyn_tick; #endif }; 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 7 Linux的时钟和定时测量 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) January 14, 2015 9 / 43
以s3c2410为例 struct sys_timer s3c24xx_timer = .init s3c2410 timer init, offset s3c2410_gettimeoffset, resume s3c2410_timer_setup 。请搜索一下s3c24 xx_timer的使用情况(即注册情况) 口·01421万至分QC 练香兰(xlanchen哪ustc,edu.cn)(计算inux操作系航分折Chapter7 Linux的时4 January14,201510/43
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 以s3c2410为例 . . struct sys_timer s3c24xx_timer = { .init = s3c2410_timer_init, .offset = s3c2410_gettimeoffset, .resume = s3c2410_timer_setup }; 请搜索一下s3c24xx_timer的使用情况(即注册情况) 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 7 Linux的时钟和定时测量 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) January 14, 2015 10 / 43
sys timer的init接口的调用 e在arch/arm/kerne1/time.c的time_init中 start kernel()-time init(): system_timer->init(); 在sys_timer的init接口函数中, 以s3c2410_timer._init为例: static void init s3c2410 timer init (void){ s3c2410timer setup(): setup_irq(IRQ_TIMER4,&s3c2410_timer_irq): 初始化时钟,并将中断处理函数s3c2410_timer._irq 关联到中断号IRQ TIMER4上 至)00 陈香兰(xlancheneustc.ed,cn) (计算Linux捧作系统分折Chapter 7 Linux的时 January14.201511/43
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sys_timer的init接口的调用 在arch/arm/kernel/time.c的time_init中 . start_kernel()→time_init(): . . ... system_timer->init(); ... 在sys_timer的init接口函数中, 以s3c2410_timer_init为例: . . static void __init s3c2410_timer_init (void) { s3c2410_timer_setup(); setup_irq(IRQ_TIMER4, &s3c2410_timer_irq); } 初始化时钟,并将中断处理函数s3c2410_timer_irq 关联到中断号IRQ_TIMER4上 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 7 Linux的时钟和定时测量 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) January 14, 2015 11 / 43