From nobody Fri Jul 24 21:29:11 2026 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 8C0563D966A; Fri, 24 Jul 2026 14:08:55 +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=1784902139; cv=none; b=lexQCtVNJd7wfxuJOBrJTv6Jusw07k+vt0zhWikz8PlQr84weA9yqVJ/XgHb4e1THGQMbS1t3A1w4AZml2fgmxsjcsVXaA0OsFHFCX+K925ut9PHDYRJ6Y55ZalzovXvvzJJ4/Q62T2s+N/H6QbSU3MOJMlYB3OwarRLG2C+A9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902139; c=relaxed/simple; bh=lza7gAmu1NvMzOMCe/mEw7H+KQNibNl/rUY8Ja34NoY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IMhPJ9YlD4YCIapLpibCHBwfnZCqGDFJd3gaLZrQS7NCGFLSx7f2kYpZK0fVjgK45V1yJliXmXre/zcFyIQM14E9atn8L5R1AkEfKSpCPdH+axv7FB8wFytjd7IS7sfKvNs+DaVxdkvPBtgbENLCRpGDhWFv+bjHjToLbglKD3c= 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=dJbhphku; 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="dJbhphku" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66ODfofG1994009; Fri, 24 Jul 2026 14:08:29 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=84eDZR6v1SPSl+gau /CA/4fFYnWZbtnOnkAICw3TfgA=; b=dJbhphkuyjUwOUFMKGDFairvLwO/ygSkg ApXY0yaY/dryG2AMX6Mp6rn2nvIGMTMDxBQ5my3APUjJjJNmks2eBPNEVdpmMVZO 61azdwWt/lsG7WximlUrb8b1FMASaDDYJEzUiEzbGLTKeq0Die0EtTKh1HEqyIyY ++IzwanHnSzPc/LOGhriZiZe/4Q8tHsJb1qFK4rS+9HUHzd9/MBkKzmrMkpsvoEa GrZAy6NYPWb/paY16sf1uBh7AcPF0S7H8MyJ0nbgqbHm3Z4BqAgIaQmh/yczDbwM SypBJQoNQVyXDjL4YBQA2xhLkwbhIn8szAjEArBwaKYU0a1CK/IAQ== 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 4fg7ahmcg9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:08:28 +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 66OE4iXx014385; Fri, 24 Jul 2026 14:08:27 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fgktqhca2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:08:27 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66OE8NGi39190940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:08:24 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD03020176; Fri, 24 Jul 2026 14:08:23 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 92A8320171; Fri, 24 Jul 2026 14:08:15 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:08:15 +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, jgross@suse.com, virtualization@lists.linux.dev, kernel test robot Subject: [PATCH v9 01/11] sched/docs: Document cpu_preferred_mask and Preferred CPU concept Date: Fri, 24 Jul 2026 19:37:22 +0530 Message-ID: <20260724140732.2683314-2-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-ORIG-GUID: zfJtBqWYy4RPBgg9Ra0grRIQS4B_uzAN X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX5Nm9c30R9/aR pbK1I1UvrcHZs1wiX2nrgLD8D7CI02N4EL3iISTPnQkEvxAeg+slKx0zwr5762UzumzSXKoBT3R lCUrhefislCRYIgHh5EldQCZCj25NkYQB3JyiGAIAvplUECaXp6ff0mUC5uegoAx3srwys6J801 FMtRa2bvy0doUQUiI+rF+A533Q85dYhKY2haOJkQ+VkcUt/+sMeWx84qykSo80dFIKyIMb59dpW KW8e6wW6seUdaWpr5zm2X2m/4raxnt6gBj1YjUOBpdEPlBMPahiE8jm/EflIbnT5qALiN08KVeY omdh7egm0FLrqhFHHJVlKS+uKzZzr+ZJiPi0E/mgVIZNi7IxUQNxcIgf6w6N4NO1jI49TLnqXJk Qp9L61D8wBVz3aFMKxMDHlr5wfPB35kq2C/T0pL5bnKGvZA52Gl9M9dsgFOgSJuARTIkOk9DF8K UJv/cfA6jAIg4q4PwDw== X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfXxi4KmnWVBiEV vZ73AyK8OZeD9gElBftOQf7mL46f+BAK6BHA2lT2rUqin5AhYgaXY5UOqb0giT96wPGl5bygDCG 6oUtHpNfdtuuNkesYTU+dYnkEmUdlZI= X-Proofpoint-GUID: SkJLJ8YmHLcpd8gHNSfk7wC9QoY1eToF X-Authority-Analysis: v=2.4 cv=SM5ykuvH c=1 sm=1 tr=0 ts=6a6371dd cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VwQbUJbxAAAA:8 a=QyXUC8HyAAAA:8 a=VnNF1IyMAAAA:8 a=d8MiXRUMn4SEn--m04oA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 priorityscore=1501 phishscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Content-Type: text/plain; charset="utf-8" Add documentation for new cpumask called cpu_preferred_mask. This could help users in understanding what this mask is and the concept behind it. Document how to enable it and implementation aspects of it. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202606180717.yNM0yb41-lkp@int= el.com/ Signed-off-by: Shrikanth Hegde --- Documentation/scheduler/sched-arch.rst | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/Documentation/scheduler/sched-arch.rst b/Documentation/schedul= er/sched-arch.rst index ed07efea7d02..0a0a8eadbfd6 100644 --- a/Documentation/scheduler/sched-arch.rst +++ b/Documentation/scheduler/sched-arch.rst @@ -62,6 +62,64 @@ Your cpu_idle routines need to obey the following rules: arch/x86/kernel/process.c has examples of both polling and sleeping idle functions. =20 +Preferred CPUs +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +In virtualised environments it is possible to overcommit CPU resources. i.= e. +the sum of virtual CPUs (vCPUs) of all VMs is greater than number of physi= cal +CPUs (pCPUs). Under such conditions when all or many VMs have high utiliza= tion, +hypervisor won't be able to satisfy the CPU requirement and has to context +switch within or across VMs. The hypervisor needs to preempt one vCPU to r= un +another. This is called vCPU preemption. This is more expensive compared to +task context switch within a vCPU. + +In such cases it is better that combined vCPU ask from all VMs is reduced +by not using some of the vCPUs in each VM. vCPUs where workload can be saf= ely +scheduled which won't increase any contention for pCPU are called as +"Preferred CPUs". + +Main design construct is preferred CPUs are always a subset of active CPUs. +In most cases preferred CPUs will be same as active CPUs, when there is pC= PU +contention, Preferred CPUs will reduce based on the amount of steal time. +When the pCPU contention goes away as indicated by steal time, Preferred C= PUs +will become same as active CPUs again. These policy decisions are taken by +steal_governor driver available at drivers/virt/steal_governor.c + +Scheduling decisions such as wakeup, pushing the task etc, need this +CPU state info. This is maintained in cpu_preferred_mask. +vCPUs which are not in cpu_preferred_mask should be treated as vCPUs which +should not be used at this moment provided it doesn't break user affinity. + +This is achieved by: + +1. Selecting a preferred CPU at wakeup using fallback mechanism. +2. Push the task away from non-preferred CPU at tick. +3. Only select preferred CPUs for load balance. + +/sys/devices/system/cpu/preferred prints the current cpu_preferred_mask in +cpulist format. + +Notes: + +1. This feature is available under CONFIG_PREFERRED_CPU. It is selected + by steal_governor driver (CONFIG_STEAL_GOVERNOR). On enabling the + driver, CPU preferred state can change based on steal time. Without that + driver, preferred CPUs is same as active CPUs. + +2. This feature works for FAIR class only. + +3. A task pinned, which can't be moved to preferred CPUs will continue + to run based on its affinity. But no load balancing happens. + +4. Decision to change the preferred CPU state is driven by kernel. + Hence it shouldn't break user affinities. One of the main reasons why + CPU hotplug or Isolated cpuset partitions was not a solution. + +5. This feature works best only when all the VMs enable the feature as + it is a co-operative scheme. If a specific VM doesn't enable this featu= re + it may end up with more CPUs than others, still should lead to better + performance when seen from system view. + Users who enable this driver must ensure it is enabled in all VMs. =20 Possible arch/ problems =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --=20 2.47.3 From nobody Fri Jul 24 21:29:11 2026 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 D2D90433031; Fri, 24 Jul 2026 14:09:01 +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=1784902143; cv=none; b=FaSNmk6bFR6/+j5OUXA1EWrwdoG6TulXK9Juhmp6o5riXtvFqpS5y4bBloJL2ResbljqtE1GkppsnfHbrKkqzXmnYgt7qMOQyV5BIAVyiHRaXLU59N7K/6GBQPzhAyPNVmnfjTLjUgLdL4d/J+TL1LfZSCJNLxWrlHhPHyoeJLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902143; c=relaxed/simple; bh=gmpHwEuFtj2beAn+ZAbelKhxkrT6blFXZd5T1X5Bdkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RcjTFpqk06tSjTnONUmQuzAdsMzuijujWVcNdOaSaogqBFNv709NG7a2UOKR4h9n4DL2aHKoFVmjKvFHjv1E6Fj7QBQL4DtaV2OvEASlXvPsBMxmgnrE1HJIz1021EXbVwotoqtl/fewkk39IYj+/hvdC9CVpiZRtbf0ftvPS4g= 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=N4H1rF00; 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="N4H1rF00" 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 66ODg0Wa1898392; Fri, 24 Jul 2026 14:08:38 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=sajGA6 s6Wp3SH4D8i6yR6GOXW8i4W+wUtSmULeZX5G0=; b=N4H1rF00mZeFadZaakQy95 aWhdJ4J7gSk4wX8iXLM33RLw4s+3dthUu95UcsCLTJnc/CaEZ9SjLKwoaV8JHMy/ zlJW79h9DWKjVH5wQD49ceLGptEhOlt2/L0YouNzQ+u9Mcc3LS+iIZrRE5WTeO6h 0qIXfNnj836GbjhT7FrKEPpdNwRs90IYOZYbiMGvshHwhI7y4pHVBOL/yBJ6/5YW ezCJNNd6SNaWQpaATtlIJaAY3T129maYJ/0pwcy3wKUI4mW3i2LCbLnoD20Vqeye VRYU2FxKLiQnwd8o9ihVp4dGymTbY7nUwi6ta9RMgDRG1RhZ1LUQLFl/w2uBAYlg == 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 4fg77kme4q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:08:37 +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 66OE4loT013262; Fri, 24 Jul 2026 14:08:36 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgm6wh9uw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:08:36 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66OE8WGU45416884 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:08:32 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AD00B20176; Fri, 24 Jul 2026 14:08:32 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 654CB20171; Fri, 24 Jul 2026 14:08:24 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:08:24 +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, jgross@suse.com, virtualization@lists.linux.dev Subject: [PATCH v9 02/11] cpumask: Introduce cpu_preferred_mask Date: Fri, 24 Jul 2026 19:37:23 +0530 Message-ID: <20260724140732.2683314-3-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=HJXz0Itv c=1 sm=1 tr=0 ts=6a6371e6 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=NEAV23lmAAAA:8 a=VnNF1IyMAAAA:8 a=9QGdkmv71c8RgJbqbJ4A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX4qxSPD6I2ajm 72L7Gm4URZkadFC6wTm8GNeWm4rfAfQR9Lm3uG0lvVAvJnYxMhRuhcG+lFxELGAzmSx1hFw/uUi Cq8ONuB469fqN9orcgxtscOVJQzoa1hbEsBayzey1o4STUOVQp/ZHugFpusxePQrgiky8RxuyfZ 3hNTVp7nJj+DlIHTdNeDQBiGIdXGQIxKVNS8sAOWA+yBE5zIN7pm6jThd9ex8DqFoiJhlq6D9ma DunVhL2FAFhjjZoT0KiOJGEYpmSu+PX+ppkrsYtFTv/EBkoUKphVsQRWwr46B25ZOCfNrKHw5ff +abKaIaxV1gK+YCymUEntHNztuTMQS9Ii64nQ5fi4khrU7DA0VmtWVm1RTKlRJNgRikTmZBk0+Y WPBJw+oKn8GACEAfb3N2qo89chDZTi67HN2V5GMLOmmXGFy2GonIV6QRLHy236XDvUqHwq0dNcE rHrPc+pvCfQ5/RJJxeQ== X-Proofpoint-ORIG-GUID: E_Ojr8MhbSDxsZciDrg2PQajybVat19y X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX0d5W3jXvJHKC KIXC/gr9bE9AyEd3nf5G1kMSEKQ5DSbFSb/HbHU7cMRnTQtEuJL/LXGfTbegaQJA5ptYiTd+kio oI9nutzjTvpjpyNzQl+vatnu+4y4fhI= X-Proofpoint-GUID: aNd3OqVi3Rg9GGrfMkIxQUDYxyAG9eQb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 malwarescore=0 impostorscore=0 clxscore=1015 phishscore=0 spamscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Provide cpu_preferred_mask infrastructure. Define get/set macros which could be used to get/set CPU state as preferred. PREFERRED_CPU config will be selected by the driver which handles steal time values. It is going to set/clear preferred CPU state. This driver will be called steal_governor and it is introduced in subsequent patches. It periodically samples the steal time and decides on 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_governor being enabled. Always maintain design construct of preferred is subset of active. i.e. preferred =E2=8A=86 active =E2=8A=86 online =E2=8A=86 present =E2=8A= =86 possible With PREFERRED_CPU=3Dn, ensure set_cpu_preferred is a nop and get method returns the active state in that case. Signed-off-by: Shrikanth Hegde --- include/linux/cpumask.h | 24 ++++++++++++++++++++++++ kernel/Kconfig.preempt | 4 ++++ kernel/cpu.c | 6 ++++++ kernel/sched/core.c | 5 +++++ 4 files changed, 39 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index d3cda0544954..34d08a3d80e1 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) =20 extern atomic_t __num_online_cpus; extern unsigned int __num_possible_cpus; @@ -1164,6 +1172,12 @@ 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, (dy= ing)) =20 +#ifdef CONFIG_PREFERRED_CPU +#define set_cpu_preferred(cpu, preferred) assign_cpu((cpu), &__cpu_preferr= ed_mask, (preferred)) +#else +#define set_cpu_preferred(cpu, preferred) do { } while (0) +#endif + void set_cpu_online(unsigned int cpu, bool online); void set_cpu_possible(unsigned int cpu, bool possible); =20 @@ -1258,6 +1272,11 @@ static __always_inline bool cpu_dying(unsigned int c= pu) return cpumask_test_cpu(cpu, cpu_dying_mask); } =20 +static __always_inline bool cpu_preferred(unsigned int cpu) +{ + return cpumask_test_cpu(cpu, cpu_preferred_mask); +} + #else =20 #define num_online_cpus() 1U @@ -1296,6 +1315,11 @@ static __always_inline bool cpu_dying(unsigned int c= pu) return false; } =20 +static __always_inline bool cpu_preferred(unsigned int cpu) +{ + return cpu =3D=3D 0; +} + #endif /* NR_CPUS > 1 */ =20 #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) diff --git a/kernel/Kconfig.preempt b/kernel/Kconfig.preempt index 88c594c6d7fc..de789b274ba3 100644 --- a/kernel/Kconfig.preempt +++ b/kernel/Kconfig.preempt @@ -192,3 +192,7 @@ config SCHED_CLASS_EXT For more information: Documentation/scheduler/sched-ext.rst https://github.com/sched-ext/scx + +config PREFERRED_CPU + bool + depends on SMP && PARAVIRT 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); =20 +#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); =20 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); =20 + /* preferred is subset of active and follows its state */ + set_cpu_preferred(cpu, true); + return 0; } =20 @@ -8703,6 +8706,8 @@ int sched_cpu_deactivate(unsigned int cpu) if (ret) return ret; =20 + set_cpu_preferred(cpu, false); + /* * Remove CPU from nohz.idle_cpus_mask to prevent participating in * load balancing when not active --=20 2.47.3 From nobody Fri Jul 24 21:29:11 2026 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 8E43142E8DD; Fri, 24 Jul 2026 14:09:11 +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=1784902154; cv=none; b=rKBPRDpMgQmEBA+wC1dBRdXqijAynOpYWZvKZ0JjbvwnrwMYmurQ73kXhf54DvLK393NFt7hphHevvIymG3RyTZFjpWtb5CA38c5QTL42P2V+SsG6d1jmviXmUMqOlhleYcsuJ81MARd2WFFP9BE8d/AfNuv+p98fSzHUODAjKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902154; c=relaxed/simple; bh=6228di3K+K40oi6cCOvgEmLnJ4IaBH3W+zV/3UUL2cY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z55y5FrSyTAfALCLUbjs+kTnEmGmAMZ3XKhk5R3Ku2AQhUZ74IWiKI1jTGSmOt1HANyLKhnh99y+WwHMOfEd6P9NxVim98eb/dR6BR85Z1oTWNBZG2wLOgHmjbWACvxsE43OAYN2XgXfmIDNHJijt053c08Dr1d7Ds9mvkQunqk= 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=tZnPYSwP; 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="tZnPYSwP" 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 66ODg0sR1898334; Fri, 24 Jul 2026 14:08:46 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=cPfhGVrlIhSc9SxNl 84q15+rcHKUKn8NOKKLryxp2NU=; b=tZnPYSwPGpBEm0iferPknDj/TQcqpZFt6 nb3OqrOLum9zenJqhlEtjsyqe77c+ZYZuJ5GHFLdKig6/tQLFODcL1xjE4GiTDPp cGGNbZAL39/Z4bhUy3u/NJj1yXA2mr+vuz8EXmgeTCSTVv82DcDpPmqz1+34gSQR FaE1UnGhatOmIAaqEonk8smCYf6TVuHPCbBFUMZaFvyT4JtS15HhdWWpBGRbzxJB +GJKUU69XKX10HfdSrHah5+Merj0B4WH41u4ay7av7ICWDm3K8AIx7bC9z46shLw oRwnmpy7CR47XH8XU3xp/LnzQec56D7gyFp5Ro20mM9B7kl4goi6w== 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 4fg77kme5b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:08:45 +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 66OE4g5D013230; Fri, 24 Jul 2026 14:08:45 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgm6wh9v6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:08:44 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66OE8exv48038334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:08:41 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBE6220176; Fri, 24 Jul 2026 14:08:40 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 27FE720171; Fri, 24 Jul 2026 14:08:33 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:08:32 +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, jgross@suse.com, virtualization@lists.linux.dev Subject: [PATCH v9 03/11] sysfs: Add preferred CPU file Date: Fri, 24 Jul 2026 19:37:24 +0530 Message-ID: <20260724140732.2683314-4-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=HJXz0Itv c=1 sm=1 tr=0 ts=6a6371ee cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=VwQbUJbxAAAA:8 a=Tj8IOOKMsRt27BSU_nUA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX/Hssb720al8b OemehvFFUjZU5Oee/28d8A2qRpfKHh42MsZ6FpBNpRBqGqaEQdMKvAEXdktzXK5mcT6CZjp3MgN NCAuywNHIJNlfFXd4pp8qR0e1jO/ubTS/xfdLJLtWWNJ35MW5VfKCcva62kjmEg75O4AMO3WC8Y oVl1HtRpfecUj/Qme6jwLQ9MNbHPTwKMxXsDnA3yeyvG9nRzOZTRB4fYQSjdHEhQNawu7e6Qywb L5g6Zx+Jpb8xP97oXRxuWkU7zRT+9nxacFlvO+ElP7zXnYFuROqbcqo8YUkxqjFOOaeTDXQKU6G S9qkJV7wHmD0MsW6teWK3Xk+CeYTeP4g6CgedBEDdbglBojP2/jFiXdTanzMlXyzE2FrNd0PkYq JNk/qn4O34CQ1OUTKTKnzhKDXmRh7dX4+fdOAN0lf5xha0bbOu9uMrg+xmNRqlEYZtLfoHExguW p6t+50SPSoKDd30LuFw== X-Proofpoint-ORIG-GUID: cgBAhnZQYFIoBVBGjB4vV7_c1y7YgfTH X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX94ngc9Hf768e pHU12CgEy/k/hUIYr7mTsJZi5EQAfB2DwGzHUKWkw/8fOQHABIQ3swJI4+oOa0OsXBr6F4qV9Gl 6SfAiadGqYxjt0pl8VQ6XaUaU3uNUpE= X-Proofpoint-GUID: yFy6dgR4DU7Y35uG7-ys7y_btMvsbmQX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 malwarescore=0 impostorscore=0 clxscore=1015 phishscore=0 spamscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Content-Type: text/plain; charset="utf-8" Add "preferred" file in /sys/devices/system/cpu This would help - Users to quickly check which CPUs are marked as preferred. - Userspace daemons such as irqbalance to use this mask to send irq into preferred CPUs. For example: cat /sys/devices/system/cpu/online 0-719 cat /sys/devices/system/cpu/preferred 0-599 <<< Implies 0-599 are preferred for workloads and 600-719 should be avoided at this moment. cat /sys/devices/system/cpu/preferred 0-719 <<< All CPUs are usable. There is no preference. Signed-off-by: Shrikanth Hegde --- Documentation/ABI/testing/sysfs-devices-system-cpu | 14 ++++++++++++++ drivers/base/cpu.c | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documenta= tion/ABI/testing/sysfs-devices-system-cpu index 82d10d556cc8..676412c46b2a 100644 --- a/Documentation/ABI/testing/sysfs-devices-system-cpu +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu @@ -806,3 +806,17 @@ Date: Nov 2022 Contact: Linux kernel mailing list Description: (RO) the list of CPUs that can be brought online. + +What: /sys/devices/system/cpu/preferred +Date: July 2026 +Contact: Linux kernel mailing list +Description: + (RO) the list of preferred CPUs applicable in + paravirtualized environments. + + The steal governor driver dynamically adjusts this mask + based on observed steal time. Scheduling tasks on + CPUs outside of this list may lead to performance + degradations due to underlying physical CPU contention. + + See Documentation/scheduler/sched-arch.rst for more details. diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 19d288a3c80c..5da2a96fb37e 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -391,6 +391,15 @@ static int cpu_uevent(const struct device *dev, struct= kobj_uevent_env *env) } #endif =20 +#ifdef CONFIG_PREFERRED_CPU +static ssize_t preferred_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_preferred_mask)); +} +static DEVICE_ATTR_RO(preferred); +#endif + const struct bus_type cpu_subsys =3D { .name =3D "cpu", .dev_name =3D "cpu", @@ -531,6 +540,9 @@ static struct attribute *cpu_root_attrs[] =3D { #endif #ifdef CONFIG_GENERIC_CPU_AUTOPROBE &dev_attr_modalias.attr, +#endif +#ifdef CONFIG_PREFERRED_CPU + &dev_attr_preferred.attr, #endif NULL }; --=20 2.47.3 From nobody Fri Jul 24 21:29:11 2026 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 C82B041D62A; Fri, 24 Jul 2026 14:09:35 +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=1784902177; cv=none; b=qXrdt4E5HV24pbQaNcwkXcDOJbf5IoYlBAkiSnMeVuzWXW83TlxmVQ96FDPq7gVAmTiOzt2jaHFUaJbmpe5UhUfvLSCpX7o7Y+27HMAB2mnKQP+b9fhnFHQV59mCBgLLOlooOvJxTFE/PCkUO1EfNZLiHM2ZY6JebEDkBe972KM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902177; c=relaxed/simple; bh=r60YBsYQkwwNOoF0Ymgd/+uEg0+fYJIikjKDd5ytK1k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aAb2nzVYHp7+Lj6HpkgIuooLCn8d6pZxtzK7/914mD5vVN0lKvoyprPnrVOeemXOAJgVS7tTV1RYQznl0HZvzwcjGGUEjbgg4Wj4yWdkjp9HhQ3OEkZIoxsQkD8adK6tjgwMK6sA060rGNIHQne2wPX8WMVcbYwYmRJp+7oxFeM= 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=sGas3Mc/; 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="sGas3Mc/" 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 66ODffIZ1973724; Fri, 24 Jul 2026 14:09:10 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=AUk7cOLmOOFx4Bh91 AksrlknVURTsH5xT72L6KGYGbA=; b=sGas3Mc/hpnci3vuM1OnyiYeQ/3TiluUd PcgxQHeNJOh0cq90hIolM3xO1wvtX2/ZTzuWqV4thUCRTRLrH75xM5UtDl2VUuXr liNTB+7X0m8vreuHj1GamtkWOr8CrB27SYZQbIzDes/OijeLh+yJNmdLR0/QyNcM 4r76w54xiKTCzM0o1gPGoSsU04J4kiDEqZ8vYzFKO4vYIk0mNN3QGrr09Ibhytkp CYos9C27llp5KAQ6nxt4MTmUUyiAAxo0oIZagCR740aLElSTnvFs3P9VfO+IiWfs W1WhE8CpwIkiV9iuVWLUeeUcUuPI0ZziE9lcyI+KIqK2cY1y9LgfA== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4fm8h509vs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:09 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 66OE4mVg029231; Fri, 24 Jul 2026 14:09:08 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fgp1gs10r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:08 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66OE95PL43057430 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:09:05 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5EFE220176; Fri, 24 Jul 2026 14:08:49 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 62C6920171; Fri, 24 Jul 2026 14:08:41 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:08: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, jgross@suse.com, virtualization@lists.linux.dev Subject: [PATCH v9 04/11] sched/core: Try to use a preferred CPU in is_cpu_allowed Date: Fri, 24 Jul 2026 19:37:25 +0530 Message-ID: <20260724140732.2683314-5-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX4lz3isBmATZL 9Zr3FgWE42TP7JRJ/DiYj4gvI2qg0yt6f5LuyVvgki13th9VvBwuQMIuWhMkQoydPZU4eiP+rkW oDgLkxjNMZAf1XkoIO1ijkttmVyCU/A= X-Proofpoint-ORIG-GUID: IzPvZt21JDwpNuL3WIEgkOuw78Zb1r7L X-Proofpoint-GUID: YNfNk_lDyvdd6oIgdWIV3Uip4YIGjLHL X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX8yqmC1tXaJWz HuSB5PDfn2RNge9o4M4wElyFklqeEuLm8azGLW7F4k3VY4ll+U1zgE0BTreT1EOaqChwEADc8/y XmysOhPr4aJXJ3yY6AVpeuXA5GXIuJjsxpbbR7l4z/x8/vHBwrwqFo/PYcrpSfS4MWW/PCwkqJE qQKqtsRVQnz7UnG/eB+JAc2YTManpfisyN8PGJ+T9t3cLgWA/fzYK1fQCj6vMQhcEE47KhkAbhR tDT7b34qiseOLDvA30VVkuZobuhZVT7oeK0F1O+1cV/pnS63bMohXaJRdOqlvNNmn5RTcEvcpoh FndV0JCk9K2MGdiAIwMOurwEtwqg0dCurkR5y8jO+NacUo0tk6xujUbYzW4KhlSyaPOY1128mQG dqneXbUIyDS1Gaom+BoOV8Xas5xNlgL/9mgpwePZRsL4IU6TnYu147OeDCxPfHz63CNp2f8OfW4 w+HUtIaJF2IaISqF2eg== X-Authority-Analysis: v=2.4 cv=du3rzVg4 c=1 sm=1 tr=0 ts=6a637206 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=7HQO46LoG9f-b4O6KL4A:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 malwarescore=0 spamscore=0 impostorscore=0 phishscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Content-Type: text/plain; charset="utf-8" When possible, choose a preferred CPUs to pick. This is essential to maintain user affinities when preferred CPUs change. A task pinned on non-preferred CPU should continue to run there, since this is non-user triggered. If CPU is non-preferred and task can run on other CPUs which are currently preferred, then choose those other CPUs instead. This is decided by checking cpus_ptr and cpu_preferred_mask intersect or not. If yes, task has other preferred CPUs, it can run there instead. Overhead is minimal when CPU is preferred. Push task mechanism uses stopper thread which going to call select_fallback_rq and use this mechanism to pick only a preferred CPU. This takes care of wakeup path for FAIR tasks too. is_cpu_allowed is called to ensure wakeup happens on preferred CPUs. With that, additional checks in available_idle_cpu is not necessary. For majority of the cases this would still keep select_fallback_rq as O(N). task_has_preferred_cpus which is O(N) is called only if !cpu_preferred. Then task running there is expected to move out. So subsequent it should run on preferred CPU. This becomes O(N**2) only for tasks pinned only non preferred CPUs. That is rare case. Signed-off-by: Shrikanth Hegde --- kernel/sched/core.c | 12 ++++++++++-- kernel/sched/sched.h | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a45f7c308329..9e8eec4451b6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2509,8 +2509,12 @@ static inline bool is_cpu_allowed(struct task_struct= *p, int cpu) return cpu_online(cpu); =20 /* Non kernel threads are not allowed during either online or offline. */ - if (!(p->flags & PF_KTHREAD)) + if (!(p->flags & PF_KTHREAD)) { + /* Try to use preferred CPU if task's affinity allows */ + if (task_can_sched_on_preferred(cpu, p)) + return false; return cpu_active(cpu); + } =20 /* KTHREAD_IS_PER_CPU is always allowed. */ if (kthread_is_per_cpu(p)) @@ -2520,7 +2524,11 @@ static inline bool is_cpu_allowed(struct task_struct= *p, int cpu) if (cpu_dying(cpu)) return false; =20 - /* But are allowed during online. */ + /* Try to keep unbound kthreads on a preferred CPU if possible. */ + if (task_can_sched_on_preferred(cpu, p)) + return false; + + /* Otherwise, they are allowed to run on online CPU. */ return cpu_online(cpu); } =20 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 26ae13c86b69..6de6366f2faa 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -4230,4 +4230,16 @@ DEFINE_CLASS_IS_UNCONDITIONAL(sched_change) =20 #include "ext/ext.h" =20 +static inline bool task_can_sched_on_preferred(int cpu, struct task_struct= *p) +{ + if (cpu_preferred(cpu)) + return false; + + /* Only FAIR tasks honor preferred CPU state */ + if (unlikely(p->sched_class !=3D &fair_sched_class)) + return false; + + return cpumask_intersects(p->cpus_ptr, cpu_preferred_mask); +} + #endif /* _KERNEL_SCHED_SCHED_H */ --=20 2.47.3 From nobody Fri Jul 24 21:29:11 2026 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 C840642124B; Fri, 24 Jul 2026 14:09:35 +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=1784902177; cv=none; b=WuIbWaIgEOc1jXSajHeLBELBDbZXx1sBEsUG1ng6mijAukrlhpV4u0JiFZcTplvP3+SvGxOKwZvxwwLnjmafHiR3tKuTddEEAfE3oYw6N0a8A0BEaj8gR33G4y7l3NdjSWFXQzwqvu7nuz8j3lLcse4Da8dGtgZNRRUTaKqCdBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902177; c=relaxed/simple; bh=mogs20aHP34NhTa3btGIMuXI02JCgfTm/y3ZNbaFR4w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DgVI7OII8rlmJDYFpWFy8R86uIBngDfIT8Kt/53IaFYZD0imJr0D38S1256h2Nu4LHuHp+ouHbQvHGZ1jpnXdyJsJG95UJQGN0dKvFQb5DRyf1VriF+PdM+IwRZlpWqWHYQhzd2zxGxW7bLmtpRfub1sP7WmWjW5NY588ZxXYnI= 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=RVYb7gtH; 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="RVYb7gtH" 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 66ODfdIZ1992736; Fri, 24 Jul 2026 14:09:13 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=qxM/3vfEnWBwdX/qG crMqWJT1i63t6l50dahfJlucf8=; b=RVYb7gtHYjSR4MPxS94hiDEk/uUPnVrSJ PjXEkN2xZmM5KT+oR+7ZHQyDbOvJjltQpPAm+10Clk4RdqiYrJ6dA0j7yctqNnoQ JG0d4pGbYWF5zHCOJWaVjzYHjhOsHxeIWPyycwSubWuYJRzrw/+S3w7tYZlDoy5g uxjRWzu3u8QjqsSQNJTZqreLHfGc2DPny6rMqgPfDBtECzR8xFS2zLnYsZoDtDQz Xdy7DUpRyxaylrH/i06E4VK3fx3SUYJ9GQBTWzrbtSDS36VHV7D+1nvHOsdahopF hOGD8Rwqz4HbQ5ohnzUAa/ezPadbjOgAFeEOHHQOzKwlyBUVUMBcA== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4fm8h009us-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:13 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 66ODo3Pr024919; Fri, 24 Jul 2026 14:09:11 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgnahh5k5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:11 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66OE97js45941206 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:09:07 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C56BB20171; Fri, 24 Jul 2026 14:09:07 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3ED520177; Fri, 24 Jul 2026 14:08:49 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:08:49 +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, jgross@suse.com, virtualization@lists.linux.dev Subject: [PATCH v9 05/11] sched/fair: Load balance only among preferred CPUs Date: Fri, 24 Jul 2026 19:37:26 +0530 Message-ID: <20260724140732.2683314-6-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=LdcMLDfi c=1 sm=1 tr=0 ts=6a637209 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=2Q5jPFoXVaBPfP7xRooA:9 X-Proofpoint-ORIG-GUID: ZUYqW2vUTDVSMu8W5ZiUi-GuKjdFPCvZ X-Proofpoint-GUID: xjJni0JwHTSuGFoqhXiE241AQaqR3A-m X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX9bCJsuRjGdrA xY4WLcxQKyG6bH5EKkeWT5dDI+56bQe8m1sYBE4o9Q0KQ6Ao6Y2dqcKobyGLca9FFGNn46e33kO kc/e6qJbRQuglQyr+hiw9bsDKi5bZ2jtrg8773RMmC+EF6isHUWj1WxdoQCcuisIpARECzmA2gM 2sXGazSYN3J8kLxfn0lgwsrRIm0rYgyCiMWhJQBH/PC2Yg/i7jeUj8to5kds9l5afkEC6tgSgdC Gs1z4XuoawrdD18v0FI2AWcgkOrh9ig/f6+nz/7FzHGllygk78UBjkwFhVIkQf6RIBUtQphCaUN qA+pMskrWxLKUD/vALsdp0XSNiVGgjB0ZIpZeW0apRjMkj+qFkKmxHci9U+DQPOhVgYhQQkLVzq 9eA1Vxnye0jxaZzsrq5dXCEXoNmwN4GOo+Q8Bx8Qj7Eq4B9HGc/OH0bJKLaAzsOWp3Ue6Msy6/g AeBo+K1MPPaBJbPm+qA== X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfXxk3zJeaMxdQa B0wK5MQ9trhR7Rd4VH7jF7PuRvZj1EDDsNsWqwn0E4Ant4JpY13RNzkWZKU9hUXoDkQIXJZYk08 JEltstOTn7okQgd8NE6xkbfnnFbZdp4= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 malwarescore=0 clxscore=1015 adultscore=0 priorityscore=1501 phishscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Content-Type: text/plain; charset="utf-8" When cpu is marked as non preferred, any load pulled towards it is pointless since in the next tick task will be pushed out again. So, Consider only preferred CPUs for load balance. This makes it not fight against the push task mechanism which happens at tick. Also, this stops active balance to happen on non-preferred CPU pulling the load. This means there is no load balancing if the task is pinned only to non-preferred CPUs. They will continue to run where they were previously running before the CPUs was marked as non-preferred. Bailout early for NEWIDLE and IDLE balance as load balancing is done only on preferred CPUs. Signed-off-by: Shrikanth Hegde --- kernel/sched/fair.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index df8c9c2c7918..12f5b7de28d2 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -13399,7 +13399,7 @@ static int sched_balance_rq(int this_cpu, struct rq= *this_rq, }; bool need_unlock =3D false; =20 - cpumask_and(cpus, sched_domain_span(sd), cpu_active_mask); + cpumask_and(cpus, sched_domain_span(sd), cpu_preferred_mask); =20 schedstat_inc(sd->lb_count[idle]); =20 @@ -14337,7 +14337,8 @@ static void _nohz_idle_balance(struct rq *this_rq, = unsigned int flags) update_rq_clock(rq); rq_unlock_irqrestore(rq, &rf); =20 - if (flags & NOHZ_BALANCE_KICK) + if (flags & NOHZ_BALANCE_KICK && + cpu_preferred(balance_cpu)) sched_balance_domains(rq, CPU_IDLE); } =20 @@ -14481,10 +14482,8 @@ static int sched_balance_newidle(struct rq *this_r= q, struct rq_flags *rf) */ this_rq->idle_stamp =3D rq_clock(this_rq); =20 - /* - * Do not pull tasks towards !active CPUs... - */ - if (!cpu_active(this_cpu)) + /* Do not pull tasks towards !preferred CPUs */ + if (!cpu_preferred(this_cpu)) return 0; =20 /* --=20 2.47.3 From nobody Fri Jul 24 21:29:11 2026 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 C5FD74908B7; Fri, 24 Jul 2026 14:09:43 +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=1784902185; cv=none; b=je6QybFzSimPCbwNRJrn04+DbdoYqhVlsY8Qc1bu+96Do+t9gySKPh7wV1UZhOyinCgiNOFKzFnNG7uzMCghGMo/PQb4k0J0KRMHdHPF/eJzJUBMVPKCJZ9ewllbyaTuetbwUw1+/vGHSWhcLuuQ9WhWXmki2fMuRlpgh9MLgSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902185; c=relaxed/simple; bh=6CVIJ23rx2F1q/8wVuK5hcqZDwr+T57KuQc2qkWXlrA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XIZ3ouv01ggLCREpMedQ8srhepP56Rn6K5q5nQCq8A8WdhhJ9JRJqGDxtgf+MrVffOkUnvt4l39YOSAF+Em/+BIWB/5bfNMcEj/GjsZmiHIwlnH7RDjchaIXgFWesnG/eHPVDXPi2BuLZiV2MEEVLyhvxW0mQKzQyuBRa11cwsA= 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=F+vx5+3H; 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="F+vx5+3H" 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 66ODg0Gs1898352; Fri, 24 Jul 2026 14:09:22 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=Qvp7lKASIi6FxhulV 1QnpUj/cv0Gt58b7Gz/8zmDO4Y=; b=F+vx5+3Hk4rAvejBTgJaQsAG2fkcKSohz /HCiNGfCz8ICiIJKPAwxRn26RFhjLp3Oc9QbU5p4F3sJfiMxLkkMNuTb2H5uHDUW bb13ferKwHAur/Wssa7Z4z1ktkZ3G79zGOHQvjwhWUYF0rVc6cmwDP42iPSe/s3Z gFL4XDHecudhccqwmG/VXLEfHy61cYhlL+OQAzv3KyY0oItmXADMZc97QjDtbT5N ZoYVufRxyxQfkgX6MPTJ+Bw4nGV7fP6pxYGFcqHY8gfLkivzsYmngSNPKxUxRF2z /kYM4zoL32/t0W+pPkZzZBB77cI/8cflDCJBjoB5/C3/tLlv4CCeg== 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 4fg77kme7p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:21 +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 66OE4iFl009171; Fri, 24 Jul 2026 14:09:20 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fgpgyrxd7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:20 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66OE9GDS42729908 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:09:16 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9A51620176; Fri, 24 Jul 2026 14:09:16 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3968820171; Fri, 24 Jul 2026 14:09:08 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:09:08 +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, jgross@suse.com, virtualization@lists.linux.dev Subject: [PATCH v9 06/11] sched/core: Push current task from non preferred CPU Date: Fri, 24 Jul 2026 19:37:27 +0530 Message-ID: <20260724140732.2683314-7-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=HJXz0Itv c=1 sm=1 tr=0 ts=6a637212 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=rPhwLmmYJdnLsqmuV48A:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX6jMXo3wulaPz zmWJK5IAmu2DuNxpfLkEjgJd8mgCPWXgcVhc8O6MBugHF10jDph3YPX7HvDoLTUz/4Ry6sosf7l hBFHfmfKtSJKqYLUIlmhRHl8LH826jf+XDlITFbtzlTGZYH5sfqakbawXiarxCcQH0mIZiUNFXq XeoSJHng6QGwUUmTz+BGWSpFshNjVSJDm72FWSGj6qyJHLn8HLOxWHP6jF2Ht9ePDIwCsSjUsDV k3fixqvbEtEj+tYcdRdzXKZV6UvNm1iEWvwxq2LeQOUtbveyhG2xjZT6vYU32OLHnLIV0WXwI1t 5KvNr5kZwHSRnQI0L9XylJmqgN15RAueS5pjGD7jprzTXa0j4bftog+e/FWv8od5BqmEIeCfcDn rA914uTkfRcV1GwGbKrubD7Im4yERCv5WTvUJPp8SpwwIlIekbAWsS/qtS4vMi0rNfz77sWVHUg jere8zzK4b2Ynrc8s7w== X-Proofpoint-ORIG-GUID: OlU09TAilH0cJ-1hjxNWLpgzTQLsIBmP X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX9YxyABk1F719 vm2RlN76UdE+kLcn0zCDTZydfvVyOXqd81jt4PTXMZAaTgKpjfg4OzpZnr5LXl1YM7BDsmZcUXx x77Se8HOO3CftHapjce0ccqz0tAyPgU= X-Proofpoint-GUID: MtkJlG71amT934T1RP_53hlT7mD88ZGT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 malwarescore=0 impostorscore=0 clxscore=1015 phishscore=0 spamscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Content-Type: text/plain; charset="utf-8" Actively push out task running on a non-preferred CPU. Since the task is running on the CPU, need to stop the cpu and push the task out. However, if the task is pinned only to non-preferred CPUs, it will continue running there. This will help in maintaining the userspace affinities unlike CPU hotplug or isolated cpusets. Though code is similar to __balance_push_cpu_stop and quite close to push_cpu_stop, it is being kept separate as it provides a cleaner implementation with CONFIG_PREFERRED_CPU. Add push_task_work_done flag to protect work buffer. Works only with FAIR class. For now, only current running task is pushed out. This keeps the code simpler. In future optimization maybe done to move all the queued task on the rq. Signed-off-by: Shrikanth Hegde --- kernel/sched/core.c | 78 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 8 +++++ 2 files changed, 86 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 9e8eec4451b6..704043531b24 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5774,6 +5774,9 @@ void sched_tick(void) unsigned long hw_pressure; u64 resched_latency; =20 + if (!cpu_preferred(cpu)) + sched_push_current_non_preferred_cpu(rq); + if (housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE)) arch_scale_freq_tick(); =20 @@ -11292,3 +11295,78 @@ void sched_change_end(struct sched_change_ctx *ctx) p->sched_class->prio_changed(rq, p, ctx->prio); } } + +#ifdef CONFIG_PREFERRED_CPU +static DEFINE_PER_CPU(struct cpu_stop_work, npc_push_task_work); + +static int sched_non_preferred_cpu_push_stop(void *arg) +{ + struct task_struct *p =3D arg; + struct rq *rq =3D this_rq(); + struct rq_flags rf; + int cpu; + + if (cpu_preferred(rq->cpu)) { + scoped_guard(rq_lock, rq) + rq->push_task_work_done =3D false; + put_task_struct(p); + return 0; + } + + raw_spin_lock_irq(&p->pi_lock); + + /* This could take rq lock. So call it before rq lock is taken */ + cpu =3D select_fallback_rq(rq->cpu, p); + rq_lock(rq, &rf); + rq->push_task_work_done =3D false; + update_rq_clock(rq); + + context_unsafe_alias(rq); + + if (task_rq(p) =3D=3D rq && task_on_rq_queued(p) && + !is_migration_disabled(p)) + rq =3D __migrate_task(rq, &rf, p, cpu); + + rq_unlock(rq, &rf); + raw_spin_unlock_irq(&p->pi_lock); + put_task_struct(p); + + return 0; +} + +/* + * Push the current task running on non-preferred CPU(npc). + * Using this non preferred CPU will lead to more contention + * in the host. So it is better not to use this CPU. + * + * Since task is running, call a stopper to push the task out. This is + * similar to how task moves during hotplug. In select_fallback_rq a + * preferred CPU will be chosen and henceforth task shouldn't come back to + * this CPU again. + * + * Works for FAIR class only. + * + * If task is affined only on non-preferred CPUs, no point in moving it ou= t. + */ +void sched_push_current_non_preferred_cpu(struct rq *rq) +{ + struct task_struct *push_task =3D rq->curr; + + scoped_guard(rq_lock, rq) { + /* Push the task if its explicit affinity allows */ + if (!task_can_sched_on_preferred(rq->cpu, push_task)) + return; + + /* There is already a stopper thread. Don't race with it. */ + if (rq->push_task_work_done) + return; + + rq->push_task_work_done =3D true; + } + + /* sched_tick runs with interrupts disabled. */ + get_task_struct(push_task); + stop_one_cpu_nowait(rq->cpu, sched_non_preferred_cpu_push_stop, + push_task, this_cpu_ptr(&npc_push_task_work)); +} +#endif diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 6de6366f2faa..80c02e2c09eb 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1277,6 +1277,8 @@ struct rq { =20 struct list_head cfs_tasks; =20 + bool push_task_work_done; + struct sched_avg avg_rt; struct sched_avg avg_dl; #ifdef CONFIG_HAVE_SCHED_AVG_IRQ @@ -4242,4 +4244,10 @@ static inline bool task_can_sched_on_preferred(int c= pu, struct task_struct *p) return cpumask_intersects(p->cpus_ptr, cpu_preferred_mask); } =20 +#ifdef CONFIG_PREFERRED_CPU +void sched_push_current_non_preferred_cpu(struct rq *rq); +#else /* !CONFIG_PREFERRED_CPU */ +static inline void sched_push_current_non_preferred_cpu(struct rq *rq) { } +#endif + #endif /* _KERNEL_SCHED_SCHED_H */ --=20 2.47.3 From nobody Fri Jul 24 21:29:11 2026 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 A455B4908B7; Fri, 24 Jul 2026 14:09:53 +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=1784902194; cv=none; b=JyEIuKxOfgKEQseo1/BKbT/3f2+NIWTFbEDMc/e0/+uErsd0KSD8vQdQIGE6eOE8LGTgHxDsoItC4mSqIebLEQJZ5G0Xp/32AT4cDfpfT1trwaIgY24zU1U3eWrp6anDf7Ri/ELCL5//9IZ3jpVjdfk89l1fa4FuIrhKRQ9Ow5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902194; c=relaxed/simple; bh=GKJDo8AI7wWFoFr67ephXxtE17uqG5Sitcmc2r3sofM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lOcZHlk4V18iepoIKEtd8Wqq8yyXu1y/02bhe05WZLxqUnsUHFpz2fWbcsfOvmBRUlyNMwhbXT8K/vJc2GgudKU6hDszTKgrpygR5Ip0K9zNax2DepWaRXdhAnNq1FQfiX9VmLSSU7Rhx3Ih3bGRRFFd8U8A2Lb0Nc5u2+tpgwU= 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=KyGGavFz; 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="KyGGavFz" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66ODgCsH1994940; Fri, 24 Jul 2026 14:09:30 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=b2ibZAPLvpNMWrXYA z/XxHR3KuVpRAIfxZuRDDmAorg=; b=KyGGavFzufNm+gBFqL2Ht4ABa0Mzlcc8f ZlID5pi/3BMHCil6WszwhQKUYsG0hn2ELeR/gzGkA03YijOk0NKZ+qaq3+qz+sdv yhH1PPLI2C0AW2xEwdX2ziFUcpomO8fJaGQNRkBhIU0y8awI1Gx8t7K0TSY8Und9 eTB7ZYohHwADr+DeAqJl2mn/op4M0vSrZWR1IDWW3WNd8OYYnQBpUIH2EqoSjnUn KOitAitxdJlg5yHb4Vzaex5P2AcM0nQAiu8MWyjeHZNWmmcLm5SDGQr/rcldzORu HFazbi7kaKDOMABS7VbhhK+aaCxuu3MPGbK2MaIaKRE0pAc2h0z/A== 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 4fg7ahmcm9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:29 +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 66OE4eeF014519; Fri, 24 Jul 2026 14:09:29 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgmtk96uv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:28 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66OE9OAB50463070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:09:25 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C819E20177; Fri, 24 Jul 2026 14:09:24 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0508020171; Fri, 24 Jul 2026 14:09:17 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:09:16 +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, jgross@suse.com, virtualization@lists.linux.dev Subject: [PATCH v9 07/11] sched/debug: Add migration stats due to non preferred CPUs Date: Fri, 24 Jul 2026 19:37:28 +0530 Message-ID: <20260724140732.2683314-8-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-ORIG-GUID: vIVDiDO0rKYOooJH_to9CyGeasr39wJL X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfXxF/t0BC7Rk55 kIKovsul7jVJmTNLqLllPO0vOhxW7keY3e4dKaVHGdxorvnxaoLh9pbRSjs6s8ux/8PG8nxhNgC 5k7mmcM97W0RVuDcL8udktrEm6BY8Qkj0vvz1hICqOgmFXKase/5WGv4iO6xEjfhD9VVXcMofEg m7U4OkiCqapjTtg/oauoRUr0820Tdf1HzZdR9VtnGMyTWA5ZeZtzINRHsYsXTOu7w8ekAgnVam/ rZ+nUG6+ENbVrYD+hbtREbAitg4GlePzXGajbCj7fBn/hQT3Lc/mRxCSFiErByZ7o1mAcKDoWSU rFpnZWzjcddytdj4Io0LKLvKGuXuph47Zrsm7oZfTafRQNUik1WsIxySzu0t5WpvEMj/CvtKU1l JLKPzD08dmWS2qsK/3QKAfR7bn5HVofPH7lTLihEWSupNyys1yL/ua4WxpFtnzLVA6l16ZEn9sp yBi6jDPMO1EDDY1sRKw== X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX48ngWp8hnvwe 1d5w+D6nWepssRCRlyQpydKa7I6CXxp7ag2TxVKls9JiFGHdE6C/dHHbF0D6pqotu9Q3Vx49ZHM 6lJoSPvtb4npTfUsjswEWlw6jP5BqzY= X-Proofpoint-GUID: dsirhQ6s-NtAP_pe_RMJv32KbwP4pzZT X-Authority-Analysis: v=2.4 cv=SM5ykuvH c=1 sm=1 tr=0 ts=6a63721a cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=-i9lZGrASMRMKgkbeRgA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 priorityscore=1501 phishscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Content-Type: text/plain; charset="utf-8" Add a new stat, - nr_migrations_cpu_non_preferred: number of migrations happened since a CPU was marked as non preferred due to high steal time. Signed-off-by: Shrikanth Hegde --- include/linux/sched.h | 1 + kernel/sched/core.c | 9 +++++++-- kernel/sched/debug.c | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 968b18a7f470..37849d2f1dbd 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -554,6 +554,7 @@ struct sched_statistics { u64 nr_failed_migrations_running; u64 nr_failed_migrations_hot; u64 nr_forced_migrations; + u64 nr_migrations_cpu_non_preferred; =20 u64 nr_wakeups; u64 nr_wakeups_sync; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 704043531b24..f0d9bcfd35e3 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11324,8 +11324,13 @@ static int sched_non_preferred_cpu_push_stop(void = *arg) context_unsafe_alias(rq); =20 if (task_rq(p) =3D=3D rq && task_on_rq_queued(p) && - !is_migration_disabled(p)) - rq =3D __migrate_task(rq, &rf, p, cpu); + !is_migration_disabled(p)) { + struct rq *dest_rq =3D __migrate_task(rq, &rf, p, cpu); + + if (rq !=3D dest_rq) + schedstat_inc(p->stats.nr_migrations_cpu_non_preferred); + rq =3D dest_rq; + } =20 rq_unlock(rq, &rf); raw_spin_unlock_irq(&p->pi_lock); diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index 72236db67983..5ebb2055e6d5 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -1446,6 +1446,7 @@ void proc_sched_show_task(struct task_struct *p, stru= ct pid_namespace *ns, P_SCHEDSTAT(nr_failed_migrations_running); P_SCHEDSTAT(nr_failed_migrations_hot); P_SCHEDSTAT(nr_forced_migrations); + P_SCHEDSTAT(nr_migrations_cpu_non_preferred); P_SCHEDSTAT(nr_wakeups); P_SCHEDSTAT(nr_wakeups_sync); P_SCHEDSTAT(nr_wakeups_migrate); --=20 2.47.3 From nobody Fri Jul 24 21:29:11 2026 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 E37CE4908B7; Fri, 24 Jul 2026 14:10: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=1784902204; cv=none; b=cOeRC84g7M8awNhQyffMFy1+3I709k9Q9l1NxbosI/GfQkLuAal5paNeQT3pyJsOvZqZB2objHkt9TJfhsTpd+bqHmM9T14aRHgVbL+v4f3V9kydlTbudopK1kWMRoLgGHlO75F9gnGO9LAebnmS/+XPNsosuPdbwUgi0qjB7zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902204; c=relaxed/simple; bh=vMCeSJV6MQCHscG5r6KOnQ98v56d4nl0k9lovG99o8c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G1F35bLZq3M1gr3Q7ss5yRpdx/3s4kN1tryaIZoPQST6AQPL1CmecH6bQfEX/JVTDZheKIKaoOUKDpatwec53seQRTqK+UBIFxFJ4JLEaFxm1Kb94yyPaJHBjEek4Iesx0hSqHY2E7QxF/eMhwySBeRS8A1hC0hEpA3KA7WpZEQ= 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=GgS8uQjM; 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="GgS8uQjM" 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 66ODfeW51992747; Fri, 24 Jul 2026 14:09:39 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=glhjCI2T2okwfViYv uRd98jthZapwwkgAM3w4Lxz5wU=; b=GgS8uQjMeLtmm10EZavzGoi39wWt/bbEo CAZWODIasYhDA4ubWInD2dnjvacjcXXgQmhH4JoMut608OZKu/wpfXI7sFPzwTLV hW450UqxnRWHGNL8OZwxSFR0heYM+qI9vrt0hvkYhh0CIOBiY2TfXTB882iSkLmG 1atk8uSbz4wnZzUHm3Jx1bQ9OHtpfLJKWBZjUkaRUu96d16MTZiZDD5JUpk9B6vz E1z+cKMuBpuXrXMP/b9bC+vGG+CD8xPF+8LRVW7cYSD+4ZRg6gkf7FiJZsIjDiG+ 7qvU/WkW+vOdtF8T+z7zw/NsfPw2jjFV+fR4OTpqQzyO0pF8XpDlQ== 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 4fm8h009ws-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:38 +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 66OE4eCr013218; Fri, 24 Jul 2026 14:09:37 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgm6wh9ym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:37 +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 66OE9XIZ28574394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:09:33 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E0F720176; Fri, 24 Jul 2026 14:09:33 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 376EB20171; Fri, 24 Jul 2026 14:09:25 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:09:24 +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, jgross@suse.com, virtualization@lists.linux.dev Subject: [PATCH v9 08/11] virt: Introduce steal governor driver Date: Fri, 24 Jul 2026 19:37:29 +0530 Message-ID: <20260724140732.2683314-9-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=LdcMLDfi c=1 sm=1 tr=0 ts=6a637223 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=pGLkceISAAAA:8 a=VwQbUJbxAAAA:8 a=8b9GpE9nAAAA:8 a=YbEHxgcznFVOlIjCzhQA:9 a=T3LWEMljR5ZiDmsYVIUa:22 X-Proofpoint-ORIG-GUID: qYpjejyhImixNt4nEuTDtof3MKnDyL9i X-Proofpoint-GUID: B8Xp6WrxfRC86bvY3lWWH3OvtY2ABeSQ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX9RzxTKes2Hsh bAijak6xmHzPeKBj7g6LoY5lmbJdo/pW+FhygbTxZVWcpZtSi7cnByFnZCLUvdTrH3jDwchN0L0 jrc9EXftXOLs3QgpdT2h18dJJ3mOzcYepM4/dGMk5b8jx20dHxXALzq/lAefuZ23H+MKRkLTRYY jaAZdntt9gRDbdsdC+wZJer5sXQbqQ8bVemNnBzOi0nesZH6nB9fSXN4TzqbSVdGkWwD9pviBU6 DoqamVx6hsWwgmHIgHE/9l7PHHk6hLqJPV8LUvnHn1Q7BS8JzX1ToNYxhpWs0VitUHEgSTjwNpg 7Of2rwtrgwOlfK9FRtughVz73jZlGgrvh2VPIFh/jbl+d4ScsxAMprDo5Vwlh2VVINOC/NTC0HW 1saW9msXPdv1kLh77mueqYTEckQYDHdGnONDWc9JBGQoBPvVAx/vqr8UER9jFwsr8oW7sZsQb7x ms7BFYnMeLSkYvHxlSQ== X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfXyhQKiNt8sHLr nyBGEXzIqIIFxhvd9q3nWFSASFsr7MdRgmrCVW961BX4CFuK/niE8+n1YQqdXh+JfrnVMVfy0Di AxOoAWRCTiqIM8TtuZ/MZB1lYykSkJA= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 malwarescore=0 clxscore=1015 adultscore=0 priorityscore=1501 phishscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Content-Type: text/plain; charset="utf-8" Introduce a new driver in virt named steal_governor. This driver will compute the steal time and drive the policy decisions of preferred CPU state. More on it can be found in the Documentation/driver-api/steal-governor.rst There is a new kconfig called STEAL_GOVERNOR which is introduced in subsequent patches. That driver is going to select PREFERRED_CPU. This makes configs driven by user preference. When the driver is disabled, preferred CPUs is same as active CPUs. File layout of the driver is being kept simple. Everything is in drivers/virt/steal_governor.c and configs are part of drivers/virt/Kconfig. Main structure of steal governor has, - work, delay: deferred periodic work function - steal, time: To calculate the deltas in periodic work. - interval_ms, high_threshold, low_threshold: debug knobs of steal_governor. While there, Add MAINTAINERS entry for this new driver. Signed-off-by: Shrikanth Hegde --- Documentation/driver-api/index.rst | 1 + Documentation/driver-api/steal-governor.rst | 118 ++++++++++++++++++++ MAINTAINERS | 9 ++ drivers/virt/steal_governor.c | 68 +++++++++++ 4 files changed, 196 insertions(+) create mode 100644 Documentation/driver-api/steal-governor.rst create mode 100644 drivers/virt/steal_governor.c diff --git a/Documentation/driver-api/index.rst b/Documentation/driver-api/= index.rst index eaf7161ff957..0a973b59cba3 100644 --- a/Documentation/driver-api/index.rst +++ b/Documentation/driver-api/index.rst @@ -138,6 +138,7 @@ Subsystem-specific APIs sm501 soundwire/index spi + steal-governor surface_aggregator/index switchtec sync_file diff --git a/Documentation/driver-api/steal-governor.rst b/Documentation/dr= iver-api/steal-governor.rst new file mode 100644 index 000000000000..a343ed6c7ff6 --- /dev/null +++ b/Documentation/driver-api/steal-governor.rst @@ -0,0 +1,118 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Steal Governor +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +:Author: Shrikanth Hegde + +Introduction +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Steal governor is a driver aimed at solving the Noisy Neighbour problem +in paravirtualized environments. The performance of workload +running in one VM gets affected significantly due to other VMs and +combined they make slower forward progress. + +When there is overcommit of CPU resources, i.e. sum of virtual CPUs (vCPUs) +of all VMs is greater than number of physical CPUs (pCPUs) and +when all or many VMs have high utilization, hypervisor won't be able +to satisfy the CPU requirement and has to context switch within or +across VMs. I.e. the hypervisor needs to preempt one vCPU to run +another. This is called vCPU preemption. +This is more expensive compared to task context switch within a vCPU. + +In such cases it is better that combined vCPU ask from all VMs is reduced +by not using some of the vCPUs. vCPUs where workload can be safely +scheduled which won't increase any contention for pCPU are called as +"Preferred CPUs". + +See more on "Preferred CPUs" in Documentation/scheduler/sched-arch.rst. +Driver code is available at drivers/virt/steal_governor.c + +This driver makes CONFIG_PREFERRED_CPU=3Dy which enables the scheduler core +infrastructure to move tasks to Preferred CPUs where possible. + +Core idea +=3D=3D=3D=3D=3D=3D=3D=3D=3D + +steal time is an indication available today in Guest which shows contention +for underlying physical CPU. Use it as a hint in the guest to fold the +workload to a reduced set of vCPUs. When there is contention, steal time +will show up in all the guests. When each guest honors the hint and folds +the workload to a smaller set of vCPUs (Preferred CPUs), it reduces the +contention and thereby reduces vCPU preemption. +This is achieved without any cross-guest communication. + +Steal governor driver effectively does: + +1. Periodically computes steal time across the system. + +2. If steal time is greater than high threshold, reduce the number of + preferred CPUs by 1 core. Ensure at least one core is left always. + +3. If steal time is lower or equal to low threshold, increase the + number of preferred CPUs by 1 core. If preferred is same as active, + nothing to be done. + +4. Ensure preferred CPUs is always subset of active CPUs. + On feature disable it is same as active CPUs. + +This feature works best only when all the VMs enable the feature as +it is a co-operative scheme. If a specific VM doesn't enable this feature +it may end up with more CPUs than others, still should lead to better +performance when seen from system view. +Those who enable this driver must ensure it is enabled in all VMs. + +Module Parameters +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +interval_ms +----------- + +How often steal governor checks for steal time. +Default: 1000 i.e 1 second. Value should be in between 100ms to 100sec. + +This controls how fast steal governor driver reacts to changes to +the contention of physical CPUs. Since it does a fair amount of +work, setting too low may have overhead. Setting it too +high might render it ineffective. + +low_threshold +------------- + +lower threshold value in percentage * 100. +Default: 200, i.e 2% steal is considered as low threshold. +Can't be higher than high_threshold. + +This determines what values should be considered as nil/no steal values. +When steal governor see steal time is below or equal to this value, it +will increase the preferred CPUs by 1 core. Having value as zero +might cause oscillations. + +high_threshold +-------------- + +higher threshold value in percentage * 100 +Default: 500, i.e 5% steal is considered as high threshold. +Can't be lower than low_threshold. Must be less than 10000. + +This determines what values should be considered as high steal values. +When steal governor sees steal time is higher than this value, it will +reduce the preferred CPUs by 1 core. + +Notes +=3D=3D=3D=3D=3D + +Selecting this driver makes CONFIG_PREFERRED_CPU=3Dy. That makes configs +driven by user preference. + +It is recommended to build CONFIG_STEAL_GOVERNOR=3Dm due to below reasons: + +1. Doing periodic work has additional overheads. Enabling this driver + in systems where steal time cannot happen is of no use. There is no + benefit with additional overheads in such systems. + +2. This works well when all VMs work in co-operative manner. When an + administrative user enables it in one VM, he/she will likely enable + it all VMs. diff --git a/MAINTAINERS b/MAINTAINERS index 15011f5752a9..40d46ba48ecd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -25914,6 +25914,15 @@ F: rust/helpers/jump_label.c F: rust/kernel/generated_arch_static_branch_asm.rs.S F: rust/kernel/jump_label.rs =20 +STEAL GOVERNOR DRIVER +M: Shrikanth Hegde +R: Yury Norov +L: linux-kernel@vger.kernel.org +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core +F: Documentation/driver-api/steal-governor.rst +F: drivers/virt/steal_governor.c + STI AUDIO (ASoC) DRIVERS M: Arnaud Pouliquen L: linux-sound@vger.kernel.org diff --git a/drivers/virt/steal_governor.c b/drivers/virt/steal_governor.c new file mode 100644 index 000000000000..d427282966d2 --- /dev/null +++ b/drivers/virt/steal_governor.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Steal time governor driver periodically computes steal time. + * Based on the thresholds it either reduce/increase the preferred + * CPUs which can be used by the workload to avoid vCPU preemption + * to an extent possible in paravirtualized environment. + * + * Available with CONFIG_STEAL_GOVERNOR + * + * Copyright (C) 2026 IBM + * Author: Shrikanth Hegde + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if !IS_ENABLED(CONFIG_PREFERRED_CPU) +#error "Steal Governor requires CONFIG_PREFERRED_CPU" +#endif + +struct steal_governor { + ktime_t time; + u64 steal; + unsigned long delay; + unsigned int interval_ms; + unsigned int high_threshold; + unsigned int low_threshold; + struct delayed_work work; +}; + +static struct steal_governor sg_ctx; + +static void restore_preferred_to_active(void) +{ + int cpu; + + guard(cpus_read_lock)(); + for_each_cpu(cpu, cpu_active_mask) + set_cpu_preferred(cpu, true); +} + +static int __init steal_governor_init(void) +{ + pr_info("enabled\n"); + return 0; +} + +static void __exit steal_governor_exit(void) +{ + restore_preferred_to_active(); + pr_info("disabled\n"); +} + +module_init(steal_governor_init); +module_exit(steal_governor_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("IBM Corporation"); +MODULE_DESCRIPTION("Virtualization Steal Time Governor"); --=20 2.47.3 From nobody Fri Jul 24 21:29:11 2026 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 5EEE641D621; Fri, 24 Jul 2026 14:10:11 +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=1784902212; cv=none; b=E3ejli4efE1/CTjbKHgHfu056lvX/kgg0ypVClasSho4QD8e+UOvvJcW371ZMuJAZePPeNFy0GWZKIOTvGdADa0TQoOoc4mNnDnISyU4mCYssTsgIST+lkQz6Iv0uS/Aub6dDeEv6L8gw21S98iIez9sP5M11F7cwHpsGdA3Pow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902212; c=relaxed/simple; bh=kx/ZUk04aAgeJ28JHBtejbxN8ke/L9KPi6V39cEnMXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W9dLrVG3P8MZOKFYp8LcH5igOXGHf2Xd3n1lQMsifvRGsQgGzt3oc6XI+9QA2nQY7ORQLb4VYHVx0C1VQlHXMJG4sYgQnvJSRzJ8/IG8jEwlX9h40sXHLoVOw1DcChFfglUNpXEeXTUkcc7EDVTsJMc2aA5uGfLonS/GC23VyF4= 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=BPXK4Gbx; 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="BPXK4Gbx" 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 66ODfqQ21869307; Fri, 24 Jul 2026 14:09:47 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=C0fdagA03XTKUOLIx e5zk2YAGrQ00SXzkE8TCVCPfew=; b=BPXK4GbxpxVnol9QpQhkUoMVUMqIcaky7 0SylfY63DrQCr5B1ufjCd3RKWexnU3vu2MtChJTDMWuOjz+Lecz3VHMRgaZzph1h zHFOdU3goOt8fE/eHgoO0EAUXYIEyNqNxwfe0mPdUXACnQ9SfDWBn20UzMVm8w9M 2JKhFbTQHhYHIwstFJsIqvSTgYqMqQ6ienFGsWRk/4/Ijhk7NKc56Ad96aq/VpL+ CZESouhM+IGi4Ffb+ab0QEmhqzHoJAwXGaKXAv2rWN61fc1iOeDiRPIJO/FhfnLx OMFa/SGaLiH8u4/VGaxHfS+Xvr2nFmrXuuLgLOq6ow4O904ioQM4w== 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 4fg78gmbpv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:46 +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 66OE4iFw009171; Fri, 24 Jul 2026 14:09:45 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fgpgyrxf6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:45 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66OE9g1p45810032 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:09:42 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 05C6820176; Fri, 24 Jul 2026 14:09:42 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AC99E20171; Fri, 24 Jul 2026 14:09:33 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:09:33 +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, jgross@suse.com, virtualization@lists.linux.dev Subject: [PATCH v9 09/11] virt/steal_governor: Add control knobs for handling steal values Date: Fri, 24 Jul 2026 19:37:30 +0530 Message-ID: <20260724140732.2683314-10-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX7m2jq5bR+Rqb VPxL/s/bcrhrjQgNxdXT41MLvvp4lRPt1rWA/RsfzbYHiJ90mLMHsrHuBnVbVg3hA1UCdro7XMU 4gqL1A1wTHIzQJ3GC2mtN9cm+kqODTeDD0uPwPzauqTavS28JTI/9Zz5l3hoLitlYlqcLr/Av+r NbnZb/QtNbaA3OcikBkIA0rdI9vpumIUe2/GQWC9HqJw1jx19r9ySpJxS5YjpT+If8x1ij2zr1P vfrpgIcfUlAhRs2Yxgn0EKrovnD7Qypy3j4Ok+NXB7pIWTd+CVt5Jnt3JrfO3hoFNASke2LjEbg r3TVwFX4S6rpBZFhulO7VmZhDS3sF1pGjnXlMAwaOotvrA+2zlCogD1qKhpz+8VuSNPO6XXcDj/ AB3B6cC7QUHY/Kanlvxd4aWL7Lzh55PqSqe2FWvND0vUQqMss7fFH7kUj73BAZxBJmRKEDBmrQc iQcAOljA47UMbcb4Yfw== X-Proofpoint-GUID: EJ1Nc5SO9oc8H4lhpQQxcWdrCuuAcapC X-Authority-Analysis: v=2.4 cv=MelcfZ/f c=1 sm=1 tr=0 ts=6a63722b cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=XC_GqrfF-lTPz34eE_0A:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX4e4X5uttbRNv amPeExRQytOZAO16Er2fncJU7+oFgrGIzCPZf5dhoVgTuYJb3lPyClEKrFhigjP7fI1MW2g87tj RFSfvwMsw3GLpy0Q+0+WxJ63v+xmbuk= X-Proofpoint-ORIG-GUID: gTDYvAJJwbMAwwxJafdh1unFPXK6MLSI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 spamscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Content-Type: text/plain; charset="utf-8" These are the knobs to control the steal_governor. interval_ms: How often steal governor checks for steal time. (Default: 1000 i.e 1 second) This controls how fast steal governor driver reacts to changes to the contention of physical CPUs. Can be set between 100 to 100000. i.e. 100ms to 100seconds. 100ms is kept as minimum to ensure few meaningful steal values accumulate even with HZ=3D100. low_threshold: lower threshold value in percentage * 100. (Default: 200, i.e 2% steal is considered as low threshold) This determines what values should be considered as nil/no steal values. When steal governor see steal time is below or equal to this value, it will increase the preferred CPUs by 1 core. Having value as zero might cause oscillations high_threshold: higher threshold value in percentage * 100 (Default: 500, i.e 5% steal is considered as high threshold) This determines what values should be considered as high steal values. When steal governor sees steal time is higher than this value, it will reduce the preferred CPUs by 1 core. module_param_cb methods are used to do the validation checks. This helps to ensure one configures sane values. Since low and high are dependent, that check is done at module init. Parameters values can't be changed at runtime. One has to unload the module and change it. Hence recommended to build it as module. Also available at: Documentation/driver-api/steal-governor.rst Signed-off-by: Shrikanth Hegde --- drivers/virt/steal_governor.c | 73 ++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/drivers/virt/steal_governor.c b/drivers/virt/steal_governor.c index d427282966d2..fda86777d6f0 100644 --- a/drivers/virt/steal_governor.c +++ b/drivers/virt/steal_governor.c @@ -37,7 +37,11 @@ struct steal_governor { struct delayed_work work; }; =20 -static struct steal_governor sg_ctx; +static struct steal_governor sg_ctx =3D { + .interval_ms =3D 1000, /* 1 second */ + .high_threshold =3D 500, /* 5% */ + .low_threshold =3D 200, /* 2% */ +}; =20 static void restore_preferred_to_active(void) { @@ -48,9 +52,74 @@ static void restore_preferred_to_active(void) set_cpu_preferred(cpu, true); } =20 +static int param_set_interval_ms(const char *val, const struct kernel_para= m *kp) +{ + unsigned int interval; + int ret; + + ret =3D kstrtouint(val, 0, &interval); + if (ret) + return ret; + + if (interval < 100 || interval > 100000) { + pr_err("interval_ms must be between 100 and 100000\n"); + return -EINVAL; + } + + return param_set_uint(val, kp); +} + +static const struct kernel_param_ops interval_ms_ops =3D { + .set =3D param_set_interval_ms, + .get =3D param_get_uint, +}; + +module_param_cb(interval_ms, &interval_ms_ops, &sg_ctx.interval_ms, 0444); +MODULE_PARM_DESC(interval_ms, + "Sampling frequency in milliseconds. default: 1000"); + +static int param_set_high_threshold(const char *val, const struct kernel_p= aram *kp) +{ + unsigned int threshold; + int ret; + + ret =3D kstrtouint(val, 0, &threshold); + if (ret) + return ret; + + if (threshold >=3D 100 * 100) { + pr_err("high_threshold (%u) can't be more than 99.99%%\n", threshold); + return -EINVAL; + } + + return param_set_uint(val, kp); +} + +static const struct kernel_param_ops high_threshold_ops =3D { + .set =3D param_set_high_threshold, + .get =3D param_get_uint, +}; + +module_param_cb(high_threshold, &high_threshold_ops, &sg_ctx.high_threshol= d, 0444); +MODULE_PARM_DESC(high_threshold, + "High steal threshold. default: 500 i.e 5%. Must be > low_threshold"); + +module_param_named(low_threshold, sg_ctx.low_threshold, uint, 0444); +MODULE_PARM_DESC(low_threshold, + "Low steal threshold. default: 200 i.e 2%. Must be < high_threshold"); + static int __init steal_governor_init(void) { - pr_info("enabled\n"); + if (sg_ctx.low_threshold >=3D sg_ctx.high_threshold) { + pr_err("low_threshold (%u) must be less than high_threshold (%u)\n", + sg_ctx.low_threshold, sg_ctx.high_threshold); + return -EINVAL; + } + + sg_ctx.delay =3D msecs_to_jiffies(sg_ctx.interval_ms); + pr_info("enabled. interval: %ums, high_threshold: %u, low_threshold: %u\n= ", + sg_ctx.interval_ms, sg_ctx.high_threshold, sg_ctx.low_threshold); + return 0; } =20 --=20 2.47.3 From nobody Fri Jul 24 21:29:11 2026 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 4F7DA41D62A; Fri, 24 Jul 2026 14:10: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=1784902221; cv=none; b=pMdtY8QuVqL3tuRQgczOhuxP0/Fw6B5BkQ22fa2sVpfIsmLp7ctwTZsfygeyFo2Jt0c22LwWgqvqwTiVJYTqe6JqMlOquw5tbXEfjeP6poDJjPz3iI/+gfrTNg0C362BGYL/i2WPaDB/sCQ+SXJo1x6AarGVypoZyESKSOMFRzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902221; c=relaxed/simple; bh=lFn6yudg7HtGZWnonuoEUEeFLNJ83HIX7SI5cWN9MVU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A6yxSe7wR0QAYA6jZjhg10oglyn2IdvdlWVdCHPRznMakKpdEqtEdRpEvF7MCAHYRg+DMtm2aBZ6ZP0Yx647gjngHybopS+BTfVTHbZgaCQm2D2hZTSk9E7bUlfKgf3Mi7shwzEPFwNnwPXx8gj6mjhwz2FU2R5w9u16K543KKE= 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=lPvnPeY/; 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="lPvnPeY/" 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 66ODfla11974199; Fri, 24 Jul 2026 14:09:58 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=C+rWP+vHDsQ3aZepR duYt4yeLX6PoV71sT1na6/prNs=; b=lPvnPeY/EwljiH8Vye1HYQP4GPwhJnYaV UmZCjwlT4ravHYc2ZCDGnP3mQkdu9lBPFf5wULgKBbbyv61R17a1bqmJbEzmlnN/ M2+3ur8QoUwHja6jBTSBZ2/p5agidksUlxKt3ja684q2pZvSkQecCZMDo2aQ7drq C7ShjQRVmGVCBNZM2UtYAEMsnl1Ou1/+l74SDh2D4ZUgWX9O/STGvN8uQuJeDlXb o1it3SqQbhQvyexqgDRlSQ3Mtmxkw6ytl6pltEiXQ5fm9kwpRPYY2E4SmfulJ2+t 55ClnSuCNcRlyG2hIQV44b7XNLfQ1r4y1nxxBHjOhjsbgj/jedtqw== 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 4fm8h50a0a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:57 +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 66OE4ltJ014575; Fri, 24 Jul 2026 14:09:56 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgmtk96wy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:09:56 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66OE9qcG42533130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:09:52 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5344520171; Fri, 24 Jul 2026 14:09:52 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2179220176; Fri, 24 Jul 2026 14:09:43 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:09:42 +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, jgross@suse.com, virtualization@lists.linux.dev Subject: [PATCH v9 10/11] virt/steal_governor: Implement steal_governor policy loop Date: Fri, 24 Jul 2026 19:37:31 +0530 Message-ID: <20260724140732.2683314-11-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX4wTYfDUwFXQ5 zhU1UA+Z0MwVQRc0LwCN++tpDw3WvqDvjlq3dHnPo7+hJDvaOOOEmsjruaDF03mwOGVMBd9Ydzy 4t2h6XdusZSE9DdupKccxIjXBTce0mA= X-Proofpoint-ORIG-GUID: hvjd0CBqvhHLmRKaZ3quIHCqS14xPXjn X-Proofpoint-GUID: Whx-zw6UZsQW4qu3eCs4PnPGZ7ixwITv X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfXyHBLQZXxdrKG Z1/9XuXGzc7AFBgJw21IKJGBGTaphkdQ+XKlg/PfuDunDWiylpGf3wVhZlx0Deipc19xlhRitFd 8X1wPHWgBzRAyjGdhFyPykADkJQJLdI+DBUESiNPvld5IK4TEz4mCLqe2QV0EpHz+dUxlmf7r5d mk31jQmlt4xc6CVRgcMWOtgtuKmIRHkCJSzysfux47ny2d216CWDIeYkXrRLM1dZhIsQjq4ySg4 DEVbYWH6uU8IvE+OCI1sl7+lidzkM2xnUEdQxs1AgvJKulmj/w5JSXN/xxkyhbTKYHMFnVEruK9 zC9XmqjsOhsRWp9pI6FvN1VYe32mdXZ6JO/PIneycLufmlhNdloh8DgoZdLiOpdyWaOgNszhoCo wTe802+hRME5Ifsj8HG9BUkuUjE43NJULll9LzzuYiwRlcDZ9TFKqfuYnWyp2jiX5IPUj2LJp0c UT7fycTK4LmBqj+6vMA== X-Authority-Analysis: v=2.4 cv=du3rzVg4 c=1 sm=1 tr=0 ts=6a637236 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=zdfznts9tQKWGqFkqZ0A:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 malwarescore=0 spamscore=0 impostorscore=0 phishscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Content-Type: text/plain; charset="utf-8" schedule work at regular intervals to implement the steal_governor policy of monitoring the steal time and take action on the state of preferred CPUs. The interval is determined by interval_ms parameter. schedule_delayed_work is used since interval_ms is in the order of milliseconds. Work need not happen instantly. Periodic policy loop essentially does: - Gets the total/delta steal values and cpus to use steal_ratio. - Calculate the steal_ratio as below. steal_ratio =3D (delta_steal * 100*100)/(delta_ns * num_cpus()) It is calculated to consider the fractional values of steal time. I.e 10 means 0.1% steal time. A few tricks such as divide by 10,000 are used to avoid possible overflow. - If steal value is higher than high threshold, call the method to reduce the preferred CPUs. - If steal value is lower or equal to low threshold, call the method to increase the preferred CPUs. - If the steal value is in between, no action is taken. - Save the values for next delta calculations. - Ensure design checks are met. 1. At least one core/CPU must be there in preferred mask. 2. preferred CPUs is subset of active CPUs. If not met, then restore preferred CPUs to active and stop requeue of the work. Driver is effectively non-functional after that. In order to help the above loop, a few helper functions have been added. 1. get_system_steal_time() - steal governor takes global view of steal time instead of individual vCPU. Collect the steal values across the vCPUs of interest. - Sum up steal time values across possible CPUs. This helps to keep it a monotonically increasing number and avoids spikes due to CPU hotplug. 2. decrease_preferred_cpus() - Called when there is high steal time. It needs to decide which CPUs to mark as non-preferred and set that state. - Get first housekeeping CPU and its core mask. Mark it as protected core. This helps to keep at least one core as preferred. kernel ensures at least one housekeeping CPU stays active. - Find the last CPU outside of this protected core mask. (target CPU) - Based on that target CPU, get its sibling and mark them as non-preferred. 3. increase_preferred_cpus() - Called when there is low steal time. It needs to decide which CPUs to mark as preferred and set that state. - Get the first active non-preferred CPUs. This likely is the last set of CPUs being marked as non-preferred. - get the siblings of that CPU and mark them as preferred. 4. get_system_cpus() - informs how many CPUs needs to be considered for steal_ratio calculations. - Return number of possible CPUs as get_system_steal_time computes steal values across possible CPUs. Notes: 1. Using core instead of individual CPUs performs better as SMT is quite common and some hypervisor such as powerVM does core scheduling. 2. This doesn't do any NUMA splicing to keep the code simpler and minimal overhead. Current code expects CPUs spread uniformly across NUMA nodes. Signed-off-by: Shrikanth Hegde --- drivers/virt/steal_governor.c | 155 ++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/drivers/virt/steal_governor.c b/drivers/virt/steal_governor.c index fda86777d6f0..991821a82485 100644 --- a/drivers/virt/steal_governor.c +++ b/drivers/virt/steal_governor.c @@ -13,13 +13,18 @@ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 +#include #include #include #include #include +#include #include #include +#include #include +#include +#include #include #include =20 @@ -108,6 +113,151 @@ module_param_named(low_threshold, sg_ctx.low_threshol= d, uint, 0444); MODULE_PARM_DESC(low_threshold, "Low steal threshold. default: 200 i.e 2%. Must be < high_threshold"); =20 +/* Return collective steal time across system. */ +static u64 get_system_steal_time(void) +{ + int cpu; + u64 total_steal =3D 0; + + for_each_possible_cpu(cpu) + total_steal +=3D kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL]; + + return total_steal; +} + +/* Return number of CPUs to consider steal ratio. */ +static unsigned int get_system_cpus(void) +{ + return num_possible_cpus(); +} + +/* + * + * Called when the steal governor detects high physical CPU contention. + * It finds the last active core in the preferred mask and mark those + * CPUs as non-preferred. + * + * Must ensure: + * - at least one core is always kept as preferred + * - preferred is always subset of active. + */ +static void decrease_preferred_cpus(void) +{ + const struct cpumask *first_hk_core; + int target_cpu =3D nr_cpu_ids; + int cpu; + + guard(cpus_read_lock)(); + cpu =3D cpumask_first_and(housekeeping_cpumask(HK_TYPE_KERNEL_NOISE), + cpu_preferred_mask); + if (cpu >=3D nr_cpu_ids) + return; + + /* Always leave first housekeeping core as preferred. */ + first_hk_core =3D topology_sibling_cpumask(cpu); + cpu =3D cpumask_last(cpu_preferred_mask); + if (cpu >=3D nr_cpu_ids) + return; + + /* Find the last CPU which doesn't belong to that first hk_core. */ + if (!cpumask_test_cpu(cpu, first_hk_core)) { + target_cpu =3D cpu; + } else { + for_each_cpu_andnot(cpu, cpu_preferred_mask, first_hk_core) + target_cpu =3D cpu; + } + + /* Only the first housekeeping core remains */ + if (target_cpu >=3D nr_cpu_ids) + return; + + for_each_cpu_and(cpu, topology_sibling_cpumask(target_cpu), + cpu_preferred_mask) + set_cpu_preferred(cpu, false); +} + +/* + * Called when the steal governor detects no/low physical CPU contention. + * It finds the first active core outside of preferred mask and mark + * those CPUs as preferred. + * + * Must ensure preferred is subset of active. + */ +static void increase_preferred_cpus(void) +{ + int first_cpu, cpu; + + guard(cpus_read_lock)(); + first_cpu =3D cpumask_first_andnot(cpu_active_mask, cpu_preferred_mask); + + /* All CPUs are preferred. Nothing to increase further */ + if (first_cpu >=3D nr_cpu_ids) + return; + + for_each_cpu_and(cpu, topology_sibling_cpumask(first_cpu), + cpu_active_mask) + set_cpu_preferred(cpu, true); +} + +static bool preferred_cpus_valid(void) +{ + if (cpumask_empty(cpu_preferred_mask)) { + pr_err("empty preferred mask. stopping\n"); + return false; + } + + if (!cpumask_subset(cpu_preferred_mask, cpu_active_mask)) { + pr_err("preferred: %*pbl is not subset of active: %*pbl, stopping\n", + cpumask_pr_args(cpu_preferred_mask), + cpumask_pr_args(cpu_active_mask)); + return false; + } + + return true; +} + +static void compute_preferred_cpus_work(struct work_struct *work) +{ + u64 curr_steal, delta_steal, delta_ns, steal_ratio; + ktime_t now; + + now =3D ktime_get(); + delta_ns =3D ktime_to_ns(ktime_sub(now, sg_ctx.time)); + + if (unlikely(delta_ns < NSEC_PER_MSEC)) { + pr_err_ratelimited("work scheduled too soon delta_ns: %llu\n", delta_ns); + goto requeue_work; + } + + curr_steal =3D get_system_steal_time(); + delta_steal =3D curr_steal > sg_ctx.steal ? curr_steal - sg_ctx.steal : 0; + sg_ctx.steal =3D curr_steal; + sg_ctx.time =3D now; + + /* + * steal_ratio =3D (delta_steal * 100*100)/(delta_ns * num_cpus()) + * To avoid possible overflow, divide the denominator early. + * Note minimum interval is 100ms. + */ + delta_ns =3D max_t(u64, div_u64(delta_ns * get_system_cpus(), 10000), 1); + steal_ratio =3D div64_u64(delta_steal, delta_ns); + + if (steal_ratio > sg_ctx.high_threshold) + decrease_preferred_cpus(); + else if (steal_ratio <=3D sg_ctx.low_threshold) + increase_preferred_cpus(); + else + goto requeue_work; + + if (!preferred_cpus_valid()) { + restore_preferred_to_active(); + return; + } + +requeue_work: + schedule_delayed_work(&sg_ctx.work, sg_ctx.delay); +} + static int __init steal_governor_init(void) { if (sg_ctx.low_threshold >=3D sg_ctx.high_threshold) { @@ -117,6 +267,10 @@ static int __init steal_governor_init(void) } =20 sg_ctx.delay =3D msecs_to_jiffies(sg_ctx.interval_ms); + INIT_DELAYED_WORK(&sg_ctx.work, compute_preferred_cpus_work); + sg_ctx.steal =3D get_system_steal_time(); + sg_ctx.time =3D ktime_get(); + schedule_delayed_work(&sg_ctx.work, sg_ctx.delay); pr_info("enabled. interval: %ums, high_threshold: %u, low_threshold: %u\n= ", sg_ctx.interval_ms, sg_ctx.high_threshold, sg_ctx.low_threshold); =20 @@ -125,6 +279,7 @@ static int __init steal_governor_init(void) =20 static void __exit steal_governor_exit(void) { + disable_delayed_work_sync(&sg_ctx.work); restore_preferred_to_active(); pr_info("disabled\n"); } --=20 2.47.3 From nobody Fri Jul 24 21:29:11 2026 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 57C0C3126B0; Fri, 24 Jul 2026 14:10:27 +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=1784902228; cv=none; b=iqSfYXYBI95e+wcdZ0J97yxoC2JZZF+FC+CvM0kZ0dw2et+oMk72gANEZRmx0vMHSE8HILOsKSDckh73kVPUe3Vy1zv/DRNlq1SrXlbXKGDq8IYFA4OcH5y12iZgvg21BM/psq4schxrh37P8YcKXrzchSF/RxptwB6EG4pOo4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784902228; c=relaxed/simple; bh=Cc+Aot7/Ahkv+9OHqikjmzjHWJ1eBD2BrbyN6S2mhPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k8vf5jS+OiXj/xrlTlZ4BKC1PE1HzP7CgAOhowO3nJcjvrRTKBzfdqWCuutgNGkbuBE2ZF7mvyfsFiIU/6Dao9uyXNVbfxR9cm2VZPKlCEDr3EhFAtCzNFrP7IYVXrMlApTSWNhMn3q7lTzbPtrcU72a0BdSQOSE4r0ONVP/4Dk= 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=jK+Vdqms; 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="jK+Vdqms" 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 66ODfgOc1992919; Fri, 24 Jul 2026 14:10:07 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=IAl3QgpjDXWIjAHYA TqpHr0xZQtj7C3ktRw0es8t1Eg=; b=jK+VdqmsO2FA8Ugz7M/pea6dvm5XthtBQ taA+0ClLJvU5y+1a34PircrIJl0jLS5kzlx63QNla8Oz29akgzXzHz0iWbx9F/T/ /r/p8pmpS2NwfsN/Gpl/TzjQE4Hz8oigfR+hag+3owZt4m4vuCWfyoU4cxbOgWfC uOhrO3tkEwZg64g9fkBoBWTvfztisTs5Uwqg2XGRoc/hDM+vnjAgZQKQZtpNuGpk d42dReKrqRh9VDwVyXLsHzbOIe7a4fz1uFMKytjzdR0opp1KCGkyl15kabQ9aWbI 2St8srCSXg112HPVUWdUJrQqrvkttVnrDy20Pa70DKimQ9EqgVJ4A== 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 4fm8h00a00-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:10:06 +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 66OE4iG1009171; Fri, 24 Jul 2026 14:10:05 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fgpgyrxg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Jul 2026 14:10:04 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66OEA1QK40436110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2026 14:10:01 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 384EA20176; Fri, 24 Jul 2026 14:10:01 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D6F8C20171; Fri, 24 Jul 2026 14:09:52 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.178]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 24 Jul 2026 14:09: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, 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, jgross@suse.com, virtualization@lists.linux.dev Subject: [PATCH v9 11/11] virt/steal_governor: Enable the driver Date: Fri, 24 Jul 2026 19:37:32 +0530 Message-ID: <20260724140732.2683314-12-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260724140732.2683314-1-sshegde@linux.ibm.com> References: <20260724140732.2683314-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=LdcMLDfi c=1 sm=1 tr=0 ts=6a63723e cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=jPZz8W9ceouySDeeKuAA:9 X-Proofpoint-ORIG-GUID: BmgeFVrMpawGRcWxjoGtjB9V0Ic9sk6s X-Proofpoint-GUID: 69TnEnxxMThsTSv6Yf7-hh9qyn_XjPlI X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX0znuyucgssZu 9ugxENNEoK11xg6ADxH1MrefmOuRKcdFsuvMI6RD+6WH4fFsMj9TsJ7FhDUbCvQ12rvyB7+jVb/ FCwLThiTOlU/nrBsUCXwGBUNI5wJF9fqqqAykc+zMvX6KWZikj+nxm6Ae029xuiWc2t7adjenp4 ueNmu35DTpbpvteVCsgtItkC6li43gOUOjRiNKTSMFz12+6j8xqIBYulyeyGk9dpRxViqZUklh0 3GWFyBz7jmeXFqx9Yyrt5xbjkNZdoEJUZHsnT+Gzhy2MExwf29V6q3o9FMkWN6vpTnJGL8Xl2sn jsTTPdBQOH9X3JtrsW6W6HQ4QlmeQ1rsaE9Ep5BccxnJhYHfi3H5kLFbknL4v3IyJ6OpM4KTNvB IwLh1TM2PIk7zHSfazp+/ysiCs7q2CmADLVPmWIaMQl8hJBtaUxOmP+yAFPQ3ltUfkEd25BvKGs fz7znngLfZ/iRpFidOA== X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI0MDEyNCBTYWx0ZWRfX4M0iV8SPdjfu p9zlv8jHbuMHUkoyRoM+jbM6i0VoEuUTg7G/dixrGTqyZ9r10lJ5HIM52/t2ezQoT81iBE5bDzh UXHARjZ+OpwoCv9ez3SD8ZfqDm6M5Ds= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-24_03,2026-07-24_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 malwarescore=0 clxscore=1015 adultscore=0 priorityscore=1501 phishscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607240124 Content-Type: text/plain; charset="utf-8" Provide a config option for users to enable the driver. Since the feature works for paravirtualized case and make sense only with SMP, enforce those dependencies. Driver is going to select CONFIG_PREFERRED_CPU=3Dy for scheduler mechanisms to work. It is recommended to build the driver as module instead of yes due to below reasons. - Module parameters are read only after init. If one wants to change them having as module allows that. - Driver can be disabled if it is built as module. - If it is module, admin user has to enable it. Since this feature works best when all VMs work in co-operative manner, admin will likely enable it in all VMs. Signed-off-by: Shrikanth Hegde --- drivers/virt/Kconfig | 18 ++++++++++++++++++ drivers/virt/Makefile | 1 + 2 files changed, 19 insertions(+) diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig index 52eb7e4ba71f..5c26a59792c9 100644 --- a/drivers/virt/Kconfig +++ b/drivers/virt/Kconfig @@ -41,6 +41,24 @@ config FSL_HV_MANAGER 4) A kernel interface for receiving callbacks when a managed partition shuts down. =20 +config STEAL_GOVERNOR + tristate "Dynamic vCPU management based on steal time" + depends on PARAVIRT && SMP + select PREFERRED_CPU + default m + help + This driver helps to reduce the steal time in paravirtualised + environments, thereby reducing vCPU preemption. Reducing vCPU + preemption provides improved lock holder preemption and reduces + cost of vCPU preemption in the host. + + By default preferred CPUs will be same as active CPUs. Depending + on the steal time when steal_governor driver is enabled, + preferred CPUs could become subset of active CPUs. + + It is recommended to build it as module and load the module + to enable it. + source "drivers/virt/vboxguest/Kconfig" =20 source "drivers/virt/nitro_enclaves/Kconfig" diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile index f29901bd7820..05fb075ef5b8 100644 --- a/drivers/virt/Makefile +++ b/drivers/virt/Makefile @@ -5,6 +5,7 @@ =20 obj-$(CONFIG_FSL_HV_MANAGER) +=3D fsl_hypervisor.o obj-$(CONFIG_VMGENID) +=3D vmgenid.o +obj-$(CONFIG_STEAL_GOVERNOR) +=3D steal_governor.o obj-y +=3D vboxguest/ =20 obj-$(CONFIG_NITRO_ENCLAVES) +=3D nitro_enclaves/ --=20 2.47.3