From nobody Sat Jul 25 02:11:08 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 C1F9D40D59C; Mon, 20 Jul 2026 17:23:58 +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=1784568244; cv=none; b=LURu41pC1IMe1p8NuO9UzRipCbn7UcuTcM5IKhWkeuKPpyqLvAAQTbsEC11W07H2Qzz+8xVSE1Okxcj6UKYLzGUE5nAvLG0Ai6X48QpCEJk86R6aGmZ3L32herQ4EsIfI2vSJlmcilri+vN8QJQ2YDeOqjF8a42wKPU8FYmWnYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568244; c=relaxed/simple; bh=dqOWdcCZX2VlhJA4pzXkTcQFDzFSnKgIi2ryjATM0bA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kTtKv2J0KGObsRmoJknFKG48pa5NWR2aMj89/ar622sNogXfGRR2vv2NpQNWG85/XQ//G75Z+kjKbTsr+5wYjl4HNoWQaV7BXkjTowaaEoeQFT9Q30l302mF2y2c0N9nIv/Y7ldRiPq1XdfkIbbz0fbaFzovcRA9xQEth9dKCDE= 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=B/hdMBjp; 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="B/hdMBjp" 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 66KHBp1r2713374; Mon, 20 Jul 2026 17:23: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=42tRobD+wTCxjiLRN 3tF22lDXmf9gwQXTXq2JNgKVRo=; b=B/hdMBjpzYaRTXl8PX1VooT4O12TexKMO zUNqhSilwnj97lec7so/OnUMgej13BlFB3hJ5tfs74QquL0nXGhZLW+ObKVSBFm4 T1MmzEOBZMUpkZJtitzGPUOOLhW8OxPtqLDtgPV5tBJNxqQbDslctLidFsSH8c5c CwlTD8DhEhV7z4pYbqC5QG0k1+4+KNV9978dB4NUJfXdB45ukJR/yC+p8KHYXpie n2ATqnF7KxMheZCH6/vv1UTOB+K8fRPsAIyTOlMpFjXsFahGsoOQO0/lIyR4tjy5 F4pMvHxW1snWau/cRNESqQGYKYOD3KpcyQW2f0t1d/YEjA2OI/YpA== 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 4fg78g0d5s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:23:21 +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 66KH4cnP016150; Mon, 20 Jul 2026 17:23:21 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgmtjpkxp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:23:20 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHNGUd29753830 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:23:16 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ACECC2004E; Mon, 20 Jul 2026 17:23:16 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1229920043; Mon, 20 Jul 2026 17:23:08 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:23:07 +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 v8 01/11] sched/docs: Document cpu_preferred_mask and Preferred CPU concept Date: Mon, 20 Jul 2026 22:52:40 +0530 Message-ID: <20260720172250.2257582-2-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX75JsjDgUTbv5 GSTytuAiSoTOAhCYUjv532Ggc+qjgiLx42qGlYJeV/2p81fzoSC5ehBsXxviKyoeAeqkiTmgTqi Tt0vl4UlIowJvz+e+8OFcyqf8X7ITgyTrz9xQxBNPmaRs5TabKOf+626IcrT7/eeGChYxH1dtQt g6AvniFK/2/5pH0dZR/ae1a4wNNd5NiuykxeNpsqrHIq5qC/TGSXgR2Um13V7Lv8A7NFTfowycq ARQjILxGQmJSSrd+4zXcjb8hu0zZh4T/D9FmOkXsvdziHseIgQmdJF6tiAEnHwBTvaV1XLfGNP4 aIC7bemkqDr4XBdXJPD3Hb9JJyAZjWBNA6OUFy86S+T8/Vz8jNk6E6SbyIwFG8q3rkJbyCIK8fZ ab/3cTSasWL4bMxu2GEh7AZIYrQyBkoJGgzLNLEtBzExtlH0NUYmkXBXbnotoxCADKVpMBK//qn X95rL69oiePsXCIeW3g== X-Proofpoint-GUID: gwTy5Sd5vLSl-e7sRmyMt8llY1Mv0fsj X-Authority-Analysis: v=2.4 cv=MelcfZ/f c=1 sm=1 tr=0 ts=6a5e598a cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VwQbUJbxAAAA:8 a=QyXUC8HyAAAA:8 a=VnNF1IyMAAAA:8 a=d8MiXRUMn4SEn--m04oA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX1WItabpm635J mP4jPvSlWeC7CpJ5OvGRjF3qAdmnLpFU6+6tVSexa0INs6AB16gIkUMz6W6Ggv7AyMD5kPcFOTY /a7k76ZZEWZEGvgc315JV+IWVSoWBZE= X-Proofpoint-ORIG-GUID: TMbTfP6QlKi6KnhQfW4FJ5O2XpfN5BsF 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-20_04,2026-07-20_03,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-2607200191 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..1ce0f92bc3f2 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. This is done by loading the +steal_governor driver available at drivers/virt/steal_governor. + +For scheduling decisions such as wakeup, pushing the task etc, needs 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 use/not use 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 Sat Jul 25 02:11:08 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 2B8F2381AFB; Mon, 20 Jul 2026 17:24:04 +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=1784568249; cv=none; b=rs34YA9L/Gnk8CxOPHosiSzR7IqZ7Vd4h6wqy7BBJr5BFb+bgWrWDQUWtT9yMlPAdhnNQvggGNaDjZQJjcdPq87IPRQu8AnxHPoU7dV5Bgoll6Oey+ItKpodOQI5mAzgShFXj3v5/JFMNo8+g/qXfUmCrm0BBvEg0CyrSVKLlmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568249; c=relaxed/simple; bh=gmpHwEuFtj2beAn+ZAbelKhxkrT6blFXZd5T1X5Bdkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ilWKAhKysCXAYiQyOv8ma/qU2z+YdDgc86DuY51kKkRKYRtenJ1YHJBfoAg23rB9LkyyOm+8x65ABwFrJ+kb+XGaEZYTj+rZt0ekyKxSvT0qKjOorsuigo6gvu6o0oazbMaNX0aD5QmYOSzNQoco9dFKxEB6Pmr1j9sjOXETf4g= 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=JW6ej23F; 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="JW6ej23F" 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 66KHBkR82816018; Mon, 20 Jul 2026 17:23:30 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=JW6ej23FWnpjHK+GbIu98p NSdjN2G/fqcU/xlpbcrKb/dEYuju0CfJ1ZB1Ts1mLEDDvcC1ycJS162kBkFAVpEu hpV1VfOJ9Nh0zImzezwT5ME0uki441l2QQT3dfwqvukZqlZAU6xTo4+V+OjDyMNd qy/nGCSpjOL3Njw4sLxDNakSPAHHCKddsKzBpButd6kJvu41zWGowLQStobsrVhc zfoLXy4pxp3P6muvbHeruDLX2W+/J1BqOPTvmTBbxFP8aQ7cr8wu7Hb11Kn1vpMb AfEKs0LR93RkkbWrTg9ih5KBs8dMmn5mb56pm+H7ZOotMpd0cgwhrTwCz7Wqn0kg == 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 4fg790rq4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:23:30 +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 66KHJvFb002533; Mon, 20 Jul 2026 17:23:29 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fgktpxsf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:23:28 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHNPrO53084420 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:23:25 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 436722004D; Mon, 20 Jul 2026 17:23:25 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2E04B20043; Mon, 20 Jul 2026 17:23:17 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:23: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 v8 02/11] cpumask: Introduce cpu_preferred_mask Date: Mon, 20 Jul 2026 22:52:41 +0530 Message-ID: <20260720172250.2257582-3-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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-Proofpoint-ORIG-GUID: twjcrRyG2Sk2wVmzk5G8BrlS44HZsg4L X-Authority-Analysis: v=2.4 cv=V6RNF+ni c=1 sm=1 tr=0 ts=6a5e5992 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=NEAV23lmAAAA:8 a=VnNF1IyMAAAA:8 a=9QGdkmv71c8RgJbqbJ4A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX797zaaLBIOS/ EbIwH4opNPgcl7BuEK2SL8MqwSYPcmjv8t3wG97b5fhAT8HkD/dct1CLA3UK8VPGD7eRW4uO9aN hcH8fsnKFvTZk4qzRuzOt+7gVbhnNCo= X-Proofpoint-GUID: uGct0AJ9iawiqx2HSB-ZtlN5MI8tCm1o X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX8A5zuZlMBC4B UZATZXMaV78mKseALWngCKLklhk59b/67bElas1lXTirRmdkPrHr8rEdKL71fzCuw1ryQFrBW7i IHGaPRaJyXvuuNZM2pHja3x5ER3zIVRJKNnijVswZDWilERoHG9PXW2DMFsCjms6bX2e1ECtVbg vrCGd9zeaHLVYgaXscljmxdWSI6L8+j2YOLED8avKNx5fu0uFWSxsEOvMVwQGvMDBuEdnXRq4kf GuI6oWZRbINTVPCabIrFFLXTGl3BTp6vdeqPgXYrPk4m4qVhMs2BFZmLsfeFGJ30M/kt334367u OGCJvb7ZVJvX8inUMrfhL/Vkl1IAl6pZw4/jAdSx9MKH5Y8BtuLK5zrxed+TQq6bd7K8CmjDcjB V9TAm9KgBcj9afId1yjjky0Jul19wLZeBLFLjvQulbCgP+p47Q+cZ2Kpj9pe3iyCvWeuEjmC3xH pjyQBWE2bZLcrYfDQxQ== 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-20_04,2026-07-20_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 bulkscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 impostorscore=0 phishscore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607200191 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 Sat Jul 25 02:11:08 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 2C2023D34BC; Mon, 20 Jul 2026 17:24:06 +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=1784568251; cv=none; b=AOoosawTQaeUJml1M5now9kf5r6NXaLjm9JQpZ9BW7WX1lpPWA+fjP53S/eDEaNqXNEmRtacPoiYYMTqCAXSJHKWVgTifmr9Oj9j8H+/0vT96A3I3cqA3nY7sy30rjn2Yiik+/VdD+weF/Qic1+GVP/6MiNA+McUUgOHsgjxkAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568251; c=relaxed/simple; bh=6228di3K+K40oi6cCOvgEmLnJ4IaBH3W+zV/3UUL2cY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q+czD5ELZaMYO59X56f/fcQF3BScfrRp3ZOdfJTxk5zfUStnqEg0C9MvAXLAA+AzD88XGvnqxyFCSlxth7mC/dfxkV+VfZrN1FOxERXbO6Wb2Wo1h6FM6fUEu1ZmSeMxsqR0oCtH6M2ptgIqx8paknVf8nnWA1AEp3qFSbOsiIc= 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=o2A0nb8B; 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="o2A0nb8B" 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 66KHBr4r2713512; Mon, 20 Jul 2026 17:23: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=cPfhGVrlIhSc9SxNl 84q15+rcHKUKn8NOKKLryxp2NU=; b=o2A0nb8BwCBSvnhEQi97M4/p/0JJSGajY I0//0k4d75gQBHvZSvbGFoBovUsVDPOC3886ti/nRZhQp0iC826gRs1VamyV3VMe jYRpn+OKYWaVIh+rpJEjhLJKWJbZTRGMgwVjLY9sxEdMZqkDhnr3xiHb6s17lgW3 E6itZ1wk+A3CAMZT5m4gzEgJDU4NPMp/PvYHzqxJgkBE7qeV+K9K4G1DpJMXIbcY cxY8huVRc9aVdjd5IsLO/jmtztQjDJXdnGrH+BiiIKzri7WTCnZYqvng+QkCLATe lIQ6vfCDIoBQK4/MuyTEly3UOEUuWLOuI06xSvUSWn25aZSTOYP7w== 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 4fg78g0d7u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:23:38 +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 66KHK0J6002260; Mon, 20 Jul 2026 17:23:38 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgnagxjq1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:23:37 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHNXP639584098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:23:34 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D7DAC2004B; Mon, 20 Jul 2026 17:23:33 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C0B6F20043; Mon, 20 Jul 2026 17:23:25 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:23:25 +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 v8 03/11] sysfs: Add preferred CPU file Date: Mon, 20 Jul 2026 22:52:42 +0530 Message-ID: <20260720172250.2257582-4-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX85tE+tyQQuEw ABgofXbJHuamfBJ2aSR6TYM2acA90ZDWbJV0OWMPJ8I1qnwgUs8ftbxhcyTDfz3vhzeVHutErA1 VE9tD7yE2rsq6FeoFR0wlro9Y+s7Dv2Y/d37mShNVKZ/U2KuiOUzBHJWUYGwJRI0F4DYJwfyp0Z Rzm2ELqDRUZMTqE+JfT96pPsGByDPIXS8mBzUo3MP0S26k8SymNlL1opErPYVT4DN8+zRVuB4fk K0dZvLh4a74lAn6VGAHI98OcTKNpb9iosCJ9/EIUcS/t18B22HYLwGBZ297fDAKlPaiTouM2Jmo aqUnCUTYFOzgcbLEoJ8YSflQjI3Bt6XK/im9AWGzBIMO9Pb8gBEbp9KbEx0gu4OrlAVX3O0PTpU Zw2IMYhear5hpADx7K+wNnF5cVUktWkWAtkri5szhZ7Ju0pngmEl+DY4LbuAw6UUUmckB7CUU5q OEPBVexmQ6EOJy6g9qA== X-Proofpoint-GUID: 15BXk6vYYeecepVdn4aZBIAxACSfipwY X-Authority-Analysis: v=2.4 cv=MelcfZ/f c=1 sm=1 tr=0 ts=6a5e599b cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=VwQbUJbxAAAA:8 a=Tj8IOOKMsRt27BSU_nUA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX8JGVi6S79VtD gYt5QA6+AcFUVFtohfad7yhDjkHo0Ol+L9Q0PB4LWA3iPmWQ8FCb3UeHWer7+E+dkCeyBpMkubY HF8X7T3s2Df1ts5xh80cUwR/QLWL5QI= X-Proofpoint-ORIG-GUID: GJMdKyygHZ4jGcGRpOH4EhFa3U_4dJIX 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-20_04,2026-07-20_03,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-2607200191 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 Sat Jul 25 02:11:08 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 C9908445AD3; Mon, 20 Jul 2026 17:24: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=1784568264; cv=none; b=gnBJN+Es9LmFaNeqRgEtAPW5qzGFx5bNsEpt/GFuTGx7V4OGOlBeXPEafVk3v9LWVbB8nWBB/mJ5c+woa6tx+osl2cnLQv/YhodlQV63/m5QaW2SUDNv4W2c7hii2HGZvWc9IVwkLn4aXCrFtbON/92GBHBkbKPSnRq7Vt4WE+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568264; c=relaxed/simple; bh=r60YBsYQkwwNOoF0Ymgd/+uEg0+fYJIikjKDd5ytK1k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LeG7bnja2A1sUwCS+dmzEMqbzT2IAWpq05ku2KUThE2qt1fmzCwRH5cPCzuqZLej+S+VIpwnSbsgdw/R7v9DXGfDbpQ2yaNLjHsDc6Roc+7wLWHaDun3Q+l74d2dtT92VIS3+tWmdOAp6TzMJ/9nHqW4TZjatV7wb7ozCLlwXFg= 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=lZZfphoE; 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="lZZfphoE" 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 66KHBpEA2816058; Mon, 20 Jul 2026 17:23:48 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=lZZfphoE2+ECNtvIcjmkJe/bi/W44Hlik JAYOSc7dgb5T4n+JT5WjFdw7gZhuf86ZiHD/l9BMjvtZolLXE5Gemr0p2D9FV6GP BwXCBOsCy1Lbx4YcZn4WIoxBUbeiKnhuqceF199KzuBV1bVRrBe0m7uA5wMtNxR/ CQXnMTb7satWn1DQZ0/g1N5OOZRfebwZPVbFBimsW3xChZ/xG6vWuDX/MtNU/rja I/2RKcc8zshzj4kXpDb84b3yd9AHpVOB6rcDrNoxLGG0ELnoMu4+4P//r1+u+FX+ 0HmlLfU/KlbO00lrPzAgkae+ukYI83thA7M4mAdbrX9dLbJX0UMkw== 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 4fg790rq6d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:23:47 +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 66KH4bv7016125; Mon, 20 Jul 2026 17:23:46 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgmtjpm14-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:23:46 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHNgwV60883230 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:23:42 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8F16420040; Mon, 20 Jul 2026 17:23:42 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 783C920043; Mon, 20 Jul 2026 17:23:34 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:23:34 +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 v8 04/11] sched/core: Try to use a preferred CPU in is_cpu_allowed Date: Mon, 20 Jul 2026 22:52:43 +0530 Message-ID: <20260720172250.2257582-5-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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: GMKjWIeFiiPUECT_MxpvwWIiyuz2YIjE X-Authority-Analysis: v=2.4 cv=V6RNF+ni c=1 sm=1 tr=0 ts=6a5e59a4 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=7HQO46LoG9f-b4O6KL4A:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfXxvjgP6ltMQ6/ BuPblXtSyvr0ciuilHVTC26xkiCmsSd4cJhNMJD1IVVVs2/yVxK0Uf5W2My0aLpE48DnGvZyug3 jCzqmOlqo0Z2r17HKVwt9B4qwVbSrj8= X-Proofpoint-GUID: LcAAntBWs20KNCBBghpFUBOaK_cidwge X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX41eXwiaHnvI1 6/tlFxvXC4+I4NDKZOqJM8glfHx97AMqunLSd9cfoA4SNTDmh6KTjp89NRePgHB2KKJRAa5dSdb vpHmGrrnsr5BNWKbYspCujVDzfF3o7xAiYYis5YUKAoPt2dUKVp93WMGqSVxKv4ghNZatpRCazt rC5yICcSExQnWKQIi+VmKaLBJOx9dGwViFtsWol28NQB2Il9e1RCUSm60RaMoe8bK7ECibKMdLk GxPAviCUq60eh55IGNmWbQiD4IcpZnuunTlkbtsmg9PQA1KLxi8QCIxm4xB/ynM4aCtzEj+X6NW TDhbo8lPa+6fb2z/iFVKXhU8sD0anyDJYhG6lKVNtBu57FNsqlFWMNEqcTI5zVFStKnHEFi3fSY aYFGgZSmWOTXxEwFHqrTsBVHtZ/8E90AIoTL00ujt7JZt7Hb7/VlV1Ch4uEmY9tXZSXRYn3vTlU n4HOCHA2Oa4W66c6IgA== 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-20_04,2026-07-20_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 bulkscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 impostorscore=0 phishscore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607200191 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 Sat Jul 25 02:11:08 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 CB083445ADB; Mon, 20 Jul 2026 17:24:28 +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=1784568275; cv=none; b=ieffGpOzeyZZABAkG0Wwi7vrYuO/VRaeVCMxsgMMk4zEnsFbO1H0GBO07sLWeYK7DjZvJk2FJIzMvx4+OD0YB/YYi2hl3YqNwnwlL5M4ICoHQFlpMRWXswS3J3YkALRxIm9d0/WIjuGMSscSjVDzWk/DJz2zKd8Cnmb/jSwxLg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568275; c=relaxed/simple; bh=mogs20aHP34NhTa3btGIMuXI02JCgfTm/y3ZNbaFR4w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T73dwG2ymxLnV86ettRng+C+fu2LqzwuzgCjEYTVQKybCLJhZav3uqUHHnfQ4ajzOCEqZimkH7BmmZhHGL5DlvYX+X38TKbPjK6TOwDoJfP5GSPtfVUiNa49oUl3fasDvCUp7X4F7rRYAZV9N3IJyyy0UkpoSFNOL9WglcP75Vg= 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=igfDG9Do; 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="igfDG9Do" 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 66KHBjBP2730703; Mon, 20 Jul 2026 17:23:56 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=igfDG9Do1AXNfCdHvO3/QCmIxSlyQYdq6 8b3VhLCaCXHcylGpSpCxoeTcxMlHlLFccPZILotpYax5x5w7WQO6D/49N/0giNA9 /pXIGu/4ovg1EZD7RysZUtNidJBtNUGHlaDOeF+rCWJ7nVVIlH9z8ugN8piNtwIp oOYxU6gLfb3mLU8xz7oN1mS2Jzb/t6rjmW7zyP7K093D4tkbbSx9O5r7L1VOuniI TONy5GDtej1KV8W0f5hfivm0se1/lNDpDUpIG9yMr0EELOfKXqZTiBJeo3WtT4MO r0U5Vjng4If3nm1n8YOJcIGNjbGzYHv0MVTVJRVbB1joFy0cJcaiw== 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 4fg77k0eab-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:23:55 +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 66KHK1hR002555; Mon, 20 Jul 2026 17:23:54 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fgktpxsgw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:23:54 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHNoXS45351216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:23:50 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CBA2B20043; Mon, 20 Jul 2026 17:23:50 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F3BEB20040; Mon, 20 Jul 2026 17:23:42 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:23: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 v8 05/11] sched/fair: Load balance only among preferred CPUs Date: Mon, 20 Jul 2026 22:52:44 +0530 Message-ID: <20260720172250.2257582-6-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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=6a5e59ac cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=2Q5jPFoXVaBPfP7xRooA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX1Iu8kfBP5BF6 awDwwH2uSvCkceNEOF4ZCmOlu1FnfV9Q+ty3esLEEI8Xex5waf9HF6JVrkc9a03Jp1eI7fqVuCx XBCIiiAqC0Ay2Np1bIvcImVmiZerHVVrMRotYySSpTiVrOVZJSmVc27kBWz5NIvtl8JJm50AqQy Tsg5Vm4bC3PGTf4osUQO4IQPkHy4wxy5mBgnbSTFaQKYK1PFVWzMpGKlTGyymVGZR+QFBXKSQzi d47aAxl/RIB87reo18VrsdWFtidNcG7eNQSDTDOGx+5xGatembGCXunay6HcoF6O8/w09At84Rp uafp6JjCEj42kUYbfhZrei9rze3tCm33z+ARF9hg9WPuZhDwvfpR+ZNZBXnbj36NCUo2qFToyKh uGfXEZDcvn1jZK14e98u7F6Sm0Q4Gm0xZA8Fd9uA/CBhyHz7yvI67rFu94bpxu9/65SUXFnUWZC Rmmn/sesCBvFxyDnVSQ== X-Proofpoint-ORIG-GUID: 9oPY5zjXGx3zLnuV7tMbon5oFZL-TrZa X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX5sczSoAvWVoH Ld0iHiHfiXbql/cIVboPOBYWPtiai3Ejem65rQ0u3Sa3Iqu2PzPPNyGbh4QjXf6uRw7CVHEbba/ 63ycJpv+fpS+ip+sa21ZM/uZY5uUdTU= X-Proofpoint-GUID: i4iKLkAEMNMw0D7gqeXaRlTuG1v6ADl_ 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-20_04,2026-07-20_03,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-2607200191 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 Sat Jul 25 02:11:08 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 2531044607F; Mon, 20 Jul 2026 17:24:35 +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=1784568285; cv=none; b=jVisBhrfHvZm0ITVca+WDPwS3BiohhpHzweZJtyWOmaVj8fLEmXcUWXvyIcmmLRyZsXen06FWUFORCP4waxYsrNZ7HMlPfgMbIOsvs9vSVzMNtrBtnURWnduVJLRszLibQfLqJ+tXvWKhuXFMAUzIxhSDzmJlgLmngE2Smw+3A8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568285; c=relaxed/simple; bh=xYaZZ11j2sFV5+8PjVh0nKD2mmXPHg4KZVuN0UomHvw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FF5NEb6D7QBQp0PwQ/vl3VA/XKqEpSzJD2GbmkBCJDdziKjVdUqbDRLKxXQmJ+J9ytgY6tNNLqL2AprUBHDN/QRA/D1q7gpuRMr9Iq5LFYrWHv2FBynXeelvMOvoMm16uhSKHDU5SPZFVZ5ACpmpteQ7HkwaWCtFwPf5jwTi/vU= 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=gchLA2Xq; 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="gchLA2Xq" 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 66KHBnOJ2713277; Mon, 20 Jul 2026 17:24:05 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=Bmcx0tI2xOrzbSGMc fWrb3sC1VpvJlYITYZEao9ETfo=; b=gchLA2XqqyDCLlblL2Zi8crC2vCjoKtaE N/blwW0zAu45SEwgTvtXGNHxWQk1WpJuckJxTWH8ZTK/mWlEjxyCl38MGOwc95hW GlOzF/9SY82nlclwoHAqUPHNXwV4CkBKBFWaZGhn+RfwgXAV5hbzB/faS8WNJqoT MpmjBOW3DSZrZdq7CdALNd1ERtMlSs/szT9X50y4/IORhqe5yiuj8OyLkT7Urkh/ mwo08Z/o+FzZnUpiqDurKThoDxR52gbgrmg3eaBAfFl/n04YfHnjsBrZGlMacPYk mWKw42oGp0UkeZDkS78gMKjmHGQpqRWDusTnmN+Ue/Ndq9sU1EzdQ== 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 4fg78g0d9s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:05 +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 66KHK9ch002413; Mon, 20 Jul 2026 17:24:04 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgnagxjrd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:04 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHO01W49283558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:24:00 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 43E6E20043; Mon, 20 Jul 2026 17:24:00 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4DFFA20040; Mon, 20 Jul 2026 17:23:51 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:23:51 +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 v8 06/11] sched/core: Push current task from non preferred CPU Date: Mon, 20 Jul 2026 22:52:45 +0530 Message-ID: <20260720172250.2257582-7-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX0ClR61GBfmLw Rs8CXBYjBjwEloEIPghSMGoKQeNWcb0wBFKcsOt0HetdKjuslAl3A50jCgWGfjTFIvIX22luMvb RKh6hTBwscgx/BKEpP0jp50Vb7k0DlpYJsYZyHGpz0G3/jVGPRkTJndi/lB3m9MI5LpGiuWF3kv m1DfgdLKOBtV2z8DpUT1Jb3h1EaaYWbNJ6IrH4/wVT92c9uqssYnb4I+im6VOUlU2fmDbQtDW6U 8GEwBYgtyr+Y81UQtyWU9Lirx3Bz0Oo7A3bujWgFZ89MtYp1T2IhBUcIUIQ4mJ2hLRD3jLTgIqY 9ANj/MVzx+ZZNHNhlFzPMasLqZMKPchYNOFZ3tEjGGwSHUh22Bl0Zj33NiLBOBH+fOydWSCX5Ro nhsVGrOUdrosV5OorXFOpinwO5ameTSR4XW/lqGfuu5Y3teJskpNNH9o5eVGoAYpi8mCUPwNRKz RAmTW/Q/b6vljfgzG9A== X-Proofpoint-GUID: S9VyMiGkjjjhLmJJCAIuAL5LPBLB19M_ X-Authority-Analysis: v=2.4 cv=MelcfZ/f c=1 sm=1 tr=0 ts=6a5e59b5 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=rPhwLmmYJdnLsqmuV48A:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX31ihFzlstode pI0fMbgNG0+tmiTN7sTHtGpPlc1pzMCZVjxnPfEOjIdO5p4RsCwMc0X3OkeVbogR6wEnKSzpWcs 2kRTru5DIprfFsPbsrGbW9v7b2ptI8o= X-Proofpoint-ORIG-GUID: Tqj9VZFAXY_J2sz1u_nJqjp3J-FoaTCI 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-20_04,2026-07-20_03,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-2607200191 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 non-preferred CPUs, no point in moving it out. + */ +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 Sat Jul 25 02:11:08 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 3BE7A446824; Mon, 20 Jul 2026 17:24:48 +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=1784568295; cv=none; b=Dr/uuCx8InDuNWlCjhutyJOdaf8GMEJv1uFVdDNFHQbUNGaE3b77ss6y2qLFkPIFOJ12HgynsXHqq0P0nb2jDR2/lU5D6O/nQxO6duKT00fBl80j09SwP3itl+pCZDz+QL4dUK1jnFQDLUU1wIBi8EH2P+BTJB3LVbKcuPCjG5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568295; c=relaxed/simple; bh=GKJDo8AI7wWFoFr67ephXxtE17uqG5Sitcmc2r3sofM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CIVbl3fBKjALodykizB4OwLCi38llUTPb8AlhSHYlwbRRv77cbyD3mbYHDAAYjBNz0vNQY/JWkGDi+SbRmoIbbNNxgRqbEdS+m5g2gmK+ZYpNIG96kN2lnPG04TnBc6pIfErv/hAyRmcBtiyTd/+Ln3btXyu6YqAIYZVHRWvpBI= 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=D3YdqaBM; 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="D3YdqaBM" 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 66KHBg022815868; Mon, 20 Jul 2026 17:24:15 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=D3YdqaBMw+nl/y/+iGJVl/9bomMFZqMY5 /E2Syj31tXCBaMekNqq1chXTGeOpxTEB0HwyQURp6bulKLc4LO+t8RIZezctgtl3 i474vBaCzBZYWG623rPBoAkB4ljzghJ+xWbW+NZ0uQFW3M3gk+v1xRpVAZq13KNw u5D98gTTadi9eaYfDPKFccXj8qpjbTySpiV0ufY4uDEEMYaiVUOFS8oqhFcAF+9p IEV6zBMaREGn5PLpzJlZH4UkFN76oPhpG9i2MxcSMfD1DNuc9r3kKYsA7LAT+/kE TiM0RYLEb2rXS5VlXvO2xVNkWbNYhYV/rfiFvIQs7G8ZLCDfUyAyQ== 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 4fg790rq8e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:14 +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 66KHK0JB002260; Mon, 20 Jul 2026 17:24:13 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgnagxjry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:13 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHO90n10420638 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:24:09 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D0CE2004D; Mon, 20 Jul 2026 17:24:09 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C982020040; Mon, 20 Jul 2026 17:24:00 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:24:00 +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 v8 07/11] sched/debug: Add migration stats due to non preferred CPUs Date: Mon, 20 Jul 2026 22:52:46 +0530 Message-ID: <20260720172250.2257582-8-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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: CMhb9ormIitGwgLRG95x5bje4v0tFU1M X-Authority-Analysis: v=2.4 cv=V6RNF+ni c=1 sm=1 tr=0 ts=6a5e59bf 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=-i9lZGrASMRMKgkbeRgA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX506iJGzgXXEr aK7ET/FUtmk4MhC33L7r5p7pibd8nqoinJVe0+tCJa7NTqCw9fxjTdxLtZBQ51aeh3KKwt82H+Q oL2uFuJsQCSs356r72IHMV9m6z5uWWw= X-Proofpoint-GUID: cOxhTDn8N0RCtGLI09-FVkanVKPWrtWP X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfXwtXiluePDxeK FDkresOJVJdl8KacuQNa01bPuC8A2Ii4L1IGs3RxhndXdhqrRElcpYCAZKIKkTf2qTynokGKRKA Zlz8e4hGizEhW4NXhzzBaLVNzLtrSCsVQ2lTrIdZkuwviPzpY/1mBVorx0iprIRnzZZBEMpA2hW fTlOJHGOReEfVrErGP87G6GTP5PvK8JFFsOTsvWywOt2815uMXHVnKtiZ97nY9B2p/4R0TFMtmz N+C+cfNuH4LtN2idzjxCez3b5EWJ/G5+/2ciAH1ErKwCS5+5P0COIDaFzh/i7lPAs+RjrfjglGy 2DMIs1DwoiwNNjct6LMmT+27GTHkHdqJTOlWclAipbGxKlAeTlYJUGsU3T1zQ3tykUsbFrCF5jX GAxEt1fkVhh0hI1lOrWpMitVZD4cmUus0k0J8hqYZUh5hHshMqaqg7ERMM1XaOFK+298TUQl8jQ W/PSSSA2HSaWSfnHpKQ== 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-20_04,2026-07-20_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 bulkscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 impostorscore=0 phishscore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607200191 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 Sat Jul 25 02:11:08 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 4261A445ADA; Mon, 20 Jul 2026 17:24:51 +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=1784568296; cv=none; b=n6xnhpbBj6uF/45SNtkqSG69gYtc7YUv58+Ffx86P3uHbcObnh6+KOXZoKITmji2hSZIfM/KMq7G9icU79xsrHAE/dcpyrMSlVofwAVdRPz1phRjZ4JKbWJSyfvqGjw0TRSvabpYNr3YCHvv/wGZEUTX6xnarv6G5BX1hlTzjN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568296; c=relaxed/simple; bh=J/wI6gIuFBixOfeuqUtjVK4AECJsiCWXkGo11z4ijf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C4Dil4aLgqz4ItUE3Mef6vEZIeFQ0jxJMyifhgX/D3Zd8jW06RCwKqeD2gp8OlTIQg4r1x4q0MGffH5NEYZV0gbF1nIGrQNZ3xvxpOJMjnyzYQg7SJqngLwLMhPzJPvbU0jKJTn3H05dosq3SlkFAIECuT3pjhgdZGUSUuua4/U= 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=PnUZ3TqT; 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="PnUZ3TqT" 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 66KHBk8l2810995; Mon, 20 Jul 2026 17:24:23 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=DLFPEsNarXY8s/Rav 7WFn9zv40N/Pf+0lGG9X6RPONU=; b=PnUZ3TqTLN6AhQBVPhiU0Om7tjZxP5crh tsSG7C+1FdPkZZqaTTVMQBXwvIA/Lca9iat23Lc3o5h/Sm0IcAjv9urg8F+u6Msw ReMeELLrHhhKpA0q3bDI6M7wvZruzlsuGchGDyLp9n9FONG021OdZksWYrvFDVBh 04oD/nyo4zma1tdQ5HYzmiu7Muev/vWtTLZ4FZlb9VgX70O1ry5Y9ParUBgkCJJW /Rb47+NInz+bkwRP1B8VdAqYPGowXDUk7mnEZxXglId6K4mYvXoQF+X9oy3bmjjj 94ztXILH0vCBbwYm2j/oCwj6sJ3rZOiWHtOYhA4lOwrbYl8hymh9w== 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 4fg7ah0dc6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:22 +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 66KH4cnf016150; Mon, 20 Jul 2026 17:24:22 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgmtjpm2v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:21 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHOH2C62456198 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:24:18 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C745820043; Mon, 20 Jul 2026 17:24:17 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AF23420040; Mon, 20 Jul 2026 17:24:09 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:24:09 +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 v8 08/11] virt: Introduce steal governor driver Date: Mon, 20 Jul 2026 22:52:47 +0530 Message-ID: <20260720172250.2257582-9-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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: z-iSRlq4_siphCBx5kU3baHRDs85IV4e X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX+aHiPHnaOLAB /j8FB5/DkvXD8EH8kyF/7m3/xELFV3YICwkGgpPAWpX76uHKr0ILMFE98exSkPOWIkY6bf6gxNd KOXIZR6gTk3+W+VOao9nGk0l9naxKRKc3nx7WcKuHnK+TbWJ60z1/4XnE/JwHagZYQ05r4hgHYE LaOfiCQT1a1H37TD/MhkavStjJUmN8GYKfD+j9qPBWdbaYJEUMcRklK54YGWnSEoeKiqd3fC7aV uqYagOILm4MF2ZcMJtuRfEvnTINGNZHYxmKWoSy49tv/2v1J0OE1LCZ2oPp3xj9x51qfKGg3zYi uBjuCGyZ9qUR2cG3Xtc6x1bLxAu3O7cNKI5G3oeIShE44pSBceIjzr3kf4lFF7iDQlOFSrJgdk7 hyrRnaPJHOOHG/dD51pTCLsvF+7S94ygaaTtTevvez6xEXHXAfg1JxqHaDotWCCzqjZk3pVLqFL 2TBbbKINcs8pAYswt5A== X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfXyctUBDWpYy81 nUTpoG4evpRfdr9s3sBux4jz7J52Y143XKSZ3pzO63Vn4d50IhkWq2Rir95vYVIXxUJwf8oi1XZ 7wKPOjafGgWKHzeYbnLQxIqnTSeyzLo= X-Proofpoint-GUID: xsjDJcY80owJOyCeAQ2YFiaHyE2NsXaS X-Authority-Analysis: v=2.4 cv=SM5ykuvH c=1 sm=1 tr=0 ts=6a5e59c7 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=pGLkceISAAAA:8 a=VwQbUJbxAAAA:8 a=8b9GpE9nAAAA:8 a=BDDCA90khhlK_pKEhh4A:9 a=T3LWEMljR5ZiDmsYVIUa:22 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-20_04,2026-07-20_03,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-2607200191 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. - core.c - contains main driver code. This includes the periodic work function and take action on steal time which is introduced in subsequent patches. - core.h - header file which includes data structure. Main structure of steal governor has, - work: deferred periodic work function - steal, time: To calculate the delta 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 | 117 ++++++++++++++++++++ MAINTAINERS | 9 ++ drivers/virt/steal_governor/core.c | 48 ++++++++ drivers/virt/steal_governor/core.h | 25 +++++ 5 files changed, 200 insertions(+) create mode 100644 Documentation/driver-api/steal-governor.rst create mode 100644 drivers/virt/steal_governor/core.c create mode 100644 drivers/virt/steal_governor/core.h 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..1039d598fc2c --- /dev/null +++ b/Documentation/driver-api/steal-governor.rst @@ -0,0 +1,117 @@ +.. 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. + +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..0906684b2243 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/ + STI AUDIO (ASoC) DRIVERS M: Arnaud Pouliquen L: linux-sound@vger.kernel.org diff --git a/drivers/virt/steal_governor/core.c b/drivers/virt/steal_govern= or/core.c new file mode 100644 index 000000000000..055f155d2045 --- /dev/null +++ b/drivers/virt/steal_governor/core.c @@ -0,0 +1,48 @@ +// 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 as module with CONFIG_STEAL_GOVERNOR + * + * Copyright (C) 2026 IBM + * Author: Shrikanth Hegde + */ + +#include "core.h" + +#if !IS_ENABLED(CONFIG_PREFERRED_CPU) +#error "Steal Governor requires CONFIG_PREFERRED_CPU" +#endif + +static struct steal_governor sg_core_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("steal_governor is enabled\n"); + return 0; +} + +static void __exit steal_governor_exit(void) +{ + restore_preferred_to_active(); + pr_info("steal_governor is 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"); diff --git a/drivers/virt/steal_governor/core.h b/drivers/virt/steal_govern= or/core.h new file mode 100644 index 000000000000..e27305284ac0 --- /dev/null +++ b/drivers/virt/steal_governor/core.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __VIRT_STEAL_CORE_H +#define __VIRT_STEAL_CORE_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +struct steal_governor { + struct delayed_work work; + ktime_t time; + u64 steal; + unsigned int interval_ms; + unsigned int high_threshold; + unsigned int low_threshold; +}; + +#endif /* __VIRT_STEAL_CORE_H */ --=20 2.47.3 From nobody Sat Jul 25 02:11:08 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 567A0445AEA; Mon, 20 Jul 2026 17:25:03 +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=1784568310; cv=none; b=eWUwiprOT1UOHcWh63jaqRoMLIyQguwM/vWsWcc9ArmbzIX77RlR+rzAxClXenACVTPGjCd11hd01CZVDOwpQidUJczSEpRn+y4NnrjDDS87svFaBV6hP+pTqteLeq5QOfyp4xRAm4gkMs76n3QSlJCbEeTif/h1D+ss0z8aD2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568310; c=relaxed/simple; bh=gAgQBybyeInWqS/Jps2UHI8s2sjg0LrS7abTgHBRJiA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N6Bk5q0PJKVxVK9fu7zYT16+hyoY3iL8AmizqcLcHw8z2dPFOpQxEkfh6Q4y5HiGxOZYimnGoAdWAPxNtujfamjaeRUNC3KbKigUscjTBaEnb2gG6TUiXmoNpBbP1xLPSMYuz7DflLRQlbW/VOU+9mRb1mNOSD/IhjkOke8Y0Ys= 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=Wo6tvO3g; 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="Wo6tvO3g" 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 66KHBg042815868; Mon, 20 Jul 2026 17:24:32 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=/Uj2IdE8ZFuqxyd6v V9cb+p/drkSgSrLxKK/Nlw5wpg=; b=Wo6tvO3g4eeqLOEzJ1EwlPiqWmEDKPPRH plSFbh2Jd6Mt0ViCZYHW1ZdUHu69Ra8qTEpH08jtw5410m/JbVSx45AKmMIn8mXh +oJ1soevZm/YWwnA/87/EZajJFqiaa+X3BacE5XIz1E6QoLHAWizhXKwv/9LJSe/ wmXWhVSAilwRW8iC2oSDMTyUnGjjhUB43hR3HiGj0sK8O+rGbv3YRleG6kugWTTS 3AQODz8xHZy/EJKkBMYe4hnFN3cSVN0rpfbdklpp6t8RPsUO5xMWzAt8ip8C+A2L 1CZlaaoa7INTL6Bfew2DggdH/jlxvyhg+WcKD9cedR2EP/1N0cOtA== 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 4fg790rq9q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:31 +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 66KHKAut023843; Mon, 20 Jul 2026 17:24:30 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgm6vxr37-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:30 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHOQxM24379874 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:24:26 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4BBB22004D; Mon, 20 Jul 2026 17:24:26 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 341C520040; Mon, 20 Jul 2026 17:24:18 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:24:17 +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 v8 09/11] virt/steal_governor: Add control knobs for handling steal values Date: Mon, 20 Jul 2026 22:52:48 +0530 Message-ID: <20260720172250.2257582-10-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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: r4LOzhnb7KqmwLwZjchrAhyzvQ9fVluJ X-Authority-Analysis: v=2.4 cv=V6RNF+ni c=1 sm=1 tr=0 ts=6a5e59d0 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=XC_GqrfF-lTPz34eE_0A:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX0pdrYH5Y1JNp aU2E2NMZ+oCni7hZMOcymDkr8YgSoiA2S27PjawBBTOCtdT9yrPfDsxtL3v9ctWSAnmvbutcCuG s1OiDST1tnf3OWsn0jNRwlxZOqtamw4= X-Proofpoint-GUID: T7ABc4SPSa_R-RuoWeFJCyd8vwtNmYkQ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX9Tk1OD2K+a6J d5HKEg3LVMFMWv3MLpqc56MP3IxDUQ+My5uCoI5c4ZIMuBO+5Qp6kueOQuz8vCxsUUlMADcr5yd 98rplo2Ngn8vnS9fptSinOlUHkKRySYgC+X890wYfUHP6eGWYDfv+1OWNe3e/tDzjoL984yYSqo sTtd6cPNVxYnemus/PbuJ+Kq17PnaC0RYNTdnfKJGX7uXu21fnm5lU/2ZQEjLGqmlfYzutAcF7y Vt046zNkaK9e5ls/ZIf826/OK45ru5XJ29Rftib6I7VerPAPzRR6fj1QKMJT3WEEtFWorRNFT5/ jcCUUmzCRZcmFcx+IRoNJtLRQQG8qxqz9ZRfq0GRMHkiurA5IWRKDXd9tntfvsZmRz7EU8mfCWd 2rLZNFtGzS/T0RQlYnt1hrpYFZDA8OFxgE0kil15k57I0gg59J2OzTZV+8f6Pa+mYZZPBNKJ7Jo XucmX2eoNXOK9A6RLqw== 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-20_04,2026-07-20_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 bulkscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 impostorscore=0 phishscore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607200191 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/core.c | 73 +++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/drivers/virt/steal_governor/core.c b/drivers/virt/steal_govern= or/core.c index 055f155d2045..1cb766a8ce28 100644 --- a/drivers/virt/steal_governor/core.c +++ b/drivers/virt/steal_governor/core.c @@ -17,7 +17,11 @@ #error "Steal Governor requires CONFIG_PREFERRED_CPU" #endif =20 -static struct steal_governor sg_core_ctx; +static struct steal_governor sg_core_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) { @@ -28,9 +32,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("steal_governor: 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_core_ctx.interval_ms, 0= 444); +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("steal_governor: 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_core_ctx.high_thr= eshold, 0444); +MODULE_PARM_DESC(high_threshold, + "High steal threshold. default: 500 i.e 5%. Must be > low_threshold"); + +module_param_named(low_threshold, sg_core_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("steal_governor is enabled\n"); + if (sg_core_ctx.low_threshold >=3D sg_core_ctx.high_threshold) { + pr_err("steal_governor: low_threshold (%u) must be less than high_thresh= old (%u)\n", + sg_core_ctx.low_threshold, sg_core_ctx.high_threshold); + return -EINVAL; + } + + pr_info("steal_governor is enabled. interval: %ums, high_threshold: %u, l= ow_threshold: %u\n", + sg_core_ctx.interval_ms, sg_core_ctx.high_threshold, sg_core_ctx.low_thr= eshold); + return 0; } =20 --=20 2.47.3 From nobody Sat Jul 25 02:11:08 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 6847F34F24C; Mon, 20 Jul 2026 17:25:12 +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=1784568320; cv=none; b=sLitxb9ibk6+jwNbDxxq6cRx2yZkJvRy72G6yF7UDPjliz3i68w1g5tRryC/QEFOonWUze93qJHqwmpSO3BE51G0n3O1y6W0OGwRk4tyrRQQfZbk4fEuHElJ2Qjh5oh/PHGxJYE/WztP4ADEC/wd+/wFPBJfgVc0yT3il2aZ/kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568320; c=relaxed/simple; bh=+gTR/UX/KM1ppW80g8D+7wCBdjKbpWLvfZ05vvbG5oQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h+mrAsciZMs083WOBS4aj1SIJ7FLPqH7Dt2sKIinpukjrwRM2gs18/jEv6Xlo4lMlJvhQaKp6dQKRMxdykUE2rCJIddfYagjH23U0C1DQlV0wXzSLOY3JfqI8xHEGZfU6wyn+gJs0N85c2tbspI/XuNwWdllAywOuYUzh/tviUU= 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=jlTLsi5a; 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="jlTLsi5a" 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 66KHCZN12714996; Mon, 20 Jul 2026 17:24:40 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=lpavJ6Y0X+wN2wVis fptYdvYz/1lyMylIj5b8vP2mjk=; b=jlTLsi5a+BiVzUJ7etCO+L0BBSngsB7Jl AUySDPZB83Uo2+pd/Ve0SSdPvO/hMixEqivpuEL5Xq/djNM9gv9JF/ejuoiSSmNv jQP5XkD2rDF10FdbJdsuzU9FC4vRxs6/An2XXEeg2Qpq8ZIFH6cv+GCHoYMUzq2H YLMZdzOJXYMif+8SE3ROlHBW6/SnLfA7gA6HZQaDD1SZ2efMmNFSvPSAjZuDXjCA bJv1l9+DFApZn3DDBD8LJC/+ESKc6UrDZK/Z/phRCYcWu6+zB/KhSf15NFP1i6d/ ujpTfBID3iWmNog4xISDszhNdlIxyktEI3bsMIX63so42CD5lK7aA== 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 4fg78g0dc8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:39 +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 66KHJwU4023243; Mon, 20 Jul 2026 17:24:38 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fgm6vxr3k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:38 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHOYW952166920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:24:34 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA2E42004B; Mon, 20 Jul 2026 17:24:34 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C7CF120040; Mon, 20 Jul 2026 17:24:26 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:24:26 +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 v8 10/11] virt/steal_governor: Implement steal_governor policy loop Date: Mon, 20 Jul 2026 22:52:49 +0530 Message-ID: <20260720172250.2257582-11-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX5hGqNIJJZ+5k zZAkF8WgrBt2lY6U3bs0wpVEeJQ0CygedZwrlmSQCMO0GQq4Isrs5xuzxKXH7kDCV0irPOulEFk ZRi7Vdj/SyG3u4+JgJO/x+1im/dQjZxGq8AhEiIeknK+Byt/qSwK0uQLe3MieXuerlBHKK2isyg ML6ImObaAQNORrIqw9uVlF7PNWViEu560EwD0HIwAeC435JAtRKBMrB7xhxIDO85eIUSwsLIxup uQrcuPHv1pGemxcswj8TiqgsHrClMeMrp1v5k0WEZtZhySRVX4RiLmWFq9DGuhvfhZiOaKY6+I9 apFPVkWQvs+jgR25GLXnT44fMrGiayucgxJYIpLA/oVmbvSheYUnh0/ewU76jKbgAiAjOyPh8S0 cr+wQJybVp/7P39zsmhjmOtq8iovg7SOuhmcFBpXRyVJ0p4xqy0ZOlaP+g7DZGPDU9N5DM9sXUX odR7plFC7u7QE48knqQ== X-Proofpoint-GUID: tFvuEG9xKY6WuYDDMzi_buEFDzUCbLIW X-Authority-Analysis: v=2.4 cv=MelcfZ/f c=1 sm=1 tr=0 ts=6a5e59d8 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=dzxYU6fr5WJrpIuQ_HEA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfXzfbMHHHsqp/U HYTkmZJPOvfGc5lHCcYii6iFqLR32yI2uSt8ySHuSatXlICTgbzxIkcGGat/KM5AmB65ha+FVpM 774gq5TTjFQLKX+hyas90RLuIaJjzgg= X-Proofpoint-ORIG-GUID: cPwz2W4GhKgr65z2WT8PLlEt2Pv2nDVr 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-20_04,2026-07-20_03,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-2607200191 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. (get_system_steal_time, get_num_cpus_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. (decrease_preferred_cpus) - If steal value is lower or equal to low threshold, call the method to increase the preferred CPUs. (increase_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_num_cpus_steal_ratio() - 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/core.c | 160 +++++++++++++++++++++++++++++ drivers/virt/steal_governor/core.h | 5 + 2 files changed, 165 insertions(+) diff --git a/drivers/virt/steal_governor/core.c b/drivers/virt/steal_govern= or/core.c index 1cb766a8ce28..97f82d6df60f 100644 --- a/drivers/virt/steal_governor/core.c +++ b/drivers/virt/steal_governor/core.c @@ -89,6 +89,158 @@ module_param_named(low_threshold, sg_core_ctx.low_thres= hold, uint, 0444); MODULE_PARM_DESC(low_threshold, "Low steal threshold. default: 200 i.e 2%. Must be < high_threshold"); =20 +/* + * Returns steal time of the full system. + * Compute collective steal time across all possible CPUs. + */ +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; +} + +/* + * Returns number of CPUs to consider for steal ratio. + * Return possible CPUs. + */ +static unsigned int get_num_cpus_steal_ratio(void) +{ + return num_possible_cpus(); +} + +/* + * Take action to decrease preferred CPUs. + * + * Decrease the preferred CPUs by 1 core. + * Take out the last core in the active & preferred. + * + * Must ensure + * - least one housekeeping core is always kept as preferred + * - preferred is always subset of active. + */ +static void decrease_preferred_cpus(void) +{ + int tmp_cpu, first_hk_cpu, last_cpu; + const struct cpumask *first_hk_core; + int target_cpu =3D nr_cpu_ids; + + guard(cpus_read_lock)(); + first_hk_cpu =3D cpumask_first_and(housekeeping_cpumask(HK_TYPE_KERNEL_NO= ISE), + cpu_preferred_mask); + if (first_hk_cpu >=3D nr_cpu_ids) + return; + + last_cpu =3D cpumask_last(cpu_preferred_mask); + + if (last_cpu >=3D nr_cpu_ids) + return; + + /* Always leave first housekeeping core as preferred. */ + first_hk_core =3D topology_sibling_cpumask(first_hk_cpu); + + /* Find the last CPU which doesn't belong to that first hk_core. */ + if (!cpumask_test_cpu(last_cpu, first_hk_core)) { + target_cpu =3D last_cpu; + } else { + for_each_cpu_andnot(tmp_cpu, cpu_preferred_mask, first_hk_core) + target_cpu =3D tmp_cpu; + } + + /* Only the first housekeeping core remains */ + if (target_cpu >=3D nr_cpu_ids) + return; + + for_each_cpu_and(tmp_cpu, topology_sibling_cpumask(target_cpu), + cpu_preferred_mask) + set_cpu_preferred(tmp_cpu, false); +} + +/* + * Take action to increase preferred CPUs. + * + * Increase the preferred CPUs by 1 core. + * Add the first core in active & !preferred + * + * Must ensure preferred is subset of active. + */ +static void increase_preferred_cpus(void) +{ + int first_cpu, tmp_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(tmp_cpu, topology_sibling_cpumask(first_cpu), + cpu_active_mask) + set_cpu_preferred(tmp_cpu, 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_core_ctx.time)); + + if (unlikely(delta_ns < NSEC_PER_MSEC)) { + pr_err_ratelimited("steal_governor: work scheduled too soon delta_ns: %l= lu\n", + delta_ns); + goto requeue_work; + } + + curr_steal =3D get_system_steal_time(); + delta_steal =3D curr_steal > sg_core_ctx.steal ? + curr_steal - sg_core_ctx.steal : 0; + + /* Update for next calculation */ + sg_core_ctx.steal =3D curr_steal; + sg_core_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_num_cpus_steal_ratio(), + 100 * 100), 1); + steal_ratio =3D div64_u64(delta_steal, delta_ns); + + if (steal_ratio > sg_core_ctx.high_threshold) + decrease_preferred_cpus(); + if (steal_ratio <=3D sg_core_ctx.low_threshold) + increase_preferred_cpus(); + + /* maintain design constructs always */ + if (cpumask_empty(cpu_preferred_mask)) { + pr_err("empty preferred mask. stop steal governor\n"); + restore_preferred_to_active(); + return; + } + + if (!cpumask_subset(cpu_preferred_mask, cpu_active_mask)) { + pr_err("preferred: %*pbl is not subset of active: %*pbl, stop steal gove= rnor\n", + cpumask_pr_args(cpu_preferred_mask), + cpumask_pr_args(cpu_active_mask)); + restore_preferred_to_active(); + return; + } + +requeue_work: + /* Trigger for next sampling */ + schedule_delayed_work(&sg_core_ctx.work, + msecs_to_jiffies(sg_core_ctx.interval_ms)); +} + static int __init steal_governor_init(void) { if (sg_core_ctx.low_threshold >=3D sg_core_ctx.high_threshold) { @@ -100,11 +252,19 @@ static int __init steal_governor_init(void) pr_info("steal_governor is enabled. interval: %ums, high_threshold: %u, l= ow_threshold: %u\n", sg_core_ctx.interval_ms, sg_core_ctx.high_threshold, sg_core_ctx.low_thr= eshold); =20 + INIT_DELAYED_WORK(&sg_core_ctx.work, compute_preferred_cpus_work); + sg_core_ctx.steal =3D get_system_steal_time(); + sg_core_ctx.time =3D ktime_get(); + + schedule_delayed_work(&sg_core_ctx.work, + msecs_to_jiffies(sg_core_ctx.interval_ms)); + return 0; } =20 static void __exit steal_governor_exit(void) { + disable_delayed_work_sync(&sg_core_ctx.work); restore_preferred_to_active(); pr_info("steal_governor is disabled\n"); } diff --git a/drivers/virt/steal_governor/core.h b/drivers/virt/steal_govern= or/core.h index e27305284ac0..59329c1d7109 100644 --- a/drivers/virt/steal_governor/core.h +++ b/drivers/virt/steal_governor/core.h @@ -12,6 +12,11 @@ #include #include #include +#include +#include +#include +#include +#include =20 struct steal_governor { struct delayed_work work; --=20 2.47.3 From nobody Sat Jul 25 02:11:08 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 B89AB3D34BC; Mon, 20 Jul 2026 17:25:20 +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=1784568328; cv=none; b=ebai0uXDQNUa+4yoC2nCo/53nzSz0mazjpYvTdVC7m6vRszeak6hEjaF0clRdAhNVLRW379y/jdhI7U106IsHf4KXFh88jp+3eZ9xcm1V70M7sJptuK762mYykrlvNgpzpF4VDYnRRabw/2X8SNRgs0aaaDnk76y8KDF7fR+FHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784568328; c=relaxed/simple; bh=iafCAOaP3qDmEL0lab8nmndNwkPiW5QlXAdGGkZoRqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pCJFFUTAUAuqC05FETBis+2AmhM6dCdV/fwPHP9MkT7+oBuok94OzsNhJllo4ITl4vSdfZk8rjgURHPS09f4K4qPbB1bmEknUd4271/n7xbyGVdS8lHxqO4Gvei5nIPaofQoZj99iEmY+oWC3EieJUHXWDizeM0Ilka7C5N6WEY= 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=lFK14ZP/; 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="lFK14ZP/" 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 66KHBjfG2807807; Mon, 20 Jul 2026 17:24:48 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=O/TMGpUmCSAvPYTnc V9etfBFBMEtb4gIkAdn6Y9c4W8=; b=lFK14ZP/Sy9WJFjAfhyfbCshUpvuQD3GY b5onCqxMS5l+/fdF+567QcrAyqNXTyIU/MFFBymaj58xT6LsRtgWwsnFbo1K8VAn OJ4ZwkO+va89CHwss4dwXJeaO3FTNX1S6iOsHHXAujsE2vIZD4Wl663Xoa9qKhkC AcMXRk136s0FpUgHItflFMigQ3HIZQyH98q1BrijrB61Sdz5h7Aw+5sWaTpCG9WV bBguNt7kp1PEiCKEriD1QkfMWnzh5p1e+lI2OZILE3hvp/kOkSp1DyNEqL8Ysorl Zvh4zE/ZAAmjTLpuzEDW58NwKWAFc5tbvTeRlO+b9w5ifTGcNboIA== 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 4fg7ab8qv9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:47 +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 66KHK2UG002609; Mon, 20 Jul 2026 17:24:46 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fgktpxskk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Jul 2026 17:24:46 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66KHOhDF53215644 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Jul 2026 17:24:43 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 329132004B; Mon, 20 Jul 2026 17:24:43 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3515920040; Mon, 20 Jul 2026 17:24:35 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.130]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Jul 2026 17:24:34 +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 v8 11/11] virt/steal_governor: Enable the driver Date: Mon, 20 Jul 2026 22:52:50 +0530 Message-ID: <20260720172250.2257582-12-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720172250.2257582-1-sshegde@linux.ibm.com> References: <20260720172250.2257582-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: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfXw22NCCToRlAI vIwx7W9I3Oit3fpgwI78GkoqFh6qREUgemblwtBAwNz2uwwCgFvDLAXfpiClseU1KUJBcl0bmdU CeS3hUGh1Zo/HgvdQoEUb7DYapZAVfUIo+PxkmZzB4NbyvfWgsJFGaR5Ch7rvgpptpZ7outN3UF JNLzaDV5MB8QICLyVKaHrUiGuKaYL+uVsxtSPoJ9yRD1k0q7hxPEYx+x4sGps8IhtOJ+Ovz4nRr ySd+9mZEwX44TeeVrrq/IflmPK7lA80G3XAhh/GZ+KiOHBZgGmDw/6Y7vSs3rI4xhDYkZAbcPNZ 9u2YkM0HAGUEj31kuL5HHju6aAlGM+1ELstqUh4Cuy24bpmxMdiklyYhh0fsoAJgrLZZUc8mx2z SPjqZfzQFsuLdGYKsMILQk8Uw1EFYdH+CKoO2mNlRQiLynT0EYFtWDmujxbbNE+VjbLuFQyycNT rcI7FkwCzI6PONYVqIg== X-Authority-Analysis: v=2.4 cv=F7ZnsKhN c=1 sm=1 tr=0 ts=6a5e59e0 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=Ch_RIXSWQKBjZD2gOggA:9 X-Proofpoint-ORIG-GUID: 24_NxIg5Gw9YIz8WIFEoGMdbCvlens1T X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIwMDE5MSBTYWx0ZWRfX8xSKIDlpX5+g YdETS0mME3TCJcukWuUUlW1KHzCboepEVue6GlOlDiHWsgGPs+XA6dgi5Pa19mk3FrildTmy4/Y Z4MAfcKygbgPckRzUz/ZEB0r3XL2BTI= X-Proofpoint-GUID: zGNLYPVMuMLHqYrgRnbKlYKuKzly0L2_ 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-20_04,2026-07-20_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607200191 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 | 2 ++ drivers/virt/Makefile | 1 + drivers/virt/steal_governor/Kconfig | 18 ++++++++++++++++++ drivers/virt/steal_governor/Makefile | 6 ++++++ 4 files changed, 27 insertions(+) create mode 100644 drivers/virt/steal_governor/Kconfig create mode 100644 drivers/virt/steal_governor/Makefile diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig index 52eb7e4ba71f..4fbc928022a4 100644 --- a/drivers/virt/Kconfig +++ b/drivers/virt/Kconfig @@ -47,6 +47,8 @@ source "drivers/virt/nitro_enclaves/Kconfig" =20 source "drivers/virt/acrn/Kconfig" =20 +source "drivers/virt/steal_governor/Kconfig" + endif =20 source "drivers/virt/coco/Kconfig" diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile index f29901bd7820..512dcfd6c73e 100644 --- a/drivers/virt/Makefile +++ b/drivers/virt/Makefile @@ -10,3 +10,4 @@ obj-y +=3D vboxguest/ obj-$(CONFIG_NITRO_ENCLAVES) +=3D nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) +=3D acrn/ obj-y +=3D coco/ +obj-$(CONFIG_STEAL_GOVERNOR) +=3D steal_governor/ diff --git a/drivers/virt/steal_governor/Kconfig b/drivers/virt/steal_gover= nor/Kconfig new file mode 100644 index 000000000000..926bb351db4f --- /dev/null +++ b/drivers/virt/steal_governor/Kconfig @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only +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 + environment, 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. diff --git a/drivers/virt/steal_governor/Makefile b/drivers/virt/steal_gove= rnor/Makefile new file mode 100644 index 000000000000..eb90ed6b94d7 --- /dev/null +++ b/drivers/virt/steal_governor/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Steal time governor to alter preferred CPU state. +obj-$(CONFIG_STEAL_GOVERNOR) +=3D steal_governor.o + +steal_governor-y :=3D core.o --=20 2.47.3