Linux使用David L. Mills的时钟调整算法(参见RFC 1305)。系统调用adjtimex() 读取并可选地设置此算法的调整参数。它接收指向timex 结构体的指针,根据字段值更新内核参数,并返回包含当前内核值的相同结构体。此结构体声明如下:
struct timex {
int modes; /* mode selector */
long offset; /* time offset (usec) */
long freq; /* frequency offset (scaled ppm) */
long maxerror; /* maximum error (usec) */
long esterror; /* estimated error (usec) */
int status; /* clock command/status */
long constant; /* pll time constant */
long precision; /* clock precision (usec) (read only) */
long tolerance; /* clock frequency tolerance (ppm)
(read only) */
struct timeval time; /* current time (read only) */
long tick; /* usecs between clock ticks */
};
modes字段确定要设置哪些参数(如果有)。它可以包含以下位的按位或组合:
#define ADJ_OFFSET 0x0001 /* time offset */
#define ADJ_FREQUENCY 0x0002 /* frequency offset */
#define ADJ_MAXERROR 0x0004 /* maximum time error */
#define ADJ_ESTERROR 0x0008 /* estimated time error */
#define ADJ_STATUS 0x0010 /* clock status */
#define ADJ_TIMECONST 0x0020 /* pll time constant */
#define ADJ_TICK 0x4000 /* tick value */
#define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime() */
普通用户被限制为mode 的零值。只有超级用户可以设置任何参数。
返回值
成功时,adjtimex() 返回时钟状态。
#define TIME_OK 0 /* clock synchronized */
#define TIME_INS 1 /* insert leap second */
#define TIME_DEL 2 /* delete leap second */
#define TIME_OOP 3 /* leap second in progress */
#define TIME_WAIT 4 /* leap second has occurred */
#define TIME_BAD 5 /* clock not synchronized */