From nobody Tue Nov 11 08:45:25 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1569567742; cv=none; d=zoho.com; s=zohoarc; b=c+wBrZfiip/UmjGrnGi/1yPfZJIi63YYF30ifuhHVibs2dryNjn4xcbuzY64GPCMkway3PRaI1ZA18mj3J1NLxS9y9GhA2SVlvT0W7nYDSSCwScY16PNfOUJ47O7sp2mGF6Gw9Ydz8JWOhlxfOMzva7h5LkmJtts5cxB5/3V+fc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569567742; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=SXkecWe8F3Tu0X9LjfStRqDFLVWjwDLAm8xnxNjnmYo=; b=SRDxh8QtymtF8lmKZiBS7JWK/yvC/ywxnIC6GDt3HiuEPlQxw1bOKODHuOB/Zj8fozjd8Lwdq6pCEJ8SEBTU1wxAmAmb204S0qe7KF8S5lr24i0zrUQCon6+3+xaZuks3tuXp8T4DQgPZjKCREZ4ZAd96wUx03DCW/3ejy0N+Hk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1569567742364443.0380039021784; Fri, 27 Sep 2019 00:02:22 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDkFP-00033P-Fi; Fri, 27 Sep 2019 07:00:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDkFN-00033J-Tz for xen-devel@lists.xenproject.org; Fri, 27 Sep 2019 07:00:57 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by localhost (Halon) with ESMTPS id 8d43251c-e0f4-11e9-bf31-bc764e2007e4; Fri, 27 Sep 2019 07:00:56 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 48B66ACEF; Fri, 27 Sep 2019 07:00:55 +0000 (UTC) X-Inumbo-ID: 8d43251c-e0f4-11e9-bf31-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 27 Sep 2019 09:00:07 +0200 Message-Id: <20190927070050.12405-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190927070050.12405-1-jgross@suse.com> References: <20190927070050.12405-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v4 03/46] 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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) V4: - rename iterator macro parameters (Jan Beulich) - modify for_each_sched_unit_vcpu() end condition (Jan Beulich) --- xen/common/schedule.c | 61 +++++++++++++++++++++++++++++++++++++++++----= ---- xen/include/xen/sched.h | 16 +++++++++++++ 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 6be30c9161..d34b789a8f 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -305,6 +305,55 @@ static void sched_spin_unlock_double(spinlock_t *lock1= , spinlock_t *lock2, spin_unlock_irqrestore(lock1, flags); } =20 +static void sched_free_unit(struct sched_unit *unit) +{ + struct sched_unit *prev_unit; + struct domain *d =3D unit->domain; + + if ( d->sched_unit_list =3D=3D unit ) + d->sched_unit_list =3D unit->next_in_list; + else + { + for_each_sched_unit ( d, prev_unit ) + { + if ( prev_unit->next_in_list =3D=3D unit ) + { + prev_unit->next_in_list =3D unit->next_in_list; + break; + } + } + } + + unit->vcpu_list->sched_unit =3D NULL; + xfree(unit); +} + +static struct sched_unit *sched_alloc_unit(struct vcpu *v) +{ + struct sched_unit *unit, **prev_unit; + struct domain *d =3D v->domain; + + if ( (unit =3D xzalloc(struct sched_unit)) =3D=3D NULL ) + return NULL; + + unit->vcpu_list =3D v; + unit->unit_id =3D v->vcpu_id; + unit->domain =3D d; + + for ( prev_unit =3D &d->sched_unit_list; *prev_unit; + prev_unit =3D &(*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 =3D *prev_unit; + *prev_unit =3D unit; + + v->sched_unit =3D unit; + + return unit; +} + int sched_init_vcpu(struct vcpu *v, unsigned int processor) { struct domain *d =3D v->domain; @@ -312,11 +361,8 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proce= ssor) =20 v->processor =3D processor; =20 - if ( (unit =3D xzalloc(struct sched_unit)) =3D=3D NULL ) + if ( (unit =3D sched_alloc_unit(v)) =3D=3D NULL ) return 1; - unit->vcpu_list =3D v; - unit->unit_id =3D v->vcpu_id; - unit->domain =3D d; =20 /* Initialise the per-vcpu timers. */ spin_lock_init(&v->periodic_timer_lock); @@ -330,12 +376,10 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proc= essor) unit->priv =3D sched_alloc_udata(dom_scheduler(d), unit, d->sched_priv= ); if ( unit->priv =3D=3D NULL ) { - xfree(unit); + sched_free_unit(unit); return 1; } =20 - v->sched_unit =3D unit; - /* * Initialize affinity settings. The idler, and potentially * domain-0 VCPUs, are pinned onto their respective physical CPUs. @@ -475,8 +519,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_udata(vcpu_scheduler(v), unit->priv); - v->sched_unit =3D NULL; - xfree(unit); + sched_free_unit(unit); } =20 int sched_init_domain(struct domain *d, int poolid) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index fb45da05ee..36b1c3b010 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -277,9 +277,24 @@ struct sched_unit { struct domain *domain; struct vcpu *vcpu_list; void *priv; /* scheduler private data */ + struct sched_unit *next_in_list; unsigned int unit_id; }; =20 +#define for_each_sched_unit(d, u) \ + for ( (u) =3D (d)->sched_unit_list; (u) !=3D NULL; (u) =3D (u)->next_i= n_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(u, v) \ + for ( (v) =3D (u)->vcpu_list; = \ + (v) !=3D NULL && (!(u)->next_in_list || = \ + (v)->vcpu_id < (u)->next_in_list->unit_id); \ + (v) =3D (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 +348,7 @@ struct domain =20 /* Scheduling. */ void *sched_priv; /* scheduler-specific data */ + struct sched_unit *sched_unit_list; struct cpupool *cpupool; =20 struct domain *next_in_list; --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel