1HWCLOCK(8)                  System Manager's Manual                 HWCLOCK(8)
2
3
4

NAME

6       hwclock - query and set the hardware clock (RTC)
7

SYNOPSIS

9       hwclock -r or hwclock --show
10       hwclock -w or hwclock --systohc
11       hwclock -s or hwclock --hctosys
12       hwclock -a or hwclock --adjust
13       hwclock -v or hwclock --version
14       hwclock --set --date=newdate
15       hwclock --getepoch
16       hwclock --setepoch --epoch=year
17
18       other options:
19
20       [-u|--utc]  --localtime  --noadjfile --directisa --test [-D|--debug]
21
22       and arcane options for DEC Alpha:
23
24       [-A|--arc] [-J|--jensen] [-S|--srm] [-F|--funky-toy]
25
26       Minimum unique abbreviations of all options are acceptable.
27
28       Also, -h asks for a help message.
29
30

DESCRIPTION

32       hwclock  is  a  tool for accessing the Hardware Clock.  You can display
33       the current time, set the Hardware Clock to a specified time,  set  the
34       Hardware  Clock  to  the  System Time, and set the System Time from the
35       Hardware Clock.
36
37       You can also run hwclock periodically to insert or remove time from the
38       Hardware Clock to compensate for systematic drift (where the clock con‐
39       sistently gains or loses time at a certain rate if left to run).
40
41

OPTIONS

