From patchwork Sat Sep 14 08:52:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11145597 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1382F112B for ; Sat, 14 Sep 2019 08:54:48 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E2EAC20717 for ; Sat, 14 Sep 2019 08:54:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2EAC20717 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i93ng-0007UA-2S; Sat, 14 Sep 2019 08:53:00 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i93ne-0007Tx-NI for xen-devel@lists.xenproject.org; Sat, 14 Sep 2019 08:52:58 +0000 X-Inumbo-ID: 0b2d589f-d6cd-11e9-95c1-12813bfff9fa Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0b2d589f-d6cd-11e9-95c1-12813bfff9fa; Sat, 14 Sep 2019 08:52:56 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 87345B617; Sat, 14 Sep 2019 08:52:55 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Sat, 14 Sep 2019 10:52:08 +0200 Message-Id: <20190914085251.18816-5-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190914085251.18816-1-jgross@suse.com> References: <20190914085251.18816-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v3 04/47] xen/sched: introduce struct sched_resource X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Tim Deegan , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Dario Faggioli , Julien Grall , Meng Xu , Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Add a scheduling abstraction layer between physical processors and the schedulers by introducing a struct sched_resource. Each scheduler unit running is active on such a scheduler resource. For the time being there is one struct sched_resource per cpu, but in future there might be one for each core or socket only. Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- V1: - add accessor functions - use DEFINE_PER_CPU_READ_MOSTLY (Dario Faggioli) V3: - don't pre-define struct sched_resource in sched.h (Jan Beulich) - rename res->processor to res->master_cpu (Jan Beulich) --- xen/common/sched_credit.c | 2 ++ xen/common/sched_credit2.c | 7 +++++++ xen/common/sched_null.c | 3 +++ xen/common/sched_rt.c | 2 ++ xen/common/schedule.c | 19 ++++++++++++++++++- xen/include/xen/sched-if.h | 18 ++++++++++++++++++ xen/include/xen/sched.h | 1 + 7 files changed, 51 insertions(+), 1 deletion(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index f4371d7c5e..2bc7fa9220 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1026,6 +1026,7 @@ csched_unit_insert(const struct scheduler *ops, struct sched_unit *unit) lock = vcpu_schedule_lock_irq(vc); vc->processor = csched_cpu_pick(ops, unit); + unit->res = get_sched_res(vc->processor); spin_unlock_irq(lock); @@ -1662,6 +1663,7 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, int balance_step) WARN_ON(vc->is_urgent); runq_remove(speer); vc->processor = cpu; + vc->sched_unit->res = get_sched_res(cpu); /* * speer will start executing directly on cpu, without having to * go through runq_insert(). So we must update the runnable count diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 2852a220c4..200de63bee 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -2520,6 +2520,7 @@ static void migrate(const struct scheduler *ops, &trqd->active); svc->vcpu->processor = cpumask_cycle(trqd->pick_bias, cpumask_scratch_cpu(cpu)); + svc->vcpu->sched_unit->res = get_sched_res(svc->vcpu->processor); trqd->pick_bias = svc->vcpu->processor; ASSERT(svc->vcpu->processor < nr_cpu_ids); @@ -2775,6 +2776,7 @@ csched2_unit_migrate( } _runq_deassign(svc); vc->processor = new_cpu; + unit->res = get_sched_res(new_cpu); return; } @@ -2795,7 +2797,10 @@ csched2_unit_migrate( if ( trqd != svc->rqd ) migrate(ops, svc, trqd, now); else + { vc->processor = new_cpu; + unit->res = get_sched_res(new_cpu); + } } static int @@ -3120,6 +3125,7 @@ csched2_unit_insert(const struct scheduler *ops, struct sched_unit *unit) lock = vcpu_schedule_lock_irq(vc); vc->processor = csched2_cpu_pick(ops, unit); + unit->res = get_sched_res(vc->processor); spin_unlock_irq(lock); @@ -3597,6 +3603,7 @@ csched2_schedule( { snext->credit += CSCHED2_MIGRATE_COMPENSATION; snext->vcpu->processor = cpu; + snext->vcpu->sched_unit->res = get_sched_res(cpu); SCHED_STAT_CRANK(migrated); ret.migrated = 1; } diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index bb9fed8aab..c30fe2e443 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -337,6 +337,7 @@ static void vcpu_assign(struct null_private *prv, struct vcpu *v, per_cpu(npc, cpu).vcpu = v; v->processor = cpu; + v->sched_unit->res = get_sched_res(cpu); cpumask_clear_cpu(cpu, &prv->cpus_free); dprintk(XENLOG_G_INFO, "%d <-- %pv\n", cpu, v); @@ -457,6 +458,7 @@ static void null_unit_insert(const struct scheduler *ops, retry: cpu = v->processor = pick_cpu(prv, v); + unit->res = get_sched_res(cpu); spin_unlock(lock); @@ -749,6 +751,7 @@ static void null_unit_migrate(const struct scheduler *ops, */ out: v->processor = new_cpu; + unit->res = get_sched_res(new_cpu); } #ifndef NDEBUG diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index dd51613845..3ba76f1c4a 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -893,6 +893,7 @@ rt_unit_insert(const struct scheduler *ops, struct sched_unit *unit) /* This is safe because vc isn't yet being scheduled */ vc->processor = rt_cpu_pick(ops, unit); + unit->res = get_sched_res(vc->processor); lock = vcpu_schedule_lock_irq(vc); @@ -1123,6 +1124,7 @@ rt_schedule(const struct scheduler *ops, s_time_t now, bool_t tasklet_work_sched if ( snext->vcpu->processor != cpu ) { snext->vcpu->processor = cpu; + snext->vcpu->sched_unit->res = get_sched_res(cpu); ret.migrated = 1; } ret.time = snext->cur_budget; /* invoke the scheduler next time */ diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 614df9d226..2bf7966476 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -67,6 +67,7 @@ static void poll_timer_fn(void *data); /* This is global for now so that private implementations can reach it */ DEFINE_PER_CPU(struct schedule_data, schedule_data); DEFINE_PER_CPU(struct scheduler *, scheduler); +DEFINE_PER_CPU_READ_MOSTLY(struct sched_resource *, sched_res); /* Scratch space for cpumasks. */ DEFINE_PER_CPU(cpumask_t, cpumask_scratch); @@ -89,7 +90,7 @@ sched_idle_switch_sched(struct scheduler *new_ops, unsigned int cpu, static int sched_idle_cpu_pick(const struct scheduler *ops, const struct sched_unit *unit) { - return unit->vcpu_list->processor; + return unit->res->master_cpu; } static void * @@ -363,6 +364,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int processor) if ( (unit = sched_alloc_unit(v)) == NULL ) return 1; + unit->res = get_sched_res(processor); /* Initialise the per-vcpu timers. */ spin_lock_init(&v->periodic_timer_lock); init_timer(&v->periodic_timer, vcpu_periodic_timer_fn, @@ -478,6 +480,7 @@ int sched_move_domain(struct domain *d, struct cpupool *c) sched_set_affinity(v, &cpumask_all, &cpumask_all); v->processor = new_p; + v->sched_unit->res = get_sched_res(new_p); /* * With v->processor modified we must not * - make any further changes assuming we hold the scheduler lock, @@ -830,12 +833,14 @@ void restore_vcpu_affinity(struct domain *d) } v->processor = cpumask_any(cpumask_scratch_cpu(cpu)); + v->sched_unit->res = get_sched_res(v->processor); spin_unlock_irq(lock); /* v->processor might have changed, so reacquire the lock. */ lock = vcpu_schedule_lock_irq(v); v->processor = sched_pick_cpu(vcpu_scheduler(v), v->sched_unit); + v->sched_unit->res = get_sched_res(v->processor); spin_unlock_irq(lock); if ( old_cpu != v->processor ) @@ -1709,6 +1714,13 @@ static void poll_timer_fn(void *data) static int cpu_schedule_up(unsigned int cpu) { struct schedule_data *sd = &per_cpu(schedule_data, cpu); + struct sched_resource *res; + + res = xzalloc(struct sched_resource); + if ( res == NULL ) + return -ENOMEM; + res->master_cpu = cpu; + set_sched_res(cpu, res); per_cpu(scheduler, cpu) = &sched_idle_ops; spin_lock_init(&sd->_lock); @@ -1722,6 +1734,8 @@ static int cpu_schedule_up(unsigned int cpu) if ( idle_vcpu[cpu] == NULL ) vcpu_create(idle_vcpu[0]->domain, cpu, cpu); + else + idle_vcpu[cpu]->sched_unit->res = res; if ( idle_vcpu[cpu] == NULL ) return -ENOMEM; @@ -1744,6 +1758,9 @@ static void cpu_schedule_down(unsigned int cpu) struct schedule_data *sd = &per_cpu(schedule_data, cpu); kill_timer(&sd->s_timer); + + set_sched_res(cpu, NULL); + xfree(sd); } void sched_rm_cpu(unsigned int cpu) diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 0af89fbd02..b9e2920c66 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -44,9 +44,24 @@ struct schedule_data { #define curr_on_cpu(c) (per_cpu(schedule_data, c).curr) +struct sched_resource { + unsigned int master_cpu; /* Cpu with lowest id in scheduling resource. */ +}; + DECLARE_PER_CPU(struct schedule_data, schedule_data); DECLARE_PER_CPU(struct scheduler *, scheduler); DECLARE_PER_CPU(struct cpupool *, cpupool); +DECLARE_PER_CPU(struct sched_resource *, sched_res); + +static inline struct sched_resource *get_sched_res(unsigned int cpu) +{ + return per_cpu(sched_res, cpu); +} + +static inline void set_sched_res(unsigned int cpu, struct sched_resource *res) +{ + per_cpu(sched_res, cpu) = res; +} /* * Scratch space, for avoiding having too many cpumask_t on the stack. @@ -334,7 +349,10 @@ static inline void sched_migrate(const struct scheduler *s, if ( s->migrate ) s->migrate(s, unit, cpu); else + { unit->vcpu_list->processor = cpu; + unit->res = get_sched_res(cpu); + } } static inline int sched_pick_cpu(const struct scheduler *s, diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 89038337b4..999e43e8cc 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -278,6 +278,7 @@ struct sched_unit { struct vcpu *vcpu_list; void *priv; /* scheduler private data */ struct sched_unit *next_in_list; + struct sched_resource *res; unsigned int unit_id; };