From nobody Mon Sep 28 06:34:45 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 B643C3DDDCA; Tue, 25 Aug 2026 10:40:15 +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=1787654417; cv=none; b=ePV6oti9fmk58Ymuf0Et/Bhm604TotzaP+VfidImX1dd82kwP5/nYDqVtRN1oMOsl1YHtkV5d/ZQCBbBYjNgPNKIewU9rGWcSd2+NZkYYkozoSVzxJBTbWRN6xi3MDH5zvQ/Wj6YKyEqNS5dcQ+VUX17si1dCZLlAVbLX/nOJ44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654417; c=relaxed/simple; bh=RFgc2L4WKSY/F0QeippM6bdE8F3DxIYfwndMfhN0lqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t1OP+p9llNQA2CzlSCXSDzmZJxvLB2Yslox1oFgFZhWLlVPeEySMZc4NSTBePVz4pLNMGe7mUcZJ3DbR2angwSnaH9JSTSIL/0Xoe7lIjB40Of0dTYYfL3MK/30bJYk/e6uDNdn5uxRAQ7pGf84z7i2afo3DiAGODE4DkTWNrhk= 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=LR6yMnD7; 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="LR6yMnD7" 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 67P8VcpW378024; Tue, 25 Aug 2026 10:39:45 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=KppzS74er64w/GSvH wVqe7UepaXnfYsXgjBBDSgiBMU=; b=LR6yMnD7cxnEY98l7npIbb+txZcPPtApj ufHVCrnbMYNSwwa3nQlgwXd/Q8VrbH9UAyYEGfLNC8xtZpm8KRTMLNp+bUFNOJav sH3TzRtIU1SPm8yaShVjl7onBukXOM9pdlotIKGU01G1gvGdp67VJxgDSuYE0GqU YBU5yDXr7OozHBG2mbe2Bgql3e+tZoPEtcz3lCvpZ9VNLK7BqGf4oxvcgztCfmdV YhK/UYRdAQKv2JWi0Gj3eTmwYqdToVOkDExYWmjIQH6HlruApsrlqBEsjJQ2v82w IAOXt91MxY1IgbdhPXFvgo5TwgvPGQqBdQbCfzlu4eL+7jS7WgpZA== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4g73dx7a78-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:39:44 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 67PAQJTU017467; Tue, 25 Aug 2026 10:39:43 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4g7ragbj4u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:39:43 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAddQ843450756 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:39:39 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BDE4120040; Tue, 25 Aug 2026 10:39:39 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A1E3F20043; Tue, 25 Aug 2026 10:39:30 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:39:30 +0000 (GMT) From: Shrikanth Hegde To: linux-kernel@vger.kernel.org, mingo@kernel.org, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, yury.norov@gmail.com, kprateek.nayak@amd.com, iii@linux.ibm.com, corbet@lwn.net, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 01/12] sched/cputime: Add kcpustat_field_total helper Date: Tue, 25 Aug 2026 16:08:44 +0530 Message-ID: <20260825103855.721013-2-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX8D4qBR712lY0 /+yr1XNlh3hTpQpcpynTmUYojNu/FF0Lt5XnBdyki9+xv+32NjrCrxcNYXVjBQwueJD9vbw/Q0m gsGn7j4bq0uPICIGvZwlpOxF7xMutHQ= X-Authority-Analysis: v=2.4 cv=AYuB2XXG c=1 sm=1 tr=0 ts=6a8d70f1 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=pGLkceISAAAA:8 a=Ikd4Dj_1AAAA:8 a=VnNF1IyMAAAA:8 a=e8TCS894uZmGZegT9CcA:9 X-Proofpoint-ORIG-GUID: DPBUR8WH_6bIwWRsG8HhI32rm0Z-_yNU X-Proofpoint-GUID: B1Om_OUypLAdxNiX4T87RO_2oaTqVbgj X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXyw/2hRs1Cl3x IxafQLSmqwOwDxNsiCUC/5JU+SAesfrRNuPZEl+bul7oYQsHung8T9GJPprQ1BOQEjqHtDX14j2 hv/u7B2MJI06nC56VcTi6F+1npG4a4qROmBu0FMPLxVnibaEaNDgOABkrw+Xpz8hb9EekhO1C32 JkB2m1FjQX99E8jl9WUsHf7RekHrFVO0JEjsaA8D8LxcVCXpzJ9RwTebgh5Sp1E/MAaTg2gL+LD O2wuNqEBSCsjvRwK2JhWCsGlYTvt1/mIqkMoKvXZuckdhroqDW+OtM38pbn7HqArte5ZnTSRKB8 ajjaJBrViSmAVEnTg8h9QqcDUixVwC+RKdh/AKTOhxPTAyrUjm/89c0Mwxzn8zq1z0003jv4Suh I2lnA6FQxGKufEc7t+ESR3rCVAGNZZubGMIYejK/M2r7ARXpvwb0XTR4ab/pGfBy/QVCK6CwT5c xBc+m89f1+GRfqsUsyw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 adultscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 Content-Type: text/plain; charset="utf-8" Provide a new helper function which sums up a given type of cpustat over a specified cpumask. This allows the caller's code to be simpler and avoids duplication. For example, subsequent patch in the steal governor use this exact same pattern when calculating steal time. Suggested-by: Yury Norov Reviewed-by: Yury Norov Reviewed-by: Mete Durlu Signed-off-by: Shrikanth Hegde --- arch/s390/kernel/hiperdispatch.c | 10 +++------- fs/proc/uptime.c | 6 +----- include/linux/kernel_stat.h | 11 +++++++++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/arch/s390/kernel/hiperdispatch.c b/arch/s390/kernel/hiperdispa= tch.c index 217206522266..c21496f0a141 100644 --- a/arch/s390/kernel/hiperdispatch.c +++ b/arch/s390/kernel/hiperdispatch.c @@ -207,16 +207,12 @@ static unsigned long hd_calculate_steal_percentage(vo= id) { unsigned long time_delta, steal_delta, steal, percentage; static ktime_t prev; - int cpus, cpu; + int cpus; ktime_t now; =20 - cpus =3D 0; - steal =3D 0; percentage =3D 0; - for_each_cpu(cpu, &hd_vmvl_cpumask) { - steal +=3D kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL]; - cpus++; - } + steal =3D kcpustat_field_total(CPUTIME_STEAL, &hd_vmvl_cpumask); + cpus =3D cpumask_weight(&hd_vmvl_cpumask); /* * If there is no vertical medium and low CPUs steal time * is 0 as vertical high CPUs shouldn't experience steal time. diff --git a/fs/proc/uptime.c b/fs/proc/uptime.c index 433aa947cd57..53143c66cbe1 100644 --- a/fs/proc/uptime.c +++ b/fs/proc/uptime.c @@ -15,12 +15,8 @@ static int uptime_proc_show(struct seq_file *m, void *v) struct timespec64 idle; u64 idle_nsec; u32 rem; - int i; - - idle_nsec =3D 0; - for_each_possible_cpu(i) - idle_nsec +=3D kcpustat_field(CPUTIME_IDLE, i); =20 + idle_nsec =3D kcpustat_field_total(CPUTIME_IDLE, cpu_possible_mask); ktime_get_boottime_ts64(&uptime); timens_add_boottime(&uptime); =20 diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 9ca6c2259dfe..c1e85550bf12 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -196,6 +196,17 @@ static inline void kcpustat_cpu_fetch(struct kernel_cp= ustat *dst, int cpu) } #endif /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */ =20 +static inline u64 kcpustat_field_total(enum cpu_usage_stat usage, const st= ruct cpumask *cpus) +{ + u64 total =3D 0; + int cpu; + + for_each_cpu(cpu, cpus) + total +=3D kcpustat_field(usage, cpu); + + return total; +} + extern void account_user_time(struct task_struct *, u64); extern void account_guest_time(struct task_struct *, u64); extern void account_system_time(struct task_struct *, int, u64); --=20 2.47.3 From nobody Mon Sep 28 06:34:45 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 71B5B3DD84C; Tue, 25 Aug 2026 10:40:13 +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=1787654415; cv=none; b=CQwCSjan/ytRPz6nqtm9oxDSEr8oZBANeM3SN777Te6DCah02SrtMomuldnVSJ9PpVttUyKcRBDum6VvzuZYZfZSnTIAPHrf+PkimL/cTpDQFfgl4JF/LlTOxRPveWiwvcTJGl1EuUgq5szRYdOVmsVtDNN4i7h8aaup+nqgzuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654415; c=relaxed/simple; bh=5f6u/bpKkYFPlM11kmtFl8Gsefsb4H7gRu7Ky6MhlBk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p9Q6gGrzIAR95ahtKU/WlLyFmdm4MAmqAUsEreQoMk0x4j8obHGVc8f2F4eTYvgs2J9BQEP2XLa5o/0D8syqZgvCNt0YqNGpwmcYQaGddcYkEs0YtveyaM9m1UB3S/uudM9vysChsmEhXA3KLYhkrM8z6rD744C9s5SrxwdFlb0= 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=pilZF5SB; 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="pilZF5SB" 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 67P8VcGv378029; Tue, 25 Aug 2026 10:39:55 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=wy0qUHa14/8d9qC8o WOxhgxGkFyPlhyXtVR7sYKZh9w=; b=pilZF5SBS81ViHlPEv+I4ZHvDHCUyT1yd ho9fJIK8TSpopQv4znW9uVVw8wHmmoApX2tYKVW2HPvG3PGRjWdsn4ytQcKEMp4p gHs4Q+a+2Zu8xkS8jn89YUmyznT4iNhP2N2A9EYKp7QqMzQNG7aWmvoBM80tZ9Od ErInnK/1D3BJSrTE0a8fDWsgDPocYE6hRuhHL+OFp6WKYhWIOobI0c1PMurHy9Md HmDT37T0ukzt8hqGwyygw1gSlFW+vFT01FBm2LhnSbdsW9x0JQvVcWXISsz8h3TR 8MFWb1hAi5ebvNirrZuIPOzferW33Yt9JeHHq6Or5aflx9+tBs36A== 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 4g73dx7a7p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:39:54 +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 67PAQH0H003307; Tue, 25 Aug 2026 10:39:53 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4g7qkh3me1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:39:53 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAdnVF45613474 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:39:49 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 31CD72004B; Tue, 25 Aug 2026 10:39:49 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 465DD20040; Tue, 25 Aug 2026 10:39:40 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:39:39 +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, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 02/12] sched/docs: Document cpu_preferred_mask and Preferred CPU concept Date: Tue, 25 Aug 2026 16:08:45 +0530 Message-ID: <20260825103855.721013-3-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXzYADsK+pp6xG WsDc/lr7knXXwj8Y4TFGZ4D7J1FkijTRtZDPE+JUHv8wO2aELHVox1F2beec4iaY1RPQjd5hDQi /8NIy3rJ6VOZLamIx66KIKQe4EqwL8I= X-Authority-Analysis: v=2.4 cv=AYuB2XXG c=1 sm=1 tr=0 ts=6a8d70fa cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=2BnLtqgf9UOq1ijo76cA:9 X-Proofpoint-ORIG-GUID: bjtvlSC7gvrDvVokii5-b_LY3tIS9qUh X-Proofpoint-GUID: MZrm8c5WWtIlUcplxRQ6MkFzCFuDVrlX X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX6RUWkqndCdz8 eNlocqfCHxGBxgBsyfRx5xSzgiQa7BL1dmFyVz41NtQZ6UU4DR3FKuKT7RDRY4bzYGuycZodXu0 cvzrt/eoKuoMkgbA+bs01q3yzxmmDZtBa9ktIkpSvKp5NNIxAYhgyGnmHBfD1Fa2/UWX396yvYT df2fjjEWj0OYmWBTs9mtkR1tUd5TKPTto47W27nA84B5E82fdT5BB10/2MHEkhpYEVNqAmwx50X e+ZvkB8FoTH2hrta6gVz6iXw4vYMvEWYXEP3zLUKsBsrOtyYNfh3GlLmc3kqzFi84SXnimueJs+ wpwBOT3l6+2PfJ2qkERbzvqoNP58rFnbjqP/FAu01u9Z/kgETncvx2BsQV4DtHVIQRlmmHf4GVC 1p7KnnGo38JsxoctVI4rN6Ib/BseDtIF87iCgNB9eze2tmTT6HjLJjmLwBXEPk+PZTdiBVy7K8G RKHz+l0yauFNHJ9d3eg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 adultscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 Content-Type: text/plain; charset="utf-8" Add documentation for new CPU state called preferred CPU state and corresponding cpumask called cpu_preferred_mask. This could help users in understanding what it is and how to use it. Document the role of scheduler and driver for this feature to work. Details regarding the driver documentation will be added in later patches under Documentation/driver-api/steal-governor.rst. Newly added file could be used for other paravirt usecase documentation. Signed-off-by: Shrikanth Hegde --- Documentation/scheduler/index.rst | 1 + Documentation/scheduler/sched-paravirt.rst | 67 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Documentation/scheduler/sched-paravirt.rst diff --git a/Documentation/scheduler/index.rst b/Documentation/scheduler/in= dex.rst index 17ce8d76befc..a43647b9706d 100644 --- a/Documentation/scheduler/index.rst +++ b/Documentation/scheduler/index.rst @@ -23,5 +23,6 @@ Scheduler sched-stats sched-ext sched-debug + sched-paravirt =20 text_files diff --git a/Documentation/scheduler/sched-paravirt.rst b/Documentation/sch= eduler/sched-paravirt.rst new file mode 100644 index 000000000000..311cdbf2722b --- /dev/null +++ b/Documentation/scheduler/sched-paravirt.rst @@ -0,0 +1,67 @@ +.. SPDX-License-Identifier: GPL-2.0 +.. _sched-paravirt: + +Preferred CPUs +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +In paravirtualized environments CPU overcommit is a common scenario. +i.e. the sum of virtual CPUs (vCPUs) of all VMs is greater than number of +physical CPUs (pCPUs). Under such conditions 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. 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, since +hypervisor lacks vCPU context and could preempt a critical section which +slows forward progress. + +In such cases it is better that combined vCPU demand from all VMs is reduc= ed +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 +"Preferred CPUs". + +One of the main design constructs is that preferred CPUs are always +a subset of active CPUs. In most cases preferred CPUs will be same as +active CPUs. When there is pCPU contention, Preferred CPUs will reduce +based on the steal time. When the pCPU contention goes away as indicated +by steal time, Preferred CPUs could become same as active CPUs again. +The policy decisions are to be taken by driver. +For example, steal_governor. Look at its documentation for more +details. (``drivers/virt/steal_governor.c``) + +Scheduling decisions such as wakeup, pushing the task etc, need this +CPU state info. This is maintained in ``cpu_preferred_mask``. +vCPUs which are not in ``cpu_preferred_mask`` should be treated as vCPUs w= hich +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. Pushing the task away from non-preferred CPU at tick. +3. Selecting only preferred CPUs for load balance. + +``/sys/devices/system/cpu/preferred`` prints the current ``cpu_preferred_m= ask`` +in cpulist format. + +Notes: + +1. This feature is available under ``CONFIG_PREFERRED_CPU``. Driver which + makes decisions should enable it. For example, steal_governor driver + (``CONFIG_STEAL_GOVERNOR``). On enabling the driver, CPU preferred state + can change based on steal time. Without the driver, preferred CPUs is + same as active CPUs. + +2. This feature works for the FAIR class only. + +3. A pinned task, which can't be moved to preferred CPUs will continue + to run based on its affinity. But no load balancing happens if it is af= fined + only on non-preferred CPUs. + +4. Decision to change the preferred CPU state is driven by the 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 Guest 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 Guest VMs. --=20 2.47.3 From nobody Mon Sep 28 06:34:45 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 38AB33DDDCA; Tue, 25 Aug 2026 10:40:25 +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=1787654426; cv=none; b=oRROhsNsOQdJdpEtEr2rNqfqqTs6e30ZDqJOtSqHpj2/f3VphrV5hVUj3dShEYieqBvKnld74seFAE2+9p9dtW6bSvOg3JCESIsm1phIQSdgl+9Nv1og2hpd2Mi5bMilL9tBtXp21kZFjss9nzXznZkg5ZazfqI4+/mlwYd4cnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654426; c=relaxed/simple; bh=NHxNTsuQ5kYaOU6wiQ3qsu9Kigs6uHpexu2ofPPXkNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QL1a70s5W9wrqObblOYqZyQGuEMlvedpMNxK4qKnsXOyLHLIPPnCWnj60VlVl/dG1ivScq44s3GLDQJPNzzv4gqXeO4fViq6YgJP4xQ6J6m24Hm6SsOmYbG6elGOl9IFaJ9qaup2+4kmozNy1r3uLnDiufYs5DNFj2DKp8IX/WE= 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=P2B151Wl; 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="P2B151Wl" 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 67P8VbkR306807; Tue, 25 Aug 2026 10:40:04 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=CjMua/ sfQJspq5hiL4ZeydI1nOj4VlT3LwXZv+NrykY=; b=P2B151Wls6wQqFCd3Eqo+O GFddKuO5aV3LQ2xJuHwOPF/e3KJIZHfQUXvbV7mScHyaslE/mWujicalqhU6wkWr 3t55wSb/RuawY+ja63sy95BBJpF2C05kH4idhWP0RgyUfTRPS9i3Ul6K0ANrR3m8 E14Bab67ntlfBdQ1i0sVAjeSIBvwhQA8OYF4ZWrGz9bVRKvN50GGIwYuW+yQzFL/ Zn8+plpEZSk/v4/ykk+bDGDrOcOa8iUN1+vk3sJA/zE4Yu4NLKyBSfoXPdndnMYb viEtYS6ySrOV32f4vOasCBbHe17qKoWGNYiBeIjuzaKFR6TL7sSY3yYvRK4Iz8Ww == Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4g7393yke7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:03 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 67PAQGoH017434; Tue, 25 Aug 2026 10:40:02 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4g7ragbj5p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:02 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAdwRa43516242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:39:58 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4748F2004B; Tue, 25 Aug 2026 10:39:58 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AD9B820040; Tue, 25 Aug 2026 10:39:49 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:39:49 +0000 (GMT) From: Shrikanth Hegde To: linux-kernel@vger.kernel.org, mingo@kernel.org, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, yury.norov@gmail.com, kprateek.nayak@amd.com, iii@linux.ibm.com, corbet@lwn.net, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 03/12] cpumask: Introduce cpu_preferred_mask Date: Tue, 25 Aug 2026 16:08:46 +0530 Message-ID: <20260825103855.721013-4-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-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-GUID: bQVFrmsIExn9C-BkGl-mIYoPxiJJOyrs X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX3YaNCK76H/H0 tN9Vcwj3Z5VItwi41ACTSKjOzg+1y56pQPSl2DcMDAqyDaZUbjgCnRUvFA2CRPol8ilBddHI65E KcBO8g7D1M7y2uNjPpuYsRXe4TWDYfoK6dRLgGhyu/kF43hhPXLMrdEynUiRngJSdqb9nyxi464 txwLU0vLlTSLn9yQGKn3UduXx8s33XXNwRVsrbKBkXL8riPNYcgZQ3iuS4JM3Rm/3yRGRvr9iVl KnDDdG59IPGyd3lHLXCBhmGweSEYeANcr6TTFJluUGT8YTtVPYSvpG+ThQLZS4v2cC310qM7qzl SHwY4QptR/75ikki0GQpyVZhvMV0kmSlKFB7sc2pjZeeJE0A8CBl8rqJdj/3kWkt87XY2/ztlrT 6DWU0KO/0Doo1aNlxc/ZROmxY/TSePyxRN92zVat8gl/gWCL3Pa2lHxr33Uhyl5alNbFz/HCccv aL5TrrzH2jRSXX+NnHA== X-Authority-Analysis: v=2.4 cv=Y/nIdBeN c=1 sm=1 tr=0 ts=6a8d7103 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=NEAV23lmAAAA:8 a=VnNF1IyMAAAA:8 a=9QGdkmv71c8RgJbqbJ4A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXyhFjGcv196y7 N52izu9YyVRI6WYQZoRCf2tPUzz/lgJ+5T/cnU07m02zscqdr+MiY8NuDYJZCqi6pYAtT00Bva+ X4AU3dFVSdnN+ekHl/LcsXs2oWJ6L0w= X-Proofpoint-ORIG-GUID: JG1hC0-Uy66EhwaO17EHheQpAJ_MEjPG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 Provide the preferred CPU infrastructure. Define get/set macros which could be used to get/set CPU state as preferred. CONFIG_PREFERRED_CPU 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 computes the steal ratio 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 ratio by the steal_governor. 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 CONFIG_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 Mon Sep 28 06:34:45 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 913A73DB634; Tue, 25 Aug 2026 10:40:32 +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=1787654434; cv=none; b=gIuI1yQLVyoACYg/2K4m/aDQNCx7M6raWyFUP9MDHCMSZecvBRhywsO7wrJNxtfxODnpGzhR2x2lUIsNIqCnatQyqCP/bRzbmdMbZKu7trVVc9MCUgc4v0vlMEOkqufW+fdPCsuV4j8zQkm56yfE6I8YGj4D4I85ygNAMjwKFiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654434; c=relaxed/simple; bh=TDsgIO48g+8UYi8pPB4M66fYIvYKuUVdrZMjt9LJrYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tzg2uNMSvrlp8Ft+K5T8/W1cATBNuwXPrhZECk1S2XNCE0TtMhZfJj2Q5PL698GIisB0iyBU7F3u75Go/+rFqf1bvKAfZOpWuXoxWR3a/bIQF1isVQGZjosmAlXiHP5cRw45icZoO0gWDV5SuPsNhcv8TIyAU3diMxrpCC88Pwc= 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=kJzKPAPK; 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="kJzKPAPK" 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 67P8VhHj378168; Tue, 25 Aug 2026 10:40:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=IdIQVMSRh1tQgR1Q2 N7Opt2bZYabyV8zrFakwyWbq7c=; b=kJzKPAPK+0/gcZZcCfPWo1CZfmiZPewX0 DoMvNY8n92KAWzYHteUixy4mcT4tRNJ1eiEQmrDsgAkbOxRzPo94c7ZZQSSffyU6 M/Rf6V2kQYy8640bhSYsKA3FDmIv66sZnawvxdiFlkTSsAHsYq2sHYbzQ70vhJxH qkooOcoSvGcnHsW5nI9eN7pvk2SereRgTXPTYbst9IDVcL8bOzkTgYw0bv1ah5cG dseT6Bx1Qj3F7Ofbg5CCpMbJyLq39SV36U+jr9EabwoRaiiMkFNMJZqRILsu0bN+ 2Znu+VyBQhEaXDKbnako0UrInLzXbAAQg/yaTwZVpkvyyAyauj91Q== 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 4g73dx7aa5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:12 +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 67PAQSwI005304; Tue, 25 Aug 2026 10:40:11 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4g7p3q3xbv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:11 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAe8L529557494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:40:08 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E669D2004D; Tue, 25 Aug 2026 10:40:07 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C97F520043; Tue, 25 Aug 2026 10:39:58 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:39:58 +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, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 04/12] sysfs: Add preferred CPU file Date: Tue, 25 Aug 2026 16:08:47 +0530 Message-ID: <20260825103855.721013-5-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX5cvotuUGpPDY bW5JSdonH54o3AsAqyECUDBUaPSkl7Fp8tQ07rGM4DX9eIX4uWPtXMXLVGO6q36s4xuwKRqwbPQ dVML3+XcCj+xUqgNUhjPq1QQkRSZK+M= X-Authority-Analysis: v=2.4 cv=AYuB2XXG c=1 sm=1 tr=0 ts=6a8d710d cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=VwQbUJbxAAAA:8 a=94fVmjRkuoLjN79_KVgA:9 X-Proofpoint-ORIG-GUID: nKLWTKMyAO9f1eo0MzZ6vfuY9c7p0f_l X-Proofpoint-GUID: VYSb_-2GSExxITTP6TGFadWd3vhICmiT X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXwN+/DWK8Lvmj za/RYqL0PdoVSlbfND3FSPceAWY/vCaGd1fMB/QrfRjbH4zbUSiKQuatVw1rFXtPEKSSxgMPXbt WZv5HSETWMFakQGWUQ0GEVeAHz6U9tk9jdBnF4pDROAzcJRiKiC5zH0fI/GfOtI0XB7Egtmkqwk NkLM9Mac17BN82urmV6DgNMvFpMlRHTib8UJGTiN1oB6tbC7iLT3sIOVuPFdYm4kT4OYOurPgWk SJ2NTGRJsLFHLClmfW79MmTA256w5Ufe+F3kZQGDlDHtT92PdVlqmHIf+zhdi4czvZiKH3RFqlp epm0YgK0ck+FHXdxv4mfbvkZrN2mIybtjppq/D35npICsTrgHrsdXaMLCKvF8uAEL2WcYsK2KfZ fh2Jme5ICzy8XIbw8vUCjQdBQ+XOEcBFsbV9oqcj0H36xa/Mw+EIOuBQZqgBd0x8Z6GyT5fkKXj 1CXZMnSDhwPjOrGkn5g== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 adultscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 Content-Type: text/plain; charset="utf-8" Add a "preferred" file in /sys/devices/system/cpu/ when kernel is built with CONFIG_PREFERRED_CPU=3Dy. This would help - Users to quickly check which CPUs are marked as preferred. - Userspace daemons such as irqbalance to use this mask to route irqs 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..080c69aca4f0 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: Aug 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-paravirt.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 Mon Sep 28 06:34:45 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 E6CC833A70A; Tue, 25 Aug 2026 10:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654445; cv=none; b=dJ9faAyMLvLT//6CMqGYRUczIZwl+Fczv/EsCzMKE3oJjPZOI1VW2pndplS4Obw2Ej6zMt56rAputgQLrrTDhYfYjM3rUSOtSUocRKTb5vx2t+3swEJkaBazmZogQJkZdfoHnjimmmlucLxpn2jviIzQfQ8+XDmGNhP2eSbUQGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654445; c=relaxed/simple; bh=BiNd8Mdg9P00eC4yhP+EJoIA/x5mEIkySM2Su1+MU/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q2lgfYp4WxWHKmkdPXVOIYC6wPq6WYxXdUGWKPlO+RKAkPZoDdZm0dtfuAloGpgvSnEyK5jpac4vITtU4XK3q4CdWeK+1609AZif+TWHBcUzzUjrw2n2WTFokT+hv3Y6zXL6BM9YfI/Ogk9fNXgTvzVq6azA77ehCIR8beLKQe8= 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=XPtpx6qW; 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="XPtpx6qW" 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 67P8VhY3212102; Tue, 25 Aug 2026 10:40: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=huPGzYzb0L8qddyfH sU+EtPMbusT9LKb8JvY8Wc6gws=; b=XPtpx6qW8q7uxLXF0WindBJYuE0tS9tk+ yjdWgWpYU82e6+M+7l1IRhUsFCc7WpPKdDDfy0WwVaJqHcqPn/Hd4NdgawJc7bs9 Zf9Se0ZAIoFKFgJCrfFs6/ZUn5sBpn0je/QPqPpjWHVOE/Oev9Il19Gqti0kDX+A mHuj+w1liviIEZ3RidZ67h4H+bai57tX+rDGF1khnKUCT9r/aDg13W47VDKoepBb MNak4p8NpNNWzjjuzOEcZ3RkVs29kHqpUv0kjGtFll7Nlf25Zm7Gxg6MRrNPWAbG EAJgcMBK5KkeGnQNr1wICwjbe3HGeBUtDnWBjicFg1TI1Fwfg7L7Q== 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 4g716hqpxx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40: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 67PAQJ71005904; Tue, 25 Aug 2026 10:40:21 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4g7q3juqnx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:21 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAeHRf45679094 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:40:17 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5897B20040; Tue, 25 Aug 2026 10:40:17 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6D63320043; Tue, 25 Aug 2026 10:40:08 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:40:08 +0000 (GMT) From: Shrikanth Hegde To: linux-kernel@vger.kernel.org, mingo@kernel.org, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, yury.norov@gmail.com, kprateek.nayak@amd.com, iii@linux.ibm.com, corbet@lwn.net, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 05/12] sched/core: Try to use a preferred CPU in is_cpu_allowed Date: Tue, 25 Aug 2026 16:08:48 +0530 Message-ID: <20260825103855.721013-6-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX0KK8QhvJyzhz u2ir2zRg5BGl8a9Lzh+L2EWViTlbIedGFboIwsJkEgHtQ+zB4+yioi/NfvVMO/a/QDSWoC39Izd ZgkoWX8seqPnCOHc778T0N3r8JK2bQw= X-Proofpoint-GUID: aLbpluOMUVAkKgYO7y018QqmbIDCULqp X-Proofpoint-ORIG-GUID: ltJNFGTdYoPJA6MjDKfu0BEJe9vqsSXR X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX9d1wBQ8XDwHM dM7fep7+Ood3211dKJjrvGDAkLnk1uEx84Wkrg2GzgjD29zHjo4NWyIFrMMkB0tTLDmlD2IlbTh yFNuaXMQy+Cv6AZG/mkLokLYrk5hn/C1qaerzFA7i5lPx4Oa1XycrQwrVutELL6yR/Gp5Sjur1j 7O7fn6P+v10eMOcpOaLgBOq883cDvTn9uFCHugNhUXxlDDC2ywO27CD00bKZhoMs2W1dyS8JqQx KsyPxiuFhMjWchwCJkoXltb4Ov5Sp6I2YPAf8XqPk5p6IpaQfrdpWE0wlPQmJ7AxvtPbF1klO5I kTytqKtgnHWFTeve3szTow3nVz2lMQrW+QC7A1W2ZqDZXpwdU3JHrN1qz1aySP6PlL/C61urtUW Vw2SgQEE346JUArhLgbaYx9Pn1ejS+9VIo4drAT613kHl7101Zxh9Po35NgUb/wgQzqk3o41CVT vrBxwhu5R3bbxUYapEw== X-Authority-Analysis: v=2.4 cv=H7brBeYi c=1 sm=1 tr=0 ts=6a8d7116 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=h9snqJY24oqFoxCgr8cA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 spamscore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1015 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 Content-Type: text/plain; charset="utf-8" When possible, try to choose a preferred CPU. This is essential to maintain user affinities when preferred CPUs change. A task pinned on a non-preferred CPU should continue to run there, since this is a non-user triggered event. If a CPU is non-preferred and the task can run on other CPUs which are currently preferred, then choose a preferred CPU instead. This is decided by checking if cpus_ptr and cpu_preferred_mask intersect or not. If yes, then the task has other preferred CPUs. The push task mechanism uses a stopper thread which calls select_fallback_rq() and uses this mechanism to pick a preferred CPU. This takes care of the wakeup path for FAIR tasks too. is_cpu_allowed() is called to ensure wakeups happen on preferred CPUs. With that, additional checks in available_idle_cpu() are not necessary. Ignore the preferred CPU state if a task's affinity is changing and its new mask no longer includes the CPU it is currently running on. This ensures migration_cpu_stop() does not abort, preventing the task from being stranded outside its allowed affinity. Account for tasks with architecture-specific CPU masks (e.g., 32-bit tasks on arm64). For such tasks, explicitly check against the arch-allowed CPUs to determine if any of the preferred CPUs are actually valid. For the majority of cases, this would still keep select_fallback_rq() as O(N). cpumask_intersects(), which is O(N), is called only if !cpu_preferred. The task running there is expected to move out. Subsequently, it should run on a preferred CPU. This becomes O(N**2) only for tasks pinned solely to non-preferred CPUs. That is a rare case. Overhead is minimal when the CPU is preferred. Signed-off-by: Shrikanth Hegde --- kernel/sched/core.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a45f7c308329..f71317fe281d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2494,6 +2494,35 @@ static inline bool rq_has_pinned_tasks(struct rq *rq) return rq->nr_pinned; } =20 +static inline bool task_can_sched_on_preferred(int cpu, struct task_struct= *p) +{ + const struct cpumask *valid_mask; + int i; + + if (cpu_preferred(cpu)) + return false; + + /* Only FAIR tasks honor preferred CPU state */ + if (unlikely(p->sched_class !=3D &fair_sched_class)) + return false; + + /* Ignore preferred state if task affinity is changing */ + if (unlikely(!cpumask_test_cpu(task_cpu(p), p->cpus_ptr))) + return false; + + valid_mask =3D task_cpu_possible_mask(p); + if (likely(valid_mask =3D=3D cpu_possible_mask)) + return cpumask_intersects(p->cpus_ptr, cpu_preferred_mask); + + /* Tasks with arch-specific CPU masks. e.g. 32-bit tasks on arm64. */ + for_each_cpu_and(i, p->cpus_ptr, cpu_preferred_mask) { + if (cpumask_test_cpu(i, valid_mask)) + return true; + } + + return false; +} + /* * Per-CPU kthreads are allowed to run on !active && online CPUs, see * __set_cpus_allowed_ptr() and select_fallback_rq(). @@ -2509,8 +2538,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 +2553,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 --=20 2.47.3 From nobody Mon Sep 28 06:34:45 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 2C8293DB634; Tue, 25 Aug 2026 10:40:52 +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=1787654454; cv=none; b=gpYtGJF024wHjJ+6h95n5nXY+p1L6rGyGFOv3XS6lef5rDEKte1sJ0bP9D6NeGVX3rrvIqf/4LiGikpImYLsRPhAJWFAfG5JZWbCcmMxfV4OTRfDb7hW7px/wiIpvBe2M0z16zbz9jX+K9OV6Nn26/n5zu5GaOFeHkX9xCLNJTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654454; c=relaxed/simple; bh=GPvVWYQDtRId4vsQqpgozI3SjqctT0MmSWzvFsN54Ns=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KBXD3i54EcYGFZK8ZEtlSTODZazUJmbfRX0U2hNlHqOzVAgcvlefnQDzUBeZ9kf9e5pIZZcXVNxwbBE2Ggg5xT4oLFVZWsqKbwiLSJgxrfd5PPFy99hz3hpF/oMW5HCh9DS4oyE9q88SXadIbh1TNpMFaot4iNE1C3wDrwfh6WU= 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=J9Cl+cR+; 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="J9Cl+cR+" 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 67P8Vias378181; Tue, 25 Aug 2026 10:40:33 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=pImetWbt1Ao/qbumC NTFwjRwcdp8/exLahCyfnPF9Dw=; b=J9Cl+cR+1UIM2EhDB3PaeAgGEmR//XIyV 2cmFAP5XpU5EFKYRQeGudCgq7BJ8HGZnRRPCSyIMRJmkgXtjmDXN0hAQtwOxqwHA ndwmnjjGh7tS7ZKp92WQ67amo38vVgEL1MUImC/ueuNRnOmqLl5cELcpKVumknvl babr+I4iyiKxMn8aHDfLMiRdCpJ013fYB8zUb6ZlwDtYO3afN2XYzo0Z2ukK6daR gAyEr7u99zNy6xiTDquOXlgJaj37gJhZyg0obyMufnzlBUvDafu56kE0IigMwbdE tDHH0/5/9i+extIDInkDveO9xTF90++z4aD1FkeDkqUojgQLmeY6w== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4g73dx7abt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:32 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 67PAQGuX018765; Tue, 25 Aug 2026 10:40:31 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4g7rsy3fdp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:31 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAeRZ253608842 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:40:27 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ADA182004D; Tue, 25 Aug 2026 10:40:27 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BFE4220043; Tue, 25 Aug 2026 10:40:17 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:40: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, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 06/12] sched/fair: Load balance only among preferred CPUs Date: Tue, 25 Aug 2026 16:08:49 +0530 Message-ID: <20260825103855.721013-7-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXyDWhKPOSeYoC q1qyqzBMf2CII7U3SohIW71GlpWGY+0GjGs0qSF4k99ETCgoZ3hk9pxWrTCsqEYTG1dQTw8asT+ /ehkKmowyYdb4ruZAiHW+TkQhMbvcyQ= X-Authority-Analysis: v=2.4 cv=AYuB2XXG c=1 sm=1 tr=0 ts=6a8d7121 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=f1WSfB00kwmd_FHdG74A:9 X-Proofpoint-ORIG-GUID: lpWK3faDoVDiubBebcV1cpjBgggmP6L0 X-Proofpoint-GUID: 45Q0TBo6lpBCsmiiCDUluVAEiRK182Uj X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXzccKQ2W4NW2g 5tn3JSTxfaab53zrm+sMxwliaGjqsgNC+kSactVzQYHw4hhXUc/t35SqK6FRCut8GHqslHrXUtn 9zMJD/nXYdccfL4Jq8/M1x+cb01V04UzNRnKV/M8DzHAMULRRgIlEtsGc1gcE3SoKQo5C0HRYML fspaSZ0NM+R4IkX/BxxzhwgtPl7DDV+jaU0TMOIfldN7ZUgRv9uTmSkL8CUjPvA0zeyjo8xzY4u b7laNqu+biXJ06s8NUb+PqLIznRJtMqkJMw1to3xaLfhuxpuzSEEH1GOcjxgLyMydmBQN06YlhS /JVt/aOzIAv4ADQwRAAOuwnTEjASOZgnrNMwVkXSPI88cmQe26eC/UugidmGbJkVKbWysbXziA2 vOiuuw27wabt2brk0MpLowoanc6XtX24PK23PmZOyoqVLJCMa/MFqOygySNKKuD5c1MZJRHoCvU NRFMWsi6SUnNmI1axKA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 adultscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 Content-Type: text/plain; charset="utf-8" When a CPU is marked as non-preferred, any load pulled towards it is pointless since the task will be pushed out again in the next tick. So, consider only preferred CPUs for load balancing. This ensures load balancing does not fight against the push task mechanism which happens at the tick. Also, this stops active balancing from happening on a non-preferred CPU pulling the load. This also means there is no load balancing if a task is pinned only to non-preferred CPUs. They will continue to run where they were previously running before the CPUs were marked as non-preferred. Bail out early for NEWIDLE balancing, as load balancing is done only on preferred CPUs. Note that idle balancing is allowed to go through, since that naturally updates nohz.next_balance when all the idle CPUs are non-preferred. Also, optimization in find_new_ilb() is skipped. The steal governor driver, which is introduced in later patches, updates the preferred CPUs state in descending order. find_new_ilb() checks for idle CPUs in ascending order. Hence, in most common scenarios, the idle CPU found by find_new_ilb() will already be a preferred CPU. When all idle CPUs are non-preferred, the first idle CPU has to be chosen anyway. All of this is naturally handled in find_new_ilb() currently. Adding additional complexity to it for rare edge cases is not necessary. Signed-off-by: Shrikanth Hegde --- kernel/sched/fair.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index f79fcba4afec..d2000ad430a0 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -13440,7 +13440,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 @@ -14555,10 +14555,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 Mon Sep 28 06:34:45 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 D70213F4DE2; Tue, 25 Aug 2026 10:41:26 +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=1787654488; cv=none; b=j+WWNinj6d3R/CxxsHZpz51K8aLn9j/DvtQ1XBS+ZSKraKp49Xe4kRDM2IU2ffEJZn2hER9rlZBympu0d80zv56CUXEuCxmqsRr66v9dkjUCUA832qTCiqEuv56Lh6LcktkgA1V2Xi4rtNyOxGCV7vLjhxA0x8xd1oJtg6XYBpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654488; c=relaxed/simple; bh=6KwuUZtuTcOUm7TntwXKfO9i782T82hHxTENBGHfBSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aj3v1aKK7gwnYeBmceLwuCpVcrh932fT9U/nz7kWkAFTb9P7JZtCqk58pDAKGyKavFjj8+qrcHlDpwpjvlnGYvioplQTC4uGikcnBPl93e13DMIOKvsWUsWnM1zbZkNlMmUgager0vP3whzUxLN9ZyN31k9bb0U00EL+oAnebI4= 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=ZF9OV925; 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="ZF9OV925" 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 67P8Vdas3390460; Tue, 25 Aug 2026 10:40:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=a8os8F5RheDxzlYAt UWfftOSSw0lp1C9oXZZzHYTR7I=; b=ZF9OV925McB61QzzKDgZkGmGCgTAz17sR wL46X47QAtqHxDRETGMEk7y5XDSbZ+r/gaW1qAuGcGnLcQTfJ2juD0j16EZ+Aj91 ldHDzWEsVz6hP5tl2FXeKyhoNe7KDq8q3h5YkMFNwXSBMSwOEmPGhmjkg5LpXW1t 6Y6+6AEAviwzIki9sWbD7gNtw8spgADRtAvr+VfG+tAOi+FVnJYyssI63dnENbux gle5ShYsyaE0A2YNI2/DYkUh127bgM7JulTOfFVaJdYpAWKfwqu89xbbf1IeDqFY f+MwRrUIElf0qL493e2KkMgRSdHo3utV/DWFJLA8a/trBpQuiHbvw== 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 4g726efh4j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:41 +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 67PAQGOC009613; Tue, 25 Aug 2026 10:40:41 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4g7pfw3ufm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:40 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAeacq12517698 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:40:37 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C960B2004F; Tue, 25 Aug 2026 10:40:36 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 36BE32004B; Tue, 25 Aug 2026 10:40:28 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:40:27 +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, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 07/12] sched/core: Push current task from non preferred CPU Date: Tue, 25 Aug 2026 16:08:50 +0530 Message-ID: <20260825103855.721013-8-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-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=TfimcxQh c=1 sm=1 tr=0 ts=6a8d712a cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=rPhwLmmYJdnLsqmuV48A:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXzOasTb0rkO8U rV/V5cLZsOQvCjvUFnfFlNaJGXrWBdu2eb0X7s2ha0LmRb6C5NNLoMZ3jcM1d0hyxSlOlIq7HX2 x/rZE+P84MqFbycG7e4Jv0ameUAW1bM= X-Proofpoint-GUID: yQnyL9wCjaJv2slSirhQbZqNchA0MaUL X-Proofpoint-ORIG-GUID: Bkz8bEWwchGHbhipsrL_ZkMo4z3Ic4Ij X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXy8sMxCX9MWzF tKiAqa96E0PfMN3wxuzQNRXj5ufutsolppj8LsbTTj0ECmmsEQ7vP1IloeDjHp+KSYvCMfqZSK4 dk8j/qbis8cQG+f2K/aKBSFjpH0koa83XPMNYqeDNZuw0TGSOHL71jXMOCeGBbuexRn7Co7ksC0 gYVtihHhaNWCpM6zjnU9wb0bq8cy4VcULe2wgadT7oVdw7cYmAojyqlmbFYyMzYH8Xg3/pPI4lS hRLjEq1bGVhtxHdl1ylpxYmD0xmIdNteEAjxUCpsB29LMp8AKlMm033q4KSrdjvKMsiD1W2uTyU OR5PXzDv+ogf39Mw647o5teuGc9kceeEgG/5jdKkrUI1MO7mnpasN929n2+o/6MBzONz7EhIoes rjx9dAgXE5bcgzDsCaP3l9FQ2K4AkqzvkQ8A9/JQz7S/xvE33Pu/uuRIZbJym5KLIny9/vGB7zW T0DR0IEEAFx1hGc/6fA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 phishscore=0 impostorscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 Content-Type: text/plain; charset="utf-8" Actively push out the current running task on a non-preferred CPU. Since the task is currently running, a stopper thread must be queued to push the task out. However, if the task is pinned only to non-preferred CPUs, it will continue running there. This helps to maintain userspace affinities, unlike CPU hotplug or isolated cpusets. Though the code is similar to __balance_push_cpu_stop and quite close to push_cpu_stop, it is kept separate as it provides a cleaner implementation specifically for CONFIG_PREFERRED_CPU. Add the push_task_work_done flag to protect the work buffer. For now, only the currently running task is pushed out. This keeps the code simpler. In the future, an optimization may be added to move all queued tasks on the runqueue. This works only for the FAIR scheduling class. Signed-off-by: Shrikanth Hegde --- kernel/sched/core.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 8 +++++ 2 files changed, 89 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f71317fe281d..2521ed5ce576 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5803,6 +5803,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 @@ -11321,3 +11324,81 @@ 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_irqsave, rq) + rq->push_task_work_done =3D false; + put_task_struct(p); + return 0; + } + + raw_spin_lock_irq(&p->pi_lock); + + /* This could take rq lock. So call it before rq lock is taken */ + cpu =3D select_fallback_rq(rq->cpu, p); + rq_lock(rq, &rf); + rq->push_task_work_done =3D false; + update_rq_clock(rq); + + context_unsafe_alias(rq); + + if (task_rq(p) =3D=3D rq && task_on_rq_queued(p) && + !is_migration_disabled(p)) + rq =3D __migrate_task(rq, &rf, p, cpu); + + rq_unlock(rq, &rf); + raw_spin_unlock_irq(&p->pi_lock); + put_task_struct(p); + + return 0; +} + +/* + * Push the current task running on non-preferred CPU(npc). + * Using this non preferred CPU will lead to more contention + * in the host. So it is better not to use this CPU. + * + * Since task is running, call a stopper to push the task out. This is + * similar to how task moves during hotplug. In select_fallback_rq a + * preferred CPU will be chosen and henceforth task shouldn't come back to + * this CPU again. + * + * Works for FAIR class only. + * + * If task is affined only on non-preferred CPUs, no point in moving it ou= t. + */ +void sched_push_current_non_preferred_cpu(struct rq *rq) +{ + struct task_struct *push_task =3D rq->curr; + + scoped_guard(rq_lock, rq) { + /* Push the task if its explicit affinity allows */ + if (!task_can_sched_on_preferred(rq->cpu, push_task)) + return; + + /* There is already a stopper thread. Don't race with it. */ + if (rq->push_task_work_done) + return; + + if (is_migration_disabled(push_task)) + 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 26ae13c86b69..6cee31466087 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 @@ -4230,4 +4232,10 @@ DEFINE_CLASS_IS_UNCONDITIONAL(sched_change) =20 #include "ext/ext.h" =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 Mon Sep 28 06:34:45 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 2A02C3DD846; Tue, 25 Aug 2026 10:41: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=1787654474; cv=none; b=KQiWxzoL7A/64rmUI6AI/82MVpM5V1OyNB/UcYtXckRhI73EXFlw9oOARGL4r1TIL1cXK0pL9ZPHV9ElQDvPDpCrp1Eb0HVec/iG1e9LSO04a/NMNYZetbdlMLQXOCySoG0zeySgsGIKhv7K1z0SG2thiThVuaZ0cOFM9svDrqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654474; c=relaxed/simple; bh=2xR+GfiiOyB6SfZW1OIBhLdJhb+vSWJx+KgzVSGdgKg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z1TgYKvIaKSv89zI+wlxUEzCwNmqrzEP7TCfydTeGiAC9jXLjzRirZi9P2aaqpl7EWF48+pR5y7ZMBnmfFsbC8oMPbPCNE672O9dRhMepHItZYIH9M/CaAbT5RT9N/a3Wd/uhivnQXq5dn/2ehsnADU28Fof+aTVTb+j6v9F6Kw= 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=tFx3XDfW; 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="tFx3XDfW" 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 67P8VobG3390794; Tue, 25 Aug 2026 10:40:52 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=Qww1wRP7Agkql+FnH hwzR+d5eVxTN2AMCyH9arsexeY=; b=tFx3XDfWVUtgfBilB4BUvIqPsXFS7orJI rE/GIti4W5AQ6V+Brkt/elH9mzDCBvJfgtrylNGcEWNtqiZJVdymCsGMxaNpwcUk uKzXv3hcN8x4WHQhd6GXQnWZQiyp+q34UjFI2IgDVS+F2xwaHD8XAZm4jpNom4hF 05zy/xNixLvl4WMszyCj68n7+brOKCyXlyXetkwcbTfi1wSRtKXeeLHh2K7mpUjj maxaIkdzUtM+tp8eR2u+m9f7xE7QU9rLmXiqoeGHGjqhZ+TWvfQfkMFxVMeWgKXA u9ukkSg0e5cfCu/+s+csF2i9xkT2H3gjY402kwlDIkNlkwq7YBPCQ== 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 4g726efh56-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:51 +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 67PAQHOn005244; Tue, 25 Aug 2026 10:40:50 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4g7p3q3xer-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:40:50 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAekY252101570 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:40:46 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 866F82004F; Tue, 25 Aug 2026 10:40:46 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3AD452004B; Tue, 25 Aug 2026 10:40:37 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:40:37 +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, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 08/12] sched/debug: Add migration stats due to non preferred CPUs Date: Tue, 25 Aug 2026 16:08:51 +0530 Message-ID: <20260825103855.721013-9-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-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=TfimcxQh c=1 sm=1 tr=0 ts=6a8d7133 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=-i9lZGrASMRMKgkbeRgA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXzWtzZte3SU6w Kexcw9wuR7eTbaEuNuzMjpbsaq9QLIgMeUearlD6uMUmilDZyi2OF7sCRlEz2XbCEouuuBrkqjB 2TtZEnpJmA251buBik0eAJI/cQ/jTjM= X-Proofpoint-GUID: vp3WLSpTWu8piiDa4fCbp5S59kfnMNKe X-Proofpoint-ORIG-GUID: DWqDtcZY1EYHHP7L3PvT0Di5dI_bQiVA X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX2Ryqr09CO4ox lMbpsE2TY36GhJ7o7K4x6PoiQ6dRzS+Xxl2ZHiKMxLYkuTSxq7d/zUTZuZWk0Lt8AD4QpQKXQQ+ ZkcoZpV8hmUcOX4gPnKOhkb6BcxtH6sZT/l/YSVEAdC8BP5ACWsl7ZdTAbJpLEQ0nzPafoGcv+8 3i8fr54l0LWRYe5y9cu98yh8P+Q90KuDo9ENRTnwAjp63qkLiD2NrUVus5BwFxEnjTgzFd4Nw0X mFitIzAormBzcp/ec9kuv3CdUXCPvASSL+2QwCgoB9595P9HRB7pBsmhyZXueC4TvyufEl6Zn+l lH38lLJmrc24x1HaPVf+wwXLJYUj2+qIrYSYnEwuN81h1RGZTlXxcCjgXyE/Bq5fFai8taJsaw5 uC7mxt/OW4md3NkE2Y0F+utaYiudlKPsLs7MJ62E4j6VzGGO0+ePOf1p6BDAgJ7JCbkaQzI1VID 8lYl9HBN1v2q1vLCqow== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 phishscore=0 impostorscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 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 2521ed5ce576..e73d2dd997b3 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11353,8 +11353,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 Mon Sep 28 06:34:45 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 5C4053D8122; Tue, 25 Aug 2026 10:41:24 +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=1787654486; cv=none; b=OFY6s91oxterAS0kla7Xi0FUuRcN0Q+M5a15srPBgxiYnqf7NBDDGt79bndkESgBmsJPF+z5UDuLZsseKNtlFO1cl9SgM0Q+eLzip3bwQl7p1vsfjoyEi9TVXukUmfGBegiVA67ur6c8QEONLoPV64ter6WHVACF4w976OoajPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654486; c=relaxed/simple; bh=f4RZbwN6k91KJukFuM0RllMcM2/UmKVh0RGHevSVTTU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DY2I+w1m/T4KFIB4w/BrEjd8gNoHwMZdrxwTnP3qFce/KbY2Av6v+EhT1N1C92baP82LvRCaY7WkNHrSrFvxTMwPyKpW6q/4idoyVTOLi8NNc/lc8s0JLVhC/oLew5d/jmGbF+KOcLj+UfDeCLYllVNjaH9Y+mcN5SkkNEV8Fd8= 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=Espd9RH3; 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="Espd9RH3" 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 67P8Vj7t378190; Tue, 25 Aug 2026 10:41:03 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=RYcC6ETWvM62aQ350 zQgjRWtGpEKDheacDz5dIWSh/o=; b=Espd9RH3uAGR8YwiGEb5RNSALJyBSl37L C4k5ZO0NUIV+I97uCgQnIMsceN7WYA+9ryVtOUJ/QnsWx3H3ZRU6YegDN0W0HsZP leilfyFOWTx13bYzckavrhWUG7Dr1uzdwZNo1GhnNRZSalsbcaDJZ3hErwVYjMpe G+Pp0HPujqO59H8jopBIbxfnmdMLOhL0WRODzz63fdasXd9xpXzeI88cKB1hu0GY HeFYDMEhXJk3rNScohHxL9CLUCLIRH2BhA3y49y/Fnmafly9OJiYNmrKmbf/LeVr c7aw4WRhIoL90ADXiWPRHea35/cxudm7TDgvVriyvx2CWJC1A2o/g== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4g73dx7adv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:41:01 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 67PAQK46018791; Tue, 25 Aug 2026 10:41:00 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4g7rsy3ffv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:41:00 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAevBD31392400 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:40:57 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2E392004B; Tue, 25 Aug 2026 10:40:56 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EBE0D20040; Tue, 25 Aug 2026 10:40:46 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:40:46 +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, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 09/12] virt: Introduce steal governor driver Date: Tue, 25 Aug 2026 16:08:52 +0530 Message-ID: <20260825103855.721013-10-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX7IvX29bnWoH7 TudtEGcFOkZ1i7kf24CcTjsTfqMBC+YVB41gvWaAZY9myRsu14zb90HwsTZ19I59BvpPzjwaM6I h3KbgpkZG1NV27hhQP0u3932fGXbfwk= X-Authority-Analysis: v=2.4 cv=AYuB2XXG c=1 sm=1 tr=0 ts=6a8d713e cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=pGLkceISAAAA:8 a=zd2uoN0lAAAA:8 a=VnNF1IyMAAAA:8 a=VwQbUJbxAAAA:8 a=8b9GpE9nAAAA:8 a=NU4kZiTgvjoGX6N8-j0A:9 a=T3LWEMljR5ZiDmsYVIUa:22 X-Proofpoint-ORIG-GUID: FVD92pthsrjbWkJmbfGkv3mgbV1NqaIG X-Proofpoint-GUID: hohLAkCMI_aFdgBSHzGwSrOfQLUz5EQS X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX/2eRYGOaEMLd MI8d4yI+9XR1K4iQZ6UvqjNH8x/FljwkhIPRNCX+7WWm7CbtDaQv5tOrp3yoyLEDn7OsHHJPX6h XKo+oQoCScGUUa0tn6WmWpnMOdxtU4JQWTCQ/W1eX6yPvQFLi0UGFztM6rEG0g+GuhTYheD1LD7 OaHy7TegBRfQk4WKROUovEt/0+l7zO/jI3v9YOxoyMY4w2PFAhsKB7jCe8rWJaDORlDB2fzSNq7 hq/s0kryHFU+TOp7qPziTUiEChLFXk0W9VvJvvkjdLdSiVOkG9N+JIj7qO4GAuAZXSble0OirMU mUcF5GpqQ5TCIojK7nQgp79DKDhxbGw7O0h1jOBLtprb7e7Y2M5wFuVXKmj57pIQ8OXgm1KIOcj y8a+wLP5tSkHRMB+ijET1oVDPiv/zVoBkILsStOZuCicCWiSqC/U9tMMDBNift47j+PCf5hm2AE SVsCBJsVmx8Ik+wDn3g== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 adultscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 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 regarding the preferred CPU state. Note that this driver is strictly intended for actual guests. Hence block it on Xen dom0. More details can be found in Documentation/driver-api/steal-governor.rst. A new kconfig called STEAL_GOVERNOR is introduced in subsequent patches, which enables this driver. This driver will select CONFIG_PREFERRED_CPU. This makes configs driven by user preference/configuration. When the driver is disabled, preferred CPUs remain the same as active CPUs. The file layout of the driver is kept simple for now. The code is in drivers/virt/steal_governor.c, and the configs are part of drivers/virt/Kconfig. The main structure of the steal governor contains: - work, delay: Deferred periodic work function variables. - steal, time: Used to calculate deltas during periodic work. - interval_ms, high_threshold, low_threshold: Tuning knobs for the steal governor. While there, add MAINTAINERS entry for this new driver. Suggested-by: Yury Norov Suggested-by: K Prateek Nayak Signed-off-by: Shrikanth Hegde --- Documentation/driver-api/index.rst | 1 + Documentation/driver-api/steal-governor.rst | 151 ++++++++++++++++++++ MAINTAINERS | 9 ++ drivers/virt/steal_governor.c | 78 ++++++++++ 4 files changed, 239 insertions(+) create mode 100644 Documentation/driver-api/steal-governor.rst create mode 100644 drivers/virt/steal_governor.c diff --git a/Documentation/driver-api/index.rst b/Documentation/driver-api/= index.rst index eaf7161ff957..0a973b59cba3 100644 --- a/Documentation/driver-api/index.rst +++ b/Documentation/driver-api/index.rst @@ -138,6 +138,7 @@ Subsystem-specific APIs sm501 soundwire/index spi + steal-governor surface_aggregator/index switchtec sync_file diff --git a/Documentation/driver-api/steal-governor.rst b/Documentation/dr= iver-api/steal-governor.rst new file mode 100644 index 000000000000..3817eedb38d7 --- /dev/null +++ b/Documentation/driver-api/steal-governor.rst @@ -0,0 +1,151 @@ +.. SPDX-License-Identifier: GPL-2.0 + +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 + +The steal governor is aimed at mitigating the Noisy Neighbour problem +which occurs in paravirtualized environments with CPU overcommit. +The performance of a workload running in one VM gets degraded by +the activity of other VMs on the same host. As a result, all VMs +collectively make slower forward progress. + +In such systems, high utilization in all VMs causes the hypervisor to +frequently preempt vCPUs. This vCPU preemption is expensive. +To mitigate this, the kernel aims to restrict workloads to a subset of +Preferred CPUs to reduce physical CPU contention. +A detailed explanation of Preferred CPUs is available in +``Documentation/scheduler/sched-paravirt.rst``. + +The steal governor selects ``CONFIG_PREFERRED_CPU=3Dy`` which enables the +scheduler core infrastructure to move the tasks to Preferred CPUs where +possible. The driver controls the policy decisions regarding the state of +preferred CPUs. That is, this driver decides which CPUs are preferred +and which CPUs are non-preferred. + +The driver code is available at ``drivers/virt/steal_governor.c``. + +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 the steal ratio using accumulated steal time + across possible CPUs, normalized by the number of active CPUs. + +2. If steal ratio is greater than high threshold, reduce the number of + preferred CPUs by 1 core. Ensure at least one core is left always. + Skip changing the state of offline CPUs in that core. + +3. If steal ratio is less than or equal to low threshold, increase the + number of preferred CPUs by 1 core. If preferred is same as active, + nothing to be done. Skip changing the state of offline CPUs. + This helps to handle cases where few CPUs are offline in a core and + those offline CPUs will not be marked as preferred. + +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. + +Note that this driver is strictly intended for actual guests; for example, +loading this module in a privileged VM like Xen Dom0 is blocked. + +Workload considerations +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The steal governor is useful for workloads where vCPU preemption has +costs beyond the lost CPU time, such as lock-holder preemption, critical +sections, communicating threads, and cache or TLB disruption. + +Pure CPU-time workloads with independent workers may not benefit and +could see a small regression due to additional guest scheduling overhead. + +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 sees steal ratio is less than or equal to this value, +it will increase the preferred CPUs by 1 core. +Using 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 ratio is higher than this value, it will +reduce the preferred CPUs by 1 core. + +Limitations of default values +----------------------------- + +Because of the vast diversity in VM configurations and different +architectures, the default thresholds may not be optimal for all systems. +Users may need to tune these parameters based on the system under +test to achieve the best results. + +The governor sums the steal time across all possible CPUs, which ensures +the accumulated steal time remains a monotonically increasing value. +However, to calculate the effective steal ratio, it divides this sum +by the number of active CPUs. Because only active CPUs contribute to +the steal time delta, this prevents threshold dilution on sparsely +populated systems. + +The driver reduces/increases preferred CPUs by core-level. This could prov= ide +faster convergence for hypervisors such as powerVM. But on KVM and Xen +convergence could be slower depending on the configuration. +Using a smaller interval_ms could help one to expedite it. + +Reasons for CONFIG_STEAL_GOVERNOR=3Dm +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Selecting this driver makes CONFIG_PREFERRED_CPU=3Dy. That makes configs +driven by user preference. Though one can have CONFIG_STEAL_GOVERNOR=3Dy, +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 a co-operative manner. When an + administrative user enables it in one VM, he/she will likely enable + it in all VMs. + +3. User can tweak the module parameters by reloading the module. diff --git a/MAINTAINERS b/MAINTAINERS index 8014b9f8253e..e0c27d97659d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -25923,6 +25923,15 @@ F: rust/helpers/jump_label.c F: rust/kernel/generated_arch_static_branch_asm.rs.S F: rust/kernel/jump_label.rs =20 +STEAL GOVERNOR DRIVER +M: Shrikanth Hegde +R: Yury Norov +L: linux-kernel@vger.kernel.org +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core +F: Documentation/driver-api/steal-governor.rst +F: drivers/virt/steal_governor.c + STI AUDIO (ASoC) DRIVERS M: Arnaud Pouliquen L: linux-sound@vger.kernel.org diff --git a/drivers/virt/steal_governor.c b/drivers/virt/steal_governor.c new file mode 100644 index 000000000000..2320cbfa4b47 --- /dev/null +++ b/drivers/virt/steal_governor.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Steal time governor driver periodically computes steal time. + * Based on the thresholds it either reduce/increase the preferred + * CPUs which can be used by the workload to avoid vCPU preemption + * to an extent possible in paravirtualized environment. + * + * Available with CONFIG_STEAL_GOVERNOR + * + * Copyright (C) 2026 IBM + * Author: Shrikanth Hegde + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef CONFIG_XEN +#include +#endif + +#if !IS_ENABLED(CONFIG_PREFERRED_CPU) +#error "Steal Governor requires CONFIG_PREFERRED_CPU" +#endif + +struct steal_governor { + ktime_t time; + u64 steal; + unsigned long delay; + unsigned int interval_ms; + unsigned int high_threshold; + unsigned int low_threshold; + struct delayed_work work; +}; + +static struct steal_governor sg_ctx; + +static void restore_preferred_to_active(void) +{ + int cpu; + + guard(cpus_read_lock)(); + for_each_cpu(cpu, cpu_active_mask) + set_cpu_preferred(cpu, true); +} + +static int __init steal_governor_init(void) +{ +#ifdef CONFIG_XEN + if (xen_initial_domain()) { + pr_err("Cannot load in Xen Dom0 (Host OS). Driver is for guests only.\n"= ); + return -ENODEV; + } +#endif + + pr_info("enabled\n"); + return 0; +} + +static void __exit steal_governor_exit(void) +{ + restore_preferred_to_active(); + pr_info("disabled\n"); +} + +module_init(steal_governor_init); +module_exit(steal_governor_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("IBM Corporation"); +MODULE_DESCRIPTION("Virtualization Steal Time Governor"); --=20 2.47.3 From nobody Mon Sep 28 06:34:45 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 C68C33F8243; Tue, 25 Aug 2026 10:41:31 +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=1787654493; cv=none; b=F2wMBY7BRuXOo6PnVBiH0HMeIatFJkLl+NJvZ0/B4g5DZNCcorA/QqOcV3BRSA4/gblF269hGKCXrWtbL7BZYWjlXR3ZOauIIK/74Q+/9ZwIavVy0it19UfTIbGI7jbvC9qhYYmVuEcF9tvMaDj2N9LcJseow+QxlevrIIrn+Xg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654493; c=relaxed/simple; bh=Ai7BZFUwbrN1gH9HpwgUQK3VLaG28dly6FZX8ayTblY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kRbwq6aL6fB6LD0/VVsiiTThDirj2cQ48lublgL5JkGqQifrh7OW+1ASJNPc5nspGpbjCN+Vun9NKO3suN0SgaZm8DaNernwNYKWZy5SFuzbTnppKxg8/6M5bbzWHXIRBFgF8GkS3L5qLxeT1mjolYCW8u7jk2F7WQ4dg9piv9w= 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=C3KUmZSd; 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="C3KUmZSd" 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 67P8Vcpi378024; Tue, 25 Aug 2026 10:41:11 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=M/Nty/8xoMmBzlksU iq0rAIJjnFP0kPDZRGSr+wzHPM=; b=C3KUmZSdybMt8OS9uwfcjhT8whbhiaxwM 983AbY4N+qaDf1YxFNH2UnjNOLc/k9UMdQQN21VbS65X9ZE5LgOv+230/z4nTi4s qmX2UwbAxO4BPjQWvwhGWdu5vXTpQz3/HoBU22n4BCrmOV4vUZU82ZRHWK7Oq1Jh 5gPuciVf0Qu75+JWTd5EM4ev11bA6IaGeClKNKrUH8SPnPX8PhuLRv9hsR/gxan3 jD40rDQqZ1AbXfZjsNybOoUws5PwYVcZonOkmZk4hAC/e0RdzpoMNgpaBKJhKUtF xKBShdaM+c1APP6YoXlmm79YR75zShcZHw8yRBtixt80qqzT0XX8A== 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 4g73dx7aep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:41:11 +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 67PAQGrw009616; Tue, 25 Aug 2026 10:41:10 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4g7pfw3uhy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:41:10 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAf6j247120842 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:41:06 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B24D20043; Tue, 25 Aug 2026 10:41:06 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7AD7620040; Tue, 25 Aug 2026 10:40:57 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:40:57 +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, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 10/12] virt/steal_governor: Add control knobs for handling steal values Date: Tue, 25 Aug 2026 16:08:53 +0530 Message-ID: <20260825103855.721013-11-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX631Pp3szzZcd h0qEoVBYwj3LVYew+yeYrDtaxdcOpPaaSvYibHCHYU2KKSDzXCNVXelQAwcR6AyS2XiD0jcAHMJ mUF1ws2XvH2eiz1CUe0aaZW0nwkMrUg= X-Authority-Analysis: v=2.4 cv=AYuB2XXG c=1 sm=1 tr=0 ts=6a8d7147 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=XC_GqrfF-lTPz34eE_0A:9 X-Proofpoint-ORIG-GUID: ji1YcgYUIhtntHhy1V64SJTHn-tW0ji7 X-Proofpoint-GUID: IQaOsq3wr4zoB7vJoGytVHpasZ47nb06 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX19qu84Y012aR Q1JgjsClvbdSas1TfUAWtBY8FIQujuLUG1smmnb/h4muL+wq32DmCaURNoY5B9SSbkGXqZE/mY0 6sJbEap6xkz1IFshQN+bsOwgfCgVRXWKX/G/8Wkg6b+XOVfd+bhv59hPuA+MbODHt74fVS7fgAh DDGH9SCe+b9yWc0WwiR9dK8dp5mY0x88SJr4fjznqNEdKikk3aHnDfgXgVpso9DhkDNTLxa3Boz W6+Wi6aet4vMPI4A0xwlk7wge+2RTfSKbvUHkA9BcN3jBzk7DLg+YCgIDDHWABNSgeoDvlE3gtN Za5FoO8nhGZiA/zPY4jE2he1taPZTT+1gdBxRmFb3BBbHtjHZ/fiwcyL9pAeug17gPOS44eBWmf 2dfXwk2VgTlwXgww/1jFeg4CRSpHKc08jEcQ5LGwEz/i6BTkMmSA1wgjhcLplz5+frlZEA21+my 9cp8nn//ienXMnqunew== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 adultscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 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 ratio 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 ratio 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. Notes: - Parameters values can't be changed at runtime. One has to unload the module and change it. Hence recommended to build it as module. - Default values may not work well for all configurations. Tune it according to the system under test. Documentation is available at: Documentation/driver-api/steal-governor.rst Suggested-by: Yury Norov Signed-off-by: Shrikanth Hegde --- drivers/virt/steal_governor.c | 73 ++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/drivers/virt/steal_governor.c b/drivers/virt/steal_governor.c index 2320cbfa4b47..27f53ea16498 100644 --- a/drivers/virt/steal_governor.c +++ b/drivers/virt/steal_governor.c @@ -40,7 +40,11 @@ struct steal_governor { struct delayed_work work; }; =20 -static struct steal_governor sg_ctx; +static struct steal_governor sg_ctx =3D { + .interval_ms =3D 1000, /* 1 second */ + .high_threshold =3D 500, /* 5% */ + .low_threshold =3D 200, /* 2% */ +}; =20 static void restore_preferred_to_active(void) { @@ -51,6 +55,62 @@ static void restore_preferred_to_active(void) set_cpu_preferred(cpu, true); } =20 +static int param_set_interval_ms(const char *val, const struct kernel_para= m *kp) +{ + unsigned int interval; + int ret; + + ret =3D kstrtouint(val, 0, &interval); + if (ret) + return ret; + + if (interval < 100 || interval > 100000) { + pr_err("interval_ms must be between 100 and 100000\n"); + return -EINVAL; + } + + return param_set_uint(val, kp); +} + +static const struct kernel_param_ops interval_ms_ops =3D { + .set =3D param_set_interval_ms, + .get =3D param_get_uint, +}; + +module_param_cb(interval_ms, &interval_ms_ops, &sg_ctx.interval_ms, 0444); +MODULE_PARM_DESC(interval_ms, + "Sampling frequency in milliseconds. default: 1000"); + +static int param_set_high_threshold(const char *val, const struct kernel_p= aram *kp) +{ + unsigned int threshold; + int ret; + + ret =3D kstrtouint(val, 0, &threshold); + if (ret) + return ret; + + if (threshold >=3D 100 * 100) { + pr_err("high_threshold (%u) can't be more than 99.99%%\n", threshold); + return -EINVAL; + } + + return param_set_uint(val, kp); +} + +static const struct kernel_param_ops high_threshold_ops =3D { + .set =3D param_set_high_threshold, + .get =3D param_get_uint, +}; + +module_param_cb(high_threshold, &high_threshold_ops, &sg_ctx.high_threshol= d, 0444); +MODULE_PARM_DESC(high_threshold, + "High steal threshold. default: 500 i.e 5%. Must be > low_threshold"); + +module_param_named(low_threshold, sg_ctx.low_threshold, uint, 0444); +MODULE_PARM_DESC(low_threshold, + "Low steal threshold. default: 200 i.e 2%. Must be < high_threshold"); + static int __init steal_governor_init(void) { #ifdef CONFIG_XEN @@ -60,7 +120,16 @@ static int __init steal_governor_init(void) } #endif =20 - pr_info("enabled\n"); + if (sg_ctx.low_threshold >=3D sg_ctx.high_threshold) { + pr_err("low_threshold (%u) must be less than high_threshold (%u)\n", + sg_ctx.low_threshold, sg_ctx.high_threshold); + return -EINVAL; + } + + sg_ctx.delay =3D msecs_to_jiffies(sg_ctx.interval_ms); + pr_info("enabled. interval: %ums, high_threshold: %u, low_threshold: %u\n= ", + sg_ctx.interval_ms, sg_ctx.high_threshold, sg_ctx.low_threshold); + return 0; } =20 --=20 2.47.3 From nobody Mon Sep 28 06:34:45 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 1F9AB3DD846; Tue, 25 Aug 2026 10:41:42 +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=1787654503; cv=none; b=VMg1jYuskvlc2XevHO8tLHecu9oo52J/NOyQ6sSz2+ZVnm3UDQPUGl16lSE4GvbstzmzHVoSo6NI6L62Xd8vY/yKsHGxp/5uLRtKOmnMtU2rri/O5ovRmb37Kptq7uBLJ7ukuESAwXSitKaHivi/Bn0oEiOwbuGiP3eZwQsL1Yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654503; c=relaxed/simple; bh=NE8QZFrI2CZDMpNTFBUpYPgHYrbDCMbuaUaP/NCDzes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aeO1wY60fr6vWAIXnHS4K4V4gdkiVLmNMjCZB3ZzkFv2nyFEWH+gURzmZ4IY8vVyMus2chmnGXxU6CUHO7T9UOEecwKYnFcA5BdeV8bhDlLpmHRV6aw8GKfwXDviDeXs0flYKnPkBd44CzyORJBOBdk3PMtdqY3wFfaLOlG0GL0= 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=U2P0m3BH; 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="U2P0m3BH" 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 67P8VSVk306493; Tue, 25 Aug 2026 10:41:21 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=7i2OrVHDYSgZ7Xt3U EJoZs+5l+QM7dXhBQd4/xCpUs0=; b=U2P0m3BHRbwyL0GY9Uxfh6cMPAMfxi2HS dxyuybqJvEcMmH1npeH8VKxf258pFsswQAOWy0hKZdh9bqCKT3kzcW7i0SDpiILm oV2/PgxRS88q8WDSv0V1PkJCxY66m3JZQLG/83W7u2VGEA7CJ6+buqQMZwK0o/mV rIBbZYbbdw9ne8f6481X4v6gtFQ3l6m6BIMPggADhZy5TD4iPdT/9Vm5YbnIfhXI Fo/eR25aJa8EHRm9srX24uUpkC+9ahCT8j5m51THuKDSrQfKasY55ntzIxNg+Lh4 FNpoNgxI+Y35jHfEo0XYP2CWGuRoX16oRJ91VBrDzyU70dGSGlOAQ== 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 4g7393ykmg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:41:20 +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 67PAfIBT023194; Tue, 25 Aug 2026 10:41:19 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4g7p3q3xh7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:41:19 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAfFhk46858708 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:41:15 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4CB1320040; Tue, 25 Aug 2026 10:41:15 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F6AA2004F; Tue, 25 Aug 2026 10:41:06 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:41:06 +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, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 11/12] virt/steal_governor: Implement steal_governor policy loop Date: Tue, 25 Aug 2026 16:08:54 +0530 Message-ID: <20260825103855.721013-12-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-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-GUID: uDubRNElMQOsqDa5S3ynKHnzoj2GSu16 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX0NCgTfQaTgTF BKk+FyrkG882UwoTzesSfzuD6Owmi5fE/msgPi9bYfjxXFzcWk/raDhkSObScF1UbP0GQxqL2yn 2F8Wu/NOHZ9vBXXax4Vf5lgWd7cOU20ZmtBzn6OPvVcdtkFrxUkjDSVj9n15BrRDhXTWPw6RqHb CpAunU3gHzFtyaZmuvMl9+KFAKxQY0FyO8dIWMNQCWVml0P/+bJ7ciWZ7Pip59TrJBUEIXqi/fu BlKeeKDFskUIifQ8jozzr/GWdg01oog2o5gP76rFa53a/uZIXiYrpcBZ56vQtveiRSKC73pvMdS PW/K4JeXf6MgSrgDgGAja02agzFMRW5Ih2UOBy72BdNHdV/PwPMEk4WCXsefExpsSlyfSOwDfgl zidjVADmKydpvS67q79scCbzcey9hcQe3wc2CSMSRgU9TBCKzkjaZF5kM3V1eKp2Vk4+QTdidIX 2Ws5o9yAqlDYanf+YKw== X-Authority-Analysis: v=2.4 cv=Y/nIdBeN c=1 sm=1 tr=0 ts=6a8d7150 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=dzxYU6fr5WJrpIuQ_HEA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfX10Rl7tGWg7c+ 7HKNS6/u+jRkMDWvsAHT3vJV19UanicqAhMPWjytWIrfITbwxLpCLFNTLyHANBemEaiPUZAb4Zx TggVyNHb/krG/+qy2IX1We9h26PGI0c= X-Proofpoint-ORIG-GUID: Q-_eX6JmEe1lafY61jkTAf3ZEArvv95_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 Content-Type: text/plain; charset="utf-8" Schedule work at regular intervals to implement the steal_governor policy loop, which monitors steal time and takes action on the state of preferred CPUs. The interval is determined by the interval_ms parameter. schedule_delayed_work() is used since interval_ms is on the order of milliseconds and the work does not need to happen instantly. Periodic policy loop essentially does: - Gets the total/delta steal values and cpus to use steal_ratio. - Calculate the steal_ratio as below. steal_ratio =3D (delta_steal * 100*100)/(delta_ns * num_cpus()) It is calculated this way 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 ratio is higher than high threshold, call the method to reduce the preferred CPUs. - If steal ratio is lower or equal to low threshold, call the method to increase the preferred CPUs. - If the steal ratio falls in between, no action is taken. - Ensures design constraints always 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. Note that design checks are always performed. This helps avoid placing driver-specific design constraints inside the core CPU hotplug mechanism. User may offline specific set of CPUs that could leave the preferred mask as empty. With the design check performed always, driver gracefully shuts down upon detecting that edge case. 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. - 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. i.e target CPU - Based on that target CPU, get its sibling and mark them as non-preferred. 3. increase_preferred_cpus() - Called when there is low steal time. It needs to decide which CPUs to mark as preferred and set that state. - Get the first active non-preferred CPUs. This likely is the last set of CPUs being marked as non-preferred. - get the siblings of that CPU and mark them as preferred. 4. get_system_cpus() - informs how many CPUs needs to be considered for steal_ratio calculations. - Since only active CPUs effectively contribute to steal time delta, returns number of active CPUs. This also helps to avoid dilution of thresholds in sparsely populated systems. Notes: 1. Using core instead of individual CPUs performs better as SMT is quite common and some hypervisor such as powerVM does core scheduling. 2. This doesn't do any NUMA splicing to keep the code simpler and minimal overhead. Current code expects CPUs spread uniformly across NUMA nodes. Signed-off-by: Shrikanth Hegde --- drivers/virt/steal_governor.c | 149 ++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/drivers/virt/steal_governor.c b/drivers/virt/steal_governor.c index 27f53ea16498..6e31f9923dea 100644 --- a/drivers/virt/steal_governor.c +++ b/drivers/virt/steal_governor.c @@ -13,13 +13,18 @@ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 +#include #include #include #include #include +#include #include #include +#include #include +#include +#include #include #include #ifdef CONFIG_XEN @@ -111,6 +116,145 @@ module_param_named(low_threshold, sg_ctx.low_threshol= d, uint, 0444); MODULE_PARM_DESC(low_threshold, "Low steal threshold. default: 200 i.e 2%. Must be < high_threshold"); =20 +/* Return collective steal time across system. */ +static u64 get_system_steal_time(void) +{ + return kcpustat_field_total(CPUTIME_STEAL, cpu_possible_mask); +} + +/* Return number of CPUs to consider for steal ratio. */ +static unsigned int get_system_cpus(void) +{ + return num_active_cpus(); +} + +/* + * Called when the steal governor detects high physical CPU contention. + * It finds the last active core in the preferred mask and mark those + * CPUs as non-preferred. + * + * Must ensure: + * - at least one core is always kept as preferred + * - preferred is always subset of active. + */ +static void decrease_preferred_cpus(void) +{ + const struct cpumask *first_hk_core; + int target_cpu =3D nr_cpu_ids; + int cpu; + + guard(cpus_read_lock)(); + cpu =3D cpumask_first_and(housekeeping_cpumask(HK_TYPE_KERNEL_NOISE), + cpu_preferred_mask); + if (cpu >=3D nr_cpu_ids) + return; + + /* Always leave first housekeeping core as preferred. */ + first_hk_core =3D topology_sibling_cpumask(cpu); + cpu =3D cpumask_last(cpu_preferred_mask); + if (cpu >=3D nr_cpu_ids) + return; + + /* Find the last CPU which doesn't belong to that first hk_core. */ + if (!cpumask_test_cpu(cpu, first_hk_core)) { + target_cpu =3D cpu; + } else { + for_each_cpu_andnot(cpu, cpu_preferred_mask, first_hk_core) + target_cpu =3D cpu; + } + + /* Only the first housekeeping core remains */ + if (target_cpu >=3D nr_cpu_ids) + return; + + for_each_cpu_and(cpu, topology_sibling_cpumask(target_cpu), + cpu_preferred_mask) + set_cpu_preferred(cpu, false); +} + +/* + * Called when the steal governor detects no/low physical CPU contention. + * It finds the first active core outside of preferred mask and mark + * those CPUs as preferred. + * + * Must ensure preferred is subset of active. + */ +static void increase_preferred_cpus(void) +{ + int first_cpu, cpu; + + guard(cpus_read_lock)(); + first_cpu =3D cpumask_first_andnot(cpu_active_mask, cpu_preferred_mask); + + /* All CPUs are preferred. Nothing to increase further */ + if (first_cpu >=3D nr_cpu_ids) + return; + + for_each_cpu_and(cpu, topology_sibling_cpumask(first_cpu), + cpu_active_mask) + set_cpu_preferred(cpu, true); +} + +static bool preferred_cpus_valid(void) +{ + if (cpumask_empty(cpu_preferred_mask)) { + pr_err("empty preferred mask. stopping\n"); + return false; + } + + if (!cpumask_subset(cpu_preferred_mask, cpu_active_mask)) { + pr_err("preferred: %*pbl is not subset of active: %*pbl, stopping\n", + cpumask_pr_args(cpu_preferred_mask), + cpumask_pr_args(cpu_active_mask)); + return false; + } + + return true; +} + +static void steal_governor_loop(struct work_struct *work) +{ + u64 curr_steal, delta_steal, delta_ns, steal_ratio; + ktime_t now; + + now =3D ktime_get(); + delta_ns =3D ktime_to_ns(ktime_sub(now, sg_ctx.time)); + + if (unlikely(delta_ns < NSEC_PER_MSEC)) { + pr_err_ratelimited("work scheduled too soon delta_ns: %llu\n", delta_ns); + goto requeue_work; + } + + curr_steal =3D get_system_steal_time(); + delta_steal =3D curr_steal > sg_ctx.steal ? curr_steal - sg_ctx.steal : 0; + sg_ctx.steal =3D curr_steal; + sg_ctx.time =3D now; + + /* + * steal_ratio =3D (delta_steal * 100*100)/(delta_ns * num_cpus()) + * To avoid possible overflow, divide the denominator early. + * Note minimum interval is 100ms. + */ + delta_ns =3D max_t(u64, div_u64(delta_ns * get_system_cpus(), 10000), 1); + steal_ratio =3D div64_u64(delta_steal, delta_ns); + + if (steal_ratio > sg_ctx.high_threshold) + decrease_preferred_cpus(); + else if (steal_ratio <=3D sg_ctx.low_threshold) + increase_preferred_cpus(); + /* + * else: steal ratio is within bounds. Still do design checks so that + * module restores to active if CPU hotplug breaks those assumptions. + */ + if (!preferred_cpus_valid()) { + restore_preferred_to_active(); + return; + } + +requeue_work: + schedule_delayed_work(&sg_ctx.work, sg_ctx.delay); +} + static int __init steal_governor_init(void) { #ifdef CONFIG_XEN @@ -127,6 +271,10 @@ static int __init steal_governor_init(void) } =20 sg_ctx.delay =3D msecs_to_jiffies(sg_ctx.interval_ms); + INIT_DELAYED_WORK(&sg_ctx.work, steal_governor_loop); + sg_ctx.steal =3D get_system_steal_time(); + sg_ctx.time =3D ktime_get(); + schedule_delayed_work(&sg_ctx.work, sg_ctx.delay); pr_info("enabled. interval: %ums, high_threshold: %u, low_threshold: %u\n= ", sg_ctx.interval_ms, sg_ctx.high_threshold, sg_ctx.low_threshold); =20 @@ -135,6 +283,7 @@ static int __init steal_governor_init(void) =20 static void __exit steal_governor_exit(void) { + disable_delayed_work_sync(&sg_ctx.work); restore_preferred_to_active(); pr_info("disabled\n"); } --=20 2.47.3 From nobody Mon Sep 28 06:34:45 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 BCB243D669F; Tue, 25 Aug 2026 10:41:51 +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=1787654513; cv=none; b=GKGb4SUj8oTOHbL0i4McnnBMXu9KB8EU9/ehPgc1xl2eTI7pptJ7MqOPj1C0MRI7y07ZkaHw6fdvvdv297ayLGlYbxHBJ7I7hp4XNGALsEpf6VpX1/P97GaFfHOC8usagxv7UtIRZn/jipvFCpHxOcTmlP1aYO54dmFKFGpi7NE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787654513; c=relaxed/simple; bh=uH+Hn7uZPJK+kiZoYAFD5EM5mgdDrTDp4nTbTBfi7JE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ABwIKxqMaSbKXY8c8E66wUCkrNcfM2/3u7IcIY7drrZLxNMdRW/i6t3TdH0APlbB+DzITRHMX1f0GQJpUKq/lncqNjwWgkrLKb3W/VmKXFeM4fLf/iJM/DFhWP5Qn5czFVVZfFpDABsmmQQyw5hHKipynJmLhUDYEM9SM7pnuNI= 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=kc/r10UH; 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="kc/r10UH" 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 67P8VcQt306815; Tue, 25 Aug 2026 10:41:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=VLsDw6fkEnlHHXt/X o79Qrq5n3tqJjESZ8GDDMjODiI=; b=kc/r10UHSi5WpR+NONfZyJ23LZdON1WB6 BbuEvPtts21pv4XU4dZQwnGq/ZIo4OQU7dpecm2Izg77N3dY1GKVBaX/CfSUzd3X Oa82ICHtQ/pTrHuhsMFZsu0H/rbOhE6EyWBFqTFmLx1yeT59+9BCwIq9de4yNucX YKZSSHFPqliS0nEqzrCX1ijkU5HB7ot+ewNXLmmwm5Q5n6c61pgbwzIseGgJP8sk PVlTYrBOoO+aaJZjOqdP1t4x6nOUdRvwLgWY2bz/k6CX24HZiBVTWIOaXTyuXBrJ EoLW+yju+7XpUGxdJotrBwG7cdrdZul5ErLG7rwUoSEYCGduTGrTw== 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 4g7393yknc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:41:29 +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 67PAfJN1021065; Tue, 25 Aug 2026 10:41:28 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4g7qkh3mn3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2026 10:41:28 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67PAfOAh32440716 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Aug 2026 10:41:24 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 854F12004D; Tue, 25 Aug 2026 10:41:24 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB9BE20040; Tue, 25 Aug 2026 10:41:15 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.21.103]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 25 Aug 2026 10:41:15 +0000 (GMT) From: Shrikanth Hegde To: linux-kernel@vger.kernel.org, mingo@kernel.org, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, yury.norov@gmail.com, kprateek.nayak@amd.com, iii@linux.ibm.com, corbet@lwn.net, meted@linux.ibm.com, ynorov@nvidia.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, 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, sunlightlinux@gmail.com Subject: [PATCH v11 12/12] virt/steal_governor: Enable the driver Date: Tue, 25 Aug 2026 16:08:55 +0530 Message-ID: <20260825103855.721013-13-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260825103855.721013-1-sshegde@linux.ibm.com> References: <20260825103855.721013-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-GUID: jNZWDPDln-panWY0jQfd4q1GEeQT3aQ6 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXwj+8FK1K2xXP bfbImwah28054Zk70hsV/JoOIfwWCdDOvJvRvi44u5Apcckb40AqImEHMonowzf9SG820iQ8bk8 6pBFo4etul4dp2MIggPSdG1AmM5JCY8C8aHOrZsl3MiqObdmP2A5gRlDXx2IU8QdpO40MTySlj3 MkX0GKKBGdKpOd0LMxBCO1NY/eOn10LVJn9OqrR0FA0BJPbmnjibeS+KsMY6O/zQc2Q9dyvT+3r uIpIF+0mLsvEj+Gd+EgszSwcQ9IWSqhRXcUi4PR0aCb1b6hcgkzKZcwqHsRdWFNQD7ITUWqhJIU HnoumIz/8HbqnwfLNidIt4jYlAnMNV1edzcqqICzWpWC6ec5GSnXDxQ45lA6GflGP/v8ubgrL01 cUkNLOCFwDv8sDcLDkzZtIUYEOOYI5UCAf7FXw2imhYnv3FeQofYNXZ3WtjUyeouQ5YJjYdUlyv 8jEBiiMDBoYT+0qgtFw== X-Authority-Analysis: v=2.4 cv=Y/nIdBeN c=1 sm=1 tr=0 ts=6a8d715a cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=jPZz8W9ceouySDeeKuAA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDA4OSBTYWx0ZWRfXzMnKBx3yS1IU gCyuwsIrPF3Iu7wF52ikDZ/f8gJhYxc5Lgw0naLKKxZL1qWJiKGLM0pfItXOHrXtvfHIWdYLRmw 3wWvaJTZOZaqm8Urxm7gokIp481bd+8= X-Proofpoint-ORIG-GUID: K76MRLkoU62FVnXVYZFQ5c3J2NKE2_LM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_02,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250089 Content-Type: text/plain; charset="utf-8" Provide a config option to enable the steal_governor driver. Since the feature targets paravirtualized environments and requires SMP, enforce those dependencies. The driver selects CONFIG_PREFERRED_CPU for the core scheduler mechanisms to work. It is recommended to build the driver as a module (m) instead of built-in (y) due to the following reasons: - Module parameters are read-only after initialization. Building as a module allows updating these parameters by simply reloading the module. Default module parameters cannot work in all configurations. - The driver can be completely disabled by unloading the module. - This feature works best when all VMs operate in a cooperative manner. Requiring an explicit module load ensures intentional deployment across all VMs by the system administrator. Suggested-by: Yury Norov Signed-off-by: Shrikanth Hegde --- drivers/virt/Kconfig | 17 +++++++++++++++++ drivers/virt/Makefile | 1 + 2 files changed, 18 insertions(+) diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig index 52eb7e4ba71f..eeb84e578ddf 100644 --- a/drivers/virt/Kconfig +++ b/drivers/virt/Kconfig @@ -41,6 +41,23 @@ config FSL_HV_MANAGER 4) A kernel interface for receiving callbacks when a managed partition shuts down. =20 +config STEAL_GOVERNOR + tristate "Dynamic vCPU management based on steal time" + depends on PARAVIRT && SMP + select PREFERRED_CPU + default m + help + This driver helps to reduce the steal time in paravirtualized + environments, thereby reducing vCPU preemption costs. + + 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. + More details are at: Documentation/driver-api/steal-governor.rst + + It is recommended to build it as module and load the module + to enable it. + source "drivers/virt/vboxguest/Kconfig" =20 source "drivers/virt/nitro_enclaves/Kconfig" diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile index f29901bd7820..05fb075ef5b8 100644 --- a/drivers/virt/Makefile +++ b/drivers/virt/Makefile @@ -5,6 +5,7 @@ =20 obj-$(CONFIG_FSL_HV_MANAGER) +=3D fsl_hypervisor.o obj-$(CONFIG_VMGENID) +=3D vmgenid.o +obj-$(CONFIG_STEAL_GOVERNOR) +=3D steal_governor.o obj-y +=3D vboxguest/ =20 obj-$(CONFIG_NITRO_ENCLAVES) +=3D nitro_enclaves/ --=20 2.47.3