* [PATCH v2 0/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP @ 2017-03-17 18:19 Dario Faggioli 2017-03-17 18:19 ` [PATCH v2 1/2] " Dario Faggioli 2017-03-17 18:19 ` [PATCH v2 2/2] xen: sched: improve robustness (and rename) DOM2OP() Dario Faggioli 0 siblings, 2 replies; 14+ messages in thread From: Dario Faggioli @ 2017-03-17 18:19 UTC (permalink / raw) To: xen-devel; +Cc: Juergen Gross, George Dunlap, Jan Beulich Hi, This is v2 of https://lists.xen.org/archives/html/xen-devel/2017-03/msg02119.html It's now two patches. Patch 1 is what I already sent, amended taking into account Jan's suggesions. It is the actual bugfix and the one that should be backported. Patch 2 is basically applying the same principle to the DOM2OP() macro, which although not buggy, was equally unclear and potentially dangerous (plus some renaming, suggested by Juergen). Thanks and Regards, Dario --- Dario Faggioli (2): xen: sched: don't call hooks of the wrong scheduler via VCPU2OP xen: sched: improve robustness (and rename) DOM2OP() xen/common/schedule.c | 76 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 19 deletions(-) -- <<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 1/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP 2017-03-17 18:19 [PATCH v2 0/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP Dario Faggioli @ 2017-03-17 18:19 ` Dario Faggioli 2017-03-17 18:27 ` Juergen Gross ` (3 more replies) 2017-03-17 18:19 ` [PATCH v2 2/2] xen: sched: improve robustness (and rename) DOM2OP() Dario Faggioli 1 sibling, 4 replies; 14+ messages in thread From: Dario Faggioli @ 2017-03-17 18:19 UTC (permalink / raw) To: xen-devel; +Cc: Juergen Gross, George Dunlap, Jan Beulich Within context_saved(), we call the context_saved hook, and we use VCPU2OP() to determine from what scheduler. VCPU2OP uses DOM2OP, which uses d->cpupool, which is NULL when d is the idle domain. And in that case, DOM2OP just returns ops, the scheduler of cpupool0. Therefore, if: - cpupool0's scheduler defines context_saved (like Credit2 and RTDS do), - we are not in cpupool0 (i.e., our scheduler is not ops), - we are context switching from idle, we call VCPU2OP(idle_vcpu), which means DOM2OP(idle->cpupool), which is ops. Therefore, we both: - check if context_saved is defined in the wrong scheduler; - if yes, call the wrong one. When using Credit2 at boot, and also Credit2 in the other cpupool, this is wrong but innocuous, because it only involves the idle vcpus. When using Credit2 at boot, and Credit1 in the other cpupool, this is *totally* wrong, and it's by chance it does not explode! When using Credit2 and other schedulers I'm developping, I hit the following assert (in sched_credit2.c, on a CPU inside a cpupool that does not use Credit2): csched2_context_saved() { ... ASSERT(!vcpu_on_runq(svc)); ... } Fix this by dealing explicitly, in VCPU2OP, with idle vcpus, returning the scheduler of the pCPU they (always) run on. While there, rename VCPU2OP itself to something that makes it easier to understand what it does. Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> --- Cc: George Dunlap <george.dunlap@citrix.com> Cc: Juergen Gross <jgross@suse.com> Cc: Jan Beulich <jbeulich@suse.com> --- Changes from v1: - refactored according to review comments. Added code comments and an ASSERT(). --- Cc-ing Jan, as this should be backported at least to 4.8, but, IMO, as back as possible. --- xen/common/schedule.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 223a120..d344b7c 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -78,7 +78,27 @@ static struct scheduler __read_mostly ops; : (typeof((opsptr)->fn(opsptr, ##__VA_ARGS__)))0 ) #define DOM2OP(_d) (((_d)->cpupool == NULL) ? &ops : ((_d)->cpupool->sched)) -#define VCPU2OP(_v) (DOM2OP((_v)->domain)) +static inline struct scheduler *VCPU2OP(const struct vcpu *v) +{ + struct domain *d = v->domain; + + if ( likely(d->cpupool != NULL) ) + return d->cpupool->sched; + + /* + * If d->cpupool is NULL, this is a vCPU of the idle domain. And this + * case is special because the idle domain does not really belong to + * a cpupool and, hence, doesn't really have a scheduler). In fact, its + * vCPUs (may) run on pCPUs which are in different pools, with different + * schedulers. + * + * What we want, in this case, is the scheduler of the pCPU where this + * particular idle vCPU is running. And, since v->processor never changes + * for idle vCPUs, it is safe to use it, with no locks, to figure that out. + */ + ASSERT(is_idle_domain(d)); + return per_cpu(scheduler, v->processor); +} #define VCPU2ONLINE(_v) cpupool_domain_cpumask((_v)->domain) static inline void trace_runstate_change(struct vcpu *v, int new_state) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2 1/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP 2017-03-17 18:19 ` [PATCH v2 1/2] " Dario Faggioli @ 2017-03-17 18:27 ` Juergen Gross 2017-03-17 18:29 ` Juergen Gross ` (2 subsequent siblings) 3 siblings, 0 replies; 14+ messages in thread From: Juergen Gross @ 2017-03-17 18:27 UTC (permalink / raw) To: Dario Faggioli, xen-devel; +Cc: George Dunlap, Jan Beulich On 17/03/17 19:19, Dario Faggioli wrote: > Within context_saved(), we call the context_saved hook, > and we use VCPU2OP() to determine from what scheduler. > VCPU2OP uses DOM2OP, which uses d->cpupool, which is > NULL when d is the idle domain. And in that case, > DOM2OP just returns ops, the scheduler of cpupool0. > > Therefore, if: > - cpupool0's scheduler defines context_saved (like > Credit2 and RTDS do), > - we are not in cpupool0 (i.e., our scheduler is > not ops), > - we are context switching from idle, > > we call VCPU2OP(idle_vcpu), which means > DOM2OP(idle->cpupool), which is ops. > > Therefore, we both: > - check if context_saved is defined in the wrong > scheduler; > - if yes, call the wrong one. > > When using Credit2 at boot, and also Credit2 in > the other cpupool, this is wrong but innocuous, > because it only involves the idle vcpus. > > When using Credit2 at boot, and Credit1 in the > other cpupool, this is *totally* wrong, and > it's by chance it does not explode! > > When using Credit2 and other schedulers I'm > developping, I hit the following assert (in > sched_credit2.c, on a CPU inside a cpupool that > does not use Credit2): > > csched2_context_saved() > { > ... > ASSERT(!vcpu_on_runq(svc)); > ... > } > > Fix this by dealing explicitly, in VCPU2OP, with > idle vcpus, returning the scheduler of the pCPU > they (always) run on. > > While there, rename VCPU2OP itself to something > that makes it easier to understand what it does. > > Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> Reviewed-by: Juergen Gross <jgross@suse.com> Juergen _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 1/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP 2017-03-17 18:19 ` [PATCH v2 1/2] " Dario Faggioli 2017-03-17 18:27 ` Juergen Gross @ 2017-03-17 18:29 ` Juergen Gross 2017-03-20 8:01 ` Jan Beulich 2017-03-27 11:48 ` George Dunlap 2017-03-27 11:49 ` George Dunlap 3 siblings, 1 reply; 14+ messages in thread From: Juergen Gross @ 2017-03-17 18:29 UTC (permalink / raw) To: Dario Faggioli, xen-devel; +Cc: George Dunlap, Jan Beulich On 17/03/17 19:19, Dario Faggioli wrote: > Within context_saved(), we call the context_saved hook, > and we use VCPU2OP() to determine from what scheduler. > VCPU2OP uses DOM2OP, which uses d->cpupool, which is > NULL when d is the idle domain. And in that case, > DOM2OP just returns ops, the scheduler of cpupool0. > > Therefore, if: > - cpupool0's scheduler defines context_saved (like > Credit2 and RTDS do), > - we are not in cpupool0 (i.e., our scheduler is > not ops), > - we are context switching from idle, > > we call VCPU2OP(idle_vcpu), which means > DOM2OP(idle->cpupool), which is ops. > > Therefore, we both: > - check if context_saved is defined in the wrong > scheduler; > - if yes, call the wrong one. > > When using Credit2 at boot, and also Credit2 in > the other cpupool, this is wrong but innocuous, > because it only involves the idle vcpus. > > When using Credit2 at boot, and Credit1 in the > other cpupool, this is *totally* wrong, and > it's by chance it does not explode! > > When using Credit2 and other schedulers I'm > developping, I hit the following assert (in > sched_credit2.c, on a CPU inside a cpupool that > does not use Credit2): > > csched2_context_saved() > { > ... > ASSERT(!vcpu_on_runq(svc)); > ... > } > > Fix this by dealing explicitly, in VCPU2OP, with > idle vcpus, returning the scheduler of the pCPU > they (always) run on. > > While there, rename VCPU2OP itself to something > that makes it easier to understand what it does. > > Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> Reviewed-by: Juergen Gross <jgross@suse.com> Juergen _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 1/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP 2017-03-17 18:29 ` Juergen Gross @ 2017-03-20 8:01 ` Jan Beulich 0 siblings, 0 replies; 14+ messages in thread From: Jan Beulich @ 2017-03-20 8:01 UTC (permalink / raw) To: Juergen Gross; +Cc: xen-devel, Dario Faggioli, George Dunlap >>> On 17.03.17 at 19:29, <jgross@suse.com> wrote: > On 17/03/17 19:19, Dario Faggioli wrote: >> Within context_saved(), we call the context_saved hook, >> and we use VCPU2OP() to determine from what scheduler. >> VCPU2OP uses DOM2OP, which uses d->cpupool, which is >> NULL when d is the idle domain. And in that case, >> DOM2OP just returns ops, the scheduler of cpupool0. >> >> Therefore, if: >> - cpupool0's scheduler defines context_saved (like >> Credit2 and RTDS do), >> - we are not in cpupool0 (i.e., our scheduler is >> not ops), >> - we are context switching from idle, >> >> we call VCPU2OP(idle_vcpu), which means >> DOM2OP(idle->cpupool), which is ops. >> >> Therefore, we both: >> - check if context_saved is defined in the wrong >> scheduler; >> - if yes, call the wrong one. >> >> When using Credit2 at boot, and also Credit2 in >> the other cpupool, this is wrong but innocuous, >> because it only involves the idle vcpus. >> >> When using Credit2 at boot, and Credit1 in the >> other cpupool, this is *totally* wrong, and >> it's by chance it does not explode! >> >> When using Credit2 and other schedulers I'm >> developping, I hit the following assert (in >> sched_credit2.c, on a CPU inside a cpupool that >> does not use Credit2): >> >> csched2_context_saved() >> { >> ... >> ASSERT(!vcpu_on_runq(svc)); >> ... >> } >> >> Fix this by dealing explicitly, in VCPU2OP, with >> idle vcpus, returning the scheduler of the pCPU >> they (always) run on. >> >> While there, rename VCPU2OP itself to something >> that makes it easier to understand what it does. >> >> Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> > > Reviewed-by: Juergen Gross <jgross@suse.com> This came through twice, so I'm now wondering whether one of them was meant for 2/2, or whether this was just some infrastructure glitch. Jan _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 1/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP 2017-03-17 18:19 ` [PATCH v2 1/2] " Dario Faggioli 2017-03-17 18:27 ` Juergen Gross 2017-03-17 18:29 ` Juergen Gross @ 2017-03-27 11:48 ` George Dunlap 2017-03-27 11:49 ` George Dunlap 3 siblings, 0 replies; 14+ messages in thread From: George Dunlap @ 2017-03-27 11:48 UTC (permalink / raw) To: Dario Faggioli, xen-devel; +Cc: Juergen Gross, Jan Beulich On 17/03/17 18:19, Dario Faggioli wrote: > Within context_saved(), we call the context_saved hook, > and we use VCPU2OP() to determine from what scheduler. > VCPU2OP uses DOM2OP, which uses d->cpupool, which is > NULL when d is the idle domain. And in that case, > DOM2OP just returns ops, the scheduler of cpupool0. > > Therefore, if: > - cpupool0's scheduler defines context_saved (like > Credit2 and RTDS do), > - we are not in cpupool0 (i.e., our scheduler is > not ops), > - we are context switching from idle, > > we call VCPU2OP(idle_vcpu), which means > DOM2OP(idle->cpupool), which is ops. > > Therefore, we both: > - check if context_saved is defined in the wrong > scheduler; > - if yes, call the wrong one. > > When using Credit2 at boot, and also Credit2 in > the other cpupool, this is wrong but innocuous, > because it only involves the idle vcpus. > > When using Credit2 at boot, and Credit1 in the > other cpupool, this is *totally* wrong, and > it's by chance it does not explode! > > When using Credit2 and other schedulers I'm > developping, I hit the following assert (in > sched_credit2.c, on a CPU inside a cpupool that > does not use Credit2): > > csched2_context_saved() > { > ... > ASSERT(!vcpu_on_runq(svc)); > ... > } > > Fix this by dealing explicitly, in VCPU2OP, with > idle vcpus, returning the scheduler of the pCPU > they (always) run on. > > While there, rename VCPU2OP itself to something > that makes it easier to understand what it does. > > Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> Reviewed-by: George Dunlap <george.dunlap@citrix.com> _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 1/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP 2017-03-17 18:19 ` [PATCH v2 1/2] " Dario Faggioli ` (2 preceding siblings ...) 2017-03-27 11:48 ` George Dunlap @ 2017-03-27 11:49 ` George Dunlap 2017-03-27 15:07 ` Dario Faggioli 3 siblings, 1 reply; 14+ messages in thread From: George Dunlap @ 2017-03-27 11:49 UTC (permalink / raw) To: Dario Faggioli, xen-devel; +Cc: Juergen Gross, Jan Beulich On 17/03/17 18:19, Dario Faggioli wrote: > Within context_saved(), we call the context_saved hook, > and we use VCPU2OP() to determine from what scheduler. > VCPU2OP uses DOM2OP, which uses d->cpupool, which is > NULL when d is the idle domain. And in that case, > DOM2OP just returns ops, the scheduler of cpupool0. > > Therefore, if: > - cpupool0's scheduler defines context_saved (like > Credit2 and RTDS do), > - we are not in cpupool0 (i.e., our scheduler is > not ops), > - we are context switching from idle, > > we call VCPU2OP(idle_vcpu), which means > DOM2OP(idle->cpupool), which is ops. > > Therefore, we both: > - check if context_saved is defined in the wrong > scheduler; > - if yes, call the wrong one. > > When using Credit2 at boot, and also Credit2 in > the other cpupool, this is wrong but innocuous, > because it only involves the idle vcpus. > > When using Credit2 at boot, and Credit1 in the > other cpupool, this is *totally* wrong, and > it's by chance it does not explode! > > When using Credit2 and other schedulers I'm > developping, I hit the following assert (in > sched_credit2.c, on a CPU inside a cpupool that > does not use Credit2): > > csched2_context_saved() > { > ... > ASSERT(!vcpu_on_runq(svc)); > ... > } > > Fix this by dealing explicitly, in VCPU2OP, with > idle vcpus, returning the scheduler of the pCPU > they (always) run on. > > While there, rename VCPU2OP itself to something > that makes it easier to understand what it does. This seems to have been moved into patch 2/2 -- I'll remove this paragraph on commit if that's OK with you. -George _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 1/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP 2017-03-27 11:49 ` George Dunlap @ 2017-03-27 15:07 ` Dario Faggioli 0 siblings, 0 replies; 14+ messages in thread From: Dario Faggioli @ 2017-03-27 15:07 UTC (permalink / raw) To: George Dunlap, xen-devel; +Cc: Juergen Gross, Jan Beulich [-- Attachment #1.1: Type: text/plain, Size: 817 bytes --] On Mon, 2017-03-27 at 12:49 +0100, George Dunlap wrote: > On 17/03/17 18:19, Dario Faggioli wrote: > > Fix this by dealing explicitly, in VCPU2OP, with > > idle vcpus, returning the scheduler of the pCPU > > they (always) run on. > > > > While there, rename VCPU2OP itself to something > > that makes it easier to understand what it does. > > This seems to have been moved into patch 2/2 -- I'll remove this > paragraph on commit if that's OK with you. > Mmm... Yes, sorry for this. I'm ok with you dropping the paragraph. Thanks. Dario -- <<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) [-- Attachment #1.2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 819 bytes --] [-- Attachment #2: Type: text/plain, Size: 127 bytes --] _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 2/2] xen: sched: improve robustness (and rename) DOM2OP() 2017-03-17 18:19 [PATCH v2 0/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP Dario Faggioli 2017-03-17 18:19 ` [PATCH v2 1/2] " Dario Faggioli @ 2017-03-17 18:19 ` Dario Faggioli 2017-03-27 13:23 ` George Dunlap 1 sibling, 1 reply; 14+ messages in thread From: Dario Faggioli @ 2017-03-17 18:19 UTC (permalink / raw) To: xen-devel; +Cc: Juergen Gross, George Dunlap, Jan Beulich Clarify and enforce (with ASSERTs) when the function is called on the idle domain, and explain in comments what it means and when it is ok to do so. While there, change the name of the function to a more self-explanatory one, and do the same to VCPU2OP. Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> --- Cc: George Dunlap <george.dunlap@citrix.com> Cc: Juergen Gross <jgross@suse.com> Cc: Jan Beulich <jbeulich@suse.com> --- Changes from v1: - new patch; - renamed VCPU2OP, as suggested during v1's review of patch 1. --- xen/common/schedule.c | 56 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index d344b7c..fdb8ff4 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -77,8 +77,25 @@ static struct scheduler __read_mostly ops; (( (opsptr)->fn != NULL ) ? (opsptr)->fn(opsptr, ##__VA_ARGS__ ) \ : (typeof((opsptr)->fn(opsptr, ##__VA_ARGS__)))0 ) -#define DOM2OP(_d) (((_d)->cpupool == NULL) ? &ops : ((_d)->cpupool->sched)) -static inline struct scheduler *VCPU2OP(const struct vcpu *v) +static inline struct scheduler *dom_get_scheduler(const struct domain *d) +{ + if ( likely(d->cpupool != NULL) ) + return d->cpupool->sched; + + /* + * If d->cpupool is NULL, this is the idle domain. This is special + * because the idle domain does not really bolong to any cpupool, and, + * hence, does not really have a scheduler. + * + * This is (should be!) only called like this for allocating the idle + * vCPUs for the first time, during boot, in which case what we want + * is the default scheduler that has been, choosen at boot. + */ + ASSERT(is_idle_domain(d)); + return &ops; +} + +static inline struct scheduler *vcpu_get_scheduler(const struct vcpu *v) { struct domain *d = v->domain; @@ -260,7 +277,8 @@ int sched_init_vcpu(struct vcpu *v, unsigned int processor) init_timer(&v->poll_timer, poll_timer_fn, v, v->processor); - v->sched_priv = SCHED_OP(DOM2OP(d), alloc_vdata, v, d->sched_priv); + v->sched_priv = SCHED_OP(dom_get_scheduler(d), alloc_vdata, v, + d->sched_priv); if ( v->sched_priv == NULL ) return 1; @@ -272,7 +290,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int processor) } else { - SCHED_OP(DOM2OP(d), insert_vcpu, v); + SCHED_OP(dom_get_scheduler(d), insert_vcpu, v); } return 0; @@ -326,7 +344,7 @@ int sched_move_domain(struct domain *d, struct cpupool *c) domain_pause(d); - old_ops = DOM2OP(d); + old_ops = dom_get_scheduler(d); old_domdata = d->sched_priv; for_each_vcpu ( d, v ) @@ -389,8 +407,8 @@ void sched_destroy_vcpu(struct vcpu *v) kill_timer(&v->poll_timer); if ( test_and_clear_bool(v->is_urgent) ) atomic_dec(&per_cpu(schedule_data, v->processor).urgent_count); - SCHED_OP(VCPU2OP(v), remove_vcpu, v); - SCHED_OP(VCPU2OP(v), free_vdata, v->sched_priv); + SCHED_OP(vcpu_get_scheduler(v), remove_vcpu, v); + SCHED_OP(vcpu_get_scheduler(v), free_vdata, v->sched_priv); } int sched_init_domain(struct domain *d, int poolid) @@ -404,7 +422,7 @@ int sched_init_domain(struct domain *d, int poolid) SCHED_STAT_CRANK(dom_init); TRACE_1D(TRC_SCHED_DOM_ADD, d->domain_id); - return SCHED_OP(DOM2OP(d), init_domain, d); + return SCHED_OP(dom_get_scheduler(d), init_domain, d); } void sched_destroy_domain(struct domain *d) @@ -413,7 +431,7 @@ void sched_destroy_domain(struct domain *d) SCHED_STAT_CRANK(dom_destroy); TRACE_1D(TRC_SCHED_DOM_REM, d->domain_id); - SCHED_OP(DOM2OP(d), destroy_domain, d); + SCHED_OP(dom_get_scheduler(d), destroy_domain, d); cpupool_rm_domain(d); } @@ -432,7 +450,7 @@ void vcpu_sleep_nosync(struct vcpu *v) if ( v->runstate.state == RUNSTATE_runnable ) vcpu_runstate_change(v, RUNSTATE_offline, NOW()); - SCHED_OP(VCPU2OP(v), sleep, v); + SCHED_OP(vcpu_get_scheduler(v), sleep, v); } vcpu_schedule_unlock_irqrestore(lock, flags, v); @@ -461,7 +479,7 @@ void vcpu_wake(struct vcpu *v) { if ( v->runstate.state >= RUNSTATE_blocked ) vcpu_runstate_change(v, RUNSTATE_runnable, NOW()); - SCHED_OP(VCPU2OP(v), wake, v); + SCHED_OP(vcpu_get_scheduler(v), wake, v); } else if ( !(v->pause_flags & VPF_blocked) ) { @@ -516,8 +534,8 @@ static void vcpu_move_locked(struct vcpu *v, unsigned int new_cpu) * Actual CPU switch to new CPU. This is safe because the lock * pointer cant' change while the current lock is held. */ - if ( VCPU2OP(v)->migrate ) - SCHED_OP(VCPU2OP(v), migrate, v, new_cpu); + if ( vcpu_get_scheduler(v)->migrate ) + SCHED_OP(vcpu_get_scheduler(v), migrate, v, new_cpu); else v->processor = new_cpu; } @@ -583,7 +601,7 @@ static void vcpu_migrate(struct vcpu *v) break; /* Select a new CPU. */ - new_cpu = SCHED_OP(VCPU2OP(v), pick_cpu, v); + new_cpu = SCHED_OP(vcpu_get_scheduler(v), pick_cpu, v); if ( (new_lock == per_cpu(schedule_data, new_cpu).schedule_lock) && cpumask_test_cpu(new_cpu, v->domain->cpupool->cpu_valid) ) break; @@ -685,7 +703,7 @@ void restore_vcpu_affinity(struct domain *d) spin_unlock_irq(lock);; lock = vcpu_schedule_lock_irq(v); - v->processor = SCHED_OP(VCPU2OP(v), pick_cpu, v); + v->processor = SCHED_OP(vcpu_get_scheduler(v), pick_cpu, v); spin_unlock_irq(lock); } @@ -975,7 +993,7 @@ long vcpu_yield(void) struct vcpu * v=current; spinlock_t *lock = vcpu_schedule_lock_irq(v); - SCHED_OP(VCPU2OP(v), yield, v); + SCHED_OP(vcpu_get_scheduler(v), yield, v); vcpu_schedule_unlock_irq(lock, v); SCHED_STAT_CRANK(vcpu_yield); @@ -1288,7 +1306,7 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op) if ( ret ) return ret; - if ( op->sched_id != DOM2OP(d)->sched_id ) + if ( op->sched_id != dom_get_scheduler(d)->sched_id ) return -EINVAL; switch ( op->cmd ) @@ -1304,7 +1322,7 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op) /* NB: the pluggable scheduler code needs to take care * of locking by itself. */ - if ( (ret = SCHED_OP(DOM2OP(d), adjust, d, op)) == 0 ) + if ( (ret = SCHED_OP(dom_get_scheduler(d), adjust, d, op)) == 0 ) TRACE_1D(TRC_SCHED_ADJDOM, d->domain_id); return ret; @@ -1482,7 +1500,7 @@ void context_saved(struct vcpu *prev) /* Check for migration request /after/ clearing running flag. */ smp_mb(); - SCHED_OP(VCPU2OP(prev), context_saved, prev); + SCHED_OP(vcpu_get_scheduler(prev), context_saved, prev); if ( unlikely(prev->pause_flags & VPF_migrating) ) vcpu_migrate(prev); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/2] xen: sched: improve robustness (and rename) DOM2OP() 2017-03-17 18:19 ` [PATCH v2 2/2] xen: sched: improve robustness (and rename) DOM2OP() Dario Faggioli @ 2017-03-27 13:23 ` George Dunlap 2017-03-27 15:13 ` Dario Faggioli 2017-04-06 10:59 ` Dario Faggioli 0 siblings, 2 replies; 14+ messages in thread From: George Dunlap @ 2017-03-27 13:23 UTC (permalink / raw) To: Dario Faggioli, xen-devel; +Cc: Juergen Gross, Jan Beulich On 17/03/17 18:19, Dario Faggioli wrote: > Clarify and enforce (with ASSERTs) when the function > is called on the idle domain, and explain in comments > what it means and when it is ok to do so. > > While there, change the name of the function to a more > self-explanatory one, and do the same to VCPU2OP. > > Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> > --- > Cc: George Dunlap <george.dunlap@citrix.com> > Cc: Juergen Gross <jgross@suse.com> > Cc: Jan Beulich <jbeulich@suse.com> > --- > Changes from v1: > - new patch; > - renamed VCPU2OP, as suggested during v1's review of patch 1. > --- > xen/common/schedule.c | 56 ++++++++++++++++++++++++++++++++----------------- > 1 file changed, 37 insertions(+), 19 deletions(-) > > diff --git a/xen/common/schedule.c b/xen/common/schedule.c > index d344b7c..fdb8ff4 100644 > --- a/xen/common/schedule.c > +++ b/xen/common/schedule.c > @@ -77,8 +77,25 @@ static struct scheduler __read_mostly ops; > (( (opsptr)->fn != NULL ) ? (opsptr)->fn(opsptr, ##__VA_ARGS__ ) \ > : (typeof((opsptr)->fn(opsptr, ##__VA_ARGS__)))0 ) > > -#define DOM2OP(_d) (((_d)->cpupool == NULL) ? &ops : ((_d)->cpupool->sched)) > -static inline struct scheduler *VCPU2OP(const struct vcpu *v) > +static inline struct scheduler *dom_get_scheduler(const struct domain *d) Hmm -- I agree that VCPU2OP is probably not the right name, but I'm not a fan of the new name either; and I don't have an option I like better yet. With your permission I'll check in the first patch and come back to this. -George _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/2] xen: sched: improve robustness (and rename) DOM2OP() 2017-03-27 13:23 ` George Dunlap @ 2017-03-27 15:13 ` Dario Faggioli 2017-04-06 10:59 ` Dario Faggioli 1 sibling, 0 replies; 14+ messages in thread From: Dario Faggioli @ 2017-03-27 15:13 UTC (permalink / raw) To: George Dunlap, xen-devel; +Cc: Juergen Gross, Jan Beulich [-- Attachment #1.1: Type: text/plain, Size: 1570 bytes --] On Mon, 2017-03-27 at 14:23 +0100, George Dunlap wrote: > On 17/03/17 18:19, Dario Faggioli wrote: > > --- a/xen/common/schedule.c > > +++ b/xen/common/schedule.c > > @@ -77,8 +77,25 @@ static struct scheduler __read_mostly ops; > > (( (opsptr)->fn != NULL ) ? (opsptr)->fn(opsptr, > > ##__VA_ARGS__ ) \ > > : (typeof((opsptr)->fn(opsptr, ##__VA_ARGS__)))0 ) > > > > -#define DOM2OP(_d) (((_d)->cpupool == NULL) ? &ops : ((_d)- > > >cpupool->sched)) > > -static inline struct scheduler *VCPU2OP(const struct vcpu *v) > > +static inline struct scheduler *dom_get_scheduler(const struct > > domain *d) > > Hmm -- I agree that VCPU2OP is probably not the right name, but I'm > not > a fan of the new name either; and I don't have an option I like > better yet. > > With your permission I'll check in the first patch and come back to > this. > Ok. The renaming was the least important part of what is done in this patch. But indeed I do think that, while here, we should take the chance the names as well (especially considering they won't be macro, so the "all capital letters" should go). But, sure, go ahead with the first patch... I'll try to think and propose a better name when/if I'll fine one. :-) Thanks, Dario -- <<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) [-- Attachment #1.2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 819 bytes --] [-- Attachment #2: Type: text/plain, Size: 127 bytes --] _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/2] xen: sched: improve robustness (and rename) DOM2OP() 2017-03-27 13:23 ` George Dunlap 2017-03-27 15:13 ` Dario Faggioli @ 2017-04-06 10:59 ` Dario Faggioli 2017-04-06 11:06 ` Juergen Gross 1 sibling, 1 reply; 14+ messages in thread From: Dario Faggioli @ 2017-04-06 10:59 UTC (permalink / raw) To: George Dunlap, xen-devel; +Cc: Juergen Gross, Jan Beulich [-- Attachment #1.1: Type: text/plain, Size: 1458 bytes --] On Mon, 2017-03-27 at 14:23 +0100, George Dunlap wrote: > On 17/03/17 18:19, Dario Faggioli wrote: > > --- a/xen/common/schedule.c > > +++ b/xen/common/schedule.c > > @@ -77,8 +77,25 @@ static struct scheduler __read_mostly ops; > > (( (opsptr)->fn != NULL ) ? (opsptr)->fn(opsptr, > > ##__VA_ARGS__ ) \ > > : (typeof((opsptr)->fn(opsptr, ##__VA_ARGS__)))0 ) > > > > -#define DOM2OP(_d) (((_d)->cpupool == NULL) ? &ops : ((_d)- > > >cpupool->sched)) > > -static inline struct scheduler *VCPU2OP(const struct vcpu *v) > > +static inline struct scheduler *dom_get_scheduler(const struct > > domain *d) > > Hmm -- I agree that VCPU2OP is probably not the right name, but I'm > not > a fan of the new name either; and I don't have an option I like > better yet. > Maybe: domain_scheduler() vcpu_scheduler() or dom_scheduler() vcpu_scheduler() I.e., basically getting rid of the 'get' part, which may misleadingly hint at some kind of reference counting. Or, also trading 'scheduler' for 'ops': dom_ops() vcpu_ops() This is all I can come up with, my preference being {dom,vcpu}_scheduler(). Dario -- <<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) [-- Attachment #1.2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 819 bytes --] [-- Attachment #2: Type: text/plain, Size: 127 bytes --] _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/2] xen: sched: improve robustness (and rename) DOM2OP() 2017-04-06 10:59 ` Dario Faggioli @ 2017-04-06 11:06 ` Juergen Gross 2017-04-07 0:31 ` Dario Faggioli 0 siblings, 1 reply; 14+ messages in thread From: Juergen Gross @ 2017-04-06 11:06 UTC (permalink / raw) To: Dario Faggioli, George Dunlap, xen-devel; +Cc: Jan Beulich On 06/04/17 12:59, Dario Faggioli wrote: > On Mon, 2017-03-27 at 14:23 +0100, George Dunlap wrote: >> On 17/03/17 18:19, Dario Faggioli wrote: >>> --- a/xen/common/schedule.c >>> +++ b/xen/common/schedule.c >>> @@ -77,8 +77,25 @@ static struct scheduler __read_mostly ops; >>> (( (opsptr)->fn != NULL ) ? (opsptr)->fn(opsptr, >>> ##__VA_ARGS__ ) \ >>> : (typeof((opsptr)->fn(opsptr, ##__VA_ARGS__)))0 ) >>> >>> -#define DOM2OP(_d) (((_d)->cpupool == NULL) ? &ops : ((_d)- >>>> cpupool->sched)) >>> -static inline struct scheduler *VCPU2OP(const struct vcpu *v) >>> +static inline struct scheduler *dom_get_scheduler(const struct >>> domain *d) >> >> Hmm -- I agree that VCPU2OP is probably not the right name, but I'm >> not >> a fan of the new name either; and I don't have an option I like >> better yet. >> > Maybe: > > domain_scheduler() > vcpu_scheduler() > > or > > dom_scheduler() > vcpu_scheduler() > > I.e., basically getting rid of the 'get' part, which may misleadingly > hint at some kind of reference counting. > > Or, also trading 'scheduler' for 'ops': > > dom_ops() > vcpu_ops() sched_ops_dom() sched_ops_vcpu() or sched_dom_ops() sched_vcpu_ops() Juergen _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/2] xen: sched: improve robustness (and rename) DOM2OP() 2017-04-06 11:06 ` Juergen Gross @ 2017-04-07 0:31 ` Dario Faggioli 0 siblings, 0 replies; 14+ messages in thread From: Dario Faggioli @ 2017-04-07 0:31 UTC (permalink / raw) To: Juergen Gross, George Dunlap, xen-devel; +Cc: Jan Beulich [-- Attachment #1.1: Type: text/plain, Size: 926 bytes --] On Thu, 2017-04-06 at 13:06 +0200, Juergen Gross wrote: > On 06/04/17 12:59, Dario Faggioli wrote: > > Maybe: > > > > domain_scheduler() > > vcpu_scheduler() > > > > or > > > > dom_scheduler() > > vcpu_scheduler() > > > > Or, also trading 'scheduler' for 'ops': > > > > dom_ops() > > vcpu_ops() > > sched_ops_dom() > sched_ops_vcpu() > > or > > sched_dom_ops() > sched_vcpu_ops() > Yeah, these too. So, for now, I've resent using dom_scheduler() and vcpu_scheduler(). But I'm happy to change them to whatever and re-send again, as soon as George tells me which one is his preferred solution. :-D Thanks and Regards, Dario -- <<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) [-- Attachment #1.2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 819 bytes --] [-- Attachment #2: Type: text/plain, Size: 127 bytes --] _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2017-04-07 0:32 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-03-17 18:19 [PATCH v2 0/2] xen: sched: don't call hooks of the wrong scheduler via VCPU2OP Dario Faggioli 2017-03-17 18:19 ` [PATCH v2 1/2] " Dario Faggioli 2017-03-17 18:27 ` Juergen Gross 2017-03-17 18:29 ` Juergen Gross 2017-03-20 8:01 ` Jan Beulich 2017-03-27 11:48 ` George Dunlap 2017-03-27 11:49 ` George Dunlap 2017-03-27 15:07 ` Dario Faggioli 2017-03-17 18:19 ` [PATCH v2 2/2] xen: sched: improve robustness (and rename) DOM2OP() Dario Faggioli 2017-03-27 13:23 ` George Dunlap 2017-03-27 15:13 ` Dario Faggioli 2017-04-06 10:59 ` Dario Faggioli 2017-04-06 11:06 ` Juergen Gross 2017-04-07 0:31 ` Dario Faggioli
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.