43       You need exactly one of the following  options  to  tell  hwclock  what
44       function to perform:
45
46       --show Read  the  Hardware Clock and print the time on Standard Output.
47              The time shown is always in local time, even if  you  keep  your
48              Hardware  Clock  in  Coordinated  Universal Time.  See the --utc
49              option.
50
51
52       --set  Set the Hardware Clock to the time given by the --date option.
53
54       --hctosys
55              Set the System Time from the Hardware Clock.
56
57              Also set the kernel's timezone value to the  local  timezone  as
58              indicated by the TZ environment variable and/or /usr/share/zone‐
59              info, as tzset(3) would interpret them.  The obsolete tz_dsttime
60              field  of  the  kernel's timezone value is set to DST_NONE. (For
61              details on what this field used to mean, see settimeofday(2).)
62
63              This is a good option to  use  in  one  of  the  system  startup
64              scripts.
65
66       --systohc
67              Set the Hardware Clock to the current System Time.
68
69       --adjust
70              Add or subtract time from the Hardware Clock to account for sys‐
71              tematic drift since the last time the clock was set or adjusted.
72              See discussion below.
73
74       --getepoch
75              Print  the  kernel's Hardware Clock epoch value to standard out‐
76              put.  This is the number of years into AD to which a  zero  year
77              value  in  the  Hardware  Clock refers.  For example, if you are
78              using the convention that the  year  counter  in  your  Hardware
79              Clock  contains  the  number  of full years since 1952, then the
80              kernel's Hardware Counter epoch value must be 1952.
81
82              This epoch value is used whenever  hwclock  reads  or  sets  the
83              Hardware Clock.
84
85       --setepoch
86              Set  the kernel's Hardware Clock epoch value to the value speci‐
87              fied by the --epoch  option.   See  the  --getepoch  option  for
88              details.
89
90       --version
91              Print the version of hwclock on Standard Output.
92
93       --date=date_string
94              You  need  this  option if you specify the --set option.  Other‐
95              wise, it is ignored.  This specifies the time to  which  to  set
96              the  Hardware Clock.  The value of this option is an argument to
97              the date(1) program.  For example,
98
99              hwclock --set --date="9/22/96 16:45:05"
100
101              The argument is in local time, even if you  keep  your  Hardware
102              Clock in Coordinated Universal time.  See the --utc option.
103
104
105       --epoch=year
106              Specifies  the  year  which  is  the  beginning  of the Hardware
107              Clock's epoch.  I.e. the number of years into AD to which a zero
108              value  in  the  Hardware Clock's year counter refers. It is used
109              together with the --setepoch option to set the kernel's idea  of
110              the  epoch  of  the  Hardware Clock, or otherwise to specify the
111              epoch for use with direct ISA access.
112
113              For example, on a Digital Unix machine:
114
115              hwclock --setepoch --epoch=1952
116
117
118       The following options apply to most functions.
119
120       --utc
121
122       --localtime
123              Indicates that the Hardware Clock is kept in Coordinated Univer‐
124              sal Time or local time, respectively.  It is your choice whether
125              to keep your clock in UTC or local  time,  but  nothing  in  the
126              clock tells which you've chosen.  So this option is how you give
127              that information to hwclock.
128
129              If you specify the wrong one of these options (or  specify  nei‐
130              ther and take a wrong default), both setting and querying of the
131              Hardware Clock will be messed up.
132
133              If you specify neither --utc nor --localtime ,  the  default  is
134              whichever  was  specified  the last time hwclock was used to set
135              the clock (i.e. hwclock was successfully run with  the  --set  ,
136              --systohc  ,  or  --adjust  options), as recorded in the adjtime
137              file.  If the adjtime file doesn't exist, the default  is  local
138              time.
139
140
141       --noadjfile
142              disables  the facilities provided by /etc/adjtime.  hwclock will
143              not read nor write to that file with this option.  Either  --utc
144              or --localtime must be specified when using this option.
145
146
147       --directisa
148              is  meaningful  only on an ISA machine or an Alpha (which imple‐
149              ments enough of ISA to be, roughly speaking, an ISA machine  for
150              hwclock's  purposes).   For  other  machines,  it has no effect.
151              This option tells hwclock to use explicit  I/O  instructions  to
152              access  the  Hardware  Clock.  Without this option, hwclock will
153              try to use the /dev/rtc device (which it assumes to be driven by
154              the rtc device driver).  If it is unable to open the device (for
155              read), it will use the explicit I/O instructions anyway.
156
157              The rtc device driver was new in Linux Release 2.
158
159       --badyear
160              Indicates that the Hardware Clock is incapable of storing  years
161              outside  the range 1994-1999.  There is a problem in some BIOSes
162              (almost all Award  BIOSes  made  between  4/26/94  and  5/31/95)
163              wherein  they  are unable to deal with years after 1999.  If one
164              attempts to set the year-of-century value to something less than
165              94 (or 95 in some cases), the value that actually gets set is 94
166              (or 95).  Thus, if you have one of these machines, hwclock  can‐
167              not  set  the  year  after  1999 and cannot use the value of the
168              clock as the true time in the normal way.
169
170              To compensate for this (without  your  getting  a  BIOS  update,
171              which  would  definitely be preferable), always use --badyear if
172              you have one of these machines.  When hwclock knows it's working
173              with  a  brain-damaged  clock,  it  ignores the year part of the
174              Hardware Clock value and instead tries to guess the  year  based
175              on  the  last  calibrated  date in the adjtime file, by assuming
176              that that date is within the past year.  For this to  work,  you
177              had better do a hwclock --set or hwclock --systohc at least once
178              a year!
179
180              Though hwclock ignores the year value when it reads the Hardware
181              Clock,  it  sets the year value when it sets the clock.  It sets
182              it to 1995, 1996, 1997, or 1998,  whichever  one  has  the  same
183              position in the leap year cycle as the true year.  That way, the
184              Hardware Clock inserts leap days where they belong.   Again,  if
185              you let the Hardware Clock run for more than a year without set‐
186              ting it, this scheme could be defeated and you could end up los‐
187              ing a day.
188
189              hwclock  warns  you that you probably need --badyear whenever it
190              finds your Hardware Clock set to 1994 or 1995.
191
192
193       --srm  This option is equivalent to --epoch=1900 and is used to specify
194              the most common epoch on Alphas with SRM console.
195
196       --arc  This option is equivalent to --epoch=1980 and is used to specify
197              the most common epoch on Alphas with ARC console  (but  Ruffians
198              have epoch 1900).
199
200       --jensen
201
202       --funky-toy
203              These  two  options specify what kind of Alpha machine you have.
204              They are invalid if you don't have  an  Alpha  and  are  usually
205              unnecessary  if you do, because hwclock should be able to deter‐
206              mine by itself what it's running on,  at  least  when  /proc  is
207              mounted.   (If  you  find  you need one of these options to make
208              hwclock work, contact the maintainer to see if the  program  can
209              be  improved  to  detect  your  system  automatically. Output of
210              `hwclock --debug' and `cat /proc/cpuinfo' may be of interest.)
211
212              --jensen means you are running on a Jensen model.
213
214              --funky-toy means that on your machine, one has to  use  the  UF
215              bit  instead  of  the  UIP bit in the Hardware Clock to detect a
216              time transition.  "Toy" in the option name refers to the Time Of
217              Year facility of the machine.
218
219
220
221       --test Do  everything  except  actually  updating the Hardware Clock or
222              anything else.  This is useful, especially in  conjunction  with
223              --debug, in learning about hwclock.
224
225       --debug
226              Display  a lot of information about what hwclock is doing inter‐
227              nally.  Some of its function is complex and this output can help
228              you understand how the program works.
229
230
231

NOTES

Clocks in a Linux System

234       There are two main clocks in a Linux system:
235
236       The Hardware Clock: This is a clock that runs independently of any con‐
237       trol program running in the CPU and even when the  machine  is  powered
238       off.
239
240       On  an ISA system, this clock is specified as part of the ISA standard.
241       The control program can read or set this clock to a whole  second,  but
242       the  control  program  can  also detect the edges of the 1 second clock
243       ticks, so the clock actually has virtually infinite precision.
244
245       This clock is commonly called the hardware clock, the real time  clock,
246       the  RTC,  the  BIOS clock, and the CMOS clock.  Hardware Clock, in its
247       capitalized form, was coined for use by  hwclock  because  all  of  the
248       other names are inappropriate to the point of being misleading.
249
250       The System Time: This is the time kept by a clock inside the Linux ker‐
251       nel and driven by a timer interrupt.  (On an  ISA  machine,  the  timer
252       interrupt  is  part  of  the  ISA standard).  It has meaning only while
253       Linux is running on the machine.  The System Time is the number of sec‐
254       onds since 00:00:00 January 1, 1970 UTC (or more succinctly, the number
255       of seconds since 1969).  The System Time is not an integer, though.  It
256       has virtually infinite precision.
257
258       The  System  Time is the time that matters.  The Hardware Clock's basic
259       purpose in a Linux system is to keep time when Linux  is  not  running.
260       You initialize the System Time to the time from the Hardware Clock when
261       Linux starts up, and then never use the  Hardware  Clock  again.   Note
262       that in DOS, for which ISA was designed, the Hardware Clock is the only
263       real time clock.
264
265       It is important that the System Time not have any discontinuities  such
266       as  would  happen  if you used the date(1L) program to set it while the
267       system is running.  You can, however, do whatever you want to the Hard‐
268       ware  Clock while the system is running, and the next time Linux starts
269       up, it will do so with the adjusted time from the Hardware Clock.   You
270       can also use the program adjtimex(8) to smoothly adjust the System Time
271       while the system runs.
272
273       A Linux kernel maintains a concept of a local timezone for the  system.
274       But  don't  be  misled  -- almost nobody cares what timezone the kernel
275       thinks it is in.  Instead, programs that care about the timezone  (per‐
276       haps  because  they want to display a local time for you) almost always
277       use a more traditional method of determining the timezone: They use the
278       TZ  environment  variable  and/or the /usr/share/zoneinfo directory, as
279       explained in the man page for tzset(3).   However,  some  programs  and
280       fringe  parts  of  the  Linux kernel such as filesystems use the kernel
281       timezone value.  An example is the  vfat  filesystem.   If  the  kernel
282       timezone  value  is  wrong, the vfat filesystem will report and set the
283       wrong timestamps on files.
284
285       hwclock sets the kernel timezone to the value indicated  by  TZ  and/or
286       /usr/share/zoneinfo  when  you  set the System Time using the --hctosys
287       option.
288
289       The timezone value actually consists of two parts: 1) a  field  tz_min‐
290       uteswest  indicating how many minutes local time (not adjusted for DST)
291       lags behind UTC, and 2) a field tz_dsttime indicating the type of  Day‐
292       light  Savings  Time (DST) convention that is in effect in the locality
293       at the present time.  This second field is not used under Linux and  is
294       always zero.  (See also settimeofday(2).)
295
296

