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 47114149DF1 for ; Tue, 30 Jun 2026 20:34:17 +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=1782851659; cv=none; b=lbtEJYVf8cHGJmak6yNM+sD9lJsAE7uh3i1KHhlR3LjkScHxpYIirjaBZAjHoM1FuuKVPe3+tqe6bJiKAAVFzsLih8E02aeytEcqgtAHXbW0BFHYoa7T3UPeHEXZ4WvuDXTO6n2UNlIwCunmt7+4ZJmpFy2pJnRpM8QZ8QLtsbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782851659; c=relaxed/simple; bh=II4H9XqqvnDaZhDzcB6WJz9euT6UCJQZIHjgXnJ6ptg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l9MvTrEcNuDYF/4YXoH9QLJ8QU663SA+IVa7pls78IE7rHcHLKbvJvPWWhzX8DAlfNB+5Vj0t1V4ng3NiablZ+CKNqKIua90KCXQJsukhTCID9R+HxrY4XFerxkYoRJgzdl23w4Ms9syCcmjudKTtQDo7ZVIglqhFa7L0lR9jyk= 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=tN5dsRAF; 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="tN5dsRAF" 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=GzQHK0OwpU1jp3oBHCYVadG27EX277H5e8NGJC0t2BQ=; b=tN5dsRAF4wtXzw9DHBLKE0IL4p sIGEE69eirrQJ7DbxBnR1yebHwnKTjOFB1OKDrqLZeDio44N8Z2tcHghJ2V8hiu9infOkiPf0Y8O5 UjeOLq5DWWwawbBgiuRgNri3Jw0xhwTnOzfLixYDcwzP/s1xA/7baIO0t94aD+pNFSyhaLNlrGMkF vWLDUJHA2TTkCf/ksjXdkbw8evNQZycps2IBNAnG0s0iPePzn5HEv5rJRj5sfsort+mJrF4yiIoHl 5L+jBXFCWQn6LtnUyG8hXsD8Uk+hlVDqYJO0I4sYJHDWhtcKpss4RJKnjXndC20MAU1fqvnlFL4Zf 5Yz0Am4g==; 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 1wef9m-00000005UxD-0hUS; Tue, 30 Jun 2026 20:34:10 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 0622F3004F8; Tue, 30 Jun 2026 22:34:09 +0200 (CEST) Date: Tue, 30 Jun 2026 22:34:08 +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: <20260630203408.GG48970@noisy.programming.kicks-ass.net> References: <20260627081657.499781-1-rhkrqnwk98@gmail.com> <6cbcc3ea742b92b6a34b5994f5498c7611beac7e.camel@redhat.com> <5f47566b-88f4-458d-87a4-7794e6ba8203@amd.com> 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 Tue, Jun 30, 2026 at 09:46:11PM +0530, K Prateek Nayak wrote: > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 96226707c2f6..934f540d0d3f 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); > } > > /* > @@ -1076,8 +1083,11 @@ static bool set_nr_if_polling(struct task_struct *p) > } > > #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) > { > + struct task_struct *curr = rq->curr; > + struct thread_info *ti = task_thread_info(curr); > + > set_ti_thread_flag(ti, tif); > return true; > } This !POLLING thing also needs tracing, no? > @@ -1202,15 +1212,17 @@ static void __resched_curr(struct rq *rq, int tif) > > cpu = cpu_of(rq); > > - trace_sched_set_need_resched_tp(curr, cpu, tif); > 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(); > return; > } > > - if (set_nr_and_not_polling(cti, tif)) { > + if (set_nr_and_not_polling(rq, tif)) { > if (tif == TIF_NEED_RESCHED) > smp_send_reschedule(cpu); > } else { > @@ -1350,7 +1362,7 @@ static void wake_up_idle_cpu(int cpu) > * and testing of the above solutions didn't appear to report > * much benefits. > */ > - if (set_nr_and_not_polling(task_thread_info(rq->idle), TIF_NEED_RESCHED)) > + if (set_nr_and_not_polling(rq, TIF_NEED_RESCHED)) > smp_send_reschedule(cpu); > else > trace_sched_wake_idle_without_ipi(cpu); > --- > > > > > Thanks, > > Gabriele > > > > -- > Thanks and Regards, > Prateek >