]>
git.ipfire.org Git - thirdparty/chrony.git/blob - sys_null.c
2 chronyd/chronyc - Programs for keeping computer clocks accurate.
4 **********************************************************************
5 * Copyright (C) Miroslav Lichvar 2017
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 **********************************************************************
22 =======================================================================
24 Null clock driver for operation with no clock control.
38 /* Current frequency offset of the system clock (in ppm) */
41 /* Offset of the system clock at the last update */
42 static double offset_register
;
44 /* Time of the last update */
45 static struct timespec last_update
;
47 /* Minimum interval between updates when frequency is constant */
48 #define MIN_UPDATE_INTERVAL 1000.0
50 /* ================================================== */
58 LCL_ReadRawTime(&now
);
59 duration
= UTI_DiffTimespecsToDouble(&now
, &last_update
);
60 offset_register
+= 1.0e-6 * freq
* duration
;
63 DEBUG_LOG("System clock offset=%e freq=%f", offset_register
, freq
);
66 /* ================================================== */
74 /* ================================================== */
77 set_frequency(double freq_ppm
)
85 /* ================================================== */
88 accrue_offset(double offset
, double corr_rate
)
90 offset_register
+= offset
;
93 /* ================================================== */
96 apply_step_offset(double offset
)
101 /* ================================================== */
104 offset_convert(struct timespec
*raw
, double *corr
, double *err
)
108 duration
= UTI_DiffTimespecsToDouble(raw
, &last_update
);
110 if (duration
> MIN_UPDATE_INTERVAL
) {
115 *corr
= -1.0e-6 * freq
* duration
- offset_register
;
121 /* ================================================== */
124 SYS_Null_Initialise(void)
126 offset_register
= 0.0;
127 LCL_ReadRawTime(&last_update
);
129 lcl_RegisterSystemDrivers(read_frequency
, set_frequency
, accrue_offset
,
130 apply_step_offset
, offset_convert
, NULL
, NULL
);
132 LOG(LOGS_INFO
, "Disabled control of system clock");
135 /* ================================================== */
138 SYS_Null_Finalise(void)