⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hwclock.8

📁 Util-linux 软件包包含许多工具。其中比较重要的是加载、卸载、格式化、分区和管理硬盘驱动器
💻 8
📖 第 1 页 / 共 2 页
字号:
.B The Hardware Clock: This is a clock that runs independently of any control program runningin the CPU and even when the machine is powered off.On an ISA system, this clock is specified as part of the ISA standard.The control program can read or set this clock to a whole second, butthe control program can also detect the edges of the 1 second clockticks, so the clock actually has virtually infinite precision..PPThis clock is commonly called the hardware clock, the real time clock,the RTC, the BIOS clock, and the CMOS clock.  Hardware Clock, in itscapitalized form, was coined for use by .B hwclock because all of the other names are inappropriate to the point of beingmisleading..PP.B The System Time: This is the time kept by a clock inside the Linux kernel and driven bya timer interrupt.  (On an ISA machine, the timer interrupt is part ofthe ISA standard).  It has meaning only while Linux is running on themachine.  The System Time is the number of seconds since 00:00:00January 1, 1970 UTC (or more succinctly, the number of seconds since1969).  The System Time is not an integer, though.  It has virtuallyinfinite precision..PPThe System Time is the time that matters.  The Hardware Clock's basicpurpose in a Linux system is to keep time when Linux is not running.  Youinitialize the System Time to the time from the Hardware Clock when Linuxstarts up, and then never use the Hardware Clock again.  Note that in DOS,for which ISA was designed, the Hardware Clock is the only real time clock..PPIt is important that the System Time not have any discontinuities such aswould happen if you used the .BR date (1L)program to set it while the system is running.  You can, however, do whateveryou want to the Hardware Clock while the system is running, and the nexttime Linux starts up, it will do so with the adjusted time from the HardwareClock.  You can also use the program .BR adjtimex (8)to smoothly adjust the System Time while the system runs..PPA Linux kernel maintains a concept of a local timezone for the system.But don't be misled -- almost nobody cares what timezone the kernelthinks it is in.  Instead, programs that care about the timezone(perhaps because they want to display a local time for you) almostalways use a more traditional method of determining the timezone: Theyuse the TZ environment variable and/or the /usr/local/timezonedirectory, as explained in the man page for tzset(3).  However, someprograms and fringe parts of the Linux kernel such as filesystems usethe kernel timezone value.  An example is the vfat filesystem.  If thekernel timezone value is wrong, the vfat filesystem will report andset the wrong timestamps on files..PP.B hwclocksets the kernel timezone to the value indicated by TZ and/or/usr/local/timezone when you set the System Time using the .B \-\-hctosysoption..PPThe timezone value actually consists of two parts: 1) a fieldtz_minuteswest indicating how many minutes local time (not adjustedfor DST) lags behind UTC, and 2) a field tz_dsttime indicatingthe type of Daylight Savings Time (DST) convention that is in effectin the locality at the present time.This second field is not used under Linux and is always zero.(See also.BR settimeofday (2).).SH How hwclock Accesses the Hardware Clock.PP.B hwclock Uses many different ways to get and set Hardware Clock values.The most normal way is to do I/O to the device special file /dev/rtc,which is presumed to be driven by the rtc device driver.  However,this method is not always available.  For one thing, the rtc driver isa relatively recent addition to Linux.  Older systems don't have it.Also, though there are versions of the rtc driver that work on DECAlphas, there appear to be plenty of Alphas on which the rtc driverdoes not work (a common symptom is hwclock hanging)..PPOn older systems, the method of accessing the Hardware Clock depends onthe system hardware. .PPOn an ISA system, .B hwclock can directly access the "CMOS memory" registers thatconstitute the clock, by doing I/O to Ports 0x70 and 0x71.  It doesthis with actual I/O instructions and consequently can only do it ifrunning with superuser effective userid.  (In the case of a JensenAlpha, there is no way for.B hwclock to execute those I/O instructions, and so it uses instead the/dev/port device special file, which provides almost as low-level aninterface to the I/O subsystem).This is a really poor method of accessing the clock, for all thereasons that user space programs are generally not supposed to dodirect I/O and disable interrupts.  Hwclock provides it because it isthe only method available on ISA and Alpha systems which don't haveworking rtc device drivers available..PPOn an m68k system,.B hwclockcan access the clock via the console driver, via the device specialfile /dev/tty1..PP.B hwclock tries to use /dev/rtc.  If it is compiled for a kernel that doesn't havethat function or it is unable to open /dev/rtc, .B hwclock will fall back to another method, if available.  On an ISA or Alphamachine, you can force.B hwclockto use the direct manipulation of the CMOS registers without even trying.I /dev/rtcby specifying the \-\-directisa option..SH The Adjust Function.PPThe Hardware Clock is usually not very accurate.  However, much of itsinaccuracy is completely predictable - it gains or loses the same amountof time every day.  This is called systematic drift..BR hwclock 's "adjust" function lets you make systematic corrections to correct thesystematic drift..PPIt works like this:  .B hwclock keeps a file,.I /etc/adjtime,that keeps some historical information.  This is called the adjtime file..PPSuppose you start with no adjtime file.  You issue a .I hwclock \-\-setcommand to set the Hardware Clock to the true current time.  .B Hwclock creates the adjtime file and records in it the current time as the last time the clock was calibrated.5 days later, the clock has gained 10 seconds, so you issue another.I hwclock \-\-setcommand to set it back 10 seconds.  .B Hwclock updates the adjtime file to show the current time as the last time theclock was calibrated, and records 2 seconds per day as the systematicdrift rate.  24 hours go by, and then you issue a.I hwclock \-\-adjustcommand.  .B Hwclock consults the adjtime file and sees that the clock gains 2 seconds perday when left alone and that it has been left alone for exactly oneday.  So it subtracts 2 seconds from the Hardware Clock.  It thenrecords the current time as the last time the clock was adjusted.Another 24 hours goes by and you issue another.I hwclock \-\-adjust..B Hwclock does the same thing: subtracts 2 seconds and updates the adjtime filewith the current time as the last time the clock was adjusted..PPEvery time you calibrate (set) the clock (using .I \-\-setor.I \-\-systohc),.B hwclock recalculates the systematic drift rate based on how long it has beensince the last calibration, how long it has been since the lastadjustment, what drift rate was assumed in any interveningadjustments, and the amount by which the clock is presently off..PPA small amount of error creeps in any time .B hwclock sets the clock, so it refrains from making an adjustment that would beless than 1 second.  Later on, when you request an adjustment again,the accumulated drift will be more than a second and.B hwclock will do the adjustment then..PPIt is good to do a .I hwclock \-\-adjustjust before the .I hwclock \-\-hctosysat system startup time, and maybe periodically while the system isrunning via cron..PPThe adjtime file, while named for its historical purpose of controllingadjustments only, actually contains other information for use by hwclockin remembering information from one invocation to the next..PPThe format of the adjtime file is, in ASCII:.PPLine 1: 3 numbers, separated by blanks: 1) systematic drift rate inseconds per day, floating point decimal; 2) Resulting number ofseconds since 1969 UTC of most recent adjustment or calibration,decimal integer; 3) zero (for compatibility with.BR clock (8))as a decimal integer..PPLine 2: 1 number: Resulting number of seconds since 1969 UTC of mostrecent calibration.  Zero if there has been no calibration yet or itis known that any previous calibration is moot (for example, becausethe Hardware Clock has been found, since that calibration, not to contain a valid time).  This is a decimal integer..PPLine 3: "UTC" or "LOCAL".  Tells whether the Hardware Clock is set to Coordinated Universal Time or local time.  You can always override thisvalue with options on the .B hwclockcommand line..PPYou can use an adjtime file that was previously used with the .BR clock (8)program with .B hwclock..SH "Automatic Hardware Clock Synchronization By the Kernel"You should be aware of another way that the Hardware Clock is kept synchronized in some systems.  The Linux kernel has a mode wherein itcopies the System Time to the Hardware Clock every 11 minutes.  This is a good mode to use when you are using something sophisticatedlike ntp to keep your System Time synchronized. (ntp is a way to keepyour System Time synchronized either to a time server somewhere on thenetwork or to a radio clock hooked up to your system.  See RFC 1305).This mode (we'll call it "11 minute mode") is off until somethingturns it on.  The ntp daemon xntpd is one thing that turns it on.  Youcan turn it off by running anything, including.IR "hwclock \-\-hctosys" ,that sets the System Time the old fashioned way.To see if it is on oroff, use the command .I adjtimex \-\-printand look at the value of "status".  If the "64" bit of this number(expressed in binary) equal to 0, 11 minute mode is on.  Otherwise, itis off.If your system runs with 11 minute mode on, don't use .I hwclock \-\-adjustor.IR "hwclock \-\-hctosys" .You'll just make a mess.  It is acceptable to use a.I hwclock \-\-hctosys at startup time to get a reasonable System Time until your system isable to set the System Time from the external source and start 11minute mode..SH ISA Hardware Clock Century valueThere is some sort of standard that defines CMOS memory Byte 50 on an ISAmachine as an indicator of what century it is.  .B hwclockdoes not use or set that byte because there are some machines thatdon't define the byte that way, and it really isn't necessary anyway,since the year-of-century does a good job of implying which century itis.If you have a bona fide use for a CMOS century byte, contact the .B hwclockmaintainer; an option may be appropriate.Note that this section is only relevant when you are using the "directISA" method of accessing the Hardware Clock..SH "ENVIRONMENT VARIABLES".I TZ.SH FILES.I /etc/adjtime.I /usr/share/zoneinfo/.RI ( /usr/lib/zoneinfoon old systems).I /dev/rtc.I /dev/port.I /dev/tty1.I /proc/cpuinfo.SH "SEE ALSO".BR adjtimex (8),.BR date (1),.BR gettimeofday (2),.BR settimeofday (2),.BR crontab (1),.BR tzset (3).SH AUTHORSWritten by Bryan Henderson, September 1996 (bryanh@giraffe-data.com),based on work done on the.I clockprogram by Charles Hedrick, Rob Hooft, and Harald Koenig.  See the source code for complete history and credits.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -