tick/common: Align tick period during sched_timer setup
[platform/kernel/linux-starfive.git] / kernel / time / tick-sched.c
index a46506f..d6fb6a6 100644 (file)
@@ -161,8 +161,19 @@ static ktime_t tick_init_jiffy_update(void)
        raw_spin_lock(&jiffies_lock);
        write_seqcount_begin(&jiffies_seq);
        /* Did we start the jiffies update yet ? */
-       if (last_jiffies_update == 0)
+       if (last_jiffies_update == 0) {
+               u32 rem;
+
+               /*
+                * Ensure that the tick is aligned to a multiple of
+                * TICK_NSEC.
+                */
+               div_u64_rem(tick_next_period, TICK_NSEC, &rem);
+               if (rem)
+                       tick_next_period += TICK_NSEC - rem;
+
                last_jiffies_update = tick_next_period;
+       }
        period = last_jiffies_update;
        write_seqcount_end(&jiffies_seq);
        raw_spin_unlock(&jiffies_lock);