The time_init() Function

Time_init() is usually located in arch/<host>/kernel/time.c.

The time_init() function initializes the host's system tick timer hardware. It installs the timer's interrupt handler, and configures the timer to produce a periodic tick. The tick interrupt handler is usually called do_timer_interrupt().

A portion of the Hitachi SH version of time_init() is shown in Figure 7. The timer interrupt handler timer_interrupt() (which calls do_timer_interrupt()) is installed, then after determining the proper clock frequency (not shown), the code starts the chip's TMU0 periodic timer.

static struct irqaction irq0 = {timer_interrupt, SA_INTERRUPT, 0,
                                "timer", NULL, NULL};

void __init time_init(void)
{
   unsigned long interval;

   ...

   setup_irq(TIMER_IRQ, &irq0);

   ...

   interval = (module_clock/4 + HZ/2) / HZ;
   printk("Interval = %ld\n", interval);

   ...

   /* Start TMU0 */
   ctrl_outb(0, TMU_TSTR);
   ctrl_outb(TMU_TOCR_INIT, TMU_TOCR);
   ctrl_outw(TMU0_TCR_INIT, TMU0_TCR);
   ctrl_outl(interval, TMU0_TCOR);
   ctrl_outl(interval, TMU0_TCNT);
   ctrl_outb(TMU_TSTR_INIT, TMU_TSTR);
}

Figure 7. An excerpt from the Hitachi SH's time_init() function.