Programmable interrupt timer (PIT)

There are certain tasks that need to be carried out by the kernel at regular intervals, such as:

  • Updating the current time and date (at midnight)
  • Updating the system running time (uptime)
  • Keeping track of the time consumed by each process so that they don't exceed the time allotted to run on the CPU
  • Keeping track of various timer activities

In order to carry out these tasks, interrupts must be periodically raised. Every time this periodic interrupt is raised, the kernel knows it's time to update the aforementioned timing data. The PIT is the piece of hardware responsible for issuing this periodic interrupt, called timer interrupt. The PIT keeps on issuing timer interrupts on IRQ0 periodically at approximately 1000 Hz frequency, once every millisecond. This periodic interrupt is called the tick and the frequency at which it's issued is called the tick rate. The tick rate frequency is defined by the kernel macro HZ and is measured in hertz.

System responsiveness depends on the tick rate: the shorter the ticks, the more responsive a system would be, and vice versa. With shorter ticks, poll() and select() system calls will have a faster response time. However, the considerable drawback of a shorter tick rate is that the CPU will be working in kernel mode (executing the interrupt handler for the timer interrupt) most of the time, leaving less time for user-mode code (programs) to execute on it. In a high-performance CPU, it wouldn't be much of an overhead, but in slower CPUs, the overall system performance would be affected considerably.

To reach a balance between response time and system performance, a tick rate of 100 Hz is used in most machines. Except for Alpha and m68knommu, which use a 1000 Hz tick rate, the rest of the common architectures, including x86 (arm, powerpc, sparc, mips, and so on) use a 100 Hz tick rate. Common PIT hardware found in x86 machines is Intel 8253. It's I/O mapped and accessed through addresses 0x40 – 0x43. The PIT is initialized by setup_pit_timer(), defined in the arch/x86/kernel/i8253.c file:

void __init setup_pit_timer(void)
{
        clockevent_i8253_init(true);
        global_clock_event = &i8253_clockevent;
}

This calls clockevent_i8253_init() internally, defined in <drivers/clocksource/i8253.c>:

void __init clockevent_i8253_init(bool oneshot)
{
        if (oneshot)
                i8253_clockevent.features |= CLOCK_EVT_FEAT_ONESHOT;
        /*
        * Start pit with the boot cpu mask. x86 might make it global
        * when it is used as broadcast device later.
        */
        i8253_clockevent.cpumask = cpumask_of(smp_processor_id());

        clockevents_config_and_register(&i8253_clockevent, PIT_TICK_RATE,
                                        0xF, 0x7FFF);
}
#endif
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.40.177