From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f43.google.com (mail-yx1-f43.google.com [74.125.224.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4479E371CE4 for ; Thu, 18 Jun 2026 04:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781756118; cv=none; b=sG6XDkCBjAnXxzGClpZBaBlFhf+S5fcUx/QLmChM//WqZS751YI/ItiNAOp+H8CTUodvPPcDo94seX7ziYXh8VpDJK6vc3xjAsy95P/IGolifECYGD02xpavnH/m6cQpgO6nUoTEuJzUL6GFjJHUG6WXxUsCkU3ZppSyKaP1pRs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781756118; c=relaxed/simple; bh=XUBI6/LFbYVq9KPWQ3K8hCTv2atuBWY5yAWdTkc70rM=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nxJ1sjhLTw1HH4NzTDv1wfE7waHCxxUBbR0bA91jxoIdiqGrK9KjpjjqF2ec4hwrZ98WoqBnOcTBwWDcREBKaFZvlUsBq4ZbfvXOOnjSiLbnN1EIunDNMWeQcKcUY82sMSYxNQysQsFJnAomTWiqb7jDnVUwiChzqrF5e45vTVE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kdcKTXMN; arc=none smtp.client-ip=74.125.224.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kdcKTXMN" Received: by mail-yx1-f43.google.com with SMTP id 956f58d0204a3-662e702eed4so259699d50.0 for ; Wed, 17 Jun 2026 21:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781756114; x=1782360914; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=r/ZrKGbnOP82qcJw6tfNYEM5gM6mgpUfklA+xSv64eY=; b=kdcKTXMNnQ3u6MVO6uRU25Q1g3envGfT1tWj327vKrRVrhtd/aFPT+QxERHYlT7kKg CnDgcaa4WAHBrcOtqefnYUVPpUbmuA+bBOuavDEQKzuswtNhgh6kLWw7YCwI7KKEqE6C A0DeqDtZoePPen9kaBZESko7nBTrLThSVfZsvYCbM2Xvjq/zVTgvFkZ+BARo0R1IFpmW 2ZjY4fy+PyNrISWkxmSTliSGBhT9mcCI1+jUXY5CI+eYp+gqiUrdIF34y08HtlucXd1X RTaF8bTPkJUgP7XSCaEzX2KPk1zxnNzXgNAA+FCwG8n6oiMJ03tpS/uZ03diZHFoyMpP pJcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781756114; x=1782360914; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r/ZrKGbnOP82qcJw6tfNYEM5gM6mgpUfklA+xSv64eY=; b=dlnOSTtdF2AG+BFniCy3zE7zUHE93IGlE5lMpxeiY5AfIoltCu52t+8q8j7ic8+LVK j2dnnBRunh+wmLK7qobpz2uS2Z8xgHEtALUz+WoAU0I9PtUbJI+uJfol20kWsc4Eq43L F3CqGG6gQ2a+boofymYdESH0ysR+3H2ZFtxUXNSw4QirdoOLm5I8UvYo3fTG7Y+2q75i +fsVWwE0fNmGfXSIBHYCMGxX4T1qTR/MwQu8moeDBs3A8XIWIApIdTyiuMkXhwAzCeIc maw5LkxJkyI0ffKj4z6DdbEruRgFuwa9b+rvkbrs/6upF7m/BQH6n2HuKDEz5ANW9Jek ffLQ== X-Gm-Message-State: AOJu0Yy3Z07QCbl72V1OaQy+A6ENhoq5jgcuVkS+4Rm4SSj1vXijgoSN SPaUA+hPPTQ+mx196Jkidi0tX3Afwd0MPV5w04SKyjiVRMRP15i/rpo4 X-Gm-Gg: AfdE7ckfVp98ysMSQje6wn12MqR/2uN7e1M+sjdPHYdkcrfvD3o34bRra9bp4bxWU76 /BvfCzqSyG/xHApmpgi5MG4yqcWzS4MjIl8AA7todOEnQ6uKDi/v1Bue9njI8o64Jfyi8S1d5Or b9UHvrictUT7sV3NfIQuf75W6t70jwtEURl1AOpU2FKWTz5jCQDpFBSEaYpK2SRPEZB5C00QgP2 JHYP1fcg/6HVFyZS1nT+8+o06RCxxs1nioLW5B/URcQvOKTzw+wWZi0/hQwH/4F81BwhvhX5N62 NYo9eO3MbvZWj4212I+MtkKK+6+Vpc7xrGhp7eiLJjKY5r5YUIwiF2i0DSwDunsbizmXM83jskQ mqefmar4y2KsjCfIsTWGOtskFflHAqRJKsb+UKUWK0vzimoMZk8Kp1VeycAUuRk+6p6txLdDSPa GUxcd24y2+Z9KukUK5p2FmZ4u5axjmthO5aXEbfyNO06YDuQ== X-Received: by 2002:a05:690e:14c6:b0:65d:7de1:2fe1 with SMTP id 956f58d0204a3-662e3b675bamr2180019d50.10.1781756113895; Wed, 17 Jun 2026 21:15:13 -0700 (PDT) Received: from localhost (syn-035-130-123-074.biz.spectrum.com. [35.130.123.74]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-66274c67d5esm11785638d50.6.2026.06.17.21.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 21:15:13 -0700 (PDT) From: Yury Norov X-Google-Original-From: Yury Norov Date: Thu, 18 Jun 2026 00:15:07 -0400 To: Shrikanth Hegde Cc: 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, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, mgorman@suse.de, bsegall@google.com, maddy@linux.ibm.com, srikar@linux.ibm.com, hdanton@sina.com, chleroy@kernel.org, vineeth@bitbyteword.org, frederic@kernel.org, arighi@nvidia.com, pauld@redhat.com, christian.loehle@arm.com, tj@kernel.org, tommaso.cucinotta@gmail.com, maz@kernel.org, rafael@kernel.org Subject: Re: [PATCH v4 16/20] sched/core: Introduce default arch handling code for inc/dec preferred CPUs Message-ID: References: <20260617174139.155540-1-sshegde@linux.ibm.com> <20260617174139.155540-17-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=us-ascii Content-Disposition: inline In-Reply-To: <20260617174139.155540-17-sshegde@linux.ibm.com> On Wed, Jun 17, 2026 at 11:11:35PM +0530, Shrikanth Hegde wrote: > Define default handlers for high/low steal time. If arch has better > decision logic, may override the default implementation. > > - If the steal time higher than threshold, reduce the number of preferred > CPUs by 1 core. The last core in the intersection of active and > preferred CPUs will be marked as non-preferred. > Ensure at least one core is left as preferred always. > > - If the steal time lower than threshold, increase the number of preferred > CPUs by 1 core. First active core which is not in cpu_preferred_mask will > be marked as preferred. > If all cores are already set to preferred, bail out. And the code below does nothing of that. > Increase/Decrease may need to modify the splicing across NUMA nodes. It is > being kept simple for now. > > Signed-off-by: Shrikanth Hegde > --- > v3->v4: > - active instead of online > - added comment for enabling tick for nohz_full. > > include/linux/sched.h | 2 ++ > kernel/sched/core.c | 61 +++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 63 insertions(+) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 5b15353ed7ef..e435f3073ffc 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -2529,5 +2529,7 @@ struct steal_monitor_t { > }; > > extern struct steal_monitor_t steal_mon; > +void arch_dec_preferred_cpus(struct steal_monitor_t *sm, u64 steal_ratio); > +void arch_inc_preferred_cpus(struct steal_monitor_t *sm, u64 steal_ratio); > #endif > #endif > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index f1a91021e357..c77045055604 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -11400,6 +11400,67 @@ void sched_init_steal_monitor(void) > steal_mon.sampling_period_ms = 1000; /* once per second */ > } > > +/* > + * Default implementation of decrementing the preferred CPUs based on steal > + * time. This is simple logic and decrease the preferred CPUs by 1 core. > + * It takes out the last core in the active & preferred. > + * > + * Ensure at least one housekeeping core is always kept as preferred > + * > + * Could be overwritten by arch specific handling. > + */ > +#ifndef arch_dec_preferred_cpus > +void arch_dec_preferred_cpus(struct steal_monitor_t *sm, u64 steal_ratio) > +{ > + int last_cpu, tmp_cpu; > + int this_cpu = raw_smp_processor_id(); > + > + last_cpu = cpumask_last(cpu_preferred_mask); > + > + /* > + * If the core belongs to the housekeeping CPUs, no action is > + * taken. This leaves at least one core preferred always. > + * This ensures at least some CPUs are available to run > + */ > + if (cpumask_equal(cpu_smt_mask(last_cpu), cpu_smt_mask(this_cpu))) > + return; > + > + /* > + * set tick bit for nohz_full CPU to push the task out. Once the tasks > + * are pushed out, bit will be cleared > + */ > + for_each_cpu_and(tmp_cpu, cpu_smt_mask(last_cpu), cpu_active_mask) { > + set_cpu_preferred(tmp_cpu, false); > + if (tick_nohz_full_cpu(tmp_cpu)) > + tick_nohz_dep_set_cpu(tmp_cpu, TICK_DEP_BIT_SCHED); > + } > +} > +#endif > + > +/* > + * Default implementation of incrementing preferred CPUs based on steal > + * time. This is simple logic and increases the preferred CPUs by 1 core. > + * It adds the first core in active & !preferred > + * > + * Nothing to do if active == preferred > + * > + * Could be overwritten by arch specific handling. > + */ > +#ifndef arch_inc_preferred_cpus > +void arch_inc_preferred_cpus(struct steal_monitor_t *sm, u64 steal_ratio) > +{ > + int first_cpu, tmp_cpu; > + > + first_cpu = cpumask_first_andnot(cpu_active_mask, cpu_preferred_mask); > + /* All CPUs are preferred. Nothing to increase further */ > + if (first_cpu >= nr_cpu_ids) > + return; > + > + for_each_cpu_and(tmp_cpu, cpu_smt_mask(first_cpu), cpu_active_mask) > + set_cpu_preferred(tmp_cpu, true); > +} > +#endif > + > /* This is only a skeleton. Subsequent patches introduce more of it */ > void sched_steal_detection_work(struct work_struct *work) > { > -- > 2.47.3