From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f47.google.com (mail-yx1-f47.google.com [74.125.224.47]) (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 A486E22576E for ; Thu, 18 Jun 2026 04:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781757054; cv=none; b=tU7BhGfiFkBgMaEZl1FSvopYGNKQM01XAipWGpd9M66+7d/WVR2SNzeG1oq6eOCwWLBrEH9Lvo0uluwL+8a2lgAl6+/40TRJa4tUSdrg5rX/eC3yshpCv21e2AIg6gd7pD4I6WEGyscU1i4UDmERwdqQnTCrGDZsbS3GixJBAfk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781757054; c=relaxed/simple; bh=Nr/+NptgMdvLmMGWpbl7FUAyGuewUwTKXxXasmcd4oM=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iNlx+8f192ns0Il2RoAs2/x98/YU8BhgpoValtOcENaJHZFN851gRtkF1/s6rMP22XIP2yA/+kpmYugTv1pqpXBO/kSB7zBUI7UUGbleFp5thckb6hS1OMY/3ka0229zpdFJNafJMXcmXPO9YlKWOI41DcIgtz/f2kNYeoOFguY= 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=gwOf/A4P; arc=none smtp.client-ip=74.125.224.47 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="gwOf/A4P" Received: by mail-yx1-f47.google.com with SMTP id 956f58d0204a3-662d484ff3bso621759d50.1 for ; Wed, 17 Jun 2026 21:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781757051; x=1782361851; 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=mvmaxPJkbT2at/EdK7LeLwqPqRB9GTeZZoLFN1WLUmU=; b=gwOf/A4PG8CYuNiP1m8+xtg3fM54IvQaZte6TCMroQVAMf/VNvGElefsU/1tir+REv O5IuUeXxxLVmAYESwi7Hj3MaMKHhB8d9wG0wCxMI03ZVp2w3JxaWYHVadGV9OxiJtTiM 5tXv9sc0ZFwu+9hr0E+y/L9JInYyd+Il/erjvSRM6Tx1K97JKNV5qpHT1GKKRy9mF2kK qgRuWZuWmPFf6NjayGM08JjqVm4GhZrokzFUkx0j534Kr55mTa4LaMI8+14qfQR1QMPh tfI51OMV1uHrQmTfI5AZn+K2I1xNJmBMH2aTrjbxm9eE97RoP93MGlH8i6jjUEoMqLtb EDaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781757051; x=1782361851; 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=mvmaxPJkbT2at/EdK7LeLwqPqRB9GTeZZoLFN1WLUmU=; b=BIZqAvRtqK2pfuEVPxOXw7N0zTmDxazZEDnuWj9GaMcfdKvgtkvTRL4QFt3kyHKX2t RJtCcz5h8wjyKKqahCzDLntIIyqlCjO2GQ44Q7mWDfps2wyg7y/yFwWzvSQNdMr1l5Px y92srg5jbMNVTKbyppTdS07trCeIzkMFogbfsswYfqgMTmkTs/HBaSe8K/zL/ZcppwBB Pm8vYCgS8LYw4+8JxARJNf9ETMzdazgYpTVQQKcClt8HcixzATAwJSBUniFkbfGC8m3T 5L5JIH/9xfLgXXlxxKNOYb/8TgnH1ePI0iVovWNPNgT4xufkkuBt8IwEUVxLdBXfg/er 193Q== X-Gm-Message-State: AOJu0Yz85Cmr0IStpXTtI3CVi2HC2TORZMbX9DuFLbzrdcZY1n8Odppg kX+AVuVT4ytcQgrM/fI8GbMAou2yRMWQCSuOgMusTdS1mL+lPT0BABpzdIzmyg== X-Gm-Gg: AfdE7cni6EgOVX0CsUdg9XekUI27yNfkJtY8bCJeC2AOyBVGae2fJwV593P+9bD54bd 7GE52PfUSr76xwO2l1XTsw4L/D5dHL/l0FeiAv2+dWQf3YBo2n6bzrMT0y/iuauTtWmoW9Hg/4T juwPQWtOyKj/LBvRJAOWUO+6P2XPZ9JWWUp4wBaGVqqJH0EPOAQA5kb3jIBay+32d144Tbj5EYk PE7OJT76nna9HzKfamPbFl1DWAACGOVPh9rRy8XBbu4qpdKE60Trt33vwjCYUAehluAu0V704fh ZjymMhPVDYko6HXLUiFVECzKZf/qRnB3qw35O91QxzM5AFehL7WO4g2NyszY1AQgojzq6UrTBCK x750w4FDHeIOaLKhuzJiQjOQnfFL2XHet1G7EV3zRHxyVpICF1V/v2PwGIGbsTvnmav2Q+AUI1M X7kwtP30eZzs2kFWbLzgZSDf9iCWnnm4N/mEjPnmoavq8ccw== X-Received: by 2002:a05:690e:1906:b0:662:f227:6230 with SMTP id 956f58d0204a3-662f227730amr94758d50.18.1781757051487; Wed, 17 Jun 2026 21:30:51 -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-66274e02e28sm11609024d50.13.2026.06.17.21.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 21:30:51 -0700 (PDT) From: Yury Norov X-Google-Original-From: Yury Norov Date: Thu, 18 Jun 2026 00:30:50 -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 14/20] sched/core: Introduce a simple steal monitor Message-ID: References: <20260617174139.155540-1-sshegde@linux.ibm.com> <20260617174139.155540-15-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-15-sshegde@linux.ibm.com> On Wed, Jun 17, 2026 at 11:11:33PM +0530, Shrikanth Hegde wrote: > Start with a simple steal monitor. > > It is meant to look at steal time and make the decision to > reduce/increase the preferred CPUs. > > It has > - work function to execute the steal time calculations and decision > making periodically. > - low and high thresholds for steal time. > - sampling period to control the frequency of steal time calculations. > - cache the previous decision to avoid oscillations This monitor is the one implementation out of quite many possible, right? I don't think it should live in the core scheduler files, it should be a module. > Signed-off-by: Shrikanth Hegde > --- > v3->v4: > - Drop tmp_mask > > include/linux/sched.h | 11 +++++++++++ > kernel/sched/core.c | 23 +++++++++++++++++++++++ > kernel/sched/sched.h | 3 +++ > 3 files changed, 37 insertions(+) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 5f523782ca28..ce6bc8a22eb1 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -2517,4 +2517,15 @@ extern void migrate_enable(void); > > DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable()) > > +#ifdef CONFIG_PREFERRED_CPU > +struct steal_monitor_t { > + struct work_struct work; > + ktime_t prev_time; > + u64 prev_steal; > + int previous_decision; > + unsigned int low_threshold; > + unsigned int high_threshold; > + unsigned int sampling_period_ms; > +}; > +#endif > #endif > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 24d4abc74241..cc48632dd42d 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -9138,6 +9138,8 @@ void __init sched_init(void) > > preempt_dynamic_init(); > > + sched_init_steal_monitor(); > + > scheduler_running = 1; > } > > @@ -11384,4 +11386,25 @@ void sched_push_current_non_preferred_cpu(struct rq *rq) > stop_one_cpu_nowait(rq->cpu, sched_non_preferred_cpu_push_stop, > push_task, this_cpu_ptr(&npc_push_task_work)); > } > + > +struct steal_monitor_t steal_mon; > + > +void sched_init_steal_monitor(void) > +{ > + INIT_WORK(&steal_mon.work, sched_steal_detection_work); > + steal_mon.low_threshold = 200; /* 2% steal time */ > + steal_mon.high_threshold = 500; /* 5% steal time */ > + steal_mon.sampling_period_ms = 1000; /* once per second */ > +} > + > +/* This is only a skeleton. Subsequent patches introduce more of it */ > +void sched_steal_detection_work(struct work_struct *work) > +{ > + struct steal_monitor_t *sm = container_of(work, struct steal_monitor_t, work); > + ktime_t now; > + > + /* Update the prev_time for next iteration*/ > + now = ktime_get(); > + sm->prev_time = now; > +} > #endif > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index 9cb006c21090..984da3827f19 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -4240,8 +4240,11 @@ static inline bool task_has_preferred_cpus(struct task_struct *p) > #ifdef CONFIG_PREFERRED_CPU > DECLARE_STATIC_KEY_FALSE(__sched_sm_enable); > > +void sched_init_steal_monitor(void); > +void sched_steal_detection_work(struct work_struct *work); > 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) { } > +static inline void sched_init_steal_monitor(void) { } > #endif > #endif /* _KERNEL_SCHED_SCHED_H */ > -- > 2.47.3