jiffies HZ 秒的区别与联系

来源:互联网 发布:anything搜索软件 编辑:程序博客网 时间:2024/04/27 23:30

HZ:1秒钟内,时钟中断的次数,即1秒钟内,系统时钟的节拍次数。

jiffies:全局变量,用来记录系统自启动以来产生的节拍总数

系统运行时间(以秒为单位):system_time=(jiffies)/HZ。

eg:jiffies定时器,HZ=1000,精度只能达到1ms。,HZ=100,精度只能达到10ms,
        jiffies+msecs_to_jiffies(xx ms);可做到ms级,

#include <linux/jiffies.h>//jiffies头文件


#include <linux/timer.h>  //timer_list结构体



static struct timer_list  ms_timer;

static void ms_timer_handler(void)
{
    printk("TIMER DEBUG:%s\n",__func__);

   // ms_timer.expires=jiffies+HZ/100;
    ms_timer.expires=jiffies+msecs_to_jiffies(10);


    ms_timer.function=&ms_timer_handler;


    add_timer(&ms_timer);//增加注册定时器,使定时器生效
}

0 0
原创粉丝点击