Skip to content

Commit

Permalink
Add options to not apply leap seconds in kernel.
Browse files Browse the repository at this point in the history
Add kernel_leap option for ptp4l and -x option for phc2sys to disable
setting of the STA_INS/STA_DEL bit to slowly correct the one-second
offset by servo.

Signed-off-by: Miroslav Lichvar <[email protected]>
  • Loading branch information
mlichvar authored and richardcochran committed Mar 20, 2013
1 parent e21af97 commit 4e24248
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 3 deletions.
5 changes: 4 additions & 1 deletion clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct clock {
int freq_est_interval;
int utc_timescale;
int leap_set;
int kernel_leap;
enum servo_state servo_state;
tmv_t master_offset;
tmv_t path_delay;
Expand Down Expand Up @@ -498,7 +499,8 @@ static int clock_utc_correct(struct clock *c, tmv_t ingress)
clock_leap = leap_second_status(ts, c->leap_set,
&leap, &utc_offset);
if (c->leap_set != clock_leap) {
clockadj_set_leap(c->clkid, clock_leap);
if (c->kernel_leap)
clockadj_set_leap(c->clkid, clock_leap);
c->leap_set = clock_leap;
}
}
Expand Down Expand Up @@ -559,6 +561,7 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count,

c->free_running = dds->free_running;
c->freq_est_interval = dds->freq_est_interval;
c->kernel_leap = dds->kernel_leap;
c->desc = dds->clock_desc;

if (c->free_running) {
Expand Down
5 changes: 5 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ static enum parser_result parse_global_setting(const char *option,
return BAD_VALUE;
cfg->dds.stats_interval = val;

} else if (!strcmp(option, "kernel_leap")) {
if (1 != sscanf(value, "%d", &val))
return BAD_VALUE;
cfg->dds.kernel_leap = val;

} else
return NOT_PARSED;

Expand Down
1 change: 1 addition & 0 deletions default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tx_timestamp_retries 100
use_syslog 1
verbose 0
summary_interval 0
kernel_leap 1
#
# Servo Options
#
Expand Down
1 change: 1 addition & 0 deletions ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct default_ds {
int free_running;
int freq_est_interval; /*log seconds*/
int stats_interval; /*log seconds*/
int kernel_leap;
struct clock_description clock_desc;
};

Expand Down
1 change: 1 addition & 0 deletions gPTP.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tx_timestamp_retries 100
use_syslog 1
verbose 0
summary_interval 0
kernel_leap 1
#
# Servo options
#
Expand Down
9 changes: 9 additions & 0 deletions phc2sys.8
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ phc2sys \- synchronize two clocks
] [
.B \-w
] [
.B \-x
] [
.BI \-l " print-level"
] [
.B \-m
Expand Down Expand Up @@ -127,6 +129,13 @@ option is not used, also keep the offset between the slave and master
times updated according to the currentUtcOffset value obtained from ptp4l and
the direction of the clock synchronization.
.TP
.B \-x
When a leap second is announced, don't apply it in the kernel by stepping the
clock, but let the servo correct the one-second offset slowly by changing the
clock frequency (unless the
.B \-S
option is used).
.TP
.BI \-l " print-level"
Set the maximum syslog level of messages which should be printed or sent to
the system logger. The default is 6 (LOG_INFO).
Expand Down
10 changes: 8 additions & 2 deletions phc2sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ struct clock {
int sync_offset_direction;
int leap;
int leap_set;
int kernel_leap;
struct pmc *pmc;
int pmc_ds_idx;
int pmc_ds_requested;
Expand Down Expand Up @@ -500,7 +501,7 @@ static int update_sync_offset(struct clock *clock, int64_t offset, uint64_t ts)

if (clock->leap_set != clock_leap) {
/* Only the system clock can leap. */
if (clock->clkid == CLOCK_REALTIME)
if (clock->clkid == CLOCK_REALTIME && clock->kernel_leap)
clockadj_set_leap(clock->clkid, clock_leap);
clock->leap_set = clock_leap;
}
Expand All @@ -525,6 +526,7 @@ static void usage(char *progname)
" -O [offset] slave-master time offset (0)\n"
" -u [num] number of clock updates in summary stats (0)\n"
" -w wait for ptp4l\n"
" -x apply leap seconds by servo instead of kernel\n"
" -h prints this message and exits\n"
" -v prints the software version and exits\n"
"\n",
Expand All @@ -542,6 +544,7 @@ int main(int argc, char *argv[])
struct clock dst_clock = {
.clkid = CLOCK_REALTIME,
.servo_state = SERVO_UNLOCKED,
.kernel_leap = 1,
};

configured_pi_kp = KP;
Expand All @@ -551,7 +554,7 @@ int main(int argc, char *argv[])
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
while (EOF != (c = getopt(argc, argv,
"c:d:hs:P:I:S:R:N:O:i:u:wl:mqv"))) {
"c:d:hs:P:I:S:R:N:O:i:u:wxl:mqv"))) {
switch (c) {
case 'c':
dst_clock.clkid = clock_open(optarg);
Expand Down Expand Up @@ -596,6 +599,9 @@ int main(int argc, char *argv[])
case 'w':
wait_sync = 1;
break;
case 'x':
dst_clock.kernel_leap = 0;
break;
case 'l':
print_level = atoi(optarg);
break;
Expand Down
8 changes: 8 additions & 0 deletions ptp4l.8
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ empty string.
.B manufacturerIdentity
The manufacturer id which should be an OUI owned by the manufacturer.
The default is 00:00:00.
.TP
.B kernel_leap
When a leap second is announced, let the kernel apply it by stepping the clock
instead of correcting the one-second offset with servo, which would correct the
one-second offset slowly by changing the clock frequency (unless the
.B pi_offset_const
option is set to correct such offset by stepping).
Relevant only with software time stamping. The default is 1 (enabled).

.SH SEE ALSO
.BR pmc (8),
Expand Down
1 change: 1 addition & 0 deletions ptp4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static struct config cfg_settings = {
.free_running = 0,
.freq_est_interval = 1,
.stats_interval = 0,
.kernel_leap = 1,
.clock_desc = {
.productDescription = {
.max_symbols = 64,
Expand Down

0 comments on commit 4e24248

Please sign in to comment.