]> git.ipfire.org Git - thirdparty/util-linux.git/blob - hwclock/hwclock.8
man pages: add "AVAILABILITY" section
[thirdparty/util-linux.git] / hwclock / hwclock.8
1 .TH HWCLOCK 8 "02 March 1998"
2 .SH NAME
3 hwclock \- query and set the hardware clock (RTC)
4 .SH SYNOPSIS
5 .BR "hwclock \-r" " or " "hwclock \-\-show"
6 .br
7 .BR "hwclock \-w" " or " "hwclock \-\-systohc"
8 .br
9 .BR "hwclock \-s" " or " "hwclock \-\-hctosys"
10 .br
11 .BR "hwclock \-a" " or " "hwclock \-\-adjust"
12 .br
13 .BR "hwclock \-v" " or " "hwclock \-\-version"
14 .br
15 .B "hwclock \-\-set \-\-date=newdate"
16 .br
17 .B "hwclock \-\-getepoch"
18 .br
19 .B "hwclock \-\-setepoch \-\-epoch=year"
20 .PP
21 other options:
22 .PP
23 .B "[\-u|\-\-utc] \-\-localtime \-\-noadjfile \-\-directisa"
24 .B "\-\-test [\-D|\-\-debug]"
25 .B "\-\-rtc=filename"
26 .PP
27 and arcane options for DEC Alpha:
28 .PP
29 .B "[\-A|\-\-arc] [\-J|\-\-jensen] [\-S|\-\-srm] [\-F|\-\-funky-toy]"
30 .PP
31 Minimum unique abbreviations of all options are acceptable.
32 .PP
33 Also, \-h asks for a help message.
34
35 .SH DESCRIPTION
36 .B hwclock
37 is a tool for accessing the Hardware Clock. You can display the
38 current time, set the Hardware Clock to a specified time, set the
39 Hardware Clock to the System Time, and set the System Time from the
40 Hardware Clock.
41 .PP
42 You can also run
43 .B hwclock
44 periodically to insert or remove time from the Hardware Clock to
45 compensate for systematic drift (where the clock consistently gains or
46 loses time at a certain rate if left to run).
47
48 .SH OPTIONS
49 You need exactly one of the following options to tell
50 .B hwclock
51 what function to perform:
52 .PP
53 .TP
54 .B \-\-show
55 Read the Hardware Clock and print the time on Standard Output.
56 The time shown is always in local time, even if you keep your Hardware Clock
57 in Coordinated Universal Time. See the
58 .B \-\-utc
59 option.
60
61 .TP
62 .B \-\-set
63 Set the Hardware Clock to the time given by the
64 .B \-\-date
65 option.
66 .TP
67 .B \-\-hctosys
68 Set the System Time from the Hardware Clock.
69
70 Also set the kernel's timezone value to the local timezone
71 as indicated by the TZ environment variable and/or
72 .IR /usr/share/zoneinfo ,
73 as
74 .BR tzset (3)
75 would interpret them.
76 The obsolete tz_dsttime field of the kernel's timezone value is set
77 to DST_NONE. (For details on what this field used to mean, see
78 .BR settimeofday (2).)
79
80 This is a good option to use in one of the system startup scripts.
81 .TP
82 .B \-\-systohc
83 Set the Hardware Clock to the current System Time.
84 .TP
85 .B \-\-adjust
86 Add or subtract time from the Hardware Clock to account for systematic
87 drift since the last time the clock was set or adjusted. See discussion
88 below.
89 .TP
90 .B \-\-getepoch
91 Print the kernel's Hardware Clock epoch value to standard output.
92 This is the number of years into AD to which a zero year value in the
93 Hardware Clock refers. For example, if you are using the convention
94 that the year counter in your Hardware Clock contains the number of
95 full years since 1952, then the kernel's Hardware Counter epoch value
96 must be 1952.
97
98 This epoch value is used whenever hwclock reads or sets the Hardware Clock.
99 .TP
100 .B \-\-setepoch
101 Set the kernel's Hardware Clock epoch value to the value specified by the
102 .B \-\-epoch
103 option. See the
104 .B \-\-getepoch
105 option for details.
106 .TP
107 .B \-\-version
108 Print the version of
109 .B hwclock
110 on Standard Output.
111 .TP
112 .B \-\-date=date_string
113 You need this option if you specify the
114 .B \-\-set
115 option. Otherwise, it is ignored.
116 This specifies the time to which to set the Hardware Clock.
117 The value of this option is an argument to the
118 .BR date (1)
119 program.
120 For example,
121 .sp
122 .I hwclock --set --date="9/22/96 16:45:05"
123 .sp
124 The argument is in local time, even if you keep your Hardware Clock in
125 Coordinated Universal time. See the
126 .B \-\-utc
127 option.
128
129 .TP
130 .B \-\-epoch=year
131 Specifies the year which is the beginning of the Hardware Clock's
132 epoch. I.e. the number of years into AD to which a zero value in the
133 Hardware Clock's year counter refers. It is used together with
134 the \-\-setepoch option to set the kernel's idea of the epoch of the
135 Hardware Clock, or otherwise to specify the epoch for use with
136 direct ISA access.
137
138 For example, on a Digital Unix machine:
139 .sp
140 .I hwclock --setepoch --epoch=1952
141
142 .PP
143 The following options apply to most functions.
144 .TP
145 .B \-\-utc
146 .TP
147 .B \-\-localtime
148 Indicates that the Hardware Clock is kept in Coordinated Universal
149 Time or local time, respectively. It is your choice whether to keep
150 your clock in UTC or local time, but nothing in the clock tells which
151 you've chosen. So this option is how you give that information to
152 .BR hwclock .
153
154 If you specify the wrong one of these options (or specify neither and
155 take a wrong default), both setting and querying of the Hardware Clock
156 will be messed up.
157
158 If you specify neither
159 .B \-\-utc
160 nor
161 .B \-\-localtime
162 , the default is whichever was specified the last time
163 .B hwclock
164 was used to set the clock (i.e. hwclock was successfully run with the
165 .B \-\-set
166 ,
167 .B \-\-systohc
168 ,
169 or
170 .B \-\-adjust
171 options), as recorded in the adjtime file. If the adjtime file doesn't
172 exist, the default is local time.
173
174 .TP
175 .B \-\-noadjfile
176 disables the facilities provided by
177 .IR /etc/adjtime .
178 .B hwclock
179 will not read nor write to that file with this option. Either
180 .B \-\-utc
181 or
182 .B \-\-localtime
183 must be specified when using this option.
184
185 .TP
186 .B \-\-rtc=filename
187 overrides the default /dev file name, which is
188 .IR /dev/rtc
189 on many platforms but may be
190 .IR /dev/rtc0 ,
191 .IR /dev/rtc1 ,
192 and so on.
193
194 .TP
195 .B \-\-directisa
196 is meaningful only on an ISA machine or an Alpha (which implements enough
197 of ISA to be, roughly speaking, an ISA machine for
198 .BR hwclock 's
199 purposes). For other machines, it has no effect. This option tells
200 .B hwclock
201 to use explicit I/O instructions to access the Hardware Clock.
202 Without this option,
203 .B hwclock
204 will try to use the /dev/rtc device (which it assumes to be driven by the
205 rtc device driver). If it is unable to open the device (for read), it will
206 use the explicit I/O instructions anyway.
207
208 The rtc device driver was new in Linux Release 2.
209 .TP
210 .B \-\-badyear
211 Indicates that the Hardware Clock is incapable of storing years outside
212 the range 1994-1999. There is a problem in some BIOSes (almost all
213 Award BIOSes made between 4/26/94 and 5/31/95) wherein they are unable
214 to deal with years after 1999. If one attempts to set the year-of-century
215 value to something less than 94 (or 95 in some cases), the value that
216 actually gets set is 94 (or 95). Thus, if you have one of these machines,
217 .B hwclock
218 cannot set the year after 1999 and cannot use the value of the clock as
219 the true time in the normal way.
220
221 To compensate for this (without your getting a BIOS update, which would
222 definitely be preferable), always use
223 .B \-\-badyear
224 if you have one of these machines. When
225 .B hwclock
226 knows it's working with a brain-damaged clock, it ignores the year part of
227 the Hardware Clock value and instead tries to guess the year based on the
228 last calibrated date in the adjtime file, by assuming that that date is
229 within the past year. For this to work, you had better do a
230 .I hwclock \-\-set
231 or
232 .I hwclock \-\-systohc
233 at least once a year!
234
235 Though
236 .B hwclock
237 ignores the year value when it reads the Hardware Clock, it sets the
238 year value when it sets the clock. It sets it to 1995, 1996, 1997, or
239 1998, whichever one has the same position in the leap year cycle as
240 the true year. That way, the Hardware Clock inserts leap days where
241 they belong. Again, if you let the Hardware Clock run for more than a
242 year without setting it, this scheme could be defeated and you could
243 end up losing a day.
244
245 .B hwclock
246 warns you that you probably need
247 .B \-\-badyear
248 whenever it finds your Hardware Clock set to 1994 or 1995.
249
250 .TP
251 .B \-\-srm
252 This option is equivalent to
253 .B \-\-epoch=1900
254 and is used to specify the most common epoch on Alphas
255 with SRM console.
256 .TP
257 .B \-\-arc
258 This option is equivalent to
259 .B \-\-epoch=1980
260 and is used to specify the most common epoch on Alphas
261 with ARC console (but Ruffians have epoch 1900).
262 .TP
263 .B \-\-jensen
264 .TP
265 .B \-\-funky\-toy
266 These two options specify what kind of Alpha machine you have. They
267 are invalid if you don't have an Alpha and are usually unnecessary
268 if you do, because
269 .B hwclock
270 should be able to determine by itself what it's
271 running on, at least when
272 .I /proc
273 is mounted.
274 (If you find you need one of these options to make
275 .B hwclock
276 work, contact the maintainer to see if the program can be improved
277 to detect your system automatically. Output of `hwclock --debug'
278 and `cat /proc/cpuinfo' may be of interest.)
279
280 .B \-\-jensen
281 means you are running on a Jensen model.
282
283 .B \-\-funky\-toy
284 means that on your machine, one has to use the UF bit instead
285 of the UIP bit in the Hardware Clock to detect a time transition. "Toy"
286 in the option name refers to the Time Of Year facility of the machine.
287
288
289 .TP
290 .B \-\-test
291 Do everything except actually updating the Hardware Clock or anything
292 else. This is useful, especially in conjunction with
293 .B \-\-debug,
294 in learning about
295 .B hwclock.
296 .TP
297 .B \-\-debug
298 Display a lot of information about what
299 .B hwclock
300 is doing internally. Some of its function is complex and this output
301 can help you understand how the program works.
302
303
304 .SH NOTES
305
306
307 .SH Clocks in a Linux System
308 .PP
309 There are two main clocks in a Linux system:
310 .PP
311 .B The Hardware Clock:
312 This is a clock that runs independently of any control program running
313 in the CPU and even when the machine is powered off.
314
315 On an ISA system, this clock is specified as part of the ISA standard.
316 The control program can read or set this clock to a whole second, but
317 the control program can also detect the edges of the 1 second clock
318 ticks, so the clock actually has virtually infinite precision.
319 .PP
320 This clock is commonly called the hardware clock, the real time clock,
321 the RTC, the BIOS clock, and the CMOS clock. Hardware Clock, in its
322 capitalized form, was coined for use by
323 .B hwclock
324 because all of the other names are inappropriate to the point of being
325 misleading.
326 .PP
327 So for example, some non-ISA systems have a few real time clocks with
328 only one of them having its own power domain.
329 A very low power external I2C or SPI clock chip might be used with a
330 backup battery as the hardware clock to initialize a more functional
331 integrated real-time clock which is used for most other purposes.
332 .PP
333 .B The System Time:
334 This is the time kept by a clock inside the Linux kernel and driven by
335 a timer interrupt. (On an ISA machine, the timer interrupt is part of
336 the ISA standard). It has meaning only while Linux is running on the
337 machine. The System Time is the number of seconds since 00:00:00
338 January 1, 1970 UTC (or more succinctly, the number of seconds since
339 1969). The System Time is not an integer, though. It has virtually
340 infinite precision.
341 .PP
342 The System Time is the time that matters. The Hardware Clock's basic
343 purpose in a Linux system is to keep time when Linux is not running. You
344 initialize the System Time to the time from the Hardware Clock when Linux
345 starts up, and then never use the Hardware Clock again. Note that in DOS,
346 for which ISA was designed, the Hardware Clock is the only real time clock.
347 .PP
348 It is important that the System Time not have any discontinuities such as
349 would happen if you used the
350 .BR date (1L)
351 program to set it while the system is running. You can, however, do whatever
352 you want to the Hardware Clock while the system is running, and the next
353 time Linux starts up, it will do so with the adjusted time from the Hardware
354 Clock. You can also use the program
355 .BR adjtimex (8)
356 to smoothly adjust the System Time while the system runs.
357 .PP
358 A Linux kernel maintains a concept of a local timezone for the system.
359 But don't be misled -- almost nobody cares what timezone the kernel
360 thinks it is in. Instead, programs that care about the timezone
361 (perhaps because they want to display a local time for you) almost
362 always use a more traditional method of determining the timezone: They
363 use the TZ environment variable and/or the
364 .I /usr/share/zoneinfo
365 directory, as explained in the man page for
366 .BR tzset (3).
367 However, some
368 programs and fringe parts of the Linux kernel such as filesystems use
369 the kernel timezone value. An example is the vfat filesystem. If the
370 kernel timezone value is wrong, the vfat filesystem will report and
371 set the wrong timestamps on files.
372 .PP
373 .B hwclock
374 sets the kernel timezone to the value indicated by TZ and/or
375 .I /usr/share/zoneinfo
376 when you set the System Time using the
377 .B \-\-hctosys
378 option.
379 .PP
380 The timezone value actually consists of two parts: 1) a field
381 tz_minuteswest indicating how many minutes local time (not adjusted
382 for DST) lags behind UTC, and 2) a field tz_dsttime indicating
383 the type of Daylight Savings Time (DST) convention that is in effect
384 in the locality at the present time.
385 This second field is not used under Linux and is always zero.
386 (See also
387 .BR settimeofday (2).)
388
389 .SH How hwclock Accesses the Hardware Clock
390 .PP
391 .B hwclock
392 Uses many different ways to get and set Hardware Clock values.
393 The most normal way is to do I/O to the device special file /dev/rtc,
394 which is presumed to be driven by the rtc device driver. However,
395 this method is not always available. For one thing, the rtc driver is
396 a relatively recent addition to Linux. Older systems don't have it.
397 Also, though there are versions of the rtc driver that work on DEC
398 Alphas, there appear to be plenty of Alphas on which the rtc driver
399 does not work (a common symptom is hwclock hanging).
400 Moreover, recent Linux systems have more generic support for RTCs,
401 even systems that have more than one, so you might need to override
402 the default by specifying
403 .I /dev/rtc0
404 or
405 .I /dev/rtc1
406 instead.
407 .PP
408 On older systems, the method of accessing the Hardware Clock depends on
409 the system hardware.
410 .PP
411 On an ISA system,
412 .B hwclock
413 can directly access the "CMOS memory" registers that
414 constitute the clock, by doing I/O to Ports 0x70 and 0x71. It does
415 this with actual I/O instructions and consequently can only do it if
416 running with superuser effective userid. (In the case of a Jensen
417 Alpha, there is no way for
418 .B hwclock
419 to execute those I/O instructions, and so it uses instead the
420 /dev/port device special file, which provides almost as low-level an
421 interface to the I/O subsystem).
422
423 This is a really poor method of accessing the clock, for all the
424 reasons that user space programs are generally not supposed to do
425 direct I/O and disable interrupts. Hwclock provides it because it is
426 the only method available on ISA and Alpha systems which don't have
427 working rtc device drivers available.
428
429 .PP
430 On an m68k system,
431 .B hwclock
432 can access the clock via the console driver, via the device special
433 file /dev/tty1.
434 .PP
435 .B hwclock
436 tries to use /dev/rtc. If it is compiled for a kernel that doesn't have
437 that function or it is unable to open /dev/rtc
438 (or the alternative special file you've defined on the command line)
439 .B hwclock
440 will fall back to another method, if available. On an ISA or Alpha
441 machine, you can force
442 .B hwclock
443 to use the direct manipulation of the CMOS registers without even trying
444 .I /dev/rtc
445 by specifying the \-\-directisa option.
446
447
448 .SH The Adjust Function
449 .PP
450 The Hardware Clock is usually not very accurate. However, much of its
451 inaccuracy is completely predictable - it gains or loses the same amount
452 of time every day. This is called systematic drift.
453 .BR hwclock 's
454 "adjust" function lets you make systematic corrections to correct the
455 systematic drift.
456 .PP
457 It works like this:
458 .B hwclock
459 keeps a file,
460 .I /etc/adjtime,
461 that keeps some historical information. This is called the adjtime file.
462 .PP
463 Suppose you start with no adjtime file. You issue a
464 .I hwclock \-\-set
465 command to set the Hardware Clock to the true current time.
466 .B Hwclock
467 creates the adjtime file and records in it the current time as the
468 last time the clock was calibrated.
469 5 days later, the clock has gained 10 seconds, so you issue another
470 .I hwclock \-\-set
471 command to set it back 10 seconds.
472 .B Hwclock
473 updates the adjtime file to show the current time as the last time the
474 clock was calibrated, and records 2 seconds per day as the systematic
475 drift rate. 24 hours go by, and then you issue a
476 .I hwclock \-\-adjust
477 command.
478 .B Hwclock
479 consults the adjtime file and sees that the clock gains 2 seconds per
480 day when left alone and that it has been left alone for exactly one
481 day. So it subtracts 2 seconds from the Hardware Clock. It then
482 records the current time as the last time the clock was adjusted.
483 Another 24 hours goes by and you issue another
484 .I hwclock \-\-adjust.
485 .B Hwclock
486 does the same thing: subtracts 2 seconds and updates the adjtime file
487 with the current time as the last time the clock was adjusted.
488 .PP
489 Every time you calibrate (set) the clock (using
490 .I \-\-set
491 or
492 .I \-\-systohc
493 ),
494 .B hwclock
495 recalculates the systematic drift rate based on how long it has been
496 since the last calibration, how long it has been since the last
497 adjustment, what drift rate was assumed in any intervening
498 adjustments, and the amount by which the clock is presently off.
499 .PP
500 A small amount of error creeps in any time
501 .B hwclock
502 sets the clock, so it refrains from making an adjustment that would be
503 less than 1 second. Later on, when you request an adjustment again,
504 the accumulated drift will be more than a second and
505 .B hwclock
506 will do the adjustment then.
507 .PP
508 It is good to do a
509 .I hwclock \-\-adjust
510 just before the
511 .I hwclock \-\-hctosys
512 at system startup time, and maybe periodically while the system is
513 running via cron.
514 .PP
515 The adjtime file, while named for its historical purpose of controlling
516 adjustments only, actually contains other information for use by hwclock
517 in remembering information from one invocation to the next.
518 .PP
519 The format of the adjtime file is, in ASCII:
520 .PP
521 Line 1: 3 numbers, separated by blanks: 1) systematic drift rate in
522 seconds per day, floating point decimal; 2) Resulting number of
523 seconds since 1969 UTC of most recent adjustment or calibration,
524 decimal integer; 3) zero (for compatibility with
525 .BR clock (8))
526 as a decimal integer.
527 .PP
528 Line 2: 1 number: Resulting number of seconds since 1969 UTC of most
529 recent calibration. Zero if there has been no calibration yet or it
530 is known that any previous calibration is moot (for example, because
531 the Hardware Clock has been found, since that calibration, not to
532 contain a valid time). This is a decimal integer.
533 .PP
534 Line 3: "UTC" or "LOCAL". Tells whether the Hardware Clock is set to
535 Coordinated Universal Time or local time. You can always override this
536 value with options on the
537 .B hwclock
538 command line.
539 .PP
540 You can use an adjtime file that was previously used with the
541 .BR clock (8)
542 program with
543 .B hwclock.
544
545
546 .SH "Automatic Hardware Clock Synchronization By the Kernel"
547
548 You should be aware of another way that the Hardware Clock is kept
549 synchronized in some systems. The Linux kernel has a mode wherein it
550 copies the System Time to the Hardware Clock every 11 minutes.
551 This is a good mode to use when you are using something sophisticated
552 like ntp to keep your System Time synchronized. (ntp is a way to keep
553 your System Time synchronized either to a time server somewhere on the
554 network or to a radio clock hooked up to your system. See RFC 1305).
555
556 This mode (we'll call it "11 minute mode") is off until something
557 turns it on. The ntp daemon xntpd is one thing that turns it on. You
558 can turn it off by running anything, including
559 .IR "hwclock \-\-hctosys" ,
560 that sets the System Time the old fashioned way.
561
562 To see if it is on or
563 off, use the command
564 .I adjtimex \-\-print
565 and look at the value of "status". If the "64" bit of this number
566 (expressed in binary) equal to 0, 11 minute mode is on. Otherwise, it
567 is off.
568
569 If your system runs with 11 minute mode on, don't use
570 .I hwclock \-\-adjust
571 or
572 .IR "hwclock \-\-hctosys" .
573 You'll just make a mess. It is acceptable to use a
574 .I hwclock \-\-hctosys
575 at startup time to get a reasonable System Time until your system is
576 able to set the System Time from the external source and start 11
577 minute mode.
578
579
580 .SH ISA Hardware Clock Century value
581
582 There is some sort of standard that defines CMOS memory Byte 50 on an ISA
583 machine as an indicator of what century it is.
584 .B hwclock
585 does not use or set that byte because there are some machines that
586 don't define the byte that way, and it really isn't necessary anyway,
587 since the year-of-century does a good job of implying which century it
588 is.
589
590 If you have a bona fide use for a CMOS century byte, contact the
591 .B hwclock
592 maintainer; an option may be appropriate.
593
594 Note that this section is only relevant when you are using the "direct
595 ISA" method of accessing the Hardware Clock.
596 ACPI provides a standard way to access century values, when they
597 are supported by the hardware.
598
599 .SH "ENVIRONMENT VARIABLES"
600 .I TZ
601
602 .SH FILES
603 .I /etc/adjtime
604 .I /usr/share/zoneinfo/
605 .RI ( /usr/lib/zoneinfo
606 on old systems)
607 .I /dev/rtc
608 .I /dev/rtc0
609 .I /dev/port
610 .I /dev/tty1
611 .I /proc/cpuinfo
612
613 .SH "SEE ALSO"
614 .BR adjtimex (8),
615 .BR date (1),
616 .BR gettimeofday (2),
617 .BR settimeofday (2),
618 .BR crontab (1),
619 .BR tzset (3)
620
621 .SH AUTHORS
622 Written by Bryan Henderson, September 1996 (bryanh@giraffe-data.com),
623 based on work done on the
624 .I clock
625 program by Charles Hedrick, Rob Hooft, and Harald Koenig.
626 See the source code for complete history and credits.
627
628 .SH AVAILABILITY
629 The hwclock command is part of the util-linux-ng package and is available from
630 ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.