Skip to contentSkip to conversation

sched: cpufreq: Track util update flags

PATCH In review Viresh Kumar 8 participants 44 messages Dec 13, 2017 – Jan 10, 2018

Subsystems (2)
lore
Share & tools
lore

Viresh Kumar

author maintainer
#0 lore raw

cover sched: cpufreq: Track util update flags

Hi,

Currently the schedutil governor overwrites the sg_cpu->flags field on every call to the utilization handler. It was pretty good as the initial implementation of utilization handlers, there are several drawbacks though.

The biggest drawback is that the sg_cpu->flags field doesn't always represent the correct type of tasks that are enqueued on a CPU's rq. For example, if a fair task is enqueued while a RT or DL task is running, we will overwrite the flags with value 0 and that may take the CPU to lower OPPs unintentionally. There can be other corner cases as well which we aren't aware of currently.

This patchset tries to solve these problems by taking a different approach than overwriting flags, i.e. set and reset them. The second patch does that transition, other three patches are minor optimizations here and there, but related to this work.

Tested these on hikey620 with cyclictest, perf-pipe, hackbench and ebizzy and no obvious regressions were seen.

Based over linux-next/master (as I wanted both tip/master and pm/linux-next).

--
viresh

Viresh Kumar (4):
cpufreq: schedutil: Initialize sg_cpu->flags to 0
sched: cpufreq: Keep track of cpufreq utilization update flags
cpufreq: schedutil: Don't pass flags to sugov_set_iowait_boost()
cpufreq: schedutil: Don't call sugov_get_util() unnecessarily

 include/linux/sched/cpufreq.h    |  7 ++++++-
 kernel/sched/cpufreq_schedutil.c | 36 +++++++++++++++++++++++++-----------
 kernel/sched/deadline.c          |  4 ++++
 kernel/sched/fair.c              |  8 ++++++--
 kernel/sched/rt.c                |  4 ++++
 5 files changed, 45 insertions(+), 14 deletions(-)
Signature · 1 line
2.15.0.194.g9af6a3dea062
author maintainer
#1 lore raw

PATCH 1/4 cpufreq: schedutil: Initialize sg_cpu->flags to 0

Initializing sg_cpu->flags to SCHED_CPUFREQ_RT has no obvious benefit. The flags field wouldn't be used until the utilization update handler is called for the first time, and once that is called we will overwrite flags anyway.

Initialize it to 0.

Change-Id I028dbb40c5c242cff52fe1b14aeaff37f29a2f8d
---
 kernel/sched/cpufreq_schedutil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/cpufreq_schedutil.c +1 -1
index 2f52ec0f1539..e8ccfa30f01a 100644
@@ -655,7 +655,7 @@ static int sugov_start(struct cpufreq_policy *policy)
 		memset(sg_cpu, 0, sizeof(*sg_cpu));
 		sg_cpu->cpu = cpu;
 		sg_cpu->sg_policy = sg_policy;
-		sg_cpu->flags = SCHED_CPUFREQ_RT;
+		sg_cpu->flags = 0;
 		sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;
 	}
 
Signature · 1 line
2.15.0.194.g9af6a3dea062
maintainer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] cpufreq: schedutil: Initialize sg_cpu->flags to 0

Hi Viresh,

Quoted 8 lines · Viresh Kumar

Initializing sg_cpu->flags to SCHED_CPUFREQ_RT has no obvious benefit. The flags field wouldn't be used until the utilization update handler is called for the first time, and once that is called we will overwrite flags anyway.

Initialize it to 0.

Change-Id: I028dbb40c5c242cff52fe1b14aeaff37f29a2f8d

Without ^

Quoted 1 line

Best,

- Juri

author maintainer
#3 lore raw

Re: [PATCH 1/4] cpufreq: schedutil: Initialize sg_cpu->flags to 0

Quoted 8 lines · Juri Lelli

Hi Viresh,

Quoted 5 lines · Viresh Kumar

Initializing sg_cpu->flags to SCHED_CPUFREQ_RT has no obvious benefit. The flags field wouldn't be used until the utilization update handler is called for the first time, and once that is called we will overwrite flags anyway.

Quoted 5 lines
Quoted 3 lines

Initialize it to 0.

Change-Id: I028dbb40c5c242cff52fe1b14aeaff37f29a2f8d

Without ^

Wow. I have a script in place to make sure this doesn't get added. Not sure how this got added here, while its not present in any of the other patches.

Quoted 7 lines
Quoted 1 line

Best,

- Juri

Signature · 1 line
viresh
#4 lore raw

[tip:sched/core] sched/cpufreq: Initialize sg_cpu->flags to 0

In reply to Viresh Kumar
sched/cpufreq: Initialize sg_cpu->flags to 0
Commit-ID:  6257e7047890084fbeeb84c641200b43f0668abc
Gitweb:     https://git.kernel.org/tip/6257e7047890084fbeeb84c641200b43f0668abc
Author:     Viresh Kumar <[email protected]>
AuthorDate: Wed, 13 Dec 2017 15:23:20 +0530
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 10 Jan 2018 11:30:29 +0100

sched/cpufreq: Initialize sg_cpu->flags to 0

Initializing sg_cpu->flags to SCHED_CPUFREQ_RT has no obvious benefit. The flags field wouldn't be used until the utilization update handler is called for the first time, and once that is called we will overwrite flags anyway.

Initialize it to 0.

---
 kernel/sched/cpufreq_schedutil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/cpufreq_schedutil.c +1 -1
index d6717a3..22d4630 100644
@@ -655,7 +655,7 @@ static int sugov_start(struct cpufreq_policy *policy)
 		memset(sg_cpu, 0, sizeof(*sg_cpu));
 		sg_cpu->cpu = cpu;
 		sg_cpu->sg_policy = sg_policy;
-		sg_cpu->flags = SCHED_CPUFREQ_RT;
+		sg_cpu->flags = 0;
 		sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;
 	}
 
author maintainer
#5 lore raw

PATCH 2/4 sched: cpufreq: Keep track of cpufreq utilization update flags

In reply to Viresh Kumar

Currently the schedutil governor overwrites the sg_cpu->flags field on every call to the utilization handler. It was pretty good as the initial implementation of utilization handlers, there are several drawbacks though.

The biggest drawback is that the sg_cpu->flags field doesn't always represent the correct type of tasks that are enqueued on a CPU's rq. For example, if a fair task is enqueued while a RT or DL task is running, we will overwrite the flags with value 0 and that may take the CPU to lower OPPs unintentionally. There can be other corner cases as well which we aren't aware of currently.

This patch changes the current implementation to keep track of all the task types that are currently enqueued to the CPUs rq. A new flag: CLEAR is introduced and is set by the scheduling classes when their last task is dequeued. When the CLEAR flag bit is set, the schedutil governor resets all the other flag bits that are present in the flags parameter. For now, the util update handlers return immediately if they were called to clear the flag.

---
 include/linux/sched/cpufreq.h    |  7 ++++++-
 kernel/sched/cpufreq_schedutil.c | 21 ++++++++++++++++++---
 kernel/sched/deadline.c          |  4 ++++
 kernel/sched/fair.c              |  8 ++++++--
 kernel/sched/rt.c                |  4 ++++
 5 files changed, 38 insertions(+), 6 deletions(-)
include/linux/sched/cpufreq.h +6 -1
index d1ad3d825561..6f6641e61236 100644
@@ -8,10 +8,15 @@
  * Interface between cpufreq drivers and the scheduler:
  */
 
+#define SCHED_CPUFREQ_CLEAR	(1U << 31)
 #define SCHED_CPUFREQ_RT	(1U << 0)
 #define SCHED_CPUFREQ_DL	(1U << 1)
