Commit c04507ac authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Thomas Gleixner
Browse files

sched: Provide and use set_need_resched_current()



set_tsk_need_resched(current) requires set_preempt_need_resched(current) to
work correctly outside of the scheduler.

Provide set_need_resched_current() which wraps this correctly and replace
all the open coded instances.

Signed-off-by: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Link: https://patch.msgid.link/20251116174750.665769842@linutronix.de
parent 33cf66d8
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -199,8 +199,7 @@ static void pfault_interrupt(struct ext_code ext_code,
			 * return to userspace schedule() to block.
			 */
			__set_current_state(TASK_UNINTERRUPTIBLE);
			set_tsk_need_resched(tsk);
			set_preempt_need_resched();
			set_need_resched_current();
		}
	}
out:
+7 −0
Original line number Diff line number Diff line
@@ -2058,6 +2058,13 @@ static inline int test_tsk_need_resched(struct task_struct *tsk)
	return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
}

static inline void set_need_resched_current(void)
{
	lockdep_assert_irqs_disabled();
	set_tsk_need_resched(current);
	set_preempt_need_resched();
}

/*
 * cond_resched() and cond_resched_lock(): latency reduction via
 * explicit rescheduling in places that are safe. The return
+3 −5
Original line number Diff line number Diff line
@@ -70,12 +70,10 @@ void rcu_qs(void)
 */
void rcu_sched_clock_irq(int user)
{
	if (user) {
	if (user)
		rcu_qs();
	} else if (rcu_ctrlblk.donetail != rcu_ctrlblk.curtail) {
		set_tsk_need_resched(current);
		set_preempt_need_resched();
	}
	else if (rcu_ctrlblk.donetail != rcu_ctrlblk.curtail)
		set_need_resched_current();
}

/*
+5 −9
Original line number Diff line number Diff line
@@ -2696,10 +2696,8 @@ void rcu_sched_clock_irq(int user)
	/* The load-acquire pairs with the store-release setting to true. */
	if (smp_load_acquire(this_cpu_ptr(&rcu_data.rcu_urgent_qs))) {
		/* Idle and userspace execution already are quiescent states. */
		if (!rcu_is_cpu_rrupt_from_idle() && !user) {
			set_tsk_need_resched(current);
			set_preempt_need_resched();
		}
		if (!rcu_is_cpu_rrupt_from_idle() && !user)
			set_need_resched_current();
		__this_cpu_write(rcu_data.rcu_urgent_qs, false);
	}
	rcu_flavor_sched_clock_irq(user);
@@ -2824,7 +2822,6 @@ static void strict_work_handler(struct work_struct *work)
/* Perform RCU core processing work for the current CPU.  */
static __latent_entropy void rcu_core(void)
{
	unsigned long flags;
	struct rcu_data *rdp = raw_cpu_ptr(&rcu_data);
	struct rcu_node *rnp = rdp->mynode;

@@ -2837,8 +2834,8 @@ static __latent_entropy void rcu_core(void)
	if (IS_ENABLED(CONFIG_PREEMPT_COUNT) && (!(preempt_count() & PREEMPT_MASK))) {
		rcu_preempt_deferred_qs(current);
	} else if (rcu_preempt_need_deferred_qs(current)) {
		set_tsk_need_resched(current);
		set_preempt_need_resched();
		guard(irqsave)();
		set_need_resched_current();
	}

	/* Update RCU state based on any recent quiescent states. */
@@ -2847,10 +2844,9 @@ static __latent_entropy void rcu_core(void)
	/* No grace period and unregistered callbacks? */
	if (!rcu_gp_in_progress() &&
	    rcu_segcblist_is_enabled(&rdp->cblist) && !rcu_rdp_is_offloaded(rdp)) {
		local_irq_save(flags);
		guard(irqsave)();
		if (!rcu_segcblist_restempty(&rdp->cblist, RCU_NEXT_READY_TAIL))
			rcu_accelerate_cbs_unlocked(rnp, rdp);
		local_irq_restore(flags);
	}

	rcu_check_gp_start_stall(rnp, rdp, rcu_jiffies_till_stall_check());
+1 −2
Original line number Diff line number Diff line
@@ -729,8 +729,7 @@ static void rcu_exp_need_qs(void)
	__this_cpu_write(rcu_data.cpu_no_qs.b.exp, true);
	/* Store .exp before .rcu_urgent_qs. */
	smp_store_release(this_cpu_ptr(&rcu_data.rcu_urgent_qs), true);
	set_tsk_need_resched(current);
	set_preempt_need_resched();
	set_need_resched_current();
}

#ifdef CONFIG_PREEMPT_RCU
Loading