Hardware clock and system clock in Linux
There are two kinds of clocks, such as hardware clock and system clock, in Linux. The hardware clock is the clock device on the motherboard, which is usually the clock that can be set on the BIOS screen. The system clock refers to the clock in the kernel. When Linux starts, the system clock reads the settings of the hardware clock, and then the system clock runs independently. All Linux-related instructions and functions are programmed to read the system clock.
The setting of the system clock is our usual date command, and the RTC driver we write is for the hardware clock, it has its own command hwclock, so using the date command is not possible to call to our driver (at this point it began to depressed me, after writing the driver, Silly to test with the date command, and of course the result is nothing), we can update the RTC clock with some instructions from hwclock-that is, the interaction between the system clock and the hardware clock.
HWCLOCK–R display hardware clock and date
The hwclock–s adjusts the system clock to match the current hardware clock.
The hwclock–w adjusts the hardware clock to coincide with the current system clock.
The Linux system has two clocks: one is a motherboard battery-powered "Real time Clock" called RTC or a CMOS clock,
Hardware clock. When the operating system shuts down, use this to record the time, but for the running system is not the time.
The other time is "System clock" also called the kernel clock or software clock, is the software according to time interrupt to count,
The kernel clock does not exist in the case of system shutdown, so when the operating system starts, the kernel clock is to read the RTC time
To make time synchronization. And when the system shuts down, the system time is written back to the RTC for synchronization.
As mentioned earlier, there are only two times when the Linux kernel is interoperable with RTC:
1) The kernel reads the start time and date from RTC at startup;
2) The kernel writes the time and date back to the RTC when needed.
When the system starts, the kernel initializes the kernel clock by reading the RTC, also called the wall time, which is placed in the Xtime variable
Linux Time Module II