ware Clock; compensate for Hardware Clock drift; correct the System Clock timescale; set the kernel’s timezone, NTP timescale, and epoch (Alpha only); and predict future Hardware Clock values based on its drift rate.
counter in the Hardware Clock to contain the number of full years since 1952, then the kernel’s Hardware Clock epoch value must be 1952.
Clock wakeup (aka alarm). See rtcwake(8).
ating system’s hwclock command, such as ’11 minute mode’ or from dual-booting another OS.
read from it must be shifted to the UTC timescale before using it to set the System Clock. The –hctosys function does this based upon the information in the /etc/adjtime file or the command line arguments
–localtime and –utc. Note: no daylight saving adjustment is made. See the discussion below, under LOCAL vs UTC.
tzset(3) would interpret them. The obsolete tz_dsttime field of the kernel’s timezone value is set to zero. (For details on what this field used to mean, see settimeofday(2).)
Hardware Clock’s timescale configuration is changed then a reboot is required to inform the kernel. See the discussion below, under Automatic Hardware Clock Synchronization by the Kernel.
’11 minute mode’, then –hctosys will set the time incorrectly by including drift compensation.
Another way to inhibit this is by using the –noadjfile option when calling the –hctosys function. A third method is to delete the /etc/adjtime file. Hwclock will then default to using the UTC timescale for the
Hardware Clock. If the Hardware Clock is ticking local time it will need to be defined in the file. This can be done by calling hwclock –localtime –adjust; when the file is not present this command will not actu‐
ally adjust the Clock, but it will create the file with local time configured, and a drift factor of zero.
then when this instance is started again the drift correction applied will be incorrect.
with kernels above version 2.6 where you know the System Clock has been set from the Hardware Clock by the kernel during boot.
then a reboot would be required to inform the kernel.
time like “+5 minutes”, because hwclock’s precision depends upon correlation between the argument’s value and when the enter key is pressed. Fractional seconds are silently dropped. This option is capable of under‐
standing many time and date formats, but the previous parameters should be observed.
Without this option, hwclock will use the rtc device file, which it assumes to be driven by the Linux RTC device driver. As of v2.26 it will no longer automatically use directisa when the rtc driver is unavailable;
this was causing an unsafe condition that could allow two processes to access the Hardware Clock at the same time. Direct hardware access from userspace should only be used for testing, troubleshooting, and as a last
resort when all other methods fail. See the –rtc option.
hwclock command. If you specify the wrong one (or specify neither and take a wrong default), both setting and reading the Hardware Clock will be incorrect.
mal drift factor is crafted it should not need to be changed. Therefore, the old behavior to automatically (re)calculate drift was changed and now requires this option to be used. See the discussion below, under The
power failure. In that case, the clock must first be set without this option. Despite it not working, the resulting drift correction factor would be invalid anyway.
Clocks in a Linux System
clock actually has virtually infinite precision.
as the persistent clock.
more functional integrated real-time clock which is used for most other purposes.
The System Time is the number of seconds since 00:00:00 January 1, 1970 UTC (or more succinctly, the number of seconds since 1969 UTC). The System Time is not an integer, though. It has virtually infinite precision.
designed, the Hardware Clock is the only real time clock.
while the system is running, and the next time Linux starts up, it will do so with the adjusted time from the Hardware Clock. Note: currently this is not possible on most systems because hwclock –systohc is called at shut‐
local time for you) almost always use a more traditional method of determining the timezone: They use the TZ environment variable or the /etc/localtime file, as explained in the man page for tzset(3). However, some programs
and fringe parts of the Linux kernel such as filesystems use the kernel’s timezone value. An example is the vfat filesystem. If the kernel timezone value is wrong, the vfat filesystem will report and set the wrong time‐
stamps on files. Another example is the kernel’s NTP ’11 minute mode’. If the kernel’s timezone value and/or the persistent_clock_is_local variable are wrong, then the Hardware Clock will be set incorrectly by
’11 minute mode’. See the discussion below, under Automatic Hardware Clock Synchronization by the Kernel.
Savings Time (DST) convention that is in effect in the locality at the present time. This second field is not used under Linux and is always zero. See also settimeofday(2).
Hardware Clock Access Methods
rtc framework with udev, are capable of supporting multiple Hardware Clocks. This may bring about the need to override the default rtc device by specifying one with the –rtc option.
if running with superuser effective userid. This method may be used by specifying the –directisa option.
because it may be the only method available on ISA systems which do not have a working rtc device driver.
The Adjust Function
tion lets you apply systematic drift corrections to the Hardware Clock.
was calibrated. Five days later, the clock has gained 10 seconds, so you issue a hwclock –set –update-drift command to set it back 10 seconds. hwclock updates the adjtime file to show the current time as the last time
the clock was calibrated, and records 2 seconds per day as the systematic drift rate. 24 hours go by, and then you issue a hwclock –adjust command. hwclock consults the adjtime file and sees that the clock gains 2 seconds
per day when left alone and that it has been left alone for exactly one day. So it subtracts 2 seconds from the Hardware Clock. It then records the current time as the last time the clock was adjusted. Another 24 hours go
by and you issue another hwclock –adjust. hwclock does the same thing: subtracts 2 seconds and updates the adjtime file with the current time as the last time the clock was adjusted.
24 hour drift rate based on the last calibrated timestamp from the adjtime file. This updated drift factor is then saved in /etc/adjtime.
more than 1 second and –adjust will make the adjustment including any fractional amount.
second drift values immediately. It does not change the Hardware Clock time nor the adjtime file. This may eliminate the need to use –adjust, unless something else on the system needs the Hardware Clock to be compensated.
The Adjtime File
ger; 3) zero (for compatibility with clock(8)) as a decimal integer.
ware Clock has been found, since that calibration, not to contain a valid time). This is a decimal integer.
Automatic Hardware Clock Synchronization by the Kernel
time option, so not all kernels will have this capability. This is a good mode to use when you are using something sophisticated like NTP to keep your System Clock synchronized. (NTP is a way to keep your System Time syn‐
chronized either to a time server somewhere on the network or to a radio clock hooked up to your system. See RFC 1305.)
time_status variable is unset. This value is output as the ‘status’ line of the adjtimex –print or ntptime commands.
tem Clock the old fashioned way, including hwclock –hctosys. However, if the NTP daemon is still running, it will turn ’11 minute mode’ back on again the next time it synchronizes the System Clock.
what timescale the Hardware Clock is using, it may clobber it with the wrong one. The kernel uses UTC by default.
will set this variable according to the adjtime file or the appropriate command-line argument. Note that when using this capability and the Hardware Clock timescale configuration is changed, then a reboot is required to
notify the kernel.
ISA Hardware Clock Century value
way, and it really isn’t necessary anyway, since the year-of-century does a good job of implying which century it is.
Keeping Time without External Synchronization
adjtimex –tick value –frequency value
- Systems without adjtimex may use ntptime.
rates. The methods and software for drift correction are different for each of them. However, most systems are configured to exchange values between these two clocks at startup and shutdown. Now the individual device’s
time keeping errors are transferred back and forth between each other. Attempt to configure drift correction for only one of them, and the other’s drift will be overlaid upon it.
upon the System Clock’s rate being correct, means that configuration of the System Clock should be done first.
an adjtimex package, ntptime -f ppm may be used instead.)
ing to catch its own tail. Success may happen eventually, but great effort and frustration will likely precede it. This automation may yield an improvement over no configuration, but expecting optimum results would be in
error. A better choice for manual configuration would be adjtimex’s –log options.
occasion that the machine is shut down for an extended period, then cold drift should yield better results.
the Hardware Clock is corrected properly at startup. To check this, first make sure that the System Time is correct before shutdown and then use sntp, or date -Ins and a precision timepiece, immediately after startup.
LOCAL vs UTC
time and makes no adjustments to the time read from it.
ment to the –date option.
supposed to be working properly so that its Hardware Clock can be kept in UTC.
POSIX vs ‘RIGHT’
base, sometimes called tz or zoneinfo.
seconds), which is equivalent to (TAI – 10). This allows calculating the exact number of seconds between two dates that cross a leap second epoch. The System Clock is then converted to the correct civil time, including UTC,
by using the ‘right’ timezone files which subtract the leap seconds. Note: this configuration is considered experimental and is known to have issues.
TZ=’right/Europe/Dublin’. This habit was becoming so common that the upstream zoneinfo project restructured the system’s file tree by moving the posix and ‘right’ subdirectories out of the zoneinfo directory and into sib‐
zone to be configured to include leap seconds while the zoneinfo database is still configured to exclude them. Then when an application such as a World Clock needs the South_Pole timezone file; or an email MTA, or hwclock
needs the UTC timezone file; they fetch it from the root of /usr/share/zoneinfo , because that is what they are supposed to do. Those files exclude leap seconds, but the System Clock now includes them, causing an incorrect
as described above, or by assigning a database path to the TZDIR environment variable.
firstname.lastname@example.org), based on work done on the clock(8) program by Charles Hedrick, Rob Hooft, and Harald Koenig. See the source code for complete history and credits.
- man 8 hwclock, Version hwclock from util-linux 2.32
- 07/15/2018 创建文章