OSDN Git Service

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