Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions drivers/rtc/rtc-macsmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ static int macsmc_rtc_probe(struct platform_device *pdev)
rtc->offset_in_seconds = of_property_read_bool(pdev->dev.of_node,
"apple,rtc-offset-seconds");

/*
* Free-running counter + nvmem offset, not a post-write tick-up RTC.
* The class default (1s + 5 ms) shrinks rtc_tv_nsec_ok to the edge fuzz
* and makes sync_hw_clock retry constantly. Use a half-second systohc
* phase window like CMOS, not a transport-time offset.
*/
rtc->rtc_dev->set_offset_nsec = NSEC_PER_SEC / 2;

rtc->rtc_dev->ops = &macsmc_rtc_ops;
ret = macsmc_rtc_init_alarm(pdev, rtc);
if (ret == -EPROBE_DEFER)
Expand Down
20 changes: 17 additions & 3 deletions kernel/time/ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,12 +747,26 @@ static enum hrtimer_restart sync_timer_callback(struct hrtimer *timer)

static void sched_sync_hw_clock(unsigned long offset_nsec, bool retry)
{
ktime_t exp = ktime_set(ktime_get_real_seconds(), 0);
ktime_t now = ktime_get_real();
ktime_t exp;

if (retry)
exp = ktime_add_ns(exp, 2ULL * NSEC_PER_SEC - offset_nsec);
exp = ktime_add_ns(ktime_set(ktime_get_real_seconds(), 0),
2ULL * NSEC_PER_SEC - offset_nsec);
else
exp = ktime_add_ns(exp, SYNC_PERIOD_NS - offset_nsec);
exp = ktime_add_ns(now, SYNC_PERIOD_NS - offset_nsec);

/* sync_hrtimer is CLOCK_REALTIME; compare and arm in the same base. */
if (ktime_compare(exp, now) <= 0) {
if (retry) {
exp = ktime_add_ns(ktime_set(ktime_get_real_seconds() + 1, 0),
2ULL * NSEC_PER_SEC - offset_nsec);
if (ktime_compare(exp, now) <= 0)
exp = ktime_add_ns(now, NSEC_PER_MSEC);
} else {
exp = ktime_add_ns(now, NSEC_PER_MSEC);
}
}

hrtimer_start(&sync_hrtimer, exp, HRTIMER_MODE_ABS);
}
Expand Down
Loading