我是靠谱客的博主 超帅书本,最近开发中收集的这篇文章主要介绍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。

最后

以上就是超帅书本为你收集整理的linux系统tick维护,Linux系统节拍定时器(system tick timer)的全部内容,希望文章能够帮你解决linux系统tick维护,Linux系统节拍定时器(system tick timer)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部