From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 77FEA42B73D for ; Thu, 14 May 2026 15:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778772243; cv=none; b=KLNDgy7nNdEs3H3LwKVdhF4lzHPRe59MPwXjW8Egwv9nVTNim3EHyKgdhcGy544eHfPFhQ6qEfTpXIyWzlZHCmbTY8MNV6nqLNLjODtajwjfNtDRdHfD2RhRNkKgoSU5nL0T5U3VuX/XjmvklSwSUsC/W14WpGvL1igj9mfLMSY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778772243; c=relaxed/simple; bh=+YVtiV401SXmd7F8CnIx4BAHEsv1eYAQS4aEEvvX3lY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kpHWkc/NZnfkTPkuA5QZVHYqP/VownhTB+0B9Hwhj7L+78cdXKqL39IZXzCJhGHh6TPzAnmLcBdLwSdFUodMXAp+r8aTd305i/jJDjM7Ta3IGUq5at0q3FOH8GrdkwH4+tR9XRCkAhjCraCpyAJMIz1uMMzjC92Wc+8bmsHskY0= 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=LcwkMQEo; arc=none smtp.client-ip=148.163.156.1 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="LcwkMQEo" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64E7UHjh2611786; Thu, 14 May 2026 15:23:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=CtVkOH3e9OjgDTnPv QMoOITqrFHDlNiTjwNeN43Hzd8=; b=LcwkMQEoOvTFlQaI0EJ2t8yMTvKQMHIDr wgil0wETCtt5PzOyupk9ck6Yq/PXFPHsOMS4YXjNnavdecpE0mV0/Hr/7KHz4y6q 3MM7Cn/JxF+sd/b0TBkyylpBQmHiXlk5nWRCnoZEawug/h3kdnTn66lLOVq0H5iN cC1TzcdNIS1gt1L5nxff8zPf/lCNJEm5oo+zCJ4u5UysktygamzC5ZCzT0cummjS NTjv8ubP6sxdeJdUXWRdDooVbapFHShFFkTpMPve75KJQaS4dNCRvXgkmoV6L9Pg 1wQot2oc8MbIS8QTKDZ5WePrtqLkSAOWrmrx6wbwwdSa/eAaZfgIA== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4e3nve54c4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 May 2026 15:23:42 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64EF9U5T007925; Thu, 14 May 2026 15:23:41 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4e3nfgmxqh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 May 2026 15:23:41 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 64EFNbj344892638 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 May 2026 15:23:37 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8ABE120043; Thu, 14 May 2026 15:23:37 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F61820040; Thu, 14 May 2026 15:23:30 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.124.213.185]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 14 May 2026 15:23:30 +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 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, mgorman@suse.de, bsegall@google.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 Subject: [PATCH v3 04/20] cpumask: Introduce cpu_preferred_mask Date: Thu, 14 May 2026 20:51:48 +0530 Message-ID: <20260514152204.481115-5-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260514152204.481115-1-sshegde@linux.ibm.com> References: <20260514152204.481115-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=Y/XIdBeN c=1 sm=1 tr=0 ts=6a05e8fe cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=aPx0SrB3icYvFU3L0J8A:9 X-Proofpoint-GUID: QEWx0-lyQjIjpynOzpgG5UvqKS9T3Ixl X-Proofpoint-ORIG-GUID: 3dhhSr9sPSCjQbn50DssNFIHBKPklYX9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTE0MDE1MyBTYWx0ZWRfX23XOkQ/crMli UVlz43ZZTw17uPYd60J6qnbR1EcGt2EjiU8JBIFYCIOwTN2kXK4D4UJoyZwuJAKXb9IOOPi34O0 dMOpfqYYB3xtz8EiX0Y1LU3iYunvDZYuIPbsxmL/o12QWXF1WDfgsa5V1SHzkHEpPGJs86EG4Yg eFfT5bLI1YAB/RctUZE7sngs9XBY8q2CMcEJnPxVj9YIvlnWpfjVdg3Xqt0E8H9OaHDZqe5unB1 6NizcMP0PEHcUJVUMJil1kRlQJtcwJHYMWqYzAglIgAYPJLilmv5gNjJjg9fvfV1ltpzDAsuIRj fKUPm8qH/avwq+yoIZ2EuoMaJkGwapyg0Vi56VGI1SD2rAT6v609uANzlDZnTtHzOasAbv3cSDK eaEHaJyywuw133yFvPn61y1ntw7DOPuH6JRRgjisLCyrKb8dj5GgqfIHeR13YPRkcp+/M0bmXs+ vaWbLhWwMEjojpg/3/A== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-14_03,2026-05-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 phishscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 adultscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605050000 definitions=main-2605140153 This patch does - Declare and Define cpu_preferred_mask. - Get/Set helpers for it. Values are set/clear by the scheduler by detecting the steal time values. A CPU is set to preferred when it comes online. 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 online. Signed-off-by: Shrikanth Hegde --- include/linux/cpumask.h | 21 ++++++++++++++++++++- kernel/cpu.c | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 80211900f373..025ad7778a6c 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -120,12 +120,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_online_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,7 @@ void init_cpu_possible(const struct cpumask *src); void set_cpu_online(unsigned int cpu, bool online); void set_cpu_possible(unsigned int cpu, bool possible); +void set_cpu_preferred(unsigned int cpu, bool preferred); /** * to_cpumask - convert a NR_CPUS bitmap to a struct cpumask * @@ -1256,7 +1265,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 @@ -1294,6 +1308,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 bc4f7a9ba64e..819167cb8bed 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -3107,6 +3107,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(__cpu_preferred_mask); +#endif + void init_cpu_present(const struct cpumask *src) { cpumask_copy(&__cpu_present_mask, src); @@ -3137,6 +3142,9 @@ void set_cpu_online(unsigned int cpu, bool online) if (cpumask_test_and_clear_cpu(cpu, &__cpu_online_mask)) atomic_dec(&__num_online_cpus); } + + /* preferred is always subset of online */ + set_cpu_preferred(cpu, online); } /* @@ -3154,6 +3162,14 @@ void set_cpu_possible(unsigned int cpu, bool possible) } } +void set_cpu_preferred(unsigned int cpu, bool preferred) +{ + if (!IS_ENABLED(CONFIG_PREFERRED_CPU)) + return; + + assign_cpu((cpu), &__cpu_preferred_mask, (preferred)); +} + /* * Activate the first processor. */ -- 2.47.3