-#define SCHED_CPUFREQ_IOWAIT	(1U << 2)
+#define SCHED_CPUFREQ_CFS	(1U << 2)
+#define SCHED_CPUFREQ_IOWAIT	(1U << 3)
 
+#define SCHED_CPUFREQ_RT_CLEAR	(SCHED_CPUFREQ_RT | SCHED_CPUFREQ_CLEAR)
+#define SCHED_CPUFREQ_DL_CLEAR	(SCHED_CPUFREQ_DL | SCHED_CPUFREQ_CLEAR)
+#define SCHED_CPUFREQ_CFS_CLEAR	(SCHED_CPUFREQ_CFS | SCHED_CPUFREQ_CLEAR)
 #define SCHED_CPUFREQ_RT_DL	(SCHED_CPUFREQ_RT | SCHED_CPUFREQ_DL)
 
 #ifdef CONFIG_CPU_FREQ
kernel/sched/cpufreq_schedutil.c +18 -3
index e8ccfa30f01a..60a2dea4c8cc 100644
@@ -191,6 +191,8 @@ static void sugov_set_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
 				   unsigned int flags)
 {
 	if (flags & SCHED_CPUFREQ_IOWAIT) {
+		sg_cpu->flags &= ~SCHED_CPUFREQ_IOWAIT;
+
 		if (sg_cpu->iowait_boost_pending)
 			return;
 
@@ -264,6 +266,13 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
 	unsigned int next_f;
 	bool busy;
 
+	if (unlikely(flags & SCHED_CPUFREQ_CLEAR)) {
+		sg_cpu->flags &= ~flags;
+		return;
+	}
+
+	sg_cpu->flags |= flags;
+
 	sugov_set_iowait_boost(sg_cpu, time, flags);
 	sg_cpu->last_update = time;
 
@@ -272,7 +281,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
 
 	busy = sugov_cpu_is_busy(sg_cpu);
 
-	if (flags & SCHED_CPUFREQ_RT_DL) {
+	if (sg_cpu->flags & SCHED_CPUFREQ_RT_DL) {
 		next_f = policy->cpuinfo.max_freq;
 	} else {
 		sugov_get_util(&util, &max, sg_cpu->cpu);
@@ -345,15 +354,20 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
 
 	raw_spin_lock(&sg_policy->update_lock);
 
+	if (unlikely(flags & SCHED_CPUFREQ_CLEAR)) {
+		sg_cpu->flags &= ~flags;
+		goto unlock;
+	}
+
 	sg_cpu->util = util;
 	sg_cpu->max = max;
-	sg_cpu->flags = flags;
+	sg_cpu->flags |= flags;
 
 	sugov_set_iowait_boost(sg_cpu, time, flags);
 	sg_cpu->last_update = time;
 
 	if (sugov_should_update_freq(sg_policy, time)) {
-		if (flags & SCHED_CPUFREQ_RT_DL)
+		if (sg_cpu->flags & SCHED_CPUFREQ_RT_DL)
 			next_f = sg_policy->policy->cpuinfo.max_freq;
 		else
 			next_f = sugov_next_freq_shared(sg_cpu, time);
@@ -361,6 +375,7 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
 		sugov_update_commit(sg_policy, time, next_f);
 	}
 
+unlock:
 	raw_spin_unlock(&sg_policy->update_lock);
 }
 
kernel/sched/deadline.c +4 -0
index 2473736c7616..d9c7c6887493 100644
@@ -1472,6 +1472,10 @@ static void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 	 */
 	if (flags & DEQUEUE_SLEEP)
 		task_non_contending(p);
+
+	/* Clear cpufreq flags after last deadline task is dequeued */
+	if (!rq->dl.dl_nr_running)
+		cpufreq_update_util(rq, SCHED_CPUFREQ_DL_CLEAR);
 }
 
 /*
kernel/sched/fair.c +6 -2
index 2915c0d95107..492188c3ee2d 100644
@@ -3033,7 +3033,7 @@ static inline void cfs_rq_util_change(struct cfs_rq *cfs_rq)
 		 *
 		 * See cpu_util().
 		 */
-		cpufreq_update_util(rq, 0);
+		cpufreq_update_util(rq, SCHED_CPUFREQ_CFS);
 	}
 }
 
@@ -5214,7 +5214,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 	 * passed.
 	 */
 	if (p->in_iowait)
-		cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT);
+		cpufreq_update_util(rq, SCHED_CPUFREQ_CFS | SCHED_CPUFREQ_IOWAIT);
 
 	for_each_sched_entity(se) {
 		if (se->on_rq)
@@ -5309,6 +5309,10 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 		sub_nr_running(rq, 1);
 
 	hrtick_update(rq);
+
+	/* Clear cpufreq flags after last CFS task is dequeued */
+	if (!rq->cfs.nr_running)
+		cpufreq_update_util(rq, SCHED_CPUFREQ_CFS_CLEAR);
 }
 
 #ifdef CONFIG_SMP
kernel/sched/rt.c +4 -0
index 862a513adca3..c9e8a8e5641b 100644
@@ -1337,6 +1337,10 @@ static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags)
 	dequeue_rt_entity(rt_se, flags);
 
 	dequeue_pushable_task(rq, p);
+
+	/* Clear cpufreq flags after last rt task is dequeued */
+	if (!rq->rt.rt_nr_running)
+		cpufreq_update_util(rq, SCHED_CPUFREQ_RT_CLEAR);
 }
 
 /*
Signature · 1 line
2.15.0.194.g9af6a3dea062
maintainer Reviewed-by on v1 2/4
#6 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Hi Viresh,

Quoted 34 lines · Viresh Kumar

Currently the schedutil governor overwrites the sg_cpu->flags field on every call to the utilization handler. It was pretty good as the initial implementation of utilization handlers, there are several drawbacks though.

The biggest drawback is that the sg_cpu->flags field doesn't always represent the correct type of tasks that are enqueued on a CPU's rq. For example, if a fair task is enqueued while a RT or DL task is running, we will overwrite the flags with value 0 and that may take the CPU to lower OPPs unintentionally. There can be other corner cases as well which we aren't aware of currently.

This patch changes the current implementation to keep track of all the task types that are currently enqueued to the CPUs rq. A new flag: CLEAR is introduced and is set by the scheduling classes when their last task is dequeued. When the CLEAR flag bit is set, the schedutil governor resets all the other flag bits that are present in the flags parameter. For now, the util update handlers return immediately if they were called to clear the flag.

---
 include/linux/sched/cpufreq.h    |  7 ++++++-
 kernel/sched/cpufreq_schedutil.c | 21 ++++++++++++++++++---
 kernel/sched/deadline.c          |  4 ++++
 kernel/sched/fair.c              |  8 ++++++--
 kernel/sched/rt.c                |  4 ++++
 5 files changed, 38 insertions(+), 6 deletions(-)
include/linux/sched/cpufreq.h +0 -0
index d1ad3d825561..6f6641e61236 100644

include/linux/sched/cpufreq.h line 14

Quoted 8 lines
include/linux/sched/cpufreq.h +2 -1
@@ -8,10 +8,15 @@
  * Interface between cpufreq drivers and the scheduler:
  */
 
+#define SCHED_CPUFREQ_CLEAR	(1U << 31)
 #define SCHED_CPUFREQ_RT	(1U << 0)
 #define SCHED_CPUFREQ_DL	(1U << 1)
-#define SCHED_CPUFREQ_IOWAIT	(1U << 2)
+#define SCHED_CPUFREQ_CFS	(1U << 2)

This flag doesn't do much, does it? I mean RT/DL/IOWAIT are used to bump up frequency, while you are adding CFS for the sake of simmetry, right? And with my patches DL will hopefully soon be in the same situation. If my understanding is correct, maybe add a comment?

Apart from this, patch looks good to me; couldn't test it though, sorry.

Thanks,

- Juri

author maintainer
#7 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 4 lines · Juri Lelli

This flag doesn't do much, does it? I mean RT/DL/IOWAIT are used to bump up frequency, while you are adding CFS for the sake of simmetry, right? And with my patches DL will hopefully soon be in the same situation. If my understanding is correct, maybe add a comment?

Symmetry yes, plus it can be useful to know when there is nothing queued on the CPU, i.e. no flags are set. Then the CPU is probably going into idle and we may want to do some tricky stuff there later on.

Signature · 1 line
viresh
#8 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

In reply to Viresh Kumar
Quoted 34 lines · Viresh Kumar

Currently the schedutil governor overwrites the sg_cpu->flags field on every call to the utilization handler. It was pretty good as the initial implementation of utilization handlers, there are several drawbacks though.

The biggest drawback is that the sg_cpu->flags field doesn't always represent the correct type of tasks that are enqueued on a CPU's rq. For example, if a fair task is enqueued while a RT or DL task is running, we will overwrite the flags with value 0 and that may take the CPU to lower OPPs unintentionally. There can be other corner cases as well which we aren't aware of currently.

This patch changes the current implementation to keep track of all the task types that are currently enqueued to the CPUs rq. A new flag: CLEAR is introduced and is set by the scheduling classes when their last task is dequeued. When the CLEAR flag bit is set, the schedutil governor resets all the other flag bits that are present in the flags parameter. For now, the util update handlers return immediately if they were called to clear the flag.

---
 include/linux/sched/cpufreq.h    |  7 ++++++-
 kernel/sched/cpufreq_schedutil.c | 21 ++++++++++++++++++---
 kernel/sched/deadline.c          |  4 ++++
 kernel/sched/fair.c              |  8 ++++++--
 kernel/sched/rt.c                |  4 ++++
 5 files changed, 38 insertions(+), 6 deletions(-)
include/linux/sched/cpufreq.h +0 -0
index d1ad3d825561..6f6641e61236 100644

include/linux/sched/cpufreq.h line 11

Quoted 4 lines
include/linux/sched/cpufreq.h +1 -0
@@ -8,10 +8,15 @@
  * Interface between cpufreq drivers and the scheduler:
  */
 
+#define SCHED_CPUFREQ_CLEAR    (1U << 31)

I'm not thrilled by this, because schedutil is not the only user of the flags and it's totally unclear what the other user(s) should do when this is set.

Thanks,
Rafael

author maintainer
#9 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 7 lines · Rafael J. Wysocki
Quoted 1 line · Viresh Kumar

+#define SCHED_CPUFREQ_CLEAR (1U << 31)

I'm not thrilled by this, because schedutil is not the only user of the flags and it's totally unclear what the other user(s) should do when this is set.

intel-pstate is the only other user of the IOWAIT flag, right? In order not to change the current behavior, we can update that to return early for now ?

--
viresh

#10 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 5 lines · CET Viresh Kumar
Quoted 4 lines · Rafael J. Wysocki
Quoted 1 line · Viresh Kumar

+#define SCHED_CPUFREQ_CLEAR (1U << 31)

Quoted 7 lines
Quoted 3 lines

I'm not thrilled by this, because schedutil is not the only user of the flags and it's totally unclear what the other user(s) should do when this is set.

intel-pstate is the only other user of the IOWAIT flag, right? In order not to change the current behavior, we can update that to return early for now ?

We can do that in principle, but why should it return early? Maybe it's a good time to update things, incidentally?

I actually don't like the SCHED_CPUFRREQ_CLEAR flag *concept* as it is very much specific to schedutil and blatantly ignores everybody else.

Alternatively, you could add two flags for clearing SCHED_CPUFREQ_RT and SCHED_CPUFREQ_DL that could just be ingored entirely by intel_pstate.

So, why don't you make SCHED_CPUFREQ_RT and SCHED_CPUFREQ_DL "sticky" until, say, SCHED_CPUFREQ_NO_RT and SCHED_CPUFREQ_NO_DL are passed, respectively?

Thanks,
Rafael

author maintainer
#11 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 11 lines · Rafael J. Wysocki

We can do that in principle, but why should it return early? Maybe it's a good time to update things, incidentally?

I actually don't like the SCHED_CPUFRREQ_CLEAR flag *concept* as it is very much specific to schedutil and blatantly ignores everybody else.

Alternatively, you could add two flags for clearing SCHED_CPUFREQ_RT and SCHED_CPUFREQ_DL that could just be ingored entirely by intel_pstate.

So, why don't you make SCHED_CPUFREQ_RT and SCHED_CPUFREQ_DL "sticky" until, say, SCHED_CPUFREQ_NO_RT and SCHED_CPUFREQ_NO_DL are passed, respectively?

I didn't like adding scheduling class specific flags, and wanted the code to treat all of them in the same way. And then the governors can make a policy over that, on what to ignore and what not to. For example with the current patchset, the governors can know when nothing else is queued on a CPU and CPU is going to get into idle loop. They can choose to (or not to) do something in that case.

I just thought that writing consistent (i.e. no special code) code across all classes would be better.

Signature · 1 line
viresh
#12 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 10 lines · Viresh Kumar
Quoted 9 lines · Rafael J. Wysocki

We can do that in principle, but why should it return early? Maybe it's a good time to update things, incidentally?

I actually don't like the SCHED_CPUFRREQ_CLEAR flag *concept* as it is very much specific to schedutil and blatantly ignores everybody else.

Alternatively, you could add two flags for clearing SCHED_CPUFREQ_RT and SCHED_CPUFREQ_DL that could just be ingored entirely by intel_pstate.

Quoted 8 lines
Quoted 2 lines

So, why don't you make SCHED_CPUFREQ_RT and SCHED_CPUFREQ_DL "sticky" until, say, SCHED_CPUFREQ_NO_RT and SCHED_CPUFREQ_NO_DL are passed, respectively?

I didn't like adding scheduling class specific flags, and wanted the code to treat all of them in the same way. And then the governors can make a policy over that, on what to ignore and what not to. For example with the current patchset, the governors can know when nothing else is queued on a CPU and CPU is going to get into idle loop. They can choose to (or not to) do something in that case.

Well, if SCHED_CPUFRREQ_CLEAR means "this CPU is going to enter the idle loop" really, then it is better to call it SCHED_CPUFRREQ_ENTER_IDLE, for example.

SCHED_CPUFRREQ_CLEAR meaning basically "you should clear these flags now" doesn't seem to convey any information to whoever doesn't squirrel the flags in the first place.

author maintainer
#13 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 7 lines · Rafael J. Wysocki

Well, if SCHED_CPUFRREQ_CLEAR means "this CPU is going to enter the idle loop" really, then it is better to call it SCHED_CPUFRREQ_ENTER_IDLE, for example.

SCHED_CPUFRREQ_CLEAR meaning basically "you should clear these flags now" doesn't seem to convey any information to whoever doesn't squirrel the flags in the first place.

Right, but when all the flags are cleared, then we can infer that we are going to idle in the most probable case.

Anyway, I will implement RT and DL clear flags as you suggested in the next version.

Signature · 1 line
viresh
#14 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 9 lines · Viresh Kumar
Quoted 7 lines · Rafael J. Wysocki

Well, if SCHED_CPUFRREQ_CLEAR means "this CPU is going to enter the idle loop" really, then it is better to call it SCHED_CPUFRREQ_ENTER_IDLE, for example.

SCHED_CPUFRREQ_CLEAR meaning basically "you should clear these flags now" doesn't seem to convey any information to whoever doesn't squirrel the flags in the first place.

