From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796154556; b=Z6yQKF+ibq+FNlFbF4B0joaj0YhzT8hMTaYiUdRnh4VLjL8Cko8dXwhL4PYgP3Xh43Ac Kd5ocCdUdRuT7Jv0EwNeu1tA6HrjI7GdsBJLHSQbcfDA5n5b/DoRTfnzu//J6qaT4lKGf WqBl/Gku1uxLoWwivhw89bjID/oxfOmdZWB7sfPRRjNtHjN3S9SaLud/9g5fJOL1eYxZU dteAVqgODOTSBMq/05g+xR/Bv5RxnreFgZB9l/xW0xslSbPoxaCpBtrjanOpglDiZR4bK 26WrU5ivAf9or+ne74TmzVhhd8FfFUJlC2PVT2oH8gqfbwLnAeB+AhhUGp+EMkHrwwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796154556; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:Content-Language:Autocrypt:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=Oa1EEP0yZnVJJqP9NrFjF0l233Nb2YoMCFcenuXOTwY=; b=xDGP2ss9iSfaibERMrYioVCDraqC3h/lGej/3+jDY+ozjEckVEkcIX1FE7NgLhGazIaw tVWsvc/6Lzb7A/ZTtyywgVeyKg4X63W9+dxxSiHtDH93A5YF1VguDBYxskmKgNHmBThZm f1/CrZwuGJ14aKJ3k7yDcwRfq3lVdbY61Ml4lfOfNQvtUzxfpeDfEA6rfSiEd0oarYwQR rqcfTNQ5kQdTVP6vt9qFMipqkYJ1cMr96KyyoZW4r+Re4u787nO8JXRatNrGh6LWbjTBQ KKzCt1/9rMXk16hop1HATcYg+H4VrGV8m89m+eqJmm+SO62Bw06K5PCYNCMs0XhSEGg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LAjXnXQF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72492606A31A for ; Tue, 1 Dec 2026 19:49:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LAjXnXQF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C7751F000C1; Tue, 1 Dec 2026 19:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796154556; bh=Oa1EEP0yZnVJJqP9NrFjF0l233Nb2YoMCFcenuXOTwY=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=LAjXnXQF3kq1C0uBU6DvkzT3HcIV7luUgg2Vizo23qJ9Wm6+v2UPhTgqJDi6SlcJN ng45tfRSahRdakVn9zzuhEimMpjsVYWMbWM4d4qJ/E+KYMqnubJFBJF6fB6YHSK/Bh vqUgh5a4vAVPG4h4NK+whR49a4elX51mpMMMIILmwrWJ+X7VugpIE4QLTKATTnebHl rE7hMbfjw/Q1A9FRDRo+bdrqrxGmcgaSaGUq/gLiSfYIfMRjPykTzWstx3TZh38bAm E39o0N26WJ1xbWlOBkgB+kExw+RhI+MDgqK+Cb0q1mfB4sCe+ZOeQOH9zEMvSET/V5 X5rlDI+FuNHbQ== Message-ID: Date: Tue, 1 Dec 2026 20:49:11 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 1/1] sched: Replace nr_pinned offset hack with a dedicated per-CPU counter To: Qiurong Fang , peterz@infradead.org, mingo@redhat.com Cc: juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, nsc@kernel.org, pmladek@suse.com, linux-kernel@vger.kernel.org References: <20260825041320.2486529-1-fangqiurong@kylinos.cn> <20260825041320.2486529-2-fangqiurong@kylinos.cn> From: Vincent Mailhol Content-Language: en-US Autocrypt: addr=mailhol@kernel.org; keydata= xjMEZluomRYJKwYBBAHaRw8BAQdAf+/PnQvy9LCWNSJLbhc+AOUsR2cNVonvxhDk/KcW7FvN JFZpbmNlbnQgTWFpbGhvbCA8bWFpbGhvbEBrZXJuZWwub3JnPsKZBBMWCgBBAhsDBQsJCAcC AiICBhUKCQgLAgQWAgMBAh4HAheAFiEE7Y9wBXTmfyDldOjiq1/riG27mcIFAmrTM8wFCR1O HxcACgkQq1/riG27mcJ2KAEAhG19xBSkjiA9dtatvq2WJnGaes4SUmY+LSn7dh1Lf7YBAIwB lsMMmigMTk3Qgwymg1nT+Z8z1Owc/TGtRlo4ZcwMzjgEZx4y8xIKKwYBBAGXVQEFAQEHQJrb YZzu0JG5w8gxE6EtQe6LmxKMqP6EyR33sA+BR9pLAwEIB8J+BBgWCgAmAhsMFiEE7Y9wBXTm fyDldOjiq1/riG27mcIFAmrTNKcFCRUFdT0ACgkQq1/riG27mcLEVwD/VmnQtTf6yhowaIFj AjUtwiyQz9ja4NRu9GOvz/pb2L8A/3QcADR0dcxADGsmOiBpN2M9KI7nqdNIq3VPM/3/5fcB In-Reply-To: <20260825041320.2486529-2-fangqiurong@kylinos.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Qiurong, This clean-up makes sense to me. Not sure why it didn't catch attention. I think it should be resent, this time dropping the RFC tag. I added a few nitpicks, but it looks mostly ready to me. On 25/08/2026 at 06:13, Qiurong Fang wrote: > From: fangqiurong > > The inlined migrate_{en,dis}able() in include/linux/sched.h cannot see > struct rq, so they bump rq->nr_pinned through a generated offset > constant, dragging along kernel/sched/rq-offsets.c, its own Kbuild rule, > a global #include from sched.h and an > arch_raw_cpu_ptr()/PERCPU_PTR() workaround that casts away the field > type. > > Replace it with a plain per-CPU counter, rq_nr_pinned: __this_cpu_inc()/ > __this_cpu_dec() in the inline writers (already preempt-disabled there) > and per_cpu_ptr() + READ_ONCE() in rq_has_pinned_tasks(). Codegen and > runtime behaviour are unchanged and modules keep the exported wrappers; Maybe this assertion that code generation is unchanged could be slightly nuanced? Now that you are doing direct increments and decrements, you don't need to compute the runqueue address anymore. And the codegen would also be modified with CONFIG_DEBUG_PREEMPT, which adds a __this_cpu_preempt_check() verification. > the missing-syscalls check is re-anchored to the regular asm-offsets > file. > > Signed-off-by: fangqiurong > --- > Kbuild | 13 +------------ > include/linux/sched.h | 30 +++--------------------------- > kernel/sched/core.c | 3 ++- > kernel/sched/rq-offsets.c | 12 ------------ > kernel/sched/sched.h | 1 - > 5 files changed, 6 insertions(+), 53 deletions(-) > delete mode 100644 kernel/sched/rq-offsets.c > > diff --git a/Kbuild b/Kbuild > index a6a0192dea08..984765c9425f 100644 > --- a/Kbuild > +++ b/Kbuild > @@ -34,17 +34,6 @@ arch/$(SRCARCH)/kernel/asm-offsets.s: $(timeconst-file) $(bounds-file) > $(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE > $(call filechk,offsets,__ASM_OFFSETS_H__) > > -# Generate rq-offsets.h > - > -rq-offsets-file := include/generated/rq-offsets.h > - > -targets += kernel/sched/rq-offsets.s > - > -kernel/sched/rq-offsets.s: $(offsets-file) > - > -$(rq-offsets-file): kernel/sched/rq-offsets.s FORCE > - $(call filechk,offsets,__RQ_OFFSETS_H__) > - > # Check for missing system calls > > missing-syscalls-file := .tmp_missing-syscalls$(missing_syscalls_instance) > @@ -54,7 +43,7 @@ targets += $(missing-syscalls-file) > quiet_cmd_syscalls = CALL $< $(addprefix for ,$(missing_syscalls_instance)) > cmd_syscalls = DEPFILE=$(depfile) $(CONFIG_SHELL) $< $(CC) $(c_flags) $(missing_syscalls_flags); touch $@ > > -$(missing-syscalls-file): scripts/checksyscalls.sh $(rq-offsets-file) FORCE > +$(missing-syscalls-file): scripts/checksyscalls.sh $(offsets-file) FORCE > $(call if_changed_dep,syscalls) > > PHONY += missing-syscalls > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 373bcc0598d1..413e6a29d1b1 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -51,9 +51,6 @@ > #include > #include > #include > -#ifndef COMPILE_OFFSETS > -#include > -#endif > > /* task_struct member predeclarations (sorted alphabetically): */ > struct audit_context; > @@ -2407,27 +2404,10 @@ struct sched_cache_stat { }; > #endif > > #ifndef MODULE > -#ifndef COMPILE_OFFSETS > > extern void ___migrate_enable(void); > > -struct rq; > -DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); > - > -/* > - * The "struct rq" is not available here, so we can't access the > - * "runqueues" with this_cpu_ptr(), as the compilation will fail in > - * this_cpu_ptr() -> raw_cpu_ptr() -> __verify_pcpu_ptr(): > - * typeof((ptr) + 0) > - * > - * So use arch_raw_cpu_ptr()/PERCPU_PTR() directly here. > - */ > -#ifdef CONFIG_SMP > -#define this_rq_raw() arch_raw_cpu_ptr(&runqueues) > -#else > -#define this_rq_raw() PERCPU_PTR(&runqueues) > -#endif > -#define this_rq_pinned() (*(unsigned int *)((void *)this_rq_raw() + RQ_nr_pinned)) > +DECLARE_PER_CPU(unsigned int, rq_nr_pinned); > > static inline void __migrate_enable(void) > { > @@ -2461,7 +2441,7 @@ static inline void __migrate_enable(void) > */ > barrier(); > p->migration_disabled = 0; > - this_rq_pinned()--; > + __this_cpu_dec(rq_nr_pinned); > } > > static inline void __migrate_disable(void) > @@ -2480,13 +2460,9 @@ static inline void __migrate_disable(void) > } > > guard(preempt)(); > - this_rq_pinned()++; > + __this_cpu_inc(rq_nr_pinned); > p->migration_disabled = 1; > } > -#else /* !COMPILE_OFFSETS */ > -static inline void __migrate_disable(void) { } > -static inline void __migrate_enable(void) { } > -#endif /* !COMPILE_OFFSETS */ > > /* > * So that it is possible to not export the runqueues variable, define and ^^^^^^^^^ That comment needs to be updated: the variable is now named rq_nr_pinned. > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 145eea2d99a1..ddfa2ee52299 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -130,6 +130,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_dl_server_stop_tp); > > DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); > DEFINE_PER_CPU(struct rnd_state, sched_rnd_state); > +DEFINE_PER_CPU(unsigned int, rq_nr_pinned); > > #ifdef CONFIG_SCHED_PROXY_EXEC > DEFINE_STATIC_KEY_TRUE(__sched_proxy_exec); > @@ -2502,7 +2503,7 @@ EXPORT_SYMBOL_GPL(migrate_enable); > > static inline bool rq_has_pinned_tasks(struct rq *rq) > { > - return rq->nr_pinned; > + return READ_ONCE(*per_cpu_ptr(&rq_nr_pinned, cpu_of(rq))); > } > > /* > diff --git a/kernel/sched/rq-offsets.c b/kernel/sched/rq-offsets.c > deleted file mode 100644 > index a23747bbe25b..000000000000 > --- a/kernel/sched/rq-offsets.c > +++ /dev/null After removing rq-offsets.c, don't forget to also clean-up makefiles.rst and hardcoded_dependencies.py: diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index 535d30eef59a..d1a869293251 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -1316,8 +1316,7 @@ The rules are defined in the top-level ``Kbuild`` and subdirectories. The same mechanism generates ``include/generated/bounds.h`` from -``kernel/bounds.c`` and ``include/generated/rq-offsets.h`` from -``kernel/sched/rq-offsets.c``. +``kernel/bounds.c``. List directories to visit when descending ----------------------------------------- diff --git a/scripts/sbom/sbom/cmd_graph/hardcoded_dependencies.py b/scripts/sbom/sbom/cmd_graph/hardcoded_dependencies.py index 2eb04d30f4e6..4d9f6a9ba3e3 100644 --- a/scripts/sbom/sbom/cmd_graph/hardcoded_dependencies.py +++ b/scripts/sbom/sbom/cmd_graph/hardcoded_dependencies.py @@ -9,8 +9,6 @@ from sbom.environment import Environment HARDCODED_DEPENDENCIES: dict[str, list[str]] = { # defined in linux/Kbuild - "include/generated/rq-offsets.h": ["kernel/sched/rq-offsets.s"], - "kernel/sched/rq-offsets.s": ["include/generated/asm-offsets.h"], "include/generated/bounds.h": ["kernel/bounds.s"], "include/generated/asm-offsets.h": ["arch/{arch}/kernel/asm-offsets.s"], } > @@ -1,12 +0,0 @@ > -// SPDX-License-Identifier: GPL-2.0 > -#define COMPILE_OFFSETS > -#include > -#include > -#include "sched.h" > - > -int main(void) > -{ > - DEFINE(RQ_nr_pinned, offsetof(struct rq, nr_pinned)); > - > - return 0; > -} > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index 7701a5a60972..b77689172793 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -1358,7 +1358,6 @@ struct rq { > struct cpuidle_state *idle_state; > #endif > > - unsigned int nr_pinned; > unsigned int push_busy; > struct cpu_stop_work push_work; Yours sincerely, Vincent Mailhol