RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1660846 - timedatectl shows NTP synchronized: no, while with ntpstat the server is synchronized
Summary: timedatectl shows NTP synchronized: no, while with ntpstat the server is sync...
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: ntp
Version: 7.6
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: rc
: ---
Assignee: Miroslav Lichvar
QA Contact: qe-baseos-daemons
URL:
Whiteboard:
: 1726671 1785488 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-12-19 11:09 UTC by Markus Schibli
Modified: 2020-03-24 16:52 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-06-27 11:47:46 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 3759171 0 None None None 2018-12-19 11:20:20 UTC

Description Markus Schibli 2018-12-19 11:09:33 UTC
Description of problem:
Customer is running their environment the ntpd in "slew" mode (ntpd -x). With running ntpd in "slew" mode, timedatectl does always show "NTP synchronized: no" while ntpstat correctly show "synchronised to NTP server (10.11.160.238) at stratum 2 "

Version-Release number of selected component (if applicable):
RHEL7.6 
systemd-219-62.el7.x86_64

How reproducible:
remove chrony package, install ntp package, configure ntpd to run in "slew" mode, wait some time to be synchronized, test timedatectl vs. ntpstat


Steps to Reproduce:
1. yum remove chrony
2. yum install ntp
3. vi /etc/sysconfig/ntpd and add -x at the end of the OPTIONS line -> OPTIONS="-g -x" 
4. systemctl enable ntpd.service
5. systemctl start ntpd.service / or / timedatectl set-ntp 1
6. *wait some time to be synchronized*
7. ntpstat
8. timedatectl | grep NTP

Actual results:
# timedatectl | grep NTP
     NTP enabled: yes
NTP synchronized: no

# ntpstat
synchronised to NTP server (10.11.160.238) at stratum 2 
   time correct to within 10 ms
   polling server every 64 s

# ps -wauxxx | grep ntp
ntp       4343  0.0  0.0  29944  2140 ?        Ss   11:33   0:00 /usr/sbin/ntpd -u ntp:ntp -g -x

Expected results:

# timedatectl | grep NTP
     NTP enabled: yes
NTP synchronized: yes

Additional info:
I reproduced the problem on RHEL7.6/7.5/7.3
Customer won't use chrony in the near future.
additional side note, there is another issue with ntpd running in "slew" mode, ntptime returns code 5 (ERROR) which is described in https://access.redhat.com/solutions/38542, which was leading me to the source of this timedatectl issue.

Comment 2 David Tardon 2019-01-23 14:52:02 UTC
The value for "NTP synchronized" is obtained by calling adjtimex() and then checking if the .status field of struct timex contains STA_UNSYNC. I assume it's ntpd that sets/unsets that flag...

Comment 3 Miroslav Lichvar 2019-01-24 08:39:35 UTC
The -x option of ntpd disables the kernel discipline. The kernel doesn't know the system clock is synchronized by ntpd, and cannot report a synchronized status. timedatectl doesn't know anything about ntpd/chronyd and just looks at the kernel status.

This may be unexpected, but it is working as designed.

Comment 4 Miroslav Lichvar 2019-05-22 14:31:20 UTC
One possible solution would be to patch ntpd to use the ntp_adjtime() system function to just set the clock status and not control the clock when the -x option is enabled and ntpd uses adjtime() for controlling the clock.

Comment 6 Miroslav Lichvar 2019-06-26 13:54:28 UTC
Here is a more detailed explanation of how it works:

The kernel maintains an "unsynchronized" flag for the system clock. The timedatectl program from systemd will print "NTP synchronized: yes" only if this flag is cleared (set to zero). It doesn't support the protocol which ntpq and ntpstat use to query the state of ntpd.

ntpd can control the system clock using two different system functions:
- ntp_adjtime() enables a phase-locked loop implemented in the kernel (aka kernel discipline), which automatically corrects the frequency offset of the clock (drift) and it needs to be called only when a new measurement is made. It clears the "unsynchronized" flag in the kernel. The main limitation is that it cannot correct offsets larger than 0.5 seconds.
- adjtime() is an older method, which makes a one-time adjustment of the clock (slew). It doesn't correct the frequency offset, so it needs to be called frequently to compensate for it, even when no measurement is made. It cannot clear the "unsynchronized" flag in the kernel, but it can correct any offset.

ntpd can use ntp_adjtime() or adjtime(), but not both at the same time. By default it uses ntp_adjtime(). If the step threshold is set to a larger value than 0.5 seconds (e.g. by enabling the -x option), it has to switch to adjtime(), because ntp_adjtime() does not work with larger offsets.

That means the kernel "unsynchronized" status will not be cleared and timedatectl will report "NTP synchronized: no" when ntpd is started with the -x option.

Comment 8 RHEL Program Management 2019-06-27 11:47:46 UTC
Development Management has reviewed and declined this request. You may appeal this decision by reopening this request.

Comment 9 David Tardon 2019-07-03 14:12:34 UTC
*** Bug 1726671 has been marked as a duplicate of this bug. ***

Comment 10 Kyle Walker 2020-02-10 19:12:48 UTC
*** Bug 1726671 has been marked as a duplicate of this bug. ***

Comment 11 Martin Pitt 2020-03-24 16:52:48 UTC
*** Bug 1785488 has been marked as a duplicate of this bug. ***


Note You need to log in before you can comment on or make changes to this bug.