Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/time: add leap seconds to initial system time

The PTFF instruction can be used to retrieve information about UTC
including the current number of leap seconds. Use this value to
convert the coordinated server time value of the TOD clock to a
proper UTC timestamp to initialize the system time. Without this
correction the system time will be off by the number of leap seonds
until it has been corrected via NTP.

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

+33 -2
+18
arch/s390/include/asm/timex.h
··· 56 56 57 57 extern unsigned char ptff_function_mask[16]; 58 58 extern unsigned long lpar_offset; 59 + extern unsigned long initial_leap_seconds; 59 60 60 61 /* Function codes for the ptff instruction. */ 61 62 #define PTFF_QAF 0x00 /* query available functions */ 62 63 #define PTFF_QTO 0x01 /* query tod offset */ 63 64 #define PTFF_QSI 0x02 /* query steering information */ 65 + #define PTFF_QUI 0x04 /* query UTC information */ 64 66 #define PTFF_ATO 0x40 /* adjust tod offset */ 65 67 #define PTFF_STO 0x41 /* set tod offset */ 66 68 #define PTFF_SFS 0x42 /* set fine steering rate */ ··· 83 81 ptr = ptff_function_mask + (nr >> 3); 84 82 return (*ptr & (0x80 >> (nr & 7))) != 0; 85 83 } 84 + 85 + /* Query UTC information result */ 86 + struct ptff_qui { 87 + unsigned int tm : 2; 88 + unsigned int ts : 2; 89 + unsigned int : 28; 90 + unsigned int pad_0x04; 91 + unsigned long leap_event; 92 + short old_leap; 93 + short new_leap; 94 + unsigned int pad_0x14; 95 + unsigned long prt[5]; 96 + unsigned long cst[3]; 97 + unsigned int skew; 98 + unsigned int pad_0x5c[41]; 99 + } __packed; 86 100 87 101 static inline int ptff(void *ptff_block, size_t len, unsigned int func) 88 102 {
+15 -2
arch/s390/kernel/time.c
··· 64 64 65 65 unsigned char ptff_function_mask[16]; 66 66 unsigned long lpar_offset; 67 + unsigned long initial_leap_seconds; 67 68 68 69 /* 69 70 * Get time offsets with PTFF ··· 72 71 void __init ptff_init(void) 73 72 { 74 73 struct ptff_qto qto; 74 + struct ptff_qui qui; 75 75 76 76 if (!test_facility(28)) 77 77 return; ··· 81 79 /* get LPAR offset */ 82 80 if (ptff_query(PTFF_QTO) && ptff(&qto, sizeof(qto), PTFF_QTO) == 0) 83 81 lpar_offset = qto.tod_epoch_difference; 82 + 83 + /* get initial leap seconds */ 84 + if (ptff_query(PTFF_QUI) && ptff(&qui, sizeof(qui), PTFF_QUI) == 0) 85 + initial_leap_seconds = (unsigned long) 86 + ((long) qui.old_leap * 4096000000L); 84 87 } 85 88 86 89 /* ··· 207 200 208 201 void read_persistent_clock64(struct timespec64 *ts) 209 202 { 210 - tod_to_timeval(get_tod_clock() - TOD_UNIX_EPOCH, ts); 203 + __u64 clock; 204 + 205 + clock = get_tod_clock() - initial_leap_seconds; 206 + tod_to_timeval(clock - TOD_UNIX_EPOCH, ts); 211 207 } 212 208 213 209 void read_boot_clock64(struct timespec64 *ts) 214 210 { 215 - tod_to_timeval(sched_clock_base_cc - TOD_UNIX_EPOCH, ts); 211 + __u64 clock; 212 + 213 + clock = sched_clock_base_cc - initial_leap_seconds; 214 + tod_to_timeval(clock - TOD_UNIX_EPOCH, ts); 216 215 } 217 216 218 217 static cycle_t read_tod_clock(struct clocksource *cs)