Quoted 5 lines

Right, but when all the flags are cleared, then we can infer that we are going to idle in the most probable case.

Anyway, I will implement RT and DL clear flags as you suggested in the next version.

I think Rafael is right, the current API is a big odd since we cannot really set the CLEAR flags by itself. I mean, you can but it will not have effects.

Thus, it's probably better from an API standpoint to have a dedicated single clear flag... unfortunately it has to be one per class, which is still not optimal and will likely make the policy code a bit odd.

What about extending the signature of the callback method?

For example, swithing from:

- void (*func)(struct update_util_data *data, u64 time,
- unsigned int flags))
+ void (*func)(struct update_util_data *data, u64 time,
+ unsigned int flags, bool set))

Where the additional boolean is actually used to define which operation we wanna perform on the flags?

Signature · 3 lines
#include <best/regards.h>

Patrick Bellasi
author maintainer
#15 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 9 lines · Patrick Bellasi

For example, swithing from:

- void (*func)(struct update_util_data *data, u64 time,
- unsigned int flags))
+ void (*func)(struct update_util_data *data, u64 time,
+ unsigned int flags, bool set))

Where the additional boolean is actually used to define which operation we wanna perform on the flags?

The code will eventually have the same complexity or ugliness in both the cases. I would like to start with another flag for now and see if people prefer another parameter.

Signature · 1 line
viresh
#16 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Hi Viresh,

Quoted 8 lines · Viresh Kumar
Quoted 7 lines · Patrick Bellasi

For example, swithing from:

- void (*func)(struct update_util_data *data, u64 time,
- unsigned int flags))
+ void (*func)(struct update_util_data *data, u64 time,
+ unsigned int flags, bool set))

Quoted 6 lines
Quoted 2 lines

Where the additional boolean is actually used to define which operation we wanna perform on the flags?

The code will eventually have the same complexity or ugliness in both the cases. I would like to start with another flag for now and see if people prefer another parameter.

Though I think that will solve Rafael's concern of polluting the flags for something schedutil specific. I also feel adding extra callback parameter is cleaner than 2 new clear flags.

Thanks,

- Joel

author maintainer
#17 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 14 lines · Joel Fernandes

Hi Viresh,

Quoted 11 lines · Viresh Kumar
Quoted 9 lines · Patrick Bellasi

For example, swithing from:

- void (*func)(struct update_util_data *data, u64 time,
- unsigned int flags))
+ void (*func)(struct update_util_data *data, u64 time,
+ unsigned int flags, bool set))

Where the additional boolean is actually used to define which operation we wanna perform on the flags?

Quoted 7 lines
Quoted 3 lines

The code will eventually have the same complexity or ugliness in both the cases. I would like to start with another flag for now and see if people prefer another parameter.

Though I think that will solve Rafael's concern of polluting the flags for something schedutil specific. I also feel adding extra callback parameter is cleaner than 2 new clear flags.

Okay, I will then wait for Rafael to come online and comment on what he would prefer before posting.

Signature · 1 line
viresh
author maintainer
#18 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 19 lines · Viresh Kumar
Quoted 18 lines · Joel Fernandes

Hi Viresh,

Quoted 14 lines · Viresh Kumar
Quoted 9 lines · Patrick Bellasi

For example, swithing from:

- void (*func)(struct update_util_data *data, u64 time,
- unsigned int flags))
+ void (*func)(struct update_util_data *data, u64 time,
+ unsigned int flags, bool set))

Where the additional boolean is actually used to define which operation we wanna perform on the flags?

The code will eventually have the same complexity or ugliness in both the cases. I would like to start with another flag for now and see if people prefer another parameter.

Quoted 6 lines
Quoted 3 lines

Though I think that will solve Rafael's concern of polluting the flags for something schedutil specific. I also feel adding extra callback parameter is cleaner than 2 new clear flags.

Okay, I will then wait for Rafael to come online and comment on what he would prefer before posting.

I thought about it once more. If we decide eventually to add another parameter, then why isn't the approach that this patch takes better than that? i.e. Use the 31st bit of flags for clear bit ? We can remove setting/clearing flags for CFS, that's it.

Signature · 1 line
viresh
#19 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 24 lines · Viresh Kumar
Quoted 23 lines · Viresh Kumar
Quoted 21 lines · Joel Fernandes

Hi Viresh,

Quoted 8 lines · Viresh Kumar
Quoted 7 lines · Patrick Bellasi

For example, swithing from:

- void (*func)(struct update_util_data *data, u64 time,
- unsigned int flags))
+ void (*func)(struct update_util_data *data, u64 time,
+ unsigned int flags, bool set))

Quoted 6 lines
Quoted 2 lines

Where the additional boolean is actually used to define which operation we wanna perform on the flags?

The code will eventually have the same complexity or ugliness in both the cases. I would like to start with another flag for now and see if people prefer another parameter.

Though I think that will solve Rafael's concern of polluting the flags for something schedutil specific. I also feel adding extra callback parameter is cleaner than 2 new clear flags.

Quoted 7 lines
Quoted 2 lines

Okay, I will then wait for Rafael to come online and comment on what he would prefer before posting.

I thought about it once more. If we decide eventually to add another parameter, then why isn't the approach that this patch takes better than that? i.e. Use the 31st bit of flags for clear bit ? We can remove setting/clearing flags for CFS, that's it.

Yes that's clean to me but then as Rafael said, the use of this flag will be too specific for schedutil-only sg_cpu->flags clearing purpose right?

If adding the single flag is OK in the grand cpufreq scheme of things, then that's fine with me.

Thanks,

- Joel

author maintainer
#20 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 3 lines · Joel Fernandes

Yes that's clean to me but then as Rafael said, the use of this flag will be too specific for schedutil-only sg_cpu->flags clearing purpose right?

And so would be the extra parameter ?

Signature · 1 line
viresh
#21 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 6 lines · CET Viresh Kumar
Quoted 3 lines · Joel Fernandes

Yes that's clean to me but then as Rafael said, the use of this flag will be too specific for schedutil-only sg_cpu->flags clearing purpose right?

And so would be the extra parameter ?

Right.

I don't like the new parameter idea too much.

"Clearing" flags are generally fine by me, but I want them to have a meaning for whoever who may receive them.

I guess you can define the original CLEAR thing to mean "clear the RT and DL flags if you have saved them or ignore them if set here otherwise" and then intel_pstate can work as though it was called with the flags argument equal to zero (or just with IOWAIT set, but that never happens if CLEAR is set I guess).

Still, IMO NO_DL and NO_RT would be conceptually more straightforward (clear X if NO_X is set or ignore NO_X otherwise).

But anyway it is scheduler code and the scheduler maintainers haven't spoken up so far, so what I'm saying may just not matter. :-)

Thanks,
Rafael

#22 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

In reply to Viresh Kumar
Quoted 9 lines · Viresh Kumar
Quoted 7 lines · Rafael J. Wysocki

Well, if SCHED_CPUFRREQ_CLEAR means "this CPU is going to enter the idle loop" really, then it is better to call it SCHED_CPUFRREQ_ENTER_IDLE, for example.

SCHED_CPUFRREQ_CLEAR meaning basically "you should clear these flags now" doesn't seem to convey any information to whoever doesn't squirrel the flags in the first place.

Quoted 5 lines

Right, but when all the flags are cleared, then we can infer that we are going to idle in the most probable case.

Anyway, I will implement RT and DL clear flags as you suggested in the next version.

Cool, thanks!

maintainer
#23 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

In reply to Viresh Kumar
Quoted 12 lines · Viresh Kumar

Currently the schedutil governor overwrites the sg_cpu->flags field on every call to the utilization handler. It was pretty good as the initial implementation of utilization handlers, there are several drawbacks though.

