系统时钟小结 init/main.c start_kernel() arch/arm/kernel/setup.c :setup_arch() arch/arm/kernel/time.c time_init() 初始化system_timer 调用system timer的init函数指针 口·0112年元#至分QC 特香兰(xlanchen哪ustc:edu.cn)(计算inux捧作系统分折Chapter7 Linux的时4 January14,201512/43
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 系统时钟小结 init/main.c :: start_kernel() arch/arm/kernel/setup.c :: setup_arch() arch/arm/kernel/time.c :: time_init() 初始化system_timer 调用system_timer的init函数指针 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 7 Linux的时钟和定时测量 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) January 14, 2015 12 / 43
Outline Linux的计时体系结构 ARM中的系统时钟system timer ●arm的滴答机制 o Jiffies变量 o Linux的时钟源 o xtime变量 。时钟中断处理 。软定时器 8 延迟函数 相关API和命令 小结和作业 口9,4二营三)Q0 陈香兰(xlanchene哪ustc,edu.cn)(计算Linuxa捧作系统分折Chapter7 Linux的时4 January14,201513/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 13 / 43
arm的滴答产生机制 ●arm中,系统时钟的周期性时钟中断用来产生滴答, 其方法是在时钟中断处理函数中调用timer_tick函数 ●以s3c24 xx_timer.为例,时钟中断处理函数如下: arch/arm/plat-s3c24xx/time.c IRQ handler for the timer */ static irgreturn_t s3c2410_timer_interrupt(int irq,void *dev_id){ timer tick(); return IRQ_HANDLED; 。timer._tick调用Linux体系结构无关的do_timer() 练香兰(xlanchenoustc,edu,cn)(计算inux捧作系统分折Chapter7 Linux的时 January14,201514/43
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . arm的滴答产生机制 arm中,系统时钟的周期性时钟中断用来产生滴答, 其方法是在时钟中断处理函数中调用timer_tick函数 以s3c24xx_timer为例,时钟中断处理函数如下: . arch/arm/plat-s3c24xx/time.c . . /* * IRQ handler for the timer */ static irqreturn_t s3c2410_timer_interrupt(int irq, void *dev_id) { timer_tick(); return IRQ_HANDLED; } timer_tick调用Linux体系结构无关的do_timer() 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 7 Linux的时钟和定时测量 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) January 14, 2015 14 / 43
arm的滴答产生机制 #ifndef CONFIG GENERIC_CLOCKEVENTS / Kernel system timer support. / void timer tick(void){ profile tick(CPU PROFILING); do_leds(); do_set_rtc(): write_seqlock(&xtime_lock); do timer(1); write_sequnlock(&xtime lock): #ifndef CONFIG SMP update_process_times(user_mode(get_irq_regs())): #endif } #endif 4口·的,4,百,至分80 陈香兰(xlanchene哪ustc,edu,cn)(计算Linux捧作系统分折Chapter7 Linux的时4 January14,201514/43
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . arm的滴答产生机制 . . #ifndef CONFIG_GENERIC_CLOCKEVENTS /* * Kernel system timer support. */ void timer_tick(void) { profile_tick(CPU_PROFILING); do_leds(); do_set_rtc(); write_seqlock(&xtime_lock); do_timer(1); write_sequnlock(&xtime_lock); #ifndef CONFIG_SMP update_process_times(user_mode(get_irq_regs())); #endif } #endif 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 7 Linux的时钟和定时测量 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) January 14, 2015 14 / 43
Outline Linux的计时体系结构 ARM中的系统时钟system timer arm的滴答机制 ●Jiffies变量 o Linux的时钟源 o xtime变量 。时钟中断处理 。软定时器 8 延迟函数 相关API和命令 小结和作业 口·942万:至分Q0 陈香兰(xlanchene哪ustc,edu.cn)(计算Linuxa捧作系统分折Chapter7 Linux的时4 January14,2015I5/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 15 / 43