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 [functions] [options]
10
11

DESCRIPTION

13       hwclock  is  a  tool for accessing the Hardware Clock.  You can display
14       the current time, set the Hardware Clock to a specified time,  set  the
15       Hardware  Clock  to  the  System Time, and set the System Time from the
16       Hardware Clock.
17
18       You can also run hwclock periodically to insert or remove time from the
19       Hardware Clock to compensate for systematic drift (where the clock con‐
20       sistently gains or loses time at a certain rate if left to run).
21
22

FUNCTIONS

24       You need exactly one of the following  options  to  tell  hwclock  what
25       function to perform:
26
27       -r, --show
28              Read  the  Hardware Clock and print the time on Standard Output.
29              The time shown is always in local time, even if  you  keep  your
30              Hardware  Clock  in  Coordinated  Universal Time.  See the --utc
31              option.
32
33
34       --set  Set the Hardware Clock to the time given by the --date option.
35
36       -s, --hctosys
37              Set the System Time from the Hardware Clock.
38
39              Also set the kernel's timezone value to the  local  timezone  as
40              indicated by the TZ environment variable and/or /usr/share/zone‐
41              info, as tzset(3) would interpret them.  The obsolete tz_dsttime
42              field  of  the  kernel's timezone value is set to DST_NONE. (For
43              details on what this field used to mean, see settimeofday(2).)
44
45              This is a good option to  use  in  one  of  the  system  startup
46              scripts.
47
48       -w, --systohc
49              Set the Hardware Clock to the current System Time.
50
51       --systz
52              Reset the System Time based on the current timezone.
53
54              Also  set  the  kernel's timezone value to the local timezone as
55              indicated by the TZ environment variable and/or /usr/share/zone‐
56              info, as tzset(3) would interpret them.  The obsolete tz_dsttime
57              field of the kernel's timezone value is set  to  DST_NONE.  (For
58              details on what this field used to mean, see settimeofday(2).)
59
60              This  is an alternate option to --hctosys that does not read the
61              hardware clock, and may be used in system  startup  scripts  for
62              recent  2.6  kernels where you know the System Time contains the
63              Hardware Clock time.
64
65       --adjust
66              Add or subtract time from the Hardware Clock to account for sys‐
67              tematic drift since the last time the clock was set or adjusted.
68              See discussion below.
69
70       --getepoch
71              Print the kernel's Hardware Clock epoch value to  standard  out‐
72              put.   This  is the number of years into AD to which a zero year
73              value in the Hardware Clock refers.  For  example,  if  you  are
74              using  the  convention  that  the  year counter in your Hardware
75              Clock contains the number of full years  since  1952,  then  the
76              kernel's Hardware Counter epoch value must be 1952.
77
78              This  epoch  value  is  used  whenever hwclock reads or sets the
79              Hardware Clock.
80
81       --setepoch
82              Set the kernel's Hardware Clock epoch value to the value  speci‐
83              fied  by  the  --epoch  option.   See  the --getepoch option for
84              details.
85
86       -v, --version
87              Print the version of hwclock on Standard Output.
88
89       --date=date_string
90              You need this option if you specify the  --set  option.   Other‐
91              wise,  it  is  ignored.  This specifies the time to which to set
92              the Hardware Clock.  The value of this option is an argument  to
93              the date(1) program.  For example,
94
95              hwclock --set --date="9/22/96 16:45:05"
96
97              The  argument  is  in local time, even if you keep your Hardware
98              Clock in Coordinated Universal time.  See the --utc option.
99
100
101       --epoch=year
102              Specifies the year  which  is  the  beginning  of  the  Hardware
103              Clock's epoch.  I.e. the number of years into AD to which a zero
104              value in the Hardware Clock's year counter refers.  It  is  used
105              together  with the --setepoch option to set the kernel's idea of
106              the epoch of the Hardware Clock, or  otherwise  to  specify  the
107              epoch for use with direct ISA access.
108
109              For example, on a Digital Unix machine:
110
111              hwclock --setepoch --epoch=1952
112
113
114       --predict
115              Predict  what  the  RTC  will  read  at time given by the --date
116              option based on the adjtime file. This is useful for example  if
117              you need to set an RTC wakeup time to distant future and want to
118              account for the RTC drift.
119
120

OPTIONS

