Bug 1448822 - glibc: Add definition of CLOCK_TAI
Summary: glibc: Add definition of CLOCK_TAI
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: glibc
Version: 7.4
Hardware: All
OS: Linux
Target Milestone: rc
: ---
Assignee: Florian Weimer
QA Contact: Sergey Kolosov
Vladimír Slávik
Depends On:
Blocks: 1420851 1473718
TreeView+ depends on / blocked
Reported: 2017-05-08 09:58 UTC by Daniele
Modified: 2021-06-10 12:17 UTC (History)
8 users (show)

Fixed In Version: glibc-2.17-209.el7
Doc Type: Enhancement
Doc Text:
TAI clock macro available Previously, the kernel provided the `CLOCK_TAI` clock, but the `CLOCK_TAI` macro to access it was missing in the *glibc* header file `time.h`. The macro definition has been added to the header file. As a result, applications can now access the `CLOCK_TAI` kernel clock.
Clone Of:
Last Closed: 2018-04-10 13:58:28 UTC
Target Upstream Version:

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2018:0805 0 None None None 2018-04-10 14:00:11 UTC
Sourceware 17608 0 None None None 2019-04-08 12:58:48 UTC

Description Daniele 2017-05-08 09:58:38 UTC
Description of problem:
While CLOCK_TAI is supported by the kernel, it seems not to be supported by glibc yet.

As of now, the customer has to add

#ifndef CLOCK_TAI
# define CLOCK_TAI 11

after the inclusion of <time.h>, to get a usable definition.

Additional info:
According the following document CLOCK_TAI is supported by RHEL7:  https://developers.redhat.com/blog/2015/06/01/five-different-ways-handle-leap-seconds-ntp/

The following is mentioned in the article:
"For applications where it would be possible to work with TAI time instead of UTC, the kernel provides a special CLOCK_TAI clock which does include leap seconds and doesn’t need to be corrected after leap second, avoiding the problem with backward jump in the time entirely. It’s implemented as a clock running at a fixed integral offset to CLOCK_REALTIME, which is atomically incremented by 1 when the CLOCK_REALTIME clock is stepped back on leap second. It was introduced in the Linux kernel version 3.10 and is available with the kernels shipped in RHEL7. "

So according the article CLOCK_TAI should be available.

Unfortunately the following code fails to compile:
[root@host2 ~]# cat test.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main()
   struct timespec ts_realtime;
   struct timespec ts_tai;

   clock_gettime(CLOCK_REALTIME, &ts_realtime);
   clock_gettime(CLOCK_TAI, &ts_tai);

   printf("Realtime: %lld.%.9ld\n", (long long)ts_realtime.tv_sec, ts_realtime.tv_nsec);
   printf("TAI: %lld.%.9ld\n", (long long)ts_tai.tv_sec, ts_tai.tv_nsec);

[root@host2 ~]# gcc -lrt test.c  -o test
test.c: In function ‘main’:
test.c:12:18: error: ‘CLOCK_TAI’ undeclared (first use in this function)
    clock_gettime(CLOCK_TAI, &ts_tai);
test.c:12:18: note: each undeclared identifier is reported only once for each function it appears in

So CLOCK_TAI is not recognized.
Used kernel:
[root@host2 ~]# uname -a
Linux host2 3.10.0-514.16.1.el7.x86_64 #1 SMP Fri Mar 10 13:12:32 EST 2017 x86_64 x86_64 x86_64 GNU/Linux

[root@host2 ~]# rpm -qa | grep glibc

Comment 16 errata-xmlrpc 2018-04-10 13:58:28 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.