The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Gabriele Monaco <gmonaco@redhat.com>,
	Sechang Lim <rhkrqnwk98@gmail.com>,
	Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] sched: set TIF_NEED_RESCHED before calling __trace_set_need_resched()
Date: Wed, 1 Jul 2026 08:54:47 +0200	[thread overview]
Message-ID: <20260701065447.GI48970@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <f6587c8a-5d5b-4928-9eea-7e10a93377b8@amd.com>

On Wed, Jul 01, 2026 at 12:21:14PM +0530, K Prateek Nayak wrote:

> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 7cbd541f656f..bd2f7fb87dc9 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1049,9 +1049,16 @@ static inline void hrtick_schedule_exit(struct rq *rq) { }
>   * this avoids any races wrt polling state changes and thereby avoids
>   * spurious IPIs.
>   */
> -static inline bool set_nr_and_not_polling(struct thread_info *ti, int tif)
> +static inline bool set_nr_and_not_polling(struct rq *rq, int tif)
>  {
> -	return !(fetch_or(&ti->flags, 1 << tif) & _TIF_POLLING_NRFLAG);
> +	struct task_struct *curr = rq->curr;
> +	struct thread_info *ti = task_thread_info(curr);
> +	unsigned long old_flags = fetch_or(&ti->flags, 1 << tif);
> +
> +	if (trace_sched_set_need_resched_tp_enabled() && !(old_flags & (1 << tif)))
> +		trace_call__sched_set_need_resched_tp(curr, cpu_of(rq), tif);
> +
> +	return !(old_flags & _TIF_POLLING_NRFLAG);
>  }
>  
>  /*
> @@ -1072,13 +1079,20 @@ static bool set_nr_if_polling(struct task_struct *p)
>  			return true;
>  	} while (!try_cmpxchg(&ti->flags, &val, val | _TIF_NEED_RESCHED));
>  
> +	trace_sched_set_need_resched_tp(p, task_cpu(p), TIF_NEED_RESCHED);
>  	return true;
>  }
>  
>  #else
> -static inline bool set_nr_and_not_polling(struct thread_info *ti, int tif)
> +static inline bool set_nr_and_not_polling(struct rq *rq, int tif)
>  {
> -	set_ti_thread_flag(ti, tif);
> +	struct task_struct *curr = rq->curr;
> +	struct thread_info *ti = task_thread_info(curr);
> +	int set = test_and_set_ti_thread_flag(ti, tif);
> +
> +	if (trace_sched_set_need_resched_tp_enabled() && !set)
> +		trace_call__sched_set_need_resched_tp(curr, cpu_of(rq), tif);
> +
>  	return true;
>  }
>  
> @@ -1186,7 +1200,6 @@ static void __resched_curr(struct rq *rq, int tif)
>  {
>  	struct task_struct *curr = rq->curr;
>  	struct thread_info *cti = task_thread_info(curr);
> -	bool need_ipi;
>  	int cpu;
>  
>  	lockdep_assert_rq_held(rq);
> @@ -1204,16 +1217,16 @@ static void __resched_curr(struct rq *rq, int tif)
>  	cpu = cpu_of(rq);
>  
>  	if (cpu == smp_processor_id()) {
> -		set_ti_thread_flag(cti, tif);
> +		int set = test_and_set_ti_thread_flag(cti, tif);
> +
> +		if (trace_sched_set_need_resched_tp_enabled() && !set)
> +			trace_call__sched_set_need_resched_tp(curr, cpu, tif);
>  		if (tif == TIF_NEED_RESCHED)
>  			set_preempt_need_resched();
> -		trace_sched_set_need_resched_tp(curr, cpu, tif);
>  		return;
>  	}

I can't help but notice that the local and !POLLING cases show
remarkable similarity. Just not sure extracting that isn't going to make
a mess.

Anyway, yes this looks about right.

  reply	other threads:[~2026-07-01  6:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-27  8:16 [PATCH v2] sched: set TIF_NEED_RESCHED before calling __trace_set_need_resched() Sechang Lim
2026-06-29  4:11 ` K Prateek Nayak
2026-06-29 12:40   ` Gabriele Monaco
2026-06-29 17:35     ` K Prateek Nayak
2026-06-30  8:58       ` Gabriele Monaco
2026-06-30 16:16         ` K Prateek Nayak
2026-06-30 20:34           ` Peter Zijlstra
2026-07-01  6:51             ` K Prateek Nayak
2026-07-01  6:54               ` Peter Zijlstra [this message]
2026-07-01  8:09                 ` K Prateek Nayak
2026-07-01  8:49                   ` Peter Zijlstra
2026-06-30  7:58   ` Sechang Lim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260701065447.GI48970@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=gmonaco@redhat.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=rhkrqnwk98@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox