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

Configure Feed

Select the types of activity you want to include in your feed.

timekeeping: Make timekeeping_inject_offset() reusable

Split out the inner workings for auxiliary clock support and feed the core time
keeper into it.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
Link: https://lore.kernel.org/all/20250625183758.059934561@linutronix.de

+15 -11
+15 -11
kernel/time/timekeeping.c
··· 1433 1433 1434 1434 /** 1435 1435 * __timekeeping_inject_offset - Adds or subtracts from the current time. 1436 + * @tkd: Pointer to the timekeeper to modify 1436 1437 * @ts: Pointer to the timespec variable containing the offset 1437 1438 * 1438 1439 * Adds or subtracts an offset value from the current time. 1439 1440 */ 1440 - static int __timekeeping_inject_offset(const struct timespec64 *ts) 1441 + static int __timekeeping_inject_offset(struct tk_data *tkd, const struct timespec64 *ts) 1441 1442 { 1442 - struct timekeeper *tks = &tk_core.shadow_timekeeper; 1443 + struct timekeeper *tks = &tkd->shadow_timekeeper; 1443 1444 struct timespec64 tmp; 1444 1445 1445 1446 if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC) 1446 1447 return -EINVAL; 1447 - 1448 1448 1449 1449 timekeeping_forward_now(tks); 1450 1450 ··· 1452 1452 tmp = timespec64_add(tk_xtime(tks), *ts); 1453 1453 if (timespec64_compare(&tks->wall_to_monotonic, ts) > 0 || 1454 1454 !timespec64_valid_settod(&tmp)) { 1455 - timekeeping_restore_shadow(&tk_core); 1455 + timekeeping_restore_shadow(tkd); 1456 1456 return -EINVAL; 1457 1457 } 1458 1458 1459 1459 tk_xtime_add(tks, ts); 1460 1460 tk_set_wall_to_mono(tks, timespec64_sub(tks->wall_to_monotonic, *ts)); 1461 - timekeeping_update_from_shadow(&tk_core, TK_UPDATE_ALL); 1461 + timekeeping_update_from_shadow(tkd, TK_UPDATE_ALL); 1462 1462 return 0; 1463 1463 } 1464 1464 ··· 1467 1467 int ret; 1468 1468 1469 1469 scoped_guard (raw_spinlock_irqsave, &tk_core.lock) 1470 - ret = __timekeeping_inject_offset(ts); 1470 + ret = __timekeeping_inject_offset(&tk_core, ts); 1471 1471 1472 1472 /* Signal hrtimers about time change */ 1473 1473 if (!ret) ··· 2568 2568 */ 2569 2569 int do_adjtimex(struct __kernel_timex *txc) 2570 2570 { 2571 + struct tk_data *tkd = &tk_core; 2571 2572 struct timespec64 delta, ts; 2572 2573 struct audit_ntp_data ad; 2573 2574 bool offset_set = false; ··· 2586 2585 ktime_get_real_ts64(&ts); 2587 2586 add_device_randomness(&ts, sizeof(ts)); 2588 2587 2589 - scoped_guard (raw_spinlock_irqsave, &tk_core.lock) { 2590 - struct timekeeper *tks = &tk_core.shadow_timekeeper; 2588 + scoped_guard (raw_spinlock_irqsave, &tkd->lock) { 2589 + struct timekeeper *tks = &tkd->shadow_timekeeper; 2591 2590 s32 orig_tai, tai; 2591 + 2592 + if (!tks->clock_valid) 2593 + return -ENODEV; 2592 2594 2593 2595 if (txc->modes & ADJ_SETOFFSET) { 2594 2596 delta.tv_sec = txc->time.tv_sec; 2595 2597 delta.tv_nsec = txc->time.tv_usec; 2596 2598 if (!(txc->modes & ADJ_NANO)) 2597 2599 delta.tv_nsec *= 1000; 2598 - ret = __timekeeping_inject_offset(&delta); 2600 + ret = __timekeeping_inject_offset(tkd, &delta); 2599 2601 if (ret) 2600 2602 return ret; 2601 2603 ··· 2611 2607 2612 2608 if (tai != orig_tai) { 2613 2609 __timekeeping_set_tai_offset(tks, tai); 2614 - timekeeping_update_from_shadow(&tk_core, TK_CLOCK_WAS_SET); 2610 + timekeeping_update_from_shadow(tkd, TK_CLOCK_WAS_SET); 2615 2611 clock_set = true; 2616 2612 } else { 2617 2613 tk_update_leap_state_all(&tk_core); ··· 2619 2615 2620 2616 /* Update the multiplier immediately if frequency was set directly */ 2621 2617 if (txc->modes & (ADJ_FREQUENCY | ADJ_TICK)) 2622 - clock_set |= __timekeeping_advance(&tk_core, TK_ADV_FREQ); 2618 + clock_set |= __timekeeping_advance(tkd, TK_ADV_FREQ); 2623 2619 } 2624 2620 2625 2621 if (txc->modes & ADJ_SETOFFSET)