How hwclock Accesses the Hardware Clock

298       hwclock  Uses many different ways to get and set Hardware Clock values.
299       The most normal way is to do I/O to the device special  file  /dev/rtc,
300       which is presumed to be driven by the rtc device driver.  However, this
301       method is not always available.  For one thing, the  rtc  driver  is  a
302       relatively  recent  addition  to  Linux.   Older systems don't have it.
303       Also, though there are versions of the rtc  driver  that  work  on  DEC
304       Alphas,  there  appear  to  be plenty of Alphas on which the rtc driver
305       does not work (a common symptom is hwclock hanging).
306
307       On older systems, the method of accessing the Hardware Clock depends on
308       the system hardware.
309
310       On  an ISA system, hwclock can directly access the "CMOS memory" regis‐
311       ters that constitute the clock, by doing I/O to Ports  0x70  and  0x71.
312       It  does this with actual I/O instructions and consequently can only do
313       it if running with superuser effective  userid.   (In  the  case  of  a
314       Jensen Alpha, there is no way for hwclock to execute those I/O instruc‐
315       tions, and so it uses instead the /dev/port device special file,  which
316       provides almost as low-level an interface to the I/O subsystem).
317
318       This  is  a really poor method of accessing the clock, for all the rea‐
319       sons that user space programs are generally not supposed to  do  direct
320       I/O and disable interrupts.  Hwclock provides it because it is the only
321       method available on ISA and Alpha systems which don't have working  rtc
322       device drivers available.
323
324
325       On an m68k system, hwclock can access the clock via the console driver,
326       via the device special file /dev/tty1.
327
328       hwclock tries to use /dev/rtc.  If it is compiled  for  a  kernel  that
329       doesn't  have  that  function or it is unable to open /dev/rtc, hwclock
330       will fall back to another method, if available.  On  an  ISA  or  Alpha
331       machine,  you  can  force hwclock to use the direct manipulation of the
332       CMOS registers without even trying /dev/rtc by specifying the  --direc‐
333       tisa option.
334
335
336

