Skip to content

Commit

Permalink
Clock Class Threshold Feature addition for PTP4L
Browse files Browse the repository at this point in the history
This code changes brings in the ability to program the acceptable
clockClass threshold beyond which device will move to holdover/free-run.
Default clockClass threshold is 248.
Example Use-Case:
This is needed in the cases where T-SC/T-BC Slave might want to listen
only on PRC clockCLass and anything beyond that might not be acceptible
and would want to go to holdover (with SyncE backup or internal oscillator).

Signed-off-by: Karthikkumar V <[email protected]>
Signed-off-by: Ramana Reddy <[email protected]>
  • Loading branch information
Karthikkumar V authored and richardcochran committed Feb 26, 2021
1 parent 9633ab5 commit f774703
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct clock {
int utc_offset;
int time_flags; /* grand master role */
int time_source; /* grand master role */
UInteger8 clock_class_threshold;
UInteger8 max_steps_removed;
enum servo_state servo_state;
enum timestamp_type timestamping;
Expand Down Expand Up @@ -978,6 +979,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
c->default_dataset.localPriority =
config_get_int(config, NULL, "G.8275.defaultDS.localPriority");
c->max_steps_removed = config_get_int(config, NULL,"maxStepsRemoved");
c->clock_class_threshold = config_get_int(config, NULL, "clock_class_threshold");

/* Harmonize the twoStepFlag with the time_stamping option. */
if (config_harmonize_onestep(config)) {
Expand Down Expand Up @@ -1711,6 +1713,11 @@ UInteger8 clock_max_steps_removed(struct clock *c)
return c->max_steps_removed;
}

UInteger8 clock_get_clock_class_threshold(struct clock *c)
{
return c->clock_class_threshold;
}

UInteger16 clock_steps_removed(struct clock *c)
{
return c->cur.stepsRemoved;
Expand Down
7 changes: 7 additions & 0 deletions clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ int clock_slave_only(struct clock *c);
*/
UInteger8 clock_max_steps_removed(struct clock *c);

/**
* Obtain the clock class threshold field from a clock's default data set.
* @param c The clock instance.
* @return Configured clock class threshold value.
*/
UInteger8 clock_get_clock_class_threshold(struct clock *c);

/**
* Obtain the steps removed field from a clock's current data set.
* @param c The clock instance.
Expand Down
1 change: 1 addition & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX),
GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
GLOB_ITEM_STR("clockIdentity", "000000.0000.000000"),
GLOB_ITEM_INT("clock_class_threshold", CLOCK_CLASS_THRESHOLD_DEFAULT, 6, CLOCK_CLASS_THRESHOLD_DEFAULT),
GLOB_ITEM_ENU("clock_servo", CLOCK_SERVO_PI, clock_servo_enu),
GLOB_ITEM_ENU("clock_type", CLOCK_TYPE_ORDINARY, clock_type_enu),
GLOB_ITEM_ENU("dataset_comparison", DS_CMP_IEEE1588, dataset_comp_enu),
Expand Down
1 change: 1 addition & 0 deletions configs/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ verbose 0
summary_interval 0
kernel_leap 1
check_fup_sync 0
clock_class_threshold 248
#
# Servo Options
#
Expand Down
1 change: 1 addition & 0 deletions ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct parent_ds {

#define CURRENT_UTC_OFFSET 37 /* 1 Jan 2017 */
#define INTERNAL_OSCILLATOR 0xA0
#define CLOCK_CLASS_THRESHOLD_DEFAULT 248

struct timePropertiesDS {
Integer16 currentUtcOffset;
Expand Down
8 changes: 8 additions & 0 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,14 @@ int process_announce(struct port *p, struct ptp_message *m)
return result;
}

if (m->announce.grandmasterClockQuality.clockClass >
clock_get_clock_class_threshold(p->clock)) {
pl_err(60, "%s: Master clock quality received is "
"greater than configured, ignoring master!",
p->log_name);
return result;
}

switch (p->state) {
case PS_INITIALIZING:
case PS_FAULTY:
Expand Down
5 changes: 5 additions & 0 deletions ptp4l.8
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ message is greater than or equal to the value of maxStepsRemoved the
Announce message is not considered in the operation of the BMCA.
The default value is 255.
.TP
.B clock_class_threshold
The maximum clock class value from master, acceptible to sub-ordinate
clock beyond which it moves out of lock state.
The default value is 248.
.TP

.B domainNumber
The domain attribute of the local clock.
Expand Down

0 comments on commit f774703

Please sign in to comment.