The biggest drawback is that the sg_cpu->flags field doesn't always represent the correct type of tasks that are enqueued on a CPU's rq. For example, if a fair task is enqueued while a RT or DL task is running, we will overwrite the flags with value 0 and that may take the CPU to lower OPPs unintentionally. There can be other corner cases as well which we aren't aware of currently.

Quoted 7 lines

This patch changes the current implementation to keep track of all the task types that are currently enqueued to the CPUs rq. A new flag: CLEAR is introduced and is set by the scheduling classes when their last task is dequeued. When the CLEAR flag bit is set, the schedutil governor resets all the other flag bits that are present in the flags parameter. For now, the util update handlers return immediately if they were called to clear the flag.

Yeah, not happy about this either; we had code that did the right thing without this extra tracking I think.

Also, we can look at the rq state if we want to, we don't need to duplicate that state.

author maintainer
#24 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 2 lines · Peter Zijlstra

Yeah, not happy about this either; we had code that did the right thing without this extra tracking I think.

Sure, but how do you suggest we fix the problems we are facing with the current design? Patrick had a completely different proposal for solving those problems, which I didn't like very much. This patchset replaced these patches from Patrick:

- [PATCH v3 1/6] cpufreq: schedutil: reset sg_cpus's flags at IDLE enter
https://marc.info/?l=linux-kernel&m=151204247801633&w=2

- [PATCH v3 2/6] cpufreq: schedutil: ensure max frequency while running RT/DL tasks
https://marc.info/?l=linux-kernel&m=151204253801657&w=2

- [PATCH v3 6/6] cpufreq: schedutil: ignore sugov kthreads
https://marc.info/?l=linux-kernel&m=151204251501647&w=2

Quoted 2 lines

Also, we can look at the rq state if we want to, we don't need to duplicate that state.

Well that also looks fine to me, and that would mean this:

- We remove SCHED_CPUFREQ_RT and SCHED_CPUFREQ_DL flags, but still call the utilization callbacks from RT and DL classes.

- From the utilization handler, we check runqueues of all three sched classes to see if they have some work pending (this can be done smartly by checking only RT first and skipping other checks if RT has some work).

Will that be acceptable ?

Signature · 1 line
viresh
maintainer
#25 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 8 lines · Viresh Kumar
Quoted 2 lines · Peter Zijlstra

Yeah, not happy about this either; we had code that did the right thing without this extra tracking I think.

Sure, but how do you suggest we fix the problems we are facing with the current design? Patrick had a completely different proposal for solving those problems, which I didn't like very much. This patchset replaced these patches from Patrick:

Please use the normal link format:

https://lkml.kernel.org/r/$MSGID

Then I can find them without having to resort to a frigging browser thing.

I'll try and dig through the email I have.

Quoted 7 lines
Quoted 2 lines

Also, we can look at the rq state if we want to, we don't need to duplicate that state.

Well that also looks fine to me, and that would mean this:

- We remove SCHED_CPUFREQ_RT and SCHED_CPUFREQ_DL flags, but still call the utilization callbacks from RT and DL classes.

Didn't juri have patches to make DL do something sane? But yes, I think those flags are part of the problem.

Quoted 4 lines

- From the utilization handler, we check runqueues of all three sched classes to see if they have some work pending (this can be done smartly by checking only RT first and skipping other checks if RT has some work).

No that's wrong. DL should provide a minimum required based on existing reservations, we can add the expected CFS average on top and request that.

And for RT all we need to know is if current is of that class, otherwise we don't care.

author maintainer
#26 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 8 lines · Peter Zijlstra

On Wed, Dec 20, 2017 at 09:34:46AM +0530, Viresh Kumar wrote:

Please use the normal link format:

https://lkml.kernel.org/r/$MSGID

Then I can find them without having to resort to a frigging browser thing.

Sure, and that would be much easier for me as well as that's how I got to those links. Here they are again ..

https://lkml.kernel.org/r/[email protected]
https://lkml.kernel.org/r/[email protected]
https://lkml.kernel.org/r/[email protected]

Quoted 1 line

I'll try and dig through the email I have.

Thanks.

Quoted 7 lines
Quoted 4 lines

Well that also looks fine to me, and that would mean this:

- We remove SCHED_CPUFREQ_RT and SCHED_CPUFREQ_DL flags, but still call the utilization callbacks from RT and DL classes.

Didn't juri have patches to make DL do something sane? But yes, I think those flags are part of the problem.

Sure, DL will be more like CFS going forward. I was just commenting based on what we have upstream today.

Quoted 8 lines
Quoted 4 lines

- From the utilization handler, we check runqueues of all three sched classes to see if they have some work pending (this can be done smartly by checking only RT first and skipping other checks if RT has some work).

No that's wrong. DL should provide a minimum required based on existing reservations, we can add the expected CFS average on top and request that.

Right, that should be the case after Juri's patches.

Quoted 2 lines

And for RT all we need to know is if current is of that class, otherwise we don't care.

What about this case: A CFS task is running currently and an RT task is enqueued.

- Is it always the case that the CFS task is preempted immediately and the CPU is given to RT task ? I was talking to Vincent earlier and he told me that for certain configurations the CFS task may keep running until the next tick.

- What if the CFS task has disabled preemption ?

- More corner cases like this ?

Above cases may not let schedutil to raise frequency to MAX even when we have RT stuff enqueued. And that's why I tried to track all sched classes for which we have work enqueued for. There are great chances that my understanding here is wrong though :)

Signature · 1 line
viresh
maintainer
#27 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 4 lines · Viresh Kumar

On 20-12-17, 09:31, Peter Zijlstra wrote:
What about this case: A CFS task is running currently and an RT task is enqueued.

Quoted 8 lines

- Is it always the case that the CFS task is preempted immediately and the CPU is given to RT task ? I was talking to Vincent earlier and he told me that for certain configurations the CFS task may keep running until the next tick.

- What if the CFS task has disabled preemption ?

- More corner cases like this ?

If there is a runnable RT task we'll schedule to it ASAP. This means for:

CONFIG_PREEMPT=y

either immediately or when next preempt_enable() hits a 0 preempt_count.

CONFIG_PREEMPT=n

on any next kernel preemption point or when returning to userspace.

But this is not something we should worry about.

#28 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

In reply to Peter Zijlstra
Quoted 22 lines · Peter Zijlstra
Quoted 8 lines · Viresh Kumar
Quoted 2 lines · Peter Zijlstra

Yeah, not happy about this either; we had code that did the right thing without this extra tracking I think.

Sure, but how do you suggest we fix the problems we are facing with the current design? Patrick had a completely different proposal for solving those problems, which I didn't like very much. This patchset replaced these patches from Patrick:

Please use the normal link format:

https://lkml.kernel.org/r/$MSGID

Then I can find them without having to resort to a frigging browser thing.

I'll try and dig through the email I have.

Quoted 3 lines
Quoted 2 lines

Also, we can look at the rq state if we want to, we don't need to duplicate that state.

Quoted 7 lines
Quoted 4 lines

Well that also looks fine to me, and that would mean this:

- We remove SCHED_CPUFREQ_RT and SCHED_CPUFREQ_DL flags, but still call the utilization callbacks from RT and DL classes.

Didn't juri have patches to make DL do something sane? But yes, I think those flags are part of the problem.

He recently reposted them here:

https://lkml.kernel.org/r/[email protected]

Quoted 11 lines
Quoted 4 lines

- From the utilization handler, we check runqueues of all three sched classes to see if they have some work pending (this can be done smartly by checking only RT first and skipping other checks if RT has some work).

No that's wrong. DL should provide a minimum required based on existing reservations, we can add the expected CFS average on top and request that.

