Chinaunix首页 | 论坛 | 博客

分类: LINUX

2011-10-08 16:36:15

   User programs get the current time and date from the xtime variable. The kernel must periodically update this variable, so that its value is always reasonably accurate.
   用户程序得到当前时间和日期通过xtime变量。kernel 一定定时的更新这个变量,这个值所以一直理论上是正确的。
  The update_times( ) function, which is invoked by the global timer interrupt handler, updates the value of the xtime variable as follows:
  update_times()函数,被一个全局的计时器中断调用,来以如下步骤来更新xtime 的值。
 
    void update_times(void)
    {
        unsigned long ticks;   /*unsigned long 类型*/
        ticks = jiffies - wall_jiffies;   /*当前的jiffies个数减去上一次记录的jiffies值*/
        if (ticks) {
            wall_jiffies += ticks;  
            update_wall_time(ticks); 
        }
        calc_load(ticks);
    }
We recall from the previous description of the timer interrupt handler that when the code of this function is executed, the xtime_lock seqlock has already been acquired for writing.
 我们回顾当这个函数的代码被执行时对前面的那个计时器中断服务程序的描述,这个xtime_lock已经被要求写了。
  The wall_jiffies variable stores the time of the last update of the xtime variable. Observe that the value of wall_jiffies can be smaller than jiffies-1, since a few timer interrupts can be lost, for instance when interrupts remain disabled for a long period of time; in other words, the kernel does not necessarily update the xtime variable at every tick. However, no tick is definitively lost, and in the long run, xtime stores the correct system time. The check for lost timer interrupts is done in the mark_offset method of cur_timer; see the earlier section "Timekeeping Architecture in Uniprocessor Systems."
   这个wall_jiffies 变量存储着上一次更新的xtime变量。观察到wall_jiffies可以比jiffies-1更小,因为一些时钟中断可能被丢失。例如,中断在一段时间内被保持禁用。换句话说,kernel没有必要每个滴答都更新xtime变量。但是,没有滴答明确会丢失,从长远来看,xtime变量存储这正确的系统时间。这个检查丢失的时钟中断在cur_timer的mark_offset()被完成的;见前面的“计时架构在单处理器系统就是前面的wall_to_monotonic变量"。
  The update_wall_time( ) function invokes the update_wall_time_one_tick( ) function ticks consecutive times; normally, each invocation adds 1,000,000 to the xtime.tv_nsec field. If the value of xtime.tv_nsec becomes greater than 999,999,999, the update_wall_time( ) function also updates the tv_sec field of xtime. If an adjtimex( ) system call has been issued, for reasons explained in the section "The adjtimex( ) System Call" later in this chapter, the function might tune the value 1,000,000 slightly so the clock speeds up or slows down a little.
  这个update_wall_time()函数调用update_wall_one_tick()函数滴答连续的次数;通常,每一个调用增加1,000,000到xtime_tv_nsec域。如果time.tv_nsec的值变的鳎鱼999,999,999,这个update_wall_time()函数也会更新xtime 的tv_sec域。如果一个adjtimex()系统调用被发出,在“The adjtimex()系统调用”解释,这个函数可能会稍微调1,000,000的值,所以时钟会加速或者减速一点。
  The calc_load( ) function is described in the section "Keeping Track of System Load" later in this chapter.
  这个calc_load()函数在后面章中“跟踪系统装载”一节描述。

阅读(1455) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~