From patchwork Fri Aug 9 14:57:48 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: 11086693 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 300BE746 for ; Fri, 9 Aug 2019 15:00:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B7B01FFBD for ; Fri, 9 Aug 2019 15:00:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 100B11FFB2; Fri, 9 Aug 2019 15:00:44 +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 86B801FFB2 for ; Fri, 9 Aug 2019 15:00:43 +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-0006PD-0H; 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-0006On-DE for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:42 +0000 X-Inumbo-ID: 2b349d10-bab6-11e9-9a69-b7b669d62bac Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2b349d10-bab6-11e9-9a69-b7b669d62bac; Fri, 09 Aug 2019 14:58:38 +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 0532EAFCE; 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:48 +0200 Message-Id: <20190809145833.1020-4-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 03/48] xen/sched: build a linked list of struct sched_unit 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 In order to make it easy to iterate over sched_unit elements of a domain, build a single linked list and add an iterator for it. The new list is guarded by the same mechanisms as the vcpu linked list as it is modified only via vcpu_create() or vcpu_destroy(). For completeness add another iterator for_each_sched_unit_vcpu() which will iterate over all vcpus of a sched_unit (right now only one). This will be needed later for larger scheduling granularity (e.g. cores). Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- V2: - add comment (Dario Faggioli) --- xen/common/schedule.c | 60 +++++++++++++++++++++++++++++++++++++++++-------- xen/include/xen/sched.h | 14 ++++++++++++ 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 038ebf5ae9..6da237110e 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -305,20 +305,64 @@ static void sched_spin_unlock_double(spinlock_t *lock1, spinlock_t *lock2, spin_unlock_irqrestore(lock1, flags); } -int sched_init_vcpu(struct vcpu *v, unsigned int processor) +static void sched_free_unit(struct sched_unit *unit) { - struct domain *d = v->domain; - struct sched_unit *unit; + struct sched_unit *prev_unit; + struct domain *d = unit->domain; - v->processor = processor; + if ( d->sched_unit_list == unit ) + d->sched_unit_list = unit->next_in_list; + else + { + for_each_sched_unit ( d, prev_unit ) + { + if ( prev_unit->next_in_list == unit ) + { + prev_unit->next_in_list = unit->next_in_list; + break; + } + } + } + + unit->vcpu_list->sched_unit = NULL; + xfree(unit); +} + +static struct sched_unit *sched_alloc_unit(struct vcpu *v) +{ + struct sched_unit *unit, **prev_unit; + struct domain *d = v->domain; if ( (unit = xzalloc(struct sched_unit)) == NULL ) - return 1; + return NULL; + v->sched_unit = unit; unit->vcpu_list = v; unit->unit_id = v->vcpu_id; unit->domain = d; + for ( prev_unit = &d->sched_unit_list; *prev_unit; + prev_unit = &(*prev_unit)->next_in_list ) + if ( (*prev_unit)->next_in_list && + (*prev_unit)->next_in_list->unit_id > unit->unit_id ) + break; + + unit->next_in_list = *prev_unit; + *prev_unit = unit; + + return unit; +} + +int sched_init_vcpu(struct vcpu *v, unsigned int processor) +{ + struct domain *d = v->domain; + struct sched_unit *unit; + + v->processor = processor; + + if ( (unit = sched_alloc_unit(v)) == NULL ) + return 1; + /* Initialise the per-vcpu timers. */ init_timer(&v->periodic_timer, vcpu_periodic_timer_fn, v, v->processor); @@ -330,8 +374,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int processor) unit->priv = sched_alloc_vdata(dom_scheduler(d), unit, d->sched_priv); if ( unit->priv == NULL ) { - v->sched_unit = NULL; - xfree(unit); + sched_free_unit(unit); return 1; } @@ -474,8 +517,7 @@ void sched_destroy_vcpu(struct vcpu *v) atomic_dec(&per_cpu(schedule_data, v->processor).urgent_count); sched_remove_unit(vcpu_scheduler(v), unit); sched_free_vdata(vcpu_scheduler(v), unit->priv); - xfree(unit); - v->sched_unit = NULL; + sched_free_unit(unit); } int sched_init_domain(struct domain *d, int poolid) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index a389ba5e1a..d7d9e153f9 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -277,9 +277,22 @@ struct sched_unit { struct domain *domain; struct vcpu *vcpu_list; void *priv; /* scheduler private data */ + struct sched_unit *next_in_list; int unit_id; }; +#define for_each_sched_unit(d, e) \ + for ( (e) = (d)->sched_unit_list; (e) != NULL; (e) = (e)->next_in_list ) + +/* + * All vcpus of a domain are in a single linked list with unit->vcpu_list + * pointing to the first vcpu of the unit. The loop must be terminated when + * a vcpu is hit not being part of the unit to loop over. + */ +#define for_each_sched_unit_vcpu(i, v) \ + for ( (v) = (i)->vcpu_list; (v) != NULL && (v)->sched_unit == (i); \ + (v) = (v)->next_in_list ) + /* Per-domain lock can be recursively acquired in fault handlers. */ #define domain_lock(d) spin_lock_recursive(&(d)->domain_lock) #define domain_unlock(d) spin_unlock_recursive(&(d)->domain_lock) @@ -333,6 +346,7 @@ struct domain /* Scheduling. */ void *sched_priv; /* scheduler-specific data */ + struct sched_unit *sched_unit_list; struct cpupool *cpupool; struct domain *next_in_list;