Skip to content

Commit

Permalink
SWPTP-1506: use smoothed ntp offset from chronyd
Browse files Browse the repository at this point in the history
  • Loading branch information
abower-amd committed Oct 17, 2024
1 parent 97ea442 commit 51bdd14
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Fixed

- Issue SWPTP-1506
- chrony: use smoothed offset from chrony not last NTP sample
- Issue SWPTP-1531
- freerun: fix resolution of bond when VLAN specified

Expand Down
15 changes: 8 additions & 7 deletions src/crny/sfptpd_crny_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ static void ntp_convergence_init(crny_module_t *ntp)
sfptpd_stats_convergence_set_max_offset(&ntp->convergence, threshold);
}


static bool ntp_convergence_update(crny_module_t *ntp, struct ntp_state *new_state)
{
struct sfptpd_timespec time;
Expand Down Expand Up @@ -580,7 +579,7 @@ static bool ntp_convergence_update(crny_module_t *ntp, struct ntp_state *new_sta
* from master */
new_state->synchronized = sfptpd_stats_convergence_update(&ntp->convergence,
time.sec,
peer->offset);
sfptpd_ntpclient_offset(peer));
}

return new_state->synchronized != ntp->state.synchronized;
Expand Down Expand Up @@ -656,7 +655,8 @@ void crny_stats_update(crny_module_t *ntp)
assert(ntp->state.selected_peer_idx < ntp->state.peer_info.num_peers);
peer = &ntp->state.peer_info.peers[ntp->state.selected_peer_idx];
/* Offset, frequency correction, one-way-delay */
sfptpd_stats_collection_update_range(stats, NTP_STATS_ID_OFFSET, peer->offset,
sfptpd_stats_collection_update_range(stats, NTP_STATS_ID_OFFSET,
sfptpd_ntpclient_offset(peer),
ntp->state.offset_timestamp, true);
} else {
struct sfptpd_timespec now;
Expand Down Expand Up @@ -742,8 +742,8 @@ void crny_parse_state(struct ntp_state *state, int rc, bool offset_unsafe)
peer = &state->peer_info.peers[state->selected_peer_idx];

state->state = SYNC_MODULE_STATE_SLAVE;
state->offset_from_master = peer->offset;
state->root_dispersion = peer->root_dispersion;
state->offset_from_master = sfptpd_ntpclient_offset(peer);
state->root_dispersion = sfptpd_ntpclient_error(peer);
state->stratum = peer->stratum;
} else {
state->state = candidates?
Expand Down Expand Up @@ -2012,7 +2012,8 @@ static void ntp_on_save_state(crny_module_t *ntp, sfptpd_sync_module_msg_t *msg)
SFPTPD_CONFIG_GET_NAME(ntp->config),
sfptpd_clock_get_long_name(clock),
crny_state_text(ntp->state.state, 0),
alarms, constraints, flags, peer->offset,
alarms, constraints, flags,
sfptpd_ntpclient_offset(peer),
ntp->state.synchronized,
host,
ntp->state.peer_info.num_peers,
Expand Down Expand Up @@ -2092,7 +2093,7 @@ static void ntp_on_write_topology(crny_module_t *ntp, sfptpd_sync_module_msg_t *
sfptpd_log_topology_write_field(stream, true, "%s", host);
sfptpd_log_topology_write_1to1_connector(stream, false, true,
SFPTPD_FORMAT_TOPOLOGY_FLOAT,
peer->offset);
sfptpd_ntpclient_offset(peer));
break;

default:
Expand Down
20 changes: 20 additions & 0 deletions src/include/sfptpd_ntpd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,24 @@ sfptpd_ntpclient_get_features(struct sfptpd_ntpclient *container);
void sfptpd_ntpclient_print_peers(struct sfptpd_ntpclient_peer_info *peer_info,
const char *subsystem);

/* Get best estimate of offset to NTP peer
* @param peer the peer info object
* @return the offset in ns
*/
static inline sfptpd_time_t sfptpd_ntpclient_offset(struct sfptpd_ntpclient_peer *peer)
{
return isnormal(peer->smoothed_offset) ? peer->smoothed_offset : peer->offset;
}


/* Get best estimate of error for NTP peer
* @param peer the peer info object
* @return the offset in ns
*/
static inline sfptpd_time_t sfptpd_ntpclient_error(struct sfptpd_ntpclient_peer *peer)
{
return isnormal(peer->smoothed_root_dispersion) ? peer->smoothed_root_dispersion : peer->root_dispersion;
}


#endif /* _SFPTPD_NTPD_CLIENT_H */

0 comments on commit 51bdd14

Please sign in to comment.