From nobody Sat Sep 26 08:37:18 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 12D413F1ABD; Thu, 3 Sep 2026 06:33:37 +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=1788417221; cv=none; b=jNnpVRqwF4QAEisAtdIFl1DXWHwZrIHt8SPujVo1PqYLlK1dsLxzn4O+0f+OGcs1Xm4EPb8VlRzXH6UAh3DmKAiea4NMHVKJB5qlzze59m3qcrL1Uxclmop4uAwOmfb7EAlPMCA0EBt+5BFKTBidxgdk6hu6+TDNa+3iIOOXXAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417221; c=relaxed/simple; bh=2eu4vRQOu6LsKhcT9hq/Hdw81Tdv7p6TCBbv2/1bsug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ibPUYszCi+bbnfvCjq/V8GiMNm1B9gAJ/hetcbUn6aNtG0TsSPm8EwyH+k3QFpLD9yohhDaLEf32xFxr5hrpPwg4f5YfAr6hpSQHDjMgBzMjxSSlQOO0kL9yJnuLqFmBKosBQ1wfvbXfPlD/pfLIOECPutRYHu+fJKjh05YXaDI= 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=YqvaZjat; 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="YqvaZjat" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68361TnL2186474; Thu, 3 Sep 2026 06:33:09 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=NQfHgXW5cs2koPTGX h0P0s8rQJgmbX6dJiIqaQWvd/I=; b=YqvaZjatTJ8LKOV+kCCksH5JV7p5E0aoU ijVrK4KRIu47QOIziOr+8/708b5mMTj2TyAoQCE6gjL0bYG8gO46P6FfJYPfsBBt tyZUp/JuQ23vb68A8VSZRZqqxE/wq14ZtjN0LMCwFDj67vPikpjeZAwjhykSALSb IpWiGd7p0T3vSWoAkENMcNzGW+zWsUHlchhyVLNjqQrY9nnJodXh/skERBLAORUt gpuLrMfztZzjUdjOLtbkGrn4EcmDiuQDfGMILq4ylnsqiPpOPUnd+fHWZHcq/yYQ 8PmdZV+iv8KTsfk6H+jMRmDbrr0d7HFuGh569+tTNAIiyPVHvaRPg== 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 4gbq553fak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:08 +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 6836QHF7020546; Thu, 3 Sep 2026 06:33:07 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4gcbygp73a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:07 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836X3A539190794 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:33:04 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D7A102004B; Thu, 3 Sep 2026 06:33:03 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 865BB20040; Thu, 3 Sep 2026 06:32:55 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:32:55 +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 v12 01/13] sched/cputime: Add kcpustat_field_total helper Date: Thu, 3 Sep 2026 12:02:28 +0530 Message-ID: <20260903063240.268775-2-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX2COnjSnIqahD UVwNmLHNNrJLaCbfVTnLDwZmDSTf8ybrwZE//7y6Wfw08MrAGhz5feTw7l042owEwuutASgLqY1 40Rh2pRH27f6EbjazgAyU889Z2eflOJc67cVDpWgojc8C8nMvlIkXuOYH6DmcwtWcZuyMCiYvtu qCCXT6tsroj3svn6qU2gaNXm0TzBQ24Dm4gAZVzvlr4NYlC5Wb495YpUPBCfcR3AfmLp/nlKJ0O KiZ6oYOo/n3o0bnfAejHt1baaBv2gVf2a17GWDr4wXPfO7HCd5ADZoqITQ2wa2RnVp21KfB1Mf0 n5hpQ1fn35amk2LER5iBg38hQOYo874FvQI+44IxyPdd+04H6yze+1F1gFyz+ZtBKDlXoMerNbq rVyjWt+j9thsdQeu4VxkOEcyK+1IijlQK8TY5l+90E1lRHueNPhVwL6G6lbzpy0aiuQtcYZ6EgM MVd5/T1zM0BM0wpQUDA== X-Proofpoint-ORIG-GUID: tQId7YB9h7jSvMrpTbKJhiXYA3O9LVgi X-Authority-Analysis: v=2.4 cv=CNgamxrD c=1 sm=1 tr=0 ts=6a9914a5 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=pGLkceISAAAA:8 a=Ikd4Dj_1AAAA:8 a=VnNF1IyMAAAA:8 a=e8TCS894uZmGZegT9CcA:9 X-Proofpoint-GUID: hZqHOvTbMu9hQ5Ujq4jrVLhHyr2k1_c0 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfXxxwpfmy98rRC hkSE64YDqSiA04FE/pB2op0PNToOgA7d5TaiaMRgzfNNngVOgu8jg7uZsGUD/IRH9zerTkGn/3K FzCCQEsNZ5MN8Ip/2LbUSLWjb5IvBXw= 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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 Acked-by: Frederic Weisbecker --- 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.52.0 From nobody Sat Sep 26 08:37:18 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 DC98B38236E; Thu, 3 Sep 2026 06:33:42 +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=1788417226; cv=none; b=pkJhfB2rAvgKVzFybI1ycvcUtU0KTlZyKu/cpUNrdjzWE1BTkDTNnRSgl0yCIR1hd6XcUfnt8cEsJC42WTFszIcahj1tdVutRTAvkOOiDKnuTwOO4elClDwpMk+zwT7d/mp1H87MWSQRanpf4bunKkiyDFSMPM/4Tt78+nNmTmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417226; c=relaxed/simple; bh=1dMM77xohsh0uUWWK5pc/n57DMoFbPH5U47NaaYCfYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WFG/WjGOHunvhHCKg5hPgrdweHzeBPI+dKal+vFzM6uqQoNM10SkomxiurW+EOrC5rb7QgqkrS3lcGDyXzGfPJcYcRCrWU7uVLgrukwTCNztA7DFzkHYcP9p77+ZKaAgRt9EPuqsO8HpyGPmjT7fUQuCDXsCXwPn98ex99zCfUA= 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=ebSD4Omq; 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="ebSD4Omq" 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 68361wNQ2067854; Thu, 3 Sep 2026 06:33:18 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=jQ6Txq0OWN8sohjwx cHNee3Hnk5lvEZRjiLQ/oqdqXs=; b=ebSD4Omqh7OsKljzzOE1p8GOxvESwnhZM wABM7vyc4BfcF0mhfaZLNeZhjV54CNqksY1U7B5Oa3Wnp9EIlD4uVjln3WC9dVNA dNy4+LOpDW0Z1lxOBOFPG7FGxrB2OX1yc/p1A3iipWrH+XLYovaf+KAYk7PfYpUt gHwOKhwwCSP6D+RA1iMj5avU+pP+e+Vyq1WCQO+ONF1fHxFvVni59M26iUkY5nDl rGdRHY384JRM3iPkEQXVT04oE1xR8/tI1Jna5LEbkNH5RGTYfMQx/oEcAtnP6d9X AFdVbEotcS/aKvnoF3yOiwefdRhkprw8Q8a3vVxEUMsfYrqQ8QCmQ== 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 4gbmuj36r5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:17 +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 6836QEBf020524; Thu, 3 Sep 2026 06:33:16 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4gcbygp73q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:16 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836XCh346727440 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:33:12 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C9302004D; Thu, 3 Sep 2026 06:33:12 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A52620040; Thu, 3 Sep 2026 06:33:04 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:33:04 +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 v12 02/13] cpumask: Introduce cpumask_intersects_and Date: Thu, 3 Sep 2026 12:02:29 +0530 Message-ID: <20260903063240.268775-3-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-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: lsbSYVmPbPrb5YhIw6PAmQVvcjCpVgE- X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX4kGQIsXsSJG2 TZ97qGSpKgz2tIbyE6RlWl8elLmLtXxpeor3r9PmY8CnNXv4yZa0yY6qFChZbVQBklxoFm98/LU /jClNi3fxNEaGm3P2vtioUJ9JoIr77S9zGSdV0H5YSmaLLL2vmUHfUCIlmTMTNzkYFOnbYApipD 2L1eKBr+DAi3FcLTE96CGeNLSeoQkoQXIriUWdSsrHBigKUcFLvF4LwTsO89IFIwo8xQFB3QSZp v3loT3nEm73DEsDHnvP1KpMRU304KbS1iD6b7ZhTeqrvQUVoih2kmaqrxOsjnAilE4jMaAELd98 lSr5PgAkQmVq9/1s6YgUlemafkkpo8644EJuN/LrGU+r5XfMngAkMgR5xlW1oM2Hrhnzqy55gOK l5JdIOsR3mztxLi+xTfnm9+K2bbAq13o8jOfVvQr5vFT/ZC78Bj6WuVvJ/f6U+F7Kawk/jSMvf6 0I5OqYwIfIFa1gxpMzw== X-Authority-Analysis: v=2.4 cv=Osl/DS/t c=1 sm=1 tr=0 ts=6a9914ae cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=Op-pV2-EWUbyySEFqtoA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX750laDqAv6I/ rvUMstuRncKn+ayjeoVTFwAxIzSIQDU/LaSZmN/Hppi7J3jtO0iKmZ5lfXo6p2Co5qgJVfUq9bY QeNx7rhCtkINQunnzlLf5SAaCEIg2bE= X-Proofpoint-ORIG-GUID: uIQJZuOyssVanKqnj-85G0FfCPf4unAs 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 impostorscore=0 phishscore=0 clxscore=1015 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 Content-Type: text/plain; charset="utf-8" Introduce bitmap_intersects_and() to determine whether the intersection of three bitmaps is non-empty. Unlike cpumask_first_and_and(), this returns immediately when an intersecting word is found and does not calculate the first matching bit. Add cpumask_intersects_and() as the corresponding cpumask wrapper. A subsequent patch uses the helper to determine whether a task has a CPU that is present in its affinity mask, the preferred CPU mask, and task possible CPU mask. Suggested-by: Yury Norov Signed-off-by: Shrikanth Hegde --- include/linux/bitmap.h | 14 ++++++++++++++ include/linux/cpumask.h | 18 ++++++++++++++++++ lib/bitmap.c | 17 +++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 7df1573a409c..adafbcf2016b 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -52,6 +52,7 @@ struct device; * bitmap_complement(dst, src, nbits) *dst =3D ~(*src) * bitmap_equal(src1, src2, nbits) Are *src1 and *src2 equal? * bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap? + * bitmap_intersects_and(src1, src2, src3, nbits) Do *src1, *src2 and *sr= c3 overlap? * bitmap_subset(src1, src2, nbits) Is *src1 a subset of *src2? * bitmap_empty(src, nbits) Are all bits zero in *src? * bitmap_full(src, nbits) Are all bits set in *src? @@ -181,6 +182,9 @@ void __bitmap_replace(unsigned long *dst, const unsigned long *mask, unsigned int nbits); bool __bitmap_intersects(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int nbits); +bool __bitmap_intersects_and(const unsigned long *bitmap1, + const unsigned long *bitmap2, + const unsigned long *bitmap3, unsigned int nbits); bool __bitmap_subset(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int nbits); unsigned int __bitmap_weight(const unsigned long *bitmap, unsigned int nbi= ts); @@ -445,6 +449,16 @@ bool bitmap_intersects(const unsigned long *src1, cons= t unsigned long *src2, uns return __bitmap_intersects(src1, src2, nbits); } =20 +static __always_inline +bool bitmap_intersects_and(const unsigned long *src1, const unsigned long = *src2, + const unsigned long *src3, unsigned int nbits) +{ + if (small_const_nbits(nbits)) + return ((*src1 & *src2 & *src3) & BITMAP_LAST_WORD_MASK(nbits)) !=3D 0; + else + return __bitmap_intersects_and(src1, src2, src3, nbits); +} + static __always_inline bool bitmap_subset(const unsigned long *src1, const unsigned long *src2, u= nsigned int nbits) { diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 4c8bb6953107..7c8f16797f94 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -824,6 +824,24 @@ bool cpumask_intersects(const struct cpumask *src1p, c= onst struct cpumask *src2p small_cpumask_bits); } =20 +/** + * cpumask_intersects_and - (*src1p & *src2p & *src3p) !=3D 0 + * @src1p: the first input + * @src2p: the second input + * @src3p: the third input + * + * Return: true if AND of the three cpumasks is non-empty, + * otherwise false + */ +static __always_inline +bool cpumask_intersects_and(const struct cpumask *src1p, + const struct cpumask *src2p, + const struct cpumask *src3p) +{ + return bitmap_intersects_and(cpumask_bits(src1p), cpumask_bits(src2p), + cpumask_bits(src3p), small_cpumask_bits); +} + /** * cpumask_subset - (*src1p & ~*src2p) =3D=3D 0 * @src1p: the first input diff --git a/lib/bitmap.c b/lib/bitmap.c index ed685127a107..d1cb8a507c60 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -308,6 +308,23 @@ bool __bitmap_intersects(const unsigned long *bitmap1, } EXPORT_SYMBOL(__bitmap_intersects); =20 +bool __bitmap_intersects_and(const unsigned long *bitmap1, + const unsigned long *bitmap2, + const unsigned long *bitmap3, unsigned int bits) +{ + unsigned int k, lim =3D bits / BITS_PER_LONG; + + for (k =3D 0; k < lim; ++k) + if (bitmap1[k] & bitmap2[k] & bitmap3[k]) + return true; + + if (bits % BITS_PER_LONG) + if ((bitmap1[k] & bitmap2[k] & bitmap3[k]) & BITMAP_LAST_WORD_MASK(bits)) + return true; + return false; +} +EXPORT_SYMBOL(__bitmap_intersects_and); + bool __bitmap_subset(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int bits) { --=20 2.52.0 From nobody Sat Sep 26 08:37:18 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 EF4D73F5BD7; Thu, 3 Sep 2026 06:33:50 +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=1788417234; cv=none; b=Yy9N5RIt3VPhQxDi9bslKbQ54RR/LGiVrVBpM2XkPFnbL5w5VZhoXdLyuPEWt3qKAlYZR0OhtEYZ+s3y8D6j1DsytR2tc763zseSaYBbQC/2ySJWnPTEkP+kJpY0D2VODSpU6ZDY+2v2r8khqeTeMT1tXB2SQP4sL1BGC5mdx9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417234; c=relaxed/simple; bh=scynNHLZntdnjgSa6fiT0L6du/g5ELrDcNjAOoQ0xrY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CWyaoYbdH1LhMrVtxhi3ZuuKqJ8cuBRW1lqluPmGvGCA54kENyGMfP7Vp9gbFVuo6A2ZsghGnCDxun6V472PvWmVxvBTgICex9B/dK8cJc3hDbe0VCpRtdYnAS3MBeWjVnhttHTpDkvCLoujbiGR2a8tMp1GIAiF92HkZjvyr3I= 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=DcnX7sr0; 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="DcnX7sr0" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68361uSI312168; Thu, 3 Sep 2026 06:33:27 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=OpXDqA4IrF6tYgvzL FsuOPdgMFXuHYqIjNNRmFkAhO4=; b=DcnX7sr0bdeawRpLJZ8ktrrukKt60sXcP /8EaWMNZkZpheMQ8UOi4HXnU0yesqHHExUVgkRL6IDCtoXlYI87fMemCIOQ3GU3M CRaPNv8f8P0su5NMhxdDKHqC0jW6r7GrxZUV3pNH9Zto4pSSmmbGNftKfrGFb95q Os+E59ekU8n+GgVgzZto8ZIttV7bPsViRRINciE/8bEMtA5h8u881VTRMQlFGoWP lTgj8hNXbGk/p1NWtkcwea674kh2/8j0muQci5xytChAObO5rCq3x8fs+7DMRocD 4FymrQOQLdImS7QCgF6ba6Dp8P4zBIbVX21Igotm5c1ySNKa0gQJQ== 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 4gbq3rkdhc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:26 +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 6836QGck002978; Thu, 3 Sep 2026 06:33:25 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gecjaprb1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:25 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836XLDS30671494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:33:21 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 576362004B; Thu, 3 Sep 2026 06:33:21 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0C42820040; Thu, 3 Sep 2026 06:33:13 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:33:12 +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 v12 03/13] sched/docs: Document cpu_preferred_mask and Preferred CPU concept Date: Thu, 3 Sep 2026 12:02:30 +0530 Message-ID: <20260903063240.268775-4-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-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=EIc2FVZC c=1 sm=1 tr=0 ts=6a9914b7 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=2BnLtqgf9UOq1ijo76cA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX5khyQ5ytna0l kIubaaA66w9Y4V5iPckpEi8vZdq+pArcdkt9nQLAguotIM6JBQwU92divjWxlyIOnQBpSIwSpCx 5E4nnf4n5Xl3j5gdnEJUCDKmxhkopW8q9DdU6nYJBQtaXtRnqfcurRh0QUU5p3T0ci+zSbtZJ7c JSiHqAV0wTFZH8nD9SLegkznGc4J0ngL2DS2L6wIZbVeNxR4kkXnaRAo6rHQ/80dIZ9FPPnixOm 2Xq+ocgA9Sbp6c1OBsL74VpcEoptztr3K9WbRJSeTaP2s7TBV7UKovR69ER2Edu4+dRLfwjVlD7 Gw7NaCbBuZgh8urbUq1ekymr+mRFJrh9JLMIv1XuZFBwjl0x2KrdOg8W31OcpDwXoEeSaxMR/Zp 29dOZLFHzTYSZLrXp1SvemhxOFr9OuUEpcJCuJ70zHZ3rjA6aZig+uEKlQMPHB4YmNkmF6cwwZ7 Cqb76oGZpRmpqezUYWg== X-Proofpoint-GUID: srczto0zDuxKQ58XLIX9KTVJkcUU9Ytb X-Proofpoint-ORIG-GUID: bzzX3l-vM0wJQsJDWBFMf0DeDRlAAf2s X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX7EFCvkNzG6q/ 0IgRRFB/0BrVg1SYdo2Yt5zJA8JzDmFwFoXLGQTOSNM2fWCCscQOllYSWSy5sXOdOZ5YRwXT+wt mpifvNa2GURPcFmmHHxwgBofWTKedxw= 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 phishscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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.52.0 From nobody Sat Sep 26 08:37:18 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 C1A8E3F1ABD; Thu, 3 Sep 2026 06:34:05 +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=1788417251; cv=none; b=kOXViiS5Ke4HyDrONH+fPdcWJr85qQ/JrexMNGvuvsj+i7YLdil4cbtbRAixlaYBwGQe9AzxLDOsVEBiyYtCF9woV4yCc7b4ug4k1snf83RdFUDWAFTID5Ogo5HZtLpdXy4h8LNG58UK+Xaff/20L/lxJoQh+08uMcEzDTpasUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417251; c=relaxed/simple; bh=97yJ0THLB4cf6SqyTlFhdn7NOun/2YQV++5NA2pinEc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TcFATfkJEBSNgbRqOXjf8IGlpLAw46EKd+kVFL2U4z6PsIBV0WUjKwiyW33wiQpaU6AOlZ37jhOfPRe9p5ht/o4lUp4MGv5oTe4fzZZqTMvl98acRMgqzj97BVIQ3DX/w4F2Z7GR+v4Kmf1iIUvu3cBBnDjcQcYj/YMRq0nAQMI= 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=qmQdfL8r; 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="qmQdfL8r" 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 68361R062187826; Thu, 3 Sep 2026 06:33:36 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=nUq4ue THD/OEH31225VtVI5W8hjEc/+402p4LxaJaHc=; b=qmQdfL8rTNKrvytL5fkhl3 odLFItYOSru5U8OcDXwjnMajCPKEfIoGuRm9N9jYhYEMq1m3OYkE0eD2TW6h5EB/ 1jnHFme7J1QEYgHxP2oKgA77b/Wsp9UwiLlIRHUMgVtGmqPSSb4cGaf6e6eXCo3I iZl65KCZrBdTq4qDRp/+CaoA9LGKOz9QrYmI1tYZX7oSF+L7T04yyVfx2zYMsYo3 ef0NkSAU2WDXpKOqNSjMKz7cF3kAxNyE2aIARqrwpAvo9n99cmFarWT7OzS4xXVX QgaejDMs146A+hif2+jZzTR5jjX+gk7TXy3LLIWUF9nmcqpqZkOM3z3l8lqZ0NVQ == 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 4gbpx5udac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:35 +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 6836QMo7003031; Thu, 3 Sep 2026 06:33:34 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gecjaprb9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:34 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836XUPD51380500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:33:30 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 18B5520043; Thu, 3 Sep 2026 06:33:30 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B9CAA20040; Thu, 3 Sep 2026 06:33:21 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:33:21 +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 v12 04/13] cpumask: Introduce cpu_preferred_mask Date: Thu, 3 Sep 2026 12:02:31 +0530 Message-ID: <20260903063240.268775-5-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=PPc/P/qC c=1 sm=1 tr=0 ts=6a9914c0 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=NEAV23lmAAAA:8 a=VnNF1IyMAAAA:8 a=LLUen9C-ZHFwCquRYTkA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-GUID: wfkPrL5O0k4eMdWtB4rJYlKfFeiUVuWZ X-Proofpoint-ORIG-GUID: aT0ZW2IRkBPDiV6tMXTa4lpT-4irK_Uq X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfXx00cLt0jHqwL RqFVOK1rcmdX7cosP0eMC9/2Hy7qFxD2Ne8et2+z0RV29ikdxM8wAbltTF37vTqVJm/YhLpC/zz ZSnu84Z5C4fo0aIJRNAMZDCTpefxcko= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfXx0ACmEkuoJX4 wA5XvfKNARYp/+TwIrAr3T2sJi8HUMMbx/M0IJxZdDgxxPaMBFowsWGpSbCjC3UcnuXrIIxLwux wT66Ly3U/MB/qNkWJCKT0l8zg6OM4S2P3A4vklRfPk1K3y4S2T41dMMGtGqlYcG1qjc/uiv6yWF Jd7vfx6dnMN2b80tBkqBP+zNSXpEPc+Buu1ZTZSTyq5zURq3w5l743OcMo/w3RX1PbbMKoa7rRo GoGhisCVbwtfmAE2uNx50uR95uqxZlxYBHS+RqTYscmYeoHVqnD5yxV4V1aUOJtzA1kuWYKjjMQ +I7ITxpZL5yyvyc19EsO88D3+t+gB3PRW0k6fXOS3H7VL+Z4EB9x6V3Gmbco3k8eTJYinRFrN6i ql+GOSuTKu5VQFgu9f39u9a0aP+3/MfbuWbpFS2WRYIbJ/jS+z9WrPEodYWB0LVUhWV/Z29UadJ jin0TVeD57Ld5QMYVVg== 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 bulkscore=0 spamscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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 7c8f16797f94..bf89bb3f30f6 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -121,12 +121,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; @@ -1181,6 +1189,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 @@ -1275,6 +1289,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 @@ -1313,6 +1332,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 985aea617cfe..edc067a0c422 100644 --- a/kernel/Kconfig.preempt +++ b/kernel/Kconfig.preempt @@ -194,3 +194,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 5a61650f12b7..a689a0cea4eb 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8582,6 +8582,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 @@ -8595,6 +8598,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.52.0 From nobody Sat Sep 26 08:37:18 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 8A5473F4854; Thu, 3 Sep 2026 06:34:14 +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=1788417256; cv=none; b=mGJvnPlUYVNo8gI1MeLRnzHBIKQ6ASSSRfmQI9EeT+iy890CnG+tr+uHrB/IEbQw6+2w5VZCnzW71vreWVeGNEA8IN4p5UbDpNuJGnrNf8k+0zNVW8lczmVzp7l5/oJ8kGVKlHDS0eyIOusJC7PAd2jXTuy0owQQ1zqgAPuf1LE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417256; c=relaxed/simple; bh=KRcnPZxJ3TxjYbvZ/ffwiydMHYyd7oDraGjHWCGvvcs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mQM5tEGGdMs4amPZ1fzrouPM6T95DCd42iV2MXRYUEUil/YVRGB45OrAVGdGYiohy98fon2yDRjv4MvZvbQCMCIDsABVPGAI3Da4Wr517wSjSOGBI8LVo53Cib4bBJn/noAukGTG/h0IhO4CuefAwiv0TEK1BlheTQwu1Uamvc0= 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=Re/C+6Q8; 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="Re/C+6Q8" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68361RRD2186402; Thu, 3 Sep 2026 06:33:44 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=zmk93sQzf03EanZhV Bee2OYiiS4IEVygsO5Vm1CSPyc=; b=Re/C+6Q8WNaPa24naZlzI5B4M7fC/Ja6e dBv8U7AaUgKu+Z/TfTyR31SzuI2e95LGHXSHSAu2WpG3pDcuICCwTDieuJ92vOYF uH5rVOhVWBtiwUK3vWO7+dM0A/rOFGTF2x/OOzVvrr9FbSRbqVntI4lLpy+KtNtB 8KMLUPLHuHI+SRHlJANoJytm+3dSyD2LgIJswwma9G32KrjjLhR82TaKQ87lhu2i 6isy3DnbaI9Q81/zf7eGYupJrpUehNH4EmJCIkR/G5WqvPavv8MMtkkdMpfLqOFy SEF88ZFMH8bzEuKRbSwRQQhOKnKjj7CGog/75eyt8WSaa4jHgFhTA== 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 4gbq553fcb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:43 +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 6836QL1v009538; Thu, 3 Sep 2026 06:33:42 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4gcceye61c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:42 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836XcSJ48759252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:33:39 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2BE420043; Thu, 3 Sep 2026 06:33:38 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7B91820040; Thu, 3 Sep 2026 06:33:30 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:33: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 v12 05/13] sysfs: Add preferred CPU file Date: Thu, 3 Sep 2026 12:02:32 +0530 Message-ID: <20260903063240.268775-6-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX5kLtQsPMI8yn cMuuODvQwhL9RsAXQLQc1zOkjIwVsokJ66GEaM+8iaSmfIdXmAVzRxP+0f1ROSzmFAVkgwFTt9Q 03/DLEVcxu3xWI9RXU/EgZ2qAsx7zH1oA22pnIKxrVFdeao7E8B1kzilTY/RtLPo6X6616M5UYF kSNf/7yJpHAODnj/Nm6TUnJ2VyEzeUfGQM2Qss668kjnr27n00A1XRJA58x9h5E/r22KoPTB1mB E9VAu2KOWLfv3UNDxm7vx8GnNBpRsfPkdEOIsNYVHuZqnpp9XwLUC5P5wW2XhMXJsx/xM15/ejT i3HY7Q/WCcjp9mxSabWLzEKF8czArofFDePXTJWFgA0iAQKwNTDAxBeSS+brejNn9g1GBIixNxx vBx6413nqnrW9Gd3TKmqAZ3MRFDuK17j0kWBHy5fVPqgFkH8TDn1hxLlow1UFzF1T6IbBOfuvf3 Ukr6jgdjl0bGAdsBZRQ== X-Proofpoint-ORIG-GUID: nzvIYDW2euOOE5HIZDo3qhnC_PGk_VRs X-Authority-Analysis: v=2.4 cv=CNgamxrD c=1 sm=1 tr=0 ts=6a9914c8 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=VwQbUJbxAAAA:8 a=94fVmjRkuoLjN79_KVgA:9 X-Proofpoint-GUID: qKhVofSj-YCpys3f_KC3-a1DgfgihM7N X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX7WxTtjI3ksIs BJNC5Fo91kO9B+raIrWGZwW36+7fyQ2ihRzdXFEwNsWL5pJA+n9VOc8o3tFrlJs3W3XvGfuEwsv wRzxF/LkVEh7X/UOGdfPOGfdVd8bJrA= 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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..8f250b8693b8 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: Sep 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 69e52fed4241..747915ff974f 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.52.0 From nobody Sat Sep 26 08:37:18 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 A78F73FB7C1; Thu, 3 Sep 2026 06:34:22 +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=1788417266; cv=none; b=Q3sELnwGIahwYp+eYL6uN9uc2Jn96pQuFdY4/dzms8VlrK3Mac1ZZ04UFSO18QdhyxCNgxDlDr+mWF++X6DXogNrt41Iw/naAvbwSM3WtuQBYWtpHNZfQ6JVEV9r3KO0UsFkekz9ngNSQtjNEGPZTkjJpe0hd+7D1cBTy98H9iE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417266; c=relaxed/simple; bh=pcimYOOL6+P+IW6Ux7ERwm14/LNW4GEhMJ81/gPpXUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WXs/QEgf8y/t0tdU9MV02WmT+lyNFyij68C+01JWxDDRLA+zr7Z4/2wwqruAhb9ANW4leUttGYpK6Kz7dNljF2zW4i+IAEnGkA8uScnwAoSeOJbQjFyb+L+1C5blHv5gtZNy79zgN7UZa+1JmxDD2tPWa+nkMp4nxC5iEYo20t0= 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=Z4n8u6nW; 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="Z4n8u6nW" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 683620pX312347; Thu, 3 Sep 2026 06:33:54 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=yzjj3BRODohMppU0o Q0SJfycz1Tb29sNFQoAAx+sX5c=; b=Z4n8u6nWEPFtPL6yMq1ku5B6uUYDGdMKx BbX2yPQfy8exVrRrGsO/HbY840RdONH/RVtla5zRxPVkldg20tLwD70eWtXF0r2+ 2iTBynna4fs0ABqMd6wuwnJyzCZhnh+Wmmojh6rIw4iSItaB+r8ouZusAglESZLJ A8CjV4xnqOGw+QSF9NBL+U2TyOBNLnX9Gde0S2D2aKuJMqDUtTvNrP/9TF4xkw/5 Qu8ctHXXGl9qi1EqAaJBYi/pJppmjBHpoFxb6kPXfPWn70kkKgQCu1ef13AhaCSu 3ii3f+Yeq2qx6m3ujtHTIB57Hgs/Rl/dTbB2BHAQaca2Lu2dvNK1w== 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 4gbq3rkdk6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:53 +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 6836QIAx023970; Thu, 3 Sep 2026 06:33:51 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gcarkecms-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:33:51 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836Xl9Y47907222 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:33:47 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9301420040; Thu, 3 Sep 2026 06:33:47 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 47E7620043; Thu, 3 Sep 2026 06:33:39 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:33: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 v12 06/13] sched/core: Try to use a preferred CPU in is_cpu_allowed Date: Thu, 3 Sep 2026 12:02:33 +0530 Message-ID: <20260903063240.268775-7-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-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=EIc2FVZC c=1 sm=1 tr=0 ts=6a9914d1 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=xlrYe_syFdJcAglVzgYA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX0K+8roSpB6GY h4+CzEIIoI/swSXJbFYJTi/Big4uBxe4BjScwyrhjycRhEd+6JazS0/IwNhsL0knFsGQ0nRIx/G GkfMFOQa06g0VM+aFxbljAUGp/4ZN49HhMHARpgekFuK+SPcpfLKqSwNkZSfIX2VDVf0aSc4/d1 Cfk2uY7zyD6+U+8c3zdWAG+Okj0oOpDkcZeJqB/c80LrPy6NS/6ALlJ9d3qPQ0ac21v0N+uF8ci /K/Q82kLUbZupeqFzfG6bK9muGv1e9VAtO7Q7tzQrXmRRtJqwzxJAwBGPuHuOJRtdHkP6IzdoQc p7kP/OrpbNREnuutRhWNeZHACQKs2xMSibGsnJQn3OKFuzzHQAmb8fFRSaRU8soknYhUZzYSlVg fLZV2WcFDWHfvDCyoZGPishdUjpKtoItHu1ADl0DEqecO7IUKCTjGX94dYS3BVpdGoIQDAFATFf qWmJ0PHhg+3hlUKJ8Hg== X-Proofpoint-GUID: 3PrdV094Hj3wTgsBZQAeX-dPsFCX_Sho X-Proofpoint-ORIG-GUID: cyc1EFtu42axnfdpbpz0C8OPyEgUL55r X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfXyw3kIn/HkVMV 5rZMbx6wBaVHfIacecSVvblGpJKfJQqtgRhkK7KPv/DP8b7XW+qt5F2XfzfiJBC9pCzzScaNI8W SsYKMUMmt57Qx+HWkoJnZ35YexChHIk= 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 phishscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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, cpu_preferred_mask and task possible CPUs intersect or not. If yes, then the task has other preferred CPUs. This takes care of tasks with architecture-specific CPU masks (e.g., 32-bit tasks on arm64). 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. For the majority of cases, this would still keep select_fallback_rq() as O(N). cpumask_intersects_and(), 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 | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a689a0cea4eb..b4ef2e92d786 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2504,6 +2504,23 @@ 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) +{ + 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; + + return cpumask_intersects_and(p->cpus_ptr, cpu_preferred_mask, + task_cpu_possible_mask(p)); +} + /* * Per-CPU kthreads are allowed to run on !active && online CPUs, see * __set_cpus_allowed_ptr() and select_fallback_rq(). @@ -2519,8 +2536,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)) @@ -2530,7 +2551,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.52.0 From nobody Sat Sep 26 08:37:18 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 499053F328F; Thu, 3 Sep 2026 06:34:30 +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=1788417274; cv=none; b=pYYD4znZBHycy7+BBCPhmz0nmhkG66W0NQQpHuzwgHsKJ6a8I6khDe+Ed+lV4ihYMxjCp4vIgR4MTpCrgmIDAnQW1HFAUBqdcclnd++XAbU3pUb6UZVQTypbF5ng4WZOdrsn2YSmYeGpjENLbIQdH5q+INWxBY1lZUSe6zAM6ZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417274; c=relaxed/simple; bh=A3ybtl3ykEgjMXQnq1OCQh0jcPITN2wyvRS4IGfAezQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T4HkNJeSYTF1XkZwjhbSplooF1ZXncoKmbTViY0GDDriyGBoBCALAm+1xvBgMFVZolTOvRbYR0cLmShEz5vcrNeIYztekp3utJPQTJUMFwSG4oESXIGOme6s32iJj42ype0eH65s/OUIel/U9YEh7lCWVtLKAc/j0vXnCTnCk9I= 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=chU8I+m/; 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="chU8I+m/" 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 68361R0T2187828; Thu, 3 Sep 2026 06:34:02 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=fnfT0ivtkk+EP4Gna 2l5cIIl//9yLKT11aDYfbke8ao=; b=chU8I+m/oT3uOXvPHQQYtXSA+K7se/2r1 yT3vIYEPKjtGUPtq+kZc1YUVgfUzdxNHBqc1hg6vg7xwaIbcsYcgu7gaBJYvtLaE r7Iw0Z1vm5DPTvc93VausAuBqzqwnigdgPHOzT2+YlIT/wgJp3gItkxl0wEJ4cVP 7CQ3kWsFra1rrsu3Q/6bmGMRFj0XlFK/rp3328XSPQMtmKXGnLHWx6sc6gNB/MnV 2KYL/5CLQA2qgDGNXOqXaCM/SGthpwDcCYs2k5gPg5tsX0r0OzvdNjoe78VeZrjm FouLNdM4iFzMVH5ZSrlqJX6guFYSm6B6ZDil7naA6WLIzAk/CsO9g== 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 4gbpx5udcf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:01 +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 6836QFuH006172; Thu, 3 Sep 2026 06:34:00 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gcb8hpa16-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:00 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836XuZV14418278 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:33:56 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 548F820043; Thu, 3 Sep 2026 06:33:56 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 04E6C20040; Thu, 3 Sep 2026 06:33:48 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:33:47 +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 v12 07/13] sched/fair: Load balance only among preferred CPUs Date: Thu, 3 Sep 2026 12:02:34 +0530 Message-ID: <20260903063240.268775-8-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-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=PPc/P/qC c=1 sm=1 tr=0 ts=6a9914da cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=f1WSfB00kwmd_FHdG74A:9 X-Proofpoint-GUID: A_aLlRxNqqJKFZk8ZjDE4qEVSCAZmL8Q X-Proofpoint-ORIG-GUID: CcMkAZ7OGpvib_7vR4mubDeP7P8aDZQi X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX7pBP59vXCAbs 6bQVTQdnwqo6ibiuwlSnxRUvPwtU0vpZ2Fm8KE4XhvSL1+ylykMB5j2ZYmbh7TZ/r/wDzflt2fM hfsewhv99/LibUr94Qnzpj32sgiX3a4= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfXzGVlE+ZkNKcx GsVgrdbbCmUFC54Zaw4aFffm+rKF6ksA9XjjNvkeVqspt9afFRuZa1c/oEKknSEzWVoNn3iPuif rBLgR+V3LAxVuTJaM7K7dUYIjpeYcJ/h1p+Lr77pn64FpWxNfObIvG5pf0dlk8G6aG7ZiSpPdAy 2YV+lhID+/rD8AyDhiq+hZPXmRXaGJIB3AadRE4vJvSIEgWFDnoj8B/K9oFsg1ioHWDDU2H4Xf7 hkvCdrKBw/8ITh7+ekRg88tNHpHpbE1vXnKiLlB6kGKM5YnZHdp3/XhnY54u4FPTPcnBJpmIGLC bFwk7j34zCiJmUSIHBO448qMLRBOfDhJWgri6W6Y0ZHpKVBk/b4RsW9ruThXYVUWaq2zLL/q4P+ BQmbx8Aj+33aHVm35ADSmspuudQkZtkmKdSRuiqhowQa3LKELKUsK5V/CaA3WPfQTgSo4+5+GTR Q46W9ksJ/VM3cxawOOQ== 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 bulkscore=0 spamscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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 b8bd308c2d5b..4ef1167b8c73 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -13473,7 +13473,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 @@ -14588,10 +14588,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.52.0 From nobody Sat Sep 26 08:37:18 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 7F24B3FDBEA; Thu, 3 Sep 2026 06:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417278; cv=none; b=l4Frm4Z/m+lf7eBpoQsWN1/8rBJ4SKrHJvJ9dM7WNwA9H3a94uUtxuq7uY9yR57YsnAnKvdEK6LgMrxqB66ZIaJl8+zMBDocITQLKX+vuzfI2LvMHZOphYbRxQmymuR+vKLYjyvwpa/4UqMKv7mXA8coXLutlUenIYNyadQ2BF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417278; c=relaxed/simple; bh=FFIqL1vOC52cOedJ/mLnt9LwToWuxsqC0oOXPpdNguw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=teIDc1+34Os60Q39xb14qQeAP3oybYrPWeTKJSEHI2itL2yy13b/7VvroL2FcTu3w9f96q4ipUkA+tcL6X3d/nt9WGh8B+iksFM/vn1U2CuUW+g4T+dsBlsyEXwAksllOWnzxwdB5cAmy4VhiiW1CoRcpyR/ByIwyaekPRd0IY8= 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=Cujb5GZA; 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="Cujb5GZA" 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 68361W022239205; Thu, 3 Sep 2026 06:34:12 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=XRkH9dkKGaFlD5hLq brlIRfogZ6fqIq/djjbF/YKrTg=; b=Cujb5GZALG02cO7yQjVDD8+8InvDVPDaD gmVRFPsvodLS4LII8xi10mP9cGuWFMqbCqqbbi2ub69bO+TzJp7rfrLxkTXFWL9D a5WqIqvUidzMJoRl3poyYrvr+fWRMfygW/349/XG26cup+jJGvRq5hA+pdQVa4am P4j1GBt3SBANAuLBwCm/ASjkl8wDxNJPornhG2p9LDayJpHR0gKO9izKA6cArH6i yMsINUd73/cFn4FLVre4VtKsxohPQDXhNFaz8xgAdUvANQ8BQ121+ITys43BCISi /lX4sR7sDVVYVp7N10X6YD/SlnaTcLQoFah7eyTHZPLM5KUs8U6og== 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 4gbq2tjutb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:11 +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 6836QL9u020580; Thu, 3 Sep 2026 06:34:10 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4gcbygp76f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:10 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836Y50I38928654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:34:05 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1299920043; Thu, 3 Sep 2026 06:34:05 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BC1ED20040; Thu, 3 Sep 2026 06:33:56 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:33:56 +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 v12 08/13] sched/core: Push current task from non preferred CPU Date: Thu, 3 Sep 2026 12:02:35 +0530 Message-ID: <20260903063240.268775-9-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-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=bc1bluPB c=1 sm=1 tr=0 ts=6a9914e4 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=rPhwLmmYJdnLsqmuV48A:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX97SmqsMXlZcC i2JBzum/vfbgIAZio0UFmPv/rnXeathvZ+zQFjs4+z6s6dcpSHqCJ/dQWFopyny8IT2b/0uyAr2 DGFPMpkRg9EF7fh9HeN2CmqUXszkZ20= X-Proofpoint-ORIG-GUID: Y9NIcWc22nZjlIX4fZ9GtK4OmzppeqmM X-Proofpoint-GUID: pwXKtR2Q5Kp7zlUrb-sx_HLIqfMcdu8Z X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX9WAEfX+LbSRB Z/qOSxFTrrTxsEzpYlf05DJJIrTW+hZdzc9ub3JNBfBMnfpojPlWavQSxlACnhfruFc5HKpfDDM ezviasbRHD47mZQ4n7FtZYLIWx6TgD2NUnIuD0fBY0ePxpb1l2TFLMMCb5oI668UHgP1Bt8isqP U/CyWEVK57Frz3JIqRpenJ4YGsJUA0vzXqaPAa8UOh4XqQoFbFPFaR1rlhEHaRygkLBKbI1Qhab d6h4CloSoUceA1ghBQdWNx84G1+Ik1adgL0mOpUcLjVSaPZsebZK5SFyM317vY7eapXlYPN8pdm vhxgJtn15Vcy41KGHWUrVa9QjCBt60AmcDOUzszIbqDQOWHp26BYTmr7Lk7+o1HswpKUl2rk5VS h7V6LVHZPzJGEij5ykm1sw5nAwu7MmoSldxyvVsGsX5UPWlfeK47tqYZ7OcYhGQZSspEKCFMaFt XP/kAKZzFNofK/jORUA== 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 suspectscore=0 adultscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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 b4ef2e92d786..35e7eedad104 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5808,6 +5808,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 @@ -11202,3 +11205,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 6c3ad70e58b8..678e44134acf 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1298,6 +1298,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 @@ -4280,4 +4282,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.52.0 From nobody Sat Sep 26 08:37:18 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 B173138655D; Thu, 3 Sep 2026 06:34:46 +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=1788417289; cv=none; b=AoFL6c7pnSc3a0krfQxNtiibJ5BpnS2xvLJh5EcCLSuhKq3988+rCRj0a4SopAw6UP730fTEUoiQWrYNuJjgzXu+EtSzN4Xmr0UBCY1eeG4+RhuaJjdHeeIBQeTejZIIQn0VJbqJRWAPYilQdLWm62ItQiAjW8/U45wKdl6EXvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417289; c=relaxed/simple; bh=vaYkKX+K8VFBybyZ3Yw8MnZeRfIljiPPd8tL1kriR9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V0cIjrRGNoEAm0v/SdVAd+s585Km3Ra/Nrs40FCzpO+W4PYBBasWSEyUeiUIemEendsDaCWHQt1z/ynDUjA6tdNUg0id1ObovES7hWcvHg1rUpnwsY02nw7GFIrCAshXd5GaCwp+Rmitc65pRdImKc/BbTt+0v5adi7ni1XWjTI= 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=TuGFiQ09; 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="TuGFiQ09" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 683620pZ312347; Thu, 3 Sep 2026 06:34:20 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=vUDbHBzfcYOv0qi67 s84ZrLezq9BmZO9KCq/jLGQ6Es=; b=TuGFiQ09EIfkNNt42rCcFLkU41xEHB/GA M/jnS61K3s5MYzgSECNmo1uHDfTroTnAUGGppf65q18xdTgSG/0CbBHqGisncx1N k8xiLnYXdkHA1dbWZx3qsn69OYpOdR39mm2XmbsaYZ7Q/rQg2fMr91ZdNp6UEl+i UBSmJRTIL0d1w0bMRFumacRwZPqDfVgSSVBorM/YX40FxlbWnKJNTLU4cXGm3Sgy 1qto3m6fOfJ8q5n6/qUADrNLTCZaLUfjENewKtUlV1+t+gilF4TFZqy365AvivKE sDkBQifQXVCkFC9fbOr0pmUgE6bOLNw5RT+tEdYjr81posFnFcH6g== 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 4gbq3rkdmu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:19 +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 6836QHSu006191; Thu, 3 Sep 2026 06:34:17 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gcb8hpa21-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:17 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836YDg439190840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:34:14 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C67C120040; Thu, 3 Sep 2026 06:34:13 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 783A22004B; Thu, 3 Sep 2026 06:34:05 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:34:05 +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 v12 09/13] sched/debug: Add migration stats due to non preferred CPUs Date: Thu, 3 Sep 2026 12:02:36 +0530 Message-ID: <20260903063240.268775-10-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-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=EIc2FVZC c=1 sm=1 tr=0 ts=6a9914ec cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=tZLFZcUqokv_Co2pBPUA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX8hD5P2BU39Rh aW/WvxEnSa91HNRXC6v1RS1uP1obwE8ywPQGcbvWwBV9Jjj1NPSo9Ivi4tGkyDcgai0d7bO7EII a8Jg9onoLpr9JER9KTlRPmd6ikCxOo8IaGcpPeFMcs+ZxnXoru7+5wipz3t/q/jlPGWmLsUFqWF SQUu6TZIsL90ONIJaBmNux+CluoqkyW8W22lh7DIUXpDYxES5/Hf3TEKFHiWEujWXwn+u42cENs nAtuklG/EWFwXZOwYaAMwZJN0zOfVZcBUaEIktZ+RWA15OaZ3Zue2502+r5tkd6CFvEoi5eCkRO i82fqfiE7cjUr7Sxp/KuJJvVJP+RrBahKIB8biiIzuj4acX1C9DXUWKaSxiLgDioHvI3mHHbjh0 v6ANHJTpQ/zJtOLDpZQdZvVkWM/tYpwoFslANfX6+auCDo+poVzvKWICmrIkFkq0gm/KgmDri5I fhFg3bdGvaERX6Qu39Q== X-Proofpoint-GUID: XgbEPRi2WnUmHjVVaEaOfljsvZEsVPE3 X-Proofpoint-ORIG-GUID: 2vj7drW60NxyzUUQwajx0Bk4wUIvqkAb X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfXxQJ3fqak60Fy J8KeGDvvmN8jwuGTjmKvQwI+9GnX5s4XBBB5NUzLkSBL414qb/ljt6uWVyTXv+smls5ddVWZOm9 xy/M42kbB7NKQhRxLORj1JjubgWYd+o= 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 phishscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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 d7cc77181ef9..48639b0c75d0 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 35e7eedad104..f32e9fc47b68 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11234,8 +11234,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 fda10b3fa249..e6a3b516c703 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -1440,6 +1440,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.52.0 From nobody Sat Sep 26 08:37:18 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 C212140099A; Thu, 3 Sep 2026 06:34: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=1788417297; cv=none; b=mAVN4SLxcwjWJSV7UpoAQkqwRnF9DcVvwcVvAPuC87dWyqLfEDWN98/EDAJ/WQG2G1ZkTRs3VKk3hpm4Z5Jua3W/fKa+FWVgENCmXxR93E4jmifhU8uSs7grirh3Bh9cTP4Cb/JURBzUWrcxi4wIE+DvDJKdDI8nJW/np6unvtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417297; c=relaxed/simple; bh=l9+99tf8RNjIHISS+hxOaqQhAJbCQld1Wms+utTD9rI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jCtmyRkkVqXH6FMgY2ALxE7n0K8eYLxZPebz9o4RyuzTiRZOSowTQt2UpuIQINADCsBZj9sGZkeSsimu/+s4XHQmKrqpw6hQZnfTWJFVgzwIl0WJWoSp7WpLQ4cnS4X80mRto7+mKm6L6VuBg6dmMTsbKQK/QLF3gHpka4AJIcc= 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=dZik74tn; 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="dZik74tn" 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 68361nS01056281; Thu, 3 Sep 2026 06:34:28 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=St2tA2rUN1w6k3rd6 Epsa1ZO9gDtub00GkTw5kZ3n1g=; b=dZik74tn5Oi5ZvtaU6eRyct7lqT8IFi3l o1vdYqqRVtsWyqNbuvo1D2EzSI8cEp+gvXxGR6PEVHSyKoiTSNEcjV/I4cwtom3v BHSN6CEWP2ebK1ILwh7dvWupFi8DXBVWZF63GxC6094Rymx1GR8qpua4kCzt1dC+ UEiQqytxliaKDVD5ehJlH5G8NvQ2yqVVzmZ8r1CGaMve3/tqJ9a2c+X0FZaJr1F1 OCCmeHFhRqTmZqhGjeawZ8FOEQjE2T/4yymwR4KFbekU6xQX0u3hGSLk9x6thWkK 8CFT0W7cvHWRte9Q+UXeMF7htVMhtqdvTiQGOmIExszJjfFh5GtLQ== 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 4gbnue32m6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:27 +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 6836QEi4002969; Thu, 3 Sep 2026 06:34:26 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gecjaprej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:26 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836YM4249021220 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:34:22 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 82C1720043; Thu, 3 Sep 2026 06:34:22 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 35D1420040; Thu, 3 Sep 2026 06:34:14 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:34:13 +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 v12 10/13] virt: Introduce steal governor driver Date: Thu, 3 Sep 2026 12:02:37 +0530 Message-ID: <20260903063240.268775-11-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-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: B8ynYomqqR5asI5MXNR2BJVxZdWAGDfa X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfXyRbKIrZ+Qppy 8NOKZjxIbH8iiK3FxQsboqRrfOWyQSZm+44WrYGg2sNFKkctOSCb0u+FK0MiDQK5Kaepqj4cBTX y5CnB0dMoTeGpB03oOnlR/p9Jrn101qzsMapX3W2xqSBKEjXMIhALcPJlYbKtNB6IzGfxuFpBxA N5xKFh2ko+Mfu3gEx4zyyiGqqctUC2pIIMo8GNg2HO9zN6af6BmabIcFKyCZfS0cJmj0T3vOBqj T4xvxcyoK33dFS9iEDuFUH3NxTwAuxhuv4NS+akQWAZDmsLaxDEhJxSwkYrNoCrYUwYGNqRMJqj FV8DyFX2kn35SecizeMckslI6JgqiaGhuX8TVc2f40cWrgJDzgsHsIg456V6Q9gcyUb5E2OSClJ H/K6M7Lh5RlxL+FcDaJ/aoFgCM9qR4owMAfxMNtpHGhHLk66SKGOxihaYSvbLH3/h2+ASSoKoXv WxcPCGZ6yGtoMRRlRAg== X-Proofpoint-ORIG-GUID: GIX7wCyfoZO-JFAccOnKO7CQcuZZNqjm X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX8vTHDX7oq1zp WJ/guMl0H3SecAxqysCrOQbv1D+sQiXzLeUYT3HjdWBcG/TqbIcbUeTQdYLeG2vqomNKMPduLBB JpgDuodmYR9u4gyYmQNRCbWDYt8yJ9Y= X-Authority-Analysis: v=2.4 cv=B92JFutM c=1 sm=1 tr=0 ts=6a9914f4 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h: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-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 clxscore=1015 suspectscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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 6601a258690f..26b7638a327d 100644 --- a/Documentation/driver-api/index.rst +++ b/Documentation/driver-api/index.rst @@ -139,6 +139,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 3a19da74d00c..28003d36b3f7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26223,6 +26223,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.52.0 From nobody Sat Sep 26 08:37:18 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 2300040245F; Thu, 3 Sep 2026 06:34:57 +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=1788417301; cv=none; b=iT8xHvd3cgqporMUlvOIE7JwGiQspaANLwbGMCRffYuXuuBw06mdA6XEvOoB8MY8Oyo7bF/38I5gKBOieLO3CHlKmiM8T0PXaktEXAr9DGyxHmfnfjwCjevy1J7ivzHyHu05nNIfCQzTFPcKz49rov9CB2J7rpWa8BCD+G799dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417301; c=relaxed/simple; bh=xWTA0IdYijO7IFASgKOZ0Vabj/amKI4jA7+ChmTjM4s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VQSF2c6soDkKP6VJbT/ZWmB42TJG35WrXWf1HW18nWjyfW7f8NZJxpvSoFS80PTHcsNbPV7FTgaP3rOiW3XW0otrlpZh9PuEIaLddH7monrp0774m8pHE8R6BctKWTBgY2G9CtbWuQld0BBrNNH16TnxjBvPYqVfAWCN2KbBUus= 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=cDWa7Nue; 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="cDWa7Nue" 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 68361mNw1056274; Thu, 3 Sep 2026 06:34:36 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=lkEEt+Avu0uDBakRz khxYQgptYGLHcGm9wFZS1Clsp8=; b=cDWa7Nue7J/rsP41fowSDLIu2qHVDngPO 3C9iGT5QBLcr7GnFGTxmI88Ieu4Eq55+LsLrq3DKdplicg1Eqbw8Vdw0admwwpyl nJt6n2aaWlHkCXJ1tjjtXLyZSvnqeGOGZPquorzUc8Bp9fFA/G2EPn+lhRgMFbd9 hZVquGrpSK49QAdEWYiCHZAb8LIVmVUvrRqidUFM+OTMy4UVC1qmRWuziKTkolaA iUQ98rhFYBoW3Ba6TMosn3Vft40jwMbghtdRZ2LoFjXqYnR4e+nJS+xOZdsippNo aPZsWoNSf0RfAlmNg+kA1NmeUvaT924TXHqKbPlQiR47q7PFS1nMQ== 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 4gbnue32mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:36 +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 6836QMet024012; Thu, 3 Sep 2026 06:34:35 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gcarkecqb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:35 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836YVSE31392300 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:34:31 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3F83820043; Thu, 3 Sep 2026 06:34:31 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E7ABE20040; Thu, 3 Sep 2026 06:34:22 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:34:22 +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 v12 11/13] virt/steal_governor: Add control knobs for handling steal values Date: Thu, 3 Sep 2026 12:02:38 +0530 Message-ID: <20260903063240.268775-12-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-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: GqZXYbUpnz70K4pKXm7MMeCtlRoGtXVr X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX31xiiCG3Ewyw wsK0oExE4IkjGzpRjUytnsabNTuiIsnA/jfUboOW5uVL2xL9yedVJqpnch8KpYLuiGUU94tjJTz Qz32eXL/6N+Ec0wx2I3d0gozgwVjYuwSD6TTA00ule0xdDaRxu52VUfMZQGTxEovseR3ZB5HDD0 s3ZA2EPSGC55MHv4lhvcUlRqWI6TzUuCOnGeqOH1Rl95L244iHXgHFMDW+Bx1UuywFqfyBVaeEB dspw78Agt19XDCq/IqQcjtv54RWjxB7WCbx4CTNXuaG54wPZtjKTA7MeeEzWXGmxIkk4AseeIyk gkL+S8NyC1J5dMl2WNIuB7Pi4Ew7BQCF8+IRXZTtnw97xJVPMGG7kvXSU0MdTON1FKRLmvv5mn+ jTa957Kthp8GRfOZ1N3wc3tb/HDJb0v5XFngx7a6AO6/RV0kv0vQvJjrU3E5uP7BquX27WVtMfE X0p9n+rxYAc8aRFjv3Q== X-Proofpoint-ORIG-GUID: 21iAHDdsa1zKU7H_Tbiw8M8aYE7plB63 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX4LMEFnIkkLHU uDDK2AGkvcudc/JJmliky4aIfTW2Q3ZsKMs1S9LnpKqIZ+yPOqogyiaBcbiLYVCgVoM1L6hZQ0z ZKMbRqjp6uuP9MHrr6cOfKmsVHMKnWM= X-Authority-Analysis: v=2.4 cv=B92JFutM c=1 sm=1 tr=0 ts=6a9914fc cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=XC_GqrfF-lTPz34eE_0A: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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 clxscore=1015 suspectscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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.52.0 From nobody Sat Sep 26 08:37:18 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 DFBB437A83B; Thu, 3 Sep 2026 06:35: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=1788417316; cv=none; b=eMvJv10sJ7rcByU886vUekFlMfbHjUuq8E4V4Y36fKHpX4m/zPArXv9kh9D24m1xibXOsFTyTkDobw8AbqlpQCQKcUxnSij6Fi2zSX/tvPI75cxQ0t4augqwR3/vMN1iT+ZNv3yVblczFj+HF8DEH/XpHrtKvYRtvMhZrOtDQwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417316; c=relaxed/simple; bh=VDp2zBoCFEaRDgWzZVNpKOazoIedhMgdmV1VZIRF634=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DC82NJ57fHgqAA2RFOLrzgZ0QiwQzRoehRSThwmTV0sFwzg6KlQyUI5cywzfauMEyIQXyNO4VPYGBTolNeqKhHDoFpggmtIbuWaiO0q6dyuK3r30muTFQOjaehCUWB8MCK1kRhvV/RUb0jzfwWdYk0nWwX0MWB1LJC8nP1S1Um8= 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=JE1qF3Yj; 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="JE1qF3Yj" 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 68361gvo2239337; Thu, 3 Sep 2026 06:34:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=gjYq6SHKwdXjFp3Ex vbEGIeub4757cwklj45vWP8riU=; b=JE1qF3YjcD5NahnnW8IkpgdZVYo5emkB4 XHylGB/rR8Xy4wsxxQ/M4fKlB8Pq4mcucwTkLeLcrh0Vi1UJGVO+paBb6E3PSGOs tfKNXhWwurNJOYvM5qhBb703xRzRm+i2a5KBDJOSrjUjLlBw5C7yiw3Eev/M4PP9 pMf/9iwc4IDnaqiTAlG3bsMzSsEpI5l68ILf97/CsiRCXD9TPDOTQSyBDHYeNj8t xWTibkH/NNMFB6pl0NBd3K8vcOrSpa+voQ2MVuBayExAwSFMJpJqCC86HBzpZ+GN xtVY7nHFGGWjLrANjAS90WR4EOw8bJoZ76PkQIoJ5ZEP6kzega+ng== 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 4gbq2tjuv3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:45 +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 6836QHQX009495; Thu, 3 Sep 2026 06:34:44 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4gcceye651-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:43 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836YeR439059738 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:34:40 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15B5220043; Thu, 3 Sep 2026 06:34:40 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A2F7820040; Thu, 3 Sep 2026 06:34:31 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:34:31 +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 v12 12/13] virt/steal_governor: Implement steal_governor policy loop Date: Thu, 3 Sep 2026 12:02:39 +0530 Message-ID: <20260903063240.268775-13-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-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=bc1bluPB c=1 sm=1 tr=0 ts=6a991505 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=dzxYU6fr5WJrpIuQ_HEA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfXzsWjw5Yj3yix p3QwCRzGsddULVISCF49cNyGHFbdNJ31F8aW3T5knMG0pS4jbqKVY6nT26XXIutMjD7XAuoGrQ6 sa0Np2uv5BXKiA0oOlAF2ubLD2wdIy4= X-Proofpoint-ORIG-GUID: osA-u4vFNdFWI5i_WR8TYiq8lND0WWKq X-Proofpoint-GUID: LKblGvXZSPskxbQ3-Q91lKR7JZidl67l X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX4qOxfEDRXSoT 6OV1V0mwFroHUybn3r/bpOiplDDoCP8R26wgO5fUOsMo46WWr16+4oowg91Xy9evBK0LovpfR7N yQDh5hdiWePm2ZhsefpBonBcY3nIxTW2c1JsV8ie7e3iHOyoYFtQsugtO2hVgxhUrcTal4jkL3l 2vECKd5f8y6ZBVAZG6hM/2C3JwMJNK2cC7xgB9dQUwrNdiwZRgw5L1NRCxhhhgfaNDnCPvobjuH ZevxoW25GRbab09hA8pk6njq3WKyuXSM+vCD4/G1KAWQzrr3tg8C/g0AZaX5LlMRHkExnuM+kyA j7V+IYDGN73ozzAUxVErQlFnRN86ELAjcunY3AtZRTdvHeZoAp3yEfBg24Oh6VIDkOgVpClwTXF VSniQUUqXiAIn3qZAwZyUqDQqLCWFH03ri8RKFgpwoOZ1+cADBvrXwYoLsTvxIgeENwyaFHngks 0TURya0Jhb5jZgKSnPQ== 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 suspectscore=0 adultscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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.52.0 From nobody Sat Sep 26 08:37:18 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 B82BC4078E9; Thu, 3 Sep 2026 06:35:24 +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=1788417328; cv=none; b=VYFLFkTqLAOUgmNp/r43vAt6pWFBfprIIOm3QUVyUkOwQTpQASLVjd4FcNoA3didVo/INMRVTJEkiUSfE4tI+1qlymYqUssalDyiLway6y3qprja1iWmNwcLWcyZN3Qj8PzupJVrNIycw+r5xsgkQ7lSVNJUWjV8lVa5xUkOD3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788417328; c=relaxed/simple; bh=5cENXDoJGErmJsLQ6ZJsBujmig6bC7WS/6A9jKS95EU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jbf/RX6pKJ4Q4eqFXR3tuYvWXBSFzdewwVBgu/+fH2O5D5w1bsz3nKLvKr+xCdw3ImY52FQ2bmi4z0dRrkk+x91R9eMs3yGQzw56DAGiJTOgPSLOfvvU1z+Mu6rGqU48RZ1TcuOGG5yxZGevPhW2i8foeE3bUwEd5mpMjQuBDos= 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=BbCmSWMN; 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="BbCmSWMN" 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 68361eko2188170; Thu, 3 Sep 2026 06:34: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=NoKs6PHgICOPvbPtx LXEGO2l3bWSaBBDHM91RDM0iP0=; b=BbCmSWMNA8a1nqrHaX1sS02b5jQSMSIUk zObJr6qCzNsXEhUkADk9+LbaaLgA3MK5EPBQZh69dRbTn1fl31M3R+zeKpsGFfLa CFPdBwj7neJbokbUZNYBMuTSXCa20IcHRNTcM1Uzqdgv7h8E6V1D2p6RvglDUUIG p2s5cYDExOW53/QFHY537gJ0nx+kBGQKsFRA3jmjTiKht0HRKPYk/v48I+0nVdQ7 6xDRYI4fvU/Mdoa/rqigrFEKROye5ekhWKVzQZInELRkqHzjT2DPmjt0ZRRv6gy3 bSaKX69HliB9Kr46h0y6tarUmCyOkMO1bhTVsQgo/yie/gIRV2dUA== 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 4gbpx5udfn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34: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 6836QHT5006191; Thu, 3 Sep 2026 06:34:53 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gcb8hpa3u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2026 06:34:53 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6836YnJ246924238 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Sep 2026 06:34:49 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1A59820043; Thu, 3 Sep 2026 06:34:49 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 78EA720040; Thu, 3 Sep 2026 06:34:40 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.27.193]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Sep 2026 06:34:40 +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 v12 13/13] virt/steal_governor: Enable the driver Date: Thu, 3 Sep 2026 12:02:40 +0530 Message-ID: <20260903063240.268775-14-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903063240.268775-1-sshegde@linux.ibm.com> References: <20260903063240.268775-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=PPc/P/qC c=1 sm=1 tr=0 ts=6a99150f cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=jPZz8W9ceouySDeeKuAA:9 X-Proofpoint-GUID: 8jmbw4Nw_27ku6VuTzGCQWkEy4_5J3-J X-Proofpoint-ORIG-GUID: bFa-iy32QYLkbHUQxW9ewRqS5ISAQxaM X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfX1Xt3wXeKIa7E SSGcDNnIMeseKPwrUFGe7Dwt9U0CCwBXyyK5EyUi80xvw2gLNzQpdwtoQg7/FBhu/q8hBfKZUCS WA+S1mruMLLdfkJwGsfDZvsVa4PEGfw= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAzMDA1NyBTYWx0ZWRfXyY6oQJi+BVM/ Jifg2iCRzeZWCyuMcfUkUWdxNP9RAcJoVNEDQCbJL0KUCXHUVpQcvf1UqVYH/Iju+s8VUcw4AM6 +zs2itv/owysnF0lrYycx62lR0h0A3/laKgA4ILcBVRx+IzFv7DLmLmpP9x+3dz3lxM90h1j9XH NqDef45LFBKBYShxhA9CGS4VvQ0mzfc2tIi4VwV7HaLHnZJI+v5JEgcLgt9WcAN92fqtvztLQgp BQRku1NXFEEPSAkE1/l/++6ufMAeElnbN0QGJ0jVP1kVV4wGhFj7x9kVaDWOcVm6MlRVZUh8jT5 /T3EPMhHdalF7flC1SRqYm9/LACSd8kv9YcWCvmL3XM8AAqFhdVuBVRlpANAgaaoIpNn7aUDCVm qVPuje6xEmeQU22XuZ+2h7beOHi6m1vVdTQ/uaQqIMZwTcy0XcJMhbVX7WRuNjv02BYXcPpqGB6 NXkilu0W8u7EeuZKRxw== 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-09-03_02,2026-09-02_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 bulkscore=0 spamscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609030057 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.52.0