@@ -169,6 +169,8 @@ static ktime_t tick_init_jiffy_update(void)
169169 return period ;
170170}
171171
172+ #define MAX_STALLED_JIFFIES 5
173+
172174static void tick_sched_do_timer (struct tick_sched * ts , ktime_t now )
173175{
174176 int cpu = smp_processor_id ();
@@ -196,6 +198,21 @@ static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now)
196198 if (tick_do_timer_cpu == cpu )
197199 tick_do_update_jiffies64 (now );
198200
201+ /*
202+ * If jiffies update stalled for too long (timekeeper in stop_machine()
203+ * or VMEXIT'ed for several msecs), force an update.
204+ */
205+ if (ts -> last_tick_jiffies != jiffies ) {
206+ ts -> stalled_jiffies = 0 ;
207+ ts -> last_tick_jiffies = READ_ONCE (jiffies );
208+ } else {
209+ if (++ ts -> stalled_jiffies == MAX_STALLED_JIFFIES ) {
210+ tick_do_update_jiffies64 (now );
211+ ts -> stalled_jiffies = 0 ;
212+ ts -> last_tick_jiffies = READ_ONCE (jiffies );
213+ }
214+ }
215+
199216 if (ts -> inidle )
200217 ts -> got_idle_tick = 1 ;
201218}
@@ -768,7 +785,7 @@ static inline bool local_timer_softirq_pending(void)
768785
769786static ktime_t tick_nohz_next_event (struct tick_sched * ts , int cpu )
770787{
771- u64 basemono , next_tick , next_tmr , next_rcu , delta , expires ;
788+ u64 basemono , next_tick , delta , expires ;
772789 unsigned long basejiff ;
773790 unsigned int seq ;
774791
@@ -791,7 +808,7 @@ static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu)
791808 * minimal delta which brings us back to this place
792809 * immediately. Lather, rinse and repeat...
793810 */
794- if (rcu_needs_cpu (basemono , & next_rcu ) || arch_needs_cpu () ||
811+ if (rcu_needs_cpu () || arch_needs_cpu () ||
795812 irq_work_needs_cpu () || local_timer_softirq_pending ()) {
796813 next_tick = basemono + TICK_NSEC ;
797814 } else {
@@ -802,10 +819,8 @@ static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu)
802819 * disabled this also looks at the next expiring
803820 * hrtimer.
804821 */
805- next_tmr = get_next_timer_interrupt (basejiff , basemono );
806- ts -> next_timer = next_tmr ;
807- /* Take the next rcu event into account */
808- next_tick = next_rcu < next_tmr ? next_rcu : next_tmr ;
822+ next_tick = get_next_timer_interrupt (basejiff , basemono );
823+ ts -> next_timer = next_tick ;
809824 }
810825
811826 /*
@@ -984,6 +999,45 @@ static void tick_nohz_full_update_tick(struct tick_sched *ts)
984999 __tick_nohz_full_update_tick (ts , ktime_get ());
9851000}
9861001
1002+ /*
1003+ * A pending softirq outside an IRQ (or softirq disabled section) context
1004+ * should be waiting for ksoftirqd to handle it. Therefore we shouldn't
1005+ * reach here due to the need_resched() early check in can_stop_idle_tick().
1006+ *
1007+ * However if we are between CPUHP_AP_SMPBOOT_THREADS and CPU_TEARDOWN_CPU on the
1008+ * cpu_down() process, softirqs can still be raised while ksoftirqd is parked,
1009+ * triggering the below since wakep_softirqd() is ignored.
1010+ *
1011+ */
1012+ static bool report_idle_softirq (void )
1013+ {
1014+ static int ratelimit ;
1015+ unsigned int pending = local_softirq_pending ();
1016+
1017+ if (likely (!pending ))
1018+ return false;
1019+
1020+ /* Some softirqs claim to be safe against hotplug and ksoftirqd parking */
1021+ if (!cpu_active (smp_processor_id ())) {
1022+ pending &= ~SOFTIRQ_HOTPLUG_SAFE_MASK ;
1023+ if (!pending )
1024+ return false;
1025+ }
1026+
1027+ if (ratelimit < 10 )
1028+ return false;
1029+
1030+ /* On RT, softirqs handling may be waiting on some lock */
1031+ if (!local_bh_blocked ())
1032+ return false;
1033+
1034+ pr_warn ("NOHZ tick-stop error: local softirq work is pending, handler #%02x!!!\n" ,
1035+ pending );
1036+ ratelimit ++ ;
1037+
1038+ return true;
1039+ }
1040+
9871041static bool can_stop_idle_tick (int cpu , struct tick_sched * ts )
9881042{
9891043 /*
@@ -1010,17 +1064,8 @@ static bool can_stop_idle_tick(int cpu, struct tick_sched *ts)
10101064 if (need_resched ())
10111065 return false;
10121066
1013- if (unlikely (local_softirq_pending ())) {
1014- static int ratelimit ;
1015-
1016- if (ratelimit < 10 && !local_bh_blocked () &&
1017- (local_softirq_pending () & SOFTIRQ_STOP_IDLE_MASK )) {
1018- pr_warn ("NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #%02x!!!\n" ,
1019- (unsigned int ) local_softirq_pending ());
1020- ratelimit ++ ;
1021- }
1067+ if (unlikely (report_idle_softirq ()))
10221068 return false;
1023- }
10241069
10251070 if (tick_nohz_full_enabled ()) {
10261071 /*
0 commit comments