linux系统tick维护,Linux系统节拍定时器(system tick timer)

内核版本2.6.30

CPU:S3C2440

本文主要说明节拍定时器是如何添加到内核中的,不对定时器实现进行说明。

ARM 平台的节拍定时器对象使用sys_timer来表示,该结构体位于arch/arm/include/asm/mach/time.h。

/*

* This is our kernel timer structure.

*

* - init

* Initialise the kernels jiffy timer source, claim interrupt

* using setup_irq. This is called early on during initialisation

* while interrupts are still disabled on the local CPU.

* - suspend

* Suspend the kernel jiffy timer source, if necessary. This

* is called with interrupts disabled, after all normal devices

* have been suspended. If no action is required, set this to

* NULL.

* - resume

* Resume the kernel jiffy timer source, if necessary. This

* is called with interrupts disabled before any normal devices

* are resumed. If no action is required, set this to NULL.

* - offset

* Return the timer offset in microseconds since the last timer

* interrupt. Note: this must take account of any unprocessed

* timer interrupt which may be pending.

*/

struct sys_timer {

struct sys_devicedev;

void(*init)(void);

void(*suspend)(void);

void(*resume)(void);

#ifndef CONFIG_GENERIC_TIME

unsigned long(*offset)(void);

#endif

};

S3C2440的sys_timer的定义在linux/arch/arm/plat-s3c24xx/time.c中,给出的三个方法也在该文件中定义。

struct sys_timer s3c24xx_timer = {

.init = s3c2410_timer_init,

.offset = s3c2410_gettimeoffset,

.resume = s3c2410_timer_setup

};

如何将该定时器告知内核呢?

在linux/arch/arm/mach-s3c2440/mach-smdk2440.c的最后使用了宏

MACHINE_START(S3C2440, "SMDK2440")

/* Maintainer: Ben Dooks */

.phys_io= S3C2410_PA_UART,

.io_pg_offst= (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,

.boot_params= S3C2410_SDRAM_PA + 0x100,

.init_irq= s3c24xx_init_irq,

.map_io= smdk2440_map_io,

.init_machine= smdk2440_machine_init,

.timer= &s3c24xx_timer,

MACHINE_END

该宏用于初始化结构体struct machine_desc,结构体成员如下:

struct machine_desc {

/*

* Note! The first four elements are used

* by assembler code in head.S, head-common.S

*/

unsigned intnr;/* architecture number*/

unsigned intphys_io;/* start of physical io*/

unsigned intio_pg_offst;/* byte offset for io

* page tabe entry*/

const char*name;/* architecture name*/

unsigned longboot_params;/* tagged list*/

unsigned intvideo_start;/* start of video RAM*/

unsigned intvideo_end;/* end of video RAM*/

unsigned intreserve_lp0 :1;/* never has lp0*/

unsigned intreserve_lp1 :1;/* never has lp1*/

unsigned intreserve_lp2 :1;/* never has lp2*/

unsigned intsoft_reboot :1;/* soft reboot*/

void(*fixup)(struct machine_desc *,

struct tag *, char **,

struct meminfo *);

void(*map_io)(void);/* IO mapping function*/

void(*init_irq)(void);

struct sys_timer*timer;/* system tick timer*/

void(*init_machine)(void);

};

在这里我们看到了timer指针。通过该宏将timer指针指向了s3c24xx_timer。

接着,再看linux/arch/arm/kernel/setup.c中的setup_arch函数,该函数中执行了下面这话:

system_timer = mdesc->timer;

mdesc->timer即为上面宏所给出的s3c24xx_timer,而system_timer为全局变量。通过该全局变量就可使用节拍定时器。

最后,我们看下节拍定时器的init方法何时被调用,调用顺序如下:

start_kernel ()-->  time_init()  --> system_timer->init()

time_init  -函数位于linux/arch/arm/kernel/time.c。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值