Fix SCHED_DEADLINE bandwidth accounting during suspend
Subsystems (4)
Juri Lelli
maintainerv2 cover Fix SCHED_DEADLINE bandwidth accounting during suspend
Hello!
Jon reported [1] a suspend regression on a Tegra board configured to boot with isolcpus and bisected it to commit 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug").
Root cause analysis pointed out that we are currently failing to correctly clear and restore bandwidth accounting on root domains after changes that initiate from partition_sched_domains(), as it is the case for suspend operations on that board.
This is v2 [2] of the proposed approach to fix the issue. With respect to v1, the following implements the approach by:
- 01: filter out DEADLINE special tasks
- 02: preparatory wrappers to be able to grab sched_domains_mutex on UP (remove !SMP wrappers - Waiman)
- 03: generalize unique visiting of root domains so that we can re-use the mechanism elsewhere
- 04: the bulk of the approach, clean and rebuild after changes
- 05: clean up a now redundant call
- 06: remove partition_and_rebuild_sched_domains() (Waiman)
- 07: stop exposing partition_sched_domains_locked (Waiman)
Please test and review. The set is also available at
[email protected]:jlelli/linux.git upstream/deadline/domains-suspend
Best,
Juri
1 - https://lore.kernel.org/lkml/[email protected]/
2 - v1 https://lore.kernel.org/lkml/[email protected]
Juri Lelli (8):
sched/deadline: Ignore special tasks when rebuilding domains sched/topology: Wrappers for sched_domains_mutex sched/deadline: Generalize unique visiting of root domains sched/deadline: Rebuild root domain accounting after every update sched/topology: Remove redundant dl_clear_root_domain call cgroup/cpuset: Remove partition_and_rebuild_sched_domains sched/topology: Stop exposing partition_sched_domains_locked include/{topology,cpuset}: Move dl_rebuild_rd_accounting to cpuset.h
include/linux/cpuset.h | 5 +++++ include/linux/sched.h | 2 ++ include/linux/sched/deadline.h | 7 +++++++ include/linux/sched/topology.h | 10 --------- kernel/cgroup/cpuset.c | 27 +++++++++---------------- kernel/sched/core.c | 4 ++-- kernel/sched/deadline.c | 37 ++++++++++++++++++++-------------- kernel/sched/debug.c | 8 ++++---- kernel/sched/rt.c | 2 ++ kernel/sched/sched.h | 2 +- kernel/sched/topology.c | 32 +++++++++++++---------------- 11 files changed, 69 insertions(+), 67 deletions(-)
base-commit: 48a5eed9ad584315c30ed35204510536235ce402
Signature · 1 line
2.48.1
Juri Lelli
maintainerPATCH v2 1/8 sched/deadline: Ignore special tasks when rebuilding domains
SCHED_DEADLINE special tasks get a fake bandwidth that is only used to make sure sleeping and priority inheritance 'work', but it is ignored for runtime enforcement and admission control.
Be consistent with it also when rebuilding root domains.
--- kernel/sched/deadline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/deadline.c +1 -1
@@ -2956,7 +2956,7 @@ void dl_add_task_root_domain(struct task_struct *p)struct dl_bw *dl_b;raw_spin_lock_irqsave (&p->pi_lock, rf.flags); -if (!dl_task (p)) { +if (!dl_task (p) ||dl_entity_is_special (&p->dl)) {raw_spin_unlock_irqrestore (&p->pi_lock, rf.flags);return ; }
Signature · 1 line
2.48.1
Juri Lelli
maintainerPATCH v2 2/8 sched/topology: Wrappers for sched_domains_mutex
In reply to Juri LelliCreate wrappers for sched_domains_mutex so that it can transparently be used on both CONFIG_SMP and !CONFIG_SMP, as some function will need to do.
---
v1 -> v2: Remove wrappers for the !SMP case as all users are not defined
either in that case
--- include/linux/sched.h | 2 ++ kernel/cgroup/cpuset.c | 4 ++-- kernel/sched/core.c | 4 ++-- kernel/sched/debug.c | 8 ++++---- kernel/sched/topology.c | 12 ++++++++++-- 5 files changed, 20 insertions(+), 10 deletions(-)
include/linux/sched.h +2 -0
@@ -383,6 +383,8 @@ enum uclamp_id {extern struct root_domain def_root_domain;extern struct mutex sched_domains_mutex;#endif +extern void sched_domains_mutex_lock (void ); +extern void sched_domains_mutex_unlock (void );struct sched_param {int sched_priority;
kernel/cgroup/cpuset.c +2 -2
@@ -994,10 +994,10 @@ static void partition_and_rebuild_sched_domains(int ndoms_new, cpumask_var_t doms_new[], struct sched_domain_attr *dattr_new) { - mutex_lock(&sched_domains_mutex); +sched_domains_mutex_lock ();partition_sched_domains_locked (ndoms_new, doms_new, dattr_new);dl_rebuild_rd_accounting (); -mutex_unlock (&sched_domains_mutex); +sched_domains_mutex_unlock (); }/*
kernel/sched/core.c +2 -2
@@ -8424,9 +8424,9 @@ void __init sched_init_smp(void)* CPU masks are stable and all blatant races in the below code cannot * happen. */ -mutex_lock (&sched_domains_mutex); +sched_domains_mutex_lock ();sched_init_domains (cpu_active_mask); -mutex_unlock (&sched_domains_mutex); +sched_domains_mutex_unlock ();/* Move init over to a non-isolated CPU */ if (set_cpus_allowed_ptr (current,housekeeping_cpumask (HK_TYPE_DOMAIN )) <0 )
kernel/sched/debug.c +4 -4
@@ -292,7 +292,7 @@ static ssize_t sched_verbose_write(struct file *filp, const char __user *ubuf,bool orig;cpus_read_lock (); -mutex_lock (&sched_domains_mutex); +sched_domains_mutex_lock (); orig = sched_debug_verbose; result =debugfs_write_file_bool (filp, ubuf, cnt, ppos);
@@ -304,7 +304,7 @@ static ssize_t sched_verbose_write(struct file *filp, const char __user *ubuf, sd_dentry =NULL ; } -mutex_unlock (&sched_domains_mutex); +sched_domains_mutex_unlock ();cpus_read_unlock ();return result;
@@ -515,9 +515,9 @@ static __init int sched_init_debug(void)debugfs_create_u32 ("migration_cost_ns" ,0644 , debugfs_sched, &sysctl_sched_migration_cost);debugfs_create_u32 ("nr_migrate" ,0644 , debugfs_sched, &sysctl_sched_nr_migrate); -mutex_lock (&sched_domains_mutex); +sched_domains_mutex_lock ();update_sched_domain_debugfs (); -mutex_unlock (&sched_domains_mutex); +sched_domains_mutex_unlock ();#endif #ifdef CONFIG_NUMA_BALANCING
kernel/sched/topology.c +10 -2
@@ -6,6 +6,14 @@#include <linux/bsearch.h> DEFINE_MUTEX (sched_domains_mutex); +void sched_domains_mutex_lock (void ) +{ +mutex_lock (&sched_domains_mutex); +} +void sched_domains_mutex_unlock (void ) +{ +mutex_unlock (&sched_domains_mutex); +}/* Protected by sched_domains_mutex: */ static cpumask_var_t sched_domains_tmpmask;
@@ -2791,7 +2799,7 @@ void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[],void partition_sched_domains (int ndoms_new,cpumask_var_t doms_new[],struct sched_domain_attr *dattr_new) { -mutex_lock (&sched_domains_mutex); +sched_domains_mutex_lock ();partition_sched_domains_locked (ndoms_new, doms_new, dattr_new); -mutex_unlock (&sched_domains_mutex); +sched_domains_mutex_unlock (); }
Signature · 1 line
2.48.1
Re: [PATCH v2 2/8] sched/topology: Wrappers for sched_domains_mutex
Hi Juri.
Quoted 118 lines · Juri Lelli
Create wrappers for
sched_domains_mutexso that it can transparently be used on bothCONFIG_SMPand !CONFIG_SMP, as some function will need to do.Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug")Signed-off-by Juri Lelli <[email protected]>---
v1 -> v2: Remove wrappers for the !SMP case as all users are not defined
either in that case--- include/linux/sched.h | 2 ++ kernel/cgroup/cpuset.c | 4 ++-- kernel/sched/core.c | 4 ++-- kernel/sched/debug.c | 8 ++++---- kernel/sched/topology.c | 12 ++++++++++-- 5 files changed, 20 insertions(+), 10 deletions(-)include/linux/sched.h +2
-0@@ -383,6 +383,8 @@ enum uclamp_id {extern struct root_domain def_root_domain;extern struct mutex sched_domains_mutex;#endif +extern void sched_domains_mutex_lock (void ); +extern void sched_domains_mutex_unlock (void );struct sched_param {int sched_priority;kernel/cgroup/cpuset.c +2
-2@@ -994,10 +994,10 @@ static void partition_and_rebuild_sched_domains(int ndoms_new, cpumask_var_t doms_new[], struct sched_domain_attr *dattr_new) { - mutex_lock(&sched_domains_mutex); +sched_domains_mutex_lock ();partition_sched_domains_locked (ndoms_new, doms_new, dattr_new);dl_rebuild_rd_accounting (); -mutex_unlock (&sched_domains_mutex); +sched_domains_mutex_unlock (); }/* kernel/sched/core.c +2
-2@@ -8424,9 +8424,9 @@ void __init sched_init_smp(void)* CPU masks are stable and all blatant races in the below code cannot * happen. */ -mutex_lock (&sched_domains_mutex); +sched_domains_mutex_lock ();sched_init_domains (cpu_active_mask); -mutex_unlock (&sched_domains_mutex); +sched_domains_mutex_unlock ();/* Move init over to a non-isolated CPU */ if (set_cpus_allowed_ptr (current,housekeeping_cpumask (HK_TYPE_DOMAIN )) <0 )kernel/sched/debug.c +4
-4@@ -292,7 +292,7 @@ static ssize_t sched_verbose_write(struct file *filp, const char __user *ubuf,bool orig;cpus_read_lock (); -mutex_lock (&sched_domains_mutex); +sched_domains_mutex_lock (); orig = sched_debug_verbose; result =debugfs_write_file_bool (filp, ubuf, cnt, ppos);@@ -304,7 +304,7 @@ static ssize_t sched_verbose_write(struct file *filp, const char __user *ubuf, sd_dentry =NULL ; } -mutex_unlock (&sched_domains_mutex); +sched_domains_mutex_unlock ();cpus_read_unlock ();return result;@@ -515,9 +515,9 @@ static __init int sched_init_debug(void)debugfs_create_u32 ("migration_cost_ns" ,0644 , debugfs_sched, &sysctl_sched_migration_cost);debugfs_create_u32 ("nr_migrate" ,0644 , debugfs_sched, &sysctl_sched_nr_migrate); -mutex_lock (&sched_domains_mutex); +sched_domains_mutex_lock ();update_sched_domain_debugfs (); -mutex_unlock (&sched_domains_mutex); +sched_domains_mutex_unlock ();#endif #ifdef CONFIG_NUMA_BALANCING kernel/sched/topology.c +8
-0@@ -6,6 +6,14 @@#include <linux/bsearch.h> DEFINE_MUTEX (sched_domains_mutex); +void sched_domains_mutex_lock (void ) +{ +mutex_lock (&sched_domains_mutex); +} +void sched_domains_mutex_unlock (void ) +{ +mutex_unlock (&sched_domains_mutex); +}/* Protected by sched_domains_mutex: */ static cpumask_var_t sched_domains_tmpmask;
kernel/sched/topology.c void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[], · line 2805
Quoted 9 lines
kernel/sched/topology.c +2
-2@@ -2791,7 +2799,7 @@ void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[],void partition_sched_domains (int ndoms_new,cpumask_var_t doms_new[],struct sched_domain_attr *dattr_new) { -mutex_lock (&sched_domains_mutex); +sched_domains_mutex_lock ();partition_sched_domains_locked (ndoms_new, doms_new, dattr_new); -mutex_unlock (&sched_domains_mutex); +sched_domains_mutex_unlock (); }
Maybe sched_domains_mutex can be static since its only used in topology.c ?
Other than the above
Juri Lelli
maintainerRe: [PATCH v2 2/8] sched/topology: Wrappers for sched_domains_mutex
Hi,
Thanks for the overall review!
Quoted 6 lines · Shrikanth Hegde
Hi Juri.
Quoted 3 lines · Juri Lelli
Create wrappers for
sched_domains_mutexso that it can transparently be used on bothCONFIG_SMPand !CONFIG_SMP, as some function will need to do.
...
Quoted 1 line
Maybe
sched_domains_mutexcan be static since its only used intopology.c?
We have a lockdep_assert in cpuset.c, don't we? We can create another wrapper for that, but I am not sure it is going to be cleaner.
Thanks,
Juri
Re: [PATCH v2 2/8] sched/topology: Wrappers for sched_domains_mutex
Quoted 12 lines · Juri Lelli
Hi,
Thanks for the overall review!
Quoted 6 lines · Shrikanth Hegde
Hi Juri.
Quoted 3 lines · Juri Lelli
Create wrappers for
sched_domains_mutexso that it can transparently be used on bothCONFIG_SMPand !CONFIG_SMP, as some function will need to do.
Quoted 6 lines
...
Quoted 1 line
Maybe
sched_domains_mutexcan be static since its only used intopology.c?We have a
lockdep_assertincpuset.c, don't we? We can create another wrapper for that, but I am not sure it is going to be cleaner.
Ok. Sorry, my bad. I searched only in kernel/sched. You can ignore this comment.
Quoted 4 lines
Thanks,
Juri
Re: [PATCH v2 2/8] sched/topology: Wrappers for sched_domains_mutex
In reply to Juri LelliQuoted 23 lines · Juri Lelli
Create wrappers for
sched_domains_mutexso that it can transparently be used on bothCONFIG_SMPand !CONFIG_SMP, as some function will need to do.Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug")Signed-off-by Juri Lelli <[email protected]>---
v1 -> v2: Remove wrappers for the !SMP case as all users are not defined
either in that case--- include/linux/sched.h | 2 ++ kernel/cgroup/cpuset.c | 4 ++-- kernel/sched/core.c | 4 ++-- kernel/sched/debug.c | 8 ++++---- kernel/sched/topology.c | 12 ++++++++++-- 5 files changed, 20 insertions(+), 10 deletions(-)include/linux/sched.h +0
-0
include/linux/sched.h enum uclamp_id { · line 387
Quoted 5 lines
include/linux/sched.h +2
-0@@ -383,6 +383,8 @@ enum uclamp_id {extern struct root_domain def_root_domain;extern struct mutex sched_domains_mutex;#endif +extern void sched_domains_mutex_lock (void ); +extern void sched_domains_mutex_unlock (void );
As discussed in the other thread, move the sched_domains_mutex_{lock/unlock}{} inside the "#if CONFIG_SMP" block and define the else part so that it can be used in code block that will also be compiled in the !CONFIG_SMP case.
Other than that, the rest looks good to me.
Cheers,
Longman
Juri Lelli
maintainerRe: [PATCH v2 2/8] sched/topology: Wrappers for sched_domains_mutex
Quoted 19 lines · Waiman Long
Quoted 18 lines · Juri Lelli
Create wrappers for
sched_domains_mutexso that it can transparently be used on bothCONFIG_SMPand !CONFIG_SMP, as some function will need to do.Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug")Signed-off-by Juri Lelli <[email protected]>---
v1 -> v2: Remove wrappers for the !SMP case as all users are not defined
either in that case--- include/linux/sched.h | 2 ++ kernel/cgroup/cpuset.c | 4 ++-- kernel/sched/core.c | 4 ++-- kernel/sched/debug.c | 8 ++++---- kernel/sched/topology.c | 12 ++++++++++-- 5 files changed, 20 insertions(+), 10 deletions(-)
Quoted 15 lines
include/linux/sched.h enum uclamp_id { · line 387
Quoted 10 lines
include/linux/sched.h +2
-0@@ -383,6 +383,8 @@ enum uclamp_id {extern struct root_domain def_root_domain;extern struct mutex sched_domains_mutex;#endif +extern void sched_domains_mutex_lock (void ); +extern void sched_domains_mutex_unlock (void );As discussed in the other thread, move the sched_domains_mutex_{lock/unlock}{} inside the "#if
CONFIG_SMP" block and define the else part so that it can be used in code block that will also be compiled in the !CONFIG_SMP case.
Ack.
Quoted 1 line
Other than that, the rest looks good to me.
Thanks! I will be sending out a v3 early next week (waiting a few more hours in case anyone spots something else that needs rework).
Best,
Juri
Re: [PATCH v2 2/8] sched/topology: Wrappers for sched_domains_mutex
In reply to Waiman LongQuoted 32 lines · Waiman Long
Quoted 23 lines · Juri Lelli
Create wrappers for
sched_domains_mutexso that it can transparently be used on bothCONFIG_SMPand !CONFIG_SMP, as some function will need to do.Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug")Signed-off-by Juri Lelli <[email protected]>---
v1 -> v2: Remove wrappers for the !SMP case as all users are not defined either in that case
---
include/linux/sched.h | 2 ++
kernel/cgroup/cpuset.c | 4 ++--
kernel/sched/core.c | 4 ++--
kernel/sched/debug.c | 8 ++++----kernel/sched/topology.c| 12 ++++++++++--5 files changed, 20 insertions(+), 10 deletions(-)include/linux/sched.h +0
-0include/linux/sched.h enum uclamp_id { · line 387
Quoted 5 lines
include/linux/sched.h +2
-0@@ -383,6 +383,8 @@ enum uclamp_id { extern struct root_domain def_root_domain; extern struct mutex sched_domains_mutex; #endif +extern void sched_domains_mutex_lock (void ); +extern void sched_domains_mutex_unlock (void );As discussed in the other thread, move the sched_domains_mutex_{lock/unlock}{} inside the "#if
CONFIG_SMP" block and define the else part so that it can be used in code block that will also be compiled in the !CONFIG_SMP case.
Quoted 1 line
Other than that, the rest looks good to me.
Actually, you can also remove sched_domains_mutex from the header and make it static as it is no longer directly accessed.
Cheers,
Longman
Juri Lelli
maintainerRe: [PATCH v2 2/8] sched/topology: Wrappers for sched_domains_mutex
Quoted 38 lines · Waiman Long
Quoted 36 lines · Waiman Long
Quoted 24 lines · Juri Lelli
Create wrappers for
sched_domains_mutexso that it can transparently be used on bothCONFIG_SMPand !CONFIG_SMP, as some function will need to do.Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflowearlier for hotplug")
Signed-off-by Juri Lelli <[email protected]>---
v1 -> v2: Remove wrappers for the !SMP case as all users are not defined either in that case
---
include/linux/sched.h | 2 ++
kernel/cgroup/cpuset.c | 4 ++--
kernel/sched/core.c | 4 ++--
kernel/sched/debug.c | 8 ++++----kernel/sched/topology.c| 12 ++++++++++--5 files changed, 20 insertions(+), 10 deletions(-)include/linux/sched.h +0
-0include/linux/sched.h enum uclamp_id { · line 387
Quoted 5 lines
include/linux/sched.h +2
-0@@ -383,6 +383,8 @@ enum uclamp_id { extern struct root_domain def_root_domain; extern struct mutex sched_domains_mutex; #endif +extern void sched_domains_mutex_lock (void ); +extern void sched_domains_mutex_unlock (void );As discussed in the other thread, move the sched_domains_mutex_{lock/unlock}{} inside the "#if
CONFIG_SMP" block and define the else part so that it can be used in code block that will also be compiled in the !CONFIG_SMP case.
Quoted 4 lines
Quoted 1 line
Other than that, the rest looks good to me.
Actually, you can also remove
sched_domains_mutexfrom the header and make it static as it is no longer directly accessed.
Apart from a lockdep_assert_held() in cpuset.c, no? Guess I can create a wrapper for that, but is it really better?
Thanks,
Juri
Re: [PATCH v2 2/8] sched/topology: Wrappers for sched_domains_mutex
Quoted 37 lines · Juri Lelli
Quoted 36 lines · Waiman Long
Quoted 35 lines · Waiman Long
Quoted 24 lines · Juri Lelli
Create wrappers for
sched_domains_mutexso that it can transparently be used on bothCONFIG_SMPand !CONFIG_SMP, as some function will need to do.Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflowearlier for hotplug")
Signed-off-by Juri Lelli <[email protected]>---
v1 -> v2: Remove wrappers for the !SMP case as all users are not defined
either in that case--- include/linux/sched.h | 2 ++ kernel/cgroup/cpuset.c | 4 ++-- kernel/sched/core.c | 4 ++-- kernel/sched/debug.c | 8 ++++---- kernel/sched/topology.c | 12 ++++++++++-- 5 files changed, 20 insertions(+), 10 deletions(-)include/linux/sched.h +0
-0include/linux/sched.h enum uclamp_id { · line 387
Quoted 5 lines
include/linux/sched.h +2
-0@@ -383,6 +383,8 @@ enum uclamp_id { extern struct root_domain def_root_domain; extern struct mutex sched_domains_mutex; #endif +extern void sched_domains_mutex_lock (void ); +extern void sched_domains_mutex_unlock (void );As discussed in the other thread, move the sched_domains_mutex_{lock/unlock}{} inside the "#if
CONFIG_SMP" block and define the else part so that it can be used in code block that will also be compiled in the !CONFIG_SMP case.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Other than that, the rest looks good to me.
Actually, you can also remove
sched_domains_mutexfrom the header and make it static as it is no longer directly accessed.Apart from a
lockdep_assert_held()incpuset.c, no? Guess I can create a wrapper for that, but is it really better?
I forgot about that. Please ignore this comment.
Thanks,
Longman
Juri Lelli
maintainerPATCH v2 3/8 sched/deadline: Generalize unique visiting of root domains
In reply to Juri LelliBandwidth checks and updates that work on root domains currently employ a cookie mechanism for efficiency. This mechanism is very much tied to when root domains are first created and initialized.
Generalize the cookie mechanism so that it can be used also later at runtime while updating root domains. Also, additionally guard it with sched_domains_mutex, since domains need to be stable while updating them (and it will be required for further dynamic changes).
--- include/linux/sched/deadline.h | 3 +++ kernel/sched/deadline.c | 23 +++++++++++++---------- kernel/sched/rt.c | 2 ++ kernel/sched/sched.h | 2 +- kernel/sched/topology.c | 2 +- 5 files changed, 20 insertions(+), 12 deletions(-)
include/linux/sched/deadline.h +3 -0
@@ -37,4 +37,7 @@ extern void dl_clear_root_domain(struct root_domain *rd);#endif /* CONFIG_SMP */ +extern u64 dl_cookie; +extern bool dl_bw_visited (int cpu,u64 cookie); +#endif /* _LINUX_SCHED_DEADLINE_H */
kernel/sched/deadline.c +13 -10
@@ -166,14 +166,14 @@ static inline unsigned long dl_bw_capacity(int i) } } -static inline bool dl_bw_visited (int cpu,u64 gen) +static inline bool dl_bw_visited (int cpu,u64 cookie) {struct root_domain *rd =cpu_rq (cpu)->rd; -if (rd->visit_gen == gen) +if (rd->visit_cookie == cookie)return true; - rd->visit_gen = gen; + rd->visit_cookie = cookie;return false; }
@@ -207,7 +207,7 @@ static inline unsigned long dl_bw_capacity(int i)return SCHED_CAPACITY_SCALE ; } -static inline bool dl_bw_visited (int cpu,u64 gen) +static inline bool dl_bw_visited (int cpu,u64 cookie) {return false; }
@@ -3171,15 +3171,18 @@ DEFINE_SCHED_CLASS(dl) = {#endif }; -/* Used for dl_bw check and update, used under sched_rt_handler()::mutex */ -static u64 dl_generation; +/* +* Used for dl_bw check and update, used under sched_rt_handler()::mutex and +* sched_domains_mutex. +*/ +u64 dl_cookie;int sched_dl_global_validate (void ) {u64 runtime =global_rt_runtime ();u64 period =global_rt_period ();u64 new_bw =to_ratio (period, runtime); -u64 gen = ++dl_generation; +u64 cookie = ++dl_cookie;struct dl_bw *dl_b;int cpu, cpus, ret =0 ;unsigned long flags;
@@ -3192,7 +3195,7 @@ int sched_dl_global_validate(void)for_each_possible_cpu (cpu) {rcu_read_lock_sched (); -if (dl_bw_visited (cpu, gen)) +if (dl_bw_visited (cpu, cookie)) goto next; dl_b =dl_bw_of (cpu);
@@ -3229,7 +3232,7 @@ static void init_dl_rq_bw_ratio(struct dl_rq *dl_rq)void sched_dl_do_global (void ) {u64 new_bw =-1 ; -u64 gen = ++dl_generation; +u64 cookie = ++dl_cookie;struct dl_bw *dl_b;int cpu;unsigned long flags;
@@ -3240,7 +3243,7 @@ void sched_dl_do_global(void)for_each_possible_cpu (cpu) {rcu_read_lock_sched (); -if (dl_bw_visited (cpu, gen)) { +if (dl_bw_visited (cpu, cookie)) {rcu_read_unlock_sched ();continue ; }
kernel/sched/rt.c +2 -0
@@ -2910,6 +2910,7 @@ static int sched_rt_handler(const struct ctl_table *table, int write, void *buffint ret;mutex_lock (&mutex); +sched_domains_mutex_lock (); old_period = sysctl_sched_rt_period; old_runtime = sysctl_sched_rt_runtime;
@@ -2936,6 +2937,7 @@ static int sched_rt_handler(const struct ctl_table *table, int write, void *buff sysctl_sched_rt_period = old_period; sysctl_sched_rt_runtime = old_runtime; } +sched_domains_mutex_unlock ();mutex_unlock (&mutex);return ret;
kernel/sched/sched.h +1 -1
@@ -998,7 +998,7 @@ struct root_domain {* Also, some corner cases, like 'wrap around' is dangerous, but given * that u64 is 'big enough'. So that shouldn't be a concern. */ -u64 visit_gen; +u64 visit_cookie;#ifdef HAVE_RT_PUSH_IPI /*
kernel/sched/topology.c +1 -1
@@ -568,7 +568,7 @@ static int init_rootdomain(struct root_domain *rd) rd->rto_push_work =IRQ_WORK_INIT_HARD (rto_push_irq_work_func);#endif - rd->visit_gen =0 ; + rd->visit_cookie =0 ;init_dl_bw (&rd->dl_bw);if (cpudl_init (&rd->cpudl) !=0 ) goto free_rto_mask;
Signature · 1 line
2.48.1
Re: [PATCH v2 3/8] sched/deadline: Generalize unique visiting of root domains
Quoted 86 lines · Juri Lelli
Bandwidth checks and updates that work on root domains currently employ a cookie mechanism for efficiency. This mechanism is very much tied to when root domains are first created and initialized.
Generalize the cookie mechanism so that it can be used also later at runtime while updating root domains. Also, additionally guard it with
sched_domains_mutex, since domains need to be stable while updating them (and it will be required for further dynamic changes).Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug")Signed-off-by Juri Lelli <[email protected]>--- include/linux/sched/deadline.h | 3 +++ kernel/sched/deadline.c | 23 +++++++++++++---------- kernel/sched/rt.c | 2 ++ kernel/sched/sched.h | 2 +- kernel/sched/topology.c | 2 +- 5 files changed, 20 insertions(+), 12 deletions(-)include/linux/sched/deadline.h +3
-0@@ -37,4 +37,7 @@ extern void dl_clear_root_domain(struct root_domain *rd);#endif /* CONFIG_SMP */ +extern u64 dl_cookie; +extern bool dl_bw_visited (int cpu,u64 cookie); +#endif /* _LINUX_SCHED_DEADLINE_H */ kernel/sched/deadline.c +10
-7@@ -166,14 +166,14 @@ static inline unsigned long dl_bw_capacity(int i) } } -static inline bool dl_bw_visited (int cpu,u64 gen) +static inline bool dl_bw_visited (int cpu,u64 cookie) {struct root_domain *rd =cpu_rq (cpu)->rd; -if (rd->visit_gen == gen) +if (rd->visit_cookie == cookie)return true; - rd->visit_gen = gen; + rd->visit_cookie = cookie;return false; }@@ -207,7 +207,7 @@ static inline unsigned long dl_bw_capacity(int i)return SCHED_CAPACITY_SCALE ; } -static inline bool dl_bw_visited (int cpu,u64 gen) +static inline bool dl_bw_visited (int cpu,u64 cookie) {return false; }@@ -3171,15 +3171,18 @@ DEFINE_SCHED_CLASS(dl) = {#endif }; -/* Used for dl_bw check and update, used under sched_rt_handler()::mutex */ -static u64 dl_generation; +/* +* Used for dl_bw check and update, used under sched_rt_handler()::mutex and +* sched_domains_mutex. +*/ +u64 dl_cookie;int sched_dl_global_validate (void ) {u64 runtime =global_rt_runtime ();u64 period =global_rt_period ();u64 new_bw =to_ratio (period, runtime); -u64 gen = ++dl_generation; +u64 cookie = ++dl_cookie;struct dl_bw *dl_b;int cpu, cpus, ret =0 ;unsigned long flags;
kernel/sched/deadline.c int sched_dl_global_validate(void) · line 3195
Quoted 1 line
kernel/sched/deadline.c +0
-0@@ -3192,7 +3195,7 @@ int sched_dl_global_validate(void)for_each_possible_cpu (cpu) {
This has been changed in 14672f059d83f591afb2ee1fff56858efe055e5a to online CPUs. So patch didn't apply cleanly to me.
Quoted 71 lines
kernel/sched/deadline.c +3
-3rcu_read_lock_sched (); -if (dl_bw_visited (cpu, gen)) +if (dl_bw_visited (cpu, cookie)) goto next; dl_b =dl_bw_of (cpu);@@ -3229,7 +3232,7 @@ static void init_dl_rq_bw_ratio(struct dl_rq *dl_rq)void sched_dl_do_global (void ) {u64 new_bw =-1 ; -u64 gen = ++dl_generation; +u64 cookie = ++dl_cookie;struct dl_bw *dl_b;int cpu;unsigned long flags;@@ -3240,7 +3243,7 @@ void sched_dl_do_global(void)for_each_possible_cpu (cpu) {rcu_read_lock_sched (); -if (dl_bw_visited (cpu, gen)) { +if (dl_bw_visited (cpu, cookie)) {rcu_read_unlock_sched ();continue ; }kernel/sched/rt.c +2
-0@@ -2910,6 +2910,7 @@ static int sched_rt_handler(const struct ctl_table *table, int write, void *buffint ret;mutex_lock (&mutex); +sched_domains_mutex_lock (); old_period = sysctl_sched_rt_period; old_runtime = sysctl_sched_rt_runtime;@@ -2936,6 +2937,7 @@ static int sched_rt_handler(const struct ctl_table *table, int write, void *buff sysctl_sched_rt_period = old_period; sysctl_sched_rt_runtime = old_runtime; } +sched_domains_mutex_unlock ();mutex_unlock (&mutex);return ret;kernel/sched/sched.h +1
-1@@ -998,7 +998,7 @@ struct root_domain {* Also, some corner cases, like 'wrap around' is dangerous, but given * that u64 is 'big enough'. So that shouldn't be a concern. */ -u64 visit_gen; +u64 visit_cookie;#ifdef HAVE_RT_PUSH_IPI /* kernel/sched/topology.c +1
-1@@ -568,7 +568,7 @@ static int init_rootdomain(struct root_domain *rd) rd->rto_push_work =IRQ_WORK_INIT_HARD (rto_push_irq_work_func);#endif - rd->visit_gen =0 ; + rd->visit_cookie =0 ;init_dl_bw (&rd->dl_bw);if (cpudl_init (&rd->cpudl) !=0 ) goto free_rto_mask;
Juri Lelli
maintainerRe: [PATCH v2 3/8] sched/deadline: Generalize unique visiting of root domains
Quoted 15 lines · Shrikanth Hegde
Quoted 12 lines · Juri Lelli
Bandwidth checks and updates that work on root domains currently employ a cookie mechanism for efficiency. This mechanism is very much tied to when root domains are first created and initialized.
Generalize the cookie mechanism so that it can be used also later at runtime while updating root domains. Also, additionally guard it with
sched_domains_mutex, since domains need to be stable while updating them (and it will be required for further dynamic changes).Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug")Signed-off-by Juri Lelli <[email protected]>
...
Quoted 6 lines
Review int sched_dl_global_validate(void) · line 3195
Quoted 2 lines
(quoted diff) +0
-0@@ -3192,7 +3195,7 @@ int sched_dl_global_validate(void) for_each_possible_cpu(cpu) {This has been changed in
14672f059d83f591afb2ee1fff56858efe055e5ato online CPUs. So patch didn't apply cleanly to me.
I based the set on Linus' tree (base commit in the cover letter) as it is modifying both sched and cgroup bits. Your fix hasn't yet be merged into Linus' I believe.
Thanks,
Juri
Juri Lelli
maintainerPATCH v2 4/8 sched/deadline: Rebuild root domain accounting after every update
In reply to Juri LelliRebuilding of root domains accounting information (total_bw) is currently broken on some cases, e.g. suspend/resume on aarch64. Problem is that the way we keep track of domain changes and try to add bandwidth back is convoluted and fragile.
Fix it by simplify things by making sure bandwidth accounting is cleared and completely restored after root domains changes (after root domains are again stable).
--- include/linux/sched/deadline.h | 4 ++++ include/linux/sched/topology.h | 2 ++ kernel/cgroup/cpuset.c | 16 +++++++++------- kernel/sched/deadline.c | 16 ++++++++++------ kernel/sched/topology.c | 1 + 5 files changed, 26 insertions(+), 13 deletions(-)
include/linux/sched/deadline.h +4 -0
@@ -34,6 +34,10 @@ static inline bool dl_time_before(u64 a, u64 b)struct root_domain ;extern void dl_add_task_root_domain (struct task_struct *p);extern void dl_clear_root_domain (struct root_domain *rd); +extern void dl_clear_root_domain_cpu (int cpu); + +extern u64 dl_cookie; +extern bool dl_bw_visited (int cpu,u64 gen);#endif /* CONFIG_SMP */
include/linux/sched/topology.h +2 -0
@@ -166,6 +166,8 @@ static inline struct cpumask *sched_domain_span(struct sched_domain *sd)return to_cpumask (sd->span); } +extern void dl_rebuild_rd_accounting (void ); +extern void partition_sched_domains_locked (int ndoms_new,cpumask_var_t doms_new[],struct sched_domain_attr *dattr_new);
kernel/cgroup/cpuset.c +9 -7
@@ -954,10 +954,12 @@ static void dl_update_tasks_root_domain(struct cpuset *cs)css_task_iter_end (&it); } -static void dl_rebuild_rd_accounting (void ) +void dl_rebuild_rd_accounting (void ) {struct cpuset *cs =NULL ;struct cgroup_subsys_state *pos_css; +int cpu; +u64 cookie = ++dl_cookie;lockdep_assert_held (&cpuset_mutex);lockdep_assert_cpus_held ();
@@ -965,11 +967,12 @@ static void dl_rebuild_rd_accounting(void)rcu_read_lock (); -/* -* Clear default root domain DL accounting, it will be computed again -* if a task belongs to it. -*/ -dl_clear_root_domain (&def_root_domain); +for_each_possible_cpu (cpu) { +if (dl_bw_visited (cpu, cookie)) +continue ; + +dl_clear_root_domain_cpu (cpu); + }cpuset_for_each_descendant_pre (cs, pos_css, &top_cpuset) {
@@ -996,7 +999,6 @@ partition_and_rebuild_sched_domains(int ndoms_new, cpumask_var_t doms_new[], {sched_domains_mutex_lock ();partition_sched_domains_locked (ndoms_new, doms_new, dattr_new); -dl_rebuild_rd_accounting ();sched_domains_mutex_unlock (); }
kernel/sched/deadline.c +10 -6
@@ -166,7 +166,7 @@ static inline unsigned long dl_bw_capacity(int i) } } -static inline bool dl_bw_visited (int cpu,u64 cookie) +bool dl_bw_visited (int cpu,u64 cookie) {struct root_domain *rd =cpu_rq (cpu)->rd;
@@ -207,7 +207,7 @@ static inline unsigned long dl_bw_capacity(int i)return SCHED_CAPACITY_SCALE ; } -static inline bool dl_bw_visited (int cpu,u64 cookie) +bool dl_bw_visited (int cpu,u64 cookie) {return false; }
@@ -2981,18 +2981,22 @@ void dl_clear_root_domain(struct root_domain *rd) rd->dl_bw.total_bw =0 ;/* -* dl_server bandwidth is only restored when CPUs are attached to root -* domains (after domains are created or CPUs moved back to the -* default root doamin). +* dl_servers are not tasks. Since dl_add_task_root_domanin ignores +* them, we need to account for them here explicitly. */ for_each_cpu (i, rd->span) {struct sched_dl_entity *dl_se = &cpu_rq (i)->fair_server;if (dl_server (dl_se) &&cpu_active (i)) - rd->dl_bw.total_bw += dl_se->dl_bw; +__dl_add (&rd->dl_bw, dl_se->dl_bw,dl_bw_cpus (i)); } } +void dl_clear_root_domain_cpu (int cpu) +{ +dl_clear_root_domain (cpu_rq (cpu)->rd); +} +#endif /* CONFIG_SMP */ static void switched_from_dl (struct rq *rq,struct task_struct *p)
kernel/sched/topology.c +1 -0
@@ -2791,6 +2791,7 @@ void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[], ndoms_cur = ndoms_new;update_sched_domain_debugfs (); +dl_rebuild_rd_accounting (); }/*
Signature · 1 line
2.48.1
Re: [PATCH v2 4/8] sched/deadline: Rebuild root domain accounting after every update
Hi Juri.
Quoted 25 lines · Juri Lelli
Rebuilding of root domains accounting information (
total_bw) is currently broken on some cases, e.g. suspend/resume on aarch64. Problem is that the way we keep track of domain changes and try to add bandwidth back is convoluted and fragile.Fix it by simplify things by making sure bandwidth accounting is cleared and completely restored after root domains changes (after root domains are again stable).
Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug")Signed-off-by Juri Lelli <[email protected]>--- include/linux/sched/deadline.h | 4 ++++ include/linux/sched/topology.h | 2 ++ kernel/cgroup/cpuset.c | 16 +++++++++------- kernel/sched/deadline.c | 16 ++++++++++------ kernel/sched/topology.c | 1 + 5 files changed, 26 insertions(+), 13 deletions(-)include/linux/sched/deadline.h +0
-0
include/linux/sched/deadline.h static inline bool dl_time_before(u64 a, u64 b) · line 40
Quoted 7 lines
include/linux/sched/deadline.h +4
-0@@ -34,6 +34,10 @@ static inline bool dl_time_before(u64 a, u64 b)struct root_domain ;extern void dl_add_task_root_domain (struct task_struct *p);extern void dl_clear_root_domain (struct root_domain *rd); +extern void dl_clear_root_domain_cpu (int cpu); + +extern u64 dl_cookie; +extern bool dl_bw_visited (int cpu,u64 gen);
Is this needed? There is same declaration outside of CONFIG_SMP done in patch 3/8.
Quoted 83 lines
include/linux/sched/deadline.h +0
-0#endif /* CONFIG_SMP */ include/linux/sched/topology.h +2
-0@@ -166,6 +166,8 @@ static inline struct cpumask *sched_domain_span(struct sched_domain *sd)return to_cpumask (sd->span); } +extern void dl_rebuild_rd_accounting (void ); +extern void partition_sched_domains_locked (int ndoms_new,cpumask_var_t doms_new[],struct sched_domain_attr *dattr_new);kernel/cgroup/cpuset.c +9
-7@@ -954,10 +954,12 @@ static void dl_update_tasks_root_domain(struct cpuset *cs)css_task_iter_end (&it); } -static void dl_rebuild_rd_accounting (void ) +void dl_rebuild_rd_accounting (void ) {struct cpuset *cs =NULL ;struct cgroup_subsys_state *pos_css; +int cpu; +u64 cookie = ++dl_cookie;lockdep_assert_held (&cpuset_mutex);lockdep_assert_cpus_held ();@@ -965,11 +967,12 @@ static void dl_rebuild_rd_accounting(void)rcu_read_lock (); -/* -* Clear default root domain DL accounting, it will be computed again -* if a task belongs to it. -*/ -dl_clear_root_domain (&def_root_domain); +for_each_possible_cpu (cpu) { +if (dl_bw_visited (cpu, cookie)) +continue ; + +dl_clear_root_domain_cpu (cpu); + }cpuset_for_each_descendant_pre (cs, pos_css, &top_cpuset) {@@ -996,7 +999,6 @@ partition_and_rebuild_sched_domains(int ndoms_new, cpumask_var_t doms_new[], {sched_domains_mutex_lock ();partition_sched_domains_locked (ndoms_new, doms_new, dattr_new); -dl_rebuild_rd_accounting ();sched_domains_mutex_unlock (); }kernel/sched/deadline.c +2
-2@@ -166,7 +166,7 @@ static inline unsigned long dl_bw_capacity(int i) } } -static inline bool dl_bw_visited (int cpu,u64 cookie) +bool dl_bw_visited (int cpu,u64 cookie) {struct root_domain *rd =cpu_rq (cpu)->rd;@@ -207,7 +207,7 @@ static inline unsigned long dl_bw_capacity(int i)return SCHED_CAPACITY_SCALE ; } -static inline bool dl_bw_visited (int cpu,u64 cookie) +bool dl_bw_visited (int cpu,u64 cookie) {return false; }
kernel/sched/deadline.c void dl_clear_root_domain(struct root_domain *rd) · line 2984
Quoted 7 lines
kernel/sched/deadline.c +1
-3@@ -2981,18 +2981,22 @@ void dl_clear_root_domain(struct root_domain *rd) rd->dl_bw.total_bw =0 ;/* -* dl_server bandwidth is only restored when CPUs are attached to root -* domains (after domains are created or CPUs moved back to the -* default root doamin). +* dl_servers are not tasks. Since dl_add_task_root_domanin ignores
s/dl_add_task_root_domanin/dl_add_task_root_domain
Quoted 31 lines
kernel/sched/deadline.c +7
-1+* them, we need to account for them here explicitly. */ for_each_cpu (i, rd->span) {struct sched_dl_entity *dl_se = &cpu_rq (i)->fair_server;if (dl_server (dl_se) &&cpu_active (i)) - rd->dl_bw.total_bw += dl_se->dl_bw; +__dl_add (&rd->dl_bw, dl_se->dl_bw,dl_bw_cpus (i)); } } +void dl_clear_root_domain_cpu (int cpu) +{ +dl_clear_root_domain (cpu_rq (cpu)->rd); +} +#endif /* CONFIG_SMP */ static void switched_from_dl (struct rq *rq,struct task_struct *p)kernel/sched/topology.c +1
-0@@ -2791,6 +2791,7 @@ void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[], ndoms_cur = ndoms_new;update_sched_domain_debugfs (); +dl_rebuild_rd_accounting (); }/*
Juri Lelli
maintainerRe: [PATCH v2 4/8] sched/deadline: Rebuild root domain accounting after every update
Quoted 23 lines · Shrikanth Hegde
Hi Juri.
Quoted 20 lines · Juri Lelli
Rebuilding of root domains accounting information (
total_bw) is currently broken on some cases, e.g. suspend/resume on aarch64. Problem is that the way we keep track of domain changes and try to add bandwidth back is convoluted and fragile.Fix it by simplify things by making sure bandwidth accounting is cleared and completely restored after root domains changes (after root domains are again stable).
Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug")Signed-off-by Juri Lelli <[email protected]>--- include/linux/sched/deadline.h | 4 ++++ include/linux/sched/topology.h | 2 ++ kernel/cgroup/cpuset.c | 16 +++++++++------- kernel/sched/deadline.c | 16 ++++++++++------ kernel/sched/topology.c | 1 + 5 files changed, 26 insertions(+), 13 deletions(-)
Quoted 15 lines
include/linux/sched/deadline.h static inline bool dl_time_before(u64 a, u64 b) · line 40
Quoted 12 lines
include/linux/sched/deadline.h +4
-0@@ -34,6 +34,10 @@ static inline bool dl_time_before(u64 a, u64 b)struct root_domain ;extern void dl_add_task_root_domain (struct task_struct *p);extern void dl_clear_root_domain (struct root_domain *rd); +extern void dl_clear_root_domain_cpu (int cpu); + +extern u64 dl_cookie; +extern bool dl_bw_visited (int cpu,u64 gen);Is this needed? There is same declaration outside of
CONFIG_SMPdone in patch 3/8.
Nope. Good catch.
Thanks,
Juri
Re: [PATCH v2 4/8] sched/deadline: Rebuild root domain accounting after every update
In reply to Juri LelliQuoted 72 lines · Juri Lelli
Rebuilding of root domains accounting information (
total_bw) is currently broken on some cases, e.g. suspend/resume on aarch64. Problem is that the way we keep track of domain changes and try to add bandwidth back is convoluted and fragile.Fix it by simplify things by making sure bandwidth accounting is cleared and completely restored after root domains changes (after root domains are again stable).
Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug")Signed-off-by Juri Lelli <[email protected]>--- include/linux/sched/deadline.h | 4 ++++ include/linux/sched/topology.h | 2 ++ kernel/cgroup/cpuset.c | 16 +++++++++------- kernel/sched/deadline.c | 16 ++++++++++------ kernel/sched/topology.c | 1 + 5 files changed, 26 insertions(+), 13 deletions(-)include/linux/sched/deadline.h +4
-0@@ -34,6 +34,10 @@ static inline bool dl_time_before(u64 a, u64 b)struct root_domain ;extern void dl_add_task_root_domain (struct task_struct *p);extern void dl_clear_root_domain (struct root_domain *rd); +extern void dl_clear_root_domain_cpu (int cpu); + +extern u64 dl_cookie; +extern bool dl_bw_visited (int cpu,u64 gen);#endif /* CONFIG_SMP */ include/linux/sched/topology.h +2
-0@@ -166,6 +166,8 @@ static inline struct cpumask *sched_domain_span(struct sched_domain *sd)return to_cpumask (sd->span); } +extern void dl_rebuild_rd_accounting (void ); +extern void partition_sched_domains_locked (int ndoms_new,cpumask_var_t doms_new[],struct sched_domain_attr *dattr_new);kernel/cgroup/cpuset.c +3
-3@@ -954,10 +954,12 @@ static void dl_update_tasks_root_domain(struct cpuset *cs)css_task_iter_end (&it); } -static void dl_rebuild_rd_accounting (void ) +void dl_rebuild_rd_accounting (void ) {struct cpuset *cs =NULL ;struct cgroup_subsys_state *pos_css; +int cpu; +u64 cookie = ++dl_cookie;lockdep_assert_held (&cpuset_mutex);lockdep_assert_cpus_held ();@@ -965,11 +967,12 @@ static void dl_rebuild_rd_accounting(void)rcu_read_lock (); -/* -* Clear default root domain DL accounting, it will be computed again
kernel/cgroup/cpuset.c static void dl_rebuild_rd_accounting(void) · line 976
Quoted 10 lines
kernel/cgroup/cpuset.c +6
-3-* if a task belongs to it. -*/ -dl_clear_root_domain (&def_root_domain); +for_each_possible_cpu (cpu) { +if (dl_bw_visited (cpu, cookie)) +continue ; + +dl_clear_root_domain_cpu (cpu); + }
This will clear all possible root domains bandwidth and rebuild it.
For an online CPUs, the fair server bandwidth is added i think in rq_attach_root. But for an offline CPUs the sched domains wont be rebuilt. It may not be an issue. but the def_root_domain's bw may be different afterwords. no?
Quoted 71 lines
kernel/cgroup/cpuset.c +0
-1cpuset_for_each_descendant_pre (cs, pos_css, &top_cpuset) {@@ -996,7 +999,6 @@ partition_and_rebuild_sched_domains(int ndoms_new, cpumask_var_t doms_new[], {sched_domains_mutex_lock ();partition_sched_domains_locked (ndoms_new, doms_new, dattr_new); -dl_rebuild_rd_accounting ();sched_domains_mutex_unlock (); }kernel/sched/deadline.c +10
-6@@ -166,7 +166,7 @@ static inline unsigned long dl_bw_capacity(int i) } } -static inline bool dl_bw_visited (int cpu,u64 cookie) +bool dl_bw_visited (int cpu,u64 cookie) {struct root_domain *rd =cpu_rq (cpu)->rd;@@ -207,7 +207,7 @@ static inline unsigned long dl_bw_capacity(int i)return SCHED_CAPACITY_SCALE ; } -static inline bool dl_bw_visited (int cpu,u64 cookie) +bool dl_bw_visited (int cpu,u64 cookie) {return false; }@@ -2981,18 +2981,22 @@ void dl_clear_root_domain(struct root_domain *rd) rd->dl_bw.total_bw =0 ;/* -* dl_server bandwidth is only restored when CPUs are attached to root -* domains (after domains are created or CPUs moved back to the -* default root doamin). +* dl_servers are not tasks. Since dl_add_task_root_domanin ignores +* them, we need to account for them here explicitly. */ for_each_cpu (i, rd->span) {struct sched_dl_entity *dl_se = &cpu_rq (i)->fair_server;if (dl_server (dl_se) &&cpu_active (i)) - rd->dl_bw.total_bw += dl_se->dl_bw; +__dl_add (&rd->dl_bw, dl_se->dl_bw,dl_bw_cpus (i)); } } +void dl_clear_root_domain_cpu (int cpu) +{ +dl_clear_root_domain (cpu_rq (cpu)->rd); +} +#endif /* CONFIG_SMP */ static void switched_from_dl (struct rq *rq,struct task_struct *p)kernel/sched/topology.c +1
-0@@ -2791,6 +2791,7 @@ void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[], ndoms_cur = ndoms_new;update_sched_domain_debugfs (); +dl_rebuild_rd_accounting (); }/*
Juri Lelli
maintainerRe: [PATCH v2 4/8] sched/deadline: Rebuild root domain accounting after every update
Quoted 15 lines · Shrikanth Hegde
Quoted 12 lines · Juri Lelli
Rebuilding of root domains accounting information (
total_bw) is currently broken on some cases, e.g. suspend/resume on aarch64. Problem is that the way we keep track of domain changes and try to add bandwidth back is convoluted and fragile.Fix it by simplify things by making sure bandwidth accounting is cleared and completely restored after root domains changes (after root domains are again stable).
Reported-by Jon Hunter <[email protected]>Fixes 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for hotplug")Signed-off-by Juri Lelli <[email protected]>
...
Quoted 16 lines
kernel/cgroup/cpuset.c static void dl_rebuild_rd_accounting(void) · line 973
Quoted 13 lines
kernel/cgroup/cpuset.c +6
-5@@ -965,11 +967,12 @@ static void dl_rebuild_rd_accounting(void)rcu_read_lock (); -/* -* Clear default root domain DL accounting, it will be computed again -* if a task belongs to it. -*/ -dl_clear_root_domain (&def_root_domain); +for_each_possible_cpu (cpu) { +if (dl_bw_visited (cpu, cookie)) +continue ; + +dl_clear_root_domain_cpu (cpu); + }This will clear all possible root domains bandwidth and rebuild it.
Quoted 4 lines
For an online CPUs, the fair server bandwidth is added i think in
rq_attach_root. But for an offline CPUs the sched domains wont be rebuilt. It may not be an issue. but the def_root_domain's bw may be different afterwords. no?
dl_clear_root_domain() actually adds DL servers contribution back on their domains (dynamic and def) and we want to keep offline CPUs DL server contribution not accounted for until they come back online and the domains are rebuilt.
Thanks,
Juri
Juri Lelli
maintainerPATCH v2 5/8 sched/topology: Remove redundant dl_clear_root_domain call
In reply to Juri LelliWe completely clean and restore root domains bandwidth accounting after every root domains change, so the dl_clear_root_domain() call in partition_sched_domains_locked() is redundant.
Remove it.
--- kernel/sched/topology.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
kernel/sched/topology.c +1 -14
@@ -2720,21 +2720,8 @@ void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[],for (i =0 ; i < ndoms_cur; i++) {for (j =0 ; j < n && !new_topology; j++) {if (cpumask_equal (doms_cur[i], doms_new[j]) && -dattrs_equal (dattr_cur, i, dattr_new, j)) { -struct root_domain *rd; - -/* -* This domain won't be destroyed and as such -* its dl_bw->total_bw needs to be cleared. -* Tasks contribution will be then recomputed -* in function dl_update_tasks_root_domain(), -* dl_servers contribution in function -* dl_restore_server_root_domain(). -*/ - rd =cpu_rq (cpumask_any (doms_cur[i]))->rd; -dl_clear_root_domain (rd); +dattrs_equal (dattr_cur, i, dattr_new, j)) goto match1; - } }/* No match - a current sched domain not in new doms_new[] */ detach_destroy_domains (doms_cur[i]);
Signature · 1 line
2.48.1
Juri Lelli
maintainerPATCH v2 6/8 cgroup/cpuset: Remove partition_and_rebuild_sched_domains
In reply to Juri Lellipartition_and_rebuild_sched_domains() and partition_sched_domains() are now equivalent.
Remove the former as a nice clean up.
--- kernel/cgroup/cpuset.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
kernel/cgroup/cpuset.c +1 -10
@@ -993,15 +993,6 @@ void dl_rebuild_rd_accounting(void)rcu_read_unlock (); } -static void -partition_and_rebuild_sched_domains (int ndoms_new,cpumask_var_t doms_new[], -struct sched_domain_attr *dattr_new) -{ -sched_domains_mutex_lock (); -partition_sched_domains_locked (ndoms_new, doms_new, dattr_new); -sched_domains_mutex_unlock (); -} -/* * Rebuild scheduler domains. *
@@ -1063,7 +1054,7 @@ void rebuild_sched_domains_locked(void) ndoms =generate_sched_domains (&doms, &attr);/* Have scheduler rebuild the domains */ - partition_and_rebuild_sched_domains(ndoms, doms, attr); + partition_sched_domains(ndoms, doms, attr); }#else /* !CONFIG_SMP */ void rebuild_sched_domains_locked (void )
Signature · 1 line
2.48.1
Re: [PATCH v2 6/8] cgroup/cpuset: Remove partition_and_rebuild_sched_domains
Quoted 32 lines · Juri Lelli
partition_and_rebuild_sched_domains()andpartition_sched_domains()are now equivalent.Remove the former as a nice clean up.
Suggested-by Waiman Long <[email protected]>Signed-off-by Juri Lelli <[email protected]>--- kernel/cgroup/cpuset.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)kernel/cgroup/cpuset.c +0
-9@@ -993,15 +993,6 @@ void dl_rebuild_rd_accounting(void)rcu_read_unlock (); } -static void -partition_and_rebuild_sched_domains (int ndoms_new,cpumask_var_t doms_new[], -struct sched_domain_attr *dattr_new) -{ -sched_domains_mutex_lock (); -partition_sched_domains_locked (ndoms_new, doms_new, dattr_new); -sched_domains_mutex_unlock (); -} -/* * Rebuild scheduler domains. *
kernel/cgroup/cpuset.c void rebuild_sched_domains_locked(void) · line 1060
Quoted 8 lines
kernel/cgroup/cpuset.c +1
-1@@ -1063,7 +1054,7 @@ void rebuild_sched_domains_locked(void) ndoms =generate_sched_domains (&doms, &attr);/* Have scheduler rebuild the domains */ - partition_and_rebuild_sched_domains(ndoms, doms, attr); + partition_sched_domains(ndoms, doms, attr); }#else /* !CONFIG_SMP */ void rebuild_sched_domains_locked (void )
This makes sense.
Re: [PATCH v2 6/8] cgroup/cpuset: Remove partition_and_rebuild_sched_domains
In reply to Juri LelliQuoted 32 lines · Juri Lelli
partition_and_rebuild_sched_domains()andpartition_sched_domains()are now equivalent.Remove the former as a nice clean up.
Suggested-by Waiman Long <[email protected]>Signed-off-by Juri Lelli <[email protected]>--- kernel/cgroup/cpuset.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)kernel/cgroup/cpuset.c +0
-9@@ -993,15 +993,6 @@ void dl_rebuild_rd_accounting(void)rcu_read_unlock (); } -static void -partition_and_rebuild_sched_domains (int ndoms_new,cpumask_var_t doms_new[], -struct sched_domain_attr *dattr_new) -{ -sched_domains_mutex_lock (); -partition_sched_domains_locked (ndoms_new, doms_new, dattr_new); -sched_domains_mutex_unlock (); -} -/* * Rebuild scheduler domains. *
kernel/cgroup/cpuset.c void rebuild_sched_domains_locked(void) · line 1060
Quoted 8 lines
kernel/cgroup/cpuset.c +1
-1@@ -1063,7 +1054,7 @@ void rebuild_sched_domains_locked(void) ndoms =generate_sched_domains (&doms, &attr);/* Have scheduler rebuild the domains */ - partition_and_rebuild_sched_domains(ndoms, doms, attr); + partition_sched_domains(ndoms, doms, attr); }#else /* !CONFIG_SMP */ void rebuild_sched_domains_locked (void )
Re: [PATCH v2 6/8] cgroup/cpuset: Remove partition_and_rebuild_sched_domains
In reply to Juri LelliQuoted 32 lines · Juri Lelli
partition_and_rebuild_sched_domains()andpartition_sched_domains()are now equivalent.Remove the former as a nice clean up.
Suggested-by Waiman Long <[email protected]>Signed-off-by Juri Lelli <[email protected]>--- kernel/cgroup/cpuset.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)kernel/cgroup/cpuset.c +0
-9@@ -993,15 +993,6 @@ void dl_rebuild_rd_accounting(void)rcu_read_unlock (); } -static void -partition_and_rebuild_sched_domains (int ndoms_new,cpumask_var_t doms_new[], -struct sched_domain_attr *dattr_new) -{ -sched_domains_mutex_lock (); -partition_sched_domains_locked (ndoms_new, doms_new, dattr_new); -sched_domains_mutex_unlock (); -} -/* * Rebuild scheduler domains. *
kernel/cgroup/cpuset.c void rebuild_sched_domains_locked(void) · line 1060
Quoted 8 lines
kernel/cgroup/cpuset.c +1
-1@@ -1063,7 +1054,7 @@ void rebuild_sched_domains_locked(void) ndoms =generate_sched_domains (&doms, &attr);/* Have scheduler rebuild the domains */ - partition_and_rebuild_sched_domains(ndoms, doms, attr); + partition_sched_domains(ndoms, doms, attr); }#else /* !CONFIG_SMP */ void rebuild_sched_domains_locked (void )
Juri Lelli
maintainerPATCH v2 7/8 sched/topology: Stop exposing partition_sched_domains_locked
In reply to Juri LelliThe are no callers of partition_sched_domains_locked() outside topology.c.
Stop exposing such function.
--- include/linux/sched/topology.h | 10 ---------- kernel/sched/topology.c | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-)
include/linux/sched/topology.h +0 -10
@@ -168,10 +168,6 @@ static inline struct cpumask *sched_domain_span(struct sched_domain *sd)extern void dl_rebuild_rd_accounting (void ); -extern void partition_sched_domains_locked (int ndoms_new, -cpumask_var_t doms_new[], -struct sched_domain_attr *dattr_new); -extern void partition_sched_domains (int ndoms_new,cpumask_var_t doms_new[],struct sched_domain_attr *dattr_new);
@@ -212,12 +208,6 @@ extern void __init set_sched_topology(struct sched_domain_topology_level *tl);struct sched_domain_attr ; -static inline void -partition_sched_domains_locked (int ndoms_new,cpumask_var_t doms_new[], -struct sched_domain_attr *dattr_new) -{ -} -static inline void partition_sched_domains (int ndoms_new,cpumask_var_t doms_new[],struct sched_domain_attr *dattr_new)
kernel/sched/topology.c +1 -1
@@ -2688,7 +2688,7 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur,* * Call with hotplug lock and sched_domains_mutex held */ -void partition_sched_domains_locked (int ndoms_new,cpumask_var_t doms_new[], +static void partition_sched_domains_locked (int ndoms_new,cpumask_var_t doms_new[],struct sched_domain_attr *dattr_new) {bool __maybe_unused has_eas = false;
Signature · 1 line
2.48.1
Juri Lelli
maintainerPATCH v2 8/8 include/{topology,cpuset}: Move dl_rebuild_rd_accounting to cpuset.h
In reply to Juri Lellidl_rebuild_rd_accounting() is defined in cpuset.c, so it makes more sense to move related declarations to cpuset.h.
Implement the move.
--- include/linux/cpuset.h | 5 +++++ include/linux/sched/topology.h | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-)
include/linux/cpuset.h +5 -0
@@ -125,6 +125,7 @@ static inline int cpuset_do_page_mem_spread(void)extern bool current_cpuset_is_being_rebound (void ); +extern void dl_rebuild_rd_accounting (void );extern void rebuild_sched_domains (void );extern void cpuset_print_current_mems_allowed (void );
@@ -259,6 +260,10 @@ static inline bool current_cpuset_is_being_rebound(void)return false; } +static inline void dl_rebuild_rd_accounting (void ) +{ +} +static inline void rebuild_sched_domains (void ) {partition_sched_domains (1 ,NULL ,NULL );
include/linux/sched/topology.h +0 -2
@@ -166,8 +166,6 @@ static inline struct cpumask *sched_domain_span(struct sched_domain *sd)return to_cpumask (sd->span); } -extern void dl_rebuild_rd_accounting (void ); -extern void partition_sched_domains (int ndoms_new,cpumask_var_t doms_new[],struct sched_domain_attr *dattr_new);
Signature · 1 line
2.48.1
Re: [PATCH v2 8/8] include/{topology,cpuset}: Move dl_rebuild_rd_accounting to cpuset.h
Quoted 40 lines · Juri Lelli
dl_rebuild_rd_accounting()is defined incpuset.c, so it makes more sense to move related declarations tocpuset.h.Implement the move.
Suggested-by Waiman Long <[email protected]>Signed-off-by Juri Lelli <[email protected]>--- include/linux/cpuset.h | 5 +++++ include/linux/sched/topology.h | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-)include/linux/cpuset.h +5
-0@@ -125,6 +125,7 @@ static inline int cpuset_do_page_mem_spread(void)extern bool current_cpuset_is_being_rebound (void ); +extern void dl_rebuild_rd_accounting (void );extern void rebuild_sched_domains (void );extern void cpuset_print_current_mems_allowed (void );@@ -259,6 +260,10 @@ static inline bool current_cpuset_is_being_rebound(void)return false; } +static inline void dl_rebuild_rd_accounting (void ) +{ +} +static inline void rebuild_sched_domains (void ) {partition_sched_domains (1 ,NULL ,NULL );include/linux/sched/topology.h +0
-0
include/linux/sched/topology.h static inline struct cpumask *sched_domain_span(struct sched_domain *sd) · line 171
Quoted 8 lines
include/linux/sched/topology.h +0
-2@@ -166,8 +166,6 @@ static inline struct cpumask *sched_domain_span(struct sched_domain *sd)return to_cpumask (sd->span); } -extern void dl_rebuild_rd_accounting (void ); -extern void partition_sched_domains (int ndoms_new,cpumask_var_t doms_new[],struct sched_domain_attr *dattr_new);
Hi Juri,
Quoted 24 lines · Juri Lelli
Hello!
Jon reported [1] a suspend regression on a Tegra board configured to boot with isolcpus and bisected it to commit
53916d5fd3c0("sched/deadline: Check bandwidth overflow earlier for hotplug").Root cause analysis pointed out that we are currently failing to correctly clear and restore bandwidth accounting on root domains after changes that initiate from
partition_sched_domains(), as it is the case for suspend operations on that board.This is v2 [2] of the proposed approach to fix the issue. With respect to v1, the following implements the approach by:
- 01: filter out DEADLINE special tasks
- 02: preparatory wrappers to be able to grabsched_domains_mutexon UP (remove !SMP wrappers - Waiman)
- 03: generalize unique visiting of root domains so that we can re-use the mechanism elsewhere
- 04: the bulk of the approach, clean and rebuild after changes
- 05: clean up a now redundant call
- 06: removepartition_and_rebuild_sched_domains()(Waiman)
- 07: stop exposingpartition_sched_domains_locked(Waiman)
Quoted 1 line
Please test and review. The set is also available at
Thanks!
Jon
Signature · 1 line
nvpublic
Juri Lelli
maintainerHi Jon,
Quoted 27 lines · Jon Hunter
Hi Juri,
Quoted 24 lines · Juri Lelli
Hello!
Jon reported [1] a suspend regression on a Tegra board configured to boot with isolcpus and bisected it to commit
53916d5fd3c0("sched/deadline: Check bandwidth overflow earlier for hotplug").Root cause analysis pointed out that we are currently failing to correctly clear and restore bandwidth accounting on root domains after changes that initiate from
partition_sched_domains(), as it is the case for suspend operations on that board.This is v2 [2] of the proposed approach to fix the issue. With respect to v1, the following implements the approach by:
- 01: filter out DEADLINE special tasks
- 02: preparatory wrappers to be able to grabsched_domains_mutexon UP (remove !SMP wrappers - Waiman)
- 03: generalize unique visiting of root domains so that we can re-use the mechanism elsewhere
- 04: the bulk of the approach, clean and rebuild after changes
- 05: clean up a now redundant call
- 06: removepartition_and_rebuild_sched_domains()(Waiman)
- 07: stop exposingpartition_sched_domains_locked(Waiman)
Quoted 4 lines
Quoted 1 line
Please test and review. The set is also available at
Tested-by Jon Hunter <[email protected]>
Thanks!
Best,
Juri
Quoted 58 lines · Juri Lelli
Hello!
Jon reported [1] a suspend regression on a Tegra board configured to boot with isolcpus and bisected it to commit
53916d5fd3c0("sched/deadline: Check bandwidth overflow earlier for hotplug").Root cause analysis pointed out that we are currently failing to correctly clear and restore bandwidth accounting on root domains after changes that initiate from
partition_sched_domains(), as it is the case for suspend operations on that board.This is v2 [2] of the proposed approach to fix the issue. With respect to v1, the following implements the approach by:
- 01: filter out DEADLINE special tasks
- 02: preparatory wrappers to be able to grabsched_domains_mutexon UP (remove !SMP wrappers - Waiman)
- 03: generalize unique visiting of root domains so that we can re-use the mechanism elsewhere
- 04: the bulk of the approach, clean and rebuild after changes
- 05: clean up a now redundant call
- 06: removepartition_and_rebuild_sched_domains()(Waiman)
- 07: stop exposingpartition_sched_domains_locked(Waiman)Please test and review. The set is also available at
[email protected]:jlelli/linux.git upstream/deadline/domains-suspend
Best,
Juri1 - https://lore.kernel.org/lkml/[email protected]/
2 - v1 https://lore.kernel.org/lkml/[email protected]Juri Lelli (8):
sched/deadline: Ignore special tasks when rebuilding domains sched/topology: Wrappers forsched_domains_mutexsched/deadline: Generalize unique visiting of root domains sched/deadline: Rebuild root domain accounting after every update sched/topology: Remove redundantdl_clear_root_domaincall cgroup/cpuset: Removepartition_and_rebuild_sched_domainssched/topology: Stop exposingpartition_sched_domains_lockedinclude/{topology,cpuset}: Movedl_rebuild_rd_accountingtocpuset.hinclude/linux/cpuset.h | 5 +++++ include/linux/sched.h | 2 ++ include/linux/sched/deadline.h | 7 +++++++ include/linux/sched/topology.h | 10 --------- kernel/cgroup/cpuset.c | 27 +++++++++---------------- kernel/sched/core.c | 4 ++-- kernel/sched/deadline.c | 37 ++++++++++++++++++++-------------- kernel/sched/debug.c | 8 ++++---- kernel/sched/rt.c | 2 ++ kernel/sched/sched.h | 2 +- kernel/sched/topology.c | 32 +++++++++++++---------------- 11 files changed, 69 insertions(+), 67 deletions(-)
Quoted 1 line
base-commit:
48a5eed9ad584315c30ed35204510536235ce402
I have run my cpuset test and it completed successfully without any issue.
Juri Lelli
maintainerQuoted 26 lines · Waiman Long
Quoted 25 lines · Juri Lelli
Hello!
Jon reported [1] a suspend regression on a Tegra board configured to boot with isolcpus and bisected it to commit
53916d5fd3c0("sched/deadline: Check bandwidth overflow earlier for hotplug").Root cause analysis pointed out that we are currently failing to correctly clear and restore bandwidth accounting on root domains after changes that initiate from
partition_sched_domains(), as it is the case for suspend operations on that board.This is v2 [2] of the proposed approach to fix the issue. With respect to v1, the following implements the approach by:
- 01: filter out DEADLINE special tasks
- 02: preparatory wrappers to be able to grabsched_domains_mutexon UP (remove !SMP wrappers - Waiman)
- 03: generalize unique visiting of root domains so that we can re-use the mechanism elsewhere
- 04: the bulk of the approach, clean and rebuild after changes
- 05: clean up a now redundant call
- 06: removepartition_and_rebuild_sched_domains()(Waiman)
- 07: stop exposingpartition_sched_domains_locked(Waiman)Please test and review. The set is also available at
...
Quoted 4 lines
I have run my cpuset test and it completed successfully without any issue.
Tested-by Waiman Long <[email protected]>
Thanks!
Juri