From patchwork Fri Aug 9 14:57:49 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: 11086631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 450E31709 for ; Fri, 9 Aug 2019 15:00:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 328C61FFB1 for ; Fri, 9 Aug 2019 15:00:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23F211FFBD; Fri, 9 Aug 2019 15:00:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2D7451FFB1 for ; Fri, 9 Aug 2019 15:00:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6Ls-0006PO-B5; Fri, 09 Aug 2019 14:58:44 +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 1hw6Lq-0006Ox-K5 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:42 +0000 X-Inumbo-ID: 2b7ba0a2-bab6-11e9-a3c6-97e7b842ae24 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2b7ba0a2-bab6-11e9-a3c6-97e7b842ae24; Fri, 09 Aug 2019 14:58:39 +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 75803AFF3; Fri, 9 Aug 2019 14:58:38 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:49 +0200 Message-Id: <20190809145833.1020-5-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190809145833.1020-1-jgross@suse.com> References: <20190809145833.1020-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v2 04/48] 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" X-Virus-Scanned: ClamAV using ClamSMTP 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) --- 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 | 3 +++ 7 files changed, 53 insertions(+), 1 deletion(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index e835a4930a..c3446551cc 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 a2403e4198..f7e5f07c7f 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 bdba237982..27c859b684 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); @@ -748,6 +750,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 0f97c0f2a5..7e622101a4 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 6da237110e..f5427cf29b 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, struct sched_unit *unit) { - return unit->vcpu_list->processor; + return unit->res->processor; } 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. */ init_timer(&v->periodic_timer, vcpu_periodic_timer_fn, v, v->processor); @@ -477,6 +479,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, @@ -847,12 +850,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 ) @@ -1702,6 +1707,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->processor = cpu; + set_sched_res(cpu, res); per_cpu(scheduler, cpu) = &sched_idle_ops; spin_lock_init(&sd->_lock); @@ -1715,6 +1727,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; @@ -1737,6 +1751,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 9fd367377a..f30dc4cdf1 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 processor; +}; + 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 d7d9e153f9..2ab1b13c63 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -273,11 +273,14 @@ struct vcpu struct arch_vcpu arch; }; +struct sched_resource; + struct sched_unit { struct domain *domain; struct vcpu *vcpu_list; void *priv; /* scheduler private data */ struct sched_unit *next_in_list; + struct sched_resource *res; int unit_id; };