And for RT all we need to know is if current is of that class, otherwise we don't care.

So, this:

https://marc.info/?i=20171130114723.29210-3-patrick.bellasi%40arm.com

was actually going in this direction, although still working on top of flags to not change the existing interface too much.

IMO, the advantage of flags is that they are a sort-of "pro-active" approach, where the scheduler notify sensible events to schedutil. But keep adding flags seems to overkilling to me too.

If we remove flags then we have to query the scheduler classes "on demand"... but, as Peter suggests, once we have DL bits Juri posted, the only issue if to know if an RT task is running.
This the patch above can be just good enough, with no flags at all and with just a check for current being RT (or DL for the time being).

Signature · 3 lines
#include <best/regards.h>

Patrick Bellasi
maintainer
#29 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 8 lines · Patrick Bellasi
Quoted 2 lines · Peter Zijlstra

Didn't juri have patches to make DL do something sane? But yes, I think those flags are part of the problem.

He recently reposted them here:

https://lkml.kernel.org/r/[email protected]

Yeah, just found them and actually munged them into my queue; did all the modifications you suggested too. Lets see if it comes apart.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

- From the utilization handler, we check runqueues of all three sched classes to see if they have some work pending (this can be done smartly by checking only RT first and skipping other checks if RT has some work).

No that's wrong. DL should provide a minimum required based on existing reservations, we can add the expected CFS average on top and request that.

Quoted 6 lines
Quoted 2 lines

And for RT all we need to know is if current is of that class, otherwise we don't care.

So, this:

   https://marc.info/?i=20171130114723.29210-3-patrick.bellasi%40arm.com

Right, I was actually looking for those patches, but I'm searching backwards and hit upon Juri's patches first.

Quoted 7 lines

was actually going in this direction, although still working on top of flags to not change the existing interface too much.

IMO, the advantage of flags is that they are a sort-of "pro-active" approach, where the scheduler notify sensible events to schedutil. But keep adding flags seems to overkilling to me too.

Quoted 5 lines

If we remove flags then we have to query the scheduler classes "on demand"... but, as Peter suggests, once we have DL bits Juri posted, the only issue if to know if an RT task is running.
This the patch above can be just good enough, with no flags at all and with just a check for current being RT (or DL for the time being).

Well, we still need flags for crap like IO-WAIT IIRC. That's sugov internal state and not something the scheduler actually already knows.

But let me continue searching for patches..

Ooh, I found patches from Brendan... should be very close to yours though, going by that msgid you posted on Nov 30th and I'm now on Dec 1st, soooon... :-)

#30 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 39 lines · Peter Zijlstra
Quoted 8 lines · Patrick Bellasi
Quoted 2 lines · Peter Zijlstra

Didn't juri have patches to make DL do something sane? But yes, I think those flags are part of the problem.

He recently reposted them here:

https://lkml.kernel.org/r/[email protected]

Yeah, just found them and actually munged them into my queue; did all the modifications you suggested too. Lets see if it comes apart.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

- From the utilization handler, we check runqueues of all three sched classes to see if they have some work pending (this can be done smartly by checking only RT first and skipping other checks if RT has some work).

No that's wrong. DL should provide a minimum required based on existing reservations, we can add the expected CFS average on top and request that.

Quoted 6 lines
Quoted 2 lines

And for RT all we need to know is if current is of that class, otherwise we don't care.

So, this:

   https://marc.info/?i=20171130114723.29210-3-patrick.bellasi%40arm.com

Right, I was actually looking for those patches, but I'm searching backwards and hit upon Juri's patches first.

Quoted 7 lines

was actually going in this direction, although still working on top of flags to not change the existing interface too much.

IMO, the advantage of flags is that they are a sort-of "pro-active" approach, where the scheduler notify sensible events to schedutil. But keep adding flags seems to overkilling to me too.

Quoted 8 lines
Quoted 5 lines

If we remove flags then we have to query the scheduler classes "on demand"... but, as Peter suggests, once we have DL bits Juri posted, the only issue if to know if an RT task is running.
This the patch above can be just good enough, with no flags at all and with just a check for current being RT (or DL for the time being).

Well, we still need flags for crap like IO-WAIT IIRC. That's sugov internal state and not something the scheduler actually already knows.

Right, that flag is set from:

core.c::io_schedule_prepare()

for the current task, which is going to be dequeued soon.

Once it wakes up the next time, at enqueue time we trigger a boosting by passing schedutil that flag.

