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.

sched_ext: Refactor lockup handlers into handle_lockup()

scx_rcu_cpu_stall() and scx_softlockup() share the same pattern: check if the
scheduler is enabled under RCU read lock and trigger an error if so. Extract
the common pattern into handle_lockup() helper. Add scx_verror() macro and use
guard(rcu)().

This simplifies both handlers, reduces code duplication, and prepares for
hardlockup handling.

Reviewed-by: Dan Schatzberg <schatzberg.dan@gmail.com>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Cc: Emil Tsalapatis <etsal@meta.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

Tejun Heo 4ba54a6c f2fe382e

+29 -44
+29 -44
kernel/sched/ext.c
··· 192 192 } 193 193 194 194 #define scx_error(sch, fmt, args...) scx_exit((sch), SCX_EXIT_ERROR, 0, fmt, ##args) 195 + #define scx_verror(sch, fmt, args) scx_vexit((sch), SCX_EXIT_ERROR, 0, fmt, args) 195 196 196 197 #define SCX_HAS_OP(sch, op) test_bit(SCX_OP_IDX(op), (sch)->has_op) 197 198 ··· 3655 3654 return false; 3656 3655 } 3657 3656 3657 + static __printf(1, 2) bool handle_lockup(const char *fmt, ...) 3658 + { 3659 + struct scx_sched *sch; 3660 + va_list args; 3661 + 3662 + guard(rcu)(); 3663 + 3664 + sch = rcu_dereference(scx_root); 3665 + if (unlikely(!sch)) 3666 + return false; 3667 + 3668 + switch (scx_enable_state()) { 3669 + case SCX_ENABLING: 3670 + case SCX_ENABLED: 3671 + va_start(args, fmt); 3672 + scx_verror(sch, fmt, args); 3673 + va_end(args); 3674 + return true; 3675 + default: 3676 + return false; 3677 + } 3678 + } 3679 + 3658 3680 /** 3659 3681 * scx_rcu_cpu_stall - sched_ext RCU CPU stall handler 3660 3682 * ··· 3688 3664 */ 3689 3665 bool scx_rcu_cpu_stall(void) 3690 3666 { 3691 - struct scx_sched *sch; 3692 - 3693 - rcu_read_lock(); 3694 - 3695 - sch = rcu_dereference(scx_root); 3696 - if (unlikely(!sch)) { 3697 - rcu_read_unlock(); 3698 - return false; 3699 - } 3700 - 3701 - switch (scx_enable_state()) { 3702 - case SCX_ENABLING: 3703 - case SCX_ENABLED: 3704 - break; 3705 - default: 3706 - rcu_read_unlock(); 3707 - return false; 3708 - } 3709 - 3710 - scx_error(sch, "RCU CPU stall detected!"); 3711 - rcu_read_unlock(); 3712 - 3713 - return true; 3667 + return handle_lockup("RCU CPU stall detected!"); 3714 3668 } 3715 3669 3716 3670 /** ··· 3703 3701 */ 3704 3702 void scx_softlockup(u32 dur_s) 3705 3703 { 3706 - struct scx_sched *sch; 3704 + if (!handle_lockup("soft lockup - CPU %d stuck for %us", smp_processor_id(), dur_s)) 3705 + return; 3707 3706 3708 - rcu_read_lock(); 3709 - 3710 - sch = rcu_dereference(scx_root); 3711 - if (unlikely(!sch)) 3712 - goto out_unlock; 3713 - 3714 - switch (scx_enable_state()) { 3715 - case SCX_ENABLING: 3716 - case SCX_ENABLED: 3717 - break; 3718 - default: 3719 - goto out_unlock; 3720 - } 3721 - 3722 - printk_deferred(KERN_ERR "sched_ext: Soft lockup - CPU%d stuck for %us, disabling \"%s\"\n", 3723 - smp_processor_id(), dur_s, scx_root->ops.name); 3724 - 3725 - scx_error(sch, "soft lockup - CPU#%d stuck for %us", smp_processor_id(), dur_s); 3726 - out_unlock: 3727 - rcu_read_unlock(); 3707 + printk_deferred(KERN_ERR "sched_ext: Soft lockup - CPU %d stuck for %us, disabling BPF scheduler\n", 3708 + smp_processor_id(), dur_s); 3728 3709 } 3729 3710 3730 3711 /**