From nobody Mon Feb 9 12:26:15 2026 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=1557125920; cv=none; d=zoho.com; s=zohoarc; b=GDeBaC/VGjHjdizpu/pQuxnRvUufTvrsk05aGlWl9dQOu1bGQFzYcQQ+94rliKz5idPAFP2cOLr0CPWKuWlg3iStqGk3VFeynfdYRkqUnjRAg+UhjbNjvX/OD1BCS4cjl/uh5bdMAX7d/ihkQoqe+fNTQ1dACXEQxN2aVGDl5fs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557125920; 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=6joTyp+lyOPf4OvAi1VSKtGtikE3JaWc6+LjqFdMT98=; b=Icb0SQW16BnWwPp1CXQc8d6v6SUNw2fepwDowffhzWl8xNeM6MA0erZlVrcAfH4PhMmmia0bW6rUsXgX31CRaH/KVISPVbsKQx55Vn2YJCYLWz3e8M+Hb67I03wjO2vr+fwKt52H3zASuw4dhGzTsaTcmdRG8l6v0SMGaFBtPR8= 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 1557125920871304.049832728797; Sun, 5 May 2019 23:58:40 -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 1hNXYd-0001ze-JY; Mon, 06 May 2019 06:57:03 +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 1hNXYb-0001wr-O1 for xen-devel@lists.xenproject.org; Mon, 06 May 2019 06:57:01 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2044310c-6fcc-11e9-a0a7-1be20a8da492; Mon, 06 May 2019 06:56:52 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AB92FAE3F; Mon, 6 May 2019 06:56:49 +0000 (UTC) X-Inumbo-ID: 2044310c-6fcc-11e9-a0a7-1be20a8da492 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Mon, 6 May 2019 08:56:04 +0200 Message-Id: <20190506065644.7415-6-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190506065644.7415-1-jgross@suse.com> References: <20190506065644.7415-1-jgross@suse.com> Subject: [Xen-devel] [PATCH RFC V2 05/45] xen/sched: build a linked list of struct sched_item 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_item 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_item_vcpu() which will iterate over all vcpus if a sched_item (right now only one). This will be needed later for larger scheduling granularity (e.g. cores). Signed-off-by: Juergen Gross --- xen/common/schedule.c | 56 ++++++++++++++++++++++++++++++++++++++++++---= ---- xen/include/xen/sched.h | 9 ++++++++ 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 795d56a793..2d719a6acc 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -249,6 +249,52 @@ static void sched_spin_unlock_double(spinlock_t *lock1= , spinlock_t *lock2, spin_unlock_irqrestore(lock1, flags); } =20 +static void sched_free_item(struct sched_item *item) +{ + struct sched_item *prev_item; + struct domain *d =3D item->vcpu->domain; + + if ( d->sched_item_list =3D=3D item ) + d->sched_item_list =3D item->next_in_list; + else + { + for_each_sched_item(d, prev_item) + { + if ( prev_item->next_in_list =3D=3D item ) + { + prev_item->next_in_list =3D item->next_in_list; + break; + } + } + } + + item->vcpu->sched_item =3D NULL; + xfree(item); +} + +static struct sched_item *sched_alloc_item(struct vcpu *v) +{ + struct sched_item *item, **prev_item; + struct domain *d =3D v->domain; + + if ( (item =3D xzalloc(struct sched_item)) =3D=3D NULL ) + return NULL; + + v->sched_item =3D item; + item->vcpu =3D v; + + for ( prev_item =3D &d->sched_item_list; *prev_item; + prev_item =3D &(*prev_item)->next_in_list ) + if ( (*prev_item)->next_in_list && + (*prev_item)->next_in_list->vcpu->vcpu_id > v->vcpu_id ) + break; + + item->next_in_list =3D *prev_item; + *prev_item =3D item; + + return item; +} + int sched_init_vcpu(struct vcpu *v, unsigned int processor) { struct domain *d =3D v->domain; @@ -256,10 +302,8 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proce= ssor) =20 v->processor =3D processor; =20 - if ( (item =3D xzalloc(struct sched_item)) =3D=3D NULL ) + if ( (item =3D sched_alloc_item(v)) =3D=3D NULL ) return 1; - v->sched_item =3D item; - item->vcpu =3D v; =20 /* Initialise the per-vcpu timers. */ init_timer(&v->periodic_timer, vcpu_periodic_timer_fn, @@ -272,8 +316,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proces= sor) item->priv =3D sched_alloc_vdata(dom_scheduler(d), item, d->sched_priv= ); if ( item->priv =3D=3D NULL ) { - v->sched_item =3D NULL; - xfree(item); + sched_free_item(item); return 1; } =20 @@ -416,8 +459,7 @@ void sched_destroy_vcpu(struct vcpu *v) atomic_dec(&per_cpu(schedule_data, v->processor).urgent_count); sched_remove_item(vcpu_scheduler(v), item); sched_free_vdata(vcpu_scheduler(v), item->priv); - xfree(item); - v->sched_item =3D NULL; + sched_free_item(item); } =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 45857b4d35..bd6489a33d 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -279,8 +279,16 @@ struct vcpu struct sched_item { struct vcpu *vcpu; void *priv; /* scheduler private data */ + struct sched_item *next_in_list; }; =20 +#define for_each_sched_item(d, e) \ + for ( (e) =3D (d)->sched_item_list; (e) !=3D NULL; (e) =3D (e)->next_i= n_list ) + +#define for_each_sched_item_vcpu(i, v) \ + for ( (v) =3D (i)->vcpu; (v) !=3D NULL && (v)->sched_item =3D=3D (i); = \ + (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) @@ -339,6 +347,7 @@ struct domain =20 /* Scheduling. */ void *sched_priv; /* scheduler-specific data */ + struct sched_item *sched_item_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