Thus, unless we are happy to delay the boosting until the task is actually picked for execution (don't think so), then we need to keep the flag and signal schedutil at enqueue time.

However, was wondering one thing: should't we already have a vruntime bonus for IO sleeping tasks? Because in that case, the task is likely to be on CPU quite soon... and thus, perhaps by removing the flag and moving the schedutil notification into core.c at the end of __schedule() should be working to detect both RT and FAIR::IOWAIT boosted tasks.

... to easy to be possible, should be missing something...

Quoted 3 lines

But let me continue searching for patches..

Ooh, I found patches from Brendan... should be very close to yours

Not sure... AFAIR those patches are for the PELT update of NO_HZ idle CPUs. Their are a "tandem" solution between Brendan and Vincent.

They fix a really important issue... but it's not the same addressed by this patchset or the one I've posted before.

Quoted 2 lines

though, going by that msgid you posted on Nov 30th and I'm now on Dec 1st, soooon... :-)

Signature · 3 lines
#include <best/regards.h>

Patrick Bellasi
#31 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 62 lines · CET Patrick Bellasi
Quoted 39 lines · Peter Zijlstra
Quoted 8 lines · Patrick Bellasi
Quoted 2 lines · Peter Zijlstra

Didn't juri have patches to make DL do something sane? But yes, I think those flags are part of the problem.

He recently reposted them here:

https://lkml.kernel.org/r/[email protected]

Yeah, just found them and actually munged them into my queue; did all the modifications you suggested too. Lets see if it comes apart.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

- From the utilization handler, we check runqueues of all three sched classes to see if they have some work pending (this can be done smartly by checking only RT first and skipping other checks if RT has some work).

No that's wrong. DL should provide a minimum required based on existing reservations, we can add the expected CFS average on top and request that.

Quoted 6 lines
Quoted 2 lines

And for RT all we need to know is if current is of that class, otherwise we don't care.

So, this:

   https://marc.info/?i=20171130114723.29210-3-patrick.bellasi%40arm.com

Right, I was actually looking for those patches, but I'm searching backwards and hit upon Juri's patches first.

Quoted 7 lines

was actually going in this direction, although still working on top of flags to not change the existing interface too much.

IMO, the advantage of flags is that they are a sort-of "pro-active" approach, where the scheduler notify sensible events to schedutil. But keep adding flags seems to overkilling to me too.

Quoted 8 lines
Quoted 5 lines

If we remove flags then we have to query the scheduler classes "on demand"... but, as Peter suggests, once we have DL bits Juri posted, the only issue if to know if an RT task is running.
This the patch above can be just good enough, with no flags at all and with just a check for current being RT (or DL for the time being).

Well, we still need flags for crap like IO-WAIT IIRC. That's sugov internal state and not something the scheduler actually already knows.

Right, that flag is set from:

core.c::io_schedule_prepare()

for the current task, which is going to be dequeued soon.

Once it wakes up the next time, at enqueue time we trigger a boosting by passing schedutil that flag.

Thus, unless we are happy to delay the boosting until the task is actually picked for execution (don't think so), then we need to keep the flag and signal schedutil at enqueue time.

Quoted 6 lines

However, was wondering one thing: should't we already have a vruntime bonus for IO sleeping tasks? Because in that case, the task is likely to be on CPU quite soon... and thus, perhaps by removing the flag and moving the schedutil notification into core.c at the end of __schedule() should be working to detect both RT and FAIR::IOWAIT boosted tasks.

schedutil is not the only user of this flag.

Thanks,
Rafael

#32 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 63 lines · Rafael J. Wysocki
Quoted 62 lines · CET Patrick Bellasi
Quoted 39 lines · Peter Zijlstra
Quoted 8 lines · Patrick Bellasi
Quoted 2 lines · Peter Zijlstra

Didn't juri have patches to make DL do something sane? But yes, I think those flags are part of the problem.

He recently reposted them here:

https://lkml.kernel.org/r/[email protected]

Yeah, just found them and actually munged them into my queue; did all the modifications you suggested too. Lets see if it comes apart.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

- From the utilization handler, we check runqueues of all three sched classes to see if they have some work pending (this can be done smartly by checking only RT first and skipping other checks if RT has some work).

No that's wrong. DL should provide a minimum required based on existing reservations, we can add the expected CFS average on top and request that.

Quoted 6 lines
Quoted 2 lines

And for RT all we need to know is if current is of that class, otherwise we don't care.

So, this:

   https://marc.info/?i=20171130114723.29210-3-patrick.bellasi%40arm.com

Right, I was actually looking for those patches, but I'm searching backwards and hit upon Juri's patches first.

Quoted 7 lines

was actually going in this direction, although still working on top of flags to not change the existing interface too much.

IMO, the advantage of flags is that they are a sort-of "pro-active" approach, where the scheduler notify sensible events to schedutil. But keep adding flags seems to overkilling to me too.

Quoted 8 lines
Quoted 5 lines

If we remove flags then we have to query the scheduler classes "on demand"... but, as Peter suggests, once we have DL bits Juri posted, the only issue if to know if an RT task is running.
This the patch above can be just good enough, with no flags at all and with just a check for current being RT (or DL for the time being).

Well, we still need flags for crap like IO-WAIT IIRC. That's sugov internal state and not something the scheduler actually already knows.

Right, that flag is set from:

core.c::io_schedule_prepare()

for the current task, which is going to be dequeued soon.

Once it wakes up the next time, at enqueue time we trigger a boosting by passing schedutil that flag.

Thus, unless we are happy to delay the boosting until the task is actually picked for execution (don't think so), then we need to keep the flag and signal schedutil at enqueue time.

Quoted 8 lines
Quoted 6 lines

However, was wondering one thing: should't we already have a vruntime bonus for IO sleeping tasks? Because in that case, the task is likely to be on CPU quite soon... and thus, perhaps by removing the flag and moving the schedutil notification into core.c at the end of __schedule() should be working to detect both RT and FAIR::IOWAIT boosted tasks.

schedutil is not the only user of this flag.

Sure, but with the idea above (not completely sure it makes sense) intel_pstate_update_util() can still get the IIOWAIT information.

We just get that info from current->in_iowait instead of checking a flag which is passed in via callback.

Quoted 3 lines

Thanks,
Rafael

Signature · 3 lines
#include <best/regards.h>

Patrick Bellasi
#33 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

In reply to Peter Zijlstra
Quoted 6 lines · CET Peter Zijlstra
Quoted 5 lines · Patrick Bellasi
Quoted 2 lines · Peter Zijlstra

Didn't juri have patches to make DL do something sane? But yes, I think those flags are part of the problem.

Quoted 6 lines
Quoted 3 lines

He recently reposted them here:

https://lkml.kernel.org/r/[email protected]

Yeah, just found them and actually munged them into my queue; did all the modifications you suggested too. Lets see if it comes apart.

Good, because I think that the Juri's patches should go in first.

Then we'll see what's still missing.

Quoted 26 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

- From the utilization handler, we check runqueues of all three sched classes to see if they have some work pending (this can be done smartly by checking only RT first and skipping other checks if RT has some work).

No that's wrong. DL should provide a minimum required based on existing reservations, we can add the expected CFS average on top and request that.

Quoted 6 lines
Quoted 2 lines

And for RT all we need to know is if current is of that class, otherwise we don't care.

So, this:

   https://marc.info/?i=20171130114723.29210-3-patrick.bellasi%40arm.com

Right, I was actually looking for those patches, but I'm searching backwards and hit upon Juri's patches first.

Quoted 7 lines

was actually going in this direction, although still working on top of flags to not change the existing interface too much.

IMO, the advantage of flags is that they are a sort-of "pro-active" approach, where the scheduler notify sensible events to schedutil. But keep adding flags seems to overkilling to me too.

Quoted 8 lines
Quoted 5 lines

If we remove flags then we have to query the scheduler classes "on demand"... but, as Peter suggests, once we have DL bits Juri posted, the only issue if to know if an RT task is running.
This the patch above can be just good enough, with no flags at all and with just a check for current being RT (or DL for the time being).

Well, we still need flags for crap like IO-WAIT IIRC. That's sugov internal state and not something the scheduler actually already knows.

Not only sugov to be precise, but yes.

Thanks,
Rafael

maintainer
#34 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines

Well, we still need flags for crap like IO-WAIT IIRC. That's sugov internal state and not something the scheduler actually already knows.

Not only sugov to be precise, but yes.

Oh, right, intel_pstate also consumes that one..

maintainer
#35 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · CET Peter Zijlstra
Quoted 5 lines · Patrick Bellasi
Quoted 2 lines · Peter Zijlstra

Didn't juri have patches to make DL do something sane? But yes, I think those flags are part of the problem.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

He recently reposted them here:

https://lkml.kernel.org/r/[email protected]

Yeah, just found them and actually munged them into my queue; did all the modifications you suggested too. Lets see if it comes apart.

Good, because I think that the Juri's patches should go in first.

Thanks Peter for taking the patches. I was actually waiting for the flag thing to be resolved to post again. :/

Anyway, let us know how it goes and if I need to make further changes.

Best,

- Juri

maintainer
#36 lore raw

Re: [PATCH 2/4] sched: cpufreq: Keep track of cpufreq utilization update flags

Quoted 2 lines · Juri Lelli

Thanks Peter for taking the patches. I was actually waiting for the flag thing to be resolved to post again. :/

Yeah, I took them because it made sorting that easier, n/p.

author maintainer
#37 lore raw

PATCH 3/4 cpufreq: schedutil: Don't pass flags to sugov_set_iowait_boost()

In reply to Viresh Kumar

We are already passing sg_cpu as argument to sugov_set_iowait_boost() helper and the same can be used to retrieve the flags value. Get rid of the redundant argument.

---
 kernel/sched/cpufreq_schedutil.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
kernel/sched/cpufreq_schedutil.c +4 -5
index 60a2dea4c8cc..7edfdc59ee8f 100644
@@ -187,10 +187,9 @@ static void sugov_get_util(unsigned long *util, unsigned long *max, int cpu)
 	*max = cfs_max;
 }
 
-static void sugov_set_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
-				   unsigned int flags)
+static void sugov_set_iowait_boost(struct sugov_cpu *sg_cpu, u64 time)
 {
-	if (flags & SCHED_CPUFREQ_IOWAIT) {
+	if (sg_cpu->flags & SCHED_CPUFREQ_IOWAIT) {
 		sg_cpu->flags &= ~SCHED_CPUFREQ_IOWAIT;
 
 		if (sg_cpu->iowait_boost_pending)
@@ -273,7 +272,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
 
 	sg_cpu->flags |= flags;
 
-	sugov_set_iowait_boost(sg_cpu, time, flags);
+	sugov_set_iowait_boost(sg_cpu, time);
 	sg_cpu->last_update = time;
 
 	if (!sugov_should_update_freq(sg_policy, time))
@@ -363,7 +362,7 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
 	sg_cpu->max = max;
 	sg_cpu->flags |= flags;
 
-	sugov_set_iowait_boost(sg_cpu, time, flags);
+	sugov_set_iowait_boost(sg_cpu, time);
 	sg_cpu->last_update = time;
 
 	if (sugov_should_update_freq(sg_policy, time)) {
Signature · 1 line
2.15.0.194.g9af6a3dea062
maintainer Reviewed-by on v1 3/4
#38 lore raw

Re: [PATCH 3/4] cpufreq: schedutil: Don't pass flags to sugov_set_iowait_boost()

Hi,

Quoted 5 lines · Viresh Kumar

We are already passing sg_cpu as argument to sugov_set_iowait_boost() helper and the same can be used to retrieve the flags value. Get rid of the redundant argument.

Best,

- Juri

#39 lore raw

[tip:sched/core] sched/cpufreq: Don't pass flags to sugov_set_iowait_boost()

In reply to Viresh Kumar
sched/cpufreq: Don't pass flags to sugov_set_iowait_boost()
Commit-ID:  5083452f8c7a11577e83842596f97625abbc9c8e
Gitweb:     https://git.kernel.org/tip/5083452f8c7a11577e83842596f97625abbc9c8e
Author:     Viresh Kumar <[email protected]>
AuthorDate: Wed, 13 Dec 2017 15:23:22 +0530
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 10 Jan 2018 11:30:29 +0100

sched/cpufreq: Don't pass flags to sugov_set_iowait_boost()

We are already passing sg_cpu as argument to sugov_set_iowait_boost() helper and the same can be used to retrieve the flags value. Get rid of the redundant argument.

---
 kernel/sched/cpufreq_schedutil.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
kernel/sched/cpufreq_schedutil.c +4 -5
index 22d4630..6dd1ec9 100644
@@ -187,10 +187,9 @@ static void sugov_get_util(unsigned long *util, unsigned long *max, int cpu)
 	*max = cfs_max;
 }
 
-static void sugov_set_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
-				   unsigned int flags)
+static void sugov_set_iowait_boost(struct sugov_cpu *sg_cpu, u64 time)
 {
-	if (flags & SCHED_CPUFREQ_IOWAIT) {
+	if (sg_cpu->flags & SCHED_CPUFREQ_IOWAIT) {
 		if (sg_cpu->iowait_boost_pending)
 			return;
 
@@ -264,7 +263,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
 	unsigned int next_f;
 	bool busy;
 
-	sugov_set_iowait_boost(sg_cpu, time, flags);
+	sugov_set_iowait_boost(sg_cpu, time);
 	sg_cpu->last_update = time;
 
 	if (!sugov_should_update_freq(sg_policy, time))
@@ -349,7 +348,7 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
 	sg_cpu->max = max;
 	sg_cpu->flags = flags;
 
-	sugov_set_iowait_boost(sg_cpu, time, flags);
+	sugov_set_iowait_boost(sg_cpu, time);
 	sg_cpu->last_update = time;
 
 	if (sugov_should_update_freq(sg_policy, time)) {
author maintainer
#40 lore raw

PATCH 4/4 cpufreq: schedutil: Don't call sugov_get_util() unnecessarily

In reply to Viresh Kumar

sugov_update_shared() may get called to clear the scheduling class flags and we would return immediately in that case. Calling sugov_get_util() in that case isn't going to be of any use then. Move invocation of sugov_get_util() after the clear flag is checked.

---
 kernel/sched/cpufreq_schedutil.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/cpufreq_schedutil.c +2 -2
index 7edfdc59ee8f..b69c37c867fe 100644
@@ -349,8 +349,6 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
 	unsigned long util, max;
 	unsigned int next_f;
 
-	sugov_get_util(&util, &max, sg_cpu->cpu);
-
 	raw_spin_lock(&sg_policy->update_lock);
 
 	if (unlikely(flags & SCHED_CPUFREQ_CLEAR)) {
@@ -358,6 +356,8 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
 		goto unlock;
 	}
 
+	sugov_get_util(&util, &max, sg_cpu->cpu);
+
 	sg_cpu->util = util;
 	sg_cpu->max = max;
 	sg_cpu->flags |= flags;
Signature · 1 line
2.15.0.194.g9af6a3dea062
maintainer
#41 lore raw

Re: [PATCH 4/4] cpufreq: schedutil: Don't call sugov_get_util() unnecessarily

Hi,

Quoted 24 lines · Viresh Kumar

sugov_update_shared() may get called to clear the scheduling class flags and we would return immediately in that case. Calling sugov_get_util() in that case isn't going to be of any use then. Move invocation of sugov_get_util() after the clear flag is checked.

---
 kernel/sched/cpufreq_schedutil.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/cpufreq_schedutil.c +0 -2
index 7edfdc59ee8f..b69c37c867fe 100644
@@ -349,8 +349,6 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
 	unsigned long util, max;
 	unsigned int next_f;
 
-	sugov_get_util(&util, &max, sg_cpu->cpu);
-
 	raw_spin_lock(&sg_policy->update_lock);
 
 	if (unlikely(flags & SCHED_CPUFREQ_CLEAR)) {

kernel/sched/cpufreq_schedutil.c static void sugov_update_shared(struct update_util_data *hook, u64 time, · line 363

Quoted 8 lines
kernel/sched/cpufreq_schedutil.c +2 -0
@@ -358,6 +356,8 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
 		goto unlock;
 	}
 
+	sugov_get_util(&util, &max, sg_cpu->cpu);
+
 	sg_cpu->util = util;
 	sg_cpu->max = max;
 	sg_cpu->flags |= flags;

It seems that Patrick already posted basically the same change:

https://patchwork.kernel.org/patch/10084669/

Also, Cc-ing him for this.. I just noticed he wasn't Cc-ed to the series.

Best,

- Juri

author maintainer
#42 lore raw

Re: [PATCH 4/4] cpufreq: schedutil: Don't call sugov_get_util() unnecessarily

Quoted 3 lines · Juri Lelli

It seems that Patrick already posted basically the same change:

https://patchwork.kernel.org/patch/10084669/

Yeah, only that the reasoning is completely different from what he had (to which many doubts were raised).

Quoted 1 line

Also, Cc-ing him for this.. I just noticed he wasn't Cc-ed to the series.

I copied everyone in cc from one of Patrick's email and forgot to copy the guy in the From field :)

I have bounced all the emails to him now, he should get them.

Signature · 1 line
viresh
Reviewed-by on v1 4/4
#43 lore raw

Re: [PATCH 4/4] cpufreq: schedutil: Don't call sugov_get_util() unnecessarily

In reply to Viresh Kumar
Quoted 24 lines · Viresh Kumar

sugov_update_shared() may get called to clear the scheduling class flags and we would return immediately in that case. Calling sugov_get_util() in that case isn't going to be of any use then. Move invocation of sugov_get_util() after the clear flag is checked.

---
 kernel/sched/cpufreq_schedutil.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/cpufreq_schedutil.c +0 -2
index 7edfdc59ee8f..b69c37c867fe 100644
@@ -349,8 +349,6 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
        unsigned long util, max;
        unsigned int next_f;
 
-       sugov_get_util(&util, &max, sg_cpu->cpu);
-
        raw_spin_lock(&sg_policy->update_lock);
 
        if (unlikely(flags & SCHED_CPUFREQ_CLEAR)) {

kernel/sched/cpufreq_schedutil.c static void sugov_update_shared(struct update_util_data *hook, u64 time, · line 361

Quoted 6 lines
kernel/sched/cpufreq_schedutil.c +2 -0
@@ -358,6 +356,8 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
                goto unlock;
        }
 
+       sugov_get_util(&util, &max, sg_cpu->cpu);
+
        sg_cpu->util = util;

Thanks,

- Joel