Skip to content

Commit

Permalink
SWPTP-1431: always set nic clock on startup by default
Browse files Browse the repository at this point in the history
  • Loading branch information
abower-amd committed Sep 18, 2024
1 parent 0098398 commit a03ee2c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Add `pidadjust` control command to tweak PID controller co-efficients
at runtime for experimental purposes only. Run `sfptpdctl` without
arguments to see syntax. (SWPTP-1411)
- Always set NIC clocks on startup by default. The previous behaviour of
only setting them when not already set or if used as PTP master or with
a freerunning clock instance can be configured. (SWPTP-1431)
- Add Debian packaging. (SWPTP-1446)
- Add `-D` command line option to specify default PTP domain. (SWPTP-1454)
- Add master-only PTP option. (SWPTP-1459)
Expand Down
10 changes: 9 additions & 1 deletion src/include/sfptpd_general_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define SFPTPD_DEFAULT_CLOCK_CTRL (SFPTPD_CLOCK_CTRL_SLEW_AND_STEP)
#define SFPTPD_DEFAULT_STEP_THRESHOLD_NS (SFPTPD_SERVO_CLOCK_STEP_THRESHOLD_S * ONE_BILLION)
#define SFPTPD_DEFAULT_EPOCH_GUARD (SFPTPD_EPOCH_GUARD_CORRECT_CLOCK)
#define SFPTPD_DEFAULT_INITIAL_CLOCK_CORRECTION (SFPTPD_CLOCK_INITIAL_CORRECTION_ALWAYS)
#define SFPTPD_DEFAULT_CLUSTERING_MODE (SFPTPD_CLUSTERING_DISABLED)
#define SFPTPD_DEFAULT_CLUSTERING_SCORE_ABSENT_DISCRIM 1
#define SFPTPD_DEFAULT_CLUSTERING_GUARD (false)
Expand Down Expand Up @@ -98,6 +99,12 @@ enum sfptpd_epoch_guard_config {
SFPTPD_EPOCH_GUARD_CORRECT_CLOCK
};

/** Initial clock correction options */
enum sfptpd_clock_initial_correction {
SFPTPD_CLOCK_INITIAL_CORRECTION_ALWAYS,
SFPTPD_CLOCK_INITIAL_CORRECTION_IF_UNSET,
};

enum clock_config_state {
CLOCK_OPTION_NOT_APPLIED = 0,
CLOCK_OPTION_APPLIED,
Expand Down Expand Up @@ -186,7 +193,7 @@ typedef struct sfptpd_config_timestamping {
* @netlink_rescan_interval: Interval between rescanning interface with netlink
* @pid_filter.kp: Secondary servo PID filter proportional term coefficient
* @pid_filter.ki: Secondary servo PID filter integral term coefficient
* rely on a signal from an external entity via sfptpdctl.
* @initial_clock_correction: When to apply an initial clock correction
*/
typedef struct sfptpd_config_general {
sfptpd_config_section_t hdr;
Expand Down Expand Up @@ -237,6 +244,7 @@ typedef struct sfptpd_config_general {
char json_stats_filename[PATH_MAX];
char json_remote_monitor_filename[PATH_MAX];
enum sfptpd_epoch_guard_config epoch_guard;
enum sfptpd_clock_initial_correction initial_clock_correction;
enum sfptpd_clustering_mode clustering_mode;
enum sfptpd_phc_diff_method phc_diff_methods[SFPTPD_DIFF_METHOD_MAX+1];
char clustering_discriminator_name[SFPTPD_CONFIG_SECTION_NAME_MAX];
Expand Down
10 changes: 8 additions & 2 deletions src/sfptpd_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2343,8 +2343,14 @@ void sfptpd_clock_correct_new(struct sfptpd_clock *clock)
if (rc != 0) {
ERROR("failed to read clock %s time, %s\n",
clock->long_name, strerror(rc));
} else if (time.sec < SFPTPD_NIC_TIME_VALID_THRESHOLD) {
sfptpd_clock_set_time(clock, sfptpd_clock_system, NULL);
} else {
struct sfptpd_config_general *gconf;
gconf = sfptpd_general_config_get(sfptpd_clock_config);

if (time.sec < SFPTPD_NIC_TIME_VALID_THRESHOLD ||
gconf->initial_clock_correction == SFPTPD_CLOCK_INITIAL_CORRECTION_ALWAYS) {
sfptpd_clock_set_time(clock, sfptpd_clock_system, NULL);
}
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/sfptpd_general_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ static int parse_unique_clockid_bits(struct sfptpd_config_section *section, cons
unsigned int num_params, const char * const params[]);
static int parse_legacy_clockids(struct sfptpd_config_section *section, const char *option,
unsigned int num_params, const char * const params[]);
static int parse_initial_clock_correction(struct sfptpd_config_section *section, const char *option,
unsigned int num_params, const char * const params[]);

static int validate_config(struct sfptpd_config_section *section);

Expand Down Expand Up @@ -377,6 +379,10 @@ static const sfptpd_config_option_t config_general_options[] =
"Use legacy 1588-2008 clock ids of the form :::ff:fe:::",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_legacy_clockids,
.dfl = SFPTPD_CONFIG_DFL_BOOL(false)},
{"initial_clock_correction", "<always | if-unset>",
"When to apply an initial clock correction to NIC clocks",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_initial_clock_correction,
.dfl = "Defaults to always"},
};

static const sfptpd_config_option_set_t config_general_option_set =
Expand Down Expand Up @@ -977,6 +983,25 @@ static int parse_epoch_guard(struct sfptpd_config_section *section, const char *
return rc;
}

static int parse_initial_clock_correction(struct sfptpd_config_section *section, const char *option,
unsigned int num_params, const char * const params[])
{
int rc = 0;
sfptpd_config_general_t *general = (sfptpd_config_general_t *)section;

assert(num_params == 1);

if (strcmp(params[0], "always") == 0) {
general->initial_clock_correction = SFPTPD_CLOCK_INITIAL_CORRECTION_ALWAYS;
} else if (strcmp(params[0], "if-unset") == 0) {
general->initial_clock_correction = SFPTPD_CLOCK_INITIAL_CORRECTION_IF_UNSET;
} else {
rc = EINVAL;
}

return rc;
}

static int parse_clock_list(struct sfptpd_config_section *section, const char *option,
unsigned int num_params, const char * const params[])
{
Expand Down Expand Up @@ -1692,6 +1717,7 @@ static struct sfptpd_config_section *general_config_create(const char *name,
new->clocks.discipline_all = SFPTPD_DEFAULT_DISCIPLINE_ALL_CLOCKS;
new->clocks.num_clocks = 0;
new->epoch_guard = SFPTPD_DEFAULT_EPOCH_GUARD;
new->initial_clock_correction = SFPTPD_DEFAULT_INITIAL_CLOCK_CORRECTION;

new->non_sfc_nics = SFPTPD_DEFAULT_NON_SFC_NICS;
new->assume_one_phc_per_nic = SFPTPD_DEFAULT_ASSUME_ONE_PHC_PER_NIC;
Expand Down

0 comments on commit a03ee2c

Please sign in to comment.