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