xen/sched: migrate timers to correct cpus after suspend
PATCH v2 1/1 xen/sched: migrate timers to correct cpus after suspend
Today all timers are migrated to cpu 0 when the system is being suspended. They are not migrated back after resuming the system again.
This results (at least) to problems with the credit scheduler, as the timer isn't handled on the cpu it was expected to occur.
Add migrating the scheduling related timers of a specific cpu from cpu 0 back to its original cpu when that cpu has gone up when resuming the system.
---
V2:
- fix smt=0 case (Marek Marczykowski-Górecki)
--- xen/common/sched/core.c | 26 +++++++++++++++++ xen/common/sched/cpupool.c | 2 ++ xen/common/sched/credit.c | 13 +++++++++ xen/common/sched/private.h | 10 +++++++ xen/common/sched/rt.c | 58 ++++++++++++++++++++++++++------------ 5 files changed, 91 insertions(+), 18 deletions(-)
xen/common/sched/core.c +26 -0
@@ -1284,6 +1284,32 @@ static int cpu_disable_scheduler_check(unsigned int cpu)return 0 ; } +/* +* Called after a cpu has come up again in a suspend/resume cycle. +* Note that on a system with smt=0 this will be called for the sibling cpus, +* too, so the case for no scheduling resource being available must be +* considered. +* Migrate all timers for this cpu (they have been migrated to cpu 0 when the +* cpu was going down). +* Note that only timers related to a physical cpu are migrated, not the ones +* related to a vcpu or domain. +*/ +void sched_migrate_timers (unsigned int cpu) +{ +struct sched_resource *sr; + +rcu_read_lock (&sched_res_rculock); + + sr =get_sched_res (cpu); +if ( sr && sr->master_cpu == cpu ) + { +migrate_timer (&sr->s_timer, cpu); +sched_move_timers (sr->scheduler, sr); + } + +rcu_read_unlock (&sched_res_rculock); +} +/* * In general, this must be called with the scheduler lock held, because the * adjust_affinity hook may want to modify the vCPU state. However, when the
xen/common/sched/cpupool.c +2 -0
@@ -1035,6 +1035,8 @@ static int cf_check cpu_callback(case CPU_ONLINE :if ( system_state <= SYS_STATE_active ) rc =cpupool_cpu_add (cpu); +else +sched_migrate_timers (cpu);break ;case CPU_DOWN_PREPARE :/* Suspend/Resume don't change assignments of cpus to cpupools. */
xen/common/sched/credit.c +13 -0
@@ -614,6 +614,18 @@ init_pdata(struct csched_private *prv, struct csched_pcpu *spc, int cpu) spc->nr_runnable =0 ; } +static void cf_check +csched_move_timers (const struct scheduler *ops,struct sched_resource *sr) +{ +struct csched_private *prv =CSCHED_PRIV (ops); +struct csched_pcpu *spc = sr->sched_priv; + +if ( sr->master_cpu == prv->master ) +migrate_timer (&prv->master_ticker, prv->master); + +migrate_timer (&spc->ticker, sr->master_cpu); +} +/* Change the scheduler of cpu to us (Credit). */ static spinlock_t *cf_check csched_switch_sched(struct scheduler *new_ops, unsigned int cpu,
@@ -2264,6 +2276,7 @@ static const struct scheduler sched_credit_def = { .switch_sched = csched_switch_sched, .alloc_domdata = csched_alloc_domdata, .free_domdata = csched_free_domdata, + .move_timers = csched_move_timers, };REGISTER_SCHEDULER (sched_credit_def);
xen/common/sched/private.h +10 -0
@@ -331,6 +331,8 @@ struct scheduler { struct xen_sysctl_scheduler_op *);void (*dump_settings) (const struct scheduler *);void (*dump_cpu_state) (const struct scheduler *,int ); +void (*move_timers) (const struct scheduler *, +struct sched_resource *); };static inline int sched_init (struct scheduler *s)
@@ -485,6 +487,13 @@ static inline int sched_adjust_cpupool(const struct scheduler *s,return s->adjust_global ? s->adjust_global (s, op) :0 ; } +static inline void sched_move_timers (const struct scheduler *s, +struct sched_resource *sr) +{ +if ( s->move_timers ) + s->move_timers (s, sr); +} +static inline void sched_unit_pause_nosync (const struct sched_unit *unit) {struct vcpu *v;
@@ -622,6 +631,7 @@ struct cpu_rm_data *alloc_cpu_rm_data(unsigned int cpu, bool aff_alloc);void free_cpu_rm_data (struct cpu_rm_data *mem,unsigned int cpu);int schedule_cpu_rm (unsigned int cpu,struct cpu_rm_data *mem);int sched_move_domain (struct domain *d,struct cpupool *c); +void sched_migrate_timers (unsigned int cpu);struct cpupool *cpupool_get_by_id (unsigned int poolid);void cpupool_put (struct cpupool *pool);int cpupool_add_domain (struct domain *d,unsigned int poolid);
xen/common/sched/rt.c +40 -18
77 lines not on this page · raw message
Signature · 1 line
2.35.3
Quoted 11 lines · Juergen Gross
Today all timers are migrated to cpu 0 when the system is being suspended. They are not migrated back after resuming the system again.
This results (at least) to problems with the credit scheduler, as the timer isn't handled on the cpu it was expected to occur.
Add migrating the scheduling related timers of a specific cpu from cpu 0 back to its original cpu when that cpu has gone up when resuming the system.
Signed-off-by Juergen Gross <[email protected]>
This time it works, thanks!
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Quoted 5 lines · Juergen Gross
Today all timers are migrated to cpu 0 when the system is being suspended. They are not migrated back after resuming the system again.
This results (at least) to problems with the credit scheduler, as the timer isn't handled on the cpu it was expected to occur.
While you say "at least", this doesn't really make clear in how far all four timers for which you change their handling are actually problematic, or whether for some you make the adjustment "just in case". Looking at core.c's s_timer I'm inclined to say that with s_timer_fn() raising the schedule softirq things can't go well when this doesn't happen on the correct CPU. Just that it won't be an obvious problem like the crash in credit1 which had prompted the creation of this patch.
Quoted 5 lines
Add migrating the scheduling related timers of a specific cpu from cpu 0 back to its original cpu when that cpu has gone up when resuming the system.
Signed-off-by Juergen Gross <[email protected]>
Is there any Fixes: tag possible? If not, could you add a respective note in the post-commit-message area, to increase the chance of recalling that this will want queuing for backport? (Or maybe the lack of a reasonable Fixes: tag could actually justify the use of the
Backport: one.)
xen/common/sched/core.c static int cpu_disable_scheduler_check(unsigned int cpu) · line 1291
Quoted 11 lines
xen/common/sched/core.c +5
-0@@ -1284,6 +1284,32 @@ static int cpu_disable_scheduler_check(unsigned int cpu)return 0 ; } +/* +* Called after a cpu has come up again in a suspend/resume cycle. +* Note that on a system with smt=0 this will be called for the sibling cpus, +* too, so the case for no scheduling resource being available must be +* considered.
I think this part of the comment would better live ...
xen/common/sched/core.c static int cpu_disable_scheduler_check(unsigned int cpu) · line 1303
Quoted 12 lines
xen/common/sched/core.c +12
-0+* Migrate all timers for this cpu (they have been migrated to cpu 0 when the +* cpu was going down). +* Note that only timers related to a physical cpu are migrated, not the ones +* related to a vcpu or domain. +*/ +void sched_migrate_timers (unsigned int cpu) +{ +struct sched_resource *sr; + +rcu_read_lock (&sched_res_rculock); + + sr =get_sched_res (cpu);
... inbetween here, increasing the chance that there won't be someone trying to remove the extra check ...
xen/common/sched/core.c static int cpu_disable_scheduler_check(unsigned int cpu) · line 1304
Quoted 1 line
xen/common/sched/core.c +1
-0+if ( sr && sr->master_cpu == cpu )
... from here.
I further think that explicitly mentioning "smt=0" isn't very helpful. Aiui a system with some CPUs otherwise soft-offlined would suffer the same problem. And I further assume no problem would occur even with "smt=0" on AMD hardware or Arm (where we don't park CPUs). At the very least I'd therefore like to ask for "e.g." to be inserted; better would be a more generic statement like "with some CPUs parked".
Jan
Quoted 19 lines · Jan Beulich
Quoted 5 lines · Juergen Gross
Today all timers are migrated to cpu 0 when the system is being suspended. They are not migrated back after resuming the system again.
This results (at least) to problems with the credit scheduler, as the timer isn't handled on the cpu it was expected to occur.
While you say "at least", this doesn't really make clear in how far all four timers for which you change their handling are actually problematic, or whether for some you make the adjustment "just in case". Looking at core.c's
s_timerI'm inclined to say that withs_timer_fn()raising the schedule softirq things can't go well when this doesn't happen on the correct CPU. Just that it won't be an obvious problem like the crash in credit1 which had prompted the creation of this patch.Quoted 4 lines
Add migrating the scheduling related timers of a specific cpu from cpu 0 back to its original cpu when that cpu has gone up when resuming the system.
Quoted 7 lines
Quoted 1 line
Signed-off-by Juergen Gross <[email protected]>Is there any Fixes: tag possible? If not, could you add a respective note in the post-commit-message area, to increase the chance of recalling that this will want queuing for backport? (Or maybe the lack of a reasonable Fixes: tag could actually justify the use of the
Backport: one.)
I'm not sure whether it is really correct, but I assume the most probable candidate for a Fixes: tag would be commit 0763cd268789.
Quoted 15 lines
xen/common/sched/core.c static int cpu_disable_scheduler_check(unsigned int cpu) · line 1291
Quoted 12 lines
xen/common/sched/core.c +5
-0@@ -1284,6 +1284,32 @@ static int cpu_disable_scheduler_check(unsigned int cpu)return 0 ; } +/* +* Called after a cpu has come up again in a suspend/resume cycle. +* Note that on a system with smt=0 this will be called for the sibling cpus, +* too, so the case for no scheduling resource being available must be +* considered. I think this part of the comment would better live ...
Quoted 15 lines
xen/common/sched/core.c static int cpu_disable_scheduler_check(unsigned int cpu) · line 1303
Quoted 12 lines
xen/common/sched/core.c +12
-0+* Migrate all timers for this cpu (they have been migrated to cpu 0 when the +* cpu was going down). +* Note that only timers related to a physical cpu are migrated, not the ones +* related to a vcpu or domain. +*/ +void sched_migrate_timers (unsigned int cpu) +{ +struct sched_resource *sr; + +rcu_read_lock (&sched_res_rculock); + + sr =get_sched_res (cpu);... inbetween here, increasing the chance that there won't be someone trying to remove the extra check ...
Okay.
Quoted 11 lines
xen/common/sched/core.c static int cpu_disable_scheduler_check(unsigned int cpu) · line 1304
Quoted 2 lines
xen/common/sched/core.c +1
-0+if ( sr && sr->master_cpu == cpu )... from here.
I further think that explicitly mentioning "smt=0" isn't very helpful. Aiui a system with some CPUs otherwise soft-offlined would suffer the same problem. And I further assume no problem would occur even with "smt=0" on AMD hardware or Arm (where we don't park CPUs). At the very least I'd therefore like to ask for "e.g." to be inserted; better would be a more generic statement like "with some CPUs parked".
I'll go with the latter.
Juergen