From nobody Mon Sep 28 07:20:14 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 352523264D2 for ; Tue, 25 Aug 2026 04:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787631227; cv=none; b=n+bqNAbuQdmPU6wLqIaWr4H2ExHv2En9vs/paIhHV+5Roa41NM01o2EzG8RS39TcanOjR4q2pZSYUTW/t2Bd4iNqtVbCjiDrM/HckDq02ShwRwLuc1XxaylqjdgYd8j4KIVisJvtkOtAoDUuJtRGWlQ4v4A7pmRqH1ifily/tJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787631227; c=relaxed/simple; bh=HZHyIe+6rxw/h/vGkz5L1CemAPrA2lqRTvSQTFW0/7Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EQEKscbh5bdsGzVcDzyC2MKqwV3NYpriw0rIePePukHrKF/7dhJnUQC+3cto3lZtJfBS5IOBFRsw/M3BeMNe/qJqxXIQ42wvZ84fE+nbk4mIya/8q9L/c2uzLUrBf3UElwkGLKGqyToESUz47H7lwUPbDShvFNNLDaPRlU4pHTs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 58d9b9cca03b11f19a56ed5b684f684d-20260825 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:80d341a7-021f-45e9-83cd-42b136c73955,IP:0,U RL:0,TC:0,Content:-25,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-META: VersionHash:7db8b62,CLOUDID:6d5645a0217a58497d33619c855ca967,BulkI D:nil,BulkQuantity:0,SF:81|82|102|850|865|898,TC:nil,Content:0|15|50,EDM:5 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 58d9b9cca03b11f19a56ed5b684f684d-20260825 X-User: fangqiurong@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 673862694; Tue, 25 Aug 2026 12:13:37 +0800 From: Qiurong Fang To: 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, masahiro@kernel.org, nsc@kernel.org, pmladek@suse.com, linux-kernel@vger.kernel.org, fangqiurong Subject: [PATCH RFC 1/1] sched: Replace nr_pinned offset hack with a dedicated per-CPU counter Date: Tue, 25 Aug 2026 12:13:20 +0800 Message-Id: <20260825041320.2486529-2-fangqiurong@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260825041320.2486529-1-fangqiurong@kylinos.cn> References: <20260825041320.2486529-1-fangqiurong@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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; 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__) =20 -# Generate rq-offsets.h - -rq-offsets-file :=3D include/generated/rq-offsets.h - -targets +=3D 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 =20 missing-syscalls-file :=3D .tmp_missing-syscalls$(missing_syscalls_instanc= e) @@ -54,7 +43,7 @@ targets +=3D $(missing-syscalls-file) quiet_cmd_syscalls =3D CALL $< $(addprefix for ,$(missing_syscalls_inst= ance)) cmd_syscalls =3D DEPFILE=3D$(depfile) $(CONFIG_SHELL) $< $(CC) $(c_f= lags) $(missing_syscalls_flags); touch $@ =20 -$(missing-syscalls-file): scripts/checksyscalls.sh $(rq-offsets-file) FORCE +$(missing-syscalls-file): scripts/checksyscalls.sh $(offsets-file) FORCE $(call if_changed_dep,syscalls) =20 PHONY +=3D 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 =20 /* task_struct member predeclarations (sorted alphabetically): */ struct audit_context; @@ -2407,27 +2404,10 @@ struct sched_cache_stat { }; #endif =20 #ifndef MODULE -#ifndef COMPILE_OFFSETS =20 extern void ___migrate_enable(void); =20 -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); =20 static inline void __migrate_enable(void) { @@ -2461,7 +2441,7 @@ static inline void __migrate_enable(void) */ barrier(); p->migration_disabled =3D 0; - this_rq_pinned()--; + __this_cpu_dec(rq_nr_pinned); } =20 static inline void __migrate_disable(void) @@ -2480,13 +2460,9 @@ static inline void __migrate_disable(void) } =20 guard(preempt)(); - this_rq_pinned()++; + __this_cpu_inc(rq_nr_pinned); p->migration_disabled =3D 1; } -#else /* !COMPILE_OFFSETS */ -static inline void __migrate_disable(void) { } -static inline void __migrate_enable(void) { } -#endif /* !COMPILE_OFFSETS */ =20 /* * So that it is possible to not export the runqueues variable, define and 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); =20 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); =20 #ifdef CONFIG_SCHED_PROXY_EXEC DEFINE_STATIC_KEY_TRUE(__sched_proxy_exec); @@ -2502,7 +2503,7 @@ EXPORT_SYMBOL_GPL(migrate_enable); =20 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))); } =20 /* 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 @@ -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 =20 - unsigned int nr_pinned; unsigned int push_busy; struct cpu_stop_work push_work; =20 --=20 2.43.0