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 2CF553806D6 for ; Mon, 8 Jun 2026 16:23:19 +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=1780935801; cv=none; b=DVknDKcIip3ONxlyQaJC2RFcpsa589OapoNvpADAElCzuqTXZsgCjx+6mNxrejAtS82OlhpdNXv41KyxB4NZQ0eqCPzSILkepX/Tw/Dc40bSRYotkaQa1HMRaiUccNTV34IEenb1wDGEMH2fqbL3DRJMNkpk1sXy2GmnMkRIwYE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780935801; c=relaxed/simple; bh=RfF9q680CQSm6Emg04mdI4JVX8VWFhyUqB5Bccv8/+k=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RlFJQaOvXV1eSmXpLuDphOm1YR2XxZ+k8W+Zq7zfP7FNdhgncchkpvWOMcqDxeunrMP8BwWiGIInyHj5eyJ0jNeDJAgt+KKJ+gsuRe+WYtiaLbIczDoghA4wIdexjnQx9eUCxS7VrAkFuTQkh4vU4BJrGyJXs1r5lyn3VDYzuuA= 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=mM8a5dED; 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="mM8a5dED" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 658EhWT44111481; Mon, 8 Jun 2026 16:22:51 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=doslB9 vxW0ZePEplXlSoUpZebsr2UvsOae9ta4FmKlo=; b=mM8a5dED751iRtUoKac/cP IjbFb8h9cEjwGN/xG+o6dGMsHwOm8CN04OEqkfYMiFU6GxPsuAGkqGQHscFZgclR HZ1Ttqnye9a6IpHPcy3tvPl8b4d0LahEL/zhrK1uMNutoanvoM03xQ1CkvRop/e/ 4RM9H8xnMNu6jFpjwweZs/9dnhEifU3qe3p1HmWuiV4roQvyaLbE0txv2IcyvYUC R5QDizxTBxfFd8WB8jpiiA02e/4z3M1yu8Ed+/zBqfY6r8iwnMqDKTjiOn/67eG7 /VxCMQgtSysYiKOiisqqJc1yvSEk6zkoEqPDF14TW1TMbTx9dMULl8mj7cu2D++w == Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4emb23r8ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jun 2026 16:22:50 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 658GJZIs022741; Mon, 8 Jun 2026 16:22:49 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4emwvpx9m0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jun 2026 16:22:49 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 658GMjlf30212614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Jun 2026 16:22:45 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 783BC20040; Mon, 8 Jun 2026 16:22:45 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E9CD420043; Mon, 8 Jun 2026 16:22:43 +0000 (GMT) Received: from [0.0.0.0] (unknown [9.111.15.218]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 8 Jun 2026 16:22:43 +0000 (GMT) Message-ID: <688322d7-660c-4600-a920-6c5f49caa11c@linux.ibm.com> Date: Mon, 8 Jun 2026 18:22:43 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 17/20] sched/core: Introduce default arch handling code for inc/dec preferred CPUs To: Shrikanth Hegde , 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 Cc: 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 References: <20260514152204.481115-1-sshegde@linux.ibm.com> <20260514152204.481115-18-sshegde@linux.ibm.com> Content-Language: en-US From: Ilya Leoshkevich In-Reply-To: <20260514152204.481115-18-sshegde@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=b4uCJNGx c=1 sm=1 tr=0 ts=6a26ec5a cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=UlZ2ukS2HOxIHO2Ec2gA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: 9UUgZPBML_QFMd2D5SO2Tbu9uJyt8aDo X-Proofpoint-GUID: 0szAOh7cXuP4oKdgD-Zgjnv0OftgWDhB X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjA4MDE1MyBTYWx0ZWRfX6mDzyT1A9Pi1 2k4I7u2MpHAo3EdhE6CBy0cTlDDhELn6z3olPjrKbpl1i4g9NgcMkLahBDnd7GInE2O6xW5gzr2 /31fwUQi/k164WvoqAXFYAjl7KGHu9FegblxWRlrhZ9ncKP9uR3hV5LoXuQWL+DUrVwP6+tFwMr dDZYOfLY+OhoDMqNwNS9S2YsZP5miBKwMutpb0Ix6yRzpIuuRkNGZC1PsMYm4W71xdEBE9xexeH f/lykPFNA+ZCc17TqCd98ZgLTtL++vfp9vflxephELEyR1WJJCTSb78+pSLLMkkTEh6POj6aTL+ OQqm3sDAIfb55AvBYLmTx8rdhWyIeged38ZfD9ss6V3Vs96D5ER0NdI/+jXuIhvvXrRqcieE7dM /m8cXjzDrgvRBQNDSx5GtrvTSiwAd2LmrGRJQLTvCk8xz062TVvLqgWqIE3jJ/uSa57fqL1ao+1 OVxt6YG2xX7iAxbwjiA== 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-08_04,2026-06-05_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 spamscore=0 bulkscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 malwarescore=0 impostorscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605210000 definitions=main-2606080153 On 5/14/26 17:22, Shrikanth Hegde wrote: > Define default handlers for high/low steal time. If arch has better > decision logic, may override the default implementation. > > - If the steal time higher than threshold, reduce the number of preferred > CPUs by 1 core. The last core in the intersection of online and > preferred CPUs will be marked as non-preferred. > Ensure at least one core is left as preferred always. > > - If the steal time lower than threshold, increase the number of preferred > CPUs by 1 core. First online core which is not in cpu_preferred_mask will > be marked as preferred. > If all cores are already set to preferred, bail out. > > Increase/Decrease may need to modify the splicing across NUMA nodes. It is > being kept simple for now. > > Signed-off-by: Shrikanth Hegde > --- > include/linux/sched.h | 2 ++ > kernel/sched/core.c | 58 +++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 60 insertions(+) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 738f17d63943..2afbcd70f0ac 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -2529,6 +2529,8 @@ struct steal_monitor_t { > }; > > extern struct steal_monitor_t steal_mon; > +void arch_dec_preferred_cpus(struct steal_monitor_t *sm, u64 steal_ratio); > +void arch_inc_preferred_cpus(struct steal_monitor_t *sm, u64 steal_ratio); > #endif > > #endif > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index a3f65e9c7d30..195e3648b1b5 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -11368,6 +11368,64 @@ void sched_init_steal_monitor(void) > steal_mon.sampling_period_ms = 1000; /* once per second */ > } > > +/* > + * Default implementation of decrementing the preferred CPUs based on steal > + * time. This is simple logic and decrease the preferred CPUs by 1 core. > + * It takes out the last core in the online & preferred. > + * > + * Ensure at least one housekeeping core is always kept as preferred > + * > + * Could be overwritten by arch specific handling. > + */ > +#ifndef arch_dec_preferred_cpus > +void arch_dec_preferred_cpus(struct steal_monitor_t *sm, u64 steal_ratio) > +{ > + int last_cpu, tmp_cpu; > + int this_cpu = raw_smp_processor_id(); > + > + cpumask_and(sm->tmp_mask, cpu_online_mask, cpu_preferred_mask); > + last_cpu = cpumask_last(sm->tmp_mask); > + > + /* > + * If the core belongs to the housekeeping CPUs, no action is > + * taken. This leaves at least one core preferred always. > + * This ensures at least some CPUs are available to run > + */ > + if (cpumask_equal(cpu_smt_mask(last_cpu), cpu_smt_mask(this_cpu))) > + return; > + > + for_each_cpu_and(tmp_cpu, cpu_smt_mask(last_cpu), cpu_online_mask) { > + set_cpu_preferred(tmp_cpu, false); > + if (tick_nohz_full_cpu(tmp_cpu)) > + tick_nohz_dep_set_cpu(tmp_cpu, TICK_DEP_BIT_SCHED); Should the opposite be done in arch_inc_preferred_cpus()? If not, it would be good to write a comment explaining why; this asymmetry catches the eye. > + } > +} > +#endif > + > +/* > + * Default implementation of incrementing preferred CPUs based on steal > + * time. This is simple logic and increases the preferred CPUs by 1 core. > + * It adds the first core in online & !preferred > + * > + * Nothing to do if online == preferred > + * > + * Could be overwritten by arch specific handling. > + */ > +#ifndef arch_inc_preferred_cpus > +void arch_inc_preferred_cpus(struct steal_monitor_t *sm, u64 steal_ratio) > +{ > + int first_cpu, tmp_cpu; > + > + first_cpu = cpumask_first_andnot(cpu_online_mask, cpu_preferred_mask); > + /* All CPUs are preferred. Nothing to increase further */ > + if (first_cpu >= nr_cpu_ids) > + return; > + > + for_each_cpu_and(tmp_cpu, cpu_smt_mask(first_cpu), cpu_online_mask) > + set_cpu_preferred(tmp_cpu, true); > +} > +#endif > + > /* This is only a skeleton. Subsequent patches introduce more of it */ > void sched_steal_detection_work(struct work_struct *work) > {