From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD88F3B1EFC for ; Wed, 1 Jul 2026 06:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782888900; cv=none; b=hRNkPLU887duVE96MapbsAcbhbUBZJf5Eeitj+a2+yCQliHO8QGsMV+GPnR5Z4Ljp76lNp21zOHpd1z1a91LSHZdEmWjB55/mIREA28dADatjj0Y4FquKOADWBDlEajp0XEI/Gg4L6IuVbP+3VG2WfAIqFiDD7YZIvXsjSOt4ok= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782888900; c=relaxed/simple; bh=iKCZJ+Umyw7l1Sps78F0+B+T+uVuXWOkw1U0pgesqoo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Im885XJ68DwiiW45Cntg+ciP0q2sGdd1wFwgNhfNgPM26KcCRtCxqxuC1zKQpJWFZgyc9zABjL5HWEAEGxXaiIv0CfADegY6O61GDiPWB2nPJXUwGBw/102GVFWC9zITqobblRJuQT+cK9UWmLzgpQPzCDDemA+meTQwjz7MRxQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=lL/kJPdm; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lL/kJPdm" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=qnWGTW4l+6RcN0pXG32qxaN/gDkQNZQlr99QO6R1h2s=; b=lL/kJPdm0NsP2CC37g5OjpmlDI s2Y5xaM2jnHv1vOHD4qM06YJA4G0Q0qgxcEuPpzDZQsbVlrdA89FwPNeJol0gg2VPqzPT4Jtnwi7v lQegxWZIBk0Js4HTwP3X+CHu4krKvT7I89acc5dv0vUGRkZQh3ud2z+LU1piEVDzOXyKepTjjmVf2 UNFmPxToF4qC3yXrJitxVf4IH21ZgwQ6Q6yivhPlGf3QPU8ZNhwgkQrXT/oTGo64AW4fD7+IZ03a6 yGIuROPjzV4sIlFuyDMr/9nRqGV25jMdvW+SOQR6zX6oDh8v1NfjnuHjnIbwpbzYTnMFg2E4yUboO VKO/7cEA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1weoqO-0000000698b-1qyi; Wed, 01 Jul 2026 06:54:48 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 6240E30035C; Wed, 01 Jul 2026 08:54:47 +0200 (CEST) Date: Wed, 1 Jul 2026 08:54:47 +0200 From: Peter Zijlstra To: K Prateek Nayak Cc: Gabriele Monaco , Sechang Lim , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] sched: set TIF_NEED_RESCHED before calling __trace_set_need_resched() Message-ID: <20260701065447.GI48970@noisy.programming.kicks-ass.net> References: <20260627081657.499781-1-rhkrqnwk98@gmail.com> <6cbcc3ea742b92b6a34b5994f5498c7611beac7e.camel@redhat.com> <5f47566b-88f4-458d-87a4-7794e6ba8203@amd.com> <20260630203408.GG48970@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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.