Skip to content

Commit

Permalink
SWPTP-1516: use macro to populate default config help text
Browse files Browse the repository at this point in the history
  • Loading branch information
abower-amd committed Sep 12, 2024
1 parent f5dad04 commit 7c04487
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 93 deletions.
17 changes: 17 additions & 0 deletions src/include/sfptpd_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,21 @@
/** Maximum section name length in config files */
#define SFPTPD_CONFIG_SECTION_NAME_MAX (64)

/** Produce help text for default config value. */
#define SFPTPD_CONFIG_DFL(val) _Generic((val), \
bool: (val) ? "Enabled by default" : "Disabled by default", \
default: "Default is " STRINGIFY(val))

/** Produce help text for default config value with compat for pre-C23
* compilers (can be removed when gcc-10 become baseline) */
#define SFPTPD_CONFIG_DFL_BOOL(val) _Generic((val), \
int: (val) ? "Enabled by default" : "Disabled by default", \
default: SFPTPD_CONFIG_DFL(val))

/** Produce help text for default string config quoted macro values */
#define SFPTPD_CONFIG_DFL_STR(val) _Generic((val), \
char *: "Defaults to " val)

/** Enumeration of different config section categories. */
enum sfptpd_config_category {

Expand Down Expand Up @@ -555,6 +570,8 @@ typedef struct sfptpd_config_option {
enum sfptpd_config_scope scope;
int (*parse)(struct sfptpd_config_section *, const char *option,
unsigned int num_params, const char * const *params);
const char *dfl;
const char *unit;
bool hidden;
bool confidential;
} sfptpd_config_option_t;
Expand Down
3 changes: 2 additions & 1 deletion src/include/sfptpd_general_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define SFPTPD_DEFAULT_STATS_LOG (SFPTPD_STATS_LOG_OFF)
#define SFPTPD_DEFAULT_STATE_PATH SFPTPD_STATE_PATH
#define SFPTPD_DEFAULT_CONTROL_PATH SFPTPD_CONTROL_SOCKET_PATH
#define SFPTPD_DEFAULT_TRACE_LEVEL (0)
#define SFPTPD_DEFAULT_TRACE_LEVEL 0
#define SFPTPD_DEFAULT_SYNC_INTERVAL -4
#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)
Expand All @@ -33,6 +33,7 @@
#define SFPTPD_DEFAULT_CLUSTERING_GUARD (false)
#define SFPTPD_DEFAULT_CLUSTERING_GUARD_THRESHOLD 1
#define SFPTPD_DEFAULT_PERSISTENT_CLOCK_CORRECTION (true)
#define SFPTPD_DEFAULT_DISABLE_ON_EXIT (true)
#define SFPTPD_DEFAULT_DISCIPLINE_ALL_CLOCKS (true)
#define SFPTPD_DEFAULT_NON_SFC_NICS (false)
#define SFPTPD_DEFAULT_ASSUME_ONE_PHC_PER_NIC (false)
Expand Down
15 changes: 10 additions & 5 deletions src/sfptpd_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ static void config_display_help(void)
printf("%s:\n", set->description);

for (j = 0; j < set->num_options; j++) {
if (!set->options[j].hidden) {
printf("%-28s %-30s %s\n",
set->options[j].option,
set->options[j].params,
set->options[j].description);
const sfptpd_config_option_t *opt = set->options + j;
if (!opt->hidden) {
printf("%-28s %-30s %s%s%s%s%s\n",
opt->option,
opt->params,
opt->description,
opt->dfl ? ". " : "",
opt->dfl ? opt->dfl : "",
opt->dfl && opt->unit ? " " : "",
opt->dfl && opt->unit ? opt->unit : "");
}
}

Expand Down
191 changes: 104 additions & 87 deletions src/sfptpd_general_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,103 +150,115 @@ static const sfptpd_config_option_t config_general_options[] =
parse_phc_pps_methods},
{"selection_holdoff_interval", "NUMBER",
"Specifies how long to wait after detecting a better instance "
"before selecting it. Default is "
STRINGIFY(SFPTPD_DEFAULT_SELECTION_HOLDOFF_INTERVAL) " seconds.",
"before selecting it",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_selection_holdoff_interval},
parse_selection_holdoff_interval,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_DEFAULT_SELECTION_HOLDOFF_INTERVAL),
.unit = "seconds"},
{"message_log", "<syslog | stderr | filename>",
"Specifies where to send messages generated by the application. By default messages are sent to stderr",
"Specifies where to send messages generated by the application",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_message_log},
parse_message_log,
.dfl = "By default messages are sent to stderr"},
{"stats_log", "<off | stdout | filename>",
"Specifies if and where to log statistics generated by the application. By default statistics logging is disabled",
"Specifies if and where to log statistics generated by the application",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_stats_log},
parse_stats_log,
.dfl = "By default statistics logging is disabled"},
{"user", "USER [GROUP]",
"Drop to the user and group named USER and GROUP retaining "
"essential capabilities. Group defaults to USER's if not "
"specified",
~1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_user},
{"daemon", "",
"Run as a daemon. Disabled by default",
"Run as a daemon.",
0, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_daemon},
parse_daemon,
.dfl = "Disabled by default"},
{"lock", "<off | on>",
"Specify whether to use a lock file to stop multiple simultaneous instances of the daemon. Enabled by default",
"Specify whether to use a lock file to stop multiple simultaneous instances of the daemon",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_lock},
parse_lock,
.dfl = "Enabled by default"},
{"state_path", "<path>",
"Directory in which to store sfptpd state data. Defaults to " SFPTPD_DEFAULT_STATE_PATH,
"Directory in which to store sfptpd state data",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_state_path},
parse_state_path,
.dfl = SFPTPD_CONFIG_DFL_STR(SFPTPD_DEFAULT_STATE_PATH)},
{"control_path", "<path>",
"Path for Unix domain control socket. Defaults to " SFPTPD_DEFAULT_CONTROL_PATH,
"Path for Unix domain control socket",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_control_path},
parse_control_path,
.dfl = SFPTPD_CONFIG_DFL_STR(SFPTPD_DEFAULT_CONTROL_PATH)},
{"sync_interval", "NUMBER",
"Specifies the interval in 2^NUMBER seconds at which the clocks "
"are synchronized to the local reference clock, where NUMBER is "
"in the range ["
STRINGIFY(SFPTPD_MIN_SYNC_INTERVAL) ","
STRINGIFY(SFPTPD_MAX_SYNC_INTERVAL) "]. The default is "
STRINGIFY(SFPTPD_DEFAULT_SYNC_INTERVAL) ".",
STRINGIFY(SFPTPD_MAX_SYNC_INTERVAL) "]",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_sync_interval},
parse_sync_interval,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_DEFAULT_SYNC_INTERVAL)},
{"local_sync_threshold", "NUMBER",
"Threshold in nanoseconds of the offset between the system clock and a NIC clock over a "
STRINGIFY(SFPTPD_STATS_CONVERGENCE_MIN_PERIOD_DEFAULT)
"s period to be considered in sync (converged). The default is "
STRINGIFY(SFPTPD_STATS_CONVERGENCE_MAX_OFFSET_DEFAULT) ".",
"s period to be considered in sync",
1, SFPTPD_CONFIG_SCOPE_INSTANCE,
parse_sync_threshold},
parse_sync_threshold,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_STATS_CONVERGENCE_MAX_OFFSET_DEFAULT)},
{"clock_control", "<slew-and-step | step-at-startup | no-step | no-adjust | step-forward | step-on-first-lock>",
"Specifies how the clocks are controlled. By default clocks are stepped and slewed as necessary",
"Specifies how the clocks are controlled",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_clock_control},
parse_clock_control,
.dfl = "By default clocks are stepped and slewed as necessary"},
{"step_threshold", "NUMBER",
"Threshold in seconds of the offset between the clock and its reference clock for sfptpd to step. The default is "
STRINGIFY(SFPTPD_SERVO_CLOCK_STEP_THRESHOLD_S) ".",
"Threshold in seconds of the offset between the clock and its reference clock for sfptpd to step.",
1, SFPTPD_CONFIG_SCOPE_INSTANCE,
parse_step_threshold},
parse_step_threshold,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_SERVO_CLOCK_STEP_THRESHOLD_S)},
{"epoch_guard", "<alarm-only | prevent-sync | correct-clock>",
"Guards against propagation of times near the epoch. The default is correct-clock",
"Guards against propagation of times near the epoch",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_epoch_guard},
parse_epoch_guard,
.dfl = "The default is correct-clock"},
{"clock_list", "[<name | mac-address | clock-id | ifname>]*",
"Specifies the set of clocks that sfptpd should discipline. By default all clocks are disciplined",
"Specifies the set of clocks that sfptpd should discipline",
~0, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_clock_list},
parse_clock_list,
.dfl = "By default all clocks are disciplined"},
{"clock_readonly", "[<name | mac-address | clock-id | ifname>]",
"Specifies a set of clocks that sfptpd should never step or slew, under any circumstance. Use with care.",
~1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_clock_readonly},
{"persistent_clock_correction", "<off | on>",
"Specifies whether to used saved clock frequency corrections when disciplining clocks. Enabled by default",
"Specifies whether to used saved clock frequency corrections when disciplining clocks",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_persistent_clock_correction},
parse_persistent_clock_correction,
.dfl = SFPTPD_CONFIG_DFL_BOOL(SFPTPD_DEFAULT_PERSISTENT_CLOCK_CORRECTION)},
{"non_solarflare_nics", "<off | on>",
"Specify whether to use timestamping and hardware clock "
"capabilities of non-Solarflare adapters. Disabled by default",
"capabilities of non-Solarflare adapters",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_non_solarflare_nics},
parse_non_solarflare_nics,
.dfl = SFPTPD_CONFIG_DFL_BOOL(SFPTPD_DEFAULT_NON_SFC_NICS)},
{"non_xilinx_nics", "<off | on>",
"Specify whether to use timestamping and hardware clock "
"capabilities of non-Xilinx adapters. Disabled by default",
"Alias for non_solarflace_nics",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_non_solarflare_nics,
.hidden = true},
{"assume_one_phc_per_nic", "<off | on>",
"Specify whether multiple reported clock devices on a NIC "
"should be assumed to represent the same underlying clock. "
"Enabled by default",
"should be assumed to represent the same underlying clock",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_assume_one_phc_per_nic},
parse_assume_one_phc_per_nic,
.dfl = SFPTPD_CONFIG_DFL_BOOL(SFPTPD_DEFAULT_ASSUME_ONE_PHC_PER_NIC)},
{"avoid_efx_ioctl", "<off | on>",
"Specify whether to avoid private SIOCEFX ioctl for Solarflare "
"adapters where possible. Disabled by default",
"adapters where possible",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_avoid_efx_ioctl,
.dfl = SFPTPD_CONFIG_DFL_BOOL(false),
.hidden = true},
{"phc_diff_methods", "<sys-offset-precise | efx | pps | sys-offset-ext | sys-offset | read-time>*",
"Define the list of PHC diff methods used",
Expand All @@ -259,60 +271,65 @@ static const sfptpd_config_option_t config_general_options[] =
{"timestamping_disable_on_exit", "<off | on>",
"Specifies whether timestamping should be disabled when daemon exits",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_timestamping_disable_on_exit},
parse_timestamping_disable_on_exit,
.dfl = SFPTPD_CONFIG_DFL_BOOL(SFPTPD_DEFAULT_DISABLE_ON_EXIT)},
{"pid_filter_p", "NUMBER",
"Secondary servo PID filter proportional term coefficient. Default value is "
STRINGIFY(SFPTPD_DEFAULT_SERVO_K_PROPORTIONAL) ".",
"Secondary servo PID filter proportional term coefficient",
1, SFPTPD_CONFIG_SCOPE_INSTANCE,
parse_pid_filter_kp},
parse_pid_filter_kp,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_DEFAULT_SERVO_K_PROPORTIONAL)},
{"pid_filter_i", "NUMBER",
"Secondary servo PID filter integral term coefficient. Default value is "
STRINGIFY(SFPTPD_DEFAULT_SERVO_K_INTEGRAL) ".",
"Secondary servo PID filter integral term coefficient",
1, SFPTPD_CONFIG_SCOPE_INSTANCE,
parse_pid_filter_ki},
parse_pid_filter_ki,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_DEFAULT_SERVO_K_INTEGRAL)},
{"trace_level", "[<general | threading | bic | netlink | ntp | servo | clocks>] NUMBER",
"Specifies a module trace level, if built with trace enabled. If module name is omitted, will set the 'general' module trace level. Default is 0 - no trace",
"Specifies a module (of 'general' if omitted) trace level from 0 (none) to 6 (excessive)",
~1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_trace_level},
parse_trace_level,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_DEFAULT_TRACE_LEVEL)},
{"test_mode", "",
"Enables features to aid testing. Disabled by default",
"Enables features to aid testing",
0, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_test_mode,
.dfl = SFPTPD_CONFIG_DFL_BOOL(SFPTPD_DEFAULT_TEST_MODE),
.hidden = true},
{"json_stats", "<filename>",
"Output realtime module statistics in JSON-lines format to this file (http://jsonlines.org). Disabled by default.",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_json_stats},
"Output realtime module statistics in JSON-lines format to this file (http://jsonlines.org)",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_json_stats,
.dfl = "Disabled by default"},
{"json_remote_monitor", "<filename>",
"Output realtime information collected by the PTP remote monitor in "
"JSON-lines format to this file (http://jsonlines.org). "
"Disabled by default. DEPRECATED since v3.7.0.",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_json_remote_monitor},
"Write JSON lines to this file for data collected by the PTP "
"remote monitor (which is DEPRECATED in favour of sfptpmon)",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_json_remote_monitor,
.dfl = "Disabled by default"},
{"hotplug_detection_mode", "<netlink | auto>",
"Deprecated option to configure how the daemon should detect "
"hotplug insertion and removal of interfaces and bond changes. "
"Netlink is used exclusively for this now and any other option "
"is ignored.",
"obsolete option to control how interface and bond changes are "
"detected. The option value is ignored and netlink used.",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_hotplug_detection_mode},
{"reporting_intervals", "<save_state|stats_log INTERVAL>*",
"Specifies period between saving state files and/or writing "
"stats log output. Default is: \"save_state "
STRINGIFY(SFPTPD_DEFAULT_STATE_SAVE_INTERVAL) " stats_log "
STRINGIFY(SFPTPD_DEFAULT_STATISTICS_LOGGING_INTERVAL) "\"",
"stats log output",
~2, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_reporting_intervals},
parse_reporting_intervals,
.dfl = "Default is: \"save_state "
STRINGIFY(SFPTPD_DEFAULT_STATE_SAVE_INTERVAL) " stats_log "
STRINGIFY(SFPTPD_DEFAULT_STATISTICS_LOGGING_INTERVAL) "\""},
{"netlink_rescan_interval", "NUMBER",
"Specifies period between rescanning the link table with netlink. "
"Periodic rescans are disabled with zero. Default is "
STRINGIFY(SFPTPD_DEFAULT_NETLINK_RESCAN_INTERVAL) " seconds.",
"Periodic rescans are disabled with zero",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_netlink_rescan_interval},
parse_netlink_rescan_interval,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_DEFAULT_NETLINK_RESCAN_INTERVAL),
.unit = "seconds"},
{"netlink_coalesce_ms", "NUMBER",
"Specifies period after a significant change is communicated "
"by netlink to wait for further changes to avoid excessive "
"perturbation. Coalescing is disabled with zero. Default is "
STRINGIFY(SFPTPD_DEFAULT_NETLINK_COALESCE_MS) " ms.",
"perturbation. Coalescing is disabled with zero",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_netlink_coalesce_ms},
parse_netlink_coalesce_ms,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_DEFAULT_NETLINK_COALESCE_MS),
.unit = "ms"},
{"clustering", "discriminator <INSTANCE> <THRESHOLD> <NO_DISCRIMINATOR_SCORE>",
"Implements clustering based on MODE. Currently only supports "
"discriminator mode, which disqualifies sync instances that differ "
Expand All @@ -334,32 +351,32 @@ static const sfptpd_config_option_t config_general_options[] =
"or diagnostic use cases.",
~1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_ignore_critical},
{"rtc_adjust", "<off | on>",
"Specify whether to let the kernel sync the RTC clock. "
"Enabled by default",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_rtc_adjust},
"Specify whether to let the kernel sync the RTC clock",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_rtc_adjust,
.dfl = SFPTPD_CONFIG_DFL_BOOL(SFPTPD_DEFAULT_RTC_ADJUST)},
{"clock_display_fmts", "SHORT-FMT LONG-FMT HWID-FMT FNAM-FMT",
"Define formats for displaying clock properties, "
"of max expansion "
STRINGIFY(SFPTPD_CLOCK_SHORT_NAME_SIZE) ", "
STRINGIFY(SFPTPD_CLOCK_FULL_NAME_SIZE) ", "
STRINGIFY(SFPTPD_CLOCK_HW_ID_STRING_SIZE) " and "
STRINGIFY(SFPTPD_CLOCK_HW_ID_STRING_SIZE) " respectively. "
"Default is "
SFPTPD_DEFAULT_CLOCK_SHORT_FMT " "
SFPTPD_DEFAULT_CLOCK_LONG_FMT " "
SFPTPD_DEFAULT_CLOCK_HWID_FMT " "
SFPTPD_DEFAULT_CLOCK_FNAM_FMT ".",
4, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_clock_display_fmts},
STRINGIFY(SFPTPD_CLOCK_HW_ID_STRING_SIZE) " respectively. ",
4, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_clock_display_fmts,
.dfl = "Default is "
SFPTPD_DEFAULT_CLOCK_SHORT_FMT " "
SFPTPD_DEFAULT_CLOCK_LONG_FMT " "
SFPTPD_DEFAULT_CLOCK_HWID_FMT " "
SFPTPD_DEFAULT_CLOCK_FNAM_FMT "."},
{"unique_clockid_bits", "<OCTETS | pid | hostid | rand>",
"Colon-delimited octets providing the unique bits that pad the "
"LSBs of an EUI-64 clock identity constructed from an EUI-48 "
"MAC address. Default is "
SFPTPD_DEFAULT_UNIQUE_CLOCKID_BITS ".",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_unique_clockid_bits},
"MAC address",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_unique_clockid_bits,
.dfl = SFPTPD_CONFIG_DFL_STR(SFPTPD_DEFAULT_UNIQUE_CLOCKID_BITS)},
{"legacy_clockids", "<off | on>",
"Use legacy 1588-2008 clock ids of the form :::ff:fe:::. "
"Default is off.",
1, SFPTPD_CONFIG_SCOPE_GLOBAL, parse_legacy_clockids},
"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)},
};

static const sfptpd_config_option_set_t config_general_option_set =
Expand Down Expand Up @@ -1684,7 +1701,7 @@ static struct sfptpd_config_section *general_config_create(const char *name,
new->rtc_adjust = SFPTPD_DEFAULT_RTC_ADJUST;

new->timestamping.all = false;
new->timestamping.disable_on_exit = true;
new->timestamping.disable_on_exit = SFPTPD_DEFAULT_DISABLE_ON_EXIT;
new->timestamping.num_interfaces = 0;

new->convergence_threshold = 0.0;
Expand Down

0 comments on commit 7c04487

Please sign in to comment.