5.4. The TIMER_BH Bottom Half Functions

The timer_bh( ) function associated with the TIMER_BH bottom half invokes the update_times( ), run_old_timers( ), and run_timer_list( ) auxiliary functions, which are described next.

5.4.1. Updating the Time and Date

The xtime variable of type struct timeval is where user programs get the current time and date. The kernel also occasionally refers to it, for instance, when updating inode timestamps (see Section 1.5.4 in Chapter 1). In particular, xtime.tv_sec stores the number of seconds that have elapsed since midnight of January 1, 1970[4], while xtime.tv_usec stores the number of microseconds that have elapsed within the last second (its value thus ranges between and 999999).

[4] This date is traditionally used by all Unix systems as the earliest moment in counting time.

During system initialization, the time_init( ) function is invoked to set up the time and date: it reads them from the Real Time Clock by invoking the get_cmos_time( ) function, then it initializes xtime. Once this has been done, the kernel does not need the RTC anymore: it relies instead on the TIMER_BH bottom half, which is activated once every tick.

The update_times( ) function invoked by the TIMER_BH bottom half updates xtime by disabling interrupts and executing the following statement:

if (lost_ticks) 
    update_wall_time(lost_ticks);

The update_wall_time( ) function invokes the update_wall_time_one_tick( ) function lost_ticks consecutive times; each invocation adds ...

Get Understanding the Linux Kernel now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.