122       The following options apply to most functions.
123
124       -u, --utc
125
126       --localtime
127              Indicates that the Hardware Clock is kept in Coordinated Univer‐
128              sal Time or local time, respectively.  It is your choice whether
129              to keep your clock in UTC or local  time,  but  nothing  in  the
130              clock tells which you've chosen.  So this option is how you give
131              that information to hwclock.
132
133              If you specify the wrong one of these options (or  specify  nei‐
134              ther and take a wrong default), both setting and querying of the
135              Hardware Clock will be messed up.
136
137              If you specify neither --utc nor --localtime ,  the  default  is
138              whichever  was  specified  the last time hwclock was used to set
139              the clock (i.e. hwclock was successfully  run  with  the  --set,
140              --systohc,  or  --adjust  options),  as  recorded in the adjtime
141              file.  If the adjtime file doesn't exist, the default  is  local
142              time.
143
144
145       --noadjfile
146              disables  the facilities provided by /etc/adjtime.  hwclock will
147              not read nor write to that file with this option.  Either  --utc
148              or --localtime must be specified when using this option.
149
150
151       --adjfile=filename
152              overrides the default /etc/adjtime.
153
154
155       -f, --rtc=filename
156              overrides  the default /dev file name, which is /dev/rtc on many
157              platforms but may be /dev/rtc0, /dev/rtc1, and so on.
158
159
160       --directisa
161              is meaningful only on an ISA machine or an Alpha  (which  imple‐
162              ments  enough of ISA to be, roughly speaking, an ISA machine for
163              hwclock's purposes).  For other  machines,  it  has  no  effect.
164              This  option  tells  hwclock to use explicit I/O instructions to
165              access the Hardware Clock.  Without this  option,  hwclock  will
166              try to use the /dev/rtc device (which it assumes to be driven by
167              the rtc device driver).  If it is unable to open the device (for
168              read), it will use the explicit I/O instructions anyway.
169
170              The rtc device driver was new in Linux Release 2.
171
172       --badyear
173              Indicates  that the Hardware Clock is incapable of storing years
174              outside the range 1994-1999.  There is a problem in some  BIOSes
175              (almost  all  Award  BIOSes  made  between  4/26/94 and 5/31/95)
176              wherein they are unable to deal with years after 1999.   If  one
177              attempts to set the year-of-century value to something less than
178              94 (or 95 in some cases), the value that actually gets set is 94
179              (or  95).  Thus, if you have one of these machines, hwclock can‐
180              not set the year after 1999 and cannot  use  the  value  of  the
181              clock as the true time in the normal way.
182
183              To  compensate  for  this  (without  your getting a BIOS update,
184              which would definitely be preferable), always use  --badyear  if
185              you have one of these machines.  When hwclock knows it's working
186              with a brain-damaged clock, it ignores  the  year  part  of  the
187              Hardware  Clock  value and instead tries to guess the year based
188              on the last calibrated date in the  adjtime  file,  by  assuming
189              that  that  date is within the past year.  For this to work, you
190              had better do a hwclock --set or hwclock --systohc at least once
191              a year!
192
193              Though hwclock ignores the year value when it reads the Hardware
194              Clock, it sets the year value when it sets the clock.   It  sets
195              it  to  1995,  1996,  1997,  or 1998, whichever one has the same
196              position in the leap year cycle as the true year.  That way, the
197              Hardware  Clock  inserts leap days where they belong.  Again, if
198              you let the Hardware Clock run for more than a year without set‐
199              ting it, this scheme could be defeated and you could end up los‐
200              ing a day.
201
202              hwclock warns you that you probably need --badyear  whenever  it
203              finds your Hardware Clock set to 1994 or 1995.
204
205
206       --srm  This option is equivalent to --epoch=1900 and is used to specify
207              the most common epoch on Alphas with SRM console.
208
209       --arc  This option is equivalent to --epoch=1980 and is used to specify
210              the  most  common epoch on Alphas with ARC console (but Ruffians
211              have epoch 1900).
212
213       --jensen
214
215       --funky-toy
216              These two options specify what kind of Alpha machine  you  have.
217              They  are  invalid  if  you  don't have an Alpha and are usually
218              unnecessary if you do, because hwclock should be able to  deter‐
219              mine  by  itself  what  it's  running on, at least when /proc is
220              mounted.  (If you find you need one of  these  options  to  make
221              hwclock  work,  contact the maintainer to see if the program can
222              be improved to  detect  your  system  automatically.  Output  of
223              `hwclock --debug' and `cat /proc/cpuinfo' may be of interest.)
224
225              --jensen means you are running on a Jensen model.
226
227              --funky-toy  means  that  on your machine, one has to use the UF
228              bit instead of the UIP bit in the Hardware  Clock  to  detect  a
229              time transition.  "Toy" in the option name refers to the Time Of
230              Year facility of the machine.
231
232
233
234       --test Do everything except actually updating  the  Hardware  Clock  or
235              anything  else.   This is useful, especially in conjunction with
236              --debug, in learning about hwclock.
237
238       --debug
239              Display a lot of information about what hwclock is doing  inter‐
240              nally.  Some of its function is complex and this output can help
241              you understand how the program works.
242
243
244

NOTES

Clocks in a Linux System

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

How hwclock Accesses the Hardware Clock

317       hwclock uses many different ways to get and set Hardware Clock  values.
318       The  most  normal way is to do I/O to the device special file /dev/rtc,
319       which is presumed to be driven by the rtc device driver.  However, this
320       method  is  not  always  available.  For one thing, the rtc driver is a
321       relatively recent addition to Linux.   Older  systems  don't  have  it.
322       Also,  though  there  are  versions  of the rtc driver that work on DEC
323       Alphas, there appear to be plenty of Alphas on  which  the  rtc  driver
324       does  not work (a common symptom is hwclock hanging).  Moreover, recent
325       Linux systems have more generic support for  RTCs,  even  systems  that
326       have more than one, so you might need to override the default by speci‐
327       fying /dev/rtc0 or /dev/rtc1 instead.
328
329       On older systems, the method of accessing the Hardware Clock depends on
330       the system hardware.
331
332       On  an ISA system, hwclock can directly access the "CMOS memory" regis‐
333       ters that constitute the clock, by doing I/O to Ports  0x70  and  0x71.
334       It  does this with actual I/O instructions and consequently can only do
335       it if running with superuser effective  userid.   (In  the  case  of  a
336       Jensen Alpha, there is no way for hwclock to execute those I/O instruc‐
337       tions, and so it uses instead the /dev/port device special file,  which
338       provides almost as low-level an interface to the I/O subsystem).
339
340       This  is  a really poor method of accessing the clock, for all the rea‐
341       sons that user space programs are generally not supposed to  do  direct
342       I/O and disable interrupts.  Hwclock provides it because it is the only
343       method available on ISA and Alpha systems which don't have working  rtc
344       device drivers available.
345
346
347       On an m68k system, hwclock can access the clock via the console driver,
348       via the device special file /dev/tty1.
349
350       hwclock tries to use /dev/rtc.  If it is compiled  for  a  kernel  that
351       doesn't  have  that  function  or it is unable to open /dev/rtc (or the
352       alternative special file you've defined on the  command  line)  hwclock
353       will  fall  back  to  another method, if available.  On an ISA or Alpha
354       machine, you can force hwclock to use the direct  manipulation  of  the
355       CMOS  registers without even trying /dev/rtc by specifying the --direc‐
356       tisa option.
357
358
359

The Adjust Function

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

Automatic Hardware Clock Synchronization By the Kernel

429       You should be aware of another way that the Hardware Clock is kept syn‐
430       chronized in some systems.  The Linux kernel  has  a  mode  wherein  it
431       copies the System Time to the Hardware Clock every 11 minutes.  This is
432       a good mode to use when you are using something sophisticated like  ntp
433       to  keep your System Time synchronized. (ntp is a way to keep your Sys‐
434       tem Time synchronized either to a time server somewhere on the  network
435       or to a radio clock hooked up to your system.  See RFC 1305).
436
437       This mode (we'll call it "11 minute mode") is off until something turns
438       it on.  The ntp daemon xntpd is one thing that turns it  on.   You  can
439       turn it off by running anything, including hwclock --hctosys, that sets
440       the System Time the old fashioned way.
441
442       To see if it is on or off, use the command adjtimex --print and look at
443       the  value  of  "status".  If the "64" bit of this number (expressed in
444       binary) equal to 0, 11 minute mode is on.  Otherwise, it is off.
445
446       If your system runs with 11 minute mode on, don't use hwclock  --adjust
447       or  hwclock  --hctosys.   You'll just make a mess.  It is acceptable to
448       use a hwclock --hctosys at startup time to get a reasonable System Time
449       until  your  system  is  able  to set the System Time from the external
450       source and start 11 minute mode.
451
452
453

ISA Hardware Clock Century value

455       There is some sort of standard that defines CMOS memory Byte 50  on  an
456       ISA  machine  as  an indicator of what century it is.  hwclock does not
457       use or set that byte because there are some machines that don't  define
458       the  byte  that  way,  and  it really isn't necessary anyway, since the
459       year-of-century does a good job of implying which century it is.
460
461       If you have a bona fide use  for  a  CMOS  century  byte,  contact  the
462       hwclock maintainer; an option may be appropriate.
463
464       Note  that this section is only relevant when you are using the "direct
465       ISA" method of accessing the Hardware Clock.  ACPI provides a  standard
466       way to access century values, when they are supported by the hardware.
467
468

ENVIRONMENT VARIABLES

470       TZ
471
472

FILES

474       /etc/adjtime  /usr/share/zoneinfo/  (/usr/lib/zoneinfo  on old systems)
475       /dev/rtc /dev/rtc0 /dev/port /dev/tty1 /proc/cpuinfo
476
477

SEE ALSO

479       adjtimex(8),  date(1),  gettimeofday(2),  settimeofday(2),  crontab(1),
480       tzset(3)
481
482

AUTHORS

484       Written  by  Bryan Henderson, September 1996 (bryanh@giraffe-data.com),
485       based on work done on the clock program by Charles Hedrick, Rob  Hooft,
486       and  Harald Koenig.  See the source code for complete history and cred‐
487       its.
488
489

AVAILABILITY

491       The hwclock command is part of the util-linux-ng package and is  avail‐
492       able from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
493
494
495
496                                06 August 2008                      HWCLOCK(8)
Impressum