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 329D01ACED5 for ; Wed, 17 Jun 2026 17:43:22 +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=1781718204; cv=none; b=X0RD+q7JuVcCN0QShccOEOAqZgActQoNeQXuP6tIBvv3ZzcVity97eFbVeFpsB8IxLDsDD0Ki/SA15Lel39g2w341j+DlzkkqAotNGWNF5rfedabHTn4k7xxtOgLfRadsJZN74uofKYgvdqPJ2qVya8Hd3CKNZCjNcazWw+U3zE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781718204; c=relaxed/simple; bh=aLnUUUvVXd2cwLWrask5MDwP37Kns5zzHffS2+k41RA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PN7twQ1DhbkFV7cGDtetyyjWa9DvlO7dB5A/dieAP0i6iv5xrCbD45uLecxoM5Q4dqRMoy2vRZerNS1kkJyJGnliWC7Ig4k7swUvfTKBEBdTSD5aHeVcfxAHfM6xclT60N0o2OCw8KR9WroPgLPSR4t5yv9ZRijkB+gpbUQAiU4= 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=UpAQgdXM; 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="UpAQgdXM" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65HFppZj744621; Wed, 17 Jun 2026 17:43:05 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=xXt+f5 iY38NpN0EYlFQFcXzA56VBaWMPq79UwN2IM9M=; b=UpAQgdXMvxC+MtJGTh4F4Y qcIhc4Mhf1oAWd+v5ES4/8NzuzivOZb3annx5UXw9HvJNreGlESFENlrq0uwx4S1 75+SIMvOF7MeIWmNRhQ1MzBfTFUmXxEKPQq4oA7Rkoa09U1JUPzeg/va0STZyfy4 qhxkoBlbuWzAGVE1MRvmCpeutFj85rISK4oRnY3DmRUFvPQK8cQ8IAwPLAx/LTGU DP21zI0O6PLjC8hhIMLn0IU2u3WPVC4ZL8x40ZLunuLkInHFjAq7lrIfW+ik1QtW RP9v4PzdoebyU9vaG2tqeC/CJ55g73vVSl0dROUnZfVnjEXlxPh6rmt9kGAN7jUw == Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4eueqx474e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Jun 2026 17:43:04 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 65HHYir5018654; Wed, 17 Jun 2026 17:43:04 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4eudvacc70-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Jun 2026 17:43:03 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 65HHh0P655116260 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Jun 2026 17:43:00 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3BAF92004B; Wed, 17 Jun 2026 17:43:00 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2FC3B20040; Wed, 17 Jun 2026 17:42:53 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.28.77]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 17 Jun 2026 17:42:52 +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 v4 04/20] cpumask: Introduce cpu_preferred_mask Date: Wed, 17 Jun 2026 23:11:23 +0530 Message-ID: <20260617174139.155540-5-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260617174139.155540-1-sshegde@linux.ibm.com> References: <20260617174139.155540-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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjE3MDE2NiBTYWx0ZWRfXzPXfFbC0qPk0 Bv9Ggfg4Sj/sBxQX72m4rygl/Q1vISLGaJQfQdkDD0p6WUcMl4keVZ50LUmnv8S8g3q9VKCg9ZO bEVOUxu5mSIEbbXBYspGbYquSI+cXzW7gRkenY3Vfv83AILiNg4sLJ++EJl2TaQZiRGC9L67uuQ 2khInkqX3N/w9NIEm2LPcvAtiYjziu/YFdTGYfmfOm24ZF8x0/HOB8XvPD2Bt8lGHIyT6ZWnZ0e O35Ue0q27C5XXZ9BlWkbYbOgCAwyX9dLPjV1UipYTik759ncWBuzU7y5d4VmbRrXRTMOhZ68D3g 9TFVbSfz118YCYC7pGA6p8mBQdzSB0BFz//W5Z3QBr5AA2vmRZTneWgoD5PX0VuAlrh0fQyIEWN ha8JOtfvOh53id3Y8NWcyUZEKblCLdOJVvdM+JViijs77LceNUVh81PKGQG5XWej3xoWIwLvZbc 9gqz7Jrp6JK7xbzgn3g== X-Proofpoint-GUID: sofkNG8Fm2w1knQCdGX7IQXLLttGcjDG X-Proofpoint-Spam-Info: AW1haW4tMjYwNjE3MDE2NiBTYWx0ZWRfX/2lreMwyPyQ7 8riXSURaGYqHHivUrTlQ0uP0vbN6DzeEkARKNx+kdVb9jZMUMDvKSA7cN08WRCNKjI3bonjYXfe Ua6MS3IupiePcGjhT7EAtrXncDXALu0= X-Proofpoint-ORIG-GUID: wnukW5y3oSgvGOwQc-ZW2jyagyvXkWxL X-Authority-Analysis: v=2.4 cv=auGCzyZV c=1 sm=1 tr=0 ts=6a32dca9 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=0mhcXptKf_jZ1Pm6q6UA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 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-06-17_02,2026-06-17_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 priorityscore=1501 suspectscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606170166 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 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 Signed-off-by: Shrikanth Hegde --- v3->v4: - Make preferred subser of active instead of online. include/linux/cpumask.h | 21 ++++++++++++++++++++- kernel/cpu.c | 14 ++++++++++++++ kernel/sched/core.c | 5 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 80211900f373..30ea64cc1656 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_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,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..c196ba5d8b2a 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); @@ -3154,6 +3159,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. */ @@ -3164,6 +3177,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 2f4530eb543f..9e16946c9d62 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8685,6 +8685,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; } @@ -8698,6 +8701,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