Skip to content

Commit 2c620ff

Browse files
deepa-hubarndb
authored andcommitted
time: Add struct __kernel_timex
struct timex uses struct timeval internally. struct timeval is not y2038 safe. Introduce a new UAPI type struct __kernel_timex that is y2038 safe. struct __kernel_timex uses a timeval type that is similar to struct __kernel_timespec which preserves the same structure size across 32 bit and 64 bit ABIs. struct __kernel_timex also restructures other members of the structure to make the structure the same on 64 bit and 32 bit architectures. Note that struct __kernel_timex is the same as struct timex on a 64 bit architecture. The above solution is similar to other new y2038 syscalls that are being introduced: both 32 bit and 64 bit ABIs have a common entry, and the compat entry supports the old 32 bit syscall interface. Alternatives considered were: 1. Add new time type to struct timex that makes use of padded bits. This time type could be based on the struct __kernel_timespec. modes will use a flag to notify which time structure should be used internally. This needs some application level changes on both 64 bit and 32 bit architectures. Although 64 bit machines could continue to use the older timeval structure without any changes. 2. Add a new u8 type to struct timex that makes use of padded bits. This can be used to save higher order tv_sec bits. modes will use a flag to notify presence of such a type. This will need some application level changes on 32 bit architectures. 3. Add a new compat_timex structure that differs in only the size of the time type; keep rest of struct timex the same. This requires extra syscalls to manage all 3 cases on 64 bit architectures. This will not need any application level changes but will add more complexity from kernel side. Signed-off-by: Deepa Dinamani <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]>
1 parent 4d5f007 commit 2c620ff

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

include/linux/timex.h

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
#ifndef _LINUX_TIMEX_H
5454
#define _LINUX_TIMEX_H
5555

56+
/* CONFIG_64BIT_TIME enables new 64 bit time_t syscalls in the compat path
57+
* and 32-bit emulation.
58+
*/
59+
#ifndef CONFIG_64BIT_TIME
60+
#define __kernel_timex timex
61+
#endif
62+
5663
#include <uapi/linux/timex.h>
5764

5865
#define ADJ_ADJTIME 0x8000 /* switch between adjtime/adjtimex modes */

include/uapi/linux/timex.h

+41
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,47 @@ struct timex {
9292
int :32; int :32; int :32;
9393
};
9494

95+
struct __kernel_timex_timeval {
96+
__kernel_time64_t tv_sec;
97+
long long tv_usec;
98+
};
99+
100+
#ifndef __kernel_timex
101+
struct __kernel_timex {
102+
unsigned int modes; /* mode selector */
103+
int :32; /* pad */
104+
long long offset; /* time offset (usec) */
105+
long long freq; /* frequency offset (scaled ppm) */
106+
long long maxerror;/* maximum error (usec) */
107+
long long esterror;/* estimated error (usec) */
108+
int status; /* clock command/status */
109+
int :32; /* pad */
110+
long long constant;/* pll time constant */
111+
long long precision;/* clock precision (usec) (read only) */
112+
long long tolerance;/* clock frequency tolerance (ppm)
113+
* (read only)
114+
*/
115+
struct __kernel_timex_timeval time; /* (read only, except for ADJ_SETOFFSET) */
116+
long long tick; /* (modified) usecs between clock ticks */
117+
118+
long long ppsfreq;/* pps frequency (scaled ppm) (ro) */
119+
long long jitter; /* pps jitter (us) (ro) */
120+
int shift; /* interval duration (s) (shift) (ro) */
121+
int :32; /* pad */
122+
long long stabil; /* pps stability (scaled ppm) (ro) */
123+
long long jitcnt; /* jitter limit exceeded (ro) */
124+
long long calcnt; /* calibration intervals (ro) */
125+
long long errcnt; /* calibration errors (ro) */
126+
long long stbcnt; /* stability limit exceeded (ro) */
127+
128+
int tai; /* TAI offset (ro) */
129+
130+
int :32; int :32; int :32; int :32;
131+
int :32; int :32; int :32; int :32;
132+
int :32; int :32; int :32;
133+
};
134+
#endif
135+
95136
/*
96137
* Mode codes (timex.mode)
97138
*/

0 commit comments

Comments
 (0)