From patchwork Fri Mar 29 15:09:03 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: 10877251 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 D766D1575 for ; Fri, 29 Mar 2019 15:11:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFC052984A for ; Fri, 29 Mar 2019 15:11:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC29C29870; Fri, 29 Mar 2019 15:11:31 +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 3DEAB29877 for ; Fri, 29 Mar 2019 15:11:31 +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 1h9t8p-0003vj-Ap; Fri, 29 Mar 2019 15:09:59 +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 1h9t8g-0003eF-FA for xen-devel@lists.xenproject.org; Fri, 29 Mar 2019 15:09:50 +0000 X-Inumbo-ID: b023ab6e-5234-11e9-b84e-c32dbddba8f1 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b023ab6e-5234-11e9-b84e-c32dbddba8f1; Fri, 29 Mar 2019 15:09:46 +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 88488AFEF; Fri, 29 Mar 2019 15:09:45 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 29 Mar 2019 16:09:03 +0100 Message-Id: <20190329150934.17694-19-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190329150934.17694-1-jgross@suse.com> References: <20190329150934.17694-1-jgross@suse.com> Subject: [Xen-devel] [PATCH RFC 18/49] xen/sched: add scheduler helpers hiding vcpu 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 , Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add the following helpers using a sched_item as input instead of a vcpu: - is_idle_item() similar to is_idle_vcpu() - item_runnable() like vcpu_runnable() - sched_set_res() to set the current processor of an item - sched_item_cpu() to get the current processor of an item - sched_{set|clear}_pause_flags[_atomic]() to modify pause_flags of the associated vcpu(s) - sched_idle_item() to get the sched_item pointer of the idle vcpu of a specific physical cpu Signed-off-by: Juergen Gross --- xen/common/sched_credit.c | 3 +-- xen/common/schedule.c | 24 +++++++++------------- xen/include/xen/sched-if.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 9e7c849b94..8cfe54ec36 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1673,8 +1673,7 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, int balance_step) SCHED_STAT_CRANK(migrate_queued); WARN_ON(vc->is_urgent); runq_remove(speer); - vc->processor = cpu; - vc->sched_item->res = per_cpu(sched_res, cpu); + sched_set_res(vc->sched_item, per_cpu(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/schedule.c b/xen/common/schedule.c index be85fb8000..99660cee67 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -321,12 +321,11 @@ int sched_init_vcpu(struct vcpu *v, unsigned int processor) struct domain *d = v->domain; struct sched_item *item; - v->processor = processor; - if ( (item = sched_alloc_item(v)) == NULL ) return 1; - item->res = per_cpu(sched_res, processor); + sched_set_res(item, per_cpu(sched_res, processor)); + /* Initialise the per-vcpu timers. */ init_timer(&v->periodic_timer, vcpu_periodic_timer_fn, v, v->processor); @@ -440,8 +439,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_item->res = per_cpu(sched_res, new_p); + sched_set_res(v->sched_item, per_cpu(sched_res, new_p)); /* * With v->processor modified we must not * - make any further changes assuming we hold the scheduler lock, @@ -632,10 +630,7 @@ static void vcpu_move_locked(struct vcpu *v, unsigned int new_cpu) if ( vcpu_scheduler(v)->migrate ) SCHED_OP(vcpu_scheduler(v), migrate, v->sched_item, new_cpu); else - { - v->processor = new_cpu; - v->sched_item->res = per_cpu(sched_res, new_cpu); - } + sched_set_res(v->sched_item, per_cpu(sched_res, new_cpu)); } /* @@ -785,8 +780,9 @@ void restore_vcpu_affinity(struct domain *d) spinlock_t *lock; unsigned int old_cpu = v->processor; struct sched_item *item = v->sched_item; + struct sched_resource *res; - ASSERT(!vcpu_runnable(v)); + ASSERT(!item_runnable(item)); /* * Re-assign the initial processor as after resume we have no @@ -817,12 +813,12 @@ void restore_vcpu_affinity(struct domain *d) } } - v->processor = cpumask_any(cpumask_scratch_cpu(cpu)); - item->res = per_cpu(sched_res, v->processor); + res = per_cpu(sched_res, cpumask_any(cpumask_scratch_cpu(cpu))); + sched_set_res(item, res); lock = item_schedule_lock_irq(item); - item->res = SCHED_OP(vcpu_scheduler(v), pick_resource, item); - v->processor = item->res->processor; + res = SCHED_OP(vcpu_scheduler(v), pick_resource, item); + sched_set_res(item, res); spin_unlock_irq(lock); if ( old_cpu != v->processor ) diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 577015b868..b5cbbbbcb1 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -79,6 +79,57 @@ struct sched_item { for ( (v) = (i)->vcpu; (v) != NULL && (v)->sched_item == (i); \ (v) = (v)->next_in_list ) +static inline bool is_idle_item(const struct sched_item *item) +{ + return is_idle_vcpu(item->vcpu); +} + +static inline bool item_runnable(const struct sched_item *item) +{ + return vcpu_runnable(item->vcpu); +} + +static inline void sched_set_res(struct sched_item *item, + struct sched_resource *res) +{ + item->vcpu->processor = res->processor; + item->res = res; +} + +static inline unsigned int sched_item_cpu(struct sched_item *item) +{ + return item->res->processor; +} + +static inline void sched_set_pause_flags(struct sched_item *item, + unsigned int bit) +{ + __set_bit(bit, &item->vcpu->pause_flags); +} + +static inline void sched_clear_pause_flags(struct sched_item *item, + unsigned int bit) +{ + __clear_bit(bit, &item->vcpu->pause_flags); +} + +static inline void sched_set_pause_flags_atomic(struct sched_item *item, + unsigned int bit) +{ + set_bit(bit, &item->vcpu->pause_flags); +} + +static inline void sched_clear_pause_flags_atomic(struct sched_item *item, + unsigned int bit) +{ + clear_bit(bit, &item->vcpu->pause_flags); +} + +static inline struct sched_item *sched_idle_item(unsigned int cpu) +{ + return idle_vcpu[cpu]->sched_item; +} + /* * Scratch space, for avoiding having too many cpumask_t on the stack. * Within each scheduler, when using the scratch mask of one pCPU: