From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 60E0B345749; Wed, 1 Jul 2026 14:18:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782915498; cv=none; b=bySlvObpgepjBXvuiutEYddST1malbv+JEY1/3jyJvTqDf/SQ6l6fmT+BbolscFp7QM19pFZtA/Up+xHWPKCTeF4DS+m9r0a/6IXqTvMIpn00U1rjZzVsvRQBxFKhQxCgoNEMMO4AGkl/ql+q7iNUG5H2623KZHiaKOSG10RDj8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782915498; c=relaxed/simple; bh=LapqazeqMO6ngV2eTEDh1c+QmVGHnJSwEWHsNFm4E5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zccv/gsqgMzdoPc2teUjcxzbPCvph1JrlQSjij7YyK4mRS4iGkyA0j2cDbqUcNdX7KddwNIY0sbhU8Ga+CIP656UFkfz7qBk0v5fhZyNyvGq3x7Q9Orgl1LsYRGbaAo8hGLZvnrn1usgXEdNl2gZnOW4XjM6y5eh+pP2jVDv4mo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=ZaDQy8ca; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="ZaDQy8ca" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 661AIbtC494784; Wed, 1 Jul 2026 14:18:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=FO5oNx ok3o0Bmbo7AkzIn/iF08jIQjGuRJv2h2T79RM=; b=ZaDQy8ca0vVPAwcufF1j19 hsgjAVffYFp1mB9K+MRfMQtXzo8yKdePocKv+U+VAtx64yaB6E0AlDOYLayTGBMy lRqvIrjP+y1ttgFqZqeVB+8cVcyl//ULVJIfpVihl9rDymCbrFGiFxD0JooBXQij E4hBAy/CvtWnyqb7nZWT8ombxCa1ldF6jeSJN6L+eEN95GB/GhzYQesvfY32TPvK JZranqBMXSbHx4ONqp+cTwDkk6JPXc66Hu9jabTGEJSS2qGVpNmY2LLQ4H4SzcEW c3KbXC7s9mgrj0xtGiuYj44273Ycvz5wGbIZXfd1UzU/nCBWVEo+JvF8EzswyoMw == Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4f26rf4gyx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jul 2026 14:18:00 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 661E4iAD013600; Wed, 1 Jul 2026 14:18:00 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4f2suk7mp8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jul 2026 14:17:59 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 661EHtfm29164162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Jul 2026 14:17:56 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D0DB32004B; Wed, 1 Jul 2026 14:17:55 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 50FFC20040; Wed, 1 Jul 2026 14:17:42 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.67.14.28]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 1 Jul 2026 14:17:41 +0000 (GMT) From: Shrikanth Hegde To: linux-kernel@vger.kernel.org, mingo@kernel.org, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, yury.norov@gmail.com, kprateek.nayak@amd.com, iii@linux.ibm.com, corbet@lwn.net Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, maddy@linux.ibm.com, srikar@linux.ibm.com, hdanton@sina.com, chleroy@kernel.org, vineeth@bitbyteword.org, frederic@kernel.org, arighi@nvidia.com, pauld@redhat.com, christian.loehle@arm.com, tj@kernel.org, tommaso.cucinotta@gmail.com, maz@kernel.org, rafael@kernel.org, rdunlap@infradead.org, kernellwp@gmail.com, linux-doc@vger.kernel.org Subject: [PATCH v6 03/23] cpumask: Introduce cpu_preferred_mask Date: Wed, 1 Jul 2026 19:46:34 +0530 Message-ID: <20260701141654.500125-4-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260701141654.500125-1-sshegde@linux.ibm.com> References: <20260701141654.500125-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=a4kAM0SF c=1 sm=1 tr=0 ts=6a452199 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=t6Yzph75v35o9eciyTUA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: 7cdeSJQy9QZf0qoUKKKIIND7MEYXmlKz X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzAxMDE0NSBTYWx0ZWRfX9qg8VtQR3FfQ zuy9foQWFoVrQ4ZutJLWsnKhqNgwwEyW3M5PxjOM5W0qKtIB1KG0zqCi50+dsrZ/vF0mb/uJeGh vW17fGs06k92xUfqhm/57p+jHIMaSBIJksWWAGLetbHXsxDEek7vDtuXLeTo+4CK1Jmt3A/DL3s SvSIft39lJziVj3avixcI+xIo4j5+A03v/Z09WNTJj0DYvItfmCAKDg/+6xYeKITzz6whVI38Bq 0Wky6cKmHcJxGdKf3nc8nDASbYfNmW7h3fv2I+z/0VpE12RvtqCw+X/szJzTBnGBM7reL4PoqfJ 4roWqysOtFQXvRMNTH08GtC92jDRWxUh5rN2nMdcRKGEiVNr5WWzcgXY/aTzC1YNtlVEiEeNHKz uvsVKWn1EbUNMFtDMJYgs1ZitvP8gW31YyzDLPMtJtCgIbm/cykQKG4eCA5xmE3BEXbghSm/uSq hJZzKgSUNiIVBPTx38w== X-Proofpoint-GUID: u4cjaIjeVx_QAktjO7sidOEq8tg8LI2F X-Proofpoint-Spam-Info: AW1haW4tMjYwNzAxMDE0NSBTYWx0ZWRfX6PcTZfwWEH9k eBCePObobaNm6qaqNuGgJZD9OsAkyEQ5HBkrt+9BwPGkUjQJ2rrNlRlhQ6abkpDITS3JudqnY7V RYktShvTvDZnrhmWWx6PlS2bIcVBQcE= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-07-01_03,2026-06-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 spamscore=0 priorityscore=1501 adultscore=0 malwarescore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607010145 Provide cpu_preferred_mask infrastructure. Define get/set macros which could be used to get/set CPU state as preferred. Values are set/clear by the new driver called steal_monitor. It periodically samples the steal time and decides preferred CPU state. A CPU is set to preferred when it becomes active. Later it may be marked as non-preferred depending on steal time values with steal_monitor being enabled. Always maintain design construct of preferred is subset of active. i.e. preferred ⊆ active ⊆ online ⊆ present ⊆ possible With PREFERRED_CPU=n, set is nop and get returns active state. Signed-off-by: Shrikanth Hegde --- v5->v6: - Make it nop for PREFERRED_CPU=n - Make it EXPORT_SYMBOL_GPL include/linux/cpumask.h | 27 ++++++++++++++++++++++++++- kernel/cpu.c | 6 ++++++ kernel/sched/core.c | 5 +++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index d3cda0544954..c97271c063ce 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -122,12 +122,20 @@ extern struct cpumask __cpu_enabled_mask; extern struct cpumask __cpu_present_mask; extern struct cpumask __cpu_active_mask; extern struct cpumask __cpu_dying_mask; + +#ifdef CONFIG_PREFERRED_CPU +extern struct cpumask __cpu_preferred_mask; +#else +#define __cpu_preferred_mask __cpu_active_mask +#endif + #define cpu_possible_mask ((const struct cpumask *)&__cpu_possible_mask) #define cpu_online_mask ((const struct cpumask *)&__cpu_online_mask) #define cpu_enabled_mask ((const struct cpumask *)&__cpu_enabled_mask) #define cpu_present_mask ((const struct cpumask *)&__cpu_present_mask) #define cpu_active_mask ((const struct cpumask *)&__cpu_active_mask) #define cpu_dying_mask ((const struct cpumask *)&__cpu_dying_mask) +#define cpu_preferred_mask ((const struct cpumask *)&__cpu_preferred_mask) extern atomic_t __num_online_cpus; extern unsigned int __num_possible_cpus; @@ -1164,6 +1172,13 @@ void init_cpu_possible(const struct cpumask *src); #define set_cpu_active(cpu, active) assign_cpu((cpu), &__cpu_active_mask, (active)) #define set_cpu_dying(cpu, dying) assign_cpu((cpu), &__cpu_dying_mask, (dying)) +#ifdef CONFIG_PREFERRED_CPU +#define set_cpu_preferred(cpu, preferred) assign_cpu((cpu), &__cpu_preferred_mask, (preferred)) +#else +/* Don't edit active state when the feature is off */ +#define set_cpu_preferred(cpu, preferred) {} +#endif + void set_cpu_online(unsigned int cpu, bool online); void set_cpu_possible(unsigned int cpu, bool possible); @@ -1258,7 +1273,12 @@ static __always_inline bool cpu_dying(unsigned int cpu) return cpumask_test_cpu(cpu, cpu_dying_mask); } -#else +static __always_inline bool cpu_preferred(unsigned int cpu) +{ + return cpumask_test_cpu(cpu, cpu_preferred_mask); +} + +#else /* NR_CPUS <= 1 */ #define num_online_cpus() 1U #define num_possible_cpus() 1U @@ -1296,6 +1316,11 @@ static __always_inline bool cpu_dying(unsigned int cpu) return false; } +static __always_inline bool cpu_preferred(unsigned int cpu) +{ + return cpu == 0; +} + #endif /* NR_CPUS > 1 */ #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) diff --git a/kernel/cpu.c b/kernel/cpu.c index b3c8553d7bd6..376d297a6292 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -3103,6 +3103,11 @@ EXPORT_SYMBOL(__cpu_dying_mask); atomic_t __num_online_cpus __read_mostly; EXPORT_SYMBOL(__num_online_cpus); +#ifdef CONFIG_PREFERRED_CPU +struct cpumask __cpu_preferred_mask __read_mostly; +EXPORT_SYMBOL_GPL(__cpu_preferred_mask); +#endif + void init_cpu_present(const struct cpumask *src) { cpumask_copy(&__cpu_present_mask, src); @@ -3160,6 +3165,7 @@ void __init boot_cpu_init(void) /* Mark the boot cpu "present", "online" etc for SMP and UP case */ set_cpu_online(cpu, true); set_cpu_active(cpu, true); + set_cpu_preferred(cpu, true); set_cpu_present(cpu, true); set_cpu_possible(cpu, true); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2e7cde033a31..a45f7c308329 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8690,6 +8690,9 @@ int sched_cpu_activate(unsigned int cpu) */ sched_set_rq_online(rq, cpu); + /* preferred is subset of active and follows its state */ + set_cpu_preferred(cpu, true); + return 0; } @@ -8703,6 +8706,8 @@ int sched_cpu_deactivate(unsigned int cpu) if (ret) return ret; + set_cpu_preferred(cpu, false); + /* * Remove CPU from nohz.idle_cpus_mask to prevent participating in * load balancing when not active -- 2.47.3