The Adjust Function

338       The  Hardware Clock is usually not very accurate.  However, much of its
339       inaccuracy is completely predictable -  it  gains  or  loses  the  same
340       amount  of time every day.  This is called systematic drift.  hwclock's
341       "adjust" function lets you make systematic corrections to  correct  the
342       systematic drift.
343
344       It works like this: hwclock keeps a file, /etc/adjtime, that keeps some
345       historical information.  This is called the adjtime file.
346
347       Suppose you start with no adjtime file.  You issue a hwclock --set com‐
348       mand  to set the Hardware Clock to the true current time.  Hwclock cre‐
349       ates the adjtime file and records in it the current time  as  the  last
350       time  the  clock was calibrated.  5 days later, the clock has gained 10
351       seconds, so you issue another hwclock --set command to set it  back  10
352       seconds.   Hwclock updates the adjtime file to show the current time as
353       the last time the clock was calibrated, and records 2 seconds  per  day
354       as  the  systematic  drift  rate.  24 hours go by, and then you issue a
355       hwclock --adjust command.  Hwclock consults the adjtime file  and  sees
356       that  the clock gains 2 seconds per day when left alone and that it has
357       been left alone for exactly one day.  So it subtracts  2  seconds  from
358       the  Hardware Clock.  It then records the current time as the last time
359       the clock was adjusted.  Another 24 hours goes by and you issue another
360       hwclock --adjust.  Hwclock does the same thing: subtracts 2 seconds and
361       updates the adjtime file with the current time as  the  last  time  the
362       clock was adjusted.
363
364       Every  time  you calibrate (set) the clock (using --set or --systohc ),
365       hwclock recalculates the systematic drift rate based on how long it has
366       been  since  the  last calibration, how long it has been since the last
367       adjustment, what drift rate was assumed in any intervening adjustments,
368       and the amount by which the clock is presently off.
369
370       A  small  amount of error creeps in any time hwclock sets the clock, so
371       it refrains from making an adjustment that would be less than 1 second.
372       Later  on,  when you request an adjustment again, the accumulated drift
373       will be more than a second and hwclock will do the adjustment then.
374
375       It is good to do a hwclock --adjust just before the  hwclock  --hctosys
376       at system startup time, and maybe periodically while the system is run‐
377       ning via cron.
378
379       The adjtime file, while named for its historical purpose of controlling
380       adjustments  only,  actually  contains  other  information  for  use by
381       hwclock in remembering information from one invocation to the next.
382
383       The format of the adjtime file is, in ASCII:
384
385       Line 1: 3 numbers, separated by blanks: 1)  systematic  drift  rate  in
386       seconds per day, floating point decimal; 2) Resulting number of seconds
387       since 1969 UTC of most recent adjustment or calibration, decimal  inte‐
388       ger; 3) zero (for compatibility with clock(8)) as a decimal integer.
389
390       Line  2:  1  number: Resulting number of seconds since 1969 UTC of most
391       recent calibration.  Zero if there has been no calibration yet or it is
392       known  that  any previous calibration is moot (for example, because the
393       Hardware Clock has been found, since that calibration, not to contain a
394       valid time).  This is a decimal integer.
395
396       Line  3:  "UTC" or "LOCAL".  Tells whether the Hardware Clock is set to
397       Coordinated Universal Time or local time.  You can always override this
398       value with options on the hwclock command line.
399
400       You  can use an adjtime file that was previously used with the clock(8)
401       program with hwclock.
402
403
404

