Wind River Support Network

HomeSafety and Security NoticesNew leap second 2016-12-31 23:59:60 UTC handling in WRLinux
Recommended

New leap second 2016-12-31 23:59:60 UTC handling in WRLinux

Released: Nov 17, 2016     Updated: Nov 27, 2016

Summary

The leap second handling in WRLinux


Affected Product Versions

Wind River Linux 5, Wind River Linux 6, Wind River Linux 7, Wind River Linux 8

Downloads


Description

Introduction

Leap seconds are a periodic one-second adjustment of Coordinated Universal Time(UTC) in order to keep a system's time of day close to the mean solar time. However, the Earth's rotation speed varies in response to climatic and geological events, and due to this, UTC leap seconds are irregularly spaced and unpredictable. This article seeks to provide information regarding the leap seconds themselves, along with addressing how Wind River Linux handles the insertion of one.

Upcoming Leap Second Events

The next leap second will occur on 2016 December 31, 23h 59m 60s UTC. The full announcement may be found at the http://datacenter.iers.org/eop/-/somos/5Rgv/latest/16

Environment

Wind River Linux 5
Wind River Linux 6
Wind River Linux 7
Wind River Linux 8

Handling of the Leap Second

The handling of this issue depends on whether or not the Linux system is running a NTP (Network Time Protocol) or PTP (Precision Time Protocol) daemon.

Systems running NTP

Systems should automatically account for leap second corrections if they are using the NTP (Network Time Protocol) daemon to synchronize their local timekeeping with an NTP server. During the last day before a leap second correction, NTP servers should notify their clients that a leap second will occur, and at 23:59:59 UTC, the Linux kernel should add or remove an extra second by making the 60th second occur twice or removing it entirely. Thus, Linux systems running an NTP client during the last leap second correction should have counted time as follows:

2008-12-31 23:59:59:052549000 UTC <-- 1st occurrence of the 60th second
2008-12-31 23:59:59:259988000 UTC
2008-12-31 23:59:59:465214000 UTC
2008-12-31 23:59:59:669629000 UTC
2008-12-31 23:59:59:873936000 UTC
2008-12-31 23:59:59:079184000 UTC <-- 2nd occurrence of the 60th second
2008-12-31 23:59:59:284011000 UTC
2008-12-31 23:59:59:488648000 UTC
2008-12-31 23:59:59:692691000 UTC
2008-12-31 23:59:59:896577000 UTC
2009-01-01 00:00:00:052378000 UTC

Systems running PTP

The timestamps exchanged in PTP are typically in TAI (International Atomic Time) which does not contain leap seconds; however, ptp4l and phc2sys will set the kernel flag to insert a leap second as the system clock continues to run in UTC. The kernel will then insert the leap second as normal.

Systems not running NTP or PTP

For systems not synchronized by ntpd or ptp an updated tzdatapackage that contains the December 31st leap second is required. So, You can configure systems to report time corrected for leap seconds by updating the zdata package to the latest version available and resetting the clock to the correct local time.

Known Issues

A ntp issue LIN5-21922/LIN6-11743/LIN7-6769:

a) Description:
Using -x with ntp still results in instantaneous clock changes when leap second occurs; this issue is documented in http://bugs.ntp.org/show_bug.cgi?id=2745
b) WRLinux Affected Version:
WRLinux 5.0.1/6.0/7.0 and all RCPLs are INVULNERABLE.
c) Hot Fix
There are two ways to avoid the issue, one is to upgrade ntp to newest by using --with-template=feature/ntp428p8 to create project. If you would not like to use the newest version, the second way is to apply a hot patch on old ntp by following:

$cd  layers/meta-networking
$git am 0001-ntpd-x-steps-clock-on-leapsecond.patch
$cd ../../build
$make ntp.distclean
$make ntp
$cd ../
$make fs

d) Official release
We will ship the patches in WRLinux 5.0.1.38/6.0.0.31/7.0.0.20.



A kernel issue LIN5-20592/LIN6-10064/LIN7-4116/LIN8-4699:

a) Description:

Absolute timers may fire early when the leap second is inserted; this issue is documented in https://lwn.net/Articles/648313/

b) WRLinux Affected Version:

WRLinux 5.0.1/6.0/7.0/8.0 and all RCPLs are VULNERABLE.

c) Hot Fix

WRLinux5.0 : 
Upgrading to WRLinux 5.0.1.37. 
$cd /build/linux-windriver-3.4-r0/linux
$git am 0005-time-Prevent-early-expiry-of-hrtimers-CLOCK_REALTIME.patch 
$cd ../../
$make linux-windriver.rebuild

WRLinux6.0 : 
Upgrading to  WRL6.0.0.30
$cd build/lbuild/linux-windriver/linux
$git am 0006-time-Prevent-early-expiry-of-hrtimers-CLOCK_REALTIME.patch 
$cd ../../
$make linux-windriver.rebuild

WRLinux7.0 : 
Upgrading to WRL 7.0.0.19
$cd build/linux-windriver/linux--standard-build/source
$git am 0007-time-Prevent-early-expiry-of-hrtimers-CLOCK_REALTIME.patch 
$cd ../../
$make linux-windriver.rebuild


WRLinux8.0 : 
Upgrading to WRL 8.0.0.0.9
$cd build/linux-windriver/linux--standard-build/source
$git am 0008-time-Prevent-early-expiry-of-hrtimers-CLOCK_REALTIME.patch 
$cd ../../
$make linux-windriver.rebuild

e) Official release

We will ship the patches in WRLinux 5.0.1.38/6.0.0.31/7.0.0.20/8.0.0.10.

f) Test

Download the test case from

gcc -o reproducer leapsecond-test.c -lrt

Run the test case on the target board, Without the kernel patch, test case will print contents in test buffer and shows 
“ERROR: timer expired before we trigger the timekeeping timer”

with the above kernel patch, test case will print “Test Pass!”.

Other packages needed to updated.

Besides kernel and ntp, the Time Zone Data and Code has been released to handle the incoming leap second. We will upgrade the verion 2016g in WRLinux 5.0.1.38/6.0.0.31/7.0.0.21/8.0.0.11. The release date of each RCPL is:

Verification for Time Zone:

UTC
$cp /usr/share/zoneinfo/right/UTC /etc/localtime
$date --date='2016-12-32 23:59:60'

(Without the patch)
date: invalid date `2016-12-31 23:59:60'
(With the patch)
Sat Dec 31 23:59:60 UTC 2016

Other timezones, for example China or Japan

For Japan:
$cp /usr/share/zoneinfo/right/Japan /etc/localtime

For China:
$cp /usr/share/zoneinfo/right/Asia/Shanghai /etc/localtime


Run the timezone.py on the target:

(Without the patch)
$./timezone.py
1972-07-01 00:00:00
1973-01-01 00:00:00
...
2009-01-01 00:00:00
2012-07-01 00:00:00
2015-07-01 00:00:00

(With the patch)
$./timezone.py
1972-07-01 00:00:00
1973-01-01 00:00:00
...
2009-01-01 00:00:00
2012-07-01 00:00:00
2016-12-31 00:00:00 (New insert)

Live chat
Online