Skip to content

Commit

Permalink
ptp4l: Make UTC offset configurable.
Browse files Browse the repository at this point in the history
Currently UTC offset is defined as a constant - CURRENT_UTC_OFFSET, and if
a leap second is added, that constant is no longer valid. Ptp4l was
updated to read the UTC offset from configuration instead.

Signed-off-by: Viliam Lejcik <[email protected]>
  • Loading branch information
Viliam Lejcik authored and richardcochran committed Feb 5, 2017
1 parent b738afb commit 33e62f9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
9 changes: 5 additions & 4 deletions clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct clock {
int leap_set;
int kernel_leap;
int utc_offset; /* grand master role */
int current_utc_offset; /* UTC offset fallback */
int time_flags; /* grand master role */
int time_source; /* grand master role */
enum servo_state servo_state;
Expand Down Expand Up @@ -681,7 +682,7 @@ static void clock_update_slave(struct clock *c)
if (!(c->tds.flags & PTP_TIMESCALE)) {
pr_warning("foreign master not using PTP timescale");
}
if (c->tds.currentUtcOffset < CURRENT_UTC_OFFSET) {
if (c->tds.currentUtcOffset < c->current_utc_offset) {
pr_warning("running in a temporal vortex");
}
}
Expand All @@ -697,10 +698,10 @@ static int clock_utc_correct(struct clock *c, tmv_t ingress)

if (c->tds.flags & UTC_OFF_VALID && c->tds.flags & TIME_TRACEABLE) {
utc_offset = c->tds.currentUtcOffset;
} else if (c->tds.currentUtcOffset > CURRENT_UTC_OFFSET) {
} else if (c->tds.currentUtcOffset > c->current_utc_offset) {
utc_offset = c->tds.currentUtcOffset;
} else {
utc_offset = CURRENT_UTC_OFFSET;
utc_offset = c->current_utc_offset;
}

if (c->tds.flags & LEAP_61) {
Expand Down Expand Up @@ -1035,7 +1036,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
c->freq_est_interval = config_get_int(config, NULL, "freq_est_interval");
c->grand_master_capable = config_get_int(config, NULL, "gmCapable");
c->kernel_leap = config_get_int(config, NULL, "kernel_leap");
c->utc_offset = CURRENT_UTC_OFFSET;
c->utc_offset = c->current_utc_offset = config_get_int(config, NULL, "utc_offset");
c->time_source = config_get_int(config, NULL, "timeSource");

if (c->free_running) {
Expand Down
1 change: 1 addition & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_STR("uds_address", "/var/run/ptp4l"),
GLOB_ITEM_INT("use_syslog", 1, 0, 1),
GLOB_ITEM_STR("userDescription", ""),
GLOB_ITEM_INT("utc_offset", CURRENT_UTC_OFFSET, 0, INT_MAX),
GLOB_ITEM_INT("verbose", 0, 0, 1),
};

Expand Down
1 change: 1 addition & 0 deletions default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ slaveOnly 0
priority1 128
priority2 128
domainNumber 0
#utc_offset 37
clockClass 248
clockAccuracy 0xFE
offsetScaledLogVariance 0xFFFF
Expand Down
1 change: 1 addition & 0 deletions gPTP.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gmCapable 1
priority1 248
priority2 248
domainNumber 0
#utc_offset 37
clockClass 248
clockAccuracy 0xFE
offsetScaledLogVariance 0xFFFF
Expand Down
4 changes: 4 additions & 0 deletions ptp4l.8
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ The default is 0xFFFF.
The domain attribute of the local clock.
The default is 0.
.TP
.B utc_offset
The current offset between TAI and UTC.
The default is 37.
.TP
.B free_running
Don't adjust the local clock if enabled.
The default is 0 (disabled).
Expand Down

0 comments on commit 33e62f9

Please sign in to comment.