Automatic Hardware Clock Synchronization By the Kernel

406       You should be aware of another way that the Hardware Clock is kept syn‐
407       chronized  in  some  systems.   The  Linux kernel has a mode wherein it
408       copies the System Time to the Hardware Clock every 11 minutes.  This is
409       a  good mode to use when you are using something sophisticated like ntp
410       to keep your System Time synchronized. (ntp is a way to keep your  Sys‐
411       tem  Time synchronized either to a time server somewhere on the network
412       or to a radio clock hooked up to your system.  See RFC 1305).
413
414       This mode (we'll call it "11 minute mode") is off until something turns
415       it  on.   The  ntp daemon xntpd is one thing that turns it on.  You can
416       turn it off by running anything, including hwclock --hctosys, that sets
417       the System Time the old fashioned way.
418
419       To see if it is on or off, use the command adjtimex --print and look at
420       the value of "status".  If the "64" bit of this  number  (expressed  in
421       binary) equal to 0, 11 minute mode is on.  Otherwise, it is off.
422
423       If  your system runs with 11 minute mode on, don't use hwclock --adjust
424       or hwclock --hctosys.  You'll just make a mess.  It  is  acceptable  to
425       use a hwclock --hctosys at startup time to get a reasonable System Time
426       until your system is able to set the  System  Time  from  the  external
427       source and start 11 minute mode.
428
429
430

ISA Hardware Clock Century value

432       There  is  some sort of standard that defines CMOS memory Byte 50 on an
433       ISA machine as an indicator of what century it is.   hwclock  does  not
434       use  or set that byte because there are some machines that don't define
435       the byte that way, and it really  isn't  necessary  anyway,  since  the
436       year-of-century does a good job of implying which century it is.
437
438       If  you  have  a  bona  fide  use  for a CMOS century byte, contact the
439       hwclock maintainer; an option may be appropriate.
440
441       Note that this section is only relevant when you are using the  "direct
442       ISA" method of accessing the Hardware Clock.
443
444
445
446

ENVIRONMENT VARIABLES

448       TZ
449
450

FILES

452       /etc/adjtime  /usr/share/zoneinfo/  (/usr/lib/zoneinfo  on old systems)
453       /dev/rtc /dev/port /dev/tty1 /proc/cpuinfo
454
455

SEE ALSO

457       adjtimex(8),  date(1),  gettimeofday(2),  settimeofday(2),  crontab(1),
458       tzset(3)
459
460

AUTHORS

462       Written  by  Bryan Henderson, September 1996 (bryanh@giraffe-data.com),
463       based on work done on the clock program by Charles Hedrick, Rob  Hooft,
464       and  Harald Koenig.  See the source code for complete history and cred‐
465       its.
466
467
468
469
470                                 02 March 1998                      HWCLOCK(8)
Impressum