6.2.2 wall time
Wall time: during system startup, the RTC chip stores data for initialization, maintains the data by the system clock during system operation, and synchronizes the data with the RTC chip at the appropriate time. The wall time is stored in the system's core variable xtime, which records the time in the real world's year, month, and day format, so that the kernel can mark some objects and events in time, for example, the file creation time, modification time, and last access time are recorded, or used by user processes through system calls.
In the kernel, the struct timespec type variable xtime is used to record the wall time. The 564th-line declaration of this variable in the src/kernel/time. c file is as follows:
struct timespec xtime __attribute__ ((aligned (16))); |
The data structure struct timespec is defined in row 12th of the src/include/Linux/time. h file. The Code is as follows:
struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; |
This structure is used to indicate the relative time between the current time and the Unix time reference 1970/01/01/00. The member variable TV _sec is used to record the seconds from the standard time 1970/01/01/00 :00:00, and the member variable TV _nsec is used to record the microsecond value in less than one second. The value range is 0 ~ 999 999.
The initial value of the variable xtime is set by the time_init () function during system initialization. This function assigns an initial value to the variable xtime by reading the value of the RTC of the System Real-Time chip; during system operation, the system clock interruption handler is responsible for updating the value of this variable during each clock interruption. The initialization statement for this variable is as follows. For more information about initialization, see section 6.3. For more information about how to update the value, see Section 6.4.2.
xtime.tv_sec = get_cmos_time(); xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ); |