Skip to content

Commit cb44400

Browse files
David Daihtejun
authored andcommitted
sched_ext, rcu: Eject BPF scheduler on RCU CPU stall panic
For systems using a sched_ext scheduler and has panic_on_rcu_stall enabled, try kicking out the current scheduler before issuing a panic. While there are numerous reasons for RCU CPU stalls that are not directly attributed to the scheduler, deferring the panic gives sched_ext an opportunity to provide additional debug info when ejecting the current scheduler. Also, handling the event more gracefully allows us to potentially recover the system instead of incurring additional down time. Suggested-by: Tejun Heo <[email protected]> Reviewed-by: Paul E. McKenney <[email protected]> Signed-off-by: David Dai <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent e2a37c2 commit cb44400

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

include/linux/sched/ext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,14 @@ struct sched_ext_entity {
206206
void sched_ext_free(struct task_struct *p);
207207
void print_scx_info(const char *log_lvl, struct task_struct *p);
208208
void scx_softlockup(u32 dur_s);
209+
bool scx_rcu_cpu_stall(void);
209210

210211
#else /* !CONFIG_SCHED_CLASS_EXT */
211212

212213
static inline void sched_ext_free(struct task_struct *p) {}
213214
static inline void print_scx_info(const char *log_lvl, struct task_struct *p) {}
214215
static inline void scx_softlockup(u32 dur_s) {}
216+
static inline bool scx_rcu_cpu_stall(void) { return false; }
215217

216218
#endif /* CONFIG_SCHED_CLASS_EXT */
217219

kernel/rcu/tree_stall.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ static void panic_on_rcu_stall(void)
134134
{
135135
static int cpu_stall;
136136

137+
/*
138+
* Attempt to kick out the BPF scheduler if it's installed and defer
139+
* the panic to give the system a chance to recover.
140+
*/
141+
if (scx_rcu_cpu_stall())
142+
return;
143+
137144
if (++cpu_stall < sysctl_max_rcu_stall_to_panic)
138145
return;
139146

kernel/sched/ext.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4672,6 +4672,41 @@ bool scx_allow_ttwu_queue(const struct task_struct *p)
46724672
p->sched_class != &ext_sched_class;
46734673
}
46744674

4675+
/**
4676+
* scx_rcu_cpu_stall - sched_ext RCU CPU stall handler
4677+
*
4678+
* While there are various reasons why RCU CPU stalls can occur on a system
4679+
* that may not be caused by the current BPF scheduler, try kicking out the
4680+
* current scheduler in an attempt to recover the system to a good state before
4681+
* issuing panics.
4682+
*/
4683+
bool scx_rcu_cpu_stall(void)
4684+
{
4685+
struct scx_sched *sch;
4686+
4687+
rcu_read_lock();
4688+
4689+
sch = rcu_dereference(scx_root);
4690+
if (unlikely(!sch)) {
4691+
rcu_read_unlock();
4692+
return false;
4693+
}
4694+
4695+
switch (scx_enable_state()) {
4696+
case SCX_ENABLING:
4697+
case SCX_ENABLED:
4698+
break;
4699+
default:
4700+
rcu_read_unlock();
4701+
return false;
4702+
}
4703+
4704+
scx_error(sch, "RCU CPU stall detected!");
4705+
rcu_read_unlock();
4706+
4707+
return true;
4708+
}
4709+
46754710
/**
46764711
* scx_softlockup - sched_ext softlockup handler
46774712
* @dur_s: number of seconds of CPU stuck due to soft lockup

0 commit comments

Comments
 (0)