Linux Power Management development
 help / color / mirror / Atom feed
From: Metin Kaya <metin.kaya@arm.com>
To: Qais Yousef <qyousef@layalina.io>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Juri Lelli <juri.lelli@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	Christian Loehle <christian.loehle@arm.com>,
	Hongyan Xia <hongyan.xia2@arm.com>,
	John Stultz <jstultz@google.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7] sched: Consolidate cpufreq updates
Date: Mon, 29 Jul 2024 17:01:53 +0100	[thread overview]
Message-ID: <315f8c55-9368-4f2a-81ee-2d7dcb05bc14@arm.com> (raw)
In-Reply-To: <20240728184551.42133-1-qyousef@layalina.io>

On 28/07/2024 7:45 pm, Qais Yousef wrote:
> Improve the interaction with cpufreq governors by making the
> cpufreq_update_util() calls more intentional.

[snip]

> We also ensure to ignore cpufreq udpates for sugov workers at context

Nit: s/udpates/updates/

> switch if it was prev task.

[snip]

>   
> +static __always_inline void
> +__update_cpufreq_ctx_switch(struct rq *rq, struct task_struct *prev)
> +{
> +#ifdef CONFIG_CPU_FREQ
> +	if (prev && prev->dl.flags & SCHED_FLAG_SUGOV) {
> +		/* Sugov just did an update, don't be too aggressive */
> +		return;
> +	}
> +
> +	/*
> +	 * RT and DL should always send a freq update. But we can do some
> +	 * simple checks to avoid it when we know it's not necessary.
> +	 *
> +	 * iowait_boost will always trigger a freq update too.
> +	 *
> +	 * Fair tasks will only trigger an update if the root cfs_rq has
> +	 * decayed.
> +	 *
> +	 * Everything else should do nothing.
> +	 */
> +	switch (current->policy) {
> +	case SCHED_NORMAL:
> +	case SCHED_BATCH:
> +	case SCHED_IDLE:
> +		if (unlikely(current->in_iowait)) {
> +			cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT | SCHED_CPUFREQ_FORCE_UPDATE);
> +			return;
> +		}
> +
> +#ifdef CONFIG_SMP
> +		/*
> +		 * Send an update if we switched from RT or DL as they tend to
> +		 * boost the CPU and we are likely able to reduce the freq now.
> +		 */
> +		rq->cfs.decayed |= prev && (rt_policy(prev->policy) || dl_policy(prev->policy));
> +
> +		if (unlikely(rq->cfs.decayed)) {
> +			rq->cfs.decayed = false;
> +			cpufreq_update_util(rq, 0);
> +			return;
> +		}
> +#else
> +		cpufreq_update_util(rq, 0);
> +#endif
> +		return;		/* ! */
> +	case SCHED_FIFO:
> +	case SCHED_RR:
> +		if (prev && rt_policy(prev->policy)) {
> +#ifdef CONFIG_UCLAMP_TASK
> +			unsigned long curr_uclamp_min = uclamp_eff_value(current, UCLAMP_MIN);
> +			unsigned long prev_uclamp_min = uclamp_eff_value(prev, UCLAMP_MIN);
> +
> +			if (curr_uclamp_min == prev_uclamp_min)
> +#endif
> +				return;
> +		}
> +#ifdef CONFIG_SMP
> +		/* Stopper task masquerades as RT */
> +		if (unlikely(current->sched_class == &stop_sched_class))
> +			return;
> +#endif
> +		cpufreq_update_util(rq, SCHED_CPUFREQ_FORCE_UPDATE);
> +		return;		/* ! */
> +	case SCHED_DEADLINE:
> +		/*
> +		 * This is handled at enqueue to avoid breaking DL bandwidth
> +		 * rules when multiple DL tasks are running on the same CPU.
> +		 * Deferring till context switch here could mean the bandwidth
> +		 * calculations would be broken to ensure all the DL tasks meet
> +		 * their deadlines.
> +		 */
> +		return;		/* ! */
> +	default:
> +		return;		/* ! */
> +	}

Nit: would it be more conventional to replace marked `return` statements 
above with `break`s?

> +#endif
> +}
> +
> +/*
> + * Call when currently running task had an attribute change that requires
> + * an immediate cpufreq update.
> + */
> +void update_cpufreq_current(struct rq *rq)
> +{
> +	__update_cpufreq_ctx_switch(rq, NULL);
> +}
> +

[snip]


  reply	other threads:[~2024-07-29 16:02 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-28 18:45 [PATCH v7] sched: Consolidate cpufreq updates Qais Yousef
2024-07-29 16:01 ` Metin Kaya [this message]
2024-08-01 12:22   ` Qais Yousef
2024-08-05 15:35 ` Christian Loehle
2024-08-09  1:13   ` Qais Yousef
2024-08-13  8:25   ` Vincent Guittot
2024-08-13  8:27     ` Vincent Guittot
2024-08-13 16:26       ` Christian Loehle
2024-08-13 16:43         ` Vincent Guittot
2024-08-13 16:56           ` Christian Loehle
2024-09-01 17:51       ` Qais Yousef
2024-09-02 12:30         ` Vincent Guittot
2024-09-02 12:35           ` Christian Loehle
2024-09-02 12:43             ` Vincent Guittot
2024-09-02 12:58           ` Qais Yousef
2024-09-02 13:34             ` Qais Yousef
2024-09-02 13:40               ` Christian Loehle
2024-09-02 13:36             ` Vincent Guittot
2024-09-02 20:43               ` Qais Yousef
2024-09-03  6:54                 ` Vincent Guittot
2024-08-13 10:02 ` Vincent Guittot
2024-09-01 18:01   ` Qais Yousef
2024-09-03 12:48     ` Vincent Guittot
2024-09-11 20:34 ` Christian Loehle
2024-09-12 11:33   ` Rafael J. Wysocki
2025-02-09 22:34     ` Qais Yousef
2024-10-07 17:20 ` Anjali K
2024-10-08  9:56   ` Christian Loehle
2024-10-10 18:32     ` Christian Loehle
2024-10-18 18:32     ` Anjali K
2024-11-25  6:32       ` Anjali K
2025-02-09 22:33         ` Qais Yousef
2024-10-11  9:34 ` Christian Loehle
2025-02-09 22:41   ` Qais Yousef

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=315f8c55-9368-4f2a-81ee-2d7dcb05bc14@arm.com \
    --to=metin.kaya@arm.com \
    --cc=bsegall@google.com \
    --cc=christian.loehle@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=hongyan.xia2@arm.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=qyousef@layalina.io \
    --cc=rafael@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox