From nobody Tue Apr 23 21:45:40 2024 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=1565362801; cv=none; d=zoho.com; s=zohoarc; b=ewehA7Kd2OXwJSk5RPPYOzVPCJcZFyCP68iMLFSBz2FmEApKS3czzpeWn855jW2lKtZLZo9IXBV99US2leaGwNRIdy1fBzTyY7ZNiexlc7YU52y0SJAp9LbKNrIMY2j4vuNer6lXg+pdbRbU/6G72LayU+To+NKF5OOUv/neSUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362801; 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=0ce0XxFpsI2Ne+MAhHJrY8kr5JmxnFqYrL/UlKs/Bdc=; b=nMo6Nk8oRo3aUsnURklxPjbzLhjR1r03CisEYLlak4qYYEluLw8bDrNOBINFhKz69TVwz0KMeSaoZeRZSITWB0YxI8jD1+1e93IznW4ic1ctcCfo9KTCz0oRCDlYbKJKn0rRHRPY5rPMj7WgWtJPx0Q5tk7+0lEYKmApg4Ai/+A= 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 1565362801929330.636702110805; Fri, 9 Aug 2019 08:00:01 -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 1hw6Ls-0006Po-R2; 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 1hw6Ls-0006PG-4S for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:44 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2ad9afae-bab6-11e9-a483-0734b6965e9a; Fri, 09 Aug 2019 14:58:38 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1DBFFAF38; Fri, 9 Aug 2019 14:58:37 +0000 (UTC) X-Inumbo-ID: 2ad9afae-bab6-11e9-a483-0734b6965e9a X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:46 +0200 Message-Id: <20190809145833.1020-2-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 01/48] xen/sched: use new sched_unit instead of vcpu in scheduler interfaces 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 , Robert VanVossen , Dario Faggioli , Julien Grall , Josh Whitehead , Meng Xu , 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 prepare core- and socket-scheduling use a new struct sched_unit instead of struct vcpu for interfaces of the different schedulers. Rename the per-scheduler functions insert_vcpu and remove_vcpu to insert_unit and remove_unit to reflect the change of the parameter. In the schedulers rename local functions switched to sched_unit, too. For now this new struct will contain a domain, a vcpu pointer and a unit_id only and is allocated at vcpu creation time. Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- RFC V2: - move definition of struct sched_unit to sched.h (Andrew Cooper) V1: - rename "item" to "unit" (George Dunlap) V2: - rename unit->vcpu to unit->vcpu_list (Jan Beulich) - merge patch with next one in series (Dario Faggioli) - merge patch introducing domain pointer in sched_unit into this one (Jan Beulich) - merge patch introducing unit_id into this one --- xen/common/sched_arinc653.c | 30 +++++++++------ xen/common/sched_credit.c | 41 ++++++++++++-------- xen/common/sched_credit2.c | 57 ++++++++++++++++------------ xen/common/sched_null.c | 37 +++++++++++------- xen/common/sched_rt.c | 33 +++++++++------- xen/common/schedule.c | 54 +++++++++++++++++--------- xen/include/xen/sched-if.h | 92 ++++++++++++++++++++++++++---------------= ---- xen/include/xen/sched.h | 8 ++++ 8 files changed, 219 insertions(+), 133 deletions(-) diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c index 72b988ea5f..2059314791 100644 --- a/xen/common/sched_arinc653.c +++ b/xen/common/sched_arinc653.c @@ -376,13 +376,16 @@ a653sched_deinit(struct scheduler *ops) * This function allocates scheduler-specific data for a VCPU * * @param ops Pointer to this instance of the scheduler structure + * @param unit Pointer to struct sched_unit * * @return Pointer to the allocated data */ static void * -a653sched_alloc_vdata(const struct scheduler *ops, struct vcpu *vc, void *= dd) +a653sched_alloc_vdata(const struct scheduler *ops, struct sched_unit *unit, + void *dd) { a653sched_priv_t *sched_priv =3D SCHED_PRIV(ops); + struct vcpu *vc =3D unit->vcpu_list; arinc653_vcpu_t *svc; unsigned int entry; unsigned long flags; @@ -458,11 +461,13 @@ a653sched_free_vdata(const struct scheduler *ops, voi= d *priv) * Xen scheduler callback function to sleep a VCPU * * @param ops Pointer to this instance of the scheduler structure - * @param vc Pointer to the VCPU structure for the current domain + * @param unit Pointer to struct sched_unit */ static void -a653sched_vcpu_sleep(const struct scheduler *ops, struct vcpu *vc) +a653sched_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; + if ( AVCPU(vc) !=3D NULL ) AVCPU(vc)->awake =3D 0; =20 @@ -478,11 +483,13 @@ a653sched_vcpu_sleep(const struct scheduler *ops, str= uct vcpu *vc) * Xen scheduler callback function to wake up a VCPU * * @param ops Pointer to this instance of the scheduler structure - * @param vc Pointer to the VCPU structure for the current domain + * @param unit Pointer to struct sched_unit */ static void -a653sched_vcpu_wake(const struct scheduler *ops, struct vcpu *vc) +a653sched_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; + if ( AVCPU(vc) !=3D NULL ) AVCPU(vc)->awake =3D 1; =20 @@ -597,13 +604,14 @@ a653sched_do_schedule( * Xen scheduler callback function to select a CPU for the VCPU to run on * * @param ops Pointer to this instance of the scheduler structure - * @param v Pointer to the VCPU structure for the current domain + * @param unit Pointer to struct sched_unit * * @return Number of selected physical CPU */ static int -a653sched_pick_cpu(const struct scheduler *ops, struct vcpu *vc) +a653sched_pick_cpu(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; cpumask_t *online; unsigned int cpu; =20 @@ -702,11 +710,11 @@ static const struct scheduler sched_arinc653_def =3D { .free_vdata =3D a653sched_free_vdata, .alloc_vdata =3D a653sched_alloc_vdata, =20 - .insert_vcpu =3D NULL, - .remove_vcpu =3D NULL, + .insert_unit =3D NULL, + .remove_unit =3D NULL, =20 - .sleep =3D a653sched_vcpu_sleep, - .wake =3D a653sched_vcpu_wake, + .sleep =3D a653sched_unit_sleep, + .wake =3D a653sched_unit_wake, .yield =3D NULL, .context_saved =3D NULL, =20 diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 70fe718127..464194a578 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -854,15 +854,16 @@ _csched_cpu_pick(const struct scheduler *ops, struct = vcpu *vc, bool_t commit) } =20 static int -csched_cpu_pick(const struct scheduler *ops, struct vcpu *vc) +csched_cpu_pick(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct csched_vcpu *svc =3D CSCHED_VCPU(vc); =20 /* * We have been called by vcpu_migrate() (in schedule.c), as part * of the process of seeing if vc can be migrated to another pcpu. * We make a note about this in svc->flags so that later, in - * csched_vcpu_wake() (still called from vcpu_migrate()) we won't + * csched_unit_wake() (still called from vcpu_migrate()) we won't * get boosted, which we don't deserve as we are "only" migrating. */ set_bit(CSCHED_FLAG_VCPU_MIGRATING, &svc->flags); @@ -990,8 +991,10 @@ csched_vcpu_acct(struct csched_private *prv, unsigned = int cpu) } =20 static void * -csched_alloc_vdata(const struct scheduler *ops, struct vcpu *vc, void *dd) +csched_alloc_vdata(const struct scheduler *ops, struct sched_unit *unit, + void *dd) { + struct vcpu *vc =3D unit->vcpu_list; struct csched_vcpu *svc; =20 /* Allocate per-VCPU info */ @@ -1011,8 +1014,9 @@ csched_alloc_vdata(const struct scheduler *ops, struc= t vcpu *vc, void *dd) } =20 static void -csched_vcpu_insert(const struct scheduler *ops, struct vcpu *vc) +csched_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct csched_vcpu *svc =3D vc->sched_priv; spinlock_t *lock; =20 @@ -1021,7 +1025,7 @@ csched_vcpu_insert(const struct scheduler *ops, struc= t vcpu *vc) /* csched_cpu_pick() looks in vc->processor's runq, so we need the loc= k. */ lock =3D vcpu_schedule_lock_irq(vc); =20 - vc->processor =3D csched_cpu_pick(ops, vc); + vc->processor =3D csched_cpu_pick(ops, unit); =20 spin_unlock_irq(lock); =20 @@ -1046,9 +1050,10 @@ csched_free_vdata(const struct scheduler *ops, void = *priv) } =20 static void -csched_vcpu_remove(const struct scheduler *ops, struct vcpu *vc) +csched_unit_remove(const struct scheduler *ops, struct sched_unit *unit) { struct csched_private *prv =3D CSCHED_PRIV(ops); + struct vcpu *vc =3D unit->vcpu_list; struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); struct csched_dom * const sdom =3D svc->sdom; =20 @@ -1073,8 +1078,9 @@ csched_vcpu_remove(const struct scheduler *ops, struc= t vcpu *vc) } =20 static void -csched_vcpu_sleep(const struct scheduler *ops, struct vcpu *vc) +csched_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); unsigned int cpu =3D vc->processor; =20 @@ -1097,8 +1103,9 @@ csched_vcpu_sleep(const struct scheduler *ops, struct= vcpu *vc) } =20 static void -csched_vcpu_wake(const struct scheduler *ops, struct vcpu *vc) +csched_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); bool_t migrating; =20 @@ -1158,8 +1165,9 @@ csched_vcpu_wake(const struct scheduler *ops, struct = vcpu *vc) } =20 static void -csched_vcpu_yield(const struct scheduler *ops, struct vcpu *vc) +csched_unit_yield(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); =20 /* Let the scheduler know that this vcpu is trying to yield */ @@ -1212,9 +1220,10 @@ csched_dom_cntl( } =20 static void -csched_aff_cntl(const struct scheduler *ops, struct vcpu *v, +csched_aff_cntl(const struct scheduler *ops, struct sched_unit *unit, const cpumask_t *hard, const cpumask_t *soft) { + struct vcpu *v =3D unit->vcpu_list; struct csched_vcpu *svc =3D CSCHED_VCPU(v); =20 if ( !hard ) @@ -1743,7 +1752,7 @@ csched_load_balance(struct csched_private *prv, int c= pu, * - if we race with inc_nr_runnable(), we skip a pCPU tha= t may * have runnable vCPUs in its runqueue, but that's not a * problem because: - * + if racing with csched_vcpu_insert() or csched_vcpu_= wake(), + * + if racing with csched_unit_insert() or csched_unit_= wake(), * __runq_tickle() will be called afterwords, so the v= CPU * won't get stuck in the runqueue for too long; * + if racing with csched_runq_steal(), it may be that a @@ -2256,12 +2265,12 @@ static const struct scheduler sched_credit_def =3D { =20 .global_init =3D csched_global_init, =20 - .insert_vcpu =3D csched_vcpu_insert, - .remove_vcpu =3D csched_vcpu_remove, + .insert_unit =3D csched_unit_insert, + .remove_unit =3D csched_unit_remove, =20 - .sleep =3D csched_vcpu_sleep, - .wake =3D csched_vcpu_wake, - .yield =3D csched_vcpu_yield, + .sleep =3D csched_unit_sleep, + .wake =3D csched_unit_wake, + .yield =3D csched_unit_yield, =20 .adjust =3D csched_dom_cntl, .adjust_affinity=3D csched_aff_cntl, diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 6b77da7476..2120da6f98 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -273,7 +273,7 @@ * CSFLAG_delayed_runq_add: Do we need to add this to the runqueue once it= 'd done * being context switched out? * + Set when scheduling out in csched2_schedule() if prev is runnable - * + Set in csched2_vcpu_wake if it finds CSFLAG_scheduled set + * + Set in csched2_unit_wake if it finds CSFLAG_scheduled set * + Read in csched2_context_saved(). If set, it adds prev to the runqueu= e and * clears the bit. */ @@ -624,14 +624,14 @@ static inline bool has_cap(const struct csched2_vcpu = *svc) * This logic is entirely implemented in runq_tickle(), and that is enough. * In fact, in this scheduler, placement of a vcpu on one of the pcpus of a * runq, _always_ happens by means of tickling: - * - when a vcpu wakes up, it calls csched2_vcpu_wake(), which calls + * - when a vcpu wakes up, it calls csched2_unit_wake(), which calls * runq_tickle(); * - when a migration is initiated in schedule.c, we call csched2_cpu_pic= k(), - * csched2_vcpu_migrate() (which calls migrate()) and csched2_vcpu_wake= (). + * csched2_unit_migrate() (which calls migrate()) and csched2_unit_wake= (). * csched2_cpu_pick() looks for the least loaded runq and return just a= ny - * of its processors. Then, csched2_vcpu_migrate() just moves the vcpu = to + * of its processors. Then, csched2_unit_migrate() just moves the vcpu = to * the chosen runq, and it is again runq_tickle(), called by - * csched2_vcpu_wake() that actually decides what pcpu to use within the + * csched2_unit_wake() that actually decides what pcpu to use within the * chosen runq; * - when a migration is initiated in sched_credit2.c, by calling migrat= e() * directly, that again temporarily use a random pcpu from the new runq, @@ -2027,8 +2027,10 @@ csched2_vcpu_check(struct vcpu *vc) #endif =20 static void * -csched2_alloc_vdata(const struct scheduler *ops, struct vcpu *vc, void *dd) +csched2_alloc_vdata(const struct scheduler *ops, struct sched_unit *unit, + void *dd) { + struct vcpu *vc =3D unit->vcpu_list; struct csched2_vcpu *svc; =20 /* Allocate per-VCPU info */ @@ -2070,8 +2072,9 @@ csched2_alloc_vdata(const struct scheduler *ops, stru= ct vcpu *vc, void *dd) } =20 static void -csched2_vcpu_sleep(const struct scheduler *ops, struct vcpu *vc) +csched2_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct csched2_vcpu * const svc =3D csched2_vcpu(vc); =20 ASSERT(!is_idle_vcpu(vc)); @@ -2092,8 +2095,9 @@ csched2_vcpu_sleep(const struct scheduler *ops, struc= t vcpu *vc) } =20 static void -csched2_vcpu_wake(const struct scheduler *ops, struct vcpu *vc) +csched2_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct csched2_vcpu * const svc =3D csched2_vcpu(vc); unsigned int cpu =3D vc->processor; s_time_t now; @@ -2147,16 +2151,18 @@ out: } =20 static void -csched2_vcpu_yield(const struct scheduler *ops, struct vcpu *v) +csched2_unit_yield(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *v =3D unit->vcpu_list; struct csched2_vcpu * const svc =3D csched2_vcpu(v); =20 __set_bit(__CSFLAG_vcpu_yield, &svc->flags); } =20 static void -csched2_context_saved(const struct scheduler *ops, struct vcpu *vc) +csched2_context_saved(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct csched2_vcpu * const svc =3D csched2_vcpu(vc); spinlock_t *lock =3D vcpu_schedule_lock_irq(vc); s_time_t now =3D NOW(); @@ -2197,9 +2203,10 @@ csched2_context_saved(const struct scheduler *ops, s= truct vcpu *vc) =20 #define MAX_LOAD (STIME_MAX) static int -csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) +csched2_cpu_pick(const struct scheduler *ops, struct sched_unit *unit) { struct csched2_private *prv =3D csched2_priv(ops); + struct vcpu *vc =3D unit->vcpu_list; int i, min_rqi =3D -1, min_s_rqi =3D -1; unsigned int new_cpu, cpu =3D vc->processor; struct csched2_vcpu *svc =3D csched2_vcpu(vc); @@ -2734,9 +2741,10 @@ retry: } =20 static void -csched2_vcpu_migrate( - const struct scheduler *ops, struct vcpu *vc, unsigned int new_cpu) +csched2_unit_migrate( + const struct scheduler *ops, struct sched_unit *unit, unsigned int new= _cpu) { + struct vcpu *vc =3D unit->vcpu_list; struct domain *d =3D vc->domain; struct csched2_vcpu * const svc =3D csched2_vcpu(vc); struct csched2_runqueue_data *trqd; @@ -2997,9 +3005,10 @@ csched2_dom_cntl( } =20 static void -csched2_aff_cntl(const struct scheduler *ops, struct vcpu *v, +csched2_aff_cntl(const struct scheduler *ops, struct sched_unit *unit, const cpumask_t *hard, const cpumask_t *soft) { + struct vcpu *v =3D unit->vcpu_list; struct csched2_vcpu *svc =3D csched2_vcpu(v); =20 if ( !hard ) @@ -3097,8 +3106,9 @@ csched2_free_domdata(const struct scheduler *ops, voi= d *data) } =20 static void -csched2_vcpu_insert(const struct scheduler *ops, struct vcpu *vc) +csched2_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct csched2_vcpu *svc =3D vc->sched_priv; struct csched2_dom * const sdom =3D svc->sdom; spinlock_t *lock; @@ -3109,7 +3119,7 @@ csched2_vcpu_insert(const struct scheduler *ops, stru= ct vcpu *vc) /* csched2_cpu_pick() expects the pcpu lock to be held */ lock =3D vcpu_schedule_lock_irq(vc); =20 - vc->processor =3D csched2_cpu_pick(ops, vc); + vc->processor =3D csched2_cpu_pick(ops, unit); =20 spin_unlock_irq(lock); =20 @@ -3136,8 +3146,9 @@ csched2_free_vdata(const struct scheduler *ops, void = *priv) } =20 static void -csched2_vcpu_remove(const struct scheduler *ops, struct vcpu *vc) +csched2_unit_remove(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct csched2_vcpu * const svc =3D csched2_vcpu(vc); spinlock_t *lock; =20 @@ -4083,19 +4094,19 @@ static const struct scheduler sched_credit2_def =3D= { =20 .global_init =3D csched2_global_init, =20 - .insert_vcpu =3D csched2_vcpu_insert, - .remove_vcpu =3D csched2_vcpu_remove, + .insert_unit =3D csched2_unit_insert, + .remove_unit =3D csched2_unit_remove, =20 - .sleep =3D csched2_vcpu_sleep, - .wake =3D csched2_vcpu_wake, - .yield =3D csched2_vcpu_yield, + .sleep =3D csched2_unit_sleep, + .wake =3D csched2_unit_wake, + .yield =3D csched2_unit_yield, =20 .adjust =3D csched2_dom_cntl, .adjust_affinity=3D csched2_aff_cntl, .adjust_global =3D csched2_sys_cntl, =20 .pick_cpu =3D csched2_cpu_pick, - .migrate =3D csched2_vcpu_migrate, + .migrate =3D csched2_unit_migrate, .do_schedule =3D csched2_schedule, .context_saved =3D csched2_context_saved, =20 diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index 6782ecda5c..fd031c989b 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -186,8 +186,9 @@ static void null_deinit_pdata(const struct scheduler *o= ps, void *pcpu, int cpu) } =20 static void *null_alloc_vdata(const struct scheduler *ops, - struct vcpu *v, void *dd) + struct sched_unit *unit, void *dd) { + struct vcpu *v =3D unit->vcpu_list; struct null_vcpu *nvc; =20 nvc =3D xzalloc(struct null_vcpu); @@ -435,8 +436,10 @@ static spinlock_t *null_switch_sched(struct scheduler = *new_ops, return &sd->_lock; } =20 -static void null_vcpu_insert(const struct scheduler *ops, struct vcpu *v) +static void null_unit_insert(const struct scheduler *ops, + struct sched_unit *unit) { + struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); struct null_vcpu *nvc =3D null_vcpu(v); unsigned int cpu; @@ -496,8 +499,10 @@ static void null_vcpu_insert(const struct scheduler *o= ps, struct vcpu *v) SCHED_STAT_CRANK(vcpu_insert); } =20 -static void null_vcpu_remove(const struct scheduler *ops, struct vcpu *v) +static void null_unit_remove(const struct scheduler *ops, + struct sched_unit *unit) { + struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); struct null_vcpu *nvc =3D null_vcpu(v); spinlock_t *lock; @@ -532,8 +537,10 @@ static void null_vcpu_remove(const struct scheduler *o= ps, struct vcpu *v) SCHED_STAT_CRANK(vcpu_remove); } =20 -static void null_vcpu_wake(const struct scheduler *ops, struct vcpu *v) +static void null_unit_wake(const struct scheduler *ops, + struct sched_unit *unit) { + struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); struct null_vcpu *nvc =3D null_vcpu(v); unsigned int cpu =3D v->processor; @@ -604,8 +611,10 @@ static void null_vcpu_wake(const struct scheduler *ops= , struct vcpu *v) cpu_raise_softirq(v->processor, SCHEDULE_SOFTIRQ); } =20 -static void null_vcpu_sleep(const struct scheduler *ops, struct vcpu *v) +static void null_unit_sleep(const struct scheduler *ops, + struct sched_unit *unit) { + struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); unsigned int cpu =3D v->processor; bool tickled =3D false; @@ -637,15 +646,17 @@ static void null_vcpu_sleep(const struct scheduler *o= ps, struct vcpu *v) SCHED_STAT_CRANK(vcpu_sleep); } =20 -static int null_cpu_pick(const struct scheduler *ops, struct vcpu *v) +static int null_cpu_pick(const struct scheduler *ops, struct sched_unit *u= nit) { + struct vcpu *v =3D unit->vcpu_list; ASSERT(!is_idle_vcpu(v)); return pick_cpu(null_priv(ops), v); } =20 -static void null_vcpu_migrate(const struct scheduler *ops, struct vcpu *v, - unsigned int new_cpu) +static void null_unit_migrate(const struct scheduler *ops, + struct sched_unit *unit, unsigned int new_cp= u) { + struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); struct null_vcpu *nvc =3D null_vcpu(v); =20 @@ -965,13 +976,13 @@ static const struct scheduler sched_null_def =3D { .alloc_domdata =3D null_alloc_domdata, .free_domdata =3D null_free_domdata, =20 - .insert_vcpu =3D null_vcpu_insert, - .remove_vcpu =3D null_vcpu_remove, + .insert_unit =3D null_unit_insert, + .remove_unit =3D null_unit_remove, =20 - .wake =3D null_vcpu_wake, - .sleep =3D null_vcpu_sleep, + .wake =3D null_unit_wake, + .sleep =3D null_unit_sleep, .pick_cpu =3D null_cpu_pick, - .migrate =3D null_vcpu_migrate, + .migrate =3D null_unit_migrate, .do_schedule =3D null_schedule, =20 .dump_cpu_state =3D null_dump_pcpu, diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index e0e350bdf3..da76a41436 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -136,7 +136,7 @@ * RTDS_delayed_runq_add: Do we need to add this to the RunQ/DepletedQ * once it's done being context switching out? * + Set when scheduling out in rt_schedule() if prev is runable - * + Set in rt_vcpu_wake if it finds RTDS_scheduled set + * + Set in rt_unit_wake if it finds RTDS_scheduled set * + Read in rt_context_saved(). If set, it adds prev to the Runqueue/Depl= etedQ * and clears the bit. */ @@ -636,8 +636,9 @@ replq_reinsert(const struct scheduler *ops, struct rt_v= cpu *svc) * and available cpus */ static int -rt_cpu_pick(const struct scheduler *ops, struct vcpu *vc) +rt_cpu_pick(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; cpumask_t cpus; cpumask_t *online; int cpu; @@ -837,8 +838,9 @@ rt_free_domdata(const struct scheduler *ops, void *data) } =20 static void * -rt_alloc_vdata(const struct scheduler *ops, struct vcpu *vc, void *dd) +rt_alloc_vdata(const struct scheduler *ops, struct sched_unit *unit, void = *dd) { + struct vcpu *vc =3D unit->vcpu_list; struct rt_vcpu *svc; =20 /* Allocate per-VCPU info */ @@ -880,8 +882,9 @@ rt_free_vdata(const struct scheduler *ops, void *priv) * dest. cpupool. */ static void -rt_vcpu_insert(const struct scheduler *ops, struct vcpu *vc) +rt_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct rt_vcpu *svc =3D rt_vcpu(vc); s_time_t now; spinlock_t *lock; @@ -889,7 +892,7 @@ rt_vcpu_insert(const struct scheduler *ops, struct vcpu= *vc) BUG_ON( is_idle_vcpu(vc) ); =20 /* This is safe because vc isn't yet being scheduled */ - vc->processor =3D rt_cpu_pick(ops, vc); + vc->processor =3D rt_cpu_pick(ops, unit); =20 lock =3D vcpu_schedule_lock_irq(vc); =20 @@ -913,8 +916,9 @@ rt_vcpu_insert(const struct scheduler *ops, struct vcpu= *vc) * Remove rt_vcpu svc from the old scheduler in source cpupool. */ static void -rt_vcpu_remove(const struct scheduler *ops, struct vcpu *vc) +rt_unit_remove(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct rt_vcpu * const svc =3D rt_vcpu(vc); struct rt_dom * const sdom =3D svc->sdom; spinlock_t *lock; @@ -1133,8 +1137,9 @@ rt_schedule(const struct scheduler *ops, s_time_t now= , bool_t tasklet_work_sched * The lock is already grabbed in schedule.c, no need to lock here */ static void -rt_vcpu_sleep(const struct scheduler *ops, struct vcpu *vc) +rt_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct rt_vcpu * const svc =3D rt_vcpu(vc); =20 BUG_ON( is_idle_vcpu(vc) ); @@ -1248,8 +1253,9 @@ runq_tickle(const struct scheduler *ops, struct rt_vc= pu *new) * TODO: what if these two vcpus belongs to the same domain? */ static void -rt_vcpu_wake(const struct scheduler *ops, struct vcpu *vc) +rt_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct rt_vcpu * const svc =3D rt_vcpu(vc); s_time_t now; bool_t missed; @@ -1318,8 +1324,9 @@ rt_vcpu_wake(const struct scheduler *ops, struct vcpu= *vc) * and then pick the highest priority vcpu from runq to run */ static void -rt_context_saved(const struct scheduler *ops, struct vcpu *vc) +rt_context_saved(const struct scheduler *ops, struct sched_unit *unit) { + struct vcpu *vc =3D unit->vcpu_list; struct rt_vcpu *svc =3D rt_vcpu(vc); spinlock_t *lock =3D vcpu_schedule_lock_irq(vc); =20 @@ -1548,15 +1555,15 @@ static const struct scheduler sched_rtds_def =3D { .free_domdata =3D rt_free_domdata, .alloc_vdata =3D rt_alloc_vdata, .free_vdata =3D rt_free_vdata, - .insert_vcpu =3D rt_vcpu_insert, - .remove_vcpu =3D rt_vcpu_remove, + .insert_unit =3D rt_unit_insert, + .remove_unit =3D rt_unit_remove, =20 .adjust =3D rt_dom_cntl, =20 .pick_cpu =3D rt_cpu_pick, .do_schedule =3D rt_schedule, - .sleep =3D rt_vcpu_sleep, - .wake =3D rt_vcpu_wake, + .sleep =3D rt_unit_sleep, + .wake =3D rt_unit_wake, .context_saved =3D rt_context_saved, }; =20 diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 1106698fb4..2c1a72c3c9 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -87,13 +87,13 @@ sched_idle_switch_sched(struct scheduler *new_ops, unsi= gned int cpu, } =20 static int -sched_idle_cpu_pick(const struct scheduler *ops, struct vcpu *v) +sched_idle_cpu_pick(const struct scheduler *ops, struct sched_unit *unit) { - return v->processor; + return unit->vcpu_list->processor; } =20 static void * -sched_idle_alloc_vdata(const struct scheduler *ops, struct vcpu *v, +sched_idle_alloc_vdata(const struct scheduler *ops, struct sched_unit *uni= t, void *dd) { /* Any non-NULL pointer is fine here. */ @@ -308,9 +308,17 @@ static void sched_spin_unlock_double(spinlock_t *lock1= , spinlock_t *lock2, int sched_init_vcpu(struct vcpu *v, unsigned int processor) { struct domain *d =3D v->domain; + struct sched_unit *unit; =20 v->processor =3D processor; =20 + if ( (unit =3D xzalloc(struct sched_unit)) =3D=3D NULL ) + return 1; + v->sched_unit =3D unit; + unit->vcpu_list =3D v; + unit->unit_id =3D v->vcpu_id; + unit->domain =3D d; + /* Initialise the per-vcpu timers. */ init_timer(&v->periodic_timer, vcpu_periodic_timer_fn, v, v->processor); @@ -319,9 +327,13 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proce= ssor) init_timer(&v->poll_timer, poll_timer_fn, v, v->processor); =20 - v->sched_priv =3D sched_alloc_vdata(dom_scheduler(d), v, d->sched_priv= ); + v->sched_priv =3D sched_alloc_vdata(dom_scheduler(d), unit, d->sched_p= riv); if ( v->sched_priv =3D=3D NULL ) + { + v->sched_unit =3D NULL; + xfree(unit); return 1; + } =20 /* * Initialize affinity settings. The idler, and potentially @@ -340,7 +352,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proces= sor) } else { - sched_insert_vcpu(dom_scheduler(d), v); + sched_insert_unit(dom_scheduler(d), unit); } =20 return 0; @@ -381,7 +393,8 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) =20 for_each_vcpu ( d, v ) { - vcpu_priv[v->vcpu_id] =3D sched_alloc_vdata(c->sched, v, domdata); + vcpu_priv[v->vcpu_id] =3D sched_alloc_vdata(c->sched, v->sched_uni= t, + domdata); if ( vcpu_priv[v->vcpu_id] =3D=3D NULL ) { for_each_vcpu ( d, v ) @@ -399,7 +412,7 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) =20 for_each_vcpu ( d, v ) { - sched_remove_vcpu(old_ops, v); + sched_remove_unit(old_ops, v->sched_unit); } =20 d->cpupool =3D c; @@ -434,7 +447,7 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) =20 new_p =3D cpumask_cycle(new_p, c->cpu_valid); =20 - sched_insert_vcpu(c->sched, v); + sched_insert_unit(c->sched, v->sched_unit); =20 sched_free_vdata(old_ops, vcpudata); } @@ -452,13 +465,17 @@ int sched_move_domain(struct domain *d, struct cpupoo= l *c) =20 void sched_destroy_vcpu(struct vcpu *v) { + struct sched_unit *unit =3D v->sched_unit; + kill_timer(&v->periodic_timer); kill_timer(&v->singleshot_timer); kill_timer(&v->poll_timer); if ( test_and_clear_bool(v->is_urgent) ) atomic_dec(&per_cpu(schedule_data, v->processor).urgent_count); - sched_remove_vcpu(vcpu_scheduler(v), v); + sched_remove_unit(vcpu_scheduler(v), unit); sched_free_vdata(vcpu_scheduler(v), v->sched_priv); + xfree(unit); + v->sched_unit =3D NULL; } =20 int sched_init_domain(struct domain *d, int poolid) @@ -509,7 +526,7 @@ void vcpu_sleep_nosync_locked(struct vcpu *v) if ( v->runstate.state =3D=3D RUNSTATE_runnable ) vcpu_runstate_change(v, RUNSTATE_offline, NOW()); =20 - sched_sleep(vcpu_scheduler(v), v); + sched_sleep(vcpu_scheduler(v), v->sched_unit); } } =20 @@ -550,7 +567,7 @@ void vcpu_wake(struct vcpu *v) { if ( v->runstate.state >=3D RUNSTATE_blocked ) vcpu_runstate_change(v, RUNSTATE_runnable, NOW()); - sched_wake(vcpu_scheduler(v), v); + sched_wake(vcpu_scheduler(v), v->sched_unit); } else if ( !(v->pause_flags & VPF_blocked) ) { @@ -605,7 +622,7 @@ static void vcpu_move_locked(struct vcpu *v, unsigned i= nt new_cpu) * Actual CPU switch to new CPU. This is safe because the lock * pointer can't change while the current lock is held. */ - sched_migrate(vcpu_scheduler(v), v, new_cpu); + sched_migrate(vcpu_scheduler(v), v->sched_unit, new_cpu); } =20 /* @@ -683,7 +700,7 @@ static void vcpu_migrate_finish(struct vcpu *v) break; =20 /* Select a new CPU. */ - new_cpu =3D sched_pick_cpu(vcpu_scheduler(v), v); + new_cpu =3D sched_pick_cpu(vcpu_scheduler(v), v->sched_unit); if ( (new_lock =3D=3D per_cpu(schedule_data, new_cpu).schedule= _lock) && cpumask_test_cpu(new_cpu, v->domain->cpupool->cpu_valid) ) break; @@ -793,7 +810,7 @@ void restore_vcpu_affinity(struct domain *d) =20 /* v->processor might have changed, so reacquire the lock. */ lock =3D vcpu_schedule_lock_irq(v); - v->processor =3D sched_pick_cpu(vcpu_scheduler(v), v); + v->processor =3D sched_pick_cpu(vcpu_scheduler(v), v->sched_unit); spin_unlock_irq(lock); =20 if ( old_cpu !=3D v->processor ) @@ -905,7 +922,7 @@ static int cpu_disable_scheduler_check(unsigned int cpu) void sched_set_affinity( struct vcpu *v, const cpumask_t *hard, const cpumask_t *soft) { - sched_adjust_affinity(dom_scheduler(v->domain), v, hard, soft); + sched_adjust_affinity(dom_scheduler(v->domain), v->sched_unit, hard, s= oft); =20 if ( hard ) cpumask_copy(v->cpu_hard_affinity, hard); @@ -1080,7 +1097,7 @@ long vcpu_yield(void) struct vcpu * v=3Dcurrent; spinlock_t *lock =3D vcpu_schedule_lock_irq(v); =20 - sched_yield(vcpu_scheduler(v), v); + sched_yield(vcpu_scheduler(v), v->sched_unit); vcpu_schedule_unlock_irq(lock, v); =20 SCHED_STAT_CRANK(vcpu_yield); @@ -1605,7 +1622,7 @@ void context_saved(struct vcpu *prev) /* Check for migration request /after/ clearing running flag. */ smp_mb(); =20 - sched_context_saved(vcpu_scheduler(prev), prev); + sched_context_saved(vcpu_scheduler(prev), prev->sched_unit); =20 vcpu_migrate_finish(prev); } @@ -1881,7 +1898,8 @@ int schedule_cpu_switch(unsigned int cpu, struct cpup= ool *c) ppriv =3D sched_alloc_pdata(new_ops, cpu); if ( IS_ERR(ppriv) ) return PTR_ERR(ppriv); - vpriv =3D sched_alloc_vdata(new_ops, idle, idle->domain->sched_priv); + vpriv =3D sched_alloc_vdata(new_ops, idle->sched_unit, + idle->domain->sched_priv); if ( vpriv =3D=3D NULL ) { sched_free_pdata(new_ops, ppriv, cpu); diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index dc255b064b..9fd367377a 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -141,8 +141,8 @@ struct scheduler { void (*deinit) (struct scheduler *); =20 void (*free_vdata) (const struct scheduler *, void *); - void * (*alloc_vdata) (const struct scheduler *, struct vcpu = *, - void *); + void * (*alloc_vdata) (const struct scheduler *, + struct sched_unit *, void *); void (*free_pdata) (const struct scheduler *, void *, int); void * (*alloc_pdata) (const struct scheduler *, int); void (*init_pdata) (const struct scheduler *, void *, int); @@ -156,24 +156,32 @@ struct scheduler { spinlock_t * (*switch_sched) (struct scheduler *, unsigned int, void *, void *); =20 - /* Activate / deactivate vcpus in a cpu pool */ - void (*insert_vcpu) (const struct scheduler *, struct vcpu = *); - void (*remove_vcpu) (const struct scheduler *, struct vcpu = *); - - void (*sleep) (const struct scheduler *, struct vcpu = *); - void (*wake) (const struct scheduler *, struct vcpu = *); - void (*yield) (const struct scheduler *, struct vcpu = *); - void (*context_saved) (const struct scheduler *, struct vcpu = *); + /* Activate / deactivate units in a cpu pool */ + void (*insert_unit) (const struct scheduler *, + struct sched_unit *); + void (*remove_unit) (const struct scheduler *, + struct sched_unit *); + + void (*sleep) (const struct scheduler *, + struct sched_unit *); + void (*wake) (const struct scheduler *, + struct sched_unit *); + void (*yield) (const struct scheduler *, + struct sched_unit *); + void (*context_saved) (const struct scheduler *, + struct sched_unit *); =20 struct task_slice (*do_schedule) (const struct scheduler *, s_time_t, bool_t tasklet_work_scheduled); =20 - int (*pick_cpu) (const struct scheduler *, struct vcpu = *); - void (*migrate) (const struct scheduler *, struct vcpu = *, - unsigned int); + int (*pick_cpu) (const struct scheduler *, + struct sched_unit *); + void (*migrate) (const struct scheduler *, + struct sched_unit *, unsigned int); int (*adjust) (const struct scheduler *, struct domai= n *, struct xen_domctl_scheduler_op *); - void (*adjust_affinity)(const struct scheduler *, struct vcpu = *, + void (*adjust_affinity)(const struct scheduler *, + struct sched_unit *, const struct cpumask *, const struct cpumask *); int (*adjust_global) (const struct scheduler *, @@ -267,10 +275,10 @@ static inline void sched_deinit_pdata(const struct sc= heduler *s, void *data, s->deinit_pdata(s, data, cpu); } =20 -static inline void *sched_alloc_vdata(const struct scheduler *s, struct vc= pu *v, - void *dom_data) +static inline void *sched_alloc_vdata(const struct scheduler *s, + struct sched_unit *unit, void *dom_d= ata) { - return s->alloc_vdata(s, v, dom_data); + return s->alloc_vdata(s, unit, dom_data); } =20 static inline void sched_free_vdata(const struct scheduler *s, void *data) @@ -278,64 +286,70 @@ static inline void sched_free_vdata(const struct sche= duler *s, void *data) s->free_vdata(s, data); } =20 -static inline void sched_insert_vcpu(const struct scheduler *s, struct vcp= u *v) +static inline void sched_insert_unit(const struct scheduler *s, + struct sched_unit *unit) { - if ( s->insert_vcpu ) - s->insert_vcpu(s, v); + if ( s->insert_unit ) + s->insert_unit(s, unit); } =20 -static inline void sched_remove_vcpu(const struct scheduler *s, struct vcp= u *v) +static inline void sched_remove_unit(const struct scheduler *s, + struct sched_unit *unit) { - if ( s->remove_vcpu ) - s->remove_vcpu(s, v); + if ( s->remove_unit ) + s->remove_unit(s, unit); } =20 -static inline void sched_sleep(const struct scheduler *s, struct vcpu *v) +static inline void sched_sleep(const struct scheduler *s, + struct sched_unit *unit) { if ( s->sleep ) - s->sleep(s, v); + s->sleep(s, unit); } =20 -static inline void sched_wake(const struct scheduler *s, struct vcpu *v) +static inline void sched_wake(const struct scheduler *s, + struct sched_unit *unit) { if ( s->wake ) - s->wake(s, v); + s->wake(s, unit); } =20 -static inline void sched_yield(const struct scheduler *s, struct vcpu *v) +static inline void sched_yield(const struct scheduler *s, + struct sched_unit *unit) { if ( s->yield ) - s->yield(s, v); + s->yield(s, unit); } =20 static inline void sched_context_saved(const struct scheduler *s, - struct vcpu *v) + struct sched_unit *unit) { if ( s->context_saved ) - s->context_saved(s, v); + s->context_saved(s, unit); } =20 -static inline void sched_migrate(const struct scheduler *s, struct vcpu *v, - unsigned int cpu) +static inline void sched_migrate(const struct scheduler *s, + struct sched_unit *unit, unsigned int cpu) { if ( s->migrate ) - s->migrate(s, v, cpu); + s->migrate(s, unit, cpu); else - v->processor =3D cpu; + unit->vcpu_list->processor =3D cpu; } =20 -static inline int sched_pick_cpu(const struct scheduler *s, struct vcpu *v) +static inline int sched_pick_cpu(const struct scheduler *s, + struct sched_unit *unit) { - return s->pick_cpu(s, v); + return s->pick_cpu(s, unit); } =20 static inline void sched_adjust_affinity(const struct scheduler *s, - struct vcpu *v, + struct sched_unit *unit, const cpumask_t *hard, const cpumask_t *soft) { if ( s->adjust_affinity ) - s->adjust_affinity(s, v, hard, soft); + s->adjust_affinity(s, unit, hard, soft); } =20 static inline int sched_adjust_dom(const struct scheduler *s, struct domai= n *d, diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 2e6e0d3488..d7dd182885 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -140,6 +140,7 @@ void evtchn_destroy(struct domain *d); /* from domain_k= ill */ void evtchn_destroy_final(struct domain *d); /* from complete_domain_destr= oy */ =20 struct waitqueue_vcpu; +struct sched_unit; =20 struct vcpu { @@ -160,6 +161,7 @@ struct vcpu =20 struct timer poll_timer; /* timeout for SCHEDOP_poll */ =20 + struct sched_unit *sched_unit; void *sched_priv; /* scheduler-specific data */ =20 struct vcpu_runstate_info runstate; @@ -272,6 +274,12 @@ struct vcpu struct arch_vcpu arch; }; =20 +struct sched_unit { + struct domain *domain; + struct vcpu *vcpu_list; + int unit_id; +}; + /* 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) --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362796; cv=none; d=zoho.com; s=zohoarc; b=n0Rk8+prD5VoXfaEiI8hf7NowbPH56MjLmCUerLLWi3TiPPyu0Pbq1QwqEs3O0pXMo1OlBhGOFpgOwxj/I0lAw7A2bYu87McqbwdGtGge7S+BfLEDL8xBlKADvajCB3QOHqO1M6BRvIu8VJIVSNP+Ismmwl8UEx1APYnlqNcmCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362796; 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=K/uJTGvn8ni2xHUpqW2Qi1JydPbXUFVtQgluN4HJkjY=; b=JkvBtJ5QekzFJOhS/mrjW4QMM6vlQz9CwTfbtoGht+U+Oo4p0Ar8Sg5Pm9JMaJe3C9L2tTN4fAa+/LUsoahezP52+3AKkAhON14IMNoI/1kUPvmngHhpc37/KF6lDKzb9RKfW6LvlNGpvUJXIVli10haLEBIK3ONeVg4NAWoSMQ= 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 1565362796101258.4661722247074; Fri, 9 Aug 2019 07:59:56 -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 1hw6Lr-0006P7-Nf; Fri, 09 Aug 2019 14:58:43 +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-0006Om-C3 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:42 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2afa70a4-bab6-11e9-8fca-4bf3aad99f02; Fri, 09 Aug 2019 14:58:38 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 95019AF83; Fri, 9 Aug 2019 14:58:37 +0000 (UTC) X-Inumbo-ID: 2afa70a4-bab6-11e9-8fca-4bf3aad99f02 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:47 +0200 Message-Id: <20190809145833.1020-3-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 02/48] xen/sched: move per-vcpu scheduler private data pointer to 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 , Robert VanVossen , Dario Faggioli , Julien Grall , Josh Whitehead , Meng Xu , 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" This prepares making the different schedulers vcpu agnostic. Note that some scheduler specific accessor function are misnamed after this patch. This will be corrected in later patches. Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- xen/common/sched_arinc653.c | 4 ++-- xen/common/sched_credit.c | 6 +++--- xen/common/sched_credit2.c | 10 +++++----- xen/common/sched_null.c | 4 ++-- xen/common/sched_rt.c | 4 ++-- xen/common/schedule.c | 14 +++++++------- xen/include/xen/sched.h | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c index 2059314791..c12b36b2d8 100644 --- a/xen/common/sched_arinc653.c +++ b/xen/common/sched_arinc653.c @@ -53,7 +53,7 @@ * Return a pointer to the ARINC 653-specific scheduler data information * associated with the given VCPU (vc) */ -#define AVCPU(vc) ((arinc653_vcpu_t *)(vc)->sched_priv) +#define AVCPU(vc) ((arinc653_vcpu_t *)(vc)->sched_unit->priv) =20 /** * Return the global scheduler private data given the scheduler ops pointer @@ -647,7 +647,7 @@ a653_switch_sched(struct scheduler *new_ops, unsigned i= nt cpu, =20 ASSERT(!pdata && svc && is_idle_vcpu(svc->vc)); =20 - idle_vcpu[cpu]->sched_priv =3D vdata; + idle_vcpu[cpu]->sched_unit->priv =3D vdata; =20 return &sd->_lock; } diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 464194a578..e835a4930a 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -83,7 +83,7 @@ ((struct csched_private *)((_ops)->sched_data)) #define CSCHED_PCPU(_c) \ ((struct csched_pcpu *)per_cpu(schedule_data, _c).sched_priv) -#define CSCHED_VCPU(_vcpu) ((struct csched_vcpu *) (_vcpu)->sched_priv) +#define CSCHED_VCPU(_vcpu) ((struct csched_vcpu *) (_vcpu)->sched_unit->p= riv) #define CSCHED_DOM(_dom) ((struct csched_dom *) (_dom)->sched_priv) #define RUNQ(_cpu) (&(CSCHED_PCPU(_cpu)->runq)) =20 @@ -634,7 +634,7 @@ csched_switch_sched(struct scheduler *new_ops, unsigned= int cpu, =20 ASSERT(svc && is_idle_vcpu(svc->vcpu)); =20 - idle_vcpu[cpu]->sched_priv =3D vdata; + idle_vcpu[cpu]->sched_unit->priv =3D vdata; =20 /* * We are holding the runqueue lock already (it's been taken in @@ -1017,7 +1017,7 @@ static void csched_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched_vcpu *svc =3D vc->sched_priv; + struct csched_vcpu *svc =3D unit->priv; spinlock_t *lock; =20 BUG_ON( is_idle_vcpu(vc) ); diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 2120da6f98..a2403e4198 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -573,7 +573,7 @@ static inline struct csched2_pcpu *csched2_pcpu(unsigne= d int cpu) =20 static inline struct csched2_vcpu *csched2_vcpu(const struct vcpu *v) { - return v->sched_priv; + return v->sched_unit->priv; } =20 static inline struct csched2_dom *csched2_dom(const struct domain *d) @@ -971,7 +971,7 @@ _runq_assign(struct csched2_vcpu *svc, struct csched2_r= unqueue_data *rqd) static void runq_assign(const struct scheduler *ops, struct vcpu *vc) { - struct csched2_vcpu *svc =3D vc->sched_priv; + struct csched2_vcpu *svc =3D vc->sched_unit->priv; =20 ASSERT(svc->rqd =3D=3D NULL); =20 @@ -998,7 +998,7 @@ _runq_deassign(struct csched2_vcpu *svc) static void runq_deassign(const struct scheduler *ops, struct vcpu *vc) { - struct csched2_vcpu *svc =3D vc->sched_priv; + struct csched2_vcpu *svc =3D vc->sched_unit->priv; =20 ASSERT(svc->rqd =3D=3D c2rqd(ops, vc->processor)); =20 @@ -3109,7 +3109,7 @@ static void csched2_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched2_vcpu *svc =3D vc->sched_priv; + struct csched2_vcpu *svc =3D unit->priv; struct csched2_dom * const sdom =3D svc->sdom; spinlock_t *lock; =20 @@ -3891,7 +3891,7 @@ csched2_switch_sched(struct scheduler *new_ops, unsig= ned int cpu, ASSERT(!local_irq_is_enabled()); write_lock(&prv->lock); =20 - idle_vcpu[cpu]->sched_priv =3D vdata; + idle_vcpu[cpu]->sched_unit->priv =3D vdata; =20 rqi =3D init_pdata(prv, pdata, cpu); =20 diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index fd031c989b..bdba237982 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -116,7 +116,7 @@ static inline struct null_private *null_priv(const stru= ct scheduler *ops) =20 static inline struct null_vcpu *null_vcpu(const struct vcpu *v) { - return v->sched_priv; + return v->sched_unit->priv; } =20 static inline bool vcpu_check_affinity(struct vcpu *v, unsigned int cpu, @@ -422,7 +422,7 @@ static spinlock_t *null_switch_sched(struct scheduler *= new_ops, =20 ASSERT(nvc && is_idle_vcpu(nvc->vcpu)); =20 - idle_vcpu[cpu]->sched_priv =3D vdata; + idle_vcpu[cpu]->sched_unit->priv =3D vdata; =20 /* * We are holding the runqueue lock already (it's been taken in diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index da76a41436..0f97c0f2a5 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -235,7 +235,7 @@ static inline struct rt_private *rt_priv(const struct s= cheduler *ops) =20 static inline struct rt_vcpu *rt_vcpu(const struct vcpu *vcpu) { - return vcpu->sched_priv; + return vcpu->sched_unit->priv; } =20 static inline struct list_head *rt_runq(const struct scheduler *ops) @@ -760,7 +760,7 @@ rt_switch_sched(struct scheduler *new_ops, unsigned int= cpu, dprintk(XENLOG_DEBUG, "RTDS: timer initialized on cpu %u\n", cpu); } =20 - idle_vcpu[cpu]->sched_priv =3D vdata; + idle_vcpu[cpu]->sched_unit->priv =3D vdata; =20 return &prv->lock; } diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 2c1a72c3c9..038ebf5ae9 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -81,7 +81,7 @@ static spinlock_t * sched_idle_switch_sched(struct scheduler *new_ops, unsigned int cpu, void *pdata, void *vdata) { - idle_vcpu[cpu]->sched_priv =3D NULL; + idle_vcpu[cpu]->sched_unit->priv =3D NULL; =20 return &sched_free_cpu_lock; } @@ -327,8 +327,8 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proces= sor) init_timer(&v->poll_timer, poll_timer_fn, v, v->processor); =20 - v->sched_priv =3D sched_alloc_vdata(dom_scheduler(d), unit, d->sched_p= riv); - if ( v->sched_priv =3D=3D NULL ) + unit->priv =3D sched_alloc_vdata(dom_scheduler(d), unit, d->sched_priv= ); + if ( unit->priv =3D=3D NULL ) { v->sched_unit =3D NULL; xfree(unit); @@ -423,7 +423,7 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) { spinlock_t *lock; =20 - vcpudata =3D v->sched_priv; + vcpudata =3D v->sched_unit->priv; =20 migrate_timer(&v->periodic_timer, new_p); migrate_timer(&v->singleshot_timer, new_p); @@ -441,7 +441,7 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) */ spin_unlock_irq(lock); =20 - v->sched_priv =3D vcpu_priv[v->vcpu_id]; + v->sched_unit->priv =3D vcpu_priv[v->vcpu_id]; if ( !d->is_dying ) sched_move_irqs(v); =20 @@ -473,7 +473,7 @@ void sched_destroy_vcpu(struct vcpu *v) if ( test_and_clear_bool(v->is_urgent) ) atomic_dec(&per_cpu(schedule_data, v->processor).urgent_count); sched_remove_unit(vcpu_scheduler(v), unit); - sched_free_vdata(vcpu_scheduler(v), v->sched_priv); + sched_free_vdata(vcpu_scheduler(v), unit->priv); xfree(unit); v->sched_unit =3D NULL; } @@ -1922,7 +1922,7 @@ int schedule_cpu_switch(unsigned int cpu, struct cpup= ool *c) */ old_lock =3D pcpu_schedule_lock_irqsave(cpu, &flags); =20 - vpriv_old =3D idle->sched_priv; + vpriv_old =3D idle->sched_unit->priv; ppriv_old =3D sd->sched_priv; new_lock =3D sched_switch_sched(new_ops, cpu, ppriv, vpriv); =20 diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index d7dd182885..a389ba5e1a 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -162,7 +162,6 @@ struct vcpu struct timer poll_timer; /* timeout for SCHEDOP_poll */ =20 struct sched_unit *sched_unit; - void *sched_priv; /* scheduler-specific data */ =20 struct vcpu_runstate_info runstate; #ifndef CONFIG_COMPAT @@ -277,6 +276,7 @@ struct vcpu struct sched_unit { struct domain *domain; struct vcpu *vcpu_list; + void *priv; /* scheduler private data */ int unit_id; }; =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362795; cv=none; d=zoho.com; s=zohoarc; b=V+Rpm+nlzPxq3d1L2sLHBOod2+vITsZKrsjJ4Wz7jgF5+KzLq07OpOScm3+nKaelD9vNeKj95d+PsjzBjAQoMHKglXJchASvjpgkyLryyAzKEFxp+eA9LBIYyhJiDJJbGieJzr2d1zGkSOoAlLGLcqy8xcZsvcJ19vPwkOw7bnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362795; 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=jZnvZgkHeyMy6VHUnRLY90fKq116KCHXGbbNe5H5sw8=; b=DXmgqwxYbPEZl1eDFE7mUpXtjrZOBLRYawO4/HahIEXtrDddE79i7y36wRIiUoGvlkCtDcYZ5P1tmPX6LlS7tlsy0lCb2E59Luh1Qzeq6POd8aqx6iDJ49K/vfJJlPD9cC9bF+B4dWqviGFEiZmuoHXEqW6OdHN/UUBw/Qq8kBw= 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 1565362795199862.6931620458371; Fri, 9 Aug 2019 07:59:55 -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 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 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) 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) X-Inumbo-ID: 2b349d10-bab6-11e9-9a69-b7b669d62bac X-Virus-Scanned: by amavisd-new at test-mx.suse.de 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 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) --- 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 *lock= 1, spinlock_t *lock2, spin_unlock_irqrestore(lock1, flags); } =20 -int sched_init_vcpu(struct vcpu *v, unsigned int processor) +static void sched_free_unit(struct sched_unit *unit) { - struct domain *d =3D v->domain; - struct sched_unit *unit; + struct sched_unit *prev_unit; + struct domain *d =3D unit->domain; =20 - v->processor =3D processor; + 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; =20 if ( (unit =3D xzalloc(struct sched_unit)) =3D=3D NULL ) - return 1; + return NULL; + v->sched_unit =3D unit; unit->vcpu_list =3D v; unit->unit_id =3D v->vcpu_id; unit->domain =3D d; =20 + 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; + + return unit; +} + +int sched_init_vcpu(struct vcpu *v, unsigned int processor) +{ + struct domain *d =3D v->domain; + struct sched_unit *unit; + + v->processor =3D processor; + + if ( (unit =3D sched_alloc_unit(v)) =3D=3D 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 proces= sor) unit->priv =3D sched_alloc_vdata(dom_scheduler(d), unit, d->sched_priv= ); if ( unit->priv =3D=3D NULL ) { - v->sched_unit =3D NULL; - xfree(unit); + sched_free_unit(unit); return 1; } =20 @@ -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 =3D NULL; + 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 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; }; =20 +#define for_each_sched_unit(d, e) \ + for ( (e) =3D (d)->sched_unit_list; (e) !=3D NULL; (e) =3D (e)->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(i, v) \ + for ( (v) =3D (i)->vcpu_list; (v) !=3D NULL && (v)->sched_unit =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) @@ -333,6 +346,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 From nobody Tue Apr 23 21:45:40 2024 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=1565362798; cv=none; d=zoho.com; s=zohoarc; b=WNNhw7hdxX6sQEXI/S+TEehzVVjzmdblHZFt2yJR8KWX1pBCrRLhiMSiBFSDHmExd/00utfTg89rb1CYtmODyT46Dcmg/UrGTgDHW06S12MBFfqi4TWDbtcOX4J/Nq7McJAesXarZCdfK++P1/K4tLtMvaV/6d9ThP+AguTRrNA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362798; 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=6dycNpJpJfyVvTF2l5MO8Ityi5+hzSdPpTJw/ZSC7B0=; b=MFvAjLFopO+YRnci+w8Sp9wTpIuNv/SIbFrFZgjjbUSr7DvvfRwFuRWjs3i1YZfTNmpGxNJMngxjg++DqfwE3y0gkT8P1Qi/uecUYBlEBgrJz850Ztk7vHCdti90YpmlrUkgdf6VUNoRyQLRuzMl0OjcaKPZig6i2F1DMt+958Q= 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 1565362798120355.5737016402303; Fri, 9 Aug 2019 07:59:58 -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 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 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) 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) X-Inumbo-ID: 2b7ba0a2-bab6-11e9-a3c6-97e7b842ae24 X-Virus-Scanned: by amavisd-new at test-mx.suse.de 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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, struc= t sched_unit *unit) lock =3D vcpu_schedule_lock_irq(vc); =20 vc->processor =3D csched_cpu_pick(ops, unit); + unit->res =3D get_sched_res(vc->processor); =20 spin_unlock_irq(lock); =20 @@ -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 =3D cpu; + vc->sched_unit->res =3D get_sched_res(cpu); /* * speer will start executing directly on cpu, without having = to * go through runq_insert(). So we must update the runnable co= unt 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 =3D cpumask_cycle(trqd->pick_bias, cpumask_scratch_cpu(cpu)); + svc->vcpu->sched_unit->res =3D get_sched_res(svc->vcpu->processor); trqd->pick_bias =3D svc->vcpu->processor; ASSERT(svc->vcpu->processor < nr_cpu_ids); =20 @@ -2775,6 +2776,7 @@ csched2_unit_migrate( } _runq_deassign(svc); vc->processor =3D new_cpu; + unit->res =3D get_sched_res(new_cpu); return; } =20 @@ -2795,7 +2797,10 @@ csched2_unit_migrate( if ( trqd !=3D svc->rqd ) migrate(ops, svc, trqd, now); else + { vc->processor =3D new_cpu; + unit->res =3D get_sched_res(new_cpu); + } } =20 static int @@ -3120,6 +3125,7 @@ csched2_unit_insert(const struct scheduler *ops, stru= ct sched_unit *unit) lock =3D vcpu_schedule_lock_irq(vc); =20 vc->processor =3D csched2_cpu_pick(ops, unit); + unit->res =3D get_sched_res(vc->processor); =20 spin_unlock_irq(lock); =20 @@ -3597,6 +3603,7 @@ csched2_schedule( { snext->credit +=3D CSCHED2_MIGRATE_COMPENSATION; snext->vcpu->processor =3D cpu; + snext->vcpu->sched_unit->res =3D get_sched_res(cpu); SCHED_STAT_CRANK(migrated); ret.migrated =3D 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, struc= t vcpu *v, =20 per_cpu(npc, cpu).vcpu =3D v; v->processor =3D cpu; + v->sched_unit->res =3D get_sched_res(cpu); cpumask_clear_cpu(cpu, &prv->cpus_free); =20 dprintk(XENLOG_G_INFO, "%d <-- %pv\n", cpu, v); @@ -457,6 +458,7 @@ static void null_unit_insert(const struct scheduler *op= s, =20 retry: cpu =3D v->processor =3D pick_cpu(prv, v); + unit->res =3D get_sched_res(cpu); =20 spin_unlock(lock); =20 @@ -748,6 +750,7 @@ static void null_unit_migrate(const struct scheduler *o= ps, */ out: v->processor =3D new_cpu; + unit->res =3D get_sched_res(new_cpu); } =20 #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 sche= d_unit *unit) =20 /* This is safe because vc isn't yet being scheduled */ vc->processor =3D rt_cpu_pick(ops, unit); + unit->res =3D get_sched_res(vc->processor); =20 lock =3D vcpu_schedule_lock_irq(vc); =20 @@ -1123,6 +1124,7 @@ rt_schedule(const struct scheduler *ops, s_time_t now= , bool_t tasklet_work_sched if ( snext->vcpu->processor !=3D cpu ) { snext->vcpu->processor =3D cpu; + snext->vcpu->sched_unit->res =3D get_sched_res(cpu); ret.migrated =3D 1; } ret.time =3D 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); =20 /* Scratch space for cpumasks. */ DEFINE_PER_CPU(cpumask_t, cpumask_scratch); @@ -89,7 +90,7 @@ sched_idle_switch_sched(struct scheduler *new_ops, unsign= ed 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; } =20 static void * @@ -363,6 +364,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proces= sor) if ( (unit =3D sched_alloc_unit(v)) =3D=3D NULL ) return 1; =20 + unit->res =3D 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); =20 v->processor =3D new_p; + v->sched_unit->res =3D 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) } =20 v->processor =3D cpumask_any(cpumask_scratch_cpu(cpu)); + v->sched_unit->res =3D get_sched_res(v->processor); =20 spin_unlock_irq(lock); =20 /* v->processor might have changed, so reacquire the lock. */ lock =3D vcpu_schedule_lock_irq(v); v->processor =3D sched_pick_cpu(vcpu_scheduler(v), v->sched_unit); + v->sched_unit->res =3D get_sched_res(v->processor); spin_unlock_irq(lock); =20 if ( old_cpu !=3D 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 =3D &per_cpu(schedule_data, cpu); + struct sched_resource *res; + + res =3D xzalloc(struct sched_resource); + if ( res =3D=3D NULL ) + return -ENOMEM; + res->processor =3D cpu; + set_sched_res(cpu, res); =20 per_cpu(scheduler, cpu) =3D &sched_idle_ops; spin_lock_init(&sd->_lock); @@ -1715,6 +1727,8 @@ static int cpu_schedule_up(unsigned int cpu) =20 if ( idle_vcpu[cpu] =3D=3D NULL ) vcpu_create(idle_vcpu[0]->domain, cpu, cpu); + else + idle_vcpu[cpu]->sched_unit->res =3D res; =20 if ( idle_vcpu[cpu] =3D=3D NULL ) return -ENOMEM; @@ -1737,6 +1751,9 @@ static void cpu_schedule_down(unsigned int cpu) struct schedule_data *sd =3D &per_cpu(schedule_data, cpu); =20 kill_timer(&sd->s_timer); + + set_sched_res(cpu, NULL); + xfree(sd); } =20 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 { =20 #define curr_on_cpu(c) (per_cpu(schedule_data, c).curr) =20 +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) =3D res; +} =20 /* * Scratch space, for avoiding having too many cpumask_t on the stack. @@ -334,7 +349,10 @@ static inline void sched_migrate(const struct schedule= r *s, if ( s->migrate ) s->migrate(s, unit, cpu); else + { unit->vcpu_list->processor =3D cpu; + unit->res =3D get_sched_res(cpu); + } } =20 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; }; =20 +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; }; =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362797; cv=none; d=zoho.com; s=zohoarc; b=n9hDDRzI1zhs6vn5k05aHEYR8+JwEqzdHKlOWOqpjtR4RcCr5ehf7lT0Nvvpd3ZK6s6HzEojsXz7alJC1JIFRbGLqsnvZ65mkrOkPkZnSiqSbSEzqMnmLhCxzwbQrp9QbVoeEj6aaLCAdq+PozSaeD1UjF6kGhmKuzm1NR1Ub1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362797; 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=P6wX3XsYufASCoeGKndaLFwSq1p4oi1EaRRUK+i2Oyo=; b=OD1xByb5vYfZe7O6ZWOyabX9dnw6PRj+ZxLVYzL/TvhbOPxzmdeFTA8Y0JlWYx4+QJPb/8/KjkCPgaL2wcKIgwKNJNvvk386xfCrM1JP4XaxUCnqWljxwJ7UGl82XIQ4yUm4ED1ntXC6LnoY3pusLgZxnfwb2HuIA2hgPc1GDrs= 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 1565362797003397.89209436344197; Fri, 9 Aug 2019 07:59:57 -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 1hw6Lu-0006Qz-UD; Fri, 09 Aug 2019 14:58:46 +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 1hw6Lt-0006QV-Uh for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:46 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2c63bc66-bab6-11e9-89b8-8fb395106bcf; Fri, 09 Aug 2019 14:58:40 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id EAF72B034; Fri, 9 Aug 2019 14:58:38 +0000 (UTC) X-Inumbo-ID: 2c63bc66-bab6-11e9-89b8-8fb395106bcf X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:50 +0200 Message-Id: <20190809145833.1020-6-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 05/48] xen/sched: let pick_cpu return a scheduler 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 , Robert VanVossen , Dario Faggioli , Julien Grall , Josh Whitehead , Meng Xu , 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" Instead of returning a physical cpu number let pick_cpu() return a scheduler resource instead. Rename pick_cpu() to pick_resource() to reflect that change. Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- xen/common/sched_arinc653.c | 12 ++++++------ xen/common/sched_credit.c | 16 ++++++++-------- xen/common/sched_credit2.c | 22 +++++++++++----------- xen/common/sched_null.c | 22 ++++++++++++---------- xen/common/sched_rt.c | 18 +++++++++--------- xen/common/schedule.c | 18 ++++++++++-------- xen/include/xen/perfc_defn.h | 2 +- xen/include/xen/sched-if.h | 10 +++++----- 8 files changed, 62 insertions(+), 58 deletions(-) diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c index c12b36b2d8..969de338b1 100644 --- a/xen/common/sched_arinc653.c +++ b/xen/common/sched_arinc653.c @@ -601,15 +601,15 @@ a653sched_do_schedule( } =20 /** - * Xen scheduler callback function to select a CPU for the VCPU to run on + * Xen scheduler callback function to select a resource for the VCPU to ru= n on * * @param ops Pointer to this instance of the scheduler structure * @param unit Pointer to struct sched_unit * - * @return Number of selected physical CPU + * @return Scheduler resource to run on */ -static int -a653sched_pick_cpu(const struct scheduler *ops, struct sched_unit *unit) +static struct sched_resource * +a653sched_pick_resource(const struct scheduler *ops, struct sched_unit *un= it) { struct vcpu *vc =3D unit->vcpu_list; cpumask_t *online; @@ -627,7 +627,7 @@ a653sched_pick_cpu(const struct scheduler *ops, struct = sched_unit *unit) || (cpu >=3D nr_cpu_ids) ) cpu =3D vc->processor; =20 - return cpu; + return get_sched_res(cpu); } =20 /** @@ -720,7 +720,7 @@ static const struct scheduler sched_arinc653_def =3D { =20 .do_schedule =3D a653sched_do_schedule, =20 - .pick_cpu =3D a653sched_pick_cpu, + .pick_resource =3D a653sched_pick_resource, =20 .switch_sched =3D a653_switch_sched, =20 diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index c3446551cc..6e56f1a3f6 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -853,8 +853,8 @@ _csched_cpu_pick(const struct scheduler *ops, struct vc= pu *vc, bool_t commit) return cpu; } =20 -static int -csched_cpu_pick(const struct scheduler *ops, struct sched_unit *unit) +static struct sched_resource * +csched_res_pick(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; struct csched_vcpu *svc =3D CSCHED_VCPU(vc); @@ -867,7 +867,7 @@ csched_cpu_pick(const struct scheduler *ops, struct sch= ed_unit *unit) * get boosted, which we don't deserve as we are "only" migrating. */ set_bit(CSCHED_FLAG_VCPU_MIGRATING, &svc->flags); - return _csched_cpu_pick(ops, vc, 1); + return get_sched_res(_csched_cpu_pick(ops, vc, 1)); } =20 static inline void @@ -967,7 +967,7 @@ csched_vcpu_acct(struct csched_private *prv, unsigned i= nt cpu) /* * If it's been active a while, check if we'd be better off * migrating it to run elsewhere (see multi-core and multi-thread - * support in csched_cpu_pick()). + * support in csched_res_pick()). */ new_cpu =3D _csched_cpu_pick(ops, current, 0); =20 @@ -1022,11 +1022,11 @@ csched_unit_insert(const struct scheduler *ops, str= uct sched_unit *unit) =20 BUG_ON( is_idle_vcpu(vc) ); =20 - /* csched_cpu_pick() looks in vc->processor's runq, so we need the loc= k. */ + /* csched_res_pick() looks in vc->processor's runq, so we need the loc= k. */ lock =3D vcpu_schedule_lock_irq(vc); =20 - vc->processor =3D csched_cpu_pick(ops, unit); - unit->res =3D get_sched_res(vc->processor); + unit->res =3D csched_res_pick(ops, unit); + vc->processor =3D unit->res->processor; =20 spin_unlock_irq(lock); =20 @@ -2278,7 +2278,7 @@ static const struct scheduler sched_credit_def =3D { .adjust_affinity=3D csched_aff_cntl, .adjust_global =3D csched_sys_cntl, =20 - .pick_cpu =3D csched_cpu_pick, + .pick_resource =3D csched_res_pick, .do_schedule =3D csched_schedule, =20 .dump_cpu_state =3D csched_dump_pcpu, diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index f7e5f07c7f..4df0afeb02 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -626,9 +626,9 @@ static inline bool has_cap(const struct csched2_vcpu *s= vc) * runq, _always_ happens by means of tickling: * - when a vcpu wakes up, it calls csched2_unit_wake(), which calls * runq_tickle(); - * - when a migration is initiated in schedule.c, we call csched2_cpu_pic= k(), + * - when a migration is initiated in schedule.c, we call csched2_res_pic= k(), * csched2_unit_migrate() (which calls migrate()) and csched2_unit_wake= (). - * csched2_cpu_pick() looks for the least loaded runq and return just a= ny + * csched2_res_pick() looks for the least loaded runq and return just a= ny * of its processors. Then, csched2_unit_migrate() just moves the vcpu = to * the chosen runq, and it is again runq_tickle(), called by * csched2_unit_wake() that actually decides what pcpu to use within the @@ -677,7 +677,7 @@ void smt_idle_mask_clear(unsigned int cpu, cpumask_t *m= ask) } =20 /* - * In csched2_cpu_pick(), it may not be possible to actually look at remote + * In csched2_res_pick(), it may not be possible to actually look at remote * runqueues (the trylock-s on their spinlocks can fail!). If that happens, * we pick, in order of decreasing preference: * 1) svc's current pcpu, if it is part of svc's soft affinity; @@ -2202,8 +2202,8 @@ csched2_context_saved(const struct scheduler *ops, st= ruct sched_unit *unit) } =20 #define MAX_LOAD (STIME_MAX) -static int -csched2_cpu_pick(const struct scheduler *ops, struct sched_unit *unit) +static struct sched_resource * +csched2_res_pick(const struct scheduler *ops, struct sched_unit *unit) { struct csched2_private *prv =3D csched2_priv(ops); struct vcpu *vc =3D unit->vcpu_list; @@ -2215,7 +2215,7 @@ csched2_cpu_pick(const struct scheduler *ops, struct = sched_unit *unit) =20 ASSERT(!cpumask_empty(&prv->active_queues)); =20 - SCHED_STAT_CRANK(pick_cpu); + SCHED_STAT_CRANK(pick_resource); =20 /* Locking: * - Runqueue lock of vc->processor is already locked @@ -2424,7 +2424,7 @@ csched2_cpu_pick(const struct scheduler *ops, struct = sched_unit *unit) (unsigned char *)&d); } =20 - return new_cpu; + return get_sched_res(new_cpu); } =20 /* Working state of the load-balancing algorithm */ @@ -3121,11 +3121,11 @@ csched2_unit_insert(const struct scheduler *ops, st= ruct sched_unit *unit) ASSERT(!is_idle_vcpu(vc)); ASSERT(list_empty(&svc->runq_elem)); =20 - /* csched2_cpu_pick() expects the pcpu lock to be held */ + /* csched2_res_pick() expects the pcpu lock to be held */ lock =3D vcpu_schedule_lock_irq(vc); =20 - vc->processor =3D csched2_cpu_pick(ops, unit); - unit->res =3D get_sched_res(vc->processor); + unit->res =3D csched2_res_pick(ops, unit); + vc->processor =3D unit->res->processor; =20 spin_unlock_irq(lock); =20 @@ -4112,7 +4112,7 @@ static const struct scheduler sched_credit2_def =3D { .adjust_affinity=3D csched2_aff_cntl, .adjust_global =3D csched2_sys_cntl, =20 - .pick_cpu =3D csched2_cpu_pick, + .pick_resource =3D csched2_res_pick, .migrate =3D csched2_unit_migrate, .do_schedule =3D csched2_schedule, .context_saved =3D csched2_context_saved, diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index 27c859b684..dd961bc3ca 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -261,9 +261,11 @@ static void null_free_domdata(const struct scheduler *= ops, void *data) * * So this is not part of any hot path. */ -static unsigned int pick_cpu(struct null_private *prv, struct vcpu *v) +static struct sched_resource * +pick_res(struct null_private *prv, struct sched_unit *unit) { unsigned int bs; + struct vcpu *v =3D unit->vcpu_list; unsigned int cpu =3D v->processor, new_cpu; cpumask_t *cpus =3D cpupool_domain_cpumask(v->domain); =20 @@ -327,7 +329,7 @@ static unsigned int pick_cpu(struct null_private *prv, = struct vcpu *v) __trace_var(TRC_SNULL_PICKED_CPU, 1, sizeof(d), &d); } =20 - return new_cpu; + return get_sched_res(new_cpu); } =20 static void vcpu_assign(struct null_private *prv, struct vcpu *v, @@ -457,8 +459,8 @@ static void null_unit_insert(const struct scheduler *op= s, } =20 retry: - cpu =3D v->processor =3D pick_cpu(prv, v); - unit->res =3D get_sched_res(cpu); + unit->res =3D pick_res(prv, unit); + cpu =3D v->processor =3D unit->res->processor; =20 spin_unlock(lock); =20 @@ -599,7 +601,7 @@ static void null_unit_wake(const struct scheduler *ops, */ while ( cpumask_intersects(&prv->cpus_free, cpumask_scratch_cpu(cp= u)) ) { - unsigned int new_cpu =3D pick_cpu(prv, v); + unsigned int new_cpu =3D pick_res(prv, unit)->processor; =20 if ( test_and_clear_bit(new_cpu, &prv->cpus_free) ) { @@ -648,11 +650,11 @@ static void null_unit_sleep(const struct scheduler *o= ps, SCHED_STAT_CRANK(vcpu_sleep); } =20 -static int null_cpu_pick(const struct scheduler *ops, struct sched_unit *u= nit) +static struct sched_resource * +null_res_pick(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *v =3D unit->vcpu_list; - ASSERT(!is_idle_vcpu(v)); - return pick_cpu(null_priv(ops), v); + ASSERT(!is_idle_vcpu(unit->vcpu_list)); + return pick_res(null_priv(ops), unit); } =20 static void null_unit_migrate(const struct scheduler *ops, @@ -984,7 +986,7 @@ static const struct scheduler sched_null_def =3D { =20 .wake =3D null_unit_wake, .sleep =3D null_unit_sleep, - .pick_cpu =3D null_cpu_pick, + .pick_resource =3D null_res_pick, .migrate =3D null_unit_migrate, .do_schedule =3D null_schedule, =20 diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index 7e622101a4..6e9424a461 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -631,12 +631,12 @@ replq_reinsert(const struct scheduler *ops, struct rt= _vcpu *svc) } =20 /* - * Pick a valid CPU for the vcpu vc - * Valid CPU of a vcpu is intesection of vcpu's affinity - * and available cpus + * Pick a valid resource for the vcpu vc + * Valid resource of a vcpu is intesection of vcpu's affinity + * and available resources */ -static int -rt_cpu_pick(const struct scheduler *ops, struct sched_unit *unit) +static struct sched_resource * +rt_res_pick(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; cpumask_t cpus; @@ -651,7 +651,7 @@ rt_cpu_pick(const struct scheduler *ops, struct sched_u= nit *unit) : cpumask_cycle(vc->processor, &cpus); ASSERT( !cpumask_empty(&cpus) && cpumask_test_cpu(cpu, &cpus) ); =20 - return cpu; + return get_sched_res(cpu); } =20 /* @@ -892,8 +892,8 @@ rt_unit_insert(const struct scheduler *ops, struct sche= d_unit *unit) BUG_ON( is_idle_vcpu(vc) ); =20 /* This is safe because vc isn't yet being scheduled */ - vc->processor =3D rt_cpu_pick(ops, unit); - unit->res =3D get_sched_res(vc->processor); + unit->res =3D rt_res_pick(ops, unit); + vc->processor =3D unit->res->processor; =20 lock =3D vcpu_schedule_lock_irq(vc); =20 @@ -1562,7 +1562,7 @@ static const struct scheduler sched_rtds_def =3D { =20 .adjust =3D rt_dom_cntl, =20 - .pick_cpu =3D rt_cpu_pick, + .pick_resource =3D rt_res_pick, .do_schedule =3D rt_schedule, .sleep =3D rt_unit_sleep, .wake =3D rt_unit_wake, diff --git a/xen/common/schedule.c b/xen/common/schedule.c index f5427cf29b..9ad11dc46d 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -87,10 +87,10 @@ sched_idle_switch_sched(struct scheduler *new_ops, unsi= gned int cpu, return &sched_free_cpu_lock; } =20 -static int -sched_idle_cpu_pick(const struct scheduler *ops, struct sched_unit *unit) +static struct sched_resource * +sched_idle_res_pick(const struct scheduler *ops, struct sched_unit *unit) { - return unit->res->processor; + return unit->res; } =20 static void * @@ -122,7 +122,7 @@ static struct scheduler sched_idle_ops =3D { .opt_name =3D "idle", .sched_data =3D NULL, =20 - .pick_cpu =3D sched_idle_cpu_pick, + .pick_resource =3D sched_idle_res_pick, .do_schedule =3D sched_idle_schedule, =20 .alloc_vdata =3D sched_idle_alloc_vdata, @@ -745,7 +745,8 @@ static void vcpu_migrate_finish(struct vcpu *v) break; =20 /* Select a new CPU. */ - new_cpu =3D sched_pick_cpu(vcpu_scheduler(v), v->sched_unit); + new_cpu =3D sched_pick_resource(vcpu_scheduler(v), + v->sched_unit)->processor; if ( (new_lock =3D=3D per_cpu(schedule_data, new_cpu).schedule= _lock) && cpumask_test_cpu(new_cpu, v->domain->cpupool->cpu_valid) ) break; @@ -856,8 +857,9 @@ void restore_vcpu_affinity(struct domain *d) =20 /* v->processor might have changed, so reacquire the lock. */ lock =3D vcpu_schedule_lock_irq(v); - v->processor =3D sched_pick_cpu(vcpu_scheduler(v), v->sched_unit); - v->sched_unit->res =3D get_sched_res(v->processor); + v->sched_unit->res =3D sched_pick_resource(vcpu_scheduler(v), + v->sched_unit); + v->processor =3D v->sched_unit->res->processor; spin_unlock_irq(lock); =20 if ( old_cpu !=3D v->processor ) @@ -1846,7 +1848,7 @@ void __init scheduler_init(void) =20 sched_test_func(init); sched_test_func(deinit); - sched_test_func(pick_cpu); + sched_test_func(pick_resource); sched_test_func(alloc_vdata); sched_test_func(free_vdata); sched_test_func(switch_sched); diff --git a/xen/include/xen/perfc_defn.h b/xen/include/xen/perfc_defn.h index ef6f86b91e..1ad4384080 100644 --- a/xen/include/xen/perfc_defn.h +++ b/xen/include/xen/perfc_defn.h @@ -69,7 +69,7 @@ PERFCOUNTER(migrate_on_runq, "csched2: migrate_on_= runq") PERFCOUNTER(migrate_no_runq, "csched2: migrate_no_runq") PERFCOUNTER(runtime_min_timer, "csched2: runtime_min_timer") PERFCOUNTER(runtime_max_timer, "csched2: runtime_max_timer") -PERFCOUNTER(pick_cpu, "csched2: pick_cpu") +PERFCOUNTER(pick_resource, "csched2: pick_resource") PERFCOUNTER(need_fallback_cpu, "csched2: need_fallback_cpu") PERFCOUNTER(migrated, "csched2: migrated") PERFCOUNTER(migrate_resisted, "csched2: migrate_resisted") diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index f30dc4cdf1..88c1e6d505 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -189,8 +189,8 @@ struct scheduler { struct task_slice (*do_schedule) (const struct scheduler *, s_time_t, bool_t tasklet_work_scheduled); =20 - int (*pick_cpu) (const struct scheduler *, - struct sched_unit *); + struct sched_resource * (*pick_resource) (const struct scheduler *, + struct sched_unit *); void (*migrate) (const struct scheduler *, struct sched_unit *, unsigned int); int (*adjust) (const struct scheduler *, struct domai= n *, @@ -355,10 +355,10 @@ static inline void sched_migrate(const struct schedul= er *s, } } =20 -static inline int sched_pick_cpu(const struct scheduler *s, - struct sched_unit *unit) +static inline struct sched_resource *sched_pick_resource( + const struct scheduler *s, struct sched_unit *unit) { - return s->pick_cpu(s, unit); + return s->pick_resource(s, unit); } =20 static inline void sched_adjust_affinity(const struct scheduler *s, --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362781; cv=none; d=zoho.com; s=zohoarc; b=h0FY6sKBWJ1H9yT4HiRFsnnAOIW7H9nDSmDJvVZGREz0gHOz0wHXY7qyWLfVzKrKlU3qAiRbpjIo0/QgOsfo81t+8VouBwiWelqb11CWsbVvLDAyG2zmja8F+80urrRPcRXqPymj49X3wF1d8pWNdex+6YcSpjvwHslCQmZS0Ro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362781; 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=Pa0G9Bh9zLW5PRX+Tou1b06KTY97VupbTaRBHEpzqu8=; b=GZjKD6HyOYXT0rEiWYCSZSIKzin5QeW+DCujUwEVP9Lf4ECMAGMBmTE+7uVEJ4aeiZeoak6ubxk5kN4fSqlvmqrMr8vrSgzJMo8fcAgmtO8yFKHefC9/ES8nhOZWwHjrVP/N37YBzguGpZqM7qssP6dJ6nM+WpJslJBHRhuBXlg= 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 1565362781506455.1497612193567; Fri, 9 Aug 2019 07:59:41 -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 1hw6M0-0006Xn-3q; Fri, 09 Aug 2019 14:58:52 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6Lx-0006TF-27 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:49 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2c69f052-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:41 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 79447B03B; Fri, 9 Aug 2019 14:58:39 +0000 (UTC) X-Inumbo-ID: 2c69f052-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:51 +0200 Message-Id: <20190809145833.1020-7-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 06/48] xen/sched: switch schedule_data.curr to point at 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 , Robert VanVossen , Dario Faggioli , Julien Grall , Josh Whitehead , Meng Xu , 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 preparation of core scheduling let the percpu pointer schedule_data.curr point to a strct sched_unit instead of the related vcpu. At the same time rename the per-vcpu scheduler specific structs to per-unit ones. Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- xen/common/sched_arinc653.c | 2 +- xen/common/sched_credit.c | 105 ++++++++++++++------------- xen/common/sched_credit2.c | 168 ++++++++++++++++++++++------------------= ---- xen/common/sched_null.c | 46 ++++++------ xen/common/sched_rt.c | 118 +++++++++++++++---------------- xen/common/schedule.c | 8 +-- xen/include/xen/sched-if.h | 2 +- 7 files changed, 222 insertions(+), 227 deletions(-) diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c index 969de338b1..34b1f235a2 100644 --- a/xen/common/sched_arinc653.c +++ b/xen/common/sched_arinc653.c @@ -475,7 +475,7 @@ a653sched_unit_sleep(const struct scheduler *ops, struc= t sched_unit *unit) * If the VCPU being put to sleep is the same one that is currently * running, raise a softirq to invoke the scheduler to switch domains. */ - if ( per_cpu(schedule_data, vc->processor).curr =3D=3D vc ) + if ( per_cpu(schedule_data, vc->processor).curr =3D=3D unit ) cpu_raise_softirq(vc->processor, SCHEDULE_SOFTIRQ); } =20 diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 6e56f1a3f6..7c3dbae892 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -83,7 +83,7 @@ ((struct csched_private *)((_ops)->sched_data)) #define CSCHED_PCPU(_c) \ ((struct csched_pcpu *)per_cpu(schedule_data, _c).sched_priv) -#define CSCHED_VCPU(_vcpu) ((struct csched_vcpu *) (_vcpu)->sched_unit->p= riv) +#define CSCHED_UNIT(unit) ((struct csched_unit *) (unit)->priv) #define CSCHED_DOM(_dom) ((struct csched_dom *) (_dom)->sched_priv) #define RUNQ(_cpu) (&(CSCHED_PCPU(_cpu)->runq)) =20 @@ -160,7 +160,7 @@ struct csched_pcpu { /* * Virtual CPU */ -struct csched_vcpu { +struct csched_unit { struct list_head runq_elem; struct list_head active_vcpu_elem; =20 @@ -233,15 +233,15 @@ static void csched_tick(void *_cpu); static void csched_acct(void *dummy); =20 static inline int -__vcpu_on_runq(struct csched_vcpu *svc) +__vcpu_on_runq(struct csched_unit *svc) { return !list_empty(&svc->runq_elem); } =20 -static inline struct csched_vcpu * +static inline struct csched_unit * __runq_elem(struct list_head *elem) { - return list_entry(elem, struct csched_vcpu, runq_elem); + return list_entry(elem, struct csched_unit, runq_elem); } =20 /* Is the first element of cpu's runq (if any) cpu's idle vcpu? */ @@ -273,7 +273,7 @@ dec_nr_runnable(unsigned int cpu) } =20 static inline void -__runq_insert(struct csched_vcpu *svc) +__runq_insert(struct csched_unit *svc) { unsigned int cpu =3D svc->vcpu->processor; const struct list_head * const runq =3D RUNQ(cpu); @@ -283,7 +283,7 @@ __runq_insert(struct csched_vcpu *svc) =20 list_for_each( iter, runq ) { - const struct csched_vcpu * const iter_svc =3D __runq_elem(iter); + const struct csched_unit * const iter_svc =3D __runq_elem(iter); if ( svc->pri > iter_svc->pri ) break; } @@ -304,34 +304,34 @@ __runq_insert(struct csched_vcpu *svc) } =20 static inline void -runq_insert(struct csched_vcpu *svc) +runq_insert(struct csched_unit *svc) { __runq_insert(svc); inc_nr_runnable(svc->vcpu->processor); } =20 static inline void -__runq_remove(struct csched_vcpu *svc) +__runq_remove(struct csched_unit *svc) { BUG_ON( !__vcpu_on_runq(svc) ); list_del_init(&svc->runq_elem); } =20 static inline void -runq_remove(struct csched_vcpu *svc) +runq_remove(struct csched_unit *svc) { dec_nr_runnable(svc->vcpu->processor); __runq_remove(svc); } =20 -static void burn_credits(struct csched_vcpu *svc, s_time_t now) +static void burn_credits(struct csched_unit *svc, s_time_t now) { s_time_t delta; uint64_t val; unsigned int credits; =20 /* Assert svc is current */ - ASSERT( svc =3D=3D CSCHED_VCPU(curr_on_cpu(svc->vcpu->processor)) ); + ASSERT( svc =3D=3D CSCHED_UNIT(curr_on_cpu(svc->vcpu->processor)) ); =20 if ( (delta =3D now - svc->start_time) <=3D 0 ) return; @@ -349,10 +349,10 @@ boolean_param("tickle_one_idle_cpu", opt_tickle_one_i= dle); =20 DEFINE_PER_CPU(unsigned int, last_tickle_cpu); =20 -static inline void __runq_tickle(struct csched_vcpu *new) +static inline void __runq_tickle(struct csched_unit *new) { unsigned int cpu =3D new->vcpu->processor; - struct csched_vcpu * const cur =3D CSCHED_VCPU(curr_on_cpu(cpu)); + struct csched_unit * const cur =3D CSCHED_UNIT(curr_on_cpu(cpu)); struct csched_private *prv =3D CSCHED_PRIV(per_cpu(scheduler, cpu)); cpumask_t mask, idle_mask, *online; int balance_step, idlers_empty; @@ -607,7 +607,7 @@ init_pdata(struct csched_private *prv, struct csched_pc= pu *spc, int cpu) spc->idle_bias =3D nr_cpu_ids - 1; =20 /* Start off idling... */ - BUG_ON(!is_idle_vcpu(curr_on_cpu(cpu))); + BUG_ON(!is_idle_vcpu(curr_on_cpu(cpu)->vcpu_list)); cpumask_set_cpu(cpu, prv->idlers); spc->nr_runnable =3D 0; } @@ -630,7 +630,7 @@ csched_switch_sched(struct scheduler *new_ops, unsigned= int cpu, { struct schedule_data *sd =3D &per_cpu(schedule_data, cpu); struct csched_private *prv =3D CSCHED_PRIV(new_ops); - struct csched_vcpu *svc =3D vdata; + struct csched_unit *svc =3D vdata; =20 ASSERT(svc && is_idle_vcpu(svc->vcpu)); =20 @@ -653,7 +653,7 @@ csched_switch_sched(struct scheduler *new_ops, unsigned= int cpu, static inline void __csched_vcpu_check(struct vcpu *vc) { - struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); + struct csched_unit * const svc =3D CSCHED_UNIT(vc->sched_unit); struct csched_dom * const sdom =3D svc->sdom; =20 BUG_ON( svc->vcpu !=3D vc ); @@ -686,7 +686,7 @@ integer_param("vcpu_migration_delay", vcpu_migration_de= lay_us); =20 static inline bool __csched_vcpu_is_cache_hot(const struct csched_private *prv, - const struct csched_vcpu *svc) + const struct csched_unit *svc) { bool hot =3D prv->vcpu_migr_delay && (NOW() - svc->last_sched_time) < prv->vcpu_migr_delay; @@ -701,7 +701,7 @@ static inline int __csched_vcpu_is_migrateable(const struct csched_private *prv, struct vcpu= *vc, int dest_cpu, cpumask_t *mask) { - const struct csched_vcpu *svc =3D CSCHED_VCPU(vc); + const struct csched_unit *svc =3D CSCHED_UNIT(vc->sched_unit); /* * Don't pick up work that's hot on peer PCPU, or that can't (or * would prefer not to) run on cpu. @@ -857,7 +857,7 @@ static struct sched_resource * csched_res_pick(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched_vcpu *svc =3D CSCHED_VCPU(vc); + struct csched_unit *svc =3D CSCHED_UNIT(unit); =20 /* * We have been called by vcpu_migrate() (in schedule.c), as part @@ -871,7 +871,7 @@ csched_res_pick(const struct scheduler *ops, struct sch= ed_unit *unit) } =20 static inline void -__csched_vcpu_acct_start(struct csched_private *prv, struct csched_vcpu *s= vc) +__csched_vcpu_acct_start(struct csched_private *prv, struct csched_unit *s= vc) { struct csched_dom * const sdom =3D svc->sdom; unsigned long flags; @@ -901,7 +901,7 @@ __csched_vcpu_acct_start(struct csched_private *prv, st= ruct csched_vcpu *svc) =20 static inline void __csched_vcpu_acct_stop_locked(struct csched_private *prv, - struct csched_vcpu *svc) + struct csched_unit *svc) { struct csched_dom * const sdom =3D svc->sdom; =20 @@ -926,7 +926,7 @@ __csched_vcpu_acct_stop_locked(struct csched_private *p= rv, static void csched_vcpu_acct(struct csched_private *prv, unsigned int cpu) { - struct csched_vcpu * const svc =3D CSCHED_VCPU(current); + struct csched_unit * const svc =3D CSCHED_UNIT(current->sched_unit); const struct scheduler *ops =3D per_cpu(scheduler, cpu); =20 ASSERT( current->processor =3D=3D cpu ); @@ -995,10 +995,10 @@ csched_alloc_vdata(const struct scheduler *ops, struc= t sched_unit *unit, void *dd) { struct vcpu *vc =3D unit->vcpu_list; - struct csched_vcpu *svc; + struct csched_unit *svc; =20 /* Allocate per-VCPU info */ - svc =3D xzalloc(struct csched_vcpu); + svc =3D xzalloc(struct csched_unit); if ( svc =3D=3D NULL ) return NULL; =20 @@ -1017,7 +1017,7 @@ static void csched_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched_vcpu *svc =3D unit->priv; + struct csched_unit *svc =3D unit->priv; spinlock_t *lock; =20 BUG_ON( is_idle_vcpu(vc) ); @@ -1043,7 +1043,7 @@ csched_unit_insert(const struct scheduler *ops, struc= t sched_unit *unit) static void csched_free_vdata(const struct scheduler *ops, void *priv) { - struct csched_vcpu *svc =3D priv; + struct csched_unit *svc =3D priv; =20 BUG_ON( !list_empty(&svc->runq_elem) ); =20 @@ -1054,8 +1054,7 @@ static void csched_unit_remove(const struct scheduler *ops, struct sched_unit *unit) { struct csched_private *prv =3D CSCHED_PRIV(ops); - struct vcpu *vc =3D unit->vcpu_list; - struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); + struct csched_unit * const svc =3D CSCHED_UNIT(unit); struct csched_dom * const sdom =3D svc->sdom; =20 SCHED_STAT_CRANK(vcpu_remove); @@ -1082,14 +1081,14 @@ static void csched_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); + struct csched_unit * const svc =3D CSCHED_UNIT(unit); unsigned int cpu =3D vc->processor; =20 SCHED_STAT_CRANK(vcpu_sleep); =20 BUG_ON( is_idle_vcpu(vc) ); =20 - if ( curr_on_cpu(cpu) =3D=3D vc ) + if ( curr_on_cpu(cpu) =3D=3D unit ) { /* * We are about to tickle cpu, so we should clear its bit in idler= s. @@ -1107,12 +1106,12 @@ static void csched_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); + struct csched_unit * const svc =3D CSCHED_UNIT(unit); bool_t migrating; =20 BUG_ON( is_idle_vcpu(vc) ); =20 - if ( unlikely(curr_on_cpu(vc->processor) =3D=3D vc) ) + if ( unlikely(curr_on_cpu(vc->processor) =3D=3D unit) ) { SCHED_STAT_CRANK(vcpu_wake_running); return; @@ -1168,8 +1167,7 @@ csched_unit_wake(const struct scheduler *ops, struct = sched_unit *unit) static void csched_unit_yield(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; - struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); + struct csched_unit * const svc =3D CSCHED_UNIT(unit); =20 /* Let the scheduler know that this vcpu is trying to yield */ set_bit(CSCHED_FLAG_VCPU_YIELD, &svc->flags); @@ -1224,8 +1222,7 @@ static void csched_aff_cntl(const struct scheduler *ops, struct sched_unit *unit, const cpumask_t *hard, const cpumask_t *soft) { - struct vcpu *v =3D unit->vcpu_list; - struct csched_vcpu *svc =3D CSCHED_VCPU(v); + struct csched_unit *svc =3D CSCHED_UNIT(unit); =20 if ( !hard ) return; @@ -1328,7 +1325,7 @@ csched_runq_sort(struct csched_private *prv, unsigned= int cpu) { struct csched_pcpu * const spc =3D CSCHED_PCPU(cpu); struct list_head *runq, *elem, *next, *last_under; - struct csched_vcpu *svc_elem; + struct csched_unit *svc_elem; spinlock_t *lock; unsigned long flags; int sort_epoch; @@ -1374,7 +1371,7 @@ csched_acct(void* dummy) unsigned long flags; struct list_head *iter_vcpu, *next_vcpu; struct list_head *iter_sdom, *next_sdom; - struct csched_vcpu *svc; + struct csched_unit *svc; struct csched_dom *sdom; uint32_t credit_total; uint32_t weight_total; @@ -1497,7 +1494,7 @@ csched_acct(void* dummy) =20 list_for_each_safe( iter_vcpu, next_vcpu, &sdom->active_vcpu ) { - svc =3D list_entry(iter_vcpu, struct csched_vcpu, active_vcpu_= elem); + svc =3D list_entry(iter_vcpu, struct csched_unit, active_vcpu_= elem); BUG_ON( sdom !=3D svc->sdom ); =20 /* Increment credit */ @@ -1601,12 +1598,12 @@ csched_tick(void *_cpu) set_timer(&spc->ticker, NOW() + MICROSECS(prv->tick_period_us) ); } =20 -static struct csched_vcpu * +static struct csched_unit * csched_runq_steal(int peer_cpu, int cpu, int pri, int balance_step) { const struct csched_private * const prv =3D CSCHED_PRIV(per_cpu(schedu= ler, cpu)); const struct csched_pcpu * const peer_pcpu =3D CSCHED_PCPU(peer_cpu); - struct csched_vcpu *speer; + struct csched_unit *speer; struct list_head *iter; struct vcpu *vc; =20 @@ -1616,7 +1613,7 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, int= balance_step) * Don't steal from an idle CPU's runq because it's about to * pick up work from it itself. */ - if ( unlikely(is_idle_vcpu(curr_on_cpu(peer_cpu))) ) + if ( unlikely(is_idle_vcpu(curr_on_cpu(peer_cpu)->vcpu_list)) ) goto out; =20 list_for_each( iter, &peer_pcpu->runq ) @@ -1678,12 +1675,12 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, i= nt balance_step) return NULL; } =20 -static struct csched_vcpu * +static struct csched_unit * csched_load_balance(struct csched_private *prv, int cpu, - struct csched_vcpu *snext, bool_t *stolen) + struct csched_unit *snext, bool_t *stolen) { struct cpupool *c =3D per_cpu(cpupool, cpu); - struct csched_vcpu *speer; + struct csched_unit *speer; cpumask_t workers; cpumask_t *online; int peer_cpu, first_cpu, peer_node, bstep; @@ -1832,9 +1829,9 @@ csched_schedule( { const int cpu =3D smp_processor_id(); struct list_head * const runq =3D RUNQ(cpu); - struct csched_vcpu * const scurr =3D CSCHED_VCPU(current); + struct csched_unit * const scurr =3D CSCHED_UNIT(current->sched_unit); struct csched_private *prv =3D CSCHED_PRIV(ops); - struct csched_vcpu *snext; + struct csched_unit *snext; struct task_slice ret; s_time_t runtime, tslice; =20 @@ -1951,7 +1948,7 @@ csched_schedule( if ( tasklet_work_scheduled ) { TRACE_0D(TRC_CSCHED_SCHED_TASKLET); - snext =3D CSCHED_VCPU(idle_vcpu[cpu]); + snext =3D CSCHED_UNIT(idle_vcpu[cpu]->sched_unit); snext->pri =3D CSCHED_PRI_TS_BOOST; } =20 @@ -2003,7 +2000,7 @@ out: } =20 static void -csched_dump_vcpu(struct csched_vcpu *svc) +csched_dump_vcpu(struct csched_unit *svc) { struct csched_dom * const sdom =3D svc->sdom; =20 @@ -2039,7 +2036,7 @@ csched_dump_pcpu(const struct scheduler *ops, int cpu) struct list_head *runq, *iter; struct csched_private *prv =3D CSCHED_PRIV(ops); struct csched_pcpu *spc; - struct csched_vcpu *svc; + struct csched_unit *svc; spinlock_t *lock; unsigned long flags; int loop; @@ -2063,7 +2060,7 @@ csched_dump_pcpu(const struct scheduler *ops, int cpu) CPUMASK_PR(per_cpu(cpu_core_mask, cpu))); =20 /* current VCPU (nothing to say if that's the idle vcpu). */ - svc =3D CSCHED_VCPU(curr_on_cpu(cpu)); + svc =3D CSCHED_UNIT(curr_on_cpu(cpu)); if ( svc && !is_idle_vcpu(svc->vcpu) ) { printk("\trun: "); @@ -2132,10 +2129,10 @@ csched_dump(const struct scheduler *ops) =20 list_for_each( iter_svc, &sdom->active_vcpu ) { - struct csched_vcpu *svc; + struct csched_unit *svc; spinlock_t *lock; =20 - svc =3D list_entry(iter_svc, struct csched_vcpu, active_vcpu_e= lem); + svc =3D list_entry(iter_svc, struct csched_unit, active_vcpu_e= lem); lock =3D vcpu_schedule_lock(svc->vcpu); =20 printk("\t%3d: ", ++loop); diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 4df0afeb02..f856293371 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -176,7 +176,7 @@ * load balancing; * + serializes runqueue operations (removing and inserting vcpus); * + protects runqueue-wide data in csched2_runqueue_data; - * + protects vcpu parameters in csched2_vcpu for the vcpu in the + * + protects vcpu parameters in csched2_unit for the vcpu in the * runqueue. * * - Private scheduler lock @@ -512,7 +512,7 @@ struct csched2_pcpu { /* * Virtual CPU */ -struct csched2_vcpu { +struct csched2_unit { struct csched2_dom *sdom; /* Up-pointer to domain = */ struct vcpu *vcpu; /* Up-pointer, to vcpu = */ struct csched2_runqueue_data *rqd; /* Up-pointer to the runqueue = */ @@ -571,9 +571,9 @@ static inline struct csched2_pcpu *csched2_pcpu(unsigne= d int cpu) return per_cpu(schedule_data, cpu).sched_priv; } =20 -static inline struct csched2_vcpu *csched2_vcpu(const struct vcpu *v) +static inline struct csched2_unit *csched2_unit(const struct sched_unit *u= nit) { - return v->sched_unit->priv; + return unit->priv; } =20 static inline struct csched2_dom *csched2_dom(const struct domain *d) @@ -595,7 +595,7 @@ static inline struct csched2_runqueue_data *c2rqd(const= struct scheduler *ops, } =20 /* Does the domain of this vCPU have a cap? */ -static inline bool has_cap(const struct csched2_vcpu *svc) +static inline bool has_cap(const struct csched2_unit *svc) { return svc->budget !=3D STIME_MAX; } @@ -689,7 +689,7 @@ void smt_idle_mask_clear(unsigned int cpu, cpumask_t *m= ask) * Of course, 1, 2 and 3 makes sense only if svc has a soft affinity. Also * note that at least 5 is guaranteed to _always_ return at least one pcpu. */ -static int get_fallback_cpu(struct csched2_vcpu *svc) +static int get_fallback_cpu(struct csched2_unit *svc) { struct vcpu *v =3D svc->vcpu; unsigned int bs; @@ -774,7 +774,7 @@ static int get_fallback_cpu(struct csched2_vcpu *svc) * FIXME: Do pre-calculated division? */ static void t2c_update(struct csched2_runqueue_data *rqd, s_time_t time, - struct csched2_vcpu *svc) + struct csched2_unit *svc) { uint64_t val =3D time * rqd->max_weight + svc->residual; =20 @@ -782,7 +782,7 @@ static void t2c_update(struct csched2_runqueue_data *rq= d, s_time_t time, svc->credit -=3D val; } =20 -static s_time_t c2t(struct csched2_runqueue_data *rqd, s_time_t credit, st= ruct csched2_vcpu *svc) +static s_time_t c2t(struct csched2_runqueue_data *rqd, s_time_t credit, st= ruct csched2_unit *svc) { return credit * svc->weight / rqd->max_weight; } @@ -791,14 +791,14 @@ static s_time_t c2t(struct csched2_runqueue_data *rqd= , s_time_t credit, struct c * Runqueue related code. */ =20 -static inline int vcpu_on_runq(struct csched2_vcpu *svc) +static inline int vcpu_on_runq(struct csched2_unit *svc) { return !list_empty(&svc->runq_elem); } =20 -static inline struct csched2_vcpu * runq_elem(struct list_head *elem) +static inline struct csched2_unit * runq_elem(struct list_head *elem) { - return list_entry(elem, struct csched2_vcpu, runq_elem); + return list_entry(elem, struct csched2_unit, runq_elem); } =20 static void activate_runqueue(struct csched2_private *prv, int rqi) @@ -916,7 +916,7 @@ static void update_max_weight(struct csched2_runqueue_d= ata *rqd, int new_weight, =20 list_for_each( iter, &rqd->svc ) { - struct csched2_vcpu * svc =3D list_entry(iter, struct csched2_= vcpu, rqd_elem); + struct csched2_unit * svc =3D list_entry(iter, struct csched2_= unit, rqd_elem); =20 if ( svc->weight > max_weight ) max_weight =3D svc->weight; @@ -941,7 +941,7 @@ static void update_max_weight(struct csched2_runqueue_d= ata *rqd, int new_weight, =20 /* Add and remove from runqueue assignment (not active run queue) */ static void -_runq_assign(struct csched2_vcpu *svc, struct csched2_runqueue_data *rqd) +_runq_assign(struct csched2_unit *svc, struct csched2_runqueue_data *rqd) { =20 svc->rqd =3D rqd; @@ -971,7 +971,7 @@ _runq_assign(struct csched2_vcpu *svc, struct csched2_r= unqueue_data *rqd) static void runq_assign(const struct scheduler *ops, struct vcpu *vc) { - struct csched2_vcpu *svc =3D vc->sched_unit->priv; + struct csched2_unit *svc =3D vc->sched_unit->priv; =20 ASSERT(svc->rqd =3D=3D NULL); =20 @@ -979,7 +979,7 @@ runq_assign(const struct scheduler *ops, struct vcpu *v= c) } =20 static void -_runq_deassign(struct csched2_vcpu *svc) +_runq_deassign(struct csched2_unit *svc) { struct csched2_runqueue_data *rqd =3D svc->rqd; =20 @@ -998,7 +998,7 @@ _runq_deassign(struct csched2_vcpu *svc) static void runq_deassign(const struct scheduler *ops, struct vcpu *vc) { - struct csched2_vcpu *svc =3D vc->sched_unit->priv; + struct csched2_unit *svc =3D vc->sched_unit->priv; =20 ASSERT(svc->rqd =3D=3D c2rqd(ops, vc->processor)); =20 @@ -1200,7 +1200,7 @@ update_runq_load(const struct scheduler *ops, =20 static void update_svc_load(const struct scheduler *ops, - struct csched2_vcpu *svc, int change, s_time_t now) + struct csched2_unit *svc, int change, s_time_t now) { struct csched2_private *prv =3D csched2_priv(ops); s_time_t delta, vcpu_load; @@ -1260,7 +1260,7 @@ update_svc_load(const struct scheduler *ops, static void update_load(const struct scheduler *ops, struct csched2_runqueue_data *rqd, - struct csched2_vcpu *svc, int change, s_time_t now) + struct csched2_unit *svc, int change, s_time_t now) { trace_var(TRC_CSCHED2_UPDATE_LOAD, 1, 0, NULL); =20 @@ -1270,7 +1270,7 @@ update_load(const struct scheduler *ops, } =20 static void -runq_insert(const struct scheduler *ops, struct csched2_vcpu *svc) +runq_insert(const struct scheduler *ops, struct csched2_unit *svc) { struct list_head *iter; unsigned int cpu =3D svc->vcpu->processor; @@ -1289,7 +1289,7 @@ runq_insert(const struct scheduler *ops, struct csche= d2_vcpu *svc) =20 list_for_each( iter, runq ) { - struct csched2_vcpu * iter_svc =3D runq_elem(iter); + struct csched2_unit * iter_svc =3D runq_elem(iter); =20 if ( svc->credit > iter_svc->credit ) break; @@ -1313,13 +1313,13 @@ runq_insert(const struct scheduler *ops, struct csc= hed2_vcpu *svc) } } =20 -static inline void runq_remove(struct csched2_vcpu *svc) +static inline void runq_remove(struct csched2_unit *svc) { ASSERT(vcpu_on_runq(svc)); list_del_init(&svc->runq_elem); } =20 -void burn_credits(struct csched2_runqueue_data *rqd, struct csched2_vcpu *= , s_time_t); +void burn_credits(struct csched2_runqueue_data *rqd, struct csched2_unit *= , s_time_t); =20 static inline void tickle_cpu(unsigned int cpu, struct csched2_runqueue_data *rqd) @@ -1335,7 +1335,7 @@ tickle_cpu(unsigned int cpu, struct csched2_runqueue_= data *rqd) * whether or not it already run for more than the ratelimit, to which we * apply some tolerance). */ -static inline bool is_preemptable(const struct csched2_vcpu *svc, +static inline bool is_preemptable(const struct csched2_unit *svc, s_time_t now, s_time_t ratelimit) { if ( ratelimit <=3D CSCHED2_RATELIMIT_TICKLE_TOLERANCE ) @@ -1361,10 +1361,10 @@ static inline bool is_preemptable(const struct csch= ed2_vcpu *svc, * Within the same class, the highest difference of credit. */ static s_time_t tickle_score(const struct scheduler *ops, s_time_t now, - struct csched2_vcpu *new, unsigned int cpu) + struct csched2_unit *new, unsigned int cpu) { struct csched2_runqueue_data *rqd =3D c2rqd(ops, cpu); - struct csched2_vcpu * cur =3D csched2_vcpu(curr_on_cpu(cpu)); + struct csched2_unit * cur =3D csched2_unit(curr_on_cpu(cpu)); struct csched2_private *prv =3D csched2_priv(ops); s_time_t score; =20 @@ -1433,7 +1433,7 @@ static s_time_t tickle_score(const struct scheduler *= ops, s_time_t now, * pick up some work, so it would be wrong to consider it idle. */ static void -runq_tickle(const struct scheduler *ops, struct csched2_vcpu *new, s_time_= t now) +runq_tickle(const struct scheduler *ops, struct csched2_unit *new, s_time_= t now) { int i, ipid =3D -1; s_time_t max =3D 0; @@ -1588,7 +1588,7 @@ runq_tickle(const struct scheduler *ops, struct csche= d2_vcpu *new, s_time_t now) return; } =20 - ASSERT(!is_idle_vcpu(curr_on_cpu(ipid))); + ASSERT(!is_idle_vcpu(curr_on_cpu(ipid)->vcpu_list)); SCHED_STAT_CRANK(tickled_busy_cpu); tickle: BUG_ON(ipid =3D=3D -1); @@ -1615,7 +1615,7 @@ runq_tickle(const struct scheduler *ops, struct csche= d2_vcpu *new, s_time_t now) * Credit-related code */ static void reset_credit(const struct scheduler *ops, int cpu, s_time_t no= w, - struct csched2_vcpu *snext) + struct csched2_unit *snext) { struct csched2_runqueue_data *rqd =3D c2rqd(ops, cpu); struct list_head *iter; @@ -1645,10 +1645,10 @@ static void reset_credit(const struct scheduler *op= s, int cpu, s_time_t now, list_for_each( iter, &rqd->svc ) { unsigned int svc_cpu; - struct csched2_vcpu * svc; + struct csched2_unit * svc; int start_credit; =20 - svc =3D list_entry(iter, struct csched2_vcpu, rqd_elem); + svc =3D list_entry(iter, struct csched2_unit, rqd_elem); svc_cpu =3D svc->vcpu->processor; =20 ASSERT(!is_idle_vcpu(svc->vcpu)); @@ -1658,7 +1658,7 @@ static void reset_credit(const struct scheduler *ops,= int cpu, s_time_t now, * If svc is running, it is our responsibility to make sure, here, * that the credit it has spent so far get accounted. */ - if ( svc->vcpu =3D=3D curr_on_cpu(svc_cpu) ) + if ( svc->vcpu =3D=3D curr_on_cpu(svc_cpu)->vcpu_list ) { burn_credits(rqd, svc, now); /* @@ -1710,11 +1710,11 @@ static void reset_credit(const struct scheduler *op= s, int cpu, s_time_t now, } =20 void burn_credits(struct csched2_runqueue_data *rqd, - struct csched2_vcpu *svc, s_time_t now) + struct csched2_unit *svc, s_time_t now) { s_time_t delta; =20 - ASSERT(svc =3D=3D csched2_vcpu(curr_on_cpu(svc->vcpu->processor))); + ASSERT(svc =3D=3D csched2_unit(curr_on_cpu(svc->vcpu->processor))); =20 if ( unlikely(is_idle_vcpu(svc->vcpu)) ) { @@ -1764,7 +1764,7 @@ void burn_credits(struct csched2_runqueue_data *rqd, * Budget-related code. */ =20 -static void park_vcpu(struct csched2_vcpu *svc) +static void park_vcpu(struct csched2_unit *svc) { struct vcpu *v =3D svc->vcpu; =20 @@ -1793,7 +1793,7 @@ static void park_vcpu(struct csched2_vcpu *svc) list_add(&svc->parked_elem, &svc->sdom->parked_vcpus); } =20 -static bool vcpu_grab_budget(struct csched2_vcpu *svc) +static bool vcpu_grab_budget(struct csched2_unit *svc) { struct csched2_dom *sdom =3D svc->sdom; unsigned int cpu =3D svc->vcpu->processor; @@ -1840,7 +1840,7 @@ static bool vcpu_grab_budget(struct csched2_vcpu *svc) } =20 static void -vcpu_return_budget(struct csched2_vcpu *svc, struct list_head *parked) +vcpu_return_budget(struct csched2_unit *svc, struct list_head *parked) { struct csched2_dom *sdom =3D svc->sdom; unsigned int cpu =3D svc->vcpu->processor; @@ -1883,7 +1883,7 @@ vcpu_return_budget(struct csched2_vcpu *svc, struct l= ist_head *parked) static void unpark_parked_vcpus(const struct scheduler *ops, struct list_head *vcpus) { - struct csched2_vcpu *svc, *tmp; + struct csched2_unit *svc, *tmp; spinlock_t *lock; =20 list_for_each_entry_safe(svc, tmp, vcpus, parked_elem) @@ -2005,7 +2005,7 @@ static void replenish_domain_budget(void* data) static inline void csched2_vcpu_check(struct vcpu *vc) { - struct csched2_vcpu * const svc =3D csched2_vcpu(vc); + struct csched2_unit * const svc =3D csched2_unit(vc->sched_unit); struct csched2_dom * const sdom =3D svc->sdom; =20 BUG_ON( svc->vcpu !=3D vc ); @@ -2031,10 +2031,10 @@ csched2_alloc_vdata(const struct scheduler *ops, st= ruct sched_unit *unit, void *dd) { struct vcpu *vc =3D unit->vcpu_list; - struct csched2_vcpu *svc; + struct csched2_unit *svc; =20 /* Allocate per-VCPU info */ - svc =3D xzalloc(struct csched2_vcpu); + svc =3D xzalloc(struct csched2_unit); if ( svc =3D=3D NULL ) return NULL; =20 @@ -2075,12 +2075,12 @@ static void csched2_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched2_vcpu * const svc =3D csched2_vcpu(vc); + struct csched2_unit * const svc =3D csched2_unit(unit); =20 ASSERT(!is_idle_vcpu(vc)); SCHED_STAT_CRANK(vcpu_sleep); =20 - if ( curr_on_cpu(vc->processor) =3D=3D vc ) + if ( curr_on_cpu(vc->processor) =3D=3D unit ) { tickle_cpu(vc->processor, svc->rqd); } @@ -2098,7 +2098,7 @@ static void csched2_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched2_vcpu * const svc =3D csched2_vcpu(vc); + struct csched2_unit * const svc =3D csched2_unit(unit); unsigned int cpu =3D vc->processor; s_time_t now; =20 @@ -2106,7 +2106,7 @@ csched2_unit_wake(const struct scheduler *ops, struct= sched_unit *unit) =20 ASSERT(!is_idle_vcpu(vc)); =20 - if ( unlikely(curr_on_cpu(cpu) =3D=3D vc) ) + if ( unlikely(curr_on_cpu(cpu) =3D=3D unit) ) { SCHED_STAT_CRANK(vcpu_wake_running); goto out; @@ -2153,8 +2153,7 @@ out: static void csched2_unit_yield(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *v =3D unit->vcpu_list; - struct csched2_vcpu * const svc =3D csched2_vcpu(v); + struct csched2_unit * const svc =3D csched2_unit(unit); =20 __set_bit(__CSFLAG_vcpu_yield, &svc->flags); } @@ -2163,7 +2162,7 @@ static void csched2_context_saved(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched2_vcpu * const svc =3D csched2_vcpu(vc); + struct csched2_unit * const svc =3D csched2_unit(unit); spinlock_t *lock =3D vcpu_schedule_lock_irq(vc); s_time_t now =3D NOW(); LIST_HEAD(were_parked); @@ -2209,7 +2208,7 @@ csched2_res_pick(const struct scheduler *ops, struct = sched_unit *unit) struct vcpu *vc =3D unit->vcpu_list; int i, min_rqi =3D -1, min_s_rqi =3D -1; unsigned int new_cpu, cpu =3D vc->processor; - struct csched2_vcpu *svc =3D csched2_vcpu(vc); + struct csched2_unit *svc =3D csched2_unit(unit); s_time_t min_avgload =3D MAX_LOAD, min_s_avgload =3D MAX_LOAD; bool has_soft; =20 @@ -2431,15 +2430,15 @@ csched2_res_pick(const struct scheduler *ops, struc= t sched_unit *unit) typedef struct { /* NB: Modified by consider() */ s_time_t load_delta; - struct csched2_vcpu * best_push_svc, *best_pull_svc; + struct csched2_unit * best_push_svc, *best_pull_svc; /* NB: Read by consider() */ struct csched2_runqueue_data *lrqd; struct csched2_runqueue_data *orqd; =20 } balance_state_t; =20 static void consider(balance_state_t *st,=20 - struct csched2_vcpu *push_svc, - struct csched2_vcpu *pull_svc) + struct csched2_unit *push_svc, + struct csched2_unit *pull_svc) { s_time_t l_load, o_load, delta; =20 @@ -2472,8 +2471,8 @@ static void consider(balance_state_t *st, =20 =20 static void migrate(const struct scheduler *ops, - struct csched2_vcpu *svc,=20 - struct csched2_runqueue_data *trqd,=20 + struct csched2_unit *svc, + struct csched2_runqueue_data *trqd, s_time_t now) { int cpu =3D svc->vcpu->processor; @@ -2542,7 +2541,7 @@ static void migrate(const struct scheduler *ops, * - svc is not already flagged to migrate, * - if svc is allowed to run on at least one of the pcpus of rqd. */ -static bool vcpu_is_migrateable(struct csched2_vcpu *svc, +static bool vcpu_is_migrateable(struct csched2_unit *svc, struct csched2_runqueue_data *rqd) { struct vcpu *v =3D svc->vcpu; @@ -2692,7 +2691,7 @@ retry: /* Reuse load delta (as we're trying to minimize it) */ list_for_each( push_iter, &st.lrqd->svc ) { - struct csched2_vcpu * push_svc =3D list_entry(push_iter, struct cs= ched2_vcpu, rqd_elem); + struct csched2_unit * push_svc =3D list_entry(push_iter, struct cs= ched2_unit, rqd_elem); =20 update_svc_load(ops, push_svc, 0, now); =20 @@ -2701,7 +2700,7 @@ retry: =20 list_for_each( pull_iter, &st.orqd->svc ) { - struct csched2_vcpu * pull_svc =3D list_entry(pull_iter, struc= t csched2_vcpu, rqd_elem); + struct csched2_unit * pull_svc =3D list_entry(pull_iter, struc= t csched2_unit, rqd_elem); =20 if ( !inner_load_updated ) update_svc_load(ops, pull_svc, 0, now); @@ -2720,7 +2719,7 @@ retry: =20 list_for_each( pull_iter, &st.orqd->svc ) { - struct csched2_vcpu * pull_svc =3D list_entry(pull_iter, struct cs= ched2_vcpu, rqd_elem); + struct csched2_unit * pull_svc =3D list_entry(pull_iter, struct cs= ched2_unit, rqd_elem); =20 if ( !vcpu_is_migrateable(pull_svc, st.lrqd) ) continue; @@ -2747,7 +2746,7 @@ csched2_unit_migrate( { struct vcpu *vc =3D unit->vcpu_list; struct domain *d =3D vc->domain; - struct csched2_vcpu * const svc =3D csched2_vcpu(vc); + struct csched2_unit * const svc =3D csched2_unit(unit); struct csched2_runqueue_data *trqd; s_time_t now =3D NOW(); =20 @@ -2848,7 +2847,7 @@ csched2_dom_cntl( /* Update weights for vcpus, and max_weight for runqueues on w= hich they reside */ for_each_vcpu ( d, v ) { - struct csched2_vcpu *svc =3D csched2_vcpu(v); + struct csched2_unit *svc =3D csched2_unit(v->sched_unit); spinlock_t *lock =3D vcpu_schedule_lock(svc->vcpu); =20 ASSERT(svc->rqd =3D=3D c2rqd(ops, svc->vcpu->processor)); @@ -2862,7 +2861,7 @@ csched2_dom_cntl( /* Cap */ if ( op->u.credit2.cap !=3D 0 ) { - struct csched2_vcpu *svc; + struct csched2_unit *svc; spinlock_t *lock; =20 /* Cap is only valid if it's below 100 * nr_of_vCPUS */ @@ -2886,7 +2885,7 @@ csched2_dom_cntl( */ for_each_vcpu ( d, v ) { - svc =3D csched2_vcpu(v); + svc =3D csched2_unit(v->sched_unit); lock =3D vcpu_schedule_lock(svc->vcpu); /* * Too small quotas would in theory cause a lot of overhea= d, @@ -2929,14 +2928,14 @@ csched2_dom_cntl( */ for_each_vcpu ( d, v ) { - svc =3D csched2_vcpu(v); + svc =3D csched2_unit(v->sched_unit); lock =3D vcpu_schedule_lock(svc->vcpu); if ( v->is_running ) { unsigned int cpu =3D v->processor; struct csched2_runqueue_data *rqd =3D c2rqd(ops, c= pu); =20 - ASSERT(curr_on_cpu(cpu) =3D=3D v); + ASSERT(curr_on_cpu(cpu)->vcpu_list =3D=3D v); =20 /* * We are triggering a reschedule on the vCPU's @@ -2976,7 +2975,7 @@ csched2_dom_cntl( /* Disable budget accounting for all the vCPUs. */ for_each_vcpu ( d, v ) { - struct csched2_vcpu *svc =3D csched2_vcpu(v); + struct csched2_unit *svc =3D csched2_unit(v->sched_unit); spinlock_t *lock =3D vcpu_schedule_lock(svc->vcpu); =20 svc->budget =3D STIME_MAX; @@ -3013,8 +3012,7 @@ static void csched2_aff_cntl(const struct scheduler *ops, struct sched_unit *unit, const cpumask_t *hard, const cpumask_t *soft) { - struct vcpu *v =3D unit->vcpu_list; - struct csched2_vcpu *svc =3D csched2_vcpu(v); + struct csched2_unit *svc =3D csched2_unit(unit); =20 if ( !hard ) return; @@ -3114,7 +3112,7 @@ static void csched2_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched2_vcpu *svc =3D unit->priv; + struct csched2_unit *svc =3D unit->priv; struct csched2_dom * const sdom =3D svc->sdom; spinlock_t *lock; =20 @@ -3146,7 +3144,7 @@ csched2_unit_insert(const struct scheduler *ops, stru= ct sched_unit *unit) static void csched2_free_vdata(const struct scheduler *ops, void *priv) { - struct csched2_vcpu *svc =3D priv; + struct csched2_unit *svc =3D priv; =20 xfree(svc); } @@ -3155,7 +3153,7 @@ static void csched2_unit_remove(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct csched2_vcpu * const svc =3D csched2_vcpu(vc); + struct csched2_unit * const svc =3D csched2_unit(unit); spinlock_t *lock; =20 ASSERT(!is_idle_vcpu(vc)); @@ -3176,7 +3174,7 @@ csched2_unit_remove(const struct scheduler *ops, stru= ct sched_unit *unit) /* How long should we let this vcpu run for? */ static s_time_t csched2_runtime(const struct scheduler *ops, int cpu, - struct csched2_vcpu *snext, s_time_t now) + struct csched2_unit *snext, s_time_t now) { s_time_t time, min_time; int rt_credit; /* Proposed runtime measured in credits */ @@ -3221,7 +3219,7 @@ csched2_runtime(const struct scheduler *ops, int cpu, */ if ( ! list_empty(runq) ) { - struct csched2_vcpu *swait =3D runq_elem(runq->next); + struct csched2_unit *swait =3D runq_elem(runq->next); =20 if ( ! is_idle_vcpu(swait->vcpu) && swait->credit > 0 ) @@ -3272,14 +3270,14 @@ csched2_runtime(const struct scheduler *ops, int cp= u, /* * Find a candidate. */ -static struct csched2_vcpu * +static struct csched2_unit * runq_candidate(struct csched2_runqueue_data *rqd, - struct csched2_vcpu *scurr, + struct csched2_unit *scurr, int cpu, s_time_t now, unsigned int *skipped) { struct list_head *iter, *temp; - struct csched2_vcpu *snext =3D NULL; + struct csched2_unit *snext =3D NULL; struct csched2_private *prv =3D csched2_priv(per_cpu(scheduler, cpu)); bool yield =3D false, soft_aff_preempt =3D false; =20 @@ -3360,12 +3358,12 @@ runq_candidate(struct csched2_runqueue_data *rqd, if ( vcpu_runnable(scurr->vcpu) && !soft_aff_preempt ) snext =3D scurr; else - snext =3D csched2_vcpu(idle_vcpu[cpu]); + snext =3D csched2_unit(idle_vcpu[cpu]->sched_unit); =20 check_runq: list_for_each_safe( iter, temp, &rqd->runq ) { - struct csched2_vcpu * svc =3D list_entry(iter, struct csched2_vcpu= , runq_elem); + struct csched2_unit * svc =3D list_entry(iter, struct csched2_unit= , runq_elem); =20 if ( unlikely(tb_init_done) ) { @@ -3464,8 +3462,8 @@ csched2_schedule( { const int cpu =3D smp_processor_id(); struct csched2_runqueue_data *rqd; - struct csched2_vcpu * const scurr =3D csched2_vcpu(current); - struct csched2_vcpu *snext =3D NULL; + struct csched2_unit * const scurr =3D csched2_unit(current->sched_unit= ); + struct csched2_unit *snext =3D NULL; unsigned int skipped_vcpus =3D 0; struct task_slice ret; bool tickled; @@ -3541,7 +3539,7 @@ csched2_schedule( { __clear_bit(__CSFLAG_vcpu_yield, &scurr->flags); trace_var(TRC_CSCHED2_SCHED_TASKLET, 1, 0, NULL); - snext =3D csched2_vcpu(idle_vcpu[cpu]); + snext =3D csched2_unit(idle_vcpu[cpu]->sched_unit); } else snext =3D runq_candidate(rqd, scurr, cpu, now, &skipped_vcpus); @@ -3644,7 +3642,7 @@ csched2_schedule( } =20 static void -csched2_dump_vcpu(struct csched2_private *prv, struct csched2_vcpu *svc) +csched2_dump_vcpu(struct csched2_private *prv, struct csched2_unit *svc) { printk("[%i.%i] flags=3D%x cpu=3D%i", svc->vcpu->domain->domain_id, @@ -3668,7 +3666,7 @@ static inline void dump_pcpu(const struct scheduler *ops, int cpu) { struct csched2_private *prv =3D csched2_priv(ops); - struct csched2_vcpu *svc; + struct csched2_unit *svc; =20 printk("CPU[%02d] runq=3D%d, sibling=3D%*pb, core=3D%*pb\n", cpu, c2r(cpu), @@ -3676,7 +3674,7 @@ dump_pcpu(const struct scheduler *ops, int cpu) CPUMASK_PR(per_cpu(cpu_core_mask, cpu))); =20 /* current VCPU (nothing to say if that's the idle vcpu) */ - svc =3D csched2_vcpu(curr_on_cpu(cpu)); + svc =3D csched2_unit(curr_on_cpu(cpu)); if ( svc && !is_idle_vcpu(svc->vcpu) ) { printk("\trun: "); @@ -3749,7 +3747,7 @@ csched2_dump(const struct scheduler *ops) =20 for_each_vcpu( sdom->dom, v ) { - struct csched2_vcpu * const svc =3D csched2_vcpu(v); + struct csched2_unit * const svc =3D csched2_unit(v->sched_unit= ); spinlock_t *lock; =20 lock =3D vcpu_schedule_lock(svc->vcpu); @@ -3778,7 +3776,7 @@ csched2_dump(const struct scheduler *ops) printk("RUNQ:\n"); list_for_each( iter, runq ) { - struct csched2_vcpu *svc =3D runq_elem(iter); + struct csched2_unit *svc =3D runq_elem(iter); =20 if ( svc ) { @@ -3882,7 +3880,7 @@ csched2_switch_sched(struct scheduler *new_ops, unsig= ned int cpu, void *pdata, void *vdata) { struct csched2_private *prv =3D csched2_priv(new_ops); - struct csched2_vcpu *svc =3D vdata; + struct csched2_unit *svc =3D vdata; unsigned rqi; =20 ASSERT(pdata && svc && is_idle_vcpu(svc->vcpu)); diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index dd961bc3ca..4dc0356f80 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -93,7 +93,7 @@ DEFINE_PER_CPU(struct null_pcpu, npc); /* * Virtual CPU */ -struct null_vcpu { +struct null_unit { struct list_head waitq_elem; struct vcpu *vcpu; }; @@ -114,9 +114,9 @@ static inline struct null_private *null_priv(const stru= ct scheduler *ops) return ops->sched_data; } =20 -static inline struct null_vcpu *null_vcpu(const struct vcpu *v) +static inline struct null_unit *null_unit(const struct sched_unit *unit) { - return v->sched_unit->priv; + return unit->priv; } =20 static inline bool vcpu_check_affinity(struct vcpu *v, unsigned int cpu, @@ -189,9 +189,9 @@ static void *null_alloc_vdata(const struct scheduler *o= ps, struct sched_unit *unit, void *dd) { struct vcpu *v =3D unit->vcpu_list; - struct null_vcpu *nvc; + struct null_unit *nvc; =20 - nvc =3D xzalloc(struct null_vcpu); + nvc =3D xzalloc(struct null_unit); if ( nvc =3D=3D NULL ) return NULL; =20 @@ -205,7 +205,7 @@ static void *null_alloc_vdata(const struct scheduler *o= ps, =20 static void null_free_vdata(const struct scheduler *ops, void *priv) { - struct null_vcpu *nvc =3D priv; + struct null_unit *nvc =3D priv; =20 xfree(nvc); } @@ -362,9 +362,9 @@ static bool vcpu_deassign(struct null_private *prv, str= uct vcpu *v) { unsigned int bs; unsigned int cpu =3D v->processor; - struct null_vcpu *wvc; + struct null_unit *wvc; =20 - ASSERT(list_empty(&null_vcpu(v)->waitq_elem)); + ASSERT(list_empty(&null_unit(v->sched_unit)->waitq_elem)); ASSERT(per_cpu(npc, v->processor).vcpu =3D=3D v); ASSERT(!cpumask_test_cpu(v->processor, &prv->cpus_free)); =20 @@ -421,7 +421,7 @@ static spinlock_t *null_switch_sched(struct scheduler *= new_ops, { struct schedule_data *sd =3D &per_cpu(schedule_data, cpu); struct null_private *prv =3D null_priv(new_ops); - struct null_vcpu *nvc =3D vdata; + struct null_unit *nvc =3D vdata; =20 ASSERT(nvc && is_idle_vcpu(nvc->vcpu)); =20 @@ -444,7 +444,7 @@ static void null_unit_insert(const struct scheduler *op= s, { struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); - struct null_vcpu *nvc =3D null_vcpu(v); + struct null_unit *nvc =3D null_unit(unit); unsigned int cpu; spinlock_t *lock; =20 @@ -508,7 +508,7 @@ static void null_unit_remove(const struct scheduler *op= s, { struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); - struct null_vcpu *nvc =3D null_vcpu(v); + struct null_unit *nvc =3D null_unit(unit); spinlock_t *lock; =20 ASSERT(!is_idle_vcpu(v)); @@ -546,12 +546,12 @@ static void null_unit_wake(const struct scheduler *op= s, { struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); - struct null_vcpu *nvc =3D null_vcpu(v); + struct null_unit *nvc =3D null_unit(unit); unsigned int cpu =3D v->processor; =20 ASSERT(!is_idle_vcpu(v)); =20 - if ( unlikely(curr_on_cpu(cpu) =3D=3D v) ) + if ( unlikely(curr_on_cpu(cpu) =3D=3D unit) ) { SCHED_STAT_CRANK(vcpu_wake_running); return; @@ -631,7 +631,7 @@ static void null_unit_sleep(const struct scheduler *ops, */ if ( unlikely(!is_vcpu_online(v)) ) { - struct null_vcpu *nvc =3D null_vcpu(v); + struct null_unit *nvc =3D null_unit(unit); =20 if ( unlikely(!list_empty(&nvc->waitq_elem)) ) { @@ -644,7 +644,7 @@ static void null_unit_sleep(const struct scheduler *ops, } =20 /* If v is not assigned to a pCPU, or is not running, no need to bothe= r */ - if ( likely(!tickled && curr_on_cpu(cpu) =3D=3D v) ) + if ( likely(!tickled && curr_on_cpu(cpu) =3D=3D unit) ) cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); =20 SCHED_STAT_CRANK(vcpu_sleep); @@ -662,7 +662,7 @@ static void null_unit_migrate(const struct scheduler *o= ps, { struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); - struct null_vcpu *nvc =3D null_vcpu(v); + struct null_unit *nvc =3D null_unit(unit); =20 ASSERT(!is_idle_vcpu(v)); =20 @@ -758,7 +758,7 @@ static void null_unit_migrate(const struct scheduler *o= ps, #ifndef NDEBUG static inline void null_vcpu_check(struct vcpu *v) { - struct null_vcpu * const nvc =3D null_vcpu(v); + struct null_unit * const nvc =3D null_unit(v->sched_unit); struct null_dom * const ndom =3D v->domain->sched_priv; =20 BUG_ON(nvc->vcpu !=3D v); @@ -788,7 +788,7 @@ static struct task_slice null_schedule(const struct sch= eduler *ops, unsigned int bs; const unsigned int cpu =3D smp_processor_id(); struct null_private *prv =3D null_priv(ops); - struct null_vcpu *wvc; + struct null_unit *wvc; struct task_slice ret; =20 SCHED_STAT_CRANK(schedule); @@ -874,7 +874,7 @@ static struct task_slice null_schedule(const struct sch= eduler *ops, return ret; } =20 -static inline void dump_vcpu(struct null_private *prv, struct null_vcpu *n= vc) +static inline void dump_vcpu(struct null_private *prv, struct null_unit *n= vc) { printk("[%i.%i] pcpu=3D%d", nvc->vcpu->domain->domain_id, nvc->vcpu->vcpu_id, list_empty(&nvc->waitq_elem) ? @@ -884,7 +884,7 @@ static inline void dump_vcpu(struct null_private *prv, = struct null_vcpu *nvc) static void null_dump_pcpu(const struct scheduler *ops, int cpu) { struct null_private *prv =3D null_priv(ops); - struct null_vcpu *nvc; + struct null_unit *nvc; spinlock_t *lock; unsigned long flags; =20 @@ -898,7 +898,7 @@ static void null_dump_pcpu(const struct scheduler *ops,= int cpu) printk("\n"); =20 /* current VCPU (nothing to say if that's the idle vcpu) */ - nvc =3D null_vcpu(curr_on_cpu(cpu)); + nvc =3D null_unit(curr_on_cpu(cpu)); if ( nvc && !is_idle_vcpu(nvc->vcpu) ) { printk("\trun: "); @@ -932,7 +932,7 @@ static void null_dump(const struct scheduler *ops) printk("\tDomain: %d\n", ndom->dom->domain_id); for_each_vcpu( ndom->dom, v ) { - struct null_vcpu * const nvc =3D null_vcpu(v); + struct null_unit * const nvc =3D null_unit(v->sched_unit); spinlock_t *lock; =20 lock =3D vcpu_schedule_lock(nvc->vcpu); @@ -950,7 +950,7 @@ static void null_dump(const struct scheduler *ops) spin_lock(&prv->waitq_lock); list_for_each( iter, &prv->waitq ) { - struct null_vcpu *nvc =3D list_entry(iter, struct null_vcpu, waitq= _elem); + struct null_unit *nvc =3D list_entry(iter, struct null_unit, waitq= _elem); =20 if ( loop++ !=3D 0 ) printk(", "); diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index 6e9424a461..06f63176ee 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -195,7 +195,7 @@ struct rt_private { /* * Virtual CPU */ -struct rt_vcpu { +struct rt_unit { struct list_head q_elem; /* on the runq/depletedq list */ struct list_head replq_elem; /* on the replenishment events list */ =20 @@ -233,9 +233,9 @@ static inline struct rt_private *rt_priv(const struct s= cheduler *ops) return ops->sched_data; } =20 -static inline struct rt_vcpu *rt_vcpu(const struct vcpu *vcpu) +static inline struct rt_unit *rt_unit(const struct sched_unit *unit) { - return vcpu->sched_unit->priv; + return unit->priv; } =20 static inline struct list_head *rt_runq(const struct scheduler *ops) @@ -253,7 +253,7 @@ static inline struct list_head *rt_replq(const struct s= cheduler *ops) return &rt_priv(ops)->replq; } =20 -static inline bool has_extratime(const struct rt_vcpu *svc) +static inline bool has_extratime(const struct rt_unit *svc) { return svc->flags & RTDS_extratime; } @@ -263,25 +263,25 @@ static inline bool has_extratime(const struct rt_vcpu= *svc) * and the replenishment events queue. */ static int -vcpu_on_q(const struct rt_vcpu *svc) +vcpu_on_q(const struct rt_unit *svc) { return !list_empty(&svc->q_elem); } =20 -static struct rt_vcpu * +static struct rt_unit * q_elem(struct list_head *elem) { - return list_entry(elem, struct rt_vcpu, q_elem); + return list_entry(elem, struct rt_unit, q_elem); } =20 -static struct rt_vcpu * +static struct rt_unit * replq_elem(struct list_head *elem) { - return list_entry(elem, struct rt_vcpu, replq_elem); + return list_entry(elem, struct rt_unit, replq_elem); } =20 static int -vcpu_on_replq(const struct rt_vcpu *svc) +vcpu_on_replq(const struct rt_unit *svc) { return !list_empty(&svc->replq_elem); } @@ -291,7 +291,7 @@ vcpu_on_replq(const struct rt_vcpu *svc) * Otherwise, return value < 0 */ static s_time_t -compare_vcpu_priority(const struct rt_vcpu *v1, const struct rt_vcpu *v2) +compare_vcpu_priority(const struct rt_unit *v1, const struct rt_unit *v2) { int prio =3D v2->priority_level - v1->priority_level; =20 @@ -305,7 +305,7 @@ compare_vcpu_priority(const struct rt_vcpu *v1, const s= truct rt_vcpu *v2) * Debug related code, dump vcpu/cpu information */ static void -rt_dump_vcpu(const struct scheduler *ops, const struct rt_vcpu *svc) +rt_dump_vcpu(const struct scheduler *ops, const struct rt_unit *svc) { cpumask_t *cpupool_mask, *mask; =20 @@ -351,13 +351,13 @@ static void rt_dump_pcpu(const struct scheduler *ops, int cpu) { struct rt_private *prv =3D rt_priv(ops); - struct rt_vcpu *svc; + struct rt_unit *svc; unsigned long flags; =20 spin_lock_irqsave(&prv->lock, flags); printk("CPU[%02d]\n", cpu); /* current VCPU (nothing to say if that's the idle vcpu). */ - svc =3D rt_vcpu(curr_on_cpu(cpu)); + svc =3D rt_unit(curr_on_cpu(cpu)); if ( svc && !is_idle_vcpu(svc->vcpu) ) { rt_dump_vcpu(ops, svc); @@ -370,7 +370,7 @@ rt_dump(const struct scheduler *ops) { struct list_head *runq, *depletedq, *replq, *iter; struct rt_private *prv =3D rt_priv(ops); - struct rt_vcpu *svc; + struct rt_unit *svc; struct rt_dom *sdom; unsigned long flags; =20 @@ -414,7 +414,7 @@ rt_dump(const struct scheduler *ops) =20 for_each_vcpu ( sdom->dom, v ) { - svc =3D rt_vcpu(v); + svc =3D rt_unit(v->sched_unit); rt_dump_vcpu(ops, svc); } } @@ -428,7 +428,7 @@ rt_dump(const struct scheduler *ops) * it needs to be updated to the deadline of the current period */ static void -rt_update_deadline(s_time_t now, struct rt_vcpu *svc) +rt_update_deadline(s_time_t now, struct rt_unit *svc) { ASSERT(now >=3D svc->cur_deadline); ASSERT(svc->period !=3D 0); @@ -499,8 +499,8 @@ deadline_queue_remove(struct list_head *queue, struct l= ist_head *elem) } =20 static inline bool -deadline_queue_insert(struct rt_vcpu * (*qelem)(struct list_head *), - struct rt_vcpu *svc, struct list_head *elem, +deadline_queue_insert(struct rt_unit * (*qelem)(struct list_head *), + struct rt_unit *svc, struct list_head *elem, struct list_head *queue) { struct list_head *iter; @@ -508,7 +508,7 @@ deadline_queue_insert(struct rt_vcpu * (*qelem)(struct = list_head *), =20 list_for_each ( iter, queue ) { - struct rt_vcpu * iter_svc =3D (*qelem)(iter); + struct rt_unit * iter_svc =3D (*qelem)(iter); if ( compare_vcpu_priority(svc, iter_svc) > 0 ) break; pos++; @@ -522,14 +522,14 @@ deadline_queue_insert(struct rt_vcpu * (*qelem)(struc= t list_head *), deadline_queue_insert(&replq_elem, ##__VA_ARGS__) =20 static inline void -q_remove(struct rt_vcpu *svc) +q_remove(struct rt_unit *svc) { ASSERT( vcpu_on_q(svc) ); list_del_init(&svc->q_elem); } =20 static inline void -replq_remove(const struct scheduler *ops, struct rt_vcpu *svc) +replq_remove(const struct scheduler *ops, struct rt_unit *svc) { struct rt_private *prv =3D rt_priv(ops); struct list_head *replq =3D rt_replq(ops); @@ -546,7 +546,7 @@ replq_remove(const struct scheduler *ops, struct rt_vcp= u *svc) */ if ( !list_empty(replq) ) { - struct rt_vcpu *svc_next =3D replq_elem(replq->next); + struct rt_unit *svc_next =3D replq_elem(replq->next); set_timer(&prv->repl_timer, svc_next->cur_deadline); } else @@ -560,7 +560,7 @@ replq_remove(const struct scheduler *ops, struct rt_vcp= u *svc) * Insert svc without budget in DepletedQ unsorted; */ static void -runq_insert(const struct scheduler *ops, struct rt_vcpu *svc) +runq_insert(const struct scheduler *ops, struct rt_unit *svc) { struct rt_private *prv =3D rt_priv(ops); struct list_head *runq =3D rt_runq(ops); @@ -578,7 +578,7 @@ runq_insert(const struct scheduler *ops, struct rt_vcpu= *svc) } =20 static void -replq_insert(const struct scheduler *ops, struct rt_vcpu *svc) +replq_insert(const struct scheduler *ops, struct rt_unit *svc) { struct list_head *replq =3D rt_replq(ops); struct rt_private *prv =3D rt_priv(ops); @@ -600,10 +600,10 @@ replq_insert(const struct scheduler *ops, struct rt_v= cpu *svc) * changed. */ static void -replq_reinsert(const struct scheduler *ops, struct rt_vcpu *svc) +replq_reinsert(const struct scheduler *ops, struct rt_unit *svc) { struct list_head *replq =3D rt_replq(ops); - struct rt_vcpu *rearm_svc =3D svc; + struct rt_unit *rearm_svc =3D svc; bool_t rearm =3D 0; =20 ASSERT( vcpu_on_replq(svc) ); @@ -734,7 +734,7 @@ rt_switch_sched(struct scheduler *new_ops, unsigned int= cpu, void *pdata, void *vdata) { struct rt_private *prv =3D rt_priv(new_ops); - struct rt_vcpu *svc =3D vdata; + struct rt_unit *svc =3D vdata; =20 ASSERT(!pdata && svc && is_idle_vcpu(svc->vcpu)); =20 @@ -841,10 +841,10 @@ static void * rt_alloc_vdata(const struct scheduler *ops, struct sched_unit *unit, void = *dd) { struct vcpu *vc =3D unit->vcpu_list; - struct rt_vcpu *svc; + struct rt_unit *svc; =20 /* Allocate per-VCPU info */ - svc =3D xzalloc(struct rt_vcpu); + svc =3D xzalloc(struct rt_unit); if ( svc =3D=3D NULL ) return NULL; =20 @@ -869,7 +869,7 @@ rt_alloc_vdata(const struct scheduler *ops, struct sche= d_unit *unit, void *dd) static void rt_free_vdata(const struct scheduler *ops, void *priv) { - struct rt_vcpu *svc =3D priv; + struct rt_unit *svc =3D priv; =20 xfree(svc); } @@ -885,7 +885,7 @@ static void rt_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct rt_vcpu *svc =3D rt_vcpu(vc); + struct rt_unit *svc =3D rt_unit(unit); s_time_t now; spinlock_t *lock; =20 @@ -914,13 +914,13 @@ rt_unit_insert(const struct scheduler *ops, struct sc= hed_unit *unit) } =20 /* - * Remove rt_vcpu svc from the old scheduler in source cpupool. + * Remove rt_unit svc from the old scheduler in source cpupool. */ static void rt_unit_remove(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct rt_vcpu * const svc =3D rt_vcpu(vc); + struct rt_unit * const svc =3D rt_unit(unit); struct rt_dom * const sdom =3D svc->sdom; spinlock_t *lock; =20 @@ -942,7 +942,7 @@ rt_unit_remove(const struct scheduler *ops, struct sche= d_unit *unit) * Burn budget in nanosecond granularity */ static void -burn_budget(const struct scheduler *ops, struct rt_vcpu *svc, s_time_t now) +burn_budget(const struct scheduler *ops, struct rt_unit *svc, s_time_t now) { s_time_t delta; =20 @@ -1006,13 +1006,13 @@ burn_budget(const struct scheduler *ops, struct rt_= vcpu *svc, s_time_t now) * RunQ is sorted. Pick first one within cpumask. If no one, return NULL * lock is grabbed before calling this function */ -static struct rt_vcpu * +static struct rt_unit * runq_pick(const struct scheduler *ops, const cpumask_t *mask) { struct list_head *runq =3D rt_runq(ops); struct list_head *iter; - struct rt_vcpu *svc =3D NULL; - struct rt_vcpu *iter_svc =3D NULL; + struct rt_unit *svc =3D NULL; + struct rt_unit *iter_svc =3D NULL; cpumask_t cpu_common; cpumask_t *online; =20 @@ -1063,8 +1063,8 @@ rt_schedule(const struct scheduler *ops, s_time_t now= , bool_t tasklet_work_sched { const int cpu =3D smp_processor_id(); struct rt_private *prv =3D rt_priv(ops); - struct rt_vcpu *const scurr =3D rt_vcpu(current); - struct rt_vcpu *snext =3D NULL; + struct rt_unit *const scurr =3D rt_unit(current->sched_unit); + struct rt_unit *snext =3D NULL; struct task_slice ret =3D { .migrated =3D 0 }; =20 /* TRACE */ @@ -1090,13 +1090,13 @@ rt_schedule(const struct scheduler *ops, s_time_t n= ow, bool_t tasklet_work_sched if ( tasklet_work_scheduled ) { trace_var(TRC_RTDS_SCHED_TASKLET, 1, 0, NULL); - snext =3D rt_vcpu(idle_vcpu[cpu]); + snext =3D rt_unit(idle_vcpu[cpu]->sched_unit); } else { snext =3D runq_pick(ops, cpumask_of(cpu)); if ( snext =3D=3D NULL ) - snext =3D rt_vcpu(idle_vcpu[cpu]); + snext =3D rt_unit(idle_vcpu[cpu]->sched_unit); =20 /* if scurr has higher priority and budget, still pick scurr */ if ( !is_idle_vcpu(current) && @@ -1142,12 +1142,12 @@ static void rt_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct rt_vcpu * const svc =3D rt_vcpu(vc); + struct rt_unit * const svc =3D rt_unit(unit); =20 BUG_ON( is_idle_vcpu(vc) ); SCHED_STAT_CRANK(vcpu_sleep); =20 - if ( curr_on_cpu(vc->processor) =3D=3D vc ) + if ( curr_on_cpu(vc->processor) =3D=3D unit ) cpu_raise_softirq(vc->processor, SCHEDULE_SOFTIRQ); else if ( vcpu_on_q(svc) ) { @@ -1177,11 +1177,11 @@ rt_unit_sleep(const struct scheduler *ops, struct s= ched_unit *unit) * lock is grabbed before calling this function */ static void -runq_tickle(const struct scheduler *ops, struct rt_vcpu *new) +runq_tickle(const struct scheduler *ops, struct rt_unit *new) { struct rt_private *prv =3D rt_priv(ops); - struct rt_vcpu *latest_deadline_vcpu =3D NULL; /* lowest priority */ - struct rt_vcpu *iter_svc; + struct rt_unit *latest_deadline_vcpu =3D NULL; /* lowest priority */ + struct rt_unit *iter_svc; struct vcpu *iter_vc; int cpu =3D 0, cpu_to_tickle =3D 0; cpumask_t not_tickled; @@ -1202,14 +1202,14 @@ runq_tickle(const struct scheduler *ops, struct rt_= vcpu *new) cpu =3D cpumask_test_or_cycle(new->vcpu->processor, ¬_tickled); while ( cpu!=3D nr_cpu_ids ) { - iter_vc =3D curr_on_cpu(cpu); + iter_vc =3D curr_on_cpu(cpu)->vcpu_list; if ( is_idle_vcpu(iter_vc) ) { SCHED_STAT_CRANK(tickled_idle_cpu); cpu_to_tickle =3D cpu; goto out; } - iter_svc =3D rt_vcpu(iter_vc); + iter_svc =3D rt_unit(iter_vc->sched_unit); if ( latest_deadline_vcpu =3D=3D NULL || compare_vcpu_priority(iter_svc, latest_deadline_vcpu) < 0 ) latest_deadline_vcpu =3D iter_svc; @@ -1258,13 +1258,13 @@ static void rt_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct rt_vcpu * const svc =3D rt_vcpu(vc); + struct rt_unit * const svc =3D rt_unit(unit); s_time_t now; bool_t missed; =20 BUG_ON( is_idle_vcpu(vc) ); =20 - if ( unlikely(curr_on_cpu(vc->processor) =3D=3D vc) ) + if ( unlikely(curr_on_cpu(vc->processor) =3D=3D unit) ) { SCHED_STAT_CRANK(vcpu_wake_running); return; @@ -1329,7 +1329,7 @@ static void rt_context_saved(const struct scheduler *ops, struct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; - struct rt_vcpu *svc =3D rt_vcpu(vc); + struct rt_unit *svc =3D rt_unit(unit); spinlock_t *lock =3D vcpu_schedule_lock_irq(vc); =20 __clear_bit(__RTDS_scheduled, &svc->flags); @@ -1360,7 +1360,7 @@ rt_dom_cntl( struct xen_domctl_scheduler_op *op) { struct rt_private *prv =3D rt_priv(ops); - struct rt_vcpu *svc; + struct rt_unit *svc; struct vcpu *v; unsigned long flags; int rc =3D 0; @@ -1384,7 +1384,7 @@ rt_dom_cntl( spin_lock_irqsave(&prv->lock, flags); for_each_vcpu ( d, v ) { - svc =3D rt_vcpu(v); + svc =3D rt_unit(v->sched_unit); svc->period =3D MICROSECS(op->u.rtds.period); /* transfer to n= anosec */ svc->budget =3D MICROSECS(op->u.rtds.budget); } @@ -1410,7 +1410,7 @@ rt_dom_cntl( if ( op->cmd =3D=3D XEN_DOMCTL_SCHEDOP_getvcpuinfo ) { spin_lock_irqsave(&prv->lock, flags); - svc =3D rt_vcpu(d->vcpu[local_sched.vcpuid]); + svc =3D rt_unit(d->vcpu[local_sched.vcpuid]->sched_unit); local_sched.u.rtds.budget =3D svc->budget / MICROSECS(1); local_sched.u.rtds.period =3D svc->period / MICROSECS(1); if ( has_extratime(svc) ) @@ -1438,7 +1438,7 @@ rt_dom_cntl( } =20 spin_lock_irqsave(&prv->lock, flags); - svc =3D rt_vcpu(d->vcpu[local_sched.vcpuid]); + svc =3D rt_unit(d->vcpu[local_sched.vcpuid]->sched_unit); svc->period =3D period; svc->budget =3D budget; if ( local_sched.u.rtds.flags & XEN_DOMCTL_SCHEDRT_extra ) @@ -1471,7 +1471,7 @@ static void repl_timer_handler(void *data){ struct list_head *replq =3D rt_replq(ops); struct list_head *runq =3D rt_runq(ops); struct list_head *iter, *tmp; - struct rt_vcpu *svc; + struct rt_unit *svc; LIST_HEAD(tmp_replq); =20 spin_lock_irq(&prv->lock); @@ -1513,10 +1513,10 @@ static void repl_timer_handler(void *data){ { svc =3D replq_elem(iter); =20 - if ( curr_on_cpu(svc->vcpu->processor) =3D=3D svc->vcpu && + if ( curr_on_cpu(svc->vcpu->processor) =3D=3D svc->vcpu->sched_uni= t && !list_empty(runq) ) { - struct rt_vcpu *next_on_runq =3D q_elem(runq->next); + struct rt_unit *next_on_runq =3D q_elem(runq->next); =20 if ( compare_vcpu_priority(svc, next_on_runq) < 0 ) runq_tickle(ops, next_on_runq); diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 9ad11dc46d..45394e6c2e 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -392,7 +392,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proces= sor) /* Idle VCPUs are scheduled immediately, so don't put them in runqueue= . */ if ( is_idle_domain(d) ) { - per_cpu(schedule_data, v->processor).curr =3D v; + per_cpu(schedule_data, v->processor).curr =3D unit; v->is_running =3D 1; } else @@ -1599,7 +1599,7 @@ static void schedule(void) =20 next =3D next_slice.task; =20 - sd->curr =3D next; + sd->curr =3D next->sched_unit; =20 if ( next_slice.time >=3D 0 ) /* -ve means no limit */ set_timer(&sd->s_timer, now + next_slice.time); @@ -1741,7 +1741,7 @@ static int cpu_schedule_up(unsigned int cpu) * allocated. */ =20 - sd->curr =3D idle_vcpu[cpu]; + sd->curr =3D idle_vcpu[cpu]->sched_unit; =20 sd->sched_priv =3D NULL; =20 @@ -1909,7 +1909,7 @@ void __init scheduler_init(void) idle_domain->max_vcpus =3D nr_cpu_ids; if ( vcpu_create(idle_domain, 0, 0) =3D=3D NULL ) BUG(); - this_cpu(schedule_data).curr =3D idle_vcpu[0]; + this_cpu(schedule_data).curr =3D idle_vcpu[0]->sched_unit; } =20 /* diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 88c1e6d505..69aedd2210 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -36,7 +36,7 @@ extern int sched_ratelimit_us; struct schedule_data { spinlock_t *schedule_lock, _lock; - struct vcpu *curr; /* current task = */ + struct sched_unit *curr; /* current task = */ void *sched_priv; struct timer s_timer; /* scheduling timer = */ atomic_t urgent_count; /* how many urgent vcpus = */ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362799; cv=none; d=zoho.com; s=zohoarc; b=UhvUL20rBpfcBBk5JJip1W9hlZz8I4EBeJGGG9dRjb3ldYUNKnn6mxkFwspdjHx/5kS1Lmt6qEY0fto8oSmobrSzVZ6soFGGVIeVjLyzDpiMhtuDiS3GIof+Li70Nj2I/WB+50LOshneva28AclAbr4ZocFJfqbGZlHIkI9mqNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362799; 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=5CrVpeoUpTdpOyPxZwSosEH27p0kIXwiNeiqUrTEAP8=; b=TX6j4OIDYPtWEC0iAv7cBAmxp0QGS8M/hU9+YhsI0SfUsKHaI9dIJyqtnuBN5+DaOFt0y+WaezKYBbMIEH4e6xQRQBs2NJ5ZfLrOKzMMiSFhAmiiY8NrFDAMkmgHw549DOoKm2uB7/rcKdFPZsZq6VWGYArhhHl6azxlEt4onS8= 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 1565362799953117.71374251089958; Fri, 9 Aug 2019 07:59:59 -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 1hw6Lz-0006Vd-7X; Fri, 09 Aug 2019 14:58:51 +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 1hw6Lv-0006Rb-R9 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:47 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2d706672-bab6-11e9-9561-732d7685f0f6; Fri, 09 Aug 2019 14:58:42 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 08F21B04C; Fri, 9 Aug 2019 14:58:40 +0000 (UTC) X-Inumbo-ID: 2d706672-bab6-11e9-9561-732d7685f0f6 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:52 +0200 Message-Id: <20190809145833.1020-8-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 07/48] xen/sched: move per cpu scheduler private data into 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Robert VanVossen , Tim Deegan , Julien Grall , Josh Whitehead , Meng Xu , Jan Beulich , Dario Faggioli , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= 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" This prepares support of larger scheduling granularities, e.g. core scheduling. While at it move sched_has_urgent_vcpu() from include/asm-x86/cpuidle.h into schedule.c removing the need for including sched-if.h in cpuidle.h and multiple other C sources. Signed-off-by: Juergen Gross Acked-by: Jan Beulich Reviewed-by: Dario Faggioli --- V1: - move sched_has_urgent_vcpu() V2: - make sched_has_urgent_vcpu() return bool (Jan Beulich) --- xen/arch/x86/acpi/cpu_idle.c | 1 - xen/arch/x86/cpu/mcheck/mce.c | 1 - xen/arch/x86/cpu/mcheck/mctelem.c | 1 - xen/arch/x86/setup.c | 1 - xen/arch/x86/smpboot.c | 1 - xen/common/sched_arinc653.c | 4 +-- xen/common/sched_credit.c | 10 +++---- xen/common/sched_credit2.c | 21 +++++++------- xen/common/sched_null.c | 4 +-- xen/common/sched_rt.c | 9 +++--- xen/common/schedule.c | 60 ++++++++++++++++++++++-------------= ---- xen/include/asm-x86/cpuidle.h | 11 ------- xen/include/xen/sched-if.h | 20 ++++++------- xen/include/xen/sched.h | 1 + 14 files changed, 68 insertions(+), 77 deletions(-) diff --git a/xen/arch/x86/acpi/cpu_idle.c b/xen/arch/x86/acpi/cpu_idle.c index 8f7b6e9b8c..836f524ef4 100644 --- a/xen/arch/x86/acpi/cpu_idle.c +++ b/xen/arch/x86/acpi/cpu_idle.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c index 28ad7dd659..4b2b6de191 100644 --- a/xen/arch/x86/cpu/mcheck/mce.c +++ b/xen/arch/x86/cpu/mcheck/mce.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/arch/x86/cpu/mcheck/mctelem.c b/xen/arch/x86/cpu/mcheck/mc= telem.c index 3bb13e5265..012a9b95e5 100644 --- a/xen/arch/x86/cpu/mcheck/mctelem.c +++ b/xen/arch/x86/cpu/mcheck/mctelem.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include =20 diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index d2011910fa..28c35bbac9 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 8d5fef0012..27b78a0b61 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c index 34b1f235a2..25fbc42f74 100644 --- a/xen/common/sched_arinc653.c +++ b/xen/common/sched_arinc653.c @@ -475,7 +475,7 @@ a653sched_unit_sleep(const struct scheduler *ops, struc= t sched_unit *unit) * If the VCPU being put to sleep is the same one that is currently * running, raise a softirq to invoke the scheduler to switch domains. */ - if ( per_cpu(schedule_data, vc->processor).curr =3D=3D unit ) + if ( get_sched_res(vc->processor)->curr =3D=3D unit ) cpu_raise_softirq(vc->processor, SCHEDULE_SOFTIRQ); } =20 @@ -642,7 +642,7 @@ static spinlock_t * a653_switch_sched(struct scheduler *new_ops, unsigned int cpu, void *pdata, void *vdata) { - struct schedule_data *sd =3D &per_cpu(schedule_data, cpu); + struct sched_resource *sd =3D get_sched_res(cpu); arinc653_vcpu_t *svc =3D vdata; =20 ASSERT(!pdata && svc && is_idle_vcpu(svc->vc)); diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 7c3dbae892..261d2083c7 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -82,7 +82,7 @@ #define CSCHED_PRIV(_ops) \ ((struct csched_private *)((_ops)->sched_data)) #define CSCHED_PCPU(_c) \ - ((struct csched_pcpu *)per_cpu(schedule_data, _c).sched_priv) + ((struct csched_pcpu *)get_sched_res(_c)->sched_priv) #define CSCHED_UNIT(unit) ((struct csched_unit *) (unit)->priv) #define CSCHED_DOM(_dom) ((struct csched_dom *) (_dom)->sched_priv) #define RUNQ(_cpu) (&(CSCHED_PCPU(_cpu)->runq)) @@ -250,7 +250,7 @@ static inline bool_t is_runq_idle(unsigned int cpu) /* * We're peeking at cpu's runq, we must hold the proper lock. */ - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 return list_empty(RUNQ(cpu)) || is_idle_vcpu(__runq_elem(RUNQ(cpu)->next)->vcpu); @@ -259,7 +259,7 @@ static inline bool_t is_runq_idle(unsigned int cpu) static inline void inc_nr_runnable(unsigned int cpu) { - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); CSCHED_PCPU(cpu)->nr_runnable++; =20 } @@ -267,7 +267,7 @@ inc_nr_runnable(unsigned int cpu) static inline void dec_nr_runnable(unsigned int cpu) { - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); ASSERT(CSCHED_PCPU(cpu)->nr_runnable >=3D 1); CSCHED_PCPU(cpu)->nr_runnable--; } @@ -628,7 +628,7 @@ static spinlock_t * csched_switch_sched(struct scheduler *new_ops, unsigned int cpu, void *pdata, void *vdata) { - struct schedule_data *sd =3D &per_cpu(schedule_data, cpu); + struct sched_resource *sd =3D get_sched_res(cpu); struct csched_private *prv =3D CSCHED_PRIV(new_ops); struct csched_unit *svc =3D vdata; =20 diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index f856293371..02e2855d8d 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -568,7 +568,7 @@ static inline struct csched2_private *csched2_priv(cons= t struct scheduler *ops) =20 static inline struct csched2_pcpu *csched2_pcpu(unsigned int cpu) { - return per_cpu(schedule_data, cpu).sched_priv; + return get_sched_res(cpu)->sched_priv; } =20 static inline struct csched2_unit *csched2_unit(const struct sched_unit *u= nit) @@ -1277,7 +1277,7 @@ runq_insert(const struct scheduler *ops, struct csche= d2_unit *svc) struct list_head * runq =3D &c2rqd(ops, cpu)->runq; int pos =3D 0; =20 - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 ASSERT(!vcpu_on_runq(svc)); ASSERT(c2r(cpu) =3D=3D c2r(svc->vcpu->processor)); @@ -1798,7 +1798,7 @@ static bool vcpu_grab_budget(struct csched2_unit *svc) struct csched2_dom *sdom =3D svc->sdom; unsigned int cpu =3D svc->vcpu->processor; =20 - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 if ( svc->budget > 0 ) return true; @@ -1845,7 +1845,7 @@ vcpu_return_budget(struct csched2_unit *svc, struct l= ist_head *parked) struct csched2_dom *sdom =3D svc->sdom; unsigned int cpu =3D svc->vcpu->processor; =20 - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); ASSERT(list_empty(parked)); =20 /* budget_lock nests inside runqueue lock. */ @@ -2102,7 +2102,7 @@ csched2_unit_wake(const struct scheduler *ops, struct= sched_unit *unit) unsigned int cpu =3D vc->processor; s_time_t now; =20 - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 ASSERT(!is_idle_vcpu(vc)); =20 @@ -2230,7 +2230,7 @@ csched2_res_pick(const struct scheduler *ops, struct = sched_unit *unit) * just grab the prv lock. Instead, we'll have to trylock, and * do something else reasonable if we fail. */ - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 if ( !read_trylock(&prv->lock) ) { @@ -2570,7 +2570,7 @@ static void balance_load(const struct scheduler *ops,= int cpu, s_time_t now) * on either side may be empty). */ =20 - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); st.lrqd =3D c2rqd(ops, cpu); =20 update_runq_load(ops, st.lrqd, 0, now); @@ -3476,7 +3476,7 @@ csched2_schedule( rqd =3D c2rqd(ops, cpu); BUG_ON(!cpumask_test_cpu(cpu, &rqd->active)); =20 - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 BUG_ON(!is_idle_vcpu(scurr->vcpu) && scurr->rqd !=3D rqd); =20 @@ -3867,7 +3867,7 @@ csched2_init_pdata(const struct scheduler *ops, void = *pdata, int cpu) =20 rqi =3D init_pdata(prv, pdata, cpu); /* Move the scheduler lock to the new runq lock. */ - per_cpu(schedule_data, cpu).schedule_lock =3D &prv->rqd[rqi].lock; + get_sched_res(cpu)->schedule_lock =3D &prv->rqd[rqi].lock; =20 /* _Not_ pcpu_schedule_unlock(): schedule_lock may have changed! */ spin_unlock(old_lock); @@ -3881,6 +3881,7 @@ csched2_switch_sched(struct scheduler *new_ops, unsig= ned int cpu, { struct csched2_private *prv =3D csched2_priv(new_ops); struct csched2_unit *svc =3D vdata; + struct sched_resource *sd =3D get_sched_res(cpu); unsigned rqi; =20 ASSERT(pdata && svc && is_idle_vcpu(svc->vcpu)); @@ -3906,7 +3907,7 @@ csched2_switch_sched(struct scheduler *new_ops, unsig= ned int cpu, * this scheduler, and so it's safe to have taken it /before/ our * private global lock. */ - ASSERT(per_cpu(schedule_data, cpu).schedule_lock !=3D &prv->rqd[rqi].l= ock); + ASSERT(sd->schedule_lock !=3D &prv->rqd[rqi].lock); =20 write_unlock(&prv->lock); =20 diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index 4dc0356f80..5f0356c7f8 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -269,7 +269,7 @@ pick_res(struct null_private *prv, struct sched_unit *u= nit) unsigned int cpu =3D v->processor, new_cpu; cpumask_t *cpus =3D cpupool_domain_cpumask(v->domain); =20 - ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 for_each_affinity_balance_step( bs ) { @@ -419,7 +419,7 @@ static spinlock_t *null_switch_sched(struct scheduler *= new_ops, unsigned int cpu, void *pdata, void *vdata) { - struct schedule_data *sd =3D &per_cpu(schedule_data, cpu); + struct sched_resource *sd =3D get_sched_res(cpu); struct null_private *prv =3D null_priv(new_ops); struct null_unit *nvc =3D vdata; =20 diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index 06f63176ee..3ce85122cc 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -75,7 +75,7 @@ /* * Locking: * A global system lock is used to protect the RunQ and DepletedQ. - * The global lock is referenced by schedule_data.schedule_lock + * The global lock is referenced by sched_res->schedule_lock * from all physical cpus. * * The lock is already grabbed when calling wake/sleep/schedule/ functions @@ -176,7 +176,7 @@ static void repl_timer_handler(void *data); =20 /* * System-wide private data, include global RunQueue/DepletedQ - * Global lock is referenced by schedule_data.schedule_lock from all + * Global lock is referenced by sched_res->schedule_lock from all * physical cpus. It can be grabbed via vcpu_schedule_lock_irq() */ struct rt_private { @@ -722,7 +722,7 @@ rt_init_pdata(const struct scheduler *ops, void *pdata,= int cpu) } =20 /* Move the scheduler lock to our global runqueue lock. */ - per_cpu(schedule_data, cpu).schedule_lock =3D &prv->lock; + get_sched_res(cpu)->schedule_lock =3D &prv->lock; =20 /* _Not_ pcpu_schedule_unlock(): per_cpu().schedule_lock changed! */ spin_unlock_irqrestore(old_lock, flags); @@ -735,6 +735,7 @@ rt_switch_sched(struct scheduler *new_ops, unsigned int= cpu, { struct rt_private *prv =3D rt_priv(new_ops); struct rt_unit *svc =3D vdata; + struct sched_resource *sd =3D get_sched_res(cpu); =20 ASSERT(!pdata && svc && is_idle_vcpu(svc->vcpu)); =20 @@ -744,7 +745,7 @@ rt_switch_sched(struct scheduler *new_ops, unsigned int= cpu, * another scheduler, but that is how things need to be, for * preventing races. */ - ASSERT(per_cpu(schedule_data, cpu).schedule_lock !=3D &prv->lock); + ASSERT(sd->schedule_lock !=3D &prv->lock); =20 /* * If we are the absolute first cpu being switched toward this diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 45394e6c2e..c167eb23f2 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -65,7 +65,6 @@ static void vcpu_singleshot_timer_fn(void *data); static void poll_timer_fn(void *data); =20 /* 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); =20 @@ -213,7 +212,7 @@ static inline void vcpu_urgent_count_update(struct vcpu= *v) !test_bit(v->vcpu_id, v->domain->poll_mask) ) { v->is_urgent =3D 0; - atomic_dec(&per_cpu(schedule_data,v->processor).urgent_count); + atomic_dec(&get_sched_res(v->processor)->urgent_count); } } else @@ -222,7 +221,7 @@ static inline void vcpu_urgent_count_update(struct vcpu= *v) unlikely(test_bit(v->vcpu_id, v->domain->poll_mask)) ) { v->is_urgent =3D 1; - atomic_inc(&per_cpu(schedule_data,v->processor).urgent_count); + atomic_inc(&get_sched_res(v->processor)->urgent_count); } } } @@ -233,7 +232,7 @@ static inline void vcpu_runstate_change( s_time_t delta; =20 ASSERT(v->runstate.state !=3D new_state); - ASSERT(spin_is_locked(per_cpu(schedule_data,v->processor).schedule_loc= k)); + ASSERT(spin_is_locked(get_sched_res(v->processor)->schedule_lock)); =20 vcpu_urgent_count_update(v); =20 @@ -392,7 +391,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proces= sor) /* Idle VCPUs are scheduled immediately, so don't put them in runqueue= . */ if ( is_idle_domain(d) ) { - per_cpu(schedule_data, v->processor).curr =3D unit; + get_sched_res(v->processor)->curr =3D unit; v->is_running =3D 1; } else @@ -517,7 +516,7 @@ void sched_destroy_vcpu(struct vcpu *v) kill_timer(&v->singleshot_timer); kill_timer(&v->poll_timer); if ( test_and_clear_bool(v->is_urgent) ) - atomic_dec(&per_cpu(schedule_data, v->processor).urgent_count); + atomic_dec(&get_sched_res(v->processor)->urgent_count); sched_remove_unit(vcpu_scheduler(v), unit); sched_free_vdata(vcpu_scheduler(v), unit->priv); sched_free_unit(unit); @@ -564,7 +563,7 @@ void sched_destroy_domain(struct domain *d) =20 void vcpu_sleep_nosync_locked(struct vcpu *v) { - ASSERT(spin_is_locked(per_cpu(schedule_data,v->processor).schedule_loc= k)); + ASSERT(spin_is_locked(get_sched_res(v->processor)->schedule_lock)); =20 if ( likely(!vcpu_runnable(v)) ) { @@ -659,8 +658,8 @@ static void vcpu_move_locked(struct vcpu *v, unsigned i= nt new_cpu) */ if ( unlikely(v->is_urgent) && (old_cpu !=3D new_cpu) ) { - atomic_inc(&per_cpu(schedule_data, new_cpu).urgent_count); - atomic_dec(&per_cpu(schedule_data, old_cpu).urgent_count); + atomic_inc(&get_sched_res(new_cpu)->urgent_count); + atomic_dec(&get_sched_res(old_cpu)->urgent_count); } =20 /* @@ -726,20 +725,20 @@ static void vcpu_migrate_finish(struct vcpu *v) * are not correct any longer after evaluating old and new cpu hol= ding * the locks. */ - old_lock =3D per_cpu(schedule_data, old_cpu).schedule_lock; - new_lock =3D per_cpu(schedule_data, new_cpu).schedule_lock; + old_lock =3D get_sched_res(old_cpu)->schedule_lock; + new_lock =3D get_sched_res(new_cpu)->schedule_lock; =20 sched_spin_lock_double(old_lock, new_lock, &flags); =20 old_cpu =3D v->processor; - if ( old_lock =3D=3D per_cpu(schedule_data, old_cpu).schedule_lock= ) + if ( old_lock =3D=3D get_sched_res(old_cpu)->schedule_lock ) { /* * If we selected a CPU on the previosu iteration, check if it * remains suitable for running this vCPU. */ if ( pick_called && - (new_lock =3D=3D per_cpu(schedule_data, new_cpu).schedule= _lock) && + (new_lock =3D=3D get_sched_res(new_cpu)->schedule_lock) && cpumask_test_cpu(new_cpu, v->cpu_hard_affinity) && cpumask_test_cpu(new_cpu, v->domain->cpupool->cpu_valid) ) break; @@ -747,7 +746,7 @@ static void vcpu_migrate_finish(struct vcpu *v) /* Select a new CPU. */ new_cpu =3D sched_pick_resource(vcpu_scheduler(v), v->sched_unit)->processor; - if ( (new_lock =3D=3D per_cpu(schedule_data, new_cpu).schedule= _lock) && + if ( (new_lock =3D=3D get_sched_res(new_cpu)->schedule_lock) && cpumask_test_cpu(new_cpu, v->domain->cpupool->cpu_valid) ) break; pick_called =3D 1; @@ -1558,7 +1557,7 @@ static void schedule(void) struct scheduler *sched; unsigned long *tasklet_work =3D &this_cpu(tasklet_work_to_do); bool_t tasklet_work_scheduled =3D 0; - struct schedule_data *sd; + struct sched_resource *sd; spinlock_t *lock; struct task_slice next_slice; int cpu =3D smp_processor_id(); @@ -1567,7 +1566,7 @@ static void schedule(void) =20 SCHED_STAT_CRANK(sched_run); =20 - sd =3D &this_cpu(schedule_data); + sd =3D get_sched_res(cpu); =20 /* Update tasklet scheduling status. */ switch ( *tasklet_work ) @@ -1708,14 +1707,13 @@ static void poll_timer_fn(void *data) =20 static int cpu_schedule_up(unsigned int cpu) { - struct schedule_data *sd =3D &per_cpu(schedule_data, cpu); - struct sched_resource *res; + struct sched_resource *sd; =20 - res =3D xzalloc(struct sched_resource); - if ( res =3D=3D NULL ) + sd =3D xzalloc(struct sched_resource); + if ( sd =3D=3D NULL ) return -ENOMEM; - res->processor =3D cpu; - set_sched_res(cpu, res); + sd->processor =3D cpu; + set_sched_res(cpu, sd); =20 per_cpu(scheduler, cpu) =3D &sched_idle_ops; spin_lock_init(&sd->_lock); @@ -1730,7 +1728,7 @@ static int cpu_schedule_up(unsigned int cpu) if ( idle_vcpu[cpu] =3D=3D NULL ) vcpu_create(idle_vcpu[0]->domain, cpu, cpu); else - idle_vcpu[cpu]->sched_unit->res =3D res; + idle_vcpu[cpu]->sched_unit->res =3D sd; =20 if ( idle_vcpu[cpu] =3D=3D NULL ) return -ENOMEM; @@ -1750,7 +1748,7 @@ static int cpu_schedule_up(unsigned int cpu) =20 static void cpu_schedule_down(unsigned int cpu) { - struct schedule_data *sd =3D &per_cpu(schedule_data, cpu); + struct sched_resource *sd =3D get_sched_res(cpu); =20 kill_timer(&sd->s_timer); =20 @@ -1909,7 +1907,7 @@ void __init scheduler_init(void) idle_domain->max_vcpus =3D nr_cpu_ids; if ( vcpu_create(idle_domain, 0, 0) =3D=3D NULL ) BUG(); - this_cpu(schedule_data).curr =3D idle_vcpu[0]->sched_unit; + get_sched_res(0)->curr =3D idle_vcpu[0]->sched_unit; } =20 /* @@ -1926,7 +1924,7 @@ int schedule_cpu_switch(unsigned int cpu, struct cpup= ool *c) struct scheduler *old_ops =3D per_cpu(scheduler, cpu); struct scheduler *new_ops =3D (c =3D=3D NULL) ? &sched_idle_ops : c->s= ched; struct cpupool *old_pool =3D per_cpu(cpupool, cpu); - struct schedule_data *sd =3D &per_cpu(schedule_data, cpu); + struct sched_resource *sd =3D get_sched_res(cpu); spinlock_t *old_lock, *new_lock; unsigned long flags; =20 @@ -2109,6 +2107,16 @@ void wait(void) schedule(); } =20 +/* + * vcpu is urgent if vcpu is polling event channel + * + * if urgent vcpu exists, CPU should not enter deep C state + */ +bool sched_has_urgent_vcpu(void) +{ + return atomic_read(&get_sched_res(smp_processor_id())->urgent_count); +} + #ifdef CONFIG_COMPAT #include "compat/schedule.c" #endif diff --git a/xen/include/asm-x86/cpuidle.h b/xen/include/asm-x86/cpuidle.h index 488f708305..5d7dffd228 100644 --- a/xen/include/asm-x86/cpuidle.h +++ b/xen/include/asm-x86/cpuidle.h @@ -4,7 +4,6 @@ #include #include #include -#include =20 extern struct acpi_processor_power *processor_powers[]; =20 @@ -27,14 +26,4 @@ void update_idle_stats(struct acpi_processor_power *, void update_last_cx_stat(struct acpi_processor_power *, struct acpi_processor_cx *, uint64_t); =20 -/* - * vcpu is urgent if vcpu is polling event channel - * - * if urgent vcpu exists, CPU should not enter deep C state - */ -static inline int sched_has_urgent_vcpu(void) -{ - return atomic_read(&this_cpu(schedule_data).urgent_count); -} - #endif /* __X86_ASM_CPUIDLE_H__ */ diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 69aedd2210..212c612374 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -33,22 +33,18 @@ extern int sched_ratelimit_us; * For cache betterness, keep the actual lock in the same cache area * as the rest of the struct. Just have the scheduler point to the * one it wants (This may be the one right in front of it).*/ -struct schedule_data { +struct sched_resource { spinlock_t *schedule_lock, _lock; struct sched_unit *curr; /* current task = */ void *sched_priv; struct timer s_timer; /* scheduling timer = */ atomic_t urgent_count; /* how many urgent vcpus = */ + unsigned int processor; }; =20 -#define curr_on_cpu(c) (per_cpu(schedule_data, c).curr) - -struct sched_resource { - unsigned int processor; -}; +#define curr_on_cpu(c) (get_sched_res(c)->curr) =20 -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); @@ -79,7 +75,7 @@ static inline spinlock_t *kind##_schedule_lock##irq(param= EXTRA_TYPE(arg)) \ { \ for ( ; ; ) \ { \ - spinlock_t *lock =3D per_cpu(schedule_data, cpu).schedule_lock; \ + spinlock_t *lock =3D get_sched_res(cpu)->schedule_lock; \ /* \ * v->processor may change when grabbing the lock; but \ * per_cpu(v->processor) may also change, if changing cpu pool \ @@ -89,7 +85,7 @@ static inline spinlock_t *kind##_schedule_lock##irq(param= EXTRA_TYPE(arg)) \ * lock may be the same; this will succeed in that case. \ */ \ spin_lock##irq(lock, ## arg); \ - if ( likely(lock =3D=3D per_cpu(schedule_data, cpu).schedule_lock)= ) \ + if ( likely(lock =3D=3D get_sched_res(cpu)->schedule_lock) ) \ return lock; \ spin_unlock##irq(lock, ## arg); \ } \ @@ -99,7 +95,7 @@ static inline spinlock_t *kind##_schedule_lock##irq(param= EXTRA_TYPE(arg)) \ static inline void kind##_schedule_unlock##irq(spinlock_t *lock \ EXTRA_TYPE(arg), param) \ { \ - ASSERT(lock =3D=3D per_cpu(schedule_data, cpu).schedule_lock); \ + ASSERT(lock =3D=3D get_sched_res(cpu)->schedule_lock); \ spin_unlock##irq(lock, ## arg); \ } =20 @@ -128,11 +124,11 @@ sched_unlock(vcpu, const struct vcpu *v, v->processor= , _irqrestore, flags) =20 static inline spinlock_t *pcpu_schedule_trylock(unsigned int cpu) { - spinlock_t *lock =3D per_cpu(schedule_data, cpu).schedule_lock; + spinlock_t *lock =3D get_sched_res(cpu)->schedule_lock; =20 if ( !spin_trylock(lock) ) return NULL; - if ( lock =3D=3D per_cpu(schedule_data, cpu).schedule_lock ) + if ( lock =3D=3D get_sched_res(cpu)->schedule_lock ) return lock; spin_unlock(lock); return NULL; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 2ab1b13c63..575ce9a245 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -903,6 +903,7 @@ void restore_vcpu_affinity(struct domain *d); =20 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate= ); uint64_t get_cpu_idle_time(unsigned int cpu); +bool sched_has_urgent_vcpu(void); =20 /* * Used by idle loop to decide whether there is work to do: --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362802; cv=none; d=zoho.com; s=zohoarc; b=B/J//JNT5xe86/joZvM4wZh9BgQaA590ziW6HwBuZGxNh8G6WVsxuc/EOa9edYiIM0SC0b7QoPVt8raRewoaxZKqz0itKAjUlGxpgOm2NZYNSvqX+NJeifEYnwXEEa2PtoFuF2GEh/TI5B57gRaCKEM36yd01FGKHP2GcegqLJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362802; 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=G+Xqlqnuybj4hUVlm59NbkLHUSG58YGJruHv8b1hLr4=; b=TAxo1WlSe0kjBA2CLngAxPP+QuGbZk/ptniU0SbTfNc7Iz5aLWw3ZcwrJPuumeeO55uANh8hwpWzz6QYXEHVHnEG1ZjKuG7okv5DzbtlLo4LCk5/QA4Wm16RtYb615a1SJoU+Rr9JoA0vDY53IL4QimNB9YfFY+5mU8v28xlVh0= 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 1565362802502717.5051388156352; Fri, 9 Aug 2019 08:00:02 -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 1hw6Lz-0006X0-LZ; Fri, 09 Aug 2019 14:58:51 +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 1hw6Lx-0006TK-48 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:49 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2d70953e-bab6-11e9-ba73-77a104decbdc; Fri, 09 Aug 2019 14:58:42 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 71042B05E; Fri, 9 Aug 2019 14:58:40 +0000 (UTC) X-Inumbo-ID: 2d70953e-bab6-11e9-ba73-77a104decbdc X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:53 +0200 Message-Id: <20190809145833.1020-9-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 08/48] xen/sched: switch vcpu_schedule_lock to unit_schedule_lock 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Rename vcpu_schedule_[un]lock[_irq]() to unit_schedule_[un]lock[_irq]() and let it take a sched_unit pointer instead of a vcpu pointer as parameter. Signed-off-by: Juergen Gross --- xen/common/sched_credit.c | 17 ++++++++-------- xen/common/sched_credit2.c | 40 ++++++++++++++++++------------------- xen/common/sched_null.c | 16 +++++++-------- xen/common/sched_rt.c | 15 +++++++------- xen/common/schedule.c | 49 +++++++++++++++++++++++-------------------= ---- xen/include/xen/sched-if.h | 12 ++++++------ 6 files changed, 75 insertions(+), 74 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 261d2083c7..603793f1d0 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -926,7 +926,8 @@ __csched_vcpu_acct_stop_locked(struct csched_private *p= rv, static void csched_vcpu_acct(struct csched_private *prv, unsigned int cpu) { - struct csched_unit * const svc =3D CSCHED_UNIT(current->sched_unit); + struct sched_unit *currunit =3D current->sched_unit; + struct csched_unit * const svc =3D CSCHED_UNIT(currunit); const struct scheduler *ops =3D per_cpu(scheduler, cpu); =20 ASSERT( current->processor =3D=3D cpu ); @@ -962,7 +963,7 @@ csched_vcpu_acct(struct csched_private *prv, unsigned i= nt cpu) { unsigned int new_cpu; unsigned long flags; - spinlock_t *lock =3D vcpu_schedule_lock_irqsave(current, &flags); + spinlock_t *lock =3D unit_schedule_lock_irqsave(currunit, &flags); =20 /* * If it's been active a while, check if we'd be better off @@ -971,7 +972,7 @@ csched_vcpu_acct(struct csched_private *prv, unsigned i= nt cpu) */ new_cpu =3D _csched_cpu_pick(ops, current, 0); =20 - vcpu_schedule_unlock_irqrestore(lock, flags, current); + unit_schedule_unlock_irqrestore(lock, flags, currunit); =20 if ( new_cpu !=3D cpu ) { @@ -1023,19 +1024,19 @@ csched_unit_insert(const struct scheduler *ops, str= uct sched_unit *unit) BUG_ON( is_idle_vcpu(vc) ); =20 /* csched_res_pick() looks in vc->processor's runq, so we need the loc= k. */ - lock =3D vcpu_schedule_lock_irq(vc); + lock =3D unit_schedule_lock_irq(unit); =20 unit->res =3D csched_res_pick(ops, unit); vc->processor =3D unit->res->processor; =20 spin_unlock_irq(lock); =20 - lock =3D vcpu_schedule_lock_irq(vc); + lock =3D unit_schedule_lock_irq(unit); =20 if ( !__vcpu_on_runq(svc) && vcpu_runnable(vc) && !vc->is_running ) runq_insert(svc); =20 - vcpu_schedule_unlock_irq(lock, vc); + unit_schedule_unlock_irq(lock, unit); =20 SCHED_STAT_CRANK(vcpu_insert); } @@ -2133,12 +2134,12 @@ csched_dump(const struct scheduler *ops) spinlock_t *lock; =20 svc =3D list_entry(iter_svc, struct csched_unit, active_vcpu_e= lem); - lock =3D vcpu_schedule_lock(svc->vcpu); + lock =3D unit_schedule_lock(svc->vcpu->sched_unit); =20 printk("\t%3d: ", ++loop); csched_dump_vcpu(svc); =20 - vcpu_schedule_unlock(lock, svc->vcpu); + unit_schedule_unlock(lock, svc->vcpu->sched_unit); } } =20 diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 02e2855d8d..1798fcf8c4 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -171,7 +171,7 @@ * - runqueue lock * + it is per-runqueue, so: * * cpus in a runqueue take the runqueue lock, when using - * pcpu_schedule_lock() / vcpu_schedule_lock() (and friends), + * pcpu_schedule_lock() / unit_schedule_lock() (and friends), * * a cpu may (try to) take a "remote" runqueue lock, e.g., for * load balancing; * + serializes runqueue operations (removing and inserting vcpus); @@ -1891,7 +1891,7 @@ unpark_parked_vcpus(const struct scheduler *ops, stru= ct list_head *vcpus) unsigned long flags; s_time_t now; =20 - lock =3D vcpu_schedule_lock_irqsave(svc->vcpu, &flags); + lock =3D unit_schedule_lock_irqsave(svc->vcpu->sched_unit, &flags); =20 __clear_bit(_VPF_parked, &svc->vcpu->pause_flags); if ( unlikely(svc->flags & CSFLAG_scheduled) ) @@ -1924,7 +1924,7 @@ unpark_parked_vcpus(const struct scheduler *ops, stru= ct list_head *vcpus) } list_del_init(&svc->parked_elem); =20 - vcpu_schedule_unlock_irqrestore(lock, flags, svc->vcpu); + unit_schedule_unlock_irqrestore(lock, flags, svc->vcpu->sched_unit= ); } } =20 @@ -2163,7 +2163,7 @@ csched2_context_saved(const struct scheduler *ops, st= ruct sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; struct csched2_unit * const svc =3D csched2_unit(unit); - spinlock_t *lock =3D vcpu_schedule_lock_irq(vc); + spinlock_t *lock =3D unit_schedule_lock_irq(unit); s_time_t now =3D NOW(); LIST_HEAD(were_parked); =20 @@ -2195,7 +2195,7 @@ csched2_context_saved(const struct scheduler *ops, st= ruct sched_unit *unit) else if ( !is_idle_vcpu(vc) ) update_load(ops, svc->rqd, svc, -1, now); =20 - vcpu_schedule_unlock_irq(lock, vc); + unit_schedule_unlock_irq(lock, unit); =20 unpark_parked_vcpus(ops, &were_parked); } @@ -2848,14 +2848,14 @@ csched2_dom_cntl( for_each_vcpu ( d, v ) { struct csched2_unit *svc =3D csched2_unit(v->sched_unit); - spinlock_t *lock =3D vcpu_schedule_lock(svc->vcpu); + spinlock_t *lock =3D unit_schedule_lock(svc->vcpu->sched_u= nit); =20 ASSERT(svc->rqd =3D=3D c2rqd(ops, svc->vcpu->processor)); =20 svc->weight =3D sdom->weight; update_max_weight(svc->rqd, svc->weight, old_weight); =20 - vcpu_schedule_unlock(lock, svc->vcpu); + unit_schedule_unlock(lock, svc->vcpu->sched_unit); } } /* Cap */ @@ -2886,7 +2886,7 @@ csched2_dom_cntl( for_each_vcpu ( d, v ) { svc =3D csched2_unit(v->sched_unit); - lock =3D vcpu_schedule_lock(svc->vcpu); + lock =3D unit_schedule_lock(svc->vcpu->sched_unit); /* * Too small quotas would in theory cause a lot of overhea= d, * which then won't happen because, in csched2_runtime(), @@ -2894,7 +2894,7 @@ csched2_dom_cntl( */ svc->budget_quota =3D max(sdom->tot_budget / sdom->nr_vcpu= s, CSCHED2_MIN_TIMER); - vcpu_schedule_unlock(lock, svc->vcpu); + unit_schedule_unlock(lock, svc->vcpu->sched_unit); } =20 if ( sdom->cap =3D=3D 0 ) @@ -2929,7 +2929,7 @@ csched2_dom_cntl( for_each_vcpu ( d, v ) { svc =3D csched2_unit(v->sched_unit); - lock =3D vcpu_schedule_lock(svc->vcpu); + lock =3D unit_schedule_lock(svc->vcpu->sched_unit); if ( v->is_running ) { unsigned int cpu =3D v->processor; @@ -2960,7 +2960,7 @@ csched2_dom_cntl( cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); } svc->budget =3D 0; - vcpu_schedule_unlock(lock, svc->vcpu); + unit_schedule_unlock(lock, svc->vcpu->sched_unit); } } =20 @@ -2976,12 +2976,12 @@ csched2_dom_cntl( for_each_vcpu ( d, v ) { struct csched2_unit *svc =3D csched2_unit(v->sched_unit); - spinlock_t *lock =3D vcpu_schedule_lock(svc->vcpu); + spinlock_t *lock =3D unit_schedule_lock(svc->vcpu->sched_u= nit); =20 svc->budget =3D STIME_MAX; svc->budget_quota =3D 0; =20 - vcpu_schedule_unlock(lock, svc->vcpu); + unit_schedule_unlock(lock, svc->vcpu->sched_unit); } sdom->cap =3D 0; /* @@ -3120,19 +3120,19 @@ csched2_unit_insert(const struct scheduler *ops, st= ruct sched_unit *unit) ASSERT(list_empty(&svc->runq_elem)); =20 /* csched2_res_pick() expects the pcpu lock to be held */ - lock =3D vcpu_schedule_lock_irq(vc); + lock =3D unit_schedule_lock_irq(unit); =20 unit->res =3D csched2_res_pick(ops, unit); vc->processor =3D unit->res->processor; =20 spin_unlock_irq(lock); =20 - lock =3D vcpu_schedule_lock_irq(vc); + lock =3D unit_schedule_lock_irq(unit); =20 /* Add vcpu to runqueue of initial processor */ runq_assign(ops, vc); =20 - vcpu_schedule_unlock_irq(lock, vc); + unit_schedule_unlock_irq(lock, unit); =20 sdom->nr_vcpus++; =20 @@ -3162,11 +3162,11 @@ csched2_unit_remove(const struct scheduler *ops, st= ruct sched_unit *unit) SCHED_STAT_CRANK(vcpu_remove); =20 /* Remove from runqueue */ - lock =3D vcpu_schedule_lock_irq(vc); + lock =3D unit_schedule_lock_irq(unit); =20 runq_deassign(ops, vc); =20 - vcpu_schedule_unlock_irq(lock, vc); + unit_schedule_unlock_irq(lock, unit); =20 svc->sdom->nr_vcpus--; } @@ -3750,12 +3750,12 @@ csched2_dump(const struct scheduler *ops) struct csched2_unit * const svc =3D csched2_unit(v->sched_unit= ); spinlock_t *lock; =20 - lock =3D vcpu_schedule_lock(svc->vcpu); + lock =3D unit_schedule_lock(svc->vcpu->sched_unit); =20 printk("\t%3d: ", ++loop); csched2_dump_vcpu(prv, svc); =20 - vcpu_schedule_unlock(lock, svc->vcpu); + unit_schedule_unlock(lock, svc->vcpu->sched_unit); } } =20 diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index 5f0356c7f8..40ef9f9089 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -309,7 +309,7 @@ pick_res(struct null_private *prv, struct sched_unit *u= nit) * all the pCPUs are busy. * * In fact, there must always be something sane in v->processor, or - * vcpu_schedule_lock() and friends won't work. This is not a problem, + * unit_schedule_lock() and friends won't work. This is not a problem, * as we will actually assign the vCPU to the pCPU we return from here, * only if the pCPU is free. */ @@ -450,11 +450,11 @@ static void null_unit_insert(const struct scheduler *= ops, =20 ASSERT(!is_idle_vcpu(v)); =20 - lock =3D vcpu_schedule_lock_irq(v); + lock =3D unit_schedule_lock_irq(unit); =20 if ( unlikely(!is_vcpu_online(v)) ) { - vcpu_schedule_unlock_irq(lock, v); + unit_schedule_unlock_irq(lock, unit); return; } =20 @@ -464,7 +464,7 @@ static void null_unit_insert(const struct scheduler *op= s, =20 spin_unlock(lock); =20 - lock =3D vcpu_schedule_lock(v); + lock =3D unit_schedule_lock(unit); =20 cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, cpupool_domain_cpumask(v->domain)); @@ -513,7 +513,7 @@ static void null_unit_remove(const struct scheduler *op= s, =20 ASSERT(!is_idle_vcpu(v)); =20 - lock =3D vcpu_schedule_lock_irq(v); + lock =3D unit_schedule_lock_irq(unit); =20 /* If offline, the vcpu shouldn't be assigned, nor in the waitqueue */ if ( unlikely(!is_vcpu_online(v)) ) @@ -536,7 +536,7 @@ static void null_unit_remove(const struct scheduler *op= s, vcpu_deassign(prv, v); =20 out: - vcpu_schedule_unlock_irq(lock, v); + unit_schedule_unlock_irq(lock, unit); =20 SCHED_STAT_CRANK(vcpu_remove); } @@ -935,13 +935,13 @@ static void null_dump(const struct scheduler *ops) struct null_unit * const nvc =3D null_unit(v->sched_unit); spinlock_t *lock; =20 - lock =3D vcpu_schedule_lock(nvc->vcpu); + lock =3D unit_schedule_lock(nvc->vcpu->sched_unit); =20 printk("\t%3d: ", ++loop); dump_vcpu(prv, nvc); printk("\n"); =20 - vcpu_schedule_unlock(lock, nvc->vcpu); + unit_schedule_unlock(lock, nvc->vcpu->sched_unit); } } =20 diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index 3ce85122cc..a279582392 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -177,7 +177,7 @@ static void repl_timer_handler(void *data); /* * System-wide private data, include global RunQueue/DepletedQ * Global lock is referenced by sched_res->schedule_lock from all - * physical cpus. It can be grabbed via vcpu_schedule_lock_irq() + * physical cpus. It can be grabbed via unit_schedule_lock_irq() */ struct rt_private { spinlock_t lock; /* the global coarse-grained lock */ @@ -896,7 +896,7 @@ rt_unit_insert(const struct scheduler *ops, struct sche= d_unit *unit) unit->res =3D rt_res_pick(ops, unit); vc->processor =3D unit->res->processor; =20 - lock =3D vcpu_schedule_lock_irq(vc); + lock =3D unit_schedule_lock_irq(unit); =20 now =3D NOW(); if ( now >=3D svc->cur_deadline ) @@ -909,7 +909,7 @@ rt_unit_insert(const struct scheduler *ops, struct sche= d_unit *unit) if ( !vc->is_running ) runq_insert(ops, svc); } - vcpu_schedule_unlock_irq(lock, vc); + unit_schedule_unlock_irq(lock, unit); =20 SCHED_STAT_CRANK(vcpu_insert); } @@ -920,7 +920,6 @@ rt_unit_insert(const struct scheduler *ops, struct sche= d_unit *unit) static void rt_unit_remove(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct rt_unit * const svc =3D rt_unit(unit); struct rt_dom * const sdom =3D svc->sdom; spinlock_t *lock; @@ -929,14 +928,14 @@ rt_unit_remove(const struct scheduler *ops, struct sc= hed_unit *unit) =20 BUG_ON( sdom =3D=3D NULL ); =20 - lock =3D vcpu_schedule_lock_irq(vc); + lock =3D unit_schedule_lock_irq(unit); if ( vcpu_on_q(svc) ) q_remove(svc); =20 if ( vcpu_on_replq(svc) ) replq_remove(ops,svc); =20 - vcpu_schedule_unlock_irq(lock, vc); + unit_schedule_unlock_irq(lock, unit); } =20 /* @@ -1331,7 +1330,7 @@ rt_context_saved(const struct scheduler *ops, struct = sched_unit *unit) { struct vcpu *vc =3D unit->vcpu_list; struct rt_unit *svc =3D rt_unit(unit); - spinlock_t *lock =3D vcpu_schedule_lock_irq(vc); + spinlock_t *lock =3D unit_schedule_lock_irq(unit); =20 __clear_bit(__RTDS_scheduled, &svc->flags); /* not insert idle vcpu to runq */ @@ -1348,7 +1347,7 @@ rt_context_saved(const struct scheduler *ops, struct = sched_unit *unit) replq_remove(ops, svc); =20 out: - vcpu_schedule_unlock_irq(lock, vc); + unit_schedule_unlock_irq(lock, unit); } =20 /* diff --git a/xen/common/schedule.c b/xen/common/schedule.c index c167eb23f2..e5ae402a29 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -250,7 +250,8 @@ static inline void vcpu_runstate_change( =20 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate) { - spinlock_t *lock =3D likely(v =3D=3D current) ? NULL : vcpu_schedule_l= ock_irq(v); + spinlock_t *lock =3D likely(v =3D=3D current) + ? NULL : unit_schedule_lock_irq(v->sched_unit); s_time_t delta; =20 memcpy(runstate, &v->runstate, sizeof(*runstate)); @@ -259,7 +260,7 @@ void vcpu_runstate_get(struct vcpu *v, struct vcpu_runs= tate_info *runstate) runstate->time[runstate->state] +=3D delta; =20 if ( unlikely(lock !=3D NULL) ) - vcpu_schedule_unlock_irq(lock, v); + unit_schedule_unlock_irq(lock, v->sched_unit); } =20 uint64_t get_cpu_idle_time(unsigned int cpu) @@ -473,7 +474,7 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) migrate_timer(&v->singleshot_timer, new_p); migrate_timer(&v->poll_timer, new_p); =20 - lock =3D vcpu_schedule_lock_irq(v); + lock =3D unit_schedule_lock_irq(v->sched_unit); =20 sched_set_affinity(v, &cpumask_all, &cpumask_all); =20 @@ -482,7 +483,7 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) /* * With v->processor modified we must not * - make any further changes assuming we hold the scheduler lock, - * - use vcpu_schedule_unlock_irq(). + * - use unit_schedule_unlock_irq(). */ spin_unlock_irq(lock); =20 @@ -581,11 +582,11 @@ void vcpu_sleep_nosync(struct vcpu *v) =20 TRACE_2D(TRC_SCHED_SLEEP, v->domain->domain_id, v->vcpu_id); =20 - lock =3D vcpu_schedule_lock_irqsave(v, &flags); + lock =3D unit_schedule_lock_irqsave(v->sched_unit, &flags); =20 vcpu_sleep_nosync_locked(v); =20 - vcpu_schedule_unlock_irqrestore(lock, flags, v); + unit_schedule_unlock_irqrestore(lock, flags, v->sched_unit); } =20 void vcpu_sleep_sync(struct vcpu *v) @@ -605,7 +606,7 @@ void vcpu_wake(struct vcpu *v) =20 TRACE_2D(TRC_SCHED_WAKE, v->domain->domain_id, v->vcpu_id); =20 - lock =3D vcpu_schedule_lock_irqsave(v, &flags); + lock =3D unit_schedule_lock_irqsave(v->sched_unit, &flags); =20 if ( likely(vcpu_runnable(v)) ) { @@ -619,7 +620,7 @@ void vcpu_wake(struct vcpu *v) vcpu_runstate_change(v, RUNSTATE_offline, NOW()); } =20 - vcpu_schedule_unlock_irqrestore(lock, flags, v); + unit_schedule_unlock_irqrestore(lock, flags, v->sched_unit); } =20 void vcpu_unblock(struct vcpu *v) @@ -687,9 +688,9 @@ static void vcpu_move_locked(struct vcpu *v, unsigned i= nt new_cpu) * These steps are encapsulated in the following two functions; they * should be called like this: * - * lock =3D vcpu_schedule_lock_irq(v); + * lock =3D unit_schedule_lock_irq(unit); * vcpu_migrate_start(v); - * vcpu_schedule_unlock_irq(lock, v) + * unit_schedule_unlock_irq(lock, unit) * vcpu_migrate_finish(v); * * vcpu_migrate_finish() will do the work now if it can, or simply @@ -794,12 +795,12 @@ static void vcpu_migrate_finish(struct vcpu *v) */ void vcpu_force_reschedule(struct vcpu *v) { - spinlock_t *lock =3D vcpu_schedule_lock_irq(v); + spinlock_t *lock =3D unit_schedule_lock_irq(v->sched_unit); =20 if ( v->is_running ) vcpu_migrate_start(v); =20 - vcpu_schedule_unlock_irq(lock, v); + unit_schedule_unlock_irq(lock, v->sched_unit); =20 vcpu_migrate_finish(v); } @@ -826,7 +827,7 @@ void restore_vcpu_affinity(struct domain *d) * set v->processor of each of their vCPUs to something that will * make sense for the scheduler of the cpupool in which they are i= n. */ - lock =3D vcpu_schedule_lock_irq(v); + lock =3D unit_schedule_lock_irq(v->sched_unit); =20 cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, cpupool_domain_cpumask(d)); @@ -855,7 +856,7 @@ void restore_vcpu_affinity(struct domain *d) spin_unlock_irq(lock); =20 /* v->processor might have changed, so reacquire the lock. */ - lock =3D vcpu_schedule_lock_irq(v); + lock =3D unit_schedule_lock_irq(v->sched_unit); v->sched_unit->res =3D sched_pick_resource(vcpu_scheduler(v), v->sched_unit); v->processor =3D v->sched_unit->res->processor; @@ -890,7 +891,7 @@ int cpu_disable_scheduler(unsigned int cpu) for_each_vcpu ( d, v ) { unsigned long flags; - spinlock_t *lock =3D vcpu_schedule_lock_irqsave(v, &flags); + spinlock_t *lock =3D unit_schedule_lock_irqsave(v->sched_unit,= &flags); =20 cpumask_and(&online_affinity, v->cpu_hard_affinity, c->cpu_val= id); if ( cpumask_empty(&online_affinity) && @@ -899,7 +900,7 @@ int cpu_disable_scheduler(unsigned int cpu) if ( v->affinity_broken ) { /* The vcpu is temporarily pinned, can't move it. */ - vcpu_schedule_unlock_irqrestore(lock, flags, v); + unit_schedule_unlock_irqrestore(lock, flags, v->sched_= unit); ret =3D -EADDRINUSE; break; } @@ -912,7 +913,7 @@ int cpu_disable_scheduler(unsigned int cpu) if ( v->processor !=3D cpu ) { /* The vcpu is not on this cpu, so we can move on. */ - vcpu_schedule_unlock_irqrestore(lock, flags, v); + unit_schedule_unlock_irqrestore(lock, flags, v->sched_unit= ); continue; } =20 @@ -925,7 +926,7 @@ int cpu_disable_scheduler(unsigned int cpu) * things would have failed before getting in here. */ vcpu_migrate_start(v); - vcpu_schedule_unlock_irqrestore(lock, flags, v); + unit_schedule_unlock_irqrestore(lock, flags, v->sched_unit); =20 vcpu_migrate_finish(v); =20 @@ -989,7 +990,7 @@ static int vcpu_set_affinity( spinlock_t *lock; int ret =3D 0; =20 - lock =3D vcpu_schedule_lock_irq(v); + lock =3D unit_schedule_lock_irq(v->sched_unit); =20 if ( v->affinity_broken ) ret =3D -EBUSY; @@ -1011,7 +1012,7 @@ static int vcpu_set_affinity( vcpu_migrate_start(v); } =20 - vcpu_schedule_unlock_irq(lock, v); + unit_schedule_unlock_irq(lock, v->sched_unit); =20 domain_update_node_affinity(v->domain); =20 @@ -1143,10 +1144,10 @@ static long do_poll(struct sched_poll *sched_poll) long vcpu_yield(void) { struct vcpu * v=3Dcurrent; - spinlock_t *lock =3D vcpu_schedule_lock_irq(v); + spinlock_t *lock =3D unit_schedule_lock_irq(v->sched_unit); =20 sched_yield(vcpu_scheduler(v), v->sched_unit); - vcpu_schedule_unlock_irq(lock, v); + unit_schedule_unlock_irq(lock, v->sched_unit); =20 SCHED_STAT_CRANK(vcpu_yield); =20 @@ -1243,7 +1244,7 @@ int vcpu_temporary_affinity(struct vcpu *v, unsigned = int cpu, uint8_t reason) int ret =3D -EINVAL; bool migrate; =20 - lock =3D vcpu_schedule_lock_irq(v); + lock =3D unit_schedule_lock_irq(v->sched_unit); =20 if ( cpu =3D=3D NR_CPUS ) { @@ -1276,7 +1277,7 @@ int vcpu_temporary_affinity(struct vcpu *v, unsigned = int cpu, uint8_t reason) if ( migrate ) vcpu_migrate_start(v); =20 - vcpu_schedule_unlock_irq(lock, v); + unit_schedule_unlock_irq(lock, v->sched_unit); =20 if ( migrate ) vcpu_migrate_finish(v); diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 212c612374..ed7b7da3a3 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -101,22 +101,22 @@ static inline void kind##_schedule_unlock##irq(spinlo= ck_t *lock \ =20 #define EXTRA_TYPE(arg) sched_lock(pcpu, unsigned int cpu, cpu, ) -sched_lock(vcpu, const struct vcpu *v, v->processor, ) +sched_lock(unit, const struct sched_unit *i, i->res->processor, ) sched_lock(pcpu, unsigned int cpu, cpu, _irq) -sched_lock(vcpu, const struct vcpu *v, v->processor, _irq) +sched_lock(unit, const struct sched_unit *i, i->res->processor, _irq) sched_unlock(pcpu, unsigned int cpu, cpu, ) -sched_unlock(vcpu, const struct vcpu *v, v->processor, ) +sched_unlock(unit, const struct sched_unit *i, i->res->processor, ) sched_unlock(pcpu, unsigned int cpu, cpu, _irq) -sched_unlock(vcpu, const struct vcpu *v, v->processor, _irq) +sched_unlock(unit, const struct sched_unit *i, i->res->processor, _irq) #undef EXTRA_TYPE =20 #define EXTRA_TYPE(arg) , unsigned long arg #define spin_unlock_irqsave spin_unlock_irqrestore sched_lock(pcpu, unsigned int cpu, cpu, _irqsave, *flags) -sched_lock(vcpu, const struct vcpu *v, v->processor, _irqsave, *flags) +sched_lock(unit, const struct sched_unit *i, i->res->processor, _irqsave, = *flags) #undef spin_unlock_irqsave sched_unlock(pcpu, unsigned int cpu, cpu, _irqrestore, flags) -sched_unlock(vcpu, const struct vcpu *v, v->processor, _irqrestore, flags) +sched_unlock(unit, const struct sched_unit *i, i->res->processor, _irqrest= ore, flags) #undef EXTRA_TYPE =20 #undef sched_unlock --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362809; cv=none; d=zoho.com; s=zohoarc; b=a772XXQu0slyHYnCFVR99DLEB0mG6CaQty9H4QXIKb+lv6sSmAgdQToKRVFrkRDurLNDQieVHpyhP2ip/ujLu0+BqYxBky09QwTesIq2525LqlW3s1/O5zO+VFe+oaI9TxF4O0IiGkxL7IEhHgPnTbYnL0RtgpzddlwOQyahNog= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362809; 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=tAOi7ytOVLNpe2pUK51Y8F+iCPJ4afgLlSvjLPSOJKI=; b=eOPJl4/q+YpP0qrUcJE+hqMg5mokxxllS1BVdawvPhGOCbnqemvn/xvQyCeiJvW5vxq224NV475zlW56pVYkucQ1gYEar+2jWxlXeQAa/FmWE/oPcrILHxJ50dIccjwyL/p5gbRDm7737pd2HFQSIK5Nk7Z4nJpZr92Kq1XHAZA= 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 1565362809481392.92438859444644; Fri, 9 Aug 2019 08:00:09 -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 1hw6M1-0006ac-IP; Fri, 09 Aug 2019 14:58:53 +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 1hw6Ly-0006Un-DV for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:50 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2d90b6a2-bab6-11e9-b123-7f9327eaa57d; Fri, 09 Aug 2019 14:58:42 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DEAB5B061; Fri, 9 Aug 2019 14:58:40 +0000 (UTC) X-Inumbo-ID: 2d90b6a2-bab6-11e9-b123-7f9327eaa57d X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:54 +0200 Message-Id: <20190809145833.1020-10-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 09/48] xen/sched: move some per-vcpu items to 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Meng Xu , Jan Beulich , Dario Faggioli 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" Affinities are scheduler specific attributes, they should be per scheduling unit. So move all affinity related fields in struct vcpu to struct sched_unit. While at it switch affinity related functions in sched-if.h to use a pointer to sched_unit instead to vcpu as parameter. The affinity_broken flag must be kept per vcpu as it is related to guest actions on specific vcpus. Signed-off-by: Juergen Gross --- V2: - move affinity_broken back to struct vcpu (Jan Beulich) - print affinities only once per unit (Jan Beulich) --- xen/common/domain.c | 15 ++------ xen/common/domctl.c | 13 ++++--- xen/common/keyhandler.c | 58 ++++++++++++++++-------------- xen/common/sched_credit.c | 18 +++++----- xen/common/sched_credit2.c | 42 +++++++++++----------- xen/common/sched_null.c | 18 +++++----- xen/common/sched_rt.c | 9 ++--- xen/common/schedule.c | 90 ++++++++++++++++++++++++++++--------------= ---- xen/include/xen/sched-if.h | 17 ++++----- xen/include/xen/sched.h | 22 ++++++------ 10 files changed, 163 insertions(+), 139 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 1051bf38a3..5aa40929c0 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -132,10 +132,6 @@ static void vcpu_info_reset(struct vcpu *v) =20 static void vcpu_destroy(struct vcpu *v) { - free_cpumask_var(v->cpu_hard_affinity); - free_cpumask_var(v->cpu_hard_affinity_saved); - free_cpumask_var(v->cpu_soft_affinity); - free_vcpu_struct(v); } =20 @@ -159,11 +155,6 @@ struct vcpu *vcpu_create( =20 grant_table_init_vcpu(v); =20 - if ( !zalloc_cpumask_var(&v->cpu_hard_affinity) || - !zalloc_cpumask_var(&v->cpu_hard_affinity_saved) || - !zalloc_cpumask_var(&v->cpu_soft_affinity) ) - goto fail; - if ( is_idle_domain(d) ) { v->runstate.state =3D RUNSTATE_running; @@ -203,7 +194,6 @@ struct vcpu *vcpu_create( sched_destroy_vcpu(v); fail_wq: destroy_waitqueue_vcpu(v); - fail: vcpu_destroy(v); =20 return NULL; @@ -596,9 +586,10 @@ void domain_update_node_affinity(struct domain *d) */ for_each_vcpu ( d, v ) { - cpumask_or(dom_cpumask, dom_cpumask, v->cpu_hard_affinity); + cpumask_or(dom_cpumask, dom_cpumask, + v->sched_unit->cpu_hard_affinity); cpumask_or(dom_cpumask_soft, dom_cpumask_soft, - v->cpu_soft_affinity); + v->sched_unit->cpu_soft_affinity); } /* Filter out non-online cpus */ cpumask_and(dom_cpumask, dom_cpumask, online); diff --git a/xen/common/domctl.c b/xen/common/domctl.c index b48e408583..ebb37a138e 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -606,6 +606,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) case XEN_DOMCTL_getvcpuaffinity: { struct vcpu *v; + const struct sched_unit *unit; struct xen_domctl_vcpuaffinity *vcpuaff =3D &op->u.vcpuaffinity; =20 ret =3D -EINVAL; @@ -616,6 +617,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) if ( (v =3D d->vcpu[vcpuaff->vcpu]) =3D=3D NULL ) break; =20 + unit =3D v->sched_unit; ret =3D -EINVAL; if ( vcpuaffinity_params_invalid(vcpuaff) ) break; @@ -635,7 +637,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) ret =3D -ENOMEM; break; } - cpumask_copy(old_affinity, v->cpu_hard_affinity); + cpumask_copy(old_affinity, unit->cpu_hard_affinity); =20 if ( !alloc_cpumask_var(&new_affinity) ) { @@ -668,7 +670,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) * For hard affinity, what we return is the intersection of * cpupool's online mask and the new hard affinity. */ - cpumask_and(new_affinity, online, v->cpu_hard_affinity); + cpumask_and(new_affinity, online, unit->cpu_hard_affinity); ret =3D cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_hard, new_affinity); } @@ -697,7 +699,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) * hard affinity. */ cpumask_and(new_affinity, new_affinity, online); - cpumask_and(new_affinity, new_affinity, v->cpu_hard_affini= ty); + cpumask_and(new_affinity, new_affinity, + unit->cpu_hard_affinity); ret =3D cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_soft, new_affinity); } @@ -710,10 +713,10 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u= _domctl) { if ( vcpuaff->flags & XEN_VCPUAFFINITY_HARD ) ret =3D cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_hard, - v->cpu_hard_affinity); + unit->cpu_hard_affinity); if ( vcpuaff->flags & XEN_VCPUAFFINITY_SOFT ) ret =3D cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_soft, - v->cpu_soft_affinity); + unit->cpu_soft_affinity); } break; } diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index 6e4ff890db..0ea7872a44 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -251,6 +251,7 @@ static void reboot_machine(unsigned char key, struct cp= u_user_regs *regs) static void dump_domains(unsigned char key) { struct domain *d; + struct sched_unit *unit; struct vcpu *v; s_time_t now =3D NOW(); =20 @@ -297,33 +298,38 @@ static void dump_domains(unsigned char key) =20 printk("VCPU information and callbacks for domain %u:\n", d->domain_id); - for_each_vcpu ( d, v ) - { - if ( !(v->vcpu_id & 0x3f) ) - process_pending_softirqs(); =20 - printk(" VCPU%d: CPU%d [has=3D%c] poll=3D%d " - "upcall_pend=3D%02x upcall_mask=3D%02x ", - v->vcpu_id, v->processor, - v->is_running ? 'T':'F', v->poll_evtchn, - vcpu_info(v, evtchn_upcall_pending), - !vcpu_event_delivery_is_enabled(v)); - if ( vcpu_cpu_dirty(v) ) - printk("dirty_cpu=3D%u", v->dirty_cpu); - printk("\n"); - printk(" cpu_hard_affinity=3D{%*pbl} cpu_soft_affinity=3D{%= *pbl}\n", - CPUMASK_PR(v->cpu_hard_affinity), - CPUMASK_PR(v->cpu_soft_affinity)); - printk(" pause_count=3D%d pause_flags=3D%lx\n", - atomic_read(&v->pause_count), v->pause_flags); - arch_dump_vcpu_info(v); - - if ( v->periodic_period =3D=3D 0 ) - printk("No periodic timer\n"); - else - printk("%"PRI_stime" Hz periodic timer (period %"PRI_stime= " ms)\n", - 1000000000 / v->periodic_period, - v->periodic_period / 1000000); + for_each_sched_unit ( d, unit ) + { + printk(" UNIT%d affinities: hard=3D{%*pbl} soft=3D{%*pbl}\n", + unit->unit_id, CPUMASK_PR(unit->cpu_hard_affinity), + CPUMASK_PR(unit->cpu_soft_affinity)); + + for_each_sched_unit_vcpu ( unit, v ) + { + if ( !(v->vcpu_id & 0x3f) ) + process_pending_softirqs(); + + printk(" VCPU%d: CPU%d [has=3D%c] poll=3D%d " + "upcall_pend=3D%02x upcall_mask=3D%02x ", + v->vcpu_id, v->processor, + v->is_running ? 'T':'F', v->poll_evtchn, + vcpu_info(v, evtchn_upcall_pending), + !vcpu_event_delivery_is_enabled(v)); + if ( vcpu_cpu_dirty(v) ) + printk("dirty_cpu=3D%u", v->dirty_cpu); + printk("\n"); + printk(" pause_count=3D%d pause_flags=3D%lx\n", + atomic_read(&v->pause_count), v->pause_flags); + arch_dump_vcpu_info(v); + + if ( v->periodic_period =3D=3D 0 ) + printk("No periodic timer\n"); + else + printk("%"PRI_stime" Hz periodic timer (period %"PRI_s= time" ms)\n", + 1000000000 / v->periodic_period, + v->periodic_period / 1000000); + } } } =20 diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 603793f1d0..22438a50e2 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -352,6 +352,7 @@ DEFINE_PER_CPU(unsigned int, last_tickle_cpu); static inline void __runq_tickle(struct csched_unit *new) { unsigned int cpu =3D new->vcpu->processor; + struct sched_unit *unit =3D new->vcpu->sched_unit; struct csched_unit * const cur =3D CSCHED_UNIT(curr_on_cpu(cpu)); struct csched_private *prv =3D CSCHED_PRIV(per_cpu(scheduler, cpu)); cpumask_t mask, idle_mask, *online; @@ -377,7 +378,7 @@ static inline void __runq_tickle(struct csched_unit *ne= w) if ( unlikely(test_bit(CSCHED_FLAG_VCPU_PINNED, &new->flags) && cpumask_test_cpu(cpu, &idle_mask)) ) { - ASSERT(cpumask_cycle(cpu, new->vcpu->cpu_hard_affinity) =3D=3D cpu= ); + ASSERT(cpumask_cycle(cpu, unit->cpu_hard_affinity) =3D=3D cpu); SCHED_STAT_CRANK(tickled_idle_cpu_excl); __cpumask_set_cpu(cpu, &mask); goto tickle; @@ -412,11 +413,11 @@ static inline void __runq_tickle(struct csched_unit *= new) int new_idlers_empty; =20 if ( balance_step =3D=3D BALANCE_SOFT_AFFINITY - && !has_soft_affinity(new->vcpu) ) + && !has_soft_affinity(unit) ) continue; =20 /* Are there idlers suitable for new (for this balance step)? = */ - affinity_balance_cpumask(new->vcpu, balance_step, + affinity_balance_cpumask(unit, balance_step, cpumask_scratch_cpu(cpu)); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), &idle_mask); @@ -445,8 +446,7 @@ static inline void __runq_tickle(struct csched_unit *ne= w) */ if ( new_idlers_empty && new->pri > cur->pri ) { - if ( cpumask_intersects(cur->vcpu->cpu_hard_affinity, - &idle_mask) ) + if ( cpumask_intersects(unit->cpu_hard_affinity, &idle_mas= k) ) { SCHED_VCPU_STAT_CRANK(cur, kicked_away); SCHED_VCPU_STAT_CRANK(cur, migrate_r); @@ -728,7 +728,7 @@ _csched_cpu_pick(const struct scheduler *ops, struct vc= pu *vc, bool_t commit) =20 for_each_affinity_balance_step( balance_step ) { - affinity_balance_cpumask(vc, balance_step, cpus); + affinity_balance_cpumask(vc->sched_unit, balance_step, cpus); cpumask_and(cpus, online, cpus); /* * We want to pick up a pcpu among the ones that are online and @@ -747,7 +747,7 @@ _csched_cpu_pick(const struct scheduler *ops, struct vc= pu *vc, bool_t commit) * balancing step all together. */ if ( balance_step =3D=3D BALANCE_SOFT_AFFINITY && - (!has_soft_affinity(vc) || cpumask_empty(cpus)) ) + (!has_soft_affinity(vc->sched_unit) || cpumask_empty(cpus)) ) continue; =20 /* If present, prefer vc's current processor */ @@ -1647,10 +1647,10 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, i= nt balance_step) * or counter. */ if ( vc->is_running || (balance_step =3D=3D BALANCE_SOFT_AFFINITY = && - !has_soft_affinity(vc)) ) + !has_soft_affinity(vc->sched_unit)) ) continue; =20 - affinity_balance_cpumask(vc, balance_step, cpumask_scratch); + affinity_balance_cpumask(vc->sched_unit, balance_step, cpumask_scr= atch); if ( __csched_vcpu_is_migrateable(prv, vc, cpu, cpumask_scratch) ) { /* We got a candidate. Grab it! */ diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 1798fcf8c4..3dcf40a342 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -700,10 +700,10 @@ static int get_fallback_cpu(struct csched2_unit *svc) { int cpu =3D v->processor; =20 - if ( bs =3D=3D BALANCE_SOFT_AFFINITY && !has_soft_affinity(v) ) + if ( bs =3D=3D BALANCE_SOFT_AFFINITY && !has_soft_affinity(v->sche= d_unit) ) continue; =20 - affinity_balance_cpumask(v, bs, cpumask_scratch_cpu(cpu)); + affinity_balance_cpumask(v->sched_unit, bs, cpumask_scratch_cpu(cp= u)); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), cpupool_domain_cpumask(v->domain)); =20 @@ -1391,10 +1391,10 @@ static s_time_t tickle_score(const struct scheduler= *ops, s_time_t now, */ if ( score > 0 ) { - if ( cpumask_test_cpu(cpu, new->vcpu->cpu_soft_affinity) ) + if ( cpumask_test_cpu(cpu, new->vcpu->sched_unit->cpu_soft_affinit= y) ) score +=3D CSCHED2_CREDIT_INIT; =20 - if ( !cpumask_test_cpu(cpu, cur->vcpu->cpu_soft_affinity) ) + if ( !cpumask_test_cpu(cpu, cur->vcpu->sched_unit->cpu_soft_affini= ty) ) score +=3D CSCHED2_CREDIT_INIT; } =20 @@ -1437,6 +1437,7 @@ runq_tickle(const struct scheduler *ops, struct csche= d2_unit *new, s_time_t now) { int i, ipid =3D -1; s_time_t max =3D 0; + struct sched_unit *unit =3D new->vcpu->sched_unit; unsigned int bs, cpu =3D new->vcpu->processor; struct csched2_runqueue_data *rqd =3D c2rqd(ops, cpu); cpumask_t *online =3D cpupool_domain_cpumask(new->vcpu->domain); @@ -1474,7 +1475,7 @@ runq_tickle(const struct scheduler *ops, struct csche= d2_unit *new, s_time_t now) cpumask_test_cpu(cpu, &rqd->idle) && !cpumask_test_cpu(cpu, &rqd->tickled)) ) { - ASSERT(cpumask_cycle(cpu, new->vcpu->cpu_hard_affinity) =3D=3D cpu= ); + ASSERT(cpumask_cycle(cpu, unit->cpu_hard_affinity) =3D=3D cpu); SCHED_STAT_CRANK(tickled_idle_cpu_excl); ipid =3D cpu; goto tickle; @@ -1483,10 +1484,10 @@ runq_tickle(const struct scheduler *ops, struct csc= hed2_unit *new, s_time_t now) for_each_affinity_balance_step( bs ) { /* Just skip first step, if we don't have a soft affinity */ - if ( bs =3D=3D BALANCE_SOFT_AFFINITY && !has_soft_affinity(new->vc= pu) ) + if ( bs =3D=3D BALANCE_SOFT_AFFINITY && !has_soft_affinity(unit) ) continue; =20 - affinity_balance_cpumask(new->vcpu, bs, cpumask_scratch_cpu(cpu)); + affinity_balance_cpumask(unit, bs, cpumask_scratch_cpu(cpu)); =20 /* * First of all, consider idle cpus, checking if we can just @@ -1558,7 +1559,7 @@ runq_tickle(const struct scheduler *ops, struct csche= d2_unit *new, s_time_t now) ipid =3D cpu; =20 /* If this is in new's soft affinity, just take it */ - if ( cpumask_test_cpu(cpu, new->vcpu->cpu_soft_affinity) ) + if ( cpumask_test_cpu(cpu, unit->cpu_soft_affinity) ) { SCHED_STAT_CRANK(tickled_busy_cpu); goto tickle; @@ -2244,7 +2245,7 @@ csched2_res_pick(const struct scheduler *ops, struct = sched_unit *unit) goto out; } =20 - cpumask_and(cpumask_scratch_cpu(cpu), vc->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity, cpupool_domain_cpumask(vc->domain)); =20 /* @@ -2289,7 +2290,7 @@ csched2_res_pick(const struct scheduler *ops, struct = sched_unit *unit) * * Find both runqueues in one pass. */ - has_soft =3D has_soft_affinity(vc); + has_soft =3D has_soft_affinity(unit); for_each_cpu(i, &prv->active_queues) { struct csched2_runqueue_data *rqd; @@ -2336,7 +2337,7 @@ csched2_res_pick(const struct scheduler *ops, struct = sched_unit *unit) cpumask_t mask; =20 cpumask_and(&mask, cpumask_scratch_cpu(cpu), &rqd->active); - if ( cpumask_intersects(&mask, svc->vcpu->cpu_soft_affinity) ) + if ( cpumask_intersects(&mask, unit->cpu_soft_affinity) ) { min_s_avgload =3D rqd_avgload; min_s_rqi =3D i; @@ -2358,9 +2359,9 @@ csched2_res_pick(const struct scheduler *ops, struct = sched_unit *unit) * Note that, to obtain the soft-affinity mask, we "just" put what= we * have in cpumask_scratch in && with vc->cpu_soft_affinity. This = is * ok because: - * - we know that vc->cpu_hard_affinity and vc->cpu_soft_affinity = have + * - we know that unit->cpu_hard_affinity and ->cpu_soft_affinity = have * a non-empty intersection (because has_soft is true); - * - we have vc->cpu_hard_affinity & cpupool_domain_cpumask() alre= ady + * - we have unit->cpu_hard_affinity & cpupool_domain_cpumask() al= ready * in cpumask_scratch, we do save a lot doing like this. * * It's kind of like open coding affinity_balance_cpumask() but, in @@ -2368,7 +2369,7 @@ csched2_res_pick(const struct scheduler *ops, struct = sched_unit *unit) * cpumask operations. */ cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), - vc->cpu_soft_affinity); + unit->cpu_soft_affinity); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), &prv->rqd[min_s_rqi].active); } @@ -2476,6 +2477,7 @@ static void migrate(const struct scheduler *ops, s_time_t now) { int cpu =3D svc->vcpu->processor; + struct sched_unit *unit =3D svc->vcpu->sched_unit; =20 if ( unlikely(tb_init_done) ) { @@ -2513,7 +2515,7 @@ static void migrate(const struct scheduler *ops, } _runq_deassign(svc); =20 - cpumask_and(cpumask_scratch_cpu(cpu), svc->vcpu->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity, cpupool_domain_cpumask(svc->vcpu->domain)); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), &trqd->active); @@ -2547,7 +2549,7 @@ static bool vcpu_is_migrateable(struct csched2_unit *= svc, struct vcpu *v =3D svc->vcpu; int cpu =3D svc->vcpu->processor; =20 - cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), v->sched_unit->cpu_hard_affinity, cpupool_domain_cpumask(v->domain)); =20 return !(svc->flags & CSFLAG_runq_migrate_request) && @@ -2781,7 +2783,7 @@ csched2_unit_migrate( =20 /* If here, new_cpu must be a valid Credit2 pCPU, and in our affinity.= */ ASSERT(cpumask_test_cpu(new_cpu, &csched2_priv(ops)->initialized)); - ASSERT(cpumask_test_cpu(new_cpu, vc->cpu_hard_affinity)); + ASSERT(cpumask_test_cpu(new_cpu, unit->cpu_hard_affinity)); =20 trqd =3D c2rqd(ops, new_cpu); =20 @@ -3321,9 +3323,9 @@ runq_candidate(struct csched2_runqueue_data *rqd, } =20 /* If scurr has a soft-affinity, let's check whether cpu is part of it= */ - if ( has_soft_affinity(scurr->vcpu) ) + if ( has_soft_affinity(scurr->vcpu->sched_unit) ) { - affinity_balance_cpumask(scurr->vcpu, BALANCE_SOFT_AFFINITY, + affinity_balance_cpumask(scurr->vcpu->sched_unit, BALANCE_SOFT_AFF= INITY, cpumask_scratch); if ( unlikely(!cpumask_test_cpu(cpu, cpumask_scratch)) ) { @@ -3378,7 +3380,7 @@ runq_candidate(struct csched2_runqueue_data *rqd, } =20 /* Only consider vcpus that are allowed to run on this processor. = */ - if ( !cpumask_test_cpu(cpu, svc->vcpu->cpu_hard_affinity) ) + if ( !cpumask_test_cpu(cpu, svc->vcpu->sched_unit->cpu_hard_affini= ty) ) { (*skipped)++; continue; diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index 40ef9f9089..62c558ee8e 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -122,7 +122,8 @@ static inline struct null_unit *null_unit(const struct = sched_unit *unit) static inline bool vcpu_check_affinity(struct vcpu *v, unsigned int cpu, unsigned int balance_step) { - affinity_balance_cpumask(v, balance_step, cpumask_scratch_cpu(cpu)); + affinity_balance_cpumask(v->sched_unit, balance_step, + cpumask_scratch_cpu(cpu)); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), cpupool_domain_cpumask(v->domain)); =20 @@ -273,10 +274,10 @@ pick_res(struct null_private *prv, struct sched_unit = *unit) =20 for_each_affinity_balance_step( bs ) { - if ( bs =3D=3D BALANCE_SOFT_AFFINITY && !has_soft_affinity(v) ) + if ( bs =3D=3D BALANCE_SOFT_AFFINITY && !has_soft_affinity(unit) ) continue; =20 - affinity_balance_cpumask(v, bs, cpumask_scratch_cpu(cpu)); + affinity_balance_cpumask(unit, bs, cpumask_scratch_cpu(cpu)); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), cp= us); =20 /* @@ -313,7 +314,7 @@ pick_res(struct null_private *prv, struct sched_unit *u= nit) * as we will actually assign the vCPU to the pCPU we return from here, * only if the pCPU is free. */ - cpumask_and(cpumask_scratch_cpu(cpu), cpus, v->cpu_hard_affinity); + cpumask_and(cpumask_scratch_cpu(cpu), cpus, unit->cpu_hard_affinity); new_cpu =3D cpumask_any(cpumask_scratch_cpu(cpu)); =20 out: @@ -396,7 +397,8 @@ static bool vcpu_deassign(struct null_private *prv, str= uct vcpu *v) { list_for_each_entry( wvc, &prv->waitq, waitq_elem ) { - if ( bs =3D=3D BALANCE_SOFT_AFFINITY && !has_soft_affinity(wvc= ->vcpu) ) + if ( bs =3D=3D BALANCE_SOFT_AFFINITY && + !has_soft_affinity(wvc->vcpu->sched_unit) ) continue; =20 if ( vcpu_check_affinity(wvc->vcpu, cpu, bs) ) @@ -466,7 +468,7 @@ static void null_unit_insert(const struct scheduler *op= s, =20 lock =3D unit_schedule_lock(unit); =20 - cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity, cpupool_domain_cpumask(v->domain)); =20 /* If the pCPU is free, we assign v to it */ @@ -579,7 +581,7 @@ static void null_unit_wake(const struct scheduler *ops, list_add_tail(&nvc->waitq_elem, &prv->waitq); spin_unlock(&prv->waitq_lock); =20 - cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity, cpupool_domain_cpumask(v->domain)); =20 if ( !cpumask_intersects(&prv->cpus_free, cpumask_scratch_cpu(cpu)= ) ) @@ -848,7 +850,7 @@ static struct task_slice null_schedule(const struct sch= eduler *ops, list_for_each_entry( wvc, &prv->waitq, waitq_elem ) { if ( bs =3D=3D BALANCE_SOFT_AFFINITY && - !has_soft_affinity(wvc->vcpu) ) + !has_soft_affinity(wvc->vcpu->sched_unit) ) continue; =20 if ( vcpu_check_affinity(wvc->vcpu, cpu, bs) ) diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index a279582392..4d29c6dd63 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -327,7 +327,7 @@ rt_dump_vcpu(const struct scheduler *ops, const struct = rt_unit *svc) mask =3D cpumask_scratch_cpu(svc->vcpu->processor); =20 cpupool_mask =3D cpupool_domain_cpumask(svc->vcpu->domain); - cpumask_and(mask, cpupool_mask, svc->vcpu->cpu_hard_affinity); + cpumask_and(mask, cpupool_mask, svc->vcpu->sched_unit->cpu_hard_affini= ty); printk("[%5d.%-2u] cpu %u, (%"PRI_stime", %"PRI_stime")," " cur_b=3D%"PRI_stime" cur_d=3D%"PRI_stime" last_start=3D%"PRI_= stime"\n" " \t\t priority_level=3D%d has_extratime=3D%d\n" @@ -644,7 +644,7 @@ rt_res_pick(const struct scheduler *ops, struct sched_u= nit *unit) int cpu; =20 online =3D cpupool_domain_cpumask(vc->domain); - cpumask_and(&cpus, online, vc->cpu_hard_affinity); + cpumask_and(&cpus, online, unit->cpu_hard_affinity); =20 cpu =3D cpumask_test_cpu(vc->processor, &cpus) ? vc->processor @@ -1022,7 +1022,8 @@ runq_pick(const struct scheduler *ops, const cpumask_= t *mask) =20 /* mask cpu_hard_affinity & cpupool & mask */ online =3D cpupool_domain_cpumask(iter_svc->vcpu->domain); - cpumask_and(&cpu_common, online, iter_svc->vcpu->cpu_hard_affinity= ); + cpumask_and(&cpu_common, online, + iter_svc->vcpu->sched_unit->cpu_hard_affinity); cpumask_and(&cpu_common, mask, &cpu_common); if ( cpumask_empty(&cpu_common) ) continue; @@ -1191,7 +1192,7 @@ runq_tickle(const struct scheduler *ops, struct rt_un= it *new) return; =20 online =3D cpupool_domain_cpumask(new->vcpu->domain); - cpumask_and(¬_tickled, online, new->vcpu->cpu_hard_affinity); + cpumask_and(¬_tickled, online, new->vcpu->sched_unit->cpu_hard_affi= nity); cpumask_andnot(¬_tickled, ¬_tickled, &prv->tickled); =20 /* diff --git a/xen/common/schedule.c b/xen/common/schedule.c index e5ae402a29..98afbb435f 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -326,6 +326,11 @@ static void sched_free_unit(struct sched_unit *unit) } =20 unit->vcpu_list->sched_unit =3D NULL; + + free_cpumask_var(unit->cpu_hard_affinity); + free_cpumask_var(unit->cpu_hard_affinity_saved); + free_cpumask_var(unit->cpu_soft_affinity); + xfree(unit); } =20 @@ -351,7 +356,16 @@ static struct sched_unit *sched_alloc_unit(struct vcpu= *v) unit->next_in_list =3D *prev_unit; *prev_unit =3D unit; =20 + if ( !zalloc_cpumask_var(&unit->cpu_hard_affinity) || + !zalloc_cpumask_var(&unit->cpu_hard_affinity_saved) || + !zalloc_cpumask_var(&unit->cpu_soft_affinity) ) + goto fail; + return unit; + + fail: + sched_free_unit(unit); + return NULL; } =20 int sched_init_vcpu(struct vcpu *v, unsigned int processor) @@ -740,7 +754,7 @@ static void vcpu_migrate_finish(struct vcpu *v) */ if ( pick_called && (new_lock =3D=3D get_sched_res(new_cpu)->schedule_lock) && - cpumask_test_cpu(new_cpu, v->cpu_hard_affinity) && + cpumask_test_cpu(new_cpu, v->sched_unit->cpu_hard_affinit= y) && cpumask_test_cpu(new_cpu, v->domain->cpupool->cpu_valid) ) break; =20 @@ -816,6 +830,7 @@ void restore_vcpu_affinity(struct domain *d) { spinlock_t *lock; unsigned int old_cpu =3D v->processor; + struct sched_unit *unit =3D v->sched_unit; =20 ASSERT(!vcpu_runnable(v)); =20 @@ -827,17 +842,17 @@ void restore_vcpu_affinity(struct domain *d) * set v->processor of each of their vCPUs to something that will * make sense for the scheduler of the cpupool in which they are i= n. */ - lock =3D unit_schedule_lock_irq(v->sched_unit); + lock =3D unit_schedule_lock_irq(unit); =20 - cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity, cpupool_domain_cpumask(d)); if ( cpumask_empty(cpumask_scratch_cpu(cpu)) ) { if ( v->affinity_broken ) { - sched_set_affinity(v, v->cpu_hard_affinity_saved, NULL); + sched_set_affinity(v, unit->cpu_hard_affinity_saved, NULL); v->affinity_broken =3D 0; - cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affin= ity, cpupool_domain_cpumask(d)); } =20 @@ -845,21 +860,20 @@ void restore_vcpu_affinity(struct domain *d) { printk(XENLOG_DEBUG "Breaking affinity for %pv\n", v); sched_set_affinity(v, &cpumask_all, NULL); - cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, + cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affin= ity, cpupool_domain_cpumask(d)); } } =20 v->processor =3D cpumask_any(cpumask_scratch_cpu(cpu)); - v->sched_unit->res =3D get_sched_res(v->processor); + unit->res =3D get_sched_res(v->processor); =20 spin_unlock_irq(lock); =20 /* v->processor might have changed, so reacquire the lock. */ - lock =3D unit_schedule_lock_irq(v->sched_unit); - v->sched_unit->res =3D sched_pick_resource(vcpu_scheduler(v), - v->sched_unit); - v->processor =3D v->sched_unit->res->processor; + lock =3D unit_schedule_lock_irq(unit); + unit->res =3D sched_pick_resource(vcpu_scheduler(v), unit); + v->processor =3D unit->res->processor; spin_unlock_irq(lock); =20 if ( old_cpu !=3D v->processor ) @@ -891,16 +905,17 @@ int cpu_disable_scheduler(unsigned int cpu) for_each_vcpu ( d, v ) { unsigned long flags; - spinlock_t *lock =3D unit_schedule_lock_irqsave(v->sched_unit,= &flags); + struct sched_unit *unit =3D v->sched_unit; + spinlock_t *lock =3D unit_schedule_lock_irqsave(unit, &flags); =20 - cpumask_and(&online_affinity, v->cpu_hard_affinity, c->cpu_val= id); + cpumask_and(&online_affinity, unit->cpu_hard_affinity, c->cpu_= valid); if ( cpumask_empty(&online_affinity) && - cpumask_test_cpu(cpu, v->cpu_hard_affinity) ) + cpumask_test_cpu(cpu, unit->cpu_hard_affinity) ) { if ( v->affinity_broken ) { /* The vcpu is temporarily pinned, can't move it. */ - unit_schedule_unlock_irqrestore(lock, flags, v->sched_= unit); + unit_schedule_unlock_irqrestore(lock, flags, unit); ret =3D -EADDRINUSE; break; } @@ -913,7 +928,7 @@ int cpu_disable_scheduler(unsigned int cpu) if ( v->processor !=3D cpu ) { /* The vcpu is not on this cpu, so we can move on. */ - unit_schedule_unlock_irqrestore(lock, flags, v->sched_unit= ); + unit_schedule_unlock_irqrestore(lock, flags, unit); continue; } =20 @@ -926,7 +941,7 @@ int cpu_disable_scheduler(unsigned int cpu) * things would have failed before getting in here. */ vcpu_migrate_start(v); - unit_schedule_unlock_irqrestore(lock, flags, v->sched_unit); + unit_schedule_unlock_irqrestore(lock, flags, unit); =20 vcpu_migrate_finish(v); =20 @@ -971,26 +986,29 @@ static int cpu_disable_scheduler_check(unsigned int c= pu) void sched_set_affinity( struct vcpu *v, const cpumask_t *hard, const cpumask_t *soft) { - sched_adjust_affinity(dom_scheduler(v->domain), v->sched_unit, hard, s= oft); + struct sched_unit *unit =3D v->sched_unit; + + sched_adjust_affinity(dom_scheduler(unit->domain), unit, hard, soft); =20 if ( hard ) - cpumask_copy(v->cpu_hard_affinity, hard); + cpumask_copy(unit->cpu_hard_affinity, hard); if ( soft ) - cpumask_copy(v->cpu_soft_affinity, soft); + cpumask_copy(unit->cpu_soft_affinity, soft); =20 - v->soft_aff_effective =3D !cpumask_subset(v->cpu_hard_affinity, - v->cpu_soft_affinity) && - cpumask_intersects(v->cpu_soft_affinity, - v->cpu_hard_affinity); + unit->soft_aff_effective =3D !cpumask_subset(unit->cpu_hard_affinity, + unit->cpu_soft_affinity) && + cpumask_intersects(unit->cpu_soft_affinity, + unit->cpu_hard_affinity); } =20 static int vcpu_set_affinity( struct vcpu *v, const cpumask_t *affinity, const cpumask_t *which) { + struct sched_unit *unit =3D v->sched_unit; spinlock_t *lock; int ret =3D 0; =20 - lock =3D unit_schedule_lock_irq(v->sched_unit); + lock =3D unit_schedule_lock_irq(unit); =20 if ( v->affinity_broken ) ret =3D -EBUSY; @@ -1000,19 +1018,19 @@ static int vcpu_set_affinity( * Tell the scheduler we changes something about affinity, * and ask to re-evaluate vcpu placement. */ - if ( which =3D=3D v->cpu_hard_affinity ) + if ( which =3D=3D unit->cpu_hard_affinity ) { sched_set_affinity(v, affinity, NULL); } else { - ASSERT(which =3D=3D v->cpu_soft_affinity); + ASSERT(which =3D=3D unit->cpu_soft_affinity); sched_set_affinity(v, NULL, affinity); } vcpu_migrate_start(v); } =20 - unit_schedule_unlock_irq(lock, v->sched_unit); + unit_schedule_unlock_irq(lock, unit); =20 domain_update_node_affinity(v->domain); =20 @@ -1031,12 +1049,12 @@ int vcpu_set_hard_affinity(struct vcpu *v, const cp= umask_t *affinity) if ( cpumask_empty(&online_affinity) ) return -EINVAL; =20 - return vcpu_set_affinity(v, affinity, v->cpu_hard_affinity); + return vcpu_set_affinity(v, affinity, v->sched_unit->cpu_hard_affinity= ); } =20 int vcpu_set_soft_affinity(struct vcpu *v, const cpumask_t *affinity) { - return vcpu_set_affinity(v, affinity, v->cpu_soft_affinity); + return vcpu_set_affinity(v, affinity, v->sched_unit->cpu_soft_affinity= ); } =20 /* Block the currently-executing domain until a pertinent event occurs. */ @@ -1240,11 +1258,12 @@ void watchdog_domain_destroy(struct domain *d) */ int vcpu_temporary_affinity(struct vcpu *v, unsigned int cpu, uint8_t reas= on) { + struct sched_unit *unit =3D v->sched_unit; spinlock_t *lock; int ret =3D -EINVAL; bool migrate; =20 - lock =3D unit_schedule_lock_irq(v->sched_unit); + lock =3D unit_schedule_lock_irq(unit); =20 if ( cpu =3D=3D NR_CPUS ) { @@ -1254,7 +1273,7 @@ int vcpu_temporary_affinity(struct vcpu *v, unsigned = int cpu, uint8_t reason) v->affinity_broken &=3D ~reason; } if ( !ret && !v->affinity_broken ) - sched_set_affinity(v, v->cpu_hard_affinity_saved, NULL); + sched_set_affinity(v, unit->cpu_hard_affinity_saved, NULL); } else if ( cpu < nr_cpu_ids ) { @@ -1265,7 +1284,8 @@ int vcpu_temporary_affinity(struct vcpu *v, unsigned = int cpu, uint8_t reason) { if ( !v->affinity_broken ) { - cpumask_copy(v->cpu_hard_affinity_saved, v->cpu_hard_affin= ity); + cpumask_copy(unit->cpu_hard_affinity_saved, + unit->cpu_hard_affinity); sched_set_affinity(v, cpumask_of(cpu), NULL); } v->affinity_broken |=3D reason; @@ -1273,11 +1293,11 @@ int vcpu_temporary_affinity(struct vcpu *v, unsigne= d int cpu, uint8_t reason) } } =20 - migrate =3D !ret && !cpumask_test_cpu(v->processor, v->cpu_hard_affini= ty); + migrate =3D !ret && !cpumask_test_cpu(v->processor, unit->cpu_hard_aff= inity); if ( migrate ) vcpu_migrate_start(v); =20 - unit_schedule_unlock_irq(lock, v->sched_unit); + unit_schedule_unlock_irq(lock, unit); =20 if ( migrate ) vcpu_migrate_finish(v); diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index ed7b7da3a3..6844fd7bc7 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -438,11 +438,11 @@ static inline cpumask_t* cpupool_domain_cpumask(struc= t domain *d) * * The hard affinity is not a subset of soft affinity * * There is an overlap between the soft and hard affinity masks */ -static inline int has_soft_affinity(const struct vcpu *v) +static inline int has_soft_affinity(const struct sched_unit *unit) { - return v->soft_aff_effective && - !cpumask_subset(cpupool_domain_cpumask(v->domain), - v->cpu_soft_affinity); + return unit->soft_aff_effective && + !cpumask_subset(cpupool_domain_cpumask(unit->domain), + unit->cpu_soft_affinity); } =20 /* @@ -452,17 +452,18 @@ static inline int has_soft_affinity(const struct vcpu= *v) * to avoid running a vcpu where it would like, but is not allowed to! */ static inline void -affinity_balance_cpumask(const struct vcpu *v, int step, cpumask_t *mask) +affinity_balance_cpumask(const struct sched_unit *unit, int step, + cpumask_t *mask) { if ( step =3D=3D BALANCE_SOFT_AFFINITY ) { - cpumask_and(mask, v->cpu_soft_affinity, v->cpu_hard_affinity); + cpumask_and(mask, unit->cpu_soft_affinity, unit->cpu_hard_affinity= ); =20 if ( unlikely(cpumask_empty(mask)) ) - cpumask_copy(mask, v->cpu_hard_affinity); + cpumask_copy(mask, unit->cpu_hard_affinity); } else /* step =3D=3D BALANCE_HARD_AFFINITY */ - cpumask_copy(mask, v->cpu_hard_affinity); + cpumask_copy(mask, unit->cpu_hard_affinity); } =20 void sched_rm_cpu(unsigned int cpu); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 575ce9a245..fa2dbf47ee 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -212,9 +212,6 @@ struct vcpu bool hcall_compat; #endif =20 - /* Does soft affinity actually play a role (given hard affinity)? */ - bool soft_aff_effective; - /* The CPU, if any, which is holding onto this VCPU's state. */ #define VCPU_CPU_CLEAN (~0u) unsigned int dirty_cpu; @@ -246,14 +243,6 @@ struct vcpu evtchn_port_t virq_to_evtchn[NR_VIRQS]; spinlock_t virq_lock; =20 - /* Bitmask of CPUs on which this VCPU may run. */ - cpumask_var_t cpu_hard_affinity; - /* Used to save affinity during temporary pinning. */ - cpumask_var_t cpu_hard_affinity_saved; - - /* Bitmask of CPUs on which this VCPU prefers to run. */ - cpumask_var_t cpu_soft_affinity; - /* Tasklet for continue_hypercall_on_cpu(). */ struct tasklet continue_hypercall_tasklet; =20 @@ -282,6 +271,15 @@ struct sched_unit { struct sched_unit *next_in_list; struct sched_resource *res; int unit_id; + + /* Does soft affinity actually play a role (given hard affinity)? */ + bool soft_aff_effective; + /* Bitmask of CPUs on which this VCPU may run. */ + cpumask_var_t cpu_hard_affinity; + /* Used to save affinity during temporary pinning. */ + cpumask_var_t cpu_hard_affinity_saved; + /* Bitmask of CPUs on which this VCPU prefers to run. */ + cpumask_var_t cpu_soft_affinity; }; =20 #define for_each_sched_unit(d, e) \ @@ -983,7 +981,7 @@ static inline bool is_hvm_vcpu(const struct vcpu *v) static inline bool is_hwdom_pinned_vcpu(const struct vcpu *v) { return (is_hardware_domain(v->domain) && - cpumask_weight(v->cpu_hard_affinity) =3D=3D 1); + cpumask_weight(v->sched_unit->cpu_hard_affinity) =3D=3D 1); } =20 #ifdef CONFIG_HAS_PASSTHROUGH --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362794; cv=none; d=zoho.com; s=zohoarc; b=L6DbClM+Kq027Enr/+gbZiTtPenCSMr8R9glRoq1w7bq0Bh1AIJIzfMkSSVonBvS+q8aE25ZSkd3GXZFqG2MmbzIvpAV1P8Vj9yIuLI79VSKgdZQGf2MyXPKTso2TkynBX8SDs9ZZa+pNj206oxOzIe+JwHnbsFvVWWkRI66l5I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362794; 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=NR6P4Zh4XfvxQK2pMV9jBRFdUL9st04tQ+1LFvfhhSs=; b=PzMEqX1Wy+fkKR/WB3r25XPRJDnVMJnyXhV7N3Gh97NBnnhJeQTKiNFi0f2daoWdwpmAgKF2+V5ZySAqp919a+lrh9dR67rnKAx2zTI9QXcSwrpH40SgoanuFsHk+Wrz+xL72+ojhCMpJJXRAYLBAygUoHe4zVIi/XRYlM0ZuV4= 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 1565362794875606.7502680682419; Fri, 9 Aug 2019 07:59:54 -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 1hw6Lu-0006Qn-K6; Fri, 09 Aug 2019 14:58:46 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6Ls-0006PQ-EC for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:44 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2d96e871-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:43 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 505B3B066; Fri, 9 Aug 2019 14:58:41 +0000 (UTC) X-Inumbo-ID: 2d96e871-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:55 +0200 Message-Id: <20190809145833.1020-11-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 10/48] 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Add the following helpers using a sched_unit as input instead of a vcpu: - is_idle_unit() similar to is_idle_vcpu() - is_unit_online() similar to is_vcpu_online() - unit_runnable() like vcpu_runnable() - sched_set_res() to set the current processor of an unit - sched_unit_cpu() to get the current processor of an unit - sched_{set|clear}_pause_flags[_atomic]() to modify pause_flags of the associated vcpu(s) - sched_idle_unit() to get the sched_unit 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 | 21 ++++++++-------- xen/include/xen/sched-if.h | 61 ++++++++++++++++++++++++++++++++++++++++++= +--- 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 22438a50e2..bdb97acd88 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1660,8 +1660,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 =3D cpu; - vc->sched_unit->res =3D get_sched_res(cpu); + sched_set_res(vc->sched_unit, get_sched_res(cpu)); /* * speer will start executing directly on cpu, without having = to * go through runq_insert(). So we must update the runnable co= unt diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 98afbb435f..d1a1103e4a 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -81,7 +81,7 @@ static spinlock_t * sched_idle_switch_sched(struct scheduler *new_ops, unsigned int cpu, void *pdata, void *vdata) { - idle_vcpu[cpu]->sched_unit->priv =3D NULL; + sched_idle_unit(cpu)->priv =3D NULL; =20 return &sched_free_cpu_lock; } @@ -373,12 +373,11 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proc= essor) struct domain *d =3D v->domain; struct sched_unit *unit; =20 - v->processor =3D processor; - if ( (unit =3D sched_alloc_unit(v)) =3D=3D NULL ) return 1; =20 - unit->res =3D get_sched_res(processor); + sched_set_res(unit, get_sched_res(processor)); + /* Initialise the per-vcpu timers. */ init_timer(&v->periodic_timer, vcpu_periodic_timer_fn, v, v->processor); @@ -492,8 +491,7 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) =20 sched_set_affinity(v, &cpumask_all, &cpumask_all); =20 - v->processor =3D new_p; - v->sched_unit->res =3D get_sched_res(new_p); + sched_set_res(v->sched_unit, get_sched_res(new_p)); /* * With v->processor modified we must not * - make any further changes assuming we hold the scheduler lock, @@ -831,8 +829,9 @@ void restore_vcpu_affinity(struct domain *d) spinlock_t *lock; unsigned int old_cpu =3D v->processor; struct sched_unit *unit =3D v->sched_unit; + struct sched_resource *res; =20 - ASSERT(!vcpu_runnable(v)); + ASSERT(!unit_runnable(unit)); =20 /* * Re-assign the initial processor as after resume we have no @@ -865,15 +864,15 @@ void restore_vcpu_affinity(struct domain *d) } } =20 - v->processor =3D cpumask_any(cpumask_scratch_cpu(cpu)); - unit->res =3D get_sched_res(v->processor); + res =3D get_sched_res(cpumask_any(cpumask_scratch_cpu(cpu))); + sched_set_res(unit, res); =20 spin_unlock_irq(lock); =20 /* v->processor might have changed, so reacquire the lock. */ lock =3D unit_schedule_lock_irq(unit); - unit->res =3D sched_pick_resource(vcpu_scheduler(v), unit); - v->processor =3D unit->res->processor; + res =3D sched_pick_resource(vcpu_scheduler(v), unit); + sched_set_res(unit, res); spin_unlock_irq(lock); =20 if ( old_cpu !=3D v->processor ) diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 6844fd7bc7..d503fd2dec 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -59,6 +59,62 @@ static inline void set_sched_res(unsigned int cpu, struc= t sched_resource *res) per_cpu(sched_res, cpu) =3D res; } =20 +static inline bool is_idle_unit(const struct sched_unit *unit) +{ + return is_idle_vcpu(unit->vcpu_list); +} + +static inline bool is_unit_online(const struct sched_unit *unit) +{ + return is_vcpu_online(unit->vcpu_list); +} + +static inline bool unit_runnable(const struct sched_unit *unit) +{ + return vcpu_runnable(unit->vcpu_list); +} + +static inline void sched_set_res(struct sched_unit *unit, + struct sched_resource *res) +{ + unit->vcpu_list->processor =3D res->processor; + unit->res =3D res; +} + +static inline unsigned int sched_unit_cpu(struct sched_unit *unit) +{ + return unit->res->processor; +} + +static inline void sched_set_pause_flags(struct sched_unit *unit, + unsigned int bit) +{ + __set_bit(bit, &unit->vcpu_list->pause_flags); +} + +static inline void sched_clear_pause_flags(struct sched_unit *unit, + unsigned int bit) +{ + __clear_bit(bit, &unit->vcpu_list->pause_flags); +} + +static inline void sched_set_pause_flags_atomic(struct sched_unit *unit, + unsigned int bit) +{ + set_bit(bit, &unit->vcpu_list->pause_flags); +} + +static inline void sched_clear_pause_flags_atomic(struct sched_unit *unit, + unsigned int bit) +{ + clear_bit(bit, &unit->vcpu_list->pause_flags); +} + +static inline struct sched_unit *sched_idle_unit(unsigned int cpu) +{ + return idle_vcpu[cpu]->sched_unit; +} + /* * Scratch space, for avoiding having too many cpumask_t on the stack. * Within each scheduler, when using the scratch mask of one pCPU: @@ -345,10 +401,7 @@ static inline void sched_migrate(const struct schedule= r *s, if ( s->migrate ) s->migrate(s, unit, cpu); else - { - unit->vcpu_list->processor =3D cpu; - unit->res =3D get_sched_res(cpu); - } + sched_set_res(unit, get_sched_res(cpu)); } =20 static inline struct sched_resource *sched_pick_resource( --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362798; cv=none; d=zoho.com; s=zohoarc; b=LX4Uv1QNkpQJVR36DzYzf83YLZeMro3NMzB92/YbxIFksL64NMlnHtLspnuAWlqNdjk6V68LqVNU6RKGdJFbbeFntae7PHilWGgKxJmGhBnu9XqhA7QrHfgMBmpQLAvaN5R0ppQgKaXvIt3o13FZpq3Ub/XI0dn1KXJiLaaO5o8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362798; 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=f4zUmOsE3aGRXx1yuWpC4aXsK1T4F7UYdaDdnx4KQJ0=; b=SzDSOiCaEEQMoaBvnWQaX865vek0o/tRtlE5y4XUTPCMoJuckdMCsUZSoN7QohLhGMmUyOphPfsJBHwBwRN6d6MFiyqeiv+TOxhsALVfswKFR/pr4+eisg1gs0NimZmU7YXty8axkEV/s9SBy2NOni3QQ2htBQqRzsxJddh9yJA= 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 1565362798750581.4233895717567; Fri, 9 Aug 2019 07:59:58 -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 1hw6Lw-0006Rk-Al; Fri, 09 Aug 2019 14:58:48 +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 1hw6Lv-0006R5-81 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:47 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2d95f4be-bab6-11e9-9d3b-a335979818ee; Fri, 09 Aug 2019 14:58:42 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B98FBB077; Fri, 9 Aug 2019 14:58:41 +0000 (UTC) X-Inumbo-ID: 2d95f4be-bab6-11e9-9d3b-a335979818ee X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:56 +0200 Message-Id: <20190809145833.1020-12-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 11/48] xen/sched: rename scheduler related perf counters 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Rename the scheduler related perf counters from vcpu* to unit* where appropriate. Signed-off-by: Juergen Gross --- xen/common/sched_credit.c | 32 ++++++++++++++++---------------- xen/common/sched_credit2.c | 18 +++++++++--------- xen/common/sched_null.c | 18 +++++++++--------- xen/common/sched_rt.c | 16 ++++++++-------- xen/include/xen/perfc_defn.h | 30 +++++++++++++++--------------- 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index bdb97acd88..e667a5decd 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -668,7 +668,7 @@ __csched_vcpu_check(struct vcpu *vc) BUG_ON( !is_idle_vcpu(vc) ); } =20 - SCHED_STAT_CRANK(vcpu_check); + SCHED_STAT_CRANK(unit_check); } #define CSCHED_VCPU_CHECK(_vc) (__csched_vcpu_check(_vc)) #else @@ -692,7 +692,7 @@ __csched_vcpu_is_cache_hot(const struct csched_private = *prv, (NOW() - svc->last_sched_time) < prv->vcpu_migr_delay; =20 if ( hot ) - SCHED_STAT_CRANK(vcpu_hot); + SCHED_STAT_CRANK(unit_hot); =20 return hot; } @@ -881,7 +881,7 @@ __csched_vcpu_acct_start(struct csched_private *prv, st= ruct csched_unit *svc) if ( list_empty(&svc->active_vcpu_elem) ) { SCHED_VCPU_STAT_CRANK(svc, state_active); - SCHED_STAT_CRANK(acct_vcpu_active); + SCHED_STAT_CRANK(acct_unit_active); =20 sdom->active_vcpu_count++; list_add(&svc->active_vcpu_elem, &sdom->active_vcpu); @@ -908,7 +908,7 @@ __csched_vcpu_acct_stop_locked(struct csched_private *p= rv, BUG_ON( list_empty(&svc->active_vcpu_elem) ); =20 SCHED_VCPU_STAT_CRANK(svc, state_idle); - SCHED_STAT_CRANK(acct_vcpu_idle); + SCHED_STAT_CRANK(acct_unit_idle); =20 BUG_ON( prv->weight < sdom->weight ); sdom->active_vcpu_count--; @@ -1010,7 +1010,7 @@ csched_alloc_vdata(const struct scheduler *ops, struc= t sched_unit *unit, svc->pri =3D is_idle_domain(vc->domain) ? CSCHED_PRI_IDLE : CSCHED_PRI_TS_UNDER; SCHED_VCPU_STATS_RESET(svc); - SCHED_STAT_CRANK(vcpu_alloc); + SCHED_STAT_CRANK(unit_alloc); return svc; } =20 @@ -1038,7 +1038,7 @@ csched_unit_insert(const struct scheduler *ops, struc= t sched_unit *unit) =20 unit_schedule_unlock_irq(lock, unit); =20 - SCHED_STAT_CRANK(vcpu_insert); + SCHED_STAT_CRANK(unit_insert); } =20 static void @@ -1058,13 +1058,13 @@ csched_unit_remove(const struct scheduler *ops, str= uct sched_unit *unit) struct csched_unit * const svc =3D CSCHED_UNIT(unit); struct csched_dom * const sdom =3D svc->sdom; =20 - SCHED_STAT_CRANK(vcpu_remove); + SCHED_STAT_CRANK(unit_remove); =20 ASSERT(!__vcpu_on_runq(svc)); =20 if ( test_and_clear_bit(CSCHED_FLAG_VCPU_PARKED, &svc->flags) ) { - SCHED_STAT_CRANK(vcpu_unpark); + SCHED_STAT_CRANK(unit_unpark); vcpu_unpause(svc->vcpu); } =20 @@ -1085,7 +1085,7 @@ csched_unit_sleep(const struct scheduler *ops, struct= sched_unit *unit) struct csched_unit * const svc =3D CSCHED_UNIT(unit); unsigned int cpu =3D vc->processor; =20 - SCHED_STAT_CRANK(vcpu_sleep); + SCHED_STAT_CRANK(unit_sleep); =20 BUG_ON( is_idle_vcpu(vc) ); =20 @@ -1114,19 +1114,19 @@ csched_unit_wake(const struct scheduler *ops, struc= t sched_unit *unit) =20 if ( unlikely(curr_on_cpu(vc->processor) =3D=3D unit) ) { - SCHED_STAT_CRANK(vcpu_wake_running); + SCHED_STAT_CRANK(unit_wake_running); return; } if ( unlikely(__vcpu_on_runq(svc)) ) { - SCHED_STAT_CRANK(vcpu_wake_onrunq); + SCHED_STAT_CRANK(unit_wake_onrunq); return; } =20 if ( likely(vcpu_runnable(vc)) ) - SCHED_STAT_CRANK(vcpu_wake_runnable); + SCHED_STAT_CRANK(unit_wake_runnable); else - SCHED_STAT_CRANK(vcpu_wake_not_runnable); + SCHED_STAT_CRANK(unit_wake_not_runnable); =20 /* * We temporarly boost the priority of awaking VCPUs! @@ -1156,7 +1156,7 @@ csched_unit_wake(const struct scheduler *ops, struct = sched_unit *unit) !test_bit(CSCHED_FLAG_VCPU_PARKED, &svc->flags) ) { TRACE_2D(TRC_CSCHED_BOOST_START, vc->domain->domain_id, vc->vcpu_i= d); - SCHED_STAT_CRANK(vcpu_boost); + SCHED_STAT_CRANK(unit_boost); svc->pri =3D CSCHED_PRI_TS_BOOST; } =20 @@ -1515,7 +1515,7 @@ csched_acct(void* dummy) credit < -credit_cap && !test_and_set_bit(CSCHED_FLAG_VCPU_PARKED, &svc->flag= s) ) { - SCHED_STAT_CRANK(vcpu_park); + SCHED_STAT_CRANK(unit_park); vcpu_pause_nosync(svc->vcpu); } =20 @@ -1539,7 +1539,7 @@ csched_acct(void* dummy) * call to make sure the VCPU's priority is not boosted * if it is woken up here. */ - SCHED_STAT_CRANK(vcpu_unpark); + SCHED_STAT_CRANK(unit_unpark); vcpu_unpause(svc->vcpu); clear_bit(CSCHED_FLAG_VCPU_PARKED, &svc->flags); } diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 3dcf40a342..96ebc8c871 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -2020,7 +2020,7 @@ csched2_vcpu_check(struct vcpu *vc) { BUG_ON( !is_idle_vcpu(vc) ); } - SCHED_STAT_CRANK(vcpu_check); + SCHED_STAT_CRANK(unit_check); } #define CSCHED2_VCPU_CHECK(_vc) (csched2_vcpu_check(_vc)) #else @@ -2067,7 +2067,7 @@ csched2_alloc_vdata(const struct scheduler *ops, stru= ct sched_unit *unit, svc->budget_quota =3D 0; INIT_LIST_HEAD(&svc->parked_elem); =20 - SCHED_STAT_CRANK(vcpu_alloc); + SCHED_STAT_CRANK(unit_alloc); =20 return svc; } @@ -2079,7 +2079,7 @@ csched2_unit_sleep(const struct scheduler *ops, struc= t sched_unit *unit) struct csched2_unit * const svc =3D csched2_unit(unit); =20 ASSERT(!is_idle_vcpu(vc)); - SCHED_STAT_CRANK(vcpu_sleep); + SCHED_STAT_CRANK(unit_sleep); =20 if ( curr_on_cpu(vc->processor) =3D=3D unit ) { @@ -2109,20 +2109,20 @@ csched2_unit_wake(const struct scheduler *ops, stru= ct sched_unit *unit) =20 if ( unlikely(curr_on_cpu(cpu) =3D=3D unit) ) { - SCHED_STAT_CRANK(vcpu_wake_running); + SCHED_STAT_CRANK(unit_wake_running); goto out; } =20 if ( unlikely(vcpu_on_runq(svc)) ) { - SCHED_STAT_CRANK(vcpu_wake_onrunq); + SCHED_STAT_CRANK(unit_wake_onrunq); goto out; } =20 if ( likely(vcpu_runnable(vc)) ) - SCHED_STAT_CRANK(vcpu_wake_runnable); + SCHED_STAT_CRANK(unit_wake_runnable); else - SCHED_STAT_CRANK(vcpu_wake_not_runnable); + SCHED_STAT_CRANK(unit_wake_not_runnable); =20 /* If the context hasn't been saved for this vcpu yet, we can't put it= on * another runqueue. Instead, we set a flag so that it will be put on= the runqueue @@ -3138,7 +3138,7 @@ csched2_unit_insert(const struct scheduler *ops, stru= ct sched_unit *unit) =20 sdom->nr_vcpus++; =20 - SCHED_STAT_CRANK(vcpu_insert); + SCHED_STAT_CRANK(unit_insert); =20 CSCHED2_VCPU_CHECK(vc); } @@ -3161,7 +3161,7 @@ csched2_unit_remove(const struct scheduler *ops, stru= ct sched_unit *unit) ASSERT(!is_idle_vcpu(vc)); ASSERT(list_empty(&svc->runq_elem)); =20 - SCHED_STAT_CRANK(vcpu_remove); + SCHED_STAT_CRANK(unit_remove); =20 /* Remove from runqueue */ lock =3D unit_schedule_lock_irq(unit); diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index 62c558ee8e..fb9b7fc42e 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -199,7 +199,7 @@ static void *null_alloc_vdata(const struct scheduler *o= ps, INIT_LIST_HEAD(&nvc->waitq_elem); nvc->vcpu =3D v; =20 - SCHED_STAT_CRANK(vcpu_alloc); + SCHED_STAT_CRANK(unit_alloc); =20 return nvc; } @@ -502,7 +502,7 @@ static void null_unit_insert(const struct scheduler *op= s, } spin_unlock_irq(lock); =20 - SCHED_STAT_CRANK(vcpu_insert); + SCHED_STAT_CRANK(unit_insert); } =20 static void null_unit_remove(const struct scheduler *ops, @@ -540,7 +540,7 @@ static void null_unit_remove(const struct scheduler *op= s, out: unit_schedule_unlock_irq(lock, unit); =20 - SCHED_STAT_CRANK(vcpu_remove); + SCHED_STAT_CRANK(unit_remove); } =20 static void null_unit_wake(const struct scheduler *ops, @@ -555,21 +555,21 @@ static void null_unit_wake(const struct scheduler *op= s, =20 if ( unlikely(curr_on_cpu(cpu) =3D=3D unit) ) { - SCHED_STAT_CRANK(vcpu_wake_running); + SCHED_STAT_CRANK(unit_wake_running); return; } =20 if ( unlikely(!list_empty(&nvc->waitq_elem)) ) { /* Not exactly "on runq", but close enough for reusing the counter= */ - SCHED_STAT_CRANK(vcpu_wake_onrunq); + SCHED_STAT_CRANK(unit_wake_onrunq); return; } =20 if ( likely(vcpu_runnable(v)) ) - SCHED_STAT_CRANK(vcpu_wake_runnable); + SCHED_STAT_CRANK(unit_wake_runnable); else - SCHED_STAT_CRANK(vcpu_wake_not_runnable); + SCHED_STAT_CRANK(unit_wake_not_runnable); =20 /* * If a vcpu is neither on a pCPU nor in the waitqueue, it means it was @@ -649,7 +649,7 @@ static void null_unit_sleep(const struct scheduler *ops, if ( likely(!tickled && curr_on_cpu(cpu) =3D=3D unit) ) cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); =20 - SCHED_STAT_CRANK(vcpu_sleep); + SCHED_STAT_CRANK(unit_sleep); } =20 static struct sched_resource * @@ -770,7 +770,7 @@ static inline void null_vcpu_check(struct vcpu *v) else BUG_ON(!is_idle_vcpu(v)); =20 - SCHED_STAT_CRANK(vcpu_check); + SCHED_STAT_CRANK(unit_check); } #define NULL_VCPU_CHECK(v) (null_vcpu_check(v)) #else diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index 4d29c6dd63..43c49f23cf 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -862,7 +862,7 @@ rt_alloc_vdata(const struct scheduler *ops, struct sche= d_unit *unit, void *dd) if ( !is_idle_vcpu(vc) ) svc->budget =3D RTDS_DEFAULT_BUDGET; =20 - SCHED_STAT_CRANK(vcpu_alloc); + SCHED_STAT_CRANK(unit_alloc); =20 return svc; } @@ -911,7 +911,7 @@ rt_unit_insert(const struct scheduler *ops, struct sche= d_unit *unit) } unit_schedule_unlock_irq(lock, unit); =20 - SCHED_STAT_CRANK(vcpu_insert); + SCHED_STAT_CRANK(unit_insert); } =20 /* @@ -924,7 +924,7 @@ rt_unit_remove(const struct scheduler *ops, struct sche= d_unit *unit) struct rt_dom * const sdom =3D svc->sdom; spinlock_t *lock; =20 - SCHED_STAT_CRANK(vcpu_remove); + SCHED_STAT_CRANK(unit_remove); =20 BUG_ON( sdom =3D=3D NULL ); =20 @@ -1146,7 +1146,7 @@ rt_unit_sleep(const struct scheduler *ops, struct sch= ed_unit *unit) struct rt_unit * const svc =3D rt_unit(unit); =20 BUG_ON( is_idle_vcpu(vc) ); - SCHED_STAT_CRANK(vcpu_sleep); + SCHED_STAT_CRANK(unit_sleep); =20 if ( curr_on_cpu(vc->processor) =3D=3D unit ) cpu_raise_softirq(vc->processor, SCHEDULE_SOFTIRQ); @@ -1267,21 +1267,21 @@ rt_unit_wake(const struct scheduler *ops, struct sc= hed_unit *unit) =20 if ( unlikely(curr_on_cpu(vc->processor) =3D=3D unit) ) { - SCHED_STAT_CRANK(vcpu_wake_running); + SCHED_STAT_CRANK(unit_wake_running); return; } =20 /* on RunQ/DepletedQ, just update info is ok */ if ( unlikely(vcpu_on_q(svc)) ) { - SCHED_STAT_CRANK(vcpu_wake_onrunq); + SCHED_STAT_CRANK(unit_wake_onrunq); return; } =20 if ( likely(vcpu_runnable(vc)) ) - SCHED_STAT_CRANK(vcpu_wake_runnable); + SCHED_STAT_CRANK(unit_wake_runnable); else - SCHED_STAT_CRANK(vcpu_wake_not_runnable); + SCHED_STAT_CRANK(unit_wake_not_runnable); =20 /* * If a deadline passed while svc was asleep/blocked, we need new diff --git a/xen/include/xen/perfc_defn.h b/xen/include/xen/perfc_defn.h index 1ad4384080..08b182ccd9 100644 --- a/xen/include/xen/perfc_defn.h +++ b/xen/include/xen/perfc_defn.h @@ -21,20 +21,20 @@ PERFCOUNTER(sched_ctx, "sched: context swi= tches") PERFCOUNTER(schedule, "sched: specific scheduler") PERFCOUNTER(dom_init, "sched: dom_init") PERFCOUNTER(dom_destroy, "sched: dom_destroy") -PERFCOUNTER(vcpu_alloc, "sched: vcpu_alloc") -PERFCOUNTER(vcpu_insert, "sched: vcpu_insert") -PERFCOUNTER(vcpu_remove, "sched: vcpu_remove") -PERFCOUNTER(vcpu_sleep, "sched: vcpu_sleep") PERFCOUNTER(vcpu_yield, "sched: vcpu_yield") -PERFCOUNTER(vcpu_wake_running, "sched: vcpu_wake_running") -PERFCOUNTER(vcpu_wake_onrunq, "sched: vcpu_wake_onrunq") -PERFCOUNTER(vcpu_wake_runnable, "sched: vcpu_wake_runnable") -PERFCOUNTER(vcpu_wake_not_runnable, "sched: vcpu_wake_not_runnable") +PERFCOUNTER(unit_alloc, "sched: unit_alloc") +PERFCOUNTER(unit_insert, "sched: unit_insert") +PERFCOUNTER(unit_remove, "sched: unit_remove") +PERFCOUNTER(unit_sleep, "sched: unit_sleep") +PERFCOUNTER(unit_wake_running, "sched: unit_wake_running") +PERFCOUNTER(unit_wake_onrunq, "sched: unit_wake_onrunq") +PERFCOUNTER(unit_wake_runnable, "sched: unit_wake_runnable") +PERFCOUNTER(unit_wake_not_runnable, "sched: unit_wake_not_runnable") PERFCOUNTER(tickled_no_cpu, "sched: tickled_no_cpu") PERFCOUNTER(tickled_idle_cpu, "sched: tickled_idle_cpu") PERFCOUNTER(tickled_idle_cpu_excl, "sched: tickled_idle_cpu_exclusive") PERFCOUNTER(tickled_busy_cpu, "sched: tickled_busy_cpu") -PERFCOUNTER(vcpu_check, "sched: vcpu_check") +PERFCOUNTER(unit_check, "sched: unit_check") =20 /* credit specific counters */ PERFCOUNTER(delay_ms, "csched: delay") @@ -43,11 +43,11 @@ PERFCOUNTER(acct_no_work, "csched: acct_no_wo= rk") PERFCOUNTER(acct_balance, "csched: acct_balance") PERFCOUNTER(acct_reorder, "csched: acct_reorder") PERFCOUNTER(acct_min_credit, "csched: acct_min_credit") -PERFCOUNTER(acct_vcpu_active, "csched: acct_vcpu_active") -PERFCOUNTER(acct_vcpu_idle, "csched: acct_vcpu_idle") -PERFCOUNTER(vcpu_boost, "csched: vcpu_boost") -PERFCOUNTER(vcpu_park, "csched: vcpu_park") -PERFCOUNTER(vcpu_unpark, "csched: vcpu_unpark") +PERFCOUNTER(acct_unit_active, "csched: acct_unit_active") +PERFCOUNTER(acct_unit_idle, "csched: acct_unit_idle") +PERFCOUNTER(unit_boost, "csched: unit_boost") +PERFCOUNTER(unit_park, "csched: unit_park") +PERFCOUNTER(unit_unpark, "csched: unit_unpark") PERFCOUNTER(load_balance_idle, "csched: load_balance_idle") PERFCOUNTER(load_balance_over, "csched: load_balance_over") PERFCOUNTER(load_balance_other, "csched: load_balance_other") @@ -57,7 +57,7 @@ PERFCOUNTER(steal_peer_idle, "csched: steal_peer_i= dle") PERFCOUNTER(migrate_queued, "csched: migrate_queued") PERFCOUNTER(migrate_running, "csched: migrate_running") PERFCOUNTER(migrate_kicked_away, "csched: migrate_kicked_away") -PERFCOUNTER(vcpu_hot, "csched: vcpu_hot") +PERFCOUNTER(unit_hot, "csched: unit_hot") =20 /* credit2 specific counters */ PERFCOUNTER(burn_credits_t2c, "csched2: burn_credits_t2c") --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362789; cv=none; d=zoho.com; s=zohoarc; b=KrnZaOujBiKNXou1SeBJ1HzQNfpetJkgadUWX4X9pXZbpDgterXp+qt3HOUOWGpEN303qGhSoQWwPmc3aqdauRzWc4R8nTWo6SZfttu/cSgbBEe5VCHE/hy5QT0b6TPBpmSE08CWGYOnN93cEN+mhKDGNVHkDEOBbvch2jxuZ4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362789; 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=5DWc/xVXZ5k5IrO/4AY4x5nQKmGJsibT+CsPXBdJLo0=; b=aTXWNMDc860mhvKPzPybuf3lzwTol0TGoTaerq5HOIXFRI/L/VWMLNh/mZxcWzPMNncx0ppjXCLx7JEZ3GPudppHBBm9Q6QlRHvZpEtCqRoJExByZFJ3teUd12lHUCCHUaygmfGAVD7AyXCTmKjvGOhyl7NZVIFeMhB9/8bjCaY= 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 156536278991499.49912827422713; Fri, 9 Aug 2019 07:59:49 -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 1hw6Lu-0006Qa-9f; Fri, 09 Aug 2019 14:58:46 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6Ls-0006PR-Eq for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:44 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2dcc7e57-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:43 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4B790B07B; Fri, 9 Aug 2019 14:58:42 +0000 (UTC) X-Inumbo-ID: 2dcc7e57-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:57 +0200 Message-Id: <20190809145833.1020-13-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 12/48] xen/sched: switch struct task_slice from vcpu to 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 , Robert VanVossen , Dario Faggioli , Julien Grall , Josh Whitehead , Meng Xu , 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" Let the schedulers put a sched_unit pointer into struct task_slice instead of a vcpu pointer. Signed-off-by: Juergen Gross --- xen/common/sched_arinc653.c | 8 ++++---- xen/common/sched_credit.c | 4 ++-- xen/common/sched_credit2.c | 4 ++-- xen/common/sched_null.c | 12 ++++++------ xen/common/sched_rt.c | 2 +- xen/common/schedule.c | 4 ++-- xen/include/xen/sched-if.h | 6 +++--- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c index 25fbc42f74..4136c33e2d 100644 --- a/xen/common/sched_arinc653.c +++ b/xen/common/sched_arinc653.c @@ -554,9 +554,9 @@ a653sched_do_schedule( =20 /* * If there are more domains to run in the current major frame, set - * new_task equal to the address of next domain's VCPU structure. - * Otherwise, set new_task equal to the address of the idle task's VCPU - * structure. + * new_task equal to the address of next domain's sched_unit structure. + * Otherwise, set new_task equal to the address of the idle task's + * sched_unit structure. */ new_task =3D (sched_index < sched_priv->num_schedule_entries) ? sched_priv->schedule[sched_index].vc @@ -592,7 +592,7 @@ a653sched_do_schedule( * of the selected task's VCPU structure. */ ret.time =3D next_switch_time - now; - ret.task =3D new_task; + ret.task =3D new_task->sched_unit; ret.migrated =3D 0; =20 BUG_ON(ret.time <=3D 0); diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index e667a5decd..339702f3ec 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1993,9 +1993,9 @@ out: */ ret.time =3D (is_idle_vcpu(snext->vcpu) ? -1 : tslice); - ret.task =3D snext->vcpu; + ret.task =3D snext->vcpu->sched_unit; =20 - CSCHED_VCPU_CHECK(ret.task); + CSCHED_VCPU_CHECK(ret.task->vcpu_list); return ret; } =20 diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 96ebc8c871..ed83381ddb 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -3637,9 +3637,9 @@ csched2_schedule( * Return task to run next... */ ret.time =3D csched2_runtime(ops, cpu, snext, now); - ret.task =3D snext->vcpu; + ret.task =3D snext->vcpu->sched_unit; =20 - CSCHED2_VCPU_CHECK(ret.task); + CSCHED2_VCPU_CHECK(ret.task->vcpu_list); return ret; } =20 diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index fb9b7fc42e..84507a41c8 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -819,10 +819,10 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, if ( tasklet_work_scheduled ) { trace_var(TRC_SNULL_TASKLET, 1, 0, NULL); - ret.task =3D idle_vcpu[cpu]; + ret.task =3D idle_vcpu[cpu]->sched_unit; } else - ret.task =3D per_cpu(npc, cpu).vcpu; + ret.task =3D per_cpu(npc, cpu).vcpu->sched_unit; ret.migrated =3D 0; ret.time =3D -1; =20 @@ -857,7 +857,7 @@ static struct task_slice null_schedule(const struct sch= eduler *ops, { vcpu_assign(prv, wvc->vcpu, cpu); list_del_init(&wvc->waitq_elem); - ret.task =3D wvc->vcpu; + ret.task =3D wvc->vcpu->sched_unit; goto unlock; } } @@ -869,10 +869,10 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, cpumask_set_cpu(cpu, &prv->cpus_free); } =20 - if ( unlikely(ret.task =3D=3D NULL || !vcpu_runnable(ret.task)) ) - ret.task =3D idle_vcpu[cpu]; + if ( unlikely(ret.task =3D=3D NULL || !unit_runnable(ret.task)) ) + ret.task =3D idle_vcpu[cpu]->sched_unit; =20 - NULL_VCPU_CHECK(ret.task); + NULL_VCPU_CHECK(ret.task->vcpu_list); return ret; } =20 diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index 43c49f23cf..b662924483 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -1130,7 +1130,7 @@ rt_schedule(const struct scheduler *ops, s_time_t now= , bool_t tasklet_work_sched } ret.time =3D snext->cur_budget; /* invoke the scheduler next time = */ } - ret.task =3D snext->vcpu; + ret.task =3D snext->vcpu->sched_unit; =20 return ret; } diff --git a/xen/common/schedule.c b/xen/common/schedule.c index d1a1103e4a..8cbb6320c6 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -112,7 +112,7 @@ static struct task_slice sched_idle_schedule( const unsigned int cpu =3D smp_processor_id(); struct task_slice ret =3D { .time =3D -1 }; =20 - ret.task =3D idle_vcpu[cpu]; + ret.task =3D sched_idle_unit(cpu); return ret; } =20 @@ -1616,7 +1616,7 @@ static void schedule(void) sched =3D this_cpu(scheduler); next_slice =3D sched->do_schedule(sched, now, tasklet_work_scheduled); =20 - next =3D next_slice.task; + next =3D next_slice.task->vcpu_list; =20 sd->curr =3D next->sched_unit; =20 diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index d503fd2dec..65fa853e90 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -191,9 +191,9 @@ static inline spinlock_t *pcpu_schedule_trylock(unsigne= d int cpu) } =20 struct task_slice { - struct vcpu *task; - s_time_t time; - bool_t migrated; + struct sched_unit *task; + s_time_t time; + bool_t migrated; }; =20 struct scheduler { --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362799; cv=none; d=zoho.com; s=zohoarc; b=PbtP2fGjjjwfsNvvxmyaWKOwQK17HRYOlBCDGnyyF1zDIpgHkWqoaefhkIJCaMqxQfM2W63ezwWWK+gxfXU+wmEpqOPjeYdP1Fn2IoWN1l/xNp65ru1VH/GMWA1AH5DBZifDtZAeuEGCsGfH/XCSE7u/NuyrX50WzbWLikIS6Fk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362799; 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=LQ37il847EyCHevNzmFf5PxVanuzWFhJ3Of8o7n1ySk=; b=YErgnVnPBsavnkKw+jcxIvtrQvM+zPXqH3RGX6BD6q7tYwtcJf3/fZi2dtXQa6NDsZFQqgwWjBQQf2cWGp/CqWSo0ezjNw4zb8FfvIkIQwNW8VaM9MvJ4JDizClSJAW7Hh6i6vXzEgGtp3yyyUbu6v0VLsVxSPR6pkOsDHGhUi8= 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 1565362799561413.2914618089002; Fri, 9 Aug 2019 07:59:59 -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 1hw6M0-0006ZU-VO; Fri, 09 Aug 2019 14:58:52 +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 1hw6Ly-0006Um-Dc for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:50 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2e9834bc-bab6-11e9-94d9-0bc1dfb3a158; Fri, 09 Aug 2019 14:58:44 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AC5A7B087; Fri, 9 Aug 2019 14:58:42 +0000 (UTC) X-Inumbo-ID: 2e9834bc-bab6-11e9-94d9-0bc1dfb3a158 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:58 +0200 Message-Id: <20190809145833.1020-14-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 13/48] xen/sched: add is_running indicator to 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 , Meng Xu , 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" Add an is_running indicator to struct sched_unit which will be set whenever the unit is being scheduled. Switch scheduler code to use unit->is_running instead of vcpu->is_running for scheduling decisions. At the same time introduce a state_entry_time field in struct sched_unit being updated whenever the is_running indicator is changed. Use that new field in the schedulers instead of the similar vcpu field. Signed-off-by: Juergen Gross --- RFC V2: fix arm build, don't drop v->is_running --- xen/common/sched_credit.c | 12 +++++++----- xen/common/sched_credit2.c | 18 +++++++++--------- xen/common/sched_rt.c | 2 +- xen/common/schedule.c | 15 +++++++++++---- xen/include/xen/sched.h | 5 +++++ 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 339702f3ec..143c7543e8 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -709,7 +709,7 @@ __csched_vcpu_is_migrateable(const struct csched_privat= e *prv, struct vcpu *vc, * The caller is supposed to have already checked that vc is also * not running. */ - ASSERT(!vc->is_running); + ASSERT(!vc->sched_unit->is_running); =20 return !__csched_vcpu_is_cache_hot(prv, svc) && cpumask_test_cpu(dest_cpu, mask); @@ -1033,7 +1033,8 @@ csched_unit_insert(const struct scheduler *ops, struc= t sched_unit *unit) =20 lock =3D unit_schedule_lock_irq(unit); =20 - if ( !__vcpu_on_runq(svc) && vcpu_runnable(vc) && !vc->is_running ) + if ( !__vcpu_on_runq(svc) && vcpu_runnable(vc) && + !vc->sched_unit->is_running ) runq_insert(svc); =20 unit_schedule_unlock_irq(lock, unit); @@ -1646,8 +1647,9 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, int= balance_step) * vCPUs with useful soft affinities in some sort of bitmap * or counter. */ - if ( vc->is_running || (balance_step =3D=3D BALANCE_SOFT_AFFINITY = && - !has_soft_affinity(vc->sched_unit)) ) + if ( vc->sched_unit->is_running || + (balance_step =3D=3D BALANCE_SOFT_AFFINITY && + !has_soft_affinity(vc->sched_unit)) ) continue; =20 affinity_balance_cpumask(vc->sched_unit, balance_step, cpumask_scr= atch); @@ -1855,7 +1857,7 @@ csched_schedule( (unsigned char *)&d); } =20 - runtime =3D now - current->runstate.state_entry_time; + runtime =3D now - current->sched_unit->state_entry_time; if ( runtime < 0 ) /* Does this ever happen? */ runtime =3D 0; =20 diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index ed83381ddb..5487d087e1 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -1284,7 +1284,7 @@ runq_insert(const struct scheduler *ops, struct csche= d2_unit *svc) =20 ASSERT(&svc->rqd->runq =3D=3D runq); ASSERT(!is_idle_vcpu(svc->vcpu)); - ASSERT(!svc->vcpu->is_running); + ASSERT(!svc->vcpu->sched_unit->is_running); ASSERT(!(svc->flags & CSFLAG_scheduled)); =20 list_for_each( iter, runq ) @@ -1341,8 +1341,8 @@ static inline bool is_preemptable(const struct csched= 2_unit *svc, if ( ratelimit <=3D CSCHED2_RATELIMIT_TICKLE_TOLERANCE ) return true; =20 - ASSERT(svc->vcpu->is_running); - return now - svc->vcpu->runstate.state_entry_time > + ASSERT(svc->vcpu->sched_unit->is_running); + return now - svc->vcpu->sched_unit->state_entry_time > ratelimit - CSCHED2_RATELIMIT_TICKLE_TOLERANCE; } =20 @@ -2932,7 +2932,7 @@ csched2_dom_cntl( { svc =3D csched2_unit(v->sched_unit); lock =3D unit_schedule_lock(svc->vcpu->sched_unit); - if ( v->is_running ) + if ( v->sched_unit->is_running ) { unsigned int cpu =3D v->processor; struct csched2_runqueue_data *rqd =3D c2rqd(ops, c= pu); @@ -3205,8 +3205,8 @@ csched2_runtime(const struct scheduler *ops, int cpu, if ( prv->ratelimit_us ) { s_time_t ratelimit_min =3D MICROSECS(prv->ratelimit_us); - if ( snext->vcpu->is_running ) - ratelimit_min =3D snext->vcpu->runstate.state_entry_time + + if ( snext->vcpu->sched_unit->is_running ) + ratelimit_min =3D snext->vcpu->sched_unit->state_entry_time + MICROSECS(prv->ratelimit_us) - now; if ( ratelimit_min > min_time ) min_time =3D ratelimit_min; @@ -3303,7 +3303,7 @@ runq_candidate(struct csched2_runqueue_data *rqd, * no point forcing it to do so until rate limiting expires. */ if ( !yield && prv->ratelimit_us && vcpu_runnable(scurr->vcpu) && - (now - scurr->vcpu->runstate.state_entry_time) < + (now - scurr->vcpu->sched_unit->state_entry_time) < MICROSECS(prv->ratelimit_us) ) { if ( unlikely(tb_init_done) ) @@ -3314,7 +3314,7 @@ runq_candidate(struct csched2_runqueue_data *rqd, } d; d.dom =3D scurr->vcpu->domain->domain_id; d.vcpu =3D scurr->vcpu->vcpu_id; - d.runtime =3D now - scurr->vcpu->runstate.state_entry_time; + d.runtime =3D now - scurr->vcpu->sched_unit->state_entry_time; __trace_var(TRC_CSCHED2_RATELIMIT, 1, sizeof(d), (unsigned char *)&d); @@ -3562,7 +3562,7 @@ csched2_schedule( if ( snext !=3D scurr ) { ASSERT(snext->rqd =3D=3D rqd); - ASSERT(!snext->vcpu->is_running); + ASSERT(!snext->vcpu->sched_unit->is_running); =20 runq_remove(snext); __set_bit(__CSFLAG_scheduled, &snext->flags); diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index b662924483..df1a874c97 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -906,7 +906,7 @@ rt_unit_insert(const struct scheduler *ops, struct sche= d_unit *unit) { replq_insert(ops, svc); =20 - if ( !vc->is_running ) + if ( !unit->is_running ) runq_insert(ops, svc); } unit_schedule_unlock_irq(lock, unit); diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 8cbb6320c6..03119af25c 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -407,6 +407,8 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proces= sor) { get_sched_res(v->processor)->curr =3D unit; v->is_running =3D 1; + unit->is_running =3D 1; + unit->state_entry_time =3D NOW(); } else { @@ -727,7 +729,8 @@ static void vcpu_migrate_finish(struct vcpu *v) * context_saved(); and in any case, if the bit is cleared, then * someone else has already done the work so we don't need to. */ - if ( v->is_running || !test_bit(_VPF_migrating, &v->pause_flags) ) + if ( v->sched_unit->is_running || + !test_bit(_VPF_migrating, &v->pause_flags) ) return; =20 old_cpu =3D new_cpu =3D v->processor; @@ -781,7 +784,7 @@ static void vcpu_migrate_finish(struct vcpu *v) * because they both happen in (different) spinlock regions, and those * regions are strictly serialised. */ - if ( v->is_running || + if ( v->sched_unit->is_running || !test_and_clear_bit(_VPF_migrating, &v->pause_flags) ) { sched_spin_unlock_double(old_lock, new_lock, flags); @@ -809,7 +812,7 @@ void vcpu_force_reschedule(struct vcpu *v) { spinlock_t *lock =3D unit_schedule_lock_irq(v->sched_unit); =20 - if ( v->is_running ) + if ( v->sched_unit->is_running ) vcpu_migrate_start(v); =20 unit_schedule_unlock_irq(lock, v->sched_unit); @@ -1663,8 +1666,10 @@ static void schedule(void) * switch, else lost_records resume will not work properly. */ =20 - ASSERT(!next->is_running); + ASSERT(!next->sched_unit->is_running); next->is_running =3D 1; + next->sched_unit->is_running =3D 1; + next->sched_unit->state_entry_time =3D now; =20 pcpu_schedule_unlock_irq(lock, cpu); =20 @@ -1686,6 +1691,8 @@ void context_saved(struct vcpu *prev) smp_wmb(); =20 prev->is_running =3D 0; + prev->sched_unit->is_running =3D 0; + prev->sched_unit->state_entry_time =3D NOW(); =20 /* Check for migration request /after/ clearing running flag. */ smp_mb(); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index fa2dbf47ee..f506c0cbd4 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -272,6 +272,11 @@ struct sched_unit { struct sched_resource *res; int unit_id; =20 + /* Last time unit got (de-)scheduled. */ + uint64_t state_entry_time; + + /* Currently running on a CPU? */ + bool is_running; /* Does soft affinity actually play a role (given hard affinity)? */ bool soft_aff_effective; /* Bitmask of CPUs on which this VCPU may run. */ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362781; cv=none; d=zoho.com; s=zohoarc; b=OyPzg82xxT4T9Ubhu/ZVBYOqnNPlWMIj1ZDcv2v9aV/QhG4sFtzbZ7xk5oe4EWPD+8C1V+2r22/8xeM4gcH8DubVnN7WOoSrp5PFaaEltQ6ZXcP4NTcHYyZbXxdGqf9LkLGhIAxj0La4lKTNes423ohTUL3SYpiBQZemedzJ194= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362781; 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=5/Z/GdxrLSejhGGHXp/OhvI17ua0Uzs4IfYloTkqmgM=; b=MdsBg359Nu1m6VSpBlKeL7+EEzRzwt/ozgn1GdV2Va5aNz7ibBlOHj24RoF5i18vEvc52DiHYGbvcLGFNMotYk7Q6JUIRD5Xe4/CwfPprer2U+OWpIjgADakGbg9+ORj/OIKVnYqe7daFRlFrbpr3OKNrflj3LAvTvwp6mDFITU= 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 1565362781309235.68497625980797; Fri, 9 Aug 2019 07:59:41 -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 1hw6M4-0006f0-0w; Fri, 09 Aug 2019 14:58:56 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6Ly-0006VQ-Vp for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:51 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2e9db398-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:44 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DA8D5AFF3; Fri, 9 Aug 2019 14:58:42 +0000 (UTC) X-Inumbo-ID: 2e9db398-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:57:59 +0200 Message-Id: <20190809145833.1020-15-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 14/48] xen/sched: make null scheduler vcpu agnostic. 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 , George Dunlap , Dario Faggioli 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" Switch null scheduler completely from vcpu to sched_unit usage. Signed-off-by: Juergen Gross --- xen/common/sched_null.c | 333 ++++++++++++++++++++++++--------------------= ---- 1 file changed, 165 insertions(+), 168 deletions(-) diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index 84507a41c8..a630951110 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -18,10 +18,10 @@ =20 /* * The 'null' scheduler always choose to run, on each pCPU, either nothing - * (i.e., the pCPU stays idle) or always the same vCPU. + * (i.e., the pCPU stays idle) or always the same Item. * * It is aimed at supporting static scenarios, where there always are - * less vCPUs than pCPUs (and the vCPUs don't need to move among pCPUs + * less Items than pCPUs (and the Items don't need to move among pCPUs * for any reason) with the least possible overhead. * * Typical usecase are embedded applications, but also HPC, especially @@ -37,8 +37,8 @@ * null tracing events. Check include/public/trace.h for more details. */ #define TRC_SNULL_PICKED_CPU TRC_SCHED_CLASS_EVT(SNULL, 1) -#define TRC_SNULL_VCPU_ASSIGN TRC_SCHED_CLASS_EVT(SNULL, 2) -#define TRC_SNULL_VCPU_DEASSIGN TRC_SCHED_CLASS_EVT(SNULL, 3) +#define TRC_SNULL_UNIT_ASSIGN TRC_SCHED_CLASS_EVT(SNULL, 2) +#define TRC_SNULL_UNIT_DEASSIGN TRC_SCHED_CLASS_EVT(SNULL, 3) #define TRC_SNULL_MIGRATE TRC_SCHED_CLASS_EVT(SNULL, 4) #define TRC_SNULL_SCHEDULE TRC_SCHED_CLASS_EVT(SNULL, 5) #define TRC_SNULL_TASKLET TRC_SCHED_CLASS_EVT(SNULL, 6) @@ -47,13 +47,13 @@ * Locking: * - Scheduler-lock (a.k.a. runqueue lock): * + is per-pCPU; - * + serializes assignment and deassignment of vCPUs to a pCPU. + * + serializes assignment and deassignment of Items to a pCPU. * - Private data lock (a.k.a. private scheduler lock): * + is scheduler-wide; * + serializes accesses to the list of domains in this scheduler. * - Waitqueue lock: * + is scheduler-wide; - * + serialize accesses to the list of vCPUs waiting to be assigned + * + serialize accesses to the list of Items waiting to be assigned * to pCPUs. * * Ordering is: private lock, runqueue lock, waitqueue lock. Or, OTOH, @@ -77,25 +77,25 @@ struct null_private { spinlock_t lock; /* scheduler lock; nests inside cpupool_lock */ struct list_head ndom; /* Domains of this scheduler */ - struct list_head waitq; /* vCPUs not assigned to any pCPU */ + struct list_head waitq; /* Items not assigned to any pCPU */ spinlock_t waitq_lock; /* serializes waitq; nests inside runq locks */ - cpumask_t cpus_free; /* CPUs without a vCPU associated to them */ + cpumask_t cpus_free; /* CPUs without a Item associated to them */ }; =20 /* * Physical CPU */ struct null_pcpu { - struct vcpu *vcpu; + struct sched_unit *unit; }; DEFINE_PER_CPU(struct null_pcpu, npc); =20 /* - * Virtual CPU + * Schedule Item */ struct null_unit { struct list_head waitq_elem; - struct vcpu *vcpu; + struct sched_unit *unit; }; =20 /* @@ -119,13 +119,13 @@ static inline struct null_unit *null_unit(const struc= t sched_unit *unit) return unit->priv; } =20 -static inline bool vcpu_check_affinity(struct vcpu *v, unsigned int cpu, +static inline bool unit_check_affinity(struct sched_unit *unit, + unsigned int cpu, unsigned int balance_step) { - affinity_balance_cpumask(v->sched_unit, balance_step, - cpumask_scratch_cpu(cpu)); + affinity_balance_cpumask(unit, balance_step, cpumask_scratch_cpu(cpu)); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), - cpupool_domain_cpumask(v->domain)); + cpupool_domain_cpumask(unit->domain)); =20 return cpumask_test_cpu(cpu, cpumask_scratch_cpu(cpu)); } @@ -160,9 +160,9 @@ static void null_deinit(struct scheduler *ops) =20 static void init_pdata(struct null_private *prv, unsigned int cpu) { - /* Mark the pCPU as free, and with no vCPU assigned */ + /* Mark the pCPU as free, and with no unit assigned */ cpumask_set_cpu(cpu, &prv->cpus_free); - per_cpu(npc, cpu).vcpu =3D NULL; + per_cpu(npc, cpu).unit =3D NULL; } =20 static void null_init_pdata(const struct scheduler *ops, void *pdata, int = cpu) @@ -183,13 +183,12 @@ static void null_deinit_pdata(const struct scheduler = *ops, void *pcpu, int cpu) ASSERT(!pcpu); =20 cpumask_clear_cpu(cpu, &prv->cpus_free); - per_cpu(npc, cpu).vcpu =3D NULL; + per_cpu(npc, cpu).unit =3D NULL; } =20 static void *null_alloc_vdata(const struct scheduler *ops, struct sched_unit *unit, void *dd) { - struct vcpu *v =3D unit->vcpu_list; struct null_unit *nvc; =20 nvc =3D xzalloc(struct null_unit); @@ -197,7 +196,7 @@ static void *null_alloc_vdata(const struct scheduler *o= ps, return NULL; =20 INIT_LIST_HEAD(&nvc->waitq_elem); - nvc->vcpu =3D v; + nvc->unit =3D unit; =20 SCHED_STAT_CRANK(unit_alloc); =20 @@ -249,15 +248,15 @@ static void null_free_domdata(const struct scheduler = *ops, void *data) } =20 /* - * vCPU to pCPU assignment and placement. This _only_ happens: + * unit to pCPU assignment and placement. This _only_ happens: * - on insert, * - on migrate. * - * Insert occurs when a vCPU joins this scheduler for the first time + * Insert occurs when a unit joins this scheduler for the first time * (e.g., when the domain it's part of is moved to the scheduler's * cpupool). * - * Migration may be necessary if a pCPU (with a vCPU assigned to it) + * Migration may be necessary if a pCPU (with a unit assigned to it) * is removed from the scheduler's cpupool. * * So this is not part of any hot path. @@ -266,9 +265,8 @@ static struct sched_resource * pick_res(struct null_private *prv, struct sched_unit *unit) { unsigned int bs; - struct vcpu *v =3D unit->vcpu_list; - unsigned int cpu =3D v->processor, new_cpu; - cpumask_t *cpus =3D cpupool_domain_cpumask(v->domain); + unsigned int cpu =3D sched_unit_cpu(unit), new_cpu; + cpumask_t *cpus =3D cpupool_domain_cpumask(unit->domain); =20 ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 @@ -283,11 +281,12 @@ pick_res(struct null_private *prv, struct sched_unit = *unit) /* * If our processor is free, or we are assigned to it, and it is a= lso * still valid and part of our affinity, just go for it. - * (Note that we may call vcpu_check_affinity(), but we deliberate= ly + * (Note that we may call unit_check_affinity(), but we deliberate= ly * don't, so we get to keep in the scratch cpumask what we have ju= st * put in it.) */ - if ( likely((per_cpu(npc, cpu).vcpu =3D=3D NULL || per_cpu(npc, cp= u).vcpu =3D=3D v) + if ( likely((per_cpu(npc, cpu).unit =3D=3D NULL || + per_cpu(npc, cpu).unit =3D=3D unit) && cpumask_test_cpu(cpu, cpumask_scratch_cpu(cpu))) ) { new_cpu =3D cpu; @@ -305,13 +304,13 @@ pick_res(struct null_private *prv, struct sched_unit = *unit) =20 /* * If we didn't find any free pCPU, just pick any valid pcpu, even if - * it has another vCPU assigned. This will happen during shutdown and + * it has another Item assigned. This will happen during shutdown and * suspend/resume, but it may also happen during "normal operation", if * all the pCPUs are busy. * * In fact, there must always be something sane in v->processor, or * unit_schedule_lock() and friends won't work. This is not a problem, - * as we will actually assign the vCPU to the pCPU we return from here, + * as we will actually assign the Item to the pCPU we return from here, * only if the pCPU is free. */ cpumask_and(cpumask_scratch_cpu(cpu), cpus, unit->cpu_hard_affinity); @@ -321,11 +320,11 @@ pick_res(struct null_private *prv, struct sched_unit = *unit) if ( unlikely(tb_init_done) ) { struct { - uint16_t vcpu, dom; + uint16_t unit, dom; uint32_t new_cpu; } d; - d.dom =3D v->domain->domain_id; - d.vcpu =3D v->vcpu_id; + d.dom =3D unit->domain->domain_id; + d.unit =3D unit->unit_id; d.new_cpu =3D new_cpu; __trace_var(TRC_SNULL_PICKED_CPU, 1, sizeof(d), &d); } @@ -333,64 +332,64 @@ pick_res(struct null_private *prv, struct sched_unit = *unit) return get_sched_res(new_cpu); } =20 -static void vcpu_assign(struct null_private *prv, struct vcpu *v, +static void unit_assign(struct null_private *prv, struct sched_unit *unit, unsigned int cpu) { - ASSERT(is_vcpu_online(v)); + ASSERT(is_unit_online(unit)); =20 - per_cpu(npc, cpu).vcpu =3D v; - v->processor =3D cpu; - v->sched_unit->res =3D get_sched_res(cpu); + per_cpu(npc, cpu).unit =3D unit; + sched_set_res(unit, get_sched_res(cpu)); cpumask_clear_cpu(cpu, &prv->cpus_free); =20 - dprintk(XENLOG_G_INFO, "%d <-- %pv\n", cpu, v); + dprintk(XENLOG_G_INFO, "%d <-- %pdv%d\n", cpu, unit->domain, unit->uni= t_id); =20 if ( unlikely(tb_init_done) ) { struct { - uint16_t vcpu, dom; + uint16_t unit, dom; uint32_t cpu; } d; - d.dom =3D v->domain->domain_id; - d.vcpu =3D v->vcpu_id; + d.dom =3D unit->domain->domain_id; + d.unit =3D unit->unit_id; d.cpu =3D cpu; - __trace_var(TRC_SNULL_VCPU_ASSIGN, 1, sizeof(d), &d); + __trace_var(TRC_SNULL_UNIT_ASSIGN, 1, sizeof(d), &d); } } =20 /* Returns true if a cpu was tickled */ -static bool vcpu_deassign(struct null_private *prv, struct vcpu *v) +static bool unit_deassign(struct null_private *prv, struct sched_unit *uni= t) { unsigned int bs; - unsigned int cpu =3D v->processor; + unsigned int cpu =3D sched_unit_cpu(unit); struct null_unit *wvc; =20 - ASSERT(list_empty(&null_unit(v->sched_unit)->waitq_elem)); - ASSERT(per_cpu(npc, v->processor).vcpu =3D=3D v); - ASSERT(!cpumask_test_cpu(v->processor, &prv->cpus_free)); + ASSERT(list_empty(&null_unit(unit)->waitq_elem)); + ASSERT(per_cpu(npc, cpu).unit =3D=3D unit); + ASSERT(!cpumask_test_cpu(cpu, &prv->cpus_free)); =20 - per_cpu(npc, cpu).vcpu =3D NULL; + per_cpu(npc, cpu).unit =3D NULL; cpumask_set_cpu(cpu, &prv->cpus_free); =20 - dprintk(XENLOG_G_INFO, "%d <-- NULL (%pv)\n", cpu, v); + dprintk(XENLOG_G_INFO, "%d <-- NULL (%pdv%d)\n", cpu, unit->domain, + unit->unit_id); =20 if ( unlikely(tb_init_done) ) { struct { - uint16_t vcpu, dom; + uint16_t unit, dom; uint32_t cpu; } d; - d.dom =3D v->domain->domain_id; - d.vcpu =3D v->vcpu_id; + d.dom =3D unit->domain->domain_id; + d.unit =3D unit->unit_id; d.cpu =3D cpu; - __trace_var(TRC_SNULL_VCPU_DEASSIGN, 1, sizeof(d), &d); + __trace_var(TRC_SNULL_UNIT_DEASSIGN, 1, sizeof(d), &d); } =20 spin_lock(&prv->waitq_lock); =20 /* - * If v is assigned to a pCPU, let's see if there is someone waiting, - * suitable to be assigned to it (prioritizing vcpus that have + * If unit is assigned to a pCPU, let's see if there is someone waitin= g, + * suitable to be assigned to it (prioritizing units that have * soft-affinity with cpu). */ for_each_affinity_balance_step( bs ) @@ -398,13 +397,13 @@ static bool vcpu_deassign(struct null_private *prv, s= truct vcpu *v) list_for_each_entry( wvc, &prv->waitq, waitq_elem ) { if ( bs =3D=3D BALANCE_SOFT_AFFINITY && - !has_soft_affinity(wvc->vcpu->sched_unit) ) + !has_soft_affinity(wvc->unit) ) continue; =20 - if ( vcpu_check_affinity(wvc->vcpu, cpu, bs) ) + if ( unit_check_affinity(wvc->unit, cpu, bs) ) { list_del_init(&wvc->waitq_elem); - vcpu_assign(prv, wvc->vcpu, cpu); + unit_assign(prv, wvc->unit, cpu); cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); spin_unlock(&prv->waitq_lock); return true; @@ -425,9 +424,9 @@ static spinlock_t *null_switch_sched(struct scheduler *= new_ops, struct null_private *prv =3D null_priv(new_ops); struct null_unit *nvc =3D vdata; =20 - ASSERT(nvc && is_idle_vcpu(nvc->vcpu)); + ASSERT(nvc && is_idle_unit(nvc->unit)); =20 - idle_vcpu[cpu]->sched_unit->priv =3D vdata; + sched_idle_unit(cpu)->priv =3D vdata; =20 /* * We are holding the runqueue lock already (it's been taken in @@ -444,41 +443,40 @@ static spinlock_t *null_switch_sched(struct scheduler= *new_ops, static void null_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); struct null_unit *nvc =3D null_unit(unit); unsigned int cpu; spinlock_t *lock; =20 - ASSERT(!is_idle_vcpu(v)); + ASSERT(!is_idle_unit(unit)); =20 lock =3D unit_schedule_lock_irq(unit); =20 - if ( unlikely(!is_vcpu_online(v)) ) + if ( unlikely(!is_unit_online(unit)) ) { unit_schedule_unlock_irq(lock, unit); return; } =20 retry: - unit->res =3D pick_res(prv, unit); - cpu =3D v->processor =3D unit->res->processor; + sched_set_res(unit, pick_res(prv, unit)); + cpu =3D sched_unit_cpu(unit); =20 spin_unlock(lock); =20 lock =3D unit_schedule_lock(unit); =20 cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity, - cpupool_domain_cpumask(v->domain)); + cpupool_domain_cpumask(unit->domain)); =20 - /* If the pCPU is free, we assign v to it */ - if ( likely(per_cpu(npc, cpu).vcpu =3D=3D NULL) ) + /* If the pCPU is free, we assign unit to it */ + if ( likely(per_cpu(npc, cpu).unit =3D=3D NULL) ) { /* * Insert is followed by vcpu_wake(), so there's no need to poke * the pcpu with the SCHEDULE_SOFTIRQ, as wake will do that. */ - vcpu_assign(prv, v, cpu); + unit_assign(prv, unit, cpu); } else if ( cpumask_intersects(&prv->cpus_free, cpumask_scratch_cpu(cpu)= ) ) { @@ -497,7 +495,8 @@ static void null_unit_insert(const struct scheduler *op= s, */ spin_lock(&prv->waitq_lock); list_add_tail(&nvc->waitq_elem, &prv->waitq); - dprintk(XENLOG_G_WARNING, "WARNING: %pv not assigned to any CPU!\n= ", v); + dprintk(XENLOG_G_WARNING, "WARNING: %pdv%d not assigned to any CPU= !\n", + unit->domain, unit->unit_id); spin_unlock(&prv->waitq_lock); } spin_unlock_irq(lock); @@ -508,24 +507,23 @@ static void null_unit_insert(const struct scheduler *= ops, static void null_unit_remove(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); struct null_unit *nvc =3D null_unit(unit); spinlock_t *lock; =20 - ASSERT(!is_idle_vcpu(v)); + ASSERT(!is_idle_unit(unit)); =20 lock =3D unit_schedule_lock_irq(unit); =20 - /* If offline, the vcpu shouldn't be assigned, nor in the waitqueue */ - if ( unlikely(!is_vcpu_online(v)) ) + /* If offline, the unit shouldn't be assigned, nor in the waitqueue */ + if ( unlikely(!is_unit_online(unit)) ) { - ASSERT(per_cpu(npc, v->processor).vcpu !=3D v); + ASSERT(per_cpu(npc, sched_unit_cpu(unit)).unit !=3D unit); ASSERT(list_empty(&nvc->waitq_elem)); goto out; } =20 - /* If v is in waitqueue, just get it out of there and bail */ + /* If unit is in waitqueue, just get it out of there and bail */ if ( unlikely(!list_empty(&nvc->waitq_elem)) ) { spin_lock(&prv->waitq_lock); @@ -535,7 +533,7 @@ static void null_unit_remove(const struct scheduler *op= s, goto out; } =20 - vcpu_deassign(prv, v); + unit_deassign(prv, unit); =20 out: unit_schedule_unlock_irq(lock, unit); @@ -546,14 +544,13 @@ static void null_unit_remove(const struct scheduler *= ops, static void null_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); struct null_unit *nvc =3D null_unit(unit); - unsigned int cpu =3D v->processor; + unsigned int cpu =3D sched_unit_cpu(unit); =20 - ASSERT(!is_idle_vcpu(v)); + ASSERT(!is_idle_unit(unit)); =20 - if ( unlikely(curr_on_cpu(cpu) =3D=3D unit) ) + if ( unlikely(curr_on_cpu(sched_unit_cpu(unit)) =3D=3D unit) ) { SCHED_STAT_CRANK(unit_wake_running); return; @@ -566,33 +563,33 @@ static void null_unit_wake(const struct scheduler *op= s, return; } =20 - if ( likely(vcpu_runnable(v)) ) + if ( likely(unit_runnable(unit)) ) SCHED_STAT_CRANK(unit_wake_runnable); else SCHED_STAT_CRANK(unit_wake_not_runnable); =20 /* - * If a vcpu is neither on a pCPU nor in the waitqueue, it means it was + * If a unit is neither on a pCPU nor in the waitqueue, it means it was * offline, and that it is now coming back being online. */ - if ( unlikely(per_cpu(npc, cpu).vcpu !=3D v && list_empty(&nvc->waitq_= elem)) ) + if ( unlikely(per_cpu(npc, cpu).unit !=3D unit && list_empty(&nvc->wai= tq_elem)) ) { spin_lock(&prv->waitq_lock); list_add_tail(&nvc->waitq_elem, &prv->waitq); spin_unlock(&prv->waitq_lock); =20 cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity, - cpupool_domain_cpumask(v->domain)); + cpupool_domain_cpumask(unit->domain)); =20 if ( !cpumask_intersects(&prv->cpus_free, cpumask_scratch_cpu(cpu)= ) ) { dprintk(XENLOG_G_WARNING, "WARNING: d%dv%d not assigned to any= CPU!\n", - v->domain->domain_id, v->vcpu_id); + unit->domain->domain_id, unit->unit_id); return; } =20 /* - * Now we would want to assign the vcpu to cpu, but we can't, beca= use + * Now we would want to assign the unit to cpu, but we can't, beca= use * we don't have the lock. So, let's do the following: * - try to remove cpu from the list of free cpus, to avoid races = with * other onlining, inserting or migrating operations; @@ -613,25 +610,24 @@ static void null_unit_wake(const struct scheduler *op= s, } } =20 - /* Note that we get here only for vCPUs assigned to a pCPU */ - cpu_raise_softirq(v->processor, SCHEDULE_SOFTIRQ); + /* Note that we get here only for units assigned to a pCPU */ + cpu_raise_softirq(sched_unit_cpu(unit), SCHEDULE_SOFTIRQ); } =20 static void null_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); - unsigned int cpu =3D v->processor; + unsigned int cpu =3D sched_unit_cpu(unit); bool tickled =3D false; =20 - ASSERT(!is_idle_vcpu(v)); + ASSERT(!is_idle_unit(unit)); =20 - /*=20 - * Check if the vcpu is in the process of being offlined. if yes, + /* + * Check if the unit is in the process of being offlined. If yes, * we need to remove it from either its pCPU or the waitqueue. */ - if ( unlikely(!is_vcpu_online(v)) ) + if ( unlikely(!is_unit_online(unit)) ) { struct null_unit *nvc =3D null_unit(unit); =20 @@ -641,11 +637,11 @@ static void null_unit_sleep(const struct scheduler *o= ps, list_del_init(&nvc->waitq_elem); spin_unlock(&prv->waitq_lock); } - else if ( per_cpu(npc, cpu).vcpu =3D=3D v ) - tickled =3D vcpu_deassign(prv, v); + else if ( per_cpu(npc, cpu).unit =3D=3D unit ) + tickled =3D unit_deassign(prv, unit); } =20 - /* If v is not assigned to a pCPU, or is not running, no need to bothe= r */ + /* If unit is not assigned to a pCPU, or is not running, no need to bo= ther */ if ( likely(!tickled && curr_on_cpu(cpu) =3D=3D unit) ) cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); =20 @@ -655,42 +651,41 @@ static void null_unit_sleep(const struct scheduler *o= ps, static struct sched_resource * null_res_pick(const struct scheduler *ops, struct sched_unit *unit) { - ASSERT(!is_idle_vcpu(unit->vcpu_list)); + ASSERT(!is_idle_unit(unit)); return pick_res(null_priv(ops), unit); } =20 static void null_unit_migrate(const struct scheduler *ops, struct sched_unit *unit, unsigned int new_cp= u) { - struct vcpu *v =3D unit->vcpu_list; struct null_private *prv =3D null_priv(ops); struct null_unit *nvc =3D null_unit(unit); =20 - ASSERT(!is_idle_vcpu(v)); + ASSERT(!is_idle_unit(unit)); =20 - if ( v->processor =3D=3D new_cpu ) + if ( sched_unit_cpu(unit) =3D=3D new_cpu ) return; =20 if ( unlikely(tb_init_done) ) { struct { - uint16_t vcpu, dom; + uint16_t unit, dom; uint16_t cpu, new_cpu; } d; - d.dom =3D v->domain->domain_id; - d.vcpu =3D v->vcpu_id; - d.cpu =3D v->processor; + d.dom =3D unit->domain->domain_id; + d.unit =3D unit->unit_id; + d.cpu =3D sched_unit_cpu(unit); d.new_cpu =3D new_cpu; __trace_var(TRC_SNULL_MIGRATE, 1, sizeof(d), &d); } =20 /* - * If v is assigned to a pCPU, then such pCPU becomes free, and we + * If unit is assigned to a pCPU, then such pCPU becomes free, and we * should look in the waitqueue if anyone else can be assigned to it. */ - if ( likely(per_cpu(npc, v->processor).vcpu =3D=3D v) ) + if ( likely(per_cpu(npc, sched_unit_cpu(unit)).unit =3D=3D unit) ) { - vcpu_deassign(prv, v); + unit_deassign(prv, unit); SCHED_STAT_CRANK(migrate_running); } else if ( !list_empty(&nvc->waitq_elem) ) @@ -699,13 +694,13 @@ static void null_unit_migrate(const struct scheduler = *ops, SCHED_STAT_CRANK(migrated); =20 /* - * If a vcpu is (going) offline, we want it to be neither assigned + * If a unit is (going) offline, we want it to be neither assigned * to a pCPU, nor in the waitqueue. * * If it was on a cpu, we've removed it from there above. If it is * in the waitqueue, we remove it from there now. And then we bail. */ - if ( unlikely(!is_vcpu_online(v)) ) + if ( unlikely(!is_unit_online(unit)) ) { spin_lock(&prv->waitq_lock); list_del_init(&nvc->waitq_elem); @@ -714,32 +709,34 @@ static void null_unit_migrate(const struct scheduler = *ops, } =20 /* - * Let's now consider new_cpu, which is where v is being sent. It can = be - * either free, or have a vCPU already assigned to it. + * Let's now consider new_cpu, which is where unit is being sent. It c= an be + * either free, or have a unit already assigned to it. * - * In the former case, we should assign v to it, and try to get it to = run, + * In the former case we should assign unit to it, and try to get it t= o run, * if possible, according to affinity. * - * In latter, all we can do is to park v in the waitqueue. + * In latter, all we can do is to park unit in the waitqueue. */ - if ( per_cpu(npc, new_cpu).vcpu =3D=3D NULL && - vcpu_check_affinity(v, new_cpu, BALANCE_HARD_AFFINITY) ) + if ( per_cpu(npc, new_cpu).unit =3D=3D NULL && + unit_check_affinity(unit, new_cpu, BALANCE_HARD_AFFINITY) ) { - /* v might have been in the waitqueue, so remove it */ + /* unit might have been in the waitqueue, so remove it */ spin_lock(&prv->waitq_lock); list_del_init(&nvc->waitq_elem); spin_unlock(&prv->waitq_lock); =20 - vcpu_assign(prv, v, new_cpu); + unit_assign(prv, unit, new_cpu); } else { - /* Put v in the waitqueue, if it wasn't there already */ + /* Put unit in the waitqueue, if it wasn't there already */ spin_lock(&prv->waitq_lock); if ( list_empty(&nvc->waitq_elem) ) { list_add_tail(&nvc->waitq_elem, &prv->waitq); - dprintk(XENLOG_G_WARNING, "WARNING: %pv not assigned to any CP= U!\n", v); + dprintk(XENLOG_G_WARNING, + "WARNING: %pdv%d not assigned to any CPU!\n", unit->do= main, + unit->unit_id); } spin_unlock(&prv->waitq_lock); } @@ -753,35 +750,34 @@ static void null_unit_migrate(const struct scheduler = *ops, * by this, will be fixed-up during resume. */ out: - v->processor =3D new_cpu; - unit->res =3D get_sched_res(new_cpu); + sched_set_res(unit, get_sched_res(new_cpu)); } =20 #ifndef NDEBUG -static inline void null_vcpu_check(struct vcpu *v) +static inline void null_unit_check(struct sched_unit *unit) { - struct null_unit * const nvc =3D null_unit(v->sched_unit); - struct null_dom * const ndom =3D v->domain->sched_priv; + struct null_unit * const nvc =3D null_unit(unit); + struct null_dom * const ndom =3D unit->domain->sched_priv; =20 - BUG_ON(nvc->vcpu !=3D v); + BUG_ON(nvc->unit !=3D unit); =20 if ( ndom ) - BUG_ON(is_idle_vcpu(v)); + BUG_ON(is_idle_unit(unit)); else - BUG_ON(!is_idle_vcpu(v)); + BUG_ON(!is_idle_unit(unit)); =20 SCHED_STAT_CRANK(unit_check); } -#define NULL_VCPU_CHECK(v) (null_vcpu_check(v)) +#define NULL_UNIT_CHECK(unit) (null_unit_check(unit)) #else -#define NULL_VCPU_CHECK(v) +#define NULL_UNIT_CHECK(unit) #endif =20 =20 /* * The most simple scheduling function of all times! We either return: - * - the vCPU assigned to the pCPU, if there's one and it can run; - * - the idle vCPU, otherwise. + * - the unit assigned to the pCPU, if there's one and it can run; + * - the idle unit, otherwise. */ static struct task_slice null_schedule(const struct scheduler *ops, s_time_t now, @@ -794,24 +790,24 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, struct task_slice ret; =20 SCHED_STAT_CRANK(schedule); - NULL_VCPU_CHECK(current); + NULL_UNIT_CHECK(current->sched_unit); =20 if ( unlikely(tb_init_done) ) { struct { uint16_t tasklet, cpu; - int16_t vcpu, dom; + int16_t unit, dom; } d; d.cpu =3D cpu; d.tasklet =3D tasklet_work_scheduled; - if ( per_cpu(npc, cpu).vcpu =3D=3D NULL ) + if ( per_cpu(npc, cpu).unit =3D=3D NULL ) { - d.vcpu =3D d.dom =3D -1; + d.unit =3D d.dom =3D -1; } else { - d.vcpu =3D per_cpu(npc, cpu).vcpu->vcpu_id; - d.dom =3D per_cpu(npc, cpu).vcpu->domain->domain_id; + d.unit =3D per_cpu(npc, cpu).unit->unit_id; + d.dom =3D per_cpu(npc, cpu).unit->domain->domain_id; } __trace_var(TRC_SNULL_SCHEDULE, 1, sizeof(d), &d); } @@ -819,16 +815,16 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, if ( tasklet_work_scheduled ) { trace_var(TRC_SNULL_TASKLET, 1, 0, NULL); - ret.task =3D idle_vcpu[cpu]->sched_unit; + ret.task =3D sched_idle_unit(cpu); } else - ret.task =3D per_cpu(npc, cpu).vcpu->sched_unit; + ret.task =3D per_cpu(npc, cpu).unit; ret.migrated =3D 0; ret.time =3D -1; =20 /* * We may be new in the cpupool, or just coming back online. In which - * case, there may be vCPUs in the waitqueue that we can assign to us + * case, there may be units in the waitqueue that we can assign to us * and run. */ if ( unlikely(ret.task =3D=3D NULL) ) @@ -839,10 +835,10 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, goto unlock; =20 /* - * We scan the waitqueue twice, for prioritizing vcpus that have + * We scan the waitqueue twice, for prioritizing units that have * soft-affinity with cpu. This may look like something expensive = to - * do here in null_schedule(), but it's actually fine, beceuse we = do - * it only in cases where a pcpu has no vcpu associated (e.g., as + * do here in null_schedule(), but it's actually fine, because we = do + * it only in cases where a pcpu has no unit associated (e.g., as * said above, the cpu has just joined a cpupool). */ for_each_affinity_balance_step( bs ) @@ -850,14 +846,14 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, list_for_each_entry( wvc, &prv->waitq, waitq_elem ) { if ( bs =3D=3D BALANCE_SOFT_AFFINITY && - !has_soft_affinity(wvc->vcpu->sched_unit) ) + !has_soft_affinity(wvc->unit) ) continue; =20 - if ( vcpu_check_affinity(wvc->vcpu, cpu, bs) ) + if ( unit_check_affinity(wvc->unit, cpu, bs) ) { - vcpu_assign(prv, wvc->vcpu, cpu); + unit_assign(prv, wvc->unit, cpu); list_del_init(&wvc->waitq_elem); - ret.task =3D wvc->vcpu->sched_unit; + ret.task =3D wvc->unit; goto unlock; } } @@ -870,17 +866,17 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, } =20 if ( unlikely(ret.task =3D=3D NULL || !unit_runnable(ret.task)) ) - ret.task =3D idle_vcpu[cpu]->sched_unit; + ret.task =3D sched_idle_unit(cpu); =20 - NULL_VCPU_CHECK(ret.task->vcpu_list); + NULL_UNIT_CHECK(ret.task); return ret; } =20 -static inline void dump_vcpu(struct null_private *prv, struct null_unit *n= vc) +static inline void dump_unit(struct null_private *prv, struct null_unit *n= vc) { - printk("[%i.%i] pcpu=3D%d", nvc->vcpu->domain->domain_id, - nvc->vcpu->vcpu_id, list_empty(&nvc->waitq_elem) ? - nvc->vcpu->processor : -1); + printk("[%i.%i] pcpu=3D%d", nvc->unit->domain->domain_id, + nvc->unit->unit_id, list_empty(&nvc->waitq_elem) ? + sched_unit_cpu(nvc->unit) : -1); } =20 static void null_dump_pcpu(const struct scheduler *ops, int cpu) @@ -895,16 +891,17 @@ static void null_dump_pcpu(const struct scheduler *op= s, int cpu) printk("CPU[%02d] sibling=3D%*pb, core=3D%*pb", cpu, CPUMASK_PR(per_cpu(cpu_sibling_mask, cpu)), CPUMASK_PR(per_cpu(cpu_core_mask, cpu))); - if ( per_cpu(npc, cpu).vcpu !=3D NULL ) - printk(", vcpu=3D%pv", per_cpu(npc, cpu).vcpu); + if ( per_cpu(npc, cpu).unit !=3D NULL ) + printk(", unit=3D%pdv%d", per_cpu(npc, cpu).unit->domain, + per_cpu(npc, cpu).unit->unit_id); printk("\n"); =20 - /* current VCPU (nothing to say if that's the idle vcpu) */ + /* current unit (nothing to say if that's the idle unit) */ nvc =3D null_unit(curr_on_cpu(cpu)); - if ( nvc && !is_idle_vcpu(nvc->vcpu) ) + if ( nvc && !is_idle_unit(nvc->unit) ) { printk("\trun: "); - dump_vcpu(prv, nvc); + dump_unit(prv, nvc); printk("\n"); } =20 @@ -927,23 +924,23 @@ static void null_dump(const struct scheduler *ops) list_for_each( iter, &prv->ndom ) { struct null_dom *ndom; - struct vcpu *v; + struct sched_unit *unit; =20 ndom =3D list_entry(iter, struct null_dom, ndom_elem); =20 printk("\tDomain: %d\n", ndom->dom->domain_id); - for_each_vcpu( ndom->dom, v ) + for_each_sched_unit( ndom->dom, unit ) { - struct null_unit * const nvc =3D null_unit(v->sched_unit); + struct null_unit * const nvc =3D null_unit(unit); spinlock_t *lock; =20 - lock =3D unit_schedule_lock(nvc->vcpu->sched_unit); + lock =3D unit_schedule_lock(unit); =20 printk("\t%3d: ", ++loop); - dump_vcpu(prv, nvc); + dump_unit(prv, nvc); printk("\n"); =20 - unit_schedule_unlock(lock, nvc->vcpu->sched_unit); + unit_schedule_unlock(lock, unit); } } =20 @@ -958,7 +955,7 @@ static void null_dump(const struct scheduler *ops) printk(", "); if ( loop % 24 =3D=3D 0 ) printk("\n\t"); - printk("%pv", nvc->vcpu); + printk("%pdv%d", nvc->unit->domain, nvc->unit->unit_id); } printk("\n"); spin_unlock(&prv->waitq_lock); --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362864; cv=none; d=zoho.com; s=zohoarc; b=OjgeIoyR+DGZxWU4DDgBy99MvQHTYyabC0rRRI9tVKvtrd/1DRAgf1JL7zl4jLWq0iC9Yha0r3V2Gf6yBFHHkyIHFwZb1tD/9gJlyG4DU/HCwir3INHD/QyYZ4ebu4G4AsroBDNNcM6tNo5eNFoYwnaYm5DZOIlb29Juvb73aB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362864; 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=+KMU6VQr27sgBmMSEOAPlqyKq4/Ov4XArpuFoaMRyWk=; b=Jbyo3tXdXKe094i78WQ+rl75zTyudg5qAAXTT1t1YzqndryRTseK277sypvVEOoLqveeVpq1WO/1zJBa2QZw7PhmRGgSjF1pYxUcBgH1i2ETmX5WCcbO/PTwa+bOaTZlEIlbDITezeDwgfcZIM/wP7OVTzJJdpO+fk42nkY5TvQ= 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 1565362864967332.5833773826022; Fri, 9 Aug 2019 08:01:04 -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 1hw6Ms-000050-DM; Fri, 09 Aug 2019 14:59:46 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6MG-00076M-N2 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:59:08 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2eab5001-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:44 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1F91BB03C; Fri, 9 Aug 2019 14:58:43 +0000 (UTC) X-Inumbo-ID: 2eab5001-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:00 +0200 Message-Id: <20190809145833.1020-16-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 15/48] xen/sched: make rt scheduler vcpu agnostic. 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 , George Dunlap , Meng Xu , Dario Faggioli 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" Switch rt scheduler completely from vcpu to sched_unit usage. Signed-off-by: Juergen Gross --- xen/common/sched_rt.c | 356 ++++++++++++++++++++++++----------------------= ---- 1 file changed, 174 insertions(+), 182 deletions(-) diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index df1a874c97..95262aff95 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -36,7 +36,7 @@ * * Migration compensation and resist like credit2 to better use cache; * Lock Holder Problem, using yield? - * Self switch problem: VCPUs of the same domain may preempt each other; + * Self switch problem: UNITs of the same domain may preempt each other; */ =20 /* @@ -44,30 +44,30 @@ * * This scheduler follows the Preemptive Global Earliest Deadline First (E= DF) * theory in real-time field. - * At any scheduling point, the VCPU with earlier deadline has higher prio= rity. - * The scheduler always picks highest priority VCPU to run on a feasible P= CPU. - * A PCPU is feasible if the VCPU can run on this PCPU and (the PCPU is id= le or - * has a lower-priority VCPU running on it.) + * At any scheduling point, the UNIT with earlier deadline has higher prio= rity. + * The scheduler always picks highest priority UNIT to run on a feasible P= CPU. + * A PCPU is feasible if the UNIT can run on this PCPU and (the PCPU is id= le or + * has a lower-priority UNIT running on it.) * - * Each VCPU has a dedicated period, budget and a extratime flag - * The deadline of a VCPU is at the end of each period; - * A VCPU has its budget replenished at the beginning of each period; - * While scheduled, a VCPU burns its budget. - * The VCPU needs to finish its budget before its deadline in each period; - * The VCPU discards its unused budget at the end of each period. - * When a VCPU runs out of budget in a period, if its extratime flag is se= t, - * the VCPU increases its priority_level by 1 and refills its budget; othe= rwise, + * Each UNIT has a dedicated period, budget and a extratime flag + * The deadline of an UNIT is at the end of each period; + * An UNIT has its budget replenished at the beginning of each period; + * While scheduled, an UNIT burns its budget. + * The UNIT needs to finish its budget before its deadline in each period; + * The UNIT discards its unused budget at the end of each period. + * When an UNIT runs out of budget in a period, if its extratime flag is s= et, + * the UNIT increases its priority_level by 1 and refills its budget; othe= rwise, * it has to wait until next period. * - * Each VCPU is implemented as a deferable server. - * When a VCPU has a task running on it, its budget is continuously burned; - * When a VCPU has no task but with budget left, its budget is preserved. + * Each UNIT is implemented as a deferable server. + * When an UNIT has a task running on it, its budget is continuously burne= d; + * When an UNIT has no task but with budget left, its budget is preserved. * * Queue scheme: * A global runqueue and a global depletedqueue for each CPU pool. - * The runqueue holds all runnable VCPUs with budget, + * The runqueue holds all runnable UNITs with budget, * sorted by priority_level and deadline; - * The depletedqueue holds all VCPUs without budget, unsorted; + * The depletedqueue holds all UNITs without budget, unsorted; * * Note: cpumask and cpupool is supported. */ @@ -82,7 +82,7 @@ * in schedule.c * * The functions involes RunQ and needs to grab locks are: - * vcpu_insert, vcpu_remove, context_saved, runq_insert + * unit_insert, unit_remove, context_saved, runq_insert */ =20 =20 @@ -95,7 +95,7 @@ =20 /* * Max period: max delta of time type, because period is added to the time - * a vcpu activates, so this must not overflow. + * an unit activates, so this must not overflow. * Min period: 10 us, considering the scheduling overhead (when period is * too low, scheduling is invoked too frequently, causing high overhead). */ @@ -121,12 +121,12 @@ * Flags */ /* - * RTDS_scheduled: Is this vcpu either running on, or context-switching of= f, + * RTDS_scheduled: Is this unit either running on, or context-switching of= f, * a phyiscal cpu? * + Accessed only with global lock held. * + Set when chosen as next in rt_schedule(). * + Cleared after context switch has been saved in rt_context_saved() - * + Checked in vcpu_wake to see if we can add to the Runqueue, or if we s= hould + * + Checked in unit_wake to see if we can add to the Runqueue, or if we s= hould * set RTDS_delayed_runq_add * + Checked to be false in runq_insert. */ @@ -146,15 +146,15 @@ /* * RTDS_depleted: Does this vcp run out of budget? * This flag is - * + set in burn_budget() if a vcpu has zero budget left; + * + set in burn_budget() if an unit has zero budget left; * + cleared and checked in the repenishment handler, - * for the vcpus that are being replenished. + * for the units that are being replenished. */ #define __RTDS_depleted 3 #define RTDS_depleted (1<<__RTDS_depleted) =20 /* - * RTDS_extratime: Can the vcpu run in the time that is + * RTDS_extratime: Can the unit run in the time that is * not part of any real-time reservation, and would therefore * be otherwise left idle? */ @@ -183,11 +183,11 @@ struct rt_private { spinlock_t lock; /* the global coarse-grained lock */ struct list_head sdom; /* list of availalbe domains, used for dum= p */ =20 - struct list_head runq; /* ordered list of runnable vcpus */ - struct list_head depletedq; /* unordered list of depleted vcpus */ + struct list_head runq; /* ordered list of runnable units */ + struct list_head depletedq; /* unordered list of depleted units */ =20 struct timer repl_timer; /* replenishment timer */ - struct list_head replq; /* ordered list of vcpus that need repleni= shment */ + struct list_head replq; /* ordered list of units that need repleni= shment */ =20 cpumask_t tickled; /* cpus been tickled */ }; @@ -199,18 +199,18 @@ struct rt_unit { struct list_head q_elem; /* on the runq/depletedq list */ struct list_head replq_elem; /* on the replenishment events list */ =20 - /* VCPU parameters, in nanoseconds */ + /* UNIT parameters, in nanoseconds */ s_time_t period; s_time_t budget; =20 - /* VCPU current information in nanosecond */ + /* UNIT current information in nanosecond */ s_time_t cur_budget; /* current budget */ s_time_t last_start; /* last start time */ s_time_t cur_deadline; /* current deadline for EDF */ =20 /* Up-pointers */ struct rt_dom *sdom; - struct vcpu *vcpu; + struct sched_unit *unit; =20 unsigned priority_level; =20 @@ -263,7 +263,7 @@ static inline bool has_extratime(const struct rt_unit *= svc) * and the replenishment events queue. */ static int -vcpu_on_q(const struct rt_unit *svc) +unit_on_q(const struct rt_unit *svc) { return !list_empty(&svc->q_elem); } @@ -281,7 +281,7 @@ replq_elem(struct list_head *elem) } =20 static int -vcpu_on_replq(const struct rt_unit *svc) +unit_on_replq(const struct rt_unit *svc) { return !list_empty(&svc->replq_elem); } @@ -291,7 +291,7 @@ vcpu_on_replq(const struct rt_unit *svc) * Otherwise, return value < 0 */ static s_time_t -compare_vcpu_priority(const struct rt_unit *v1, const struct rt_unit *v2) +compare_unit_priority(const struct rt_unit *v1, const struct rt_unit *v2) { int prio =3D v2->priority_level - v1->priority_level; =20 @@ -302,15 +302,15 @@ compare_vcpu_priority(const struct rt_unit *v1, const= struct rt_unit *v2) } =20 /* - * Debug related code, dump vcpu/cpu information + * Debug related code, dump unit/cpu information */ static void -rt_dump_vcpu(const struct scheduler *ops, const struct rt_unit *svc) +rt_dump_unit(const struct scheduler *ops, const struct rt_unit *svc) { cpumask_t *cpupool_mask, *mask; =20 ASSERT(svc !=3D NULL); - /* idle vcpu */ + /* idle unit */ if( svc->sdom =3D=3D NULL ) { printk("\n"); @@ -321,20 +321,20 @@ rt_dump_vcpu(const struct scheduler *ops, const struc= t rt_unit *svc) * We can't just use 'cpumask_scratch' because the dumping can * happen from a pCPU outside of this scheduler's cpupool, and * hence it's not right to use its pCPU's scratch mask. - * On the other hand, it is safe to use svc->vcpu->processor's + * On the other hand, it is safe to use sched_unit_cpu(svc->unit)'s * own scratch space, since we hold the runqueue lock. */ - mask =3D cpumask_scratch_cpu(svc->vcpu->processor); + mask =3D cpumask_scratch_cpu(sched_unit_cpu(svc->unit)); =20 - cpupool_mask =3D cpupool_domain_cpumask(svc->vcpu->domain); - cpumask_and(mask, cpupool_mask, svc->vcpu->sched_unit->cpu_hard_affini= ty); + cpupool_mask =3D cpupool_domain_cpumask(svc->unit->domain); + cpumask_and(mask, cpupool_mask, svc->unit->cpu_hard_affinity); printk("[%5d.%-2u] cpu %u, (%"PRI_stime", %"PRI_stime")," " cur_b=3D%"PRI_stime" cur_d=3D%"PRI_stime" last_start=3D%"PRI_= stime"\n" " \t\t priority_level=3D%d has_extratime=3D%d\n" " \t\t onQ=3D%d runnable=3D%d flags=3D%x effective hard_affinit= y=3D%*pbl\n", - svc->vcpu->domain->domain_id, - svc->vcpu->vcpu_id, - svc->vcpu->processor, + svc->unit->domain->domain_id, + svc->unit->unit_id, + sched_unit_cpu(svc->unit), svc->period, svc->budget, svc->cur_budget, @@ -342,8 +342,8 @@ rt_dump_vcpu(const struct scheduler *ops, const struct = rt_unit *svc) svc->last_start, svc->priority_level, has_extratime(svc), - vcpu_on_q(svc), - vcpu_runnable(svc->vcpu), + unit_on_q(svc), + unit_runnable(svc->unit), svc->flags, CPUMASK_PR(mask)); } =20 @@ -356,11 +356,11 @@ rt_dump_pcpu(const struct scheduler *ops, int cpu) =20 spin_lock_irqsave(&prv->lock, flags); printk("CPU[%02d]\n", cpu); - /* current VCPU (nothing to say if that's the idle vcpu). */ + /* current UNIT (nothing to say if that's the idle unit). */ svc =3D rt_unit(curr_on_cpu(cpu)); - if ( svc && !is_idle_vcpu(svc->vcpu) ) + if ( svc && !is_idle_unit(svc->unit) ) { - rt_dump_vcpu(ops, svc); + rt_dump_unit(ops, svc); } spin_unlock_irqrestore(&prv->lock, flags); } @@ -387,35 +387,35 @@ rt_dump(const struct scheduler *ops) list_for_each ( iter, runq ) { svc =3D q_elem(iter); - rt_dump_vcpu(ops, svc); + rt_dump_unit(ops, svc); } =20 printk("Global DepletedQueue info:\n"); list_for_each ( iter, depletedq ) { svc =3D q_elem(iter); - rt_dump_vcpu(ops, svc); + rt_dump_unit(ops, svc); } =20 printk("Global Replenishment Events info:\n"); list_for_each ( iter, replq ) { svc =3D replq_elem(iter); - rt_dump_vcpu(ops, svc); + rt_dump_unit(ops, svc); } =20 printk("Domain info:\n"); list_for_each ( iter, &prv->sdom ) { - struct vcpu *v; + struct sched_unit *unit; =20 sdom =3D list_entry(iter, struct rt_dom, sdom_elem); printk("\tdomain: %d\n", sdom->dom->domain_id); =20 - for_each_vcpu ( sdom->dom, v ) + for_each_sched_unit ( sdom->dom, unit ) { - svc =3D rt_unit(v->sched_unit); - rt_dump_vcpu(ops, svc); + svc =3D rt_unit(unit); + rt_dump_unit(ops, svc); } } =20 @@ -457,12 +457,12 @@ rt_update_deadline(s_time_t now, struct rt_unit *svc) /* TRACE */ { struct __packed { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; unsigned priority_level; uint64_t cur_deadline, cur_budget; } d; - d.dom =3D svc->vcpu->domain->domain_id; - d.vcpu =3D svc->vcpu->vcpu_id; + d.dom =3D svc->unit->domain->domain_id; + d.unit =3D svc->unit->unit_id; d.priority_level =3D svc->priority_level; d.cur_deadline =3D (uint64_t) svc->cur_deadline; d.cur_budget =3D (uint64_t) svc->cur_budget; @@ -475,15 +475,15 @@ rt_update_deadline(s_time_t now, struct rt_unit *svc) } =20 /* - * Helpers for removing and inserting a vcpu in a queue - * that is being kept ordered by the vcpus' deadlines (as EDF + * Helpers for removing and inserting an unit in a queue + * that is being kept ordered by the units' deadlines (as EDF * mandates). * - * For callers' convenience, the vcpu removing helper returns - * true if the vcpu removed was the one at the front of the + * For callers' convenience, the unit removing helper returns + * true if the unit removed was the one at the front of the * queue; similarly, the inserting helper returns true if the * inserted ended at the front of the queue (i.e., in both - * cases, if the vcpu with the earliest deadline is what we + * cases, if the unit with the earliest deadline is what we * are dealing with). */ static inline bool @@ -509,7 +509,7 @@ deadline_queue_insert(struct rt_unit * (*qelem)(struct = list_head *), list_for_each ( iter, queue ) { struct rt_unit * iter_svc =3D (*qelem)(iter); - if ( compare_vcpu_priority(svc, iter_svc) > 0 ) + if ( compare_unit_priority(svc, iter_svc) > 0 ) break; pos++; } @@ -524,7 +524,7 @@ deadline_queue_insert(struct rt_unit * (*qelem)(struct = list_head *), static inline void q_remove(struct rt_unit *svc) { - ASSERT( vcpu_on_q(svc) ); + ASSERT( unit_on_q(svc) ); list_del_init(&svc->q_elem); } =20 @@ -534,14 +534,14 @@ replq_remove(const struct scheduler *ops, struct rt_u= nit *svc) struct rt_private *prv =3D rt_priv(ops); struct list_head *replq =3D rt_replq(ops); =20 - ASSERT( vcpu_on_replq(svc) ); + ASSERT( unit_on_replq(svc) ); =20 if ( deadline_queue_remove(replq, &svc->replq_elem) ) { /* * The replenishment timer needs to be set to fire when a - * replenishment for the vcpu at the front of the replenishment - * queue is due. If it is such vcpu that we just removed, we may + * replenishment for the unit at the front of the replenishment + * queue is due. If it is such unit that we just removed, we may * need to reprogram the timer. */ if ( !list_empty(replq) ) @@ -556,7 +556,7 @@ replq_remove(const struct scheduler *ops, struct rt_uni= t *svc) =20 /* * Insert svc with budget in RunQ according to EDF: - * vcpus with smaller deadlines go first. + * units with smaller deadlines go first. * Insert svc without budget in DepletedQ unsorted; */ static void @@ -566,8 +566,8 @@ runq_insert(const struct scheduler *ops, struct rt_unit= *svc) struct list_head *runq =3D rt_runq(ops); =20 ASSERT( spin_is_locked(&prv->lock) ); - ASSERT( !vcpu_on_q(svc) ); - ASSERT( vcpu_on_replq(svc) ); + ASSERT( !unit_on_q(svc) ); + ASSERT( unit_on_replq(svc) ); =20 /* add svc to runq if svc still has budget or its extratime is set */ if ( svc->cur_budget > 0 || @@ -583,7 +583,7 @@ replq_insert(const struct scheduler *ops, struct rt_uni= t *svc) struct list_head *replq =3D rt_replq(ops); struct rt_private *prv =3D rt_priv(ops); =20 - ASSERT( !vcpu_on_replq(svc) ); + ASSERT( !unit_on_replq(svc) ); =20 /* * The timer may be re-programmed if svc is inserted @@ -606,12 +606,12 @@ replq_reinsert(const struct scheduler *ops, struct rt= _unit *svc) struct rt_unit *rearm_svc =3D svc; bool_t rearm =3D 0; =20 - ASSERT( vcpu_on_replq(svc) ); + ASSERT( unit_on_replq(svc) ); =20 /* * If svc was at the front of the replenishment queue, we certainly * need to re-program the timer, and we want to use the deadline of - * the vcpu which is now at the front of the queue (which may still + * the unit which is now at the front of the queue (which may still * be svc or not). * * We may also need to re-program, if svc has been put at the front @@ -631,24 +631,23 @@ replq_reinsert(const struct scheduler *ops, struct rt= _unit *svc) } =20 /* - * Pick a valid resource for the vcpu vc - * Valid resource of a vcpu is intesection of vcpu's affinity + * Pick a valid resource for the unit vc + * Valid resource of an unit is intesection of unit's affinity * and available resources */ static struct sched_resource * rt_res_pick(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; cpumask_t cpus; cpumask_t *online; int cpu; =20 - online =3D cpupool_domain_cpumask(vc->domain); + online =3D cpupool_domain_cpumask(unit->domain); cpumask_and(&cpus, online, unit->cpu_hard_affinity); =20 - cpu =3D cpumask_test_cpu(vc->processor, &cpus) - ? vc->processor - : cpumask_cycle(vc->processor, &cpus); + cpu =3D cpumask_test_cpu(sched_unit_cpu(unit), &cpus) + ? sched_unit_cpu(unit) + : cpumask_cycle(sched_unit_cpu(unit), &cpus); ASSERT( !cpumask_empty(&cpus) && cpumask_test_cpu(cpu, &cpus) ); =20 return get_sched_res(cpu); @@ -737,7 +736,7 @@ rt_switch_sched(struct scheduler *new_ops, unsigned int= cpu, struct rt_unit *svc =3D vdata; struct sched_resource *sd =3D get_sched_res(cpu); =20 - ASSERT(!pdata && svc && is_idle_vcpu(svc->vcpu)); + ASSERT(!pdata && svc && is_idle_unit(svc->unit)); =20 /* * We are holding the runqueue lock already (it's been taken in @@ -761,7 +760,7 @@ rt_switch_sched(struct scheduler *new_ops, unsigned int= cpu, dprintk(XENLOG_DEBUG, "RTDS: timer initialized on cpu %u\n", cpu); } =20 - idle_vcpu[cpu]->sched_unit->priv =3D vdata; + sched_idle_unit(cpu)->priv =3D vdata; =20 return &prv->lock; } @@ -841,10 +840,9 @@ rt_free_domdata(const struct scheduler *ops, void *dat= a) static void * rt_alloc_vdata(const struct scheduler *ops, struct sched_unit *unit, void = *dd) { - struct vcpu *vc =3D unit->vcpu_list; struct rt_unit *svc; =20 - /* Allocate per-VCPU info */ + /* Allocate per-UNIT info */ svc =3D xzalloc(struct rt_unit); if ( svc =3D=3D NULL ) return NULL; @@ -853,13 +851,13 @@ rt_alloc_vdata(const struct scheduler *ops, struct sc= hed_unit *unit, void *dd) INIT_LIST_HEAD(&svc->replq_elem); svc->flags =3D 0U; svc->sdom =3D dd; - svc->vcpu =3D vc; + svc->unit =3D unit; svc->last_start =3D 0; =20 __set_bit(__RTDS_extratime, &svc->flags); svc->priority_level =3D 0; svc->period =3D RTDS_DEFAULT_PERIOD; - if ( !is_idle_vcpu(vc) ) + if ( !is_idle_unit(unit) ) svc->budget =3D RTDS_DEFAULT_BUDGET; =20 SCHED_STAT_CRANK(unit_alloc); @@ -879,22 +877,20 @@ rt_free_vdata(const struct scheduler *ops, void *priv) * It is called in sched_move_domain() and sched_init_vcpu * in schedule.c. * When move a domain to a new cpupool. - * It inserts vcpus of moving domain to the scheduler's RunQ in + * It inserts units of moving domain to the scheduler's RunQ in * dest. cpupool. */ static void rt_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct rt_unit *svc =3D rt_unit(unit); s_time_t now; spinlock_t *lock; =20 - BUG_ON( is_idle_vcpu(vc) ); + BUG_ON( is_idle_unit(unit) ); =20 - /* This is safe because vc isn't yet being scheduled */ - unit->res =3D rt_res_pick(ops, unit); - vc->processor =3D unit->res->processor; + /* This is safe because unit isn't yet being scheduled */ + sched_set_res(unit, rt_res_pick(ops, unit)); =20 lock =3D unit_schedule_lock_irq(unit); =20 @@ -902,7 +898,7 @@ rt_unit_insert(const struct scheduler *ops, struct sche= d_unit *unit) if ( now >=3D svc->cur_deadline ) rt_update_deadline(now, svc); =20 - if ( !vcpu_on_q(svc) && vcpu_runnable(vc) ) + if ( !unit_on_q(svc) && unit_runnable(unit) ) { replq_insert(ops, svc); =20 @@ -929,10 +925,10 @@ rt_unit_remove(const struct scheduler *ops, struct sc= hed_unit *unit) BUG_ON( sdom =3D=3D NULL ); =20 lock =3D unit_schedule_lock_irq(unit); - if ( vcpu_on_q(svc) ) + if ( unit_on_q(svc) ) q_remove(svc); =20 - if ( vcpu_on_replq(svc) ) + if ( unit_on_replq(svc) ) replq_remove(ops,svc); =20 unit_schedule_unlock_irq(lock, unit); @@ -946,8 +942,8 @@ burn_budget(const struct scheduler *ops, struct rt_unit= *svc, s_time_t now) { s_time_t delta; =20 - /* don't burn budget for idle VCPU */ - if ( is_idle_vcpu(svc->vcpu) ) + /* don't burn budget for idle UNIT */ + if ( is_idle_unit(svc->unit) ) return; =20 /* burn at nanoseconds level */ @@ -984,14 +980,14 @@ burn_budget(const struct scheduler *ops, struct rt_un= it *svc, s_time_t now) /* TRACE */ { struct __packed { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; uint64_t cur_budget; int delta; unsigned priority_level; bool has_extratime; } d; - d.dom =3D svc->vcpu->domain->domain_id; - d.vcpu =3D svc->vcpu->vcpu_id; + d.dom =3D svc->unit->domain->domain_id; + d.unit =3D svc->unit->unit_id; d.cur_budget =3D (uint64_t) svc->cur_budget; d.delta =3D delta; d.priority_level =3D svc->priority_level; @@ -1021,9 +1017,8 @@ runq_pick(const struct scheduler *ops, const cpumask_= t *mask) iter_svc =3D q_elem(iter); =20 /* mask cpu_hard_affinity & cpupool & mask */ - online =3D cpupool_domain_cpumask(iter_svc->vcpu->domain); - cpumask_and(&cpu_common, online, - iter_svc->vcpu->sched_unit->cpu_hard_affinity); + online =3D cpupool_domain_cpumask(iter_svc->unit->domain); + cpumask_and(&cpu_common, online, iter_svc->unit->cpu_hard_affinity= ); cpumask_and(&cpu_common, mask, &cpu_common); if ( cpumask_empty(&cpu_common) ) continue; @@ -1039,11 +1034,11 @@ runq_pick(const struct scheduler *ops, const cpumas= k_t *mask) if( svc !=3D NULL ) { struct __packed { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; uint64_t cur_deadline, cur_budget; } d; - d.dom =3D svc->vcpu->domain->domain_id; - d.vcpu =3D svc->vcpu->vcpu_id; + d.dom =3D svc->unit->domain->domain_id; + d.unit =3D svc->unit->unit_id; d.cur_deadline =3D (uint64_t) svc->cur_deadline; d.cur_budget =3D (uint64_t) svc->cur_budget; trace_var(TRC_RTDS_RUNQ_PICK, 1, @@ -1067,6 +1062,7 @@ rt_schedule(const struct scheduler *ops, s_time_t now= , bool_t tasklet_work_sched struct rt_unit *const scurr =3D rt_unit(current->sched_unit); struct rt_unit *snext =3D NULL; struct task_slice ret =3D { .migrated =3D 0 }; + struct sched_unit *currunit =3D current->sched_unit; =20 /* TRACE */ { @@ -1076,7 +1072,7 @@ rt_schedule(const struct scheduler *ops, s_time_t now= , bool_t tasklet_work_sched d.cpu =3D cpu; d.tasklet =3D tasklet_work_scheduled; d.tickled =3D cpumask_test_cpu(cpu, &prv->tickled); - d.idle =3D is_idle_vcpu(current); + d.idle =3D is_idle_unit(currunit); trace_var(TRC_RTDS_SCHEDULE, 1, sizeof(d), (unsigned char *)&d); @@ -1085,72 +1081,70 @@ rt_schedule(const struct scheduler *ops, s_time_t n= ow, bool_t tasklet_work_sched /* clear ticked bit now that we've been scheduled */ cpumask_clear_cpu(cpu, &prv->tickled); =20 - /* burn_budget would return for IDLE VCPU */ + /* burn_budget would return for IDLE UNIT */ burn_budget(ops, scurr, now); =20 if ( tasklet_work_scheduled ) { trace_var(TRC_RTDS_SCHED_TASKLET, 1, 0, NULL); - snext =3D rt_unit(idle_vcpu[cpu]->sched_unit); + snext =3D rt_unit(sched_idle_unit(cpu)); } else { snext =3D runq_pick(ops, cpumask_of(cpu)); if ( snext =3D=3D NULL ) - snext =3D rt_unit(idle_vcpu[cpu]->sched_unit); + snext =3D rt_unit(sched_idle_unit(cpu)); =20 /* if scurr has higher priority and budget, still pick scurr */ - if ( !is_idle_vcpu(current) && - vcpu_runnable(current) && + if ( !is_idle_unit(currunit) && + unit_runnable(currunit) && scurr->cur_budget > 0 && - ( is_idle_vcpu(snext->vcpu) || - compare_vcpu_priority(scurr, snext) > 0 ) ) + ( is_idle_unit(snext->unit) || + compare_unit_priority(scurr, snext) > 0 ) ) snext =3D scurr; } =20 if ( snext !=3D scurr && - !is_idle_vcpu(current) && - vcpu_runnable(current) ) + !is_idle_unit(currunit) && + unit_runnable(currunit) ) __set_bit(__RTDS_delayed_runq_add, &scurr->flags); =20 snext->last_start =3D now; - ret.time =3D -1; /* if an idle vcpu is picked */ - if ( !is_idle_vcpu(snext->vcpu) ) + ret.time =3D -1; /* if an idle unit is picked */ + if ( !is_idle_unit(snext->unit) ) { if ( snext !=3D scurr ) { q_remove(snext); __set_bit(__RTDS_scheduled, &snext->flags); } - if ( snext->vcpu->processor !=3D cpu ) + if ( sched_unit_cpu(snext->unit) !=3D cpu ) { - snext->vcpu->processor =3D cpu; - snext->vcpu->sched_unit->res =3D get_sched_res(cpu); + sched_set_res(snext->unit, get_sched_res(cpu)); ret.migrated =3D 1; } ret.time =3D snext->cur_budget; /* invoke the scheduler next time = */ } - ret.task =3D snext->vcpu->sched_unit; + ret.task =3D snext->unit; =20 return ret; } =20 /* - * Remove VCPU from RunQ + * Remove UNIT from RunQ * The lock is already grabbed in schedule.c, no need to lock here */ static void rt_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct rt_unit * const svc =3D rt_unit(unit); =20 - BUG_ON( is_idle_vcpu(vc) ); + BUG_ON( is_idle_unit(unit) ); SCHED_STAT_CRANK(unit_sleep); =20 - if ( curr_on_cpu(vc->processor) =3D=3D unit ) - cpu_raise_softirq(vc->processor, SCHEDULE_SOFTIRQ); - else if ( vcpu_on_q(svc) ) + if ( curr_on_cpu(sched_unit_cpu(unit)) =3D=3D unit ) + cpu_raise_softirq(sched_unit_cpu(unit), SCHEDULE_SOFTIRQ); + else if ( unit_on_q(svc) ) { q_remove(svc); replq_remove(ops, svc); @@ -1160,20 +1154,20 @@ rt_unit_sleep(const struct scheduler *ops, struct s= ched_unit *unit) } =20 /* - * Pick a cpu where to run a vcpu, - * possibly kicking out the vcpu running there + * Pick a cpu where to run an unit, + * possibly kicking out the unit running there * Called by wake() and context_saved() * We have a running candidate here, the kick logic is: * Among all the cpus that are within the cpu affinity * 1) if there are any idle CPUs, kick one. For cache benefit, we check new->cpu as first * 2) now all pcpus are busy; - * among all the running vcpus, pick lowest priority one + * among all the running units, pick lowest priority one * if snext has higher priority, kick it. * * TODO: - * 1) what if these two vcpus belongs to the same domain? - * replace a vcpu belonging to the same domain introduces more overhead + * 1) what if these two units belongs to the same domain? + * replace an unit belonging to the same domain introduces more overhead * * lock is grabbed before calling this function */ @@ -1181,18 +1175,18 @@ static void runq_tickle(const struct scheduler *ops, struct rt_unit *new) { struct rt_private *prv =3D rt_priv(ops); - struct rt_unit *latest_deadline_vcpu =3D NULL; /* lowest priority */ + struct rt_unit *latest_deadline_unit =3D NULL; /* lowest priority */ struct rt_unit *iter_svc; - struct vcpu *iter_vc; + struct sched_unit *iter_unit; int cpu =3D 0, cpu_to_tickle =3D 0; cpumask_t not_tickled; cpumask_t *online; =20 - if ( new =3D=3D NULL || is_idle_vcpu(new->vcpu) ) + if ( new =3D=3D NULL || is_idle_unit(new->unit) ) return; =20 - online =3D cpupool_domain_cpumask(new->vcpu->domain); - cpumask_and(¬_tickled, online, new->vcpu->sched_unit->cpu_hard_affi= nity); + online =3D cpupool_domain_cpumask(new->unit->domain); + cpumask_and(¬_tickled, online, new->unit->cpu_hard_affinity); cpumask_andnot(¬_tickled, ¬_tickled, &prv->tickled); =20 /* @@ -1200,31 +1194,31 @@ runq_tickle(const struct scheduler *ops, struct rt_= unit *new) * For cache benefit,we first search new->cpu. * The same loop also find the one with lowest priority. */ - cpu =3D cpumask_test_or_cycle(new->vcpu->processor, ¬_tickled); + cpu =3D cpumask_test_or_cycle(sched_unit_cpu(new->unit), ¬_tickled); while ( cpu!=3D nr_cpu_ids ) { - iter_vc =3D curr_on_cpu(cpu)->vcpu_list; - if ( is_idle_vcpu(iter_vc) ) + iter_unit =3D curr_on_cpu(cpu); + if ( is_idle_unit(iter_unit) ) { SCHED_STAT_CRANK(tickled_idle_cpu); cpu_to_tickle =3D cpu; goto out; } - iter_svc =3D rt_unit(iter_vc->sched_unit); - if ( latest_deadline_vcpu =3D=3D NULL || - compare_vcpu_priority(iter_svc, latest_deadline_vcpu) < 0 ) - latest_deadline_vcpu =3D iter_svc; + iter_svc =3D rt_unit(iter_unit); + if ( latest_deadline_unit =3D=3D NULL || + compare_unit_priority(iter_svc, latest_deadline_unit) < 0 ) + latest_deadline_unit =3D iter_svc; =20 cpumask_clear_cpu(cpu, ¬_tickled); cpu =3D cpumask_cycle(cpu, ¬_tickled); } =20 - /* 2) candicate has higher priority, kick out lowest priority vcpu */ - if ( latest_deadline_vcpu !=3D NULL && - compare_vcpu_priority(latest_deadline_vcpu, new) < 0 ) + /* 2) candicate has higher priority, kick out lowest priority unit */ + if ( latest_deadline_unit !=3D NULL && + compare_unit_priority(latest_deadline_unit, new) < 0 ) { SCHED_STAT_CRANK(tickled_busy_cpu); - cpu_to_tickle =3D latest_deadline_vcpu->vcpu->processor; + cpu_to_tickle =3D sched_unit_cpu(latest_deadline_unit->unit); goto out; } =20 @@ -1250,35 +1244,34 @@ runq_tickle(const struct scheduler *ops, struct rt_= unit *new) } =20 /* - * Should always wake up runnable vcpu, put it back to RunQ. + * Should always wake up runnable unit, put it back to RunQ. * Check priority to raise interrupt * The lock is already grabbed in schedule.c, no need to lock here - * TODO: what if these two vcpus belongs to the same domain? + * TODO: what if these two units belongs to the same domain? */ static void rt_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct rt_unit * const svc =3D rt_unit(unit); s_time_t now; bool_t missed; =20 - BUG_ON( is_idle_vcpu(vc) ); + BUG_ON( is_idle_unit(unit) ); =20 - if ( unlikely(curr_on_cpu(vc->processor) =3D=3D unit) ) + if ( unlikely(curr_on_cpu(sched_unit_cpu(unit)) =3D=3D unit) ) { SCHED_STAT_CRANK(unit_wake_running); return; } =20 /* on RunQ/DepletedQ, just update info is ok */ - if ( unlikely(vcpu_on_q(svc)) ) + if ( unlikely(unit_on_q(svc)) ) { SCHED_STAT_CRANK(unit_wake_onrunq); return; } =20 - if ( likely(vcpu_runnable(vc)) ) + if ( likely(unit_runnable(unit)) ) SCHED_STAT_CRANK(unit_wake_runnable); else SCHED_STAT_CRANK(unit_wake_not_runnable); @@ -1294,16 +1287,16 @@ rt_unit_wake(const struct scheduler *ops, struct sc= hed_unit *unit) rt_update_deadline(now, svc); =20 /* - * If context hasn't been saved for this vcpu yet, we can't put it on + * If context hasn't been saved for this unit yet, we can't put it on * the run-queue/depleted-queue. Instead, we set the appropriate flag, - * the vcpu will be put back on queue after the context has been saved + * the unit will be put back on queue after the context has been saved * (in rt_context_save()). */ if ( unlikely(svc->flags & RTDS_scheduled) ) { __set_bit(__RTDS_delayed_runq_add, &svc->flags); /* - * The vcpu is waking up already, and we didn't even had the time = to + * The unit is waking up already, and we didn't even had the time = to * remove its next replenishment event from the replenishment queue * when it blocked! No big deal. If we did not miss the deadline in * the meantime, let's just leave it there. If we did, let's remov= e it @@ -1324,22 +1317,21 @@ rt_unit_wake(const struct scheduler *ops, struct sc= hed_unit *unit) =20 /* * scurr has finished context switch, insert it back to the RunQ, - * and then pick the highest priority vcpu from runq to run + * and then pick the highest priority unit from runq to run */ static void rt_context_saved(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct rt_unit *svc =3D rt_unit(unit); spinlock_t *lock =3D unit_schedule_lock_irq(unit); =20 __clear_bit(__RTDS_scheduled, &svc->flags); - /* not insert idle vcpu to runq */ - if ( is_idle_vcpu(vc) ) + /* not insert idle unit to runq */ + if ( is_idle_unit(unit) ) goto out; =20 if ( __test_and_clear_bit(__RTDS_delayed_runq_add, &svc->flags) && - likely(vcpu_runnable(vc)) ) + likely(unit_runnable(unit)) ) { runq_insert(ops, svc); runq_tickle(ops, svc); @@ -1352,7 +1344,7 @@ out: } =20 /* - * set/get each vcpu info of each domain + * set/get each unit info of each domain */ static int rt_dom_cntl( @@ -1362,7 +1354,7 @@ rt_dom_cntl( { struct rt_private *prv =3D rt_priv(ops); struct rt_unit *svc; - struct vcpu *v; + struct sched_unit *unit; unsigned long flags; int rc =3D 0; struct xen_domctl_schedparam_vcpu local_sched; @@ -1383,9 +1375,9 @@ rt_dom_cntl( break; } spin_lock_irqsave(&prv->lock, flags); - for_each_vcpu ( d, v ) + for_each_sched_unit ( d, unit ) { - svc =3D rt_unit(v->sched_unit); + svc =3D rt_unit(unit); svc->period =3D MICROSECS(op->u.rtds.period); /* transfer to n= anosec */ svc->budget =3D MICROSECS(op->u.rtds.budget); } @@ -1453,7 +1445,7 @@ rt_dom_cntl( break; } if ( !rc ) - /* notify upper caller how many vcpus have been processed. */ + /* notify upper caller how many units have been processed. */ op->u.v.nr_vcpus =3D index; break; } @@ -1462,7 +1454,7 @@ rt_dom_cntl( } =20 /* - * The replenishment timer handler picks vcpus + * The replenishment timer handler picks units * from the replq and does the actual replenishment. */ static void repl_timer_handler(void *data){ @@ -1480,7 +1472,7 @@ static void repl_timer_handler(void *data){ now =3D NOW(); =20 /* - * Do the replenishment and move replenished vcpus + * Do the replenishment and move replenished units * to the temporary list to tickle. * If svc is on run queue, we need to put it at * the correct place since its deadline changes. @@ -1496,7 +1488,7 @@ static void repl_timer_handler(void *data){ rt_update_deadline(now, svc); list_add(&svc->replq_elem, &tmp_replq); =20 - if ( vcpu_on_q(svc) ) + if ( unit_on_q(svc) ) { q_remove(svc); runq_insert(ops, svc); @@ -1504,26 +1496,26 @@ static void repl_timer_handler(void *data){ } =20 /* - * Iterate through the list of updated vcpus. - * If an updated vcpu is running, tickle the head of the + * Iterate through the list of updated units. + * If an updated unit is running, tickle the head of the * runqueue if it has a higher priority. - * If an updated vcpu was depleted and on the runqueue, tickle it. - * Finally, reinsert the vcpus back to replenishement events list. + * If an updated unit was depleted and on the runqueue, tickle it. + * Finally, reinsert the units back to replenishement events list. */ list_for_each_safe ( iter, tmp, &tmp_replq ) { svc =3D replq_elem(iter); =20 - if ( curr_on_cpu(svc->vcpu->processor) =3D=3D svc->vcpu->sched_uni= t && + if ( curr_on_cpu(sched_unit_cpu(svc->unit)) =3D=3D svc->unit && !list_empty(runq) ) { struct rt_unit *next_on_runq =3D q_elem(runq->next); =20 - if ( compare_vcpu_priority(svc, next_on_runq) < 0 ) + if ( compare_unit_priority(svc, next_on_runq) < 0 ) runq_tickle(ops, next_on_runq); } else if ( __test_and_clear_bit(__RTDS_depleted, &svc->flags) && - vcpu_on_q(svc) ) + unit_on_q(svc) ) runq_tickle(ops, svc); =20 list_del(&svc->replq_elem); @@ -1531,7 +1523,7 @@ static void repl_timer_handler(void *data){ } =20 /* - * If there are vcpus left in the replenishment event list, + * If there are units left in the replenishment event list, * set the next replenishment to happen at the deadline of * the one in the front. */ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362789; cv=none; d=zoho.com; s=zohoarc; b=h2WbpMy3rUQqIWlhFGbN98IVxXw41unJCV9lZUWcFIfr70TXL4Lznf0wK4+A6kLt3478Nwknl1kRsqgswWqktrZUY9H7HKnd3LIYQeb+5g2qp3aSpG65P4kDOOIeReL7FRXiw6fKDOsJhT7ddAsweQ5E+UGBx4bmmu+V6QQb9uQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362789; 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=1BhLlt3r54V3+y5ADronCVPPw25Vk1G/VhFjnPyn9EE=; b=g3LIsRTz+sYEgU7RfmtNi6XRif8jHr9VVOtskgGSF7Fgil0Z845JYUND1TxM9NOcmf35qRR0qakJffhAVZd2xhpxSCzz/dsndDYos2/Kpy/XFE1GXyFzraW80fJZ4R9czOU/ASxS49487HhthUREqXIcFySi5JAZpGcR6uk1yVs= 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 1565362789881487.7845237336735; Fri, 9 Aug 2019 07:59:49 -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 1hw6MB-0006tT-9G; Fri, 09 Aug 2019 14:59: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 1hw6M1-0006Zt-68 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:53 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2ea544fe-bab6-11e9-9bb7-f37360988314; Fri, 09 Aug 2019 14:58:44 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 66D6CB08C; Fri, 9 Aug 2019 14:58:43 +0000 (UTC) X-Inumbo-ID: 2ea544fe-bab6-11e9-9bb7-f37360988314 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:01 +0200 Message-Id: <20190809145833.1020-17-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 16/48] xen/sched: make credit scheduler vcpu agnostic. 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 , George Dunlap , Dario Faggioli 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" Switch credit scheduler completely from vcpu to sched_unit usage. Signed-off-by: Juergen Gross --- xen/common/sched_credit.c | 503 +++++++++++++++++++++++-------------------= ---- 1 file changed, 250 insertions(+), 253 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 143c7543e8..60eb4d3244 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -70,10 +70,10 @@ * inconsistent set of locks. Therefore atomic-safe bit operations must * be used for accessing it. */ -#define CSCHED_FLAG_VCPU_PARKED 0x0 /* VCPU over capped credits */ -#define CSCHED_FLAG_VCPU_YIELD 0x1 /* VCPU yielding */ -#define CSCHED_FLAG_VCPU_MIGRATING 0x2 /* VCPU may have moved to a new pc= pu */ -#define CSCHED_FLAG_VCPU_PINNED 0x4 /* VCPU can run only on 1 pcpu */ +#define CSCHED_FLAG_UNIT_PARKED 0x0 /* UNIT over capped credits */ +#define CSCHED_FLAG_UNIT_YIELD 0x1 /* UNIT yielding */ +#define CSCHED_FLAG_UNIT_MIGRATING 0x2 /* UNIT may have moved to a new pc= pu */ +#define CSCHED_FLAG_UNIT_PINNED 0x4 /* UNIT can run only on 1 pcpu */ =20 =20 /* @@ -91,7 +91,7 @@ /* * CSCHED_STATS * - * Manage very basic per-vCPU counters and stats. + * Manage very basic per-unit counters and stats. * * Useful for debugging live systems. The stats are displayed * with runq dumps ('r' on the Xen console). @@ -100,23 +100,23 @@ =20 #define CSCHED_STATS =20 -#define SCHED_VCPU_STATS_RESET(_V) \ +#define SCHED_UNIT_STATS_RESET(_V) \ do \ { \ memset(&(_V)->stats, 0, sizeof((_V)->stats)); \ } while ( 0 ) =20 -#define SCHED_VCPU_STAT_CRANK(_V, _X) (((_V)->stats._X)++) +#define SCHED_UNIT_STAT_CRANK(_V, _X) (((_V)->stats._X)++) =20 -#define SCHED_VCPU_STAT_SET(_V, _X, _Y) (((_V)->stats._X) =3D (_Y)) +#define SCHED_UNIT_STAT_SET(_V, _X, _Y) (((_V)->stats._X) =3D (_Y)) =20 #else /* !SCHED_STATS */ =20 #undef CSCHED_STATS =20 -#define SCHED_VCPU_STATS_RESET(_V) do {} while ( 0 ) -#define SCHED_VCPU_STAT_CRANK(_V, _X) do {} while ( 0 ) -#define SCHED_VCPU_STAT_SET(_V, _X, _Y) do {} while ( 0 ) +#define SCHED_UNIT_STATS_RESET(_V) do {} while ( 0 ) +#define SCHED_UNIT_STAT_CRANK(_V, _X) do {} while ( 0 ) +#define SCHED_UNIT_STAT_SET(_V, _X, _Y) do {} while ( 0 ) =20 #endif /* SCHED_STATS */ =20 @@ -128,7 +128,7 @@ #define TRC_CSCHED_SCHED_TASKLET TRC_SCHED_CLASS_EVT(CSCHED, 1) #define TRC_CSCHED_ACCOUNT_START TRC_SCHED_CLASS_EVT(CSCHED, 2) #define TRC_CSCHED_ACCOUNT_STOP TRC_SCHED_CLASS_EVT(CSCHED, 3) -#define TRC_CSCHED_STOLEN_VCPU TRC_SCHED_CLASS_EVT(CSCHED, 4) +#define TRC_CSCHED_STOLEN_UNIT TRC_SCHED_CLASS_EVT(CSCHED, 4) #define TRC_CSCHED_PICKED_CPU TRC_SCHED_CLASS_EVT(CSCHED, 5) #define TRC_CSCHED_TICKLE TRC_SCHED_CLASS_EVT(CSCHED, 6) #define TRC_CSCHED_BOOST_START TRC_SCHED_CLASS_EVT(CSCHED, 7) @@ -158,15 +158,15 @@ struct csched_pcpu { }; =20 /* - * Virtual CPU + * Virtual UNIT */ struct csched_unit { struct list_head runq_elem; - struct list_head active_vcpu_elem; + struct list_head active_unit_elem; =20 /* Up-pointers */ struct csched_dom *sdom; - struct vcpu *vcpu; + struct sched_unit *unit; =20 s_time_t start_time; /* When we were scheduled (used for credit) */ unsigned flags; @@ -194,10 +194,10 @@ struct csched_unit { * Domain */ struct csched_dom { - struct list_head active_vcpu; + struct list_head active_unit; struct list_head active_sdom_elem; struct domain *dom; - uint16_t active_vcpu_count; + uint16_t active_unit_count; uint16_t weight; uint16_t cap; }; @@ -217,7 +217,7 @@ struct csched_private { =20 /* Period of master and tick in milliseconds */ unsigned int tick_period_us, ticks_per_tslice; - s_time_t ratelimit, tslice, vcpu_migr_delay; + s_time_t ratelimit, tslice, unit_migr_delay; =20 struct list_head active_sdom; uint32_t weight; @@ -233,7 +233,7 @@ static void csched_tick(void *_cpu); static void csched_acct(void *dummy); =20 static inline int -__vcpu_on_runq(struct csched_unit *svc) +__unit_on_runq(struct csched_unit *svc) { return !list_empty(&svc->runq_elem); } @@ -244,7 +244,7 @@ __runq_elem(struct list_head *elem) return list_entry(elem, struct csched_unit, runq_elem); } =20 -/* Is the first element of cpu's runq (if any) cpu's idle vcpu? */ +/* Is the first element of cpu's runq (if any) cpu's idle unit? */ static inline bool_t is_runq_idle(unsigned int cpu) { /* @@ -253,7 +253,7 @@ static inline bool_t is_runq_idle(unsigned int cpu) ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 return list_empty(RUNQ(cpu)) || - is_idle_vcpu(__runq_elem(RUNQ(cpu)->next)->vcpu); + is_idle_unit(__runq_elem(RUNQ(cpu)->next)->unit); } =20 static inline void @@ -275,11 +275,11 @@ dec_nr_runnable(unsigned int cpu) static inline void __runq_insert(struct csched_unit *svc) { - unsigned int cpu =3D svc->vcpu->processor; + unsigned int cpu =3D sched_unit_cpu(svc->unit); const struct list_head * const runq =3D RUNQ(cpu); struct list_head *iter; =20 - BUG_ON( __vcpu_on_runq(svc) ); + BUG_ON( __unit_on_runq(svc) ); =20 list_for_each( iter, runq ) { @@ -288,10 +288,10 @@ __runq_insert(struct csched_unit *svc) break; } =20 - /* If the vcpu yielded, try to put it behind one lower-priority - * runnable vcpu if we can. The next runq_sort will bring it forward + /* If the unit yielded, try to put it behind one lower-priority + * runnable unit if we can. The next runq_sort will bring it forward * within 30ms if the queue too long. */ - if ( test_bit(CSCHED_FLAG_VCPU_YIELD, &svc->flags) + if ( test_bit(CSCHED_FLAG_UNIT_YIELD, &svc->flags) && __runq_elem(iter)->pri > CSCHED_PRI_IDLE ) { iter=3Diter->next; @@ -307,20 +307,20 @@ static inline void runq_insert(struct csched_unit *svc) { __runq_insert(svc); - inc_nr_runnable(svc->vcpu->processor); + inc_nr_runnable(sched_unit_cpu(svc->unit)); } =20 static inline void __runq_remove(struct csched_unit *svc) { - BUG_ON( !__vcpu_on_runq(svc) ); + BUG_ON( !__unit_on_runq(svc) ); list_del_init(&svc->runq_elem); } =20 static inline void runq_remove(struct csched_unit *svc) { - dec_nr_runnable(svc->vcpu->processor); + dec_nr_runnable(sched_unit_cpu(svc->unit)); __runq_remove(svc); } =20 @@ -331,7 +331,7 @@ static void burn_credits(struct csched_unit *svc, s_tim= e_t now) unsigned int credits; =20 /* Assert svc is current */ - ASSERT( svc =3D=3D CSCHED_UNIT(curr_on_cpu(svc->vcpu->processor)) ); + ASSERT( svc =3D=3D CSCHED_UNIT(curr_on_cpu(sched_unit_cpu(svc->unit)))= ); =20 if ( (delta =3D now - svc->start_time) <=3D 0 ) return; @@ -351,8 +351,8 @@ DEFINE_PER_CPU(unsigned int, last_tickle_cpu); =20 static inline void __runq_tickle(struct csched_unit *new) { - unsigned int cpu =3D new->vcpu->processor; - struct sched_unit *unit =3D new->vcpu->sched_unit; + unsigned int cpu =3D sched_unit_cpu(new->unit); + struct sched_unit *unit =3D new->unit; struct csched_unit * const cur =3D CSCHED_UNIT(curr_on_cpu(cpu)); struct csched_private *prv =3D CSCHED_PRIV(per_cpu(scheduler, cpu)); cpumask_t mask, idle_mask, *online; @@ -366,16 +366,16 @@ static inline void __runq_tickle(struct csched_unit *= new) idlers_empty =3D cpumask_empty(&idle_mask); =20 /* - * Exclusive pinning is when a vcpu has hard-affinity with only one - * cpu, and there is no other vcpu that has hard-affinity with that + * Exclusive pinning is when a unit has hard-affinity with only one + * cpu, and there is no other unit that has hard-affinity with that * same cpu. This is infrequent, but if it happens, is for achieving * the most possible determinism, and least possible overhead for - * the vcpus in question. + * the units in question. * * Try to identify the vast majority of these situations, and deal * with them quickly. */ - if ( unlikely(test_bit(CSCHED_FLAG_VCPU_PINNED, &new->flags) && + if ( unlikely(test_bit(CSCHED_FLAG_UNIT_PINNED, &new->flags) && cpumask_test_cpu(cpu, &idle_mask)) ) { ASSERT(cpumask_cycle(cpu, unit->cpu_hard_affinity) =3D=3D cpu); @@ -386,7 +386,7 @@ static inline void __runq_tickle(struct csched_unit *ne= w) =20 /* * If the pcpu is idle, or there are no idlers and the new - * vcpu is a higher priority than the old vcpu, run it here. + * unit is a higher priority than the old unit, run it here. * * If there are idle cpus, first try to find one suitable to run * new, so we can avoid preempting cur. If we cannot find a @@ -405,7 +405,7 @@ static inline void __runq_tickle(struct csched_unit *ne= w) else if ( !idlers_empty ) { /* - * Soft and hard affinity balancing loop. For vcpus without + * Soft and hard affinity balancing loop. For units without * a useful soft affinity, consider hard affinity only. */ for_each_affinity_balance_step( balance_step ) @@ -448,10 +448,10 @@ static inline void __runq_tickle(struct csched_unit *= new) { if ( cpumask_intersects(unit->cpu_hard_affinity, &idle_mas= k) ) { - SCHED_VCPU_STAT_CRANK(cur, kicked_away); - SCHED_VCPU_STAT_CRANK(cur, migrate_r); + SCHED_UNIT_STAT_CRANK(cur, kicked_away); + SCHED_UNIT_STAT_CRANK(cur, migrate_r); SCHED_STAT_CRANK(migrate_kicked_away); - set_bit(_VPF_migrating, &cur->vcpu->pause_flags); + sched_set_pause_flags_atomic(cur->unit, _VPF_migrating= ); } /* Tickle cpu anyway, to let new preempt cur. */ SCHED_STAT_CRANK(tickled_busy_cpu); @@ -607,7 +607,7 @@ init_pdata(struct csched_private *prv, struct csched_pc= pu *spc, int cpu) spc->idle_bias =3D nr_cpu_ids - 1; =20 /* Start off idling... */ - BUG_ON(!is_idle_vcpu(curr_on_cpu(cpu)->vcpu_list)); + BUG_ON(!is_idle_unit(curr_on_cpu(cpu))); cpumask_set_cpu(cpu, prv->idlers); spc->nr_runnable =3D 0; } @@ -632,9 +632,9 @@ csched_switch_sched(struct scheduler *new_ops, unsigned= int cpu, struct csched_private *prv =3D CSCHED_PRIV(new_ops); struct csched_unit *svc =3D vdata; =20 - ASSERT(svc && is_idle_vcpu(svc->vcpu)); + ASSERT(svc && is_idle_unit(svc->unit)); =20 - idle_vcpu[cpu]->sched_unit->priv =3D vdata; + sched_idle_unit(cpu)->priv =3D vdata; =20 /* * We are holding the runqueue lock already (it's been taken in @@ -651,33 +651,33 @@ csched_switch_sched(struct scheduler *new_ops, unsign= ed int cpu, =20 #ifndef NDEBUG static inline void -__csched_vcpu_check(struct vcpu *vc) +__csched_unit_check(struct sched_unit *unit) { - struct csched_unit * const svc =3D CSCHED_UNIT(vc->sched_unit); + struct csched_unit * const svc =3D CSCHED_UNIT(unit); struct csched_dom * const sdom =3D svc->sdom; =20 - BUG_ON( svc->vcpu !=3D vc ); - BUG_ON( sdom !=3D CSCHED_DOM(vc->domain) ); + BUG_ON( svc->unit !=3D unit ); + BUG_ON( sdom !=3D CSCHED_DOM(unit->domain) ); if ( sdom ) { - BUG_ON( is_idle_vcpu(vc) ); - BUG_ON( sdom->dom !=3D vc->domain ); + BUG_ON( is_idle_unit(unit) ); + BUG_ON( sdom->dom !=3D unit->domain ); } else { - BUG_ON( !is_idle_vcpu(vc) ); + BUG_ON( !is_idle_unit(unit) ); } =20 SCHED_STAT_CRANK(unit_check); } -#define CSCHED_VCPU_CHECK(_vc) (__csched_vcpu_check(_vc)) +#define CSCHED_UNIT_CHECK(unit) (__csched_unit_check(unit)) #else -#define CSCHED_VCPU_CHECK(_vc) +#define CSCHED_UNIT_CHECK(unit) #endif =20 /* - * Delay, in microseconds, between migrations of a VCPU between PCPUs. - * This prevents rapid fluttering of a VCPU between CPUs, and reduces the + * Delay, in microseconds, between migrations of a UNIT between PCPUs. + * This prevents rapid fluttering of a UNIT between CPUs, and reduces the * implicit overheads such as cache-warming. 1ms (1000) has been measured * as a good value. */ @@ -688,8 +688,8 @@ static inline bool __csched_vcpu_is_cache_hot(const struct csched_private *prv, const struct csched_unit *svc) { - bool hot =3D prv->vcpu_migr_delay && - (NOW() - svc->last_sched_time) < prv->vcpu_migr_delay; + bool hot =3D prv->unit_migr_delay && + (NOW() - svc->last_sched_time) < prv->unit_migr_delay; =20 if ( hot ) SCHED_STAT_CRANK(unit_hot); @@ -698,37 +698,39 @@ __csched_vcpu_is_cache_hot(const struct csched_privat= e *prv, } =20 static inline int -__csched_vcpu_is_migrateable(const struct csched_private *prv, struct vcpu= *vc, +__csched_unit_is_migrateable(const struct csched_private *prv, + struct sched_unit *unit, int dest_cpu, cpumask_t *mask) { - const struct csched_unit *svc =3D CSCHED_UNIT(vc->sched_unit); + const struct csched_unit *svc =3D CSCHED_UNIT(unit); /* * Don't pick up work that's hot on peer PCPU, or that can't (or * would prefer not to) run on cpu. * - * The caller is supposed to have already checked that vc is also + * The caller is supposed to have already checked that unit is also * not running. */ - ASSERT(!vc->sched_unit->is_running); + ASSERT(!unit->is_running); =20 return !__csched_vcpu_is_cache_hot(prv, svc) && cpumask_test_cpu(dest_cpu, mask); } =20 static int -_csched_cpu_pick(const struct scheduler *ops, struct vcpu *vc, bool_t comm= it) +_csched_cpu_pick(const struct scheduler *ops, struct sched_unit *unit, + bool_t commit) { - /* We must always use vc->procssor's scratch space */ - cpumask_t *cpus =3D cpumask_scratch_cpu(vc->processor); + int cpu =3D sched_unit_cpu(unit); + /* We must always use cpu's scratch space */ + cpumask_t *cpus =3D cpumask_scratch_cpu(cpu); cpumask_t idlers; - cpumask_t *online =3D cpupool_domain_cpumask(vc->domain); + cpumask_t *online =3D cpupool_domain_cpumask(unit->domain); struct csched_pcpu *spc =3D NULL; - int cpu =3D vc->processor; int balance_step; =20 for_each_affinity_balance_step( balance_step ) { - affinity_balance_cpumask(vc->sched_unit, balance_step, cpus); + affinity_balance_cpumask(unit, balance_step, cpus); cpumask_and(cpus, online, cpus); /* * We want to pick up a pcpu among the ones that are online and @@ -747,12 +749,13 @@ _csched_cpu_pick(const struct scheduler *ops, struct = vcpu *vc, bool_t commit) * balancing step all together. */ if ( balance_step =3D=3D BALANCE_SOFT_AFFINITY && - (!has_soft_affinity(vc->sched_unit) || cpumask_empty(cpus)) ) + (!has_soft_affinity(unit) || cpumask_empty(cpus)) ) continue; =20 /* If present, prefer vc's current processor */ - cpu =3D cpumask_test_cpu(vc->processor, cpus) - ? vc->processor : cpumask_cycle(vc->processor, cpus); + cpu =3D cpumask_test_cpu(sched_unit_cpu(unit), cpus) + ? sched_unit_cpu(unit) + : cpumask_cycle(sched_unit_cpu(unit), cpus); ASSERT(cpumask_test_cpu(cpu, cpus)); =20 /* @@ -764,15 +767,15 @@ _csched_cpu_pick(const struct scheduler *ops, struct = vcpu *vc, bool_t commit) * We give preference to the idle execution vehicle with the most * idling neighbours in its grouping. This distributes work across * distinct cores first and guarantees we don't do something stupid - * like run two VCPUs on co-hyperthreads while there are idle cores + * like run two UNITs on co-hyperthreads while there are idle cores * or sockets. * * Notice that, when computing the "idleness" of cpu, we may want = to - * discount vc. That is, iff vc is the currently running and the o= nly - * runnable vcpu on cpu, we add cpu to the idlers. + * discount unit. That is, iff unit is the currently running and t= he + * only runnable unit on cpu, we add cpu to the idlers. */ cpumask_and(&idlers, &cpu_online_map, CSCHED_PRIV(ops)->idlers); - if ( vc->processor =3D=3D cpu && is_runq_idle(cpu) ) + if ( sched_unit_cpu(unit) =3D=3D cpu && is_runq_idle(cpu) ) __cpumask_set_cpu(cpu, &idlers); cpumask_and(cpus, &idlers, cpus); =20 @@ -782,7 +785,7 @@ _csched_cpu_pick(const struct scheduler *ops, struct vc= pu *vc, bool_t commit) * CPU, as we just &&-ed it with idlers). In fact, if we are on SM= T, and * cpu points to a busy thread with an idle sibling, both the thre= ads * will be considered the same, from the "idleness" calculation po= int - * of view", preventing vcpu from being moved to the thread that is + * of view", preventing unit from being moved to the thread that is * actually idle. * * Notice that cpumask_test_cpu() is quicker than cpumask_empty(),= so @@ -848,7 +851,8 @@ _csched_cpu_pick(const struct scheduler *ops, struct vc= pu *vc, bool_t commit) if ( commit && spc ) spc->idle_bias =3D cpu; =20 - TRACE_3D(TRC_CSCHED_PICKED_CPU, vc->domain->domain_id, vc->vcpu_id, cp= u); + TRACE_3D(TRC_CSCHED_PICKED_CPU, unit->domain->domain_id, unit->unit_id, + cpu); =20 return cpu; } @@ -856,7 +860,6 @@ _csched_cpu_pick(const struct scheduler *ops, struct vc= pu *vc, bool_t commit) static struct sched_resource * csched_res_pick(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct csched_unit *svc =3D CSCHED_UNIT(unit); =20 /* @@ -866,26 +869,26 @@ csched_res_pick(const struct scheduler *ops, struct s= ched_unit *unit) * csched_unit_wake() (still called from vcpu_migrate()) we won't * get boosted, which we don't deserve as we are "only" migrating. */ - set_bit(CSCHED_FLAG_VCPU_MIGRATING, &svc->flags); - return get_sched_res(_csched_cpu_pick(ops, vc, 1)); + set_bit(CSCHED_FLAG_UNIT_MIGRATING, &svc->flags); + return get_sched_res(_csched_cpu_pick(ops, unit, 1)); } =20 static inline void -__csched_vcpu_acct_start(struct csched_private *prv, struct csched_unit *s= vc) +__csched_unit_acct_start(struct csched_private *prv, struct csched_unit *s= vc) { struct csched_dom * const sdom =3D svc->sdom; unsigned long flags; =20 spin_lock_irqsave(&prv->lock, flags); =20 - if ( list_empty(&svc->active_vcpu_elem) ) + if ( list_empty(&svc->active_unit_elem) ) { - SCHED_VCPU_STAT_CRANK(svc, state_active); + SCHED_UNIT_STAT_CRANK(svc, state_active); SCHED_STAT_CRANK(acct_unit_active); =20 - sdom->active_vcpu_count++; - list_add(&svc->active_vcpu_elem, &sdom->active_vcpu); - /* Make weight per-vcpu */ + sdom->active_unit_count++; + list_add(&svc->active_unit_elem, &sdom->active_unit); + /* Make weight per-unit */ prv->weight +=3D sdom->weight; if ( list_empty(&sdom->active_sdom_elem) ) { @@ -894,56 +897,56 @@ __csched_vcpu_acct_start(struct csched_private *prv, = struct csched_unit *svc) } =20 TRACE_3D(TRC_CSCHED_ACCOUNT_START, sdom->dom->domain_id, - svc->vcpu->vcpu_id, sdom->active_vcpu_count); + svc->unit->unit_id, sdom->active_unit_count); =20 spin_unlock_irqrestore(&prv->lock, flags); } =20 static inline void -__csched_vcpu_acct_stop_locked(struct csched_private *prv, +__csched_unit_acct_stop_locked(struct csched_private *prv, struct csched_unit *svc) { struct csched_dom * const sdom =3D svc->sdom; =20 - BUG_ON( list_empty(&svc->active_vcpu_elem) ); + BUG_ON( list_empty(&svc->active_unit_elem) ); =20 - SCHED_VCPU_STAT_CRANK(svc, state_idle); + SCHED_UNIT_STAT_CRANK(svc, state_idle); SCHED_STAT_CRANK(acct_unit_idle); =20 BUG_ON( prv->weight < sdom->weight ); - sdom->active_vcpu_count--; - list_del_init(&svc->active_vcpu_elem); + sdom->active_unit_count--; + list_del_init(&svc->active_unit_elem); prv->weight -=3D sdom->weight; - if ( list_empty(&sdom->active_vcpu) ) + if ( list_empty(&sdom->active_unit) ) { list_del_init(&sdom->active_sdom_elem); } =20 TRACE_3D(TRC_CSCHED_ACCOUNT_STOP, sdom->dom->domain_id, - svc->vcpu->vcpu_id, sdom->active_vcpu_count); + svc->unit->unit_id, sdom->active_unit_count); } =20 static void -csched_vcpu_acct(struct csched_private *prv, unsigned int cpu) +csched_unit_acct(struct csched_private *prv, unsigned int cpu) { struct sched_unit *currunit =3D current->sched_unit; struct csched_unit * const svc =3D CSCHED_UNIT(currunit); const struct scheduler *ops =3D per_cpu(scheduler, cpu); =20 - ASSERT( current->processor =3D=3D cpu ); + ASSERT( sched_unit_cpu(currunit) =3D=3D cpu ); ASSERT( svc->sdom !=3D NULL ); - ASSERT( !is_idle_vcpu(svc->vcpu) ); + ASSERT( !is_idle_unit(svc->unit) ); =20 /* - * If this VCPU's priority was boosted when it last awoke, reset it. - * If the VCPU is found here, then it's consuming a non-negligeable + * If this UNIT's priority was boosted when it last awoke, reset it. + * If the UNIT is found here, then it's consuming a non-negligeable * amount of CPU resources and should no longer be boosted. */ if ( svc->pri =3D=3D CSCHED_PRI_TS_BOOST ) { svc->pri =3D CSCHED_PRI_TS_UNDER; TRACE_2D(TRC_CSCHED_BOOST_END, svc->sdom->dom->domain_id, - svc->vcpu->vcpu_id); + svc->unit->unit_id); } =20 /* @@ -952,12 +955,12 @@ csched_vcpu_acct(struct csched_private *prv, unsigned= int cpu) burn_credits(svc, NOW()); =20 /* - * Put this VCPU and domain back on the active list if it was + * Put this UNIT and domain back on the active list if it was * idling. */ - if ( list_empty(&svc->active_vcpu_elem) ) + if ( list_empty(&svc->active_unit_elem) ) { - __csched_vcpu_acct_start(prv, svc); + __csched_unit_acct_start(prv, svc); } else { @@ -970,15 +973,15 @@ csched_vcpu_acct(struct csched_private *prv, unsigned= int cpu) * migrating it to run elsewhere (see multi-core and multi-thread * support in csched_res_pick()). */ - new_cpu =3D _csched_cpu_pick(ops, current, 0); + new_cpu =3D _csched_cpu_pick(ops, currunit, 0); =20 unit_schedule_unlock_irqrestore(lock, flags, currunit); =20 if ( new_cpu !=3D cpu ) { - SCHED_VCPU_STAT_CRANK(svc, migrate_r); + SCHED_UNIT_STAT_CRANK(svc, migrate_r); SCHED_STAT_CRANK(migrate_running); - set_bit(_VPF_migrating, ¤t->pause_flags); + sched_set_pause_flags_atomic(currunit, _VPF_migrating); /* * As we are about to tickle cpu, we should clear its bit in * idlers. But, if we are here, it means there is someone runn= ing @@ -995,21 +998,20 @@ static void * csched_alloc_vdata(const struct scheduler *ops, struct sched_unit *unit, void *dd) { - struct vcpu *vc =3D unit->vcpu_list; struct csched_unit *svc; =20 - /* Allocate per-VCPU info */ + /* Allocate per-UNIT info */ svc =3D xzalloc(struct csched_unit); if ( svc =3D=3D NULL ) return NULL; =20 INIT_LIST_HEAD(&svc->runq_elem); - INIT_LIST_HEAD(&svc->active_vcpu_elem); + INIT_LIST_HEAD(&svc->active_unit_elem); svc->sdom =3D dd; - svc->vcpu =3D vc; - svc->pri =3D is_idle_domain(vc->domain) ? + svc->unit =3D unit; + svc->pri =3D is_idle_unit(unit) ? CSCHED_PRI_IDLE : CSCHED_PRI_TS_UNDER; - SCHED_VCPU_STATS_RESET(svc); + SCHED_UNIT_STATS_RESET(svc); SCHED_STAT_CRANK(unit_alloc); return svc; } @@ -1017,24 +1019,21 @@ csched_alloc_vdata(const struct scheduler *ops, str= uct sched_unit *unit, static void csched_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct csched_unit *svc =3D unit->priv; spinlock_t *lock; =20 - BUG_ON( is_idle_vcpu(vc) ); + BUG_ON( is_idle_unit(unit) ); =20 /* csched_res_pick() looks in vc->processor's runq, so we need the loc= k. */ lock =3D unit_schedule_lock_irq(unit); =20 - unit->res =3D csched_res_pick(ops, unit); - vc->processor =3D unit->res->processor; + sched_set_res(unit, csched_res_pick(ops, unit)); =20 spin_unlock_irq(lock); =20 lock =3D unit_schedule_lock_irq(unit); =20 - if ( !__vcpu_on_runq(svc) && vcpu_runnable(vc) && - !vc->sched_unit->is_running ) + if ( !__unit_on_runq(svc) && unit_runnable(unit) && !unit->is_running ) runq_insert(svc); =20 unit_schedule_unlock_irq(lock, unit); @@ -1061,18 +1060,18 @@ csched_unit_remove(const struct scheduler *ops, str= uct sched_unit *unit) =20 SCHED_STAT_CRANK(unit_remove); =20 - ASSERT(!__vcpu_on_runq(svc)); + ASSERT(!__unit_on_runq(svc)); =20 - if ( test_and_clear_bit(CSCHED_FLAG_VCPU_PARKED, &svc->flags) ) + if ( test_and_clear_bit(CSCHED_FLAG_UNIT_PARKED, &svc->flags) ) { SCHED_STAT_CRANK(unit_unpark); - vcpu_unpause(svc->vcpu); + vcpu_unpause(svc->unit->vcpu_list); } =20 spin_lock_irq(&prv->lock); =20 - if ( !list_empty(&svc->active_vcpu_elem) ) - __csched_vcpu_acct_stop_locked(prv, svc); + if ( !list_empty(&svc->active_unit_elem) ) + __csched_unit_acct_stop_locked(prv, svc); =20 spin_unlock_irq(&prv->lock); =20 @@ -1082,86 +1081,85 @@ csched_unit_remove(const struct scheduler *ops, str= uct sched_unit *unit) static void csched_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct csched_unit * const svc =3D CSCHED_UNIT(unit); - unsigned int cpu =3D vc->processor; + unsigned int cpu =3D sched_unit_cpu(unit); =20 SCHED_STAT_CRANK(unit_sleep); =20 - BUG_ON( is_idle_vcpu(vc) ); + BUG_ON( is_idle_unit(unit) ); =20 if ( curr_on_cpu(cpu) =3D=3D unit ) { /* * We are about to tickle cpu, so we should clear its bit in idler= s. - * But, we are here because vc is going to sleep while running on = cpu, + * But, we are here because unit is going to sleep while running o= n cpu, * so the bit must be zero already. */ ASSERT(!cpumask_test_cpu(cpu, CSCHED_PRIV(per_cpu(scheduler, cpu))= ->idlers)); cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); } - else if ( __vcpu_on_runq(svc) ) + else if ( __unit_on_runq(svc) ) runq_remove(svc); } =20 static void csched_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct csched_unit * const svc =3D CSCHED_UNIT(unit); bool_t migrating; =20 - BUG_ON( is_idle_vcpu(vc) ); + BUG_ON( is_idle_unit(unit) ); =20 - if ( unlikely(curr_on_cpu(vc->processor) =3D=3D unit) ) + if ( unlikely(curr_on_cpu(sched_unit_cpu(unit)) =3D=3D unit) ) { SCHED_STAT_CRANK(unit_wake_running); return; } - if ( unlikely(__vcpu_on_runq(svc)) ) + if ( unlikely(__unit_on_runq(svc)) ) { SCHED_STAT_CRANK(unit_wake_onrunq); return; } =20 - if ( likely(vcpu_runnable(vc)) ) + if ( likely(unit_runnable(unit)) ) SCHED_STAT_CRANK(unit_wake_runnable); else SCHED_STAT_CRANK(unit_wake_not_runnable); =20 /* - * We temporarly boost the priority of awaking VCPUs! + * We temporarily boost the priority of awaking UNITs! * - * If this VCPU consumes a non negligeable amount of CPU, it + * If this UNIT consumes a non negligible amount of CPU, it * will eventually find itself in the credit accounting code * path where its priority will be reset to normal. * - * If on the other hand the VCPU consumes little CPU and is + * If on the other hand the UNIT consumes little CPU and is * blocking and awoken a lot (doing I/O for example), its * priority will remain boosted, optimizing it's wake-to-run * latencies. * - * This allows wake-to-run latency sensitive VCPUs to preempt - * more CPU resource intensive VCPUs without impacting overall=20 + * This allows wake-to-run latency sensitive UNITs to preempt + * more CPU resource intensive UNITs without impacting overall * system fairness. * * There are two cases, when we don't want to boost: - * - VCPUs that are waking up after a migration, rather than + * - UNITs that are waking up after a migration, rather than * after having block; - * - VCPUs of capped domains unpausing after earning credits + * - UNITs of capped domains unpausing after earning credits * they had overspent. */ - migrating =3D test_and_clear_bit(CSCHED_FLAG_VCPU_MIGRATING, &svc->fla= gs); + migrating =3D test_and_clear_bit(CSCHED_FLAG_UNIT_MIGRATING, &svc->fla= gs); =20 if ( !migrating && svc->pri =3D=3D CSCHED_PRI_TS_UNDER && - !test_bit(CSCHED_FLAG_VCPU_PARKED, &svc->flags) ) + !test_bit(CSCHED_FLAG_UNIT_PARKED, &svc->flags) ) { - TRACE_2D(TRC_CSCHED_BOOST_START, vc->domain->domain_id, vc->vcpu_i= d); + TRACE_2D(TRC_CSCHED_BOOST_START, unit->domain->domain_id, + unit->unit_id); SCHED_STAT_CRANK(unit_boost); svc->pri =3D CSCHED_PRI_TS_BOOST; } =20 - /* Put the VCPU on the runq and tickle CPUs */ + /* Put the UNIT on the runq and tickle CPUs */ runq_insert(svc); __runq_tickle(svc); } @@ -1172,7 +1170,7 @@ csched_unit_yield(const struct scheduler *ops, struct= sched_unit *unit) struct csched_unit * const svc =3D CSCHED_UNIT(unit); =20 /* Let the scheduler know that this vcpu is trying to yield */ - set_bit(CSCHED_FLAG_VCPU_YIELD, &svc->flags); + set_bit(CSCHED_FLAG_UNIT_YIELD, &svc->flags); } =20 static int @@ -1201,8 +1199,8 @@ csched_dom_cntl( { if ( !list_empty(&sdom->active_sdom_elem) ) { - prv->weight -=3D sdom->weight * sdom->active_vcpu_count; - prv->weight +=3D op->u.credit.weight * sdom->active_vcpu_c= ount; + prv->weight -=3D sdom->weight * sdom->active_unit_count; + prv->weight +=3D op->u.credit.weight * sdom->active_unit_c= ount; } sdom->weight =3D op->u.credit.weight; } @@ -1231,9 +1229,9 @@ csched_aff_cntl(const struct scheduler *ops, struct s= ched_unit *unit, =20 /* Are we becoming exclusively pinned? */ if ( cpumask_weight(hard) =3D=3D 1 ) - set_bit(CSCHED_FLAG_VCPU_PINNED, &svc->flags); + set_bit(CSCHED_FLAG_UNIT_PINNED, &svc->flags); else - clear_bit(CSCHED_FLAG_VCPU_PINNED, &svc->flags); + clear_bit(CSCHED_FLAG_UNIT_PINNED, &svc->flags); } =20 static inline void @@ -1276,14 +1274,14 @@ csched_sys_cntl(const struct scheduler *ops, else if ( prv->ratelimit && !params->ratelimit_us ) printk(XENLOG_INFO "Disabling context switch rate limiting\n"); prv->ratelimit =3D MICROSECS(params->ratelimit_us); - prv->vcpu_migr_delay =3D MICROSECS(params->vcpu_migr_delay_us); + prv->unit_migr_delay =3D MICROSECS(params->vcpu_migr_delay_us); spin_unlock_irqrestore(&prv->lock, flags); =20 /* FALLTHRU */ case XEN_SYSCTL_SCHEDOP_getinfo: params->tslice_ms =3D prv->tslice / MILLISECS(1); params->ratelimit_us =3D prv->ratelimit / MICROSECS(1); - params->vcpu_migr_delay_us =3D prv->vcpu_migr_delay / MICROSECS(1); + params->vcpu_migr_delay_us =3D prv->unit_migr_delay / MICROSECS(1); rc =3D 0; break; } @@ -1301,7 +1299,7 @@ csched_alloc_domdata(const struct scheduler *ops, str= uct domain *dom) return ERR_PTR(-ENOMEM); =20 /* Initialize credit and weight */ - INIT_LIST_HEAD(&sdom->active_vcpu); + INIT_LIST_HEAD(&sdom->active_unit); INIT_LIST_HEAD(&sdom->active_sdom_elem); sdom->dom =3D dom; sdom->weight =3D CSCHED_DEFAULT_WEIGHT; @@ -1318,7 +1316,7 @@ csched_free_domdata(const struct scheduler *ops, void= *data) /* * This is a O(n) optimized sort of the runq. * - * Time-share VCPUs can only be one of two priorities, UNDER or OVER. We w= alk + * Time-share UNITs can only be one of two priorities, UNDER or OVER. We w= alk * through the runq and move up any UNDERs that are preceded by OVERS. We * remember the last UNDER to make the move up operation O(1). */ @@ -1371,7 +1369,7 @@ csched_acct(void* dummy) { struct csched_private *prv =3D dummy; unsigned long flags; - struct list_head *iter_vcpu, *next_vcpu; + struct list_head *iter_unit, *next_unit; struct list_head *iter_sdom, *next_sdom; struct csched_unit *svc; struct csched_dom *sdom; @@ -1418,26 +1416,26 @@ csched_acct(void* dummy) sdom =3D list_entry(iter_sdom, struct csched_dom, active_sdom_elem= ); =20 BUG_ON( is_idle_domain(sdom->dom) ); - BUG_ON( sdom->active_vcpu_count =3D=3D 0 ); + BUG_ON( sdom->active_unit_count =3D=3D 0 ); BUG_ON( sdom->weight =3D=3D 0 ); - BUG_ON( (sdom->weight * sdom->active_vcpu_count) > weight_left ); + BUG_ON( (sdom->weight * sdom->active_unit_count) > weight_left ); =20 - weight_left -=3D ( sdom->weight * sdom->active_vcpu_count ); + weight_left -=3D ( sdom->weight * sdom->active_unit_count ); =20 /* * A domain's fair share is computed using its weight in competiti= on * with that of all other active domains. * - * At most, a domain can use credits to run all its active VCPUs + * At most, a domain can use credits to run all its active UNITs * for one full accounting period. We allow a domain to earn more * only when the system-wide credit balance is negative. */ - credit_peak =3D sdom->active_vcpu_count * prv->credits_per_tslice; + credit_peak =3D sdom->active_unit_count * prv->credits_per_tslice; if ( prv->credit_balance < 0 ) { credit_peak +=3D ( ( -prv->credit_balance * sdom->weight - * sdom->active_vcpu_count) + + * sdom->active_unit_count) + (weight_total - 1) ) / weight_total; } @@ -1448,14 +1446,14 @@ csched_acct(void* dummy) if ( credit_cap < credit_peak ) credit_peak =3D credit_cap; =20 - /* FIXME -- set cap per-vcpu as well...? */ - credit_cap =3D ( credit_cap + ( sdom->active_vcpu_count - 1 ) - ) / sdom->active_vcpu_count; + /* FIXME -- set cap per-unit as well...? */ + credit_cap =3D ( credit_cap + ( sdom->active_unit_count - 1 ) + ) / sdom->active_unit_count; } =20 credit_fair =3D ( ( credit_total * sdom->weight - * sdom->active_vcpu_count ) + * sdom->active_unit_count ) + (weight_total - 1) ) / weight_total; =20 @@ -1489,14 +1487,14 @@ csched_acct(void* dummy) credit_fair =3D credit_peak; } =20 - /* Compute fair share per VCPU */ - credit_fair =3D ( credit_fair + ( sdom->active_vcpu_count - 1 ) - ) / sdom->active_vcpu_count; + /* Compute fair share per UNIT */ + credit_fair =3D ( credit_fair + ( sdom->active_unit_count - 1 ) + ) / sdom->active_unit_count; =20 =20 - list_for_each_safe( iter_vcpu, next_vcpu, &sdom->active_vcpu ) + list_for_each_safe( iter_unit, next_unit, &sdom->active_unit ) { - svc =3D list_entry(iter_vcpu, struct csched_unit, active_vcpu_= elem); + svc =3D list_entry(iter_unit, struct csched_unit, active_unit_= elem); BUG_ON( sdom !=3D svc->sdom ); =20 /* Increment credit */ @@ -1504,20 +1502,20 @@ csched_acct(void* dummy) credit =3D atomic_read(&svc->credit); =20 /* - * Recompute priority or, if VCPU is idling, remove it from + * Recompute priority or, if UNIT is idling, remove it from * the active list. */ if ( credit < 0 ) { svc->pri =3D CSCHED_PRI_TS_OVER; =20 - /* Park running VCPUs of capped-out domains */ + /* Park running UNITs of capped-out domains */ if ( sdom->cap !=3D 0U && credit < -credit_cap && - !test_and_set_bit(CSCHED_FLAG_VCPU_PARKED, &svc->flag= s) ) + !test_and_set_bit(CSCHED_FLAG_UNIT_PARKED, &svc->flag= s) ) { SCHED_STAT_CRANK(unit_park); - vcpu_pause_nosync(svc->vcpu); + vcpu_pause_nosync(svc->unit->vcpu_list); } =20 /* Lower bound on credits */ @@ -1533,22 +1531,22 @@ csched_acct(void* dummy) svc->pri =3D CSCHED_PRI_TS_UNDER; =20 /* Unpark any capped domains whose credits go positive */ - if ( test_bit(CSCHED_FLAG_VCPU_PARKED, &svc->flags) ) + if ( test_bit(CSCHED_FLAG_UNIT_PARKED, &svc->flags) ) { /* * It's important to unset the flag AFTER the unpause() - * call to make sure the VCPU's priority is not boosted + * call to make sure the UNIT's priority is not boosted * if it is woken up here. */ SCHED_STAT_CRANK(unit_unpark); - vcpu_unpause(svc->vcpu); - clear_bit(CSCHED_FLAG_VCPU_PARKED, &svc->flags); + vcpu_unpause(svc->unit->vcpu_list); + clear_bit(CSCHED_FLAG_UNIT_PARKED, &svc->flags); } =20 - /* Upper bound on credits means VCPU stops earning */ + /* Upper bound on credits means UNIT stops earning */ if ( credit > prv->credits_per_tslice ) { - __csched_vcpu_acct_stop_locked(prv, svc); + __csched_unit_acct_stop_locked(prv, svc); /* Divide credits in half, so that when it starts * accounting again, it starts a little bit "ahead" */ credit /=3D 2; @@ -1556,8 +1554,8 @@ csched_acct(void* dummy) } } =20 - SCHED_VCPU_STAT_SET(svc, credit_last, credit); - SCHED_VCPU_STAT_SET(svc, credit_incr, credit_fair); + SCHED_UNIT_STAT_SET(svc, credit_last, credit); + SCHED_UNIT_STAT_SET(svc, credit_incr, credit_fair); credit_balance +=3D credit; } } @@ -1583,10 +1581,10 @@ csched_tick(void *_cpu) spc->tick++; =20 /* - * Accounting for running VCPU + * Accounting for running UNIT */ - if ( !is_idle_vcpu(current) ) - csched_vcpu_acct(prv, cpu); + if ( !is_idle_unit(current->sched_unit) ) + csched_unit_acct(prv, cpu); =20 /* * Check if runq needs to be sorted @@ -1607,7 +1605,7 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, int= balance_step) const struct csched_pcpu * const peer_pcpu =3D CSCHED_PCPU(peer_cpu); struct csched_unit *speer; struct list_head *iter; - struct vcpu *vc; + struct sched_unit *unit; =20 ASSERT(peer_pcpu !=3D NULL); =20 @@ -1615,7 +1613,7 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, int= balance_step) * Don't steal from an idle CPU's runq because it's about to * pick up work from it itself. */ - if ( unlikely(is_idle_vcpu(curr_on_cpu(peer_cpu)->vcpu_list)) ) + if ( unlikely(is_idle_unit(curr_on_cpu(peer_cpu))) ) goto out; =20 list_for_each( iter, &peer_pcpu->runq ) @@ -1623,46 +1621,44 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, i= nt balance_step) speer =3D __runq_elem(iter); =20 /* - * If next available VCPU here is not of strictly higher + * If next available UNIT here is not of strictly higher * priority than ours, this PCPU is useless to us. */ if ( speer->pri <=3D pri ) break; =20 - /* Is this VCPU runnable on our PCPU? */ - vc =3D speer->vcpu; - BUG_ON( is_idle_vcpu(vc) ); + /* Is this UNIT runnable on our PCPU? */ + unit =3D speer->unit; + BUG_ON( is_idle_unit(unit) ); =20 /* - * If the vcpu is still in peer_cpu's scheduling tail, or if it + * If the unit is still in peer_cpu's scheduling tail, or if it * has no useful soft affinity, skip it. * * In fact, what we want is to check if we have any "soft-affine * work" to steal, before starting to look at "hard-affine work". * - * Notice that, if not even one vCPU on this runq has a useful + * Notice that, if not even one unit on this runq has a useful * soft affinity, we could have avoid considering this runq for * a soft balancing step in the first place. This, for instance, * can be implemented by taking note of on what runq there are - * vCPUs with useful soft affinities in some sort of bitmap + * units with useful soft affinities in some sort of bitmap * or counter. */ - if ( vc->sched_unit->is_running || - (balance_step =3D=3D BALANCE_SOFT_AFFINITY && - !has_soft_affinity(vc->sched_unit)) ) + if ( unit->is_running || (balance_step =3D=3D BALANCE_SOFT_AFFINIT= Y && + !has_soft_affinity(unit)) ) continue; =20 - affinity_balance_cpumask(vc->sched_unit, balance_step, cpumask_scr= atch); - if ( __csched_vcpu_is_migrateable(prv, vc, cpu, cpumask_scratch) ) + affinity_balance_cpumask(unit, balance_step, cpumask_scratch); + if ( __csched_unit_is_migrateable(prv, unit, cpu, cpumask_scratch)= ) { /* We got a candidate. Grab it! */ - TRACE_3D(TRC_CSCHED_STOLEN_VCPU, peer_cpu, - vc->domain->domain_id, vc->vcpu_id); - SCHED_VCPU_STAT_CRANK(speer, migrate_q); + TRACE_3D(TRC_CSCHED_STOLEN_UNIT, peer_cpu, + unit->domain->domain_id, unit->unit_id); + SCHED_UNIT_STAT_CRANK(speer, migrate_q); SCHED_STAT_CRANK(migrate_queued); - WARN_ON(vc->is_urgent); runq_remove(speer); - sched_set_res(vc->sched_unit, get_sched_res(cpu)); + sched_set_res(unit, get_sched_res(cpu)); /* * speer will start executing directly on cpu, without having = to * go through runq_insert(). So we must update the runnable co= unt @@ -1688,7 +1684,7 @@ csched_load_balance(struct csched_private *prv, int c= pu, int peer_cpu, first_cpu, peer_node, bstep; int node =3D cpu_to_node(cpu); =20 - BUG_ON( cpu !=3D snext->vcpu->processor ); + BUG_ON( cpu !=3D sched_unit_cpu(snext->unit) ); online =3D cpupool_online_cpumask(c); =20 /* @@ -1717,7 +1713,7 @@ csched_load_balance(struct csched_private *prv, int c= pu, /* * We peek at the non-idling CPUs in a node-wise fashion. In fact, * it is more likely that we find some affine work on our same - * node, not to mention that migrating vcpus within the same node + * node, not to mention that migrating units within the same node * could well expected to be cheaper than across-nodes (memory * stays local, there might be some node-wide cache[s], etc.). */ @@ -1738,7 +1734,7 @@ csched_load_balance(struct csched_private *prv, int c= pu, spinlock_t *lock; =20 /* - * If there is only one runnable vCPU on peer_cpu, it means + * If there is only one runnable unit on peer_cpu, it means * there's no one to be stolen in its runqueue, so skip it. * * Checking this without holding the lock is racy... But t= hat's @@ -1751,13 +1747,13 @@ csched_load_balance(struct csched_private *prv, int= cpu, * And we can avoid that by re-checking nr_runnable after * having grabbed the lock, if we want; * - if we race with inc_nr_runnable(), we skip a pCPU tha= t may - * have runnable vCPUs in its runqueue, but that's not a + * have runnable units in its runqueue, but that's not a * problem because: * + if racing with csched_unit_insert() or csched_unit_= wake(), - * __runq_tickle() will be called afterwords, so the v= CPU + * __runq_tickle() will be called afterwords, so the u= nit * won't get stuck in the runqueue for too long; - * + if racing with csched_runq_steal(), it may be that a - * vCPU that we could have picked up, stays in a runqu= eue + * + if racing with csched_runq_steal(), it may be that = an + * unit that we could have picked up, stays in a runqu= eue * until someone else tries to steal it again. But thi= s is * no worse than what can happen already (without this * optimization), it the pCPU would schedule right aft= er we @@ -1792,7 +1788,7 @@ csched_load_balance(struct csched_private *prv, int c= pu, csched_runq_steal(peer_cpu, cpu, snext->pri, bstep) : = NULL; pcpu_schedule_unlock(lock, peer_cpu); =20 - /* As soon as one vcpu is found, balancing ends */ + /* As soon as one unit is found, balancing ends */ if ( speer !=3D NULL ) { *stolen =3D 1; @@ -1831,14 +1827,15 @@ csched_schedule( { const int cpu =3D smp_processor_id(); struct list_head * const runq =3D RUNQ(cpu); - struct csched_unit * const scurr =3D CSCHED_UNIT(current->sched_unit); + struct sched_unit *unit =3D current->sched_unit; + struct csched_unit * const scurr =3D CSCHED_UNIT(unit); struct csched_private *prv =3D CSCHED_PRIV(ops); struct csched_unit *snext; struct task_slice ret; s_time_t runtime, tslice; =20 SCHED_STAT_CRANK(schedule); - CSCHED_VCPU_CHECK(current); + CSCHED_UNIT_CHECK(unit); =20 /* * Here in Credit1 code, we usually just call TRACE_nD() helpers, and @@ -1852,31 +1849,31 @@ csched_schedule( } d; d.cpu =3D cpu; d.tasklet =3D tasklet_work_scheduled; - d.idle =3D is_idle_vcpu(current); + d.idle =3D is_idle_unit(unit); __trace_var(TRC_CSCHED_SCHEDULE, 1, sizeof(d), (unsigned char *)&d); } =20 - runtime =3D now - current->sched_unit->state_entry_time; + runtime =3D now - unit->state_entry_time; if ( runtime < 0 ) /* Does this ever happen? */ runtime =3D 0; =20 - if ( !is_idle_vcpu(scurr->vcpu) ) + if ( !is_idle_unit(unit) ) { - /* Update credits of a non-idle VCPU. */ + /* Update credits of a non-idle UNIT. */ burn_credits(scurr, now); scurr->start_time -=3D now; scurr->last_sched_time =3D now; } else { - /* Re-instate a boosted idle VCPU as normal-idle. */ + /* Re-instate a boosted idle UNIT as normal-idle. */ scurr->pri =3D CSCHED_PRI_IDLE; } =20 /* Choices, choices: - * - If we have a tasklet, we need to run the idle vcpu no matter what. - * - If sched rate limiting is in effect, and the current vcpu has + * - If we have a tasklet, we need to run the idle unit no matter what. + * - If sched rate limiting is in effect, and the current unit has * run for less than that amount of time, continue the current one, * but with a shorter timeslice and return it immediately * - Otherwise, chose the one with the highest priority (which may @@ -1894,11 +1891,11 @@ csched_schedule( * In fact, it may be the case that scurr is about to spin, and there's * no point forcing it to do so until rate limiting expires. */ - if ( !test_bit(CSCHED_FLAG_VCPU_YIELD, &scurr->flags) + if ( !test_bit(CSCHED_FLAG_UNIT_YIELD, &scurr->flags) && !tasklet_work_scheduled && prv->ratelimit - && vcpu_runnable(current) - && !is_idle_vcpu(current) + && unit_runnable(unit) + && !is_idle_unit(unit) && runtime < prv->ratelimit ) { snext =3D scurr; @@ -1916,11 +1913,11 @@ csched_schedule( if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; unsigned runtime; } d; - d.dom =3D scurr->vcpu->domain->domain_id; - d.vcpu =3D scurr->vcpu->vcpu_id; + d.dom =3D unit->domain->domain_id; + d.unit =3D unit->unit_id; d.runtime =3D runtime; __trace_var(TRC_CSCHED_RATELIMIT, 1, sizeof(d), (unsigned char *)&d); @@ -1932,13 +1929,13 @@ csched_schedule( tslice =3D prv->tslice; =20 /* - * Select next runnable local VCPU (ie top of local runq) + * Select next runnable local UNIT (ie top of local runq) */ - if ( vcpu_runnable(current) ) + if ( unit_runnable(unit) ) __runq_insert(scurr); else { - BUG_ON( is_idle_vcpu(current) || list_empty(runq) ); + BUG_ON( is_idle_unit(unit) || list_empty(runq) ); /* Current has blocked. Update the runnable counter for this cpu. = */ dec_nr_runnable(cpu); } @@ -1946,23 +1943,23 @@ csched_schedule( snext =3D __runq_elem(runq->next); ret.migrated =3D 0; =20 - /* Tasklet work (which runs in idle VCPU context) overrides all else. = */ + /* Tasklet work (which runs in idle UNIT context) overrides all else. = */ if ( tasklet_work_scheduled ) { TRACE_0D(TRC_CSCHED_SCHED_TASKLET); - snext =3D CSCHED_UNIT(idle_vcpu[cpu]->sched_unit); + snext =3D CSCHED_UNIT(sched_idle_unit(cpu)); snext->pri =3D CSCHED_PRI_TS_BOOST; } =20 /* * Clear YIELD flag before scheduling out */ - clear_bit(CSCHED_FLAG_VCPU_YIELD, &scurr->flags); + clear_bit(CSCHED_FLAG_UNIT_YIELD, &scurr->flags); =20 /* * SMP Load balance: * - * If the next highest priority local runnable VCPU has already eaten + * If the next highest priority local runnable UNIT has already eaten * through its credits, look on other PCPUs to see if we have more * urgent work... If not, csched_load_balance() will return snext, but * already removed from the runq. @@ -1986,32 +1983,32 @@ csched_schedule( cpumask_clear_cpu(cpu, prv->idlers); } =20 - if ( !is_idle_vcpu(snext->vcpu) ) + if ( !is_idle_unit(snext->unit) ) snext->start_time +=3D now; =20 out: /* * Return task to run next... */ - ret.time =3D (is_idle_vcpu(snext->vcpu) ? + ret.time =3D (is_idle_unit(snext->unit) ? -1 : tslice); - ret.task =3D snext->vcpu->sched_unit; + ret.task =3D snext->unit; =20 - CSCHED_VCPU_CHECK(ret.task->vcpu_list); + CSCHED_UNIT_CHECK(ret.task); return ret; } =20 static void -csched_dump_vcpu(struct csched_unit *svc) +csched_dump_unit(struct csched_unit *svc) { struct csched_dom * const sdom =3D svc->sdom; =20 printk("[%i.%i] pri=3D%i flags=3D%x cpu=3D%i", - svc->vcpu->domain->domain_id, - svc->vcpu->vcpu_id, + svc->unit->domain->domain_id, + svc->unit->unit_id, svc->pri, svc->flags, - svc->vcpu->processor); + sched_unit_cpu(svc->unit)); =20 if ( sdom ) { @@ -2045,7 +2042,7 @@ csched_dump_pcpu(const struct scheduler *ops, int cpu) =20 /* * We need both locks: - * - csched_dump_vcpu() wants to access domains' scheduling + * - csched_dump_unit() wants to access domains' scheduling * parameters, which are protected by the private scheduler lock; * - we scan through the runqueue, so we need the proper runqueue * lock (the one of the runqueue of this cpu). @@ -2061,12 +2058,12 @@ csched_dump_pcpu(const struct scheduler *ops, int c= pu) CPUMASK_PR(per_cpu(cpu_sibling_mask, cpu)), CPUMASK_PR(per_cpu(cpu_core_mask, cpu))); =20 - /* current VCPU (nothing to say if that's the idle vcpu). */ + /* current UNIT (nothing to say if that's the idle unit). */ svc =3D CSCHED_UNIT(curr_on_cpu(cpu)); - if ( svc && !is_idle_vcpu(svc->vcpu) ) + if ( svc && !is_idle_unit(svc->unit) ) { printk("\trun: "); - csched_dump_vcpu(svc); + csched_dump_unit(svc); } =20 loop =3D 0; @@ -2076,7 +2073,7 @@ csched_dump_pcpu(const struct scheduler *ops, int cpu) if ( svc ) { printk("\t%3d: ", ++loop); - csched_dump_vcpu(svc); + csched_dump_unit(svc); } } =20 @@ -2118,29 +2115,29 @@ csched_dump(const struct scheduler *ops) prv->ratelimit / MICROSECS(1), CSCHED_CREDITS_PER_MSEC, prv->ticks_per_tslice, - prv->vcpu_migr_delay/ MICROSECS(1)); + prv->unit_migr_delay/ MICROSECS(1)); =20 printk("idlers: %*pb\n", CPUMASK_PR(prv->idlers)); =20 - printk("active vcpus:\n"); + printk("active units:\n"); loop =3D 0; list_for_each( iter_sdom, &prv->active_sdom ) { struct csched_dom *sdom; sdom =3D list_entry(iter_sdom, struct csched_dom, active_sdom_elem= ); =20 - list_for_each( iter_svc, &sdom->active_vcpu ) + list_for_each( iter_svc, &sdom->active_unit ) { struct csched_unit *svc; spinlock_t *lock; =20 - svc =3D list_entry(iter_svc, struct csched_unit, active_vcpu_e= lem); - lock =3D unit_schedule_lock(svc->vcpu->sched_unit); + svc =3D list_entry(iter_svc, struct csched_unit, active_unit_e= lem); + lock =3D unit_schedule_lock(svc->unit); =20 printk("\t%3d: ", ++loop); - csched_dump_vcpu(svc); + csched_dump_unit(svc); =20 - unit_schedule_unlock(lock, svc->vcpu->sched_unit); + unit_schedule_unlock(lock, svc->unit); } } =20 @@ -2214,7 +2211,7 @@ csched_init(struct scheduler *ops) else prv->ratelimit =3D MICROSECS(sched_ratelimit_us); =20 - prv->vcpu_migr_delay =3D MICROSECS(vcpu_migration_delay_us); + prv->unit_migr_delay =3D MICROSECS(vcpu_migration_delay_us); =20 return 0; } --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362825; cv=none; d=zoho.com; s=zohoarc; b=jWoDjAnDKZLpBAhxa55QNzbWJ1Rof2kQmVDocWxrUS+PVDoPNxcippPXi+j8hyYzFwNV4NCin8FsnNAfDkGUuYLsoDuKm47c9ckeiSL7+mnRw/BjDNs51SsQdHC3jxkQMoFY6sdaQ0hz1awgFkhkMcilr1zTrIWh0ZFqcNF+L+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362825; 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=LZSF1DjKTIhgV3u3V6iY6SmOWhv7DLtyuhknza4DxkU=; b=Y2U/22o6zW6OinZz+bvKVcjkxEiByIiX0vIWBCIZvZKxY1ui4hAlJH31yXLxYHuyAgssAvuwM+a9PKqB14/bdUChShBXzT96kQJV/MdFSTq7JFfovm5glG7Hs/oxL/StRH5A59Puk3/SMtNDa+j5cCtFQyAeDTNxQdG32XuF1hU= 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 1565362825328301.61177288590636; Fri, 9 Aug 2019 08:00:25 -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 1hw6MY-0007lV-Kh; Fri, 09 Aug 2019 14:59:26 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M6-0006kX-Tb for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:59 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2ee570fc-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:45 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A3CBAB090; Fri, 9 Aug 2019 14:58:43 +0000 (UTC) X-Inumbo-ID: 2ee570fc-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:02 +0200 Message-Id: <20190809145833.1020-18-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 17/48] xen/sched: make credit2 scheduler vcpu agnostic. 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 , George Dunlap , Dario Faggioli 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" Switch credit2 scheduler completely from vcpu to sched_unit usage. As we are touching lots of lines remove some white space at the end of the line, too. Signed-off-by: Juergen Gross --- xen/common/sched_credit2.c | 820 ++++++++++++++++++++++-------------------= ---- 1 file changed, 403 insertions(+), 417 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 5487d087e1..e3ac9c5460 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -45,7 +45,7 @@ #define TRC_CSCHED2_SCHED_TASKLET TRC_SCHED_CLASS_EVT(CSCHED2, 8) #define TRC_CSCHED2_UPDATE_LOAD TRC_SCHED_CLASS_EVT(CSCHED2, 9) #define TRC_CSCHED2_RUNQ_ASSIGN TRC_SCHED_CLASS_EVT(CSCHED2, 10) -#define TRC_CSCHED2_UPDATE_VCPU_LOAD TRC_SCHED_CLASS_EVT(CSCHED2, 11) +#define TRC_CSCHED2_UPDATE_UNIT_LOAD TRC_SCHED_CLASS_EVT(CSCHED2, 11) #define TRC_CSCHED2_UPDATE_RUNQ_LOAD TRC_SCHED_CLASS_EVT(CSCHED2, 12) #define TRC_CSCHED2_TICKLE_NEW TRC_SCHED_CLASS_EVT(CSCHED2, 13) #define TRC_CSCHED2_RUNQ_MAX_WEIGHT TRC_SCHED_CLASS_EVT(CSCHED2, 14) @@ -74,13 +74,13 @@ * Design: * * VMs "burn" credits based on their weight; higher weight means - * credits burn more slowly. The highest weight vcpu burns credits at + * credits burn more slowly. The highest weight unit burns credits at * a rate of 1 credit per nanosecond. Others burn proportionally * more. * - * vcpus are inserted into the runqueue by credit order. + * units are inserted into the runqueue by credit order. * - * Credits are "reset" when the next vcpu in the runqueue is less than + * Credits are "reset" when the next unit in the runqueue is less than * or equal to zero. At that point, everyone's credits are "clipped" * to a small value, and a fixed credit is added to everyone. */ @@ -95,33 +95,33 @@ * be given a cap of 25%; a domain that must not use more than 1+1/2 of * physical CPU time, will be given a cap of 150%; * - * - caps are per-domain (not per-vCPU). If a domain has only 1 vCPU, and - * a 40% cap, that one vCPU will use 40% of one pCPU. If a somain has 4 - * vCPUs, and a 200% cap, the equivalent of 100% time on 2 pCPUs will be - * split among the v vCPUs. How much each of the vCPUs will actually get, + * - caps are per-domain (not per-unit). If a domain has only 1 unit, and + * a 40% cap, that one unit will use 40% of one pCPU. If a somain has 4 + * units, and a 200% cap, the equivalent of 100% time on 2 pCPUs will be + * split among the v units. How much each of the units will actually get, * during any given interval of time, is unspecified (as it depends on * various aspects: workload, system load, etc.). For instance, it is - * possible that, during a given time interval, 2 vCPUs use 100% each, + * possible that, during a given time interval, 2 units use 100% each, * and the other two use nothing; while during another time interval, - * two vCPUs use 80%, one uses 10% and the other 30%; or that each use + * two units use 80%, one uses 10% and the other 30%; or that each use * 50% (and so on and so forth). * * For implementing this, we use the following approach: * * - each domain is given a 'budget', an each domain has a timer, which * replenishes the domain's budget periodically. The budget is the amount - * of time the vCPUs of the domain can use every 'period'; + * of time the units of the domain can use every 'period'; * * - the period is CSCHED2_BDGT_REPL_PERIOD, and is the same for all domai= ns * (but each domain has its own timer; so the all are periodic by the sa= me * period, but replenishment of the budgets of the various domains, at * periods boundaries, are not synchronous); * - * - when vCPUs run, they consume budget. When they don't run, they don't - * consume budget. If there is no budget left for the domain, no vCPU of - * that domain can run. If a vCPU tries to run and finds that there is no + * - when units run, they consume budget. When they don't run, they don't + * consume budget. If there is no budget left for the domain, no unit of + * that domain can run. If an unit tries to run and finds that there is = no * budget, it blocks. - * At whatever time a vCPU wants to run, it must check the domain's budg= et, + * At whatever time an unit wants to run, it must check the domain's bud= get, * and if there is some, it can use it. * * - budget is replenished to the top of the capacity for the domain once @@ -129,39 +129,39 @@ * though, the budget after a replenishment will always be at most equal * to the total capacify of the domain ('tot_budget'); * - * - when a budget replenishment occurs, if there are vCPUs that had been + * - when a budget replenishment occurs, if there are units that had been * blocked because of lack of budget, they'll be unblocked, and they will * (potentially) be able to run again. * * Finally, some even more implementation related detail: * - * - budget is stored in a domain-wide pool. vCPUs of the domain that want + * - budget is stored in a domain-wide pool. Items of the domain that want * to run go to such pool, and grub some. When they do so, the amount * they grabbed is _immediately_ removed from the pool. This happens in - * vcpu_grab_budget(); + * unit_grab_budget(); * - * - when vCPUs stop running, if they've not consumed all the budget they + * - when units stop running, if they've not consumed all the budget they * took, the leftover is put back in the pool. This happens in - * vcpu_return_budget(); + * unit_return_budget(); * - * - the above means that a vCPU can find out that there is no budget and + * - the above means that an unit can find out that there is no budget and * block, not only if the cap has actually been reached (for this period= ), - * but also if some other vCPUs, in order to run, have grabbed a certain + * but also if some other units, in order to run, have grabbed a certain * quota of budget, no matter whether they've already used it all or not. - * A vCPU blocking because (any form of) lack of budget is said to be - * "parked", and such blocking happens in park_vcpu(); + * An unit blocking because (any form of) lack of budget is said to be + * "parked", and such blocking happens in park_unit(); * - * - when a vCPU stops running, and puts back some budget in the domain po= ol, + * - when an unit stops running, and puts back some budget in the domain p= ool, * we need to check whether there is someone which has been parked and t= hat - * can be unparked. This happens in unpark_parked_vcpus(), called from + * can be unparked. This happens in unpark_parked_units(), called from * csched2_context_saved(); * * - of course, unparking happens also as a consequence of the domain's bu= dget * being replenished by the periodic timer. This also occurs by means of * calling csched2_context_saved() (but from replenish_domain_budget()); * - * - parked vCPUs of a domain are kept in a (per-domain) list, called - * 'parked_vcpus'). Manipulation of the list and of the domain-wide budg= et + * - parked units of a domain are kept in a (per-domain) list, called + * 'parked_units'). Manipulation of the list and of the domain-wide budg= et * pool, must occur only when holding the 'budget_lock'. */ =20 @@ -174,9 +174,9 @@ * pcpu_schedule_lock() / unit_schedule_lock() (and friends), * * a cpu may (try to) take a "remote" runqueue lock, e.g., for * load balancing; - * + serializes runqueue operations (removing and inserting vcpus); + * + serializes runqueue operations (removing and inserting units); * + protects runqueue-wide data in csched2_runqueue_data; - * + protects vcpu parameters in csched2_unit for the vcpu in the + * + protects unit parameters in csched2_unit for the unit in the * runqueue. * * - Private scheduler lock @@ -190,8 +190,8 @@ * + it is per-domain; * + protects, in domains that have an utilization cap; * * manipulation of the total budget of the domain (as it is shared - * among all vCPUs of the domain), - * * manipulation of the list of vCPUs that are blocked waiting for + * among all units of the domain), + * * manipulation of the list of units that are blocked waiting for * some budget to be available. * * - Type: @@ -228,9 +228,9 @@ */ #define CSCHED2_CREDIT_INIT MILLISECS(10) /* - * Amount of credit the idle vcpus have. It never changes, as idle - * vcpus does not consume credits, and it must be lower than whatever - * amount of credit 'regular' vcpu would end up with. + * Amount of credit the idle units have. It never changes, as idle + * units does not consume credits, and it must be lower than whatever + * amount of credit 'regular' unit would end up with. */ #define CSCHED2_IDLE_CREDIT (-(1U<<30)) /* @@ -243,9 +243,9 @@ * MIN_TIMER. */ #define CSCHED2_MIGRATE_RESIST ((opt_migrate_resist)*MICROSECS(1)) -/* How much to "compensate" a vcpu for L2 migration. */ +/* How much to "compensate" an unit for L2 migration. */ #define CSCHED2_MIGRATE_COMPENSATION MICROSECS(50) -/* How tolerant we should be when peeking at runtime of vcpus on other cpu= s */ +/* How tolerant we should be when peeking at runtime of units on other cpu= s */ #define CSCHED2_RATELIMIT_TICKLE_TOLERANCE MICROSECS(50) /* Reset: Value below which credit will be reset. */ #define CSCHED2_CREDIT_RESET 0 @@ -258,7 +258,7 @@ * Flags */ /* - * CSFLAG_scheduled: Is this vcpu either running on, or context-switching = off, + * CSFLAG_scheduled: Is this unit either running on, or context-switching = off, * a physical cpu? * + Accessed only with runqueue lock held * + Set when chosen as next in csched2_schedule(). @@ -280,21 +280,21 @@ #define __CSFLAG_delayed_runq_add 2 #define CSFLAG_delayed_runq_add (1U<<__CSFLAG_delayed_runq_add) /* - * CSFLAG_runq_migrate_request: This vcpu is being migrated as a result of= a + * CSFLAG_runq_migrate_request: This unit is being migrated as a result of= a * credit2-initiated runq migrate request; migrate it to the runqueue indi= cated - * in the svc struct.=20 + * in the svc struct. */ #define __CSFLAG_runq_migrate_request 3 #define CSFLAG_runq_migrate_request (1U<<__CSFLAG_runq_migrate_request) /* - * CSFLAG_vcpu_yield: this vcpu was running, and has called vcpu_yield(). = The + * CSFLAG_unit_yield: this unit was running, and has called vcpu_yield(). = The * scheduler is invoked to see if we can give the cpu to someone else, and - * get back to the yielding vcpu in a while. + * get back to the yielding unit in a while. */ -#define __CSFLAG_vcpu_yield 4 -#define CSFLAG_vcpu_yield (1U<<__CSFLAG_vcpu_yield) +#define __CSFLAG_unit_yield 4 +#define CSFLAG_unit_yield (1U<<__CSFLAG_unit_yield) /* - * CSFLAGS_pinned: this vcpu is currently 'pinned', i.e., has its hard + * CSFLAGS_pinned: this unit is currently 'pinned', i.e., has its hard * affinity set to one and only 1 cpu (and, hence, can only run there). */ #define __CSFLAG_pinned 5 @@ -306,7 +306,7 @@ integer_param("sched_credit2_migrate_resist", opt_migra= te_resist); /* * Load tracking and load balancing * - * Load history of runqueues and vcpus is accounted for by using an + * Load history of runqueues and units is accounted for by using an * exponential weighted moving average algorithm. However, instead of using * fractions,we shift everything to left by the number of bits we want to * use for representing the fractional part (Q-format). @@ -326,7 +326,7 @@ integer_param("sched_credit2_migrate_resist", opt_migra= te_resist); * * where W is the length of the window, P the multiplier for transitiong i= nto * Q-format fixed point arithmetic and load is the instantaneous load of a - * runqueue, which basically is the number of runnable vcpus there are on = the + * runqueue, which basically is the number of runnable units there are on = the * runqueue (for the meaning of the other terms, look at the doc comment to * update_runq_load()). * @@ -338,7 +338,7 @@ integer_param("sched_credit2_migrate_resist", opt_migra= te_resist); * The maximum possible value for the average load, which we want to store= in * s_time_t type variables (i.e., we have 63 bits available) is load*P. Th= is * means that, with P 18 bits wide, load can occupy 45 bits. This in turn - * means we can have 2^45 vcpus in each runqueue, before overflow occurs! + * means we can have 2^45 units in each runqueue, before overflow occurs! * * However, it can happen that, at step j+1, if: * @@ -354,13 +354,13 @@ integer_param("sched_credit2_migrate_resist", opt_mig= rate_resist); * * 2^(63 - 30 - 18) =3D 2^15 =3D 32768 * - * So 32768 is the maximum number of vcpus the we can have in a runqueue, + * So 32768 is the maximum number of units the we can have in a runqueue, * at any given time, and still not have problems with the load tracking * calculations... and this is more than fine. * * As a matter of fact, since we are using microseconds granularity, we ha= ve * W=3D2^20. So, still with 18 fractional bits and a 1 second long window,= there - * may be 2^25 =3D 33554432 vcpus in a runq before we have to start thinki= ng + * may be 2^25 =3D 33554432 units in a runq before we have to start thinki= ng * about overflow. */ =20 @@ -469,7 +469,7 @@ struct csched2_runqueue_data { unsigned int nr_cpus; /* How many CPUs are sharing this runqueue = */ int id; /* ID of this runqueue (-1 if invalid) = */ =20 - int load; /* Instantaneous load (num of non-idle vcpu= s) */ + int load; /* Instantaneous load (num of non-idle unit= s) */ s_time_t load_last_update; /* Last time average was updated = */ s_time_t avgload; /* Decaying queue load = */ s_time_t b_avgload; /* Decaying queue load modified by balancin= g */ @@ -479,8 +479,8 @@ struct csched2_runqueue_data { tickled, /* Have been asked to go through schedule = */ idle; /* Currently idle pcpus = */ =20 - struct list_head svc; /* List of all vcpus assigned to the runque= ue */ - unsigned int max_weight; /* Max weight of the vcpus in this runqueue= */ + struct list_head svc; /* List of all units assigned to the runque= ue */ + unsigned int max_weight; /* Max weight of the units in this runqueue= */ unsigned int pick_bias; /* Last picked pcpu. Start from it next tim= e */ }; =20 @@ -510,20 +510,20 @@ struct csched2_pcpu { }; =20 /* - * Virtual CPU + * Schedule Item */ struct csched2_unit { struct csched2_dom *sdom; /* Up-pointer to domain = */ - struct vcpu *vcpu; /* Up-pointer, to vcpu = */ + struct sched_unit *unit; /* Up-pointer, to schedule unit = */ struct csched2_runqueue_data *rqd; /* Up-pointer to the runqueue = */ =20 int credit; /* Current amount of credit = */ - unsigned int weight; /* Weight of this vcpu = */ + unsigned int weight; /* Weight of this unit = */ unsigned int residual; /* Reminder of div(max_weight/weigh= t) */ unsigned flags; /* Status flags (16 bits would be o= k, */ s_time_t budget; /* Current budget (if domains has c= ap) */ /* but clear_bit() does not like th= at) */ - s_time_t budget_quota; /* Budget to which vCPU is entitled= */ + s_time_t budget_quota; /* Budget to which unit is entitled= */ =20 s_time_t start_time; /* Time we were scheduled (for cred= it) */ =20 @@ -532,7 +532,7 @@ struct csched2_unit { s_time_t avgload; /* Decaying queue load = */ =20 struct list_head runq_elem; /* On the runqueue (rqd->runq) = */ - struct list_head parked_elem; /* On the parked_vcpus list = */ + struct list_head parked_elem; /* On the parked_units list = */ struct list_head rqd_elem; /* On csched2_runqueue_data's svc l= ist */ struct csched2_runqueue_data *migrate_rqd; /* Pre-determined migr. tar= get */ int tickled_cpu; /* Cpu that will pick us (-1 if non= e) */ @@ -550,12 +550,12 @@ struct csched2_dom { =20 struct timer repl_timer; /* Timer for periodic replenishment of bud= get */ s_time_t next_repl; /* Time at which next replenishment occurs= */ - struct list_head parked_vcpus; /* List of CPUs waiting for budget = */ + struct list_head parked_units; /* List of CPUs waiting for budget = */ =20 struct list_head sdom_elem; /* On csched2_runqueue_data's sdom list = */ uint16_t weight; /* User specified weight = */ uint16_t cap; /* User specified cap = */ - uint16_t nr_vcpus; /* Number of vcpus of this domain = */ + uint16_t nr_units; /* Number of units of this domain = */ }; =20 /* @@ -594,7 +594,7 @@ static inline struct csched2_runqueue_data *c2rqd(const= struct scheduler *ops, return &csched2_priv(ops)->rqd[c2r(cpu)]; } =20 -/* Does the domain of this vCPU have a cap? */ +/* Does the domain of this unit have a cap? */ static inline bool has_cap(const struct csched2_unit *svc) { return svc->budget !=3D STIME_MAX; @@ -612,24 +612,24 @@ static inline bool has_cap(const struct csched2_unit = *svc) * smt_idle mask. * * Once we have such a mask, it is easy to implement a policy that, either: - * - uses fully idle cores first: it is enough to try to schedule the vcp= us + * - uses fully idle cores first: it is enough to try to schedule the uni= ts * on pcpus from smt_idle mask first. This is what happens if * sched_smt_power_savings was not set at boot (default), and it maximi= zes * true parallelism, and hence performance; - * - uses already busy cores first: it is enough to try to schedule the v= cpus + * - uses already busy cores first: it is enough to try to schedule the u= nits * on pcpus that are idle, but are not in smt_idle. This is what happen= s if * sched_smt_power_savings is set at boot, and it allows as more cores = as * possible to stay in low power states, minimizing power consumption. * * This logic is entirely implemented in runq_tickle(), and that is enough. - * In fact, in this scheduler, placement of a vcpu on one of the pcpus of a + * In fact, in this scheduler, placement of an unit on one of the pcpus of= a * runq, _always_ happens by means of tickling: - * - when a vcpu wakes up, it calls csched2_unit_wake(), which calls + * - when an unit wakes up, it calls csched2_unit_wake(), which calls * runq_tickle(); * - when a migration is initiated in schedule.c, we call csched2_res_pic= k(), * csched2_unit_migrate() (which calls migrate()) and csched2_unit_wake= (). * csched2_res_pick() looks for the least loaded runq and return just a= ny - * of its processors. Then, csched2_unit_migrate() just moves the vcpu = to + * of its processors. Then, csched2_unit_migrate() just moves the unit = to * the chosen runq, and it is again runq_tickle(), called by * csched2_unit_wake() that actually decides what pcpu to use within the * chosen runq; @@ -644,7 +644,7 @@ static inline bool has_cap(const struct csched2_unit *s= vc) * * NB that rqd->smt_idle is different than rqd->idle. rqd->idle * records pcpus that at are merely idle (i.e., at the moment do not - * have a vcpu running on them). But you have to manually filter out + * have an unit running on them). But you have to manually filter out * which pcpus have been tickled in order to find cores that are not * going to be busy soon. Filtering out tickled cpus pairwise is a * lot of extra pain; so for rqd->smt_idle, we explicitly make so that @@ -691,24 +691,24 @@ void smt_idle_mask_clear(unsigned int cpu, cpumask_t = *mask) */ static int get_fallback_cpu(struct csched2_unit *svc) { - struct vcpu *v =3D svc->vcpu; + struct sched_unit *unit =3D svc->unit; unsigned int bs; =20 SCHED_STAT_CRANK(need_fallback_cpu); =20 for_each_affinity_balance_step( bs ) { - int cpu =3D v->processor; + int cpu =3D sched_unit_cpu(unit); =20 - if ( bs =3D=3D BALANCE_SOFT_AFFINITY && !has_soft_affinity(v->sche= d_unit) ) + if ( bs =3D=3D BALANCE_SOFT_AFFINITY && !has_soft_affinity(unit) ) continue; =20 - affinity_balance_cpumask(v->sched_unit, bs, cpumask_scratch_cpu(cp= u)); + affinity_balance_cpumask(unit, bs, cpumask_scratch_cpu(cpu)); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), - cpupool_domain_cpumask(v->domain)); + cpupool_domain_cpumask(unit->domain)); =20 /* - * This is cases 1 or 3 (depending on bs): if v->processor is (sti= ll) + * This is cases 1 or 3 (depending on bs): if processor is (still) * in our affinity, go for it, for cache betterness. */ if ( likely(cpumask_test_cpu(cpu, cpumask_scratch_cpu(cpu))) ) @@ -730,7 +730,7 @@ static int get_fallback_cpu(struct csched2_unit *svc) * We may well pick any valid pcpu from our soft-affinity, outside * of our current runqueue, but we decide not to. In fact, changing * runqueue is slow, affects load distribution, and is a source of - * overhead for the vcpus running on the other runqueue (we need t= he + * overhead for the units running on the other runqueue (we need t= he * lock). So, better do that as a consequence of a well informed * decision (or if we really don't have any other chance, as we wi= ll, * at step 5, if we get to there). @@ -762,7 +762,7 @@ static int get_fallback_cpu(struct csched2_unit *svc) * We can't be here. But if that somehow happen (in non-debug builds), * at least return something which both online and in our hard-affinit= y. */ - return cpumask_any(cpumask_scratch_cpu(v->processor)); + return cpumask_any(cpumask_scratch_cpu(sched_unit_cpu(unit))); } =20 /* @@ -791,7 +791,7 @@ static s_time_t c2t(struct csched2_runqueue_data *rqd, = s_time_t credit, struct c * Runqueue related code. */ =20 -static inline int vcpu_on_runq(struct csched2_unit *svc) +static inline int unit_on_runq(struct csched2_unit *svc) { return !list_empty(&svc->runq_elem); } @@ -949,17 +949,17 @@ _runq_assign(struct csched2_unit *svc, struct csched2= _runqueue_data *rqd) =20 update_max_weight(svc->rqd, svc->weight, 0); =20 - /* Expected new load based on adding this vcpu */ + /* Expected new load based on adding this unit */ rqd->b_avgload +=3D svc->avgload; =20 if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; unsigned rqi:16; } d; - d.dom =3D svc->vcpu->domain->domain_id; - d.vcpu =3D svc->vcpu->vcpu_id; + d.dom =3D svc->unit->domain->domain_id; + d.unit =3D svc->unit->unit_id; d.rqi=3Drqd->id; __trace_var(TRC_CSCHED2_RUNQ_ASSIGN, 1, sizeof(d), @@ -969,13 +969,13 @@ _runq_assign(struct csched2_unit *svc, struct csched2= _runqueue_data *rqd) } =20 static void -runq_assign(const struct scheduler *ops, struct vcpu *vc) +runq_assign(const struct scheduler *ops, struct sched_unit *unit) { - struct csched2_unit *svc =3D vc->sched_unit->priv; + struct csched2_unit *svc =3D unit->priv; =20 ASSERT(svc->rqd =3D=3D NULL); =20 - _runq_assign(svc, c2rqd(ops, vc->processor)); + _runq_assign(svc, c2rqd(ops, sched_unit_cpu(unit))); } =20 static void @@ -983,24 +983,24 @@ _runq_deassign(struct csched2_unit *svc) { struct csched2_runqueue_data *rqd =3D svc->rqd; =20 - ASSERT(!vcpu_on_runq(svc)); + ASSERT(!unit_on_runq(svc)); ASSERT(!(svc->flags & CSFLAG_scheduled)); =20 list_del_init(&svc->rqd_elem); update_max_weight(rqd, 0, svc->weight); =20 - /* Expected new load based on removing this vcpu */ + /* Expected new load based on removing this unit */ rqd->b_avgload =3D max_t(s_time_t, rqd->b_avgload - svc->avgload, 0); =20 svc->rqd =3D NULL; } =20 static void -runq_deassign(const struct scheduler *ops, struct vcpu *vc) +runq_deassign(const struct scheduler *ops, struct sched_unit *unit) { - struct csched2_unit *svc =3D vc->sched_unit->priv; + struct csched2_unit *svc =3D unit->priv; =20 - ASSERT(svc->rqd =3D=3D c2rqd(ops, vc->processor)); + ASSERT(svc->rqd =3D=3D c2rqd(ops, sched_unit_cpu(unit))); =20 _runq_deassign(svc); } @@ -1203,15 +1203,15 @@ update_svc_load(const struct scheduler *ops, struct csched2_unit *svc, int change, s_time_t now) { struct csched2_private *prv =3D csched2_priv(ops); - s_time_t delta, vcpu_load; + s_time_t delta, unit_load; unsigned int P, W; =20 if ( change =3D=3D -1 ) - vcpu_load =3D 1; + unit_load =3D 1; else if ( change =3D=3D 1 ) - vcpu_load =3D 0; + unit_load =3D 0; else - vcpu_load =3D vcpu_runnable(svc->vcpu); + unit_load =3D unit_runnable(svc->unit); =20 W =3D prv->load_window_shift; P =3D prv->load_precision_shift; @@ -1219,7 +1219,7 @@ update_svc_load(const struct scheduler *ops, =20 if ( svc->load_last_update + (1ULL << W) < now ) { - svc->avgload =3D vcpu_load << P; + svc->avgload =3D unit_load << P; } else { @@ -1232,7 +1232,7 @@ update_svc_load(const struct scheduler *ops, } =20 svc->avgload =3D svc->avgload + - ((delta * (vcpu_load << P)) >> W) - + ((delta * (unit_load << P)) >> W) - ((delta * svc->avgload) >> W); } svc->load_last_update =3D now; @@ -1244,14 +1244,14 @@ update_svc_load(const struct scheduler *ops, { struct { uint64_t v_avgload; - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; unsigned shift; } d; - d.dom =3D svc->vcpu->domain->domain_id; - d.vcpu =3D svc->vcpu->vcpu_id; + d.dom =3D svc->unit->domain->domain_id; + d.unit =3D svc->unit->unit_id; d.v_avgload =3D svc->avgload; d.shift =3D P; - __trace_var(TRC_CSCHED2_UPDATE_VCPU_LOAD, 1, + __trace_var(TRC_CSCHED2_UPDATE_UNIT_LOAD, 1, sizeof(d), (unsigned char *)&d); } @@ -1273,18 +1273,18 @@ static void runq_insert(const struct scheduler *ops, struct csched2_unit *svc) { struct list_head *iter; - unsigned int cpu =3D svc->vcpu->processor; + unsigned int cpu =3D sched_unit_cpu(svc->unit); struct list_head * runq =3D &c2rqd(ops, cpu)->runq; int pos =3D 0; =20 ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 - ASSERT(!vcpu_on_runq(svc)); - ASSERT(c2r(cpu) =3D=3D c2r(svc->vcpu->processor)); + ASSERT(!unit_on_runq(svc)); + ASSERT(c2r(cpu) =3D=3D c2r(sched_unit_cpu(svc->unit))); =20 ASSERT(&svc->rqd->runq =3D=3D runq); - ASSERT(!is_idle_vcpu(svc->vcpu)); - ASSERT(!svc->vcpu->sched_unit->is_running); + ASSERT(!is_idle_unit(svc->unit)); + ASSERT(!svc->unit->is_running); ASSERT(!(svc->flags & CSFLAG_scheduled)); =20 list_for_each( iter, runq ) @@ -1301,11 +1301,11 @@ runq_insert(const struct scheduler *ops, struct csc= hed2_unit *svc) if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; unsigned pos; } d; - d.dom =3D svc->vcpu->domain->domain_id; - d.vcpu =3D svc->vcpu->vcpu_id; + d.dom =3D svc->unit->domain->domain_id; + d.unit =3D svc->unit->unit_id; d.pos =3D pos; __trace_var(TRC_CSCHED2_RUNQ_POS, 1, sizeof(d), @@ -1315,7 +1315,7 @@ runq_insert(const struct scheduler *ops, struct csche= d2_unit *svc) =20 static inline void runq_remove(struct csched2_unit *svc) { - ASSERT(vcpu_on_runq(svc)); + ASSERT(unit_on_runq(svc)); list_del_init(&svc->runq_elem); } =20 @@ -1341,8 +1341,8 @@ static inline bool is_preemptable(const struct csched= 2_unit *svc, if ( ratelimit <=3D CSCHED2_RATELIMIT_TICKLE_TOLERANCE ) return true; =20 - ASSERT(svc->vcpu->sched_unit->is_running); - return now - svc->vcpu->sched_unit->state_entry_time > + ASSERT(svc->unit->is_running); + return now - svc->unit->state_entry_time > ratelimit - CSCHED2_RATELIMIT_TICKLE_TOLERANCE; } =20 @@ -1370,17 +1370,17 @@ static s_time_t tickle_score(const struct scheduler= *ops, s_time_t now, =20 /* * We are dealing with cpus that are marked non-idle (i.e., that are n= ot - * in rqd->idle). However, some of them may be running their idle vcpu, + * in rqd->idle). However, some of them may be running their idle unit, * if taking care of tasklets. In that case, we want to leave it alone. */ - if ( unlikely(is_idle_vcpu(cur->vcpu) || + if ( unlikely(is_idle_unit(cur->unit) || !is_preemptable(cur, now, MICROSECS(prv->ratelimit_us))) ) return -1; =20 burn_credits(rqd, cur, now); =20 score =3D new->credit - cur->credit; - if ( new->vcpu->processor !=3D cpu ) + if ( sched_unit_cpu(new->unit) !=3D cpu ) score -=3D CSCHED2_MIGRATE_RESIST; =20 /* @@ -1391,21 +1391,21 @@ static s_time_t tickle_score(const struct scheduler= *ops, s_time_t now, */ if ( score > 0 ) { - if ( cpumask_test_cpu(cpu, new->vcpu->sched_unit->cpu_soft_affinit= y) ) + if ( cpumask_test_cpu(cpu, new->unit->cpu_soft_affinity) ) score +=3D CSCHED2_CREDIT_INIT; =20 - if ( !cpumask_test_cpu(cpu, cur->vcpu->sched_unit->cpu_soft_affini= ty) ) + if ( !cpumask_test_cpu(cpu, cur->unit->cpu_soft_affinity) ) score +=3D CSCHED2_CREDIT_INIT; } =20 if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; int credit, score; } d; - d.dom =3D cur->vcpu->domain->domain_id; - d.vcpu =3D cur->vcpu->vcpu_id; + d.dom =3D cur->unit->domain->domain_id; + d.unit =3D cur->unit->unit_id; d.credit =3D cur->credit; d.score =3D score; __trace_var(TRC_CSCHED2_TICKLE_CHECK, 1, @@ -1417,14 +1417,14 @@ static s_time_t tickle_score(const struct scheduler= *ops, s_time_t now, } =20 /* - * Check what processor it is best to 'wake', for picking up a vcpu that h= as + * Check what processor it is best to 'wake', for picking up an unit that = has * just been put (back) in the runqueue. Logic is as follows: * 1. if there are idle processors in the runq, wake one of them; - * 2. if there aren't idle processor, check the one were the vcpu was + * 2. if there aren't idle processor, check the one were the unit was * running before to see if we can preempt what's running there now * (and hence doing just one migration); - * 3. last stand: check all processors and see if the vcpu is in right - * of preempting any of the other vcpus running on them (this requires + * 3. last stand: check all processors and see if the unit is in right + * of preempting any of the other units running on them (this requires * two migrations, and that's indeed why it is left as the last stand). * * Note that when we say 'idle processors' what we really mean is (pretty @@ -1437,10 +1437,10 @@ runq_tickle(const struct scheduler *ops, struct csc= hed2_unit *new, s_time_t now) { int i, ipid =3D -1; s_time_t max =3D 0; - struct sched_unit *unit =3D new->vcpu->sched_unit; - unsigned int bs, cpu =3D new->vcpu->processor; + struct sched_unit *unit =3D new->unit; + unsigned int bs, cpu =3D sched_unit_cpu(unit); struct csched2_runqueue_data *rqd =3D c2rqd(ops, cpu); - cpumask_t *online =3D cpupool_domain_cpumask(new->vcpu->domain); + cpumask_t *online =3D cpupool_domain_cpumask(unit->domain); cpumask_t mask; =20 ASSERT(new->rqd =3D=3D rqd); @@ -1448,13 +1448,13 @@ runq_tickle(const struct scheduler *ops, struct csc= hed2_unit *new, s_time_t now) if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; unsigned processor; int credit; } d; - d.dom =3D new->vcpu->domain->domain_id; - d.vcpu =3D new->vcpu->vcpu_id; - d.processor =3D new->vcpu->processor; + d.dom =3D unit->domain->domain_id; + d.unit =3D unit->unit_id; + d.processor =3D cpu; d.credit =3D new->credit; __trace_var(TRC_CSCHED2_TICKLE_NEW, 1, sizeof(d), @@ -1462,11 +1462,11 @@ runq_tickle(const struct scheduler *ops, struct csc= hed2_unit *new, s_time_t now) } =20 /* - * Exclusive pinning is when a vcpu has hard-affinity with only one - * cpu, and there is no other vcpu that has hard-affinity with that + * Exclusive pinning is when an unit has hard-affinity with only one + * cpu, and there is no other unit that has hard-affinity with that * same cpu. This is infrequent, but if it happens, is for achieving * the most possible determinism, and least possible overhead for - * the vcpus in question. + * the units in question. * * Try to identify the vast majority of these situations, and deal * with them quickly. @@ -1533,7 +1533,7 @@ runq_tickle(const struct scheduler *ops, struct csche= d2_unit *new, s_time_t now) /* * Note that, if we are here, it means we have done the hard-affinity * balancing step of the loop, and hence what we have in cpumask_scrat= ch - * is what we put there for last, i.e., new's vcpu_hard_affinity & onl= ine + * is what we put there for last, i.e., new's unit_hard_affinity & onl= ine * which is exactly what we need for the next part of the function. */ =20 @@ -1544,7 +1544,7 @@ runq_tickle(const struct scheduler *ops, struct csche= d2_unit *new, s_time_t now) * * For deciding which cpu to tickle, we use tickle_score(), which will * factor in both new's soft-affinity, and the soft-affinity of the - * vcpu running on each cpu that we consider. + * unit running on each cpu that we consider. */ cpumask_andnot(&mask, &rqd->active, &rqd->idle); cpumask_andnot(&mask, &mask, &rqd->tickled); @@ -1589,7 +1589,7 @@ runq_tickle(const struct scheduler *ops, struct csche= d2_unit *new, s_time_t now) return; } =20 - ASSERT(!is_idle_vcpu(curr_on_cpu(ipid)->vcpu_list)); + ASSERT(!is_idle_unit(curr_on_cpu(ipid))); SCHED_STAT_CRANK(tickled_busy_cpu); tickle: BUG_ON(ipid =3D=3D -1); @@ -1624,16 +1624,16 @@ static void reset_credit(const struct scheduler *op= s, int cpu, s_time_t now, =20 /* * Under normal circumstances, snext->credit should never be less - * than -CSCHED2_MIN_TIMER. However, under some circumstances, a - * vcpu with low credits may be allowed to run long enough that + * than -CSCHED2_MIN_TIMER. However, under some circumstances, an + * unit with low credits may be allowed to run long enough that * its credits are actually less than -CSCHED2_CREDIT_INIT. - * (Instances have been observed, for example, where a vcpu with + * (Instances have been observed, for example, where an unit with * 200us of credit was allowed to run for 11ms, giving it -10.8ms * of credit. Thus it was still negative even after the reset.) * * If this is the case for snext, we simply want to keep moving * everyone up until it is in the black again. This fair because - * none of the other vcpus want to run at the moment. + * none of the other units want to run at the moment. * * Rather than looping, however, we just calculate a multiplier, * avoiding an integer division and multiplication in the common @@ -1650,16 +1650,16 @@ static void reset_credit(const struct scheduler *op= s, int cpu, s_time_t now, int start_credit; =20 svc =3D list_entry(iter, struct csched2_unit, rqd_elem); - svc_cpu =3D svc->vcpu->processor; + svc_cpu =3D sched_unit_cpu(svc->unit); =20 - ASSERT(!is_idle_vcpu(svc->vcpu)); + ASSERT(!is_idle_unit(svc->unit)); ASSERT(svc->rqd =3D=3D rqd); =20 /* * If svc is running, it is our responsibility to make sure, here, * that the credit it has spent so far get accounted. */ - if ( svc->vcpu =3D=3D curr_on_cpu(svc_cpu)->vcpu_list ) + if ( svc->unit =3D=3D curr_on_cpu(svc_cpu) ) { burn_credits(rqd, svc, now); /* @@ -1690,12 +1690,12 @@ static void reset_credit(const struct scheduler *op= s, int cpu, s_time_t now, if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; int credit_start, credit_end; unsigned multiplier; } d; - d.dom =3D svc->vcpu->domain->domain_id; - d.vcpu =3D svc->vcpu->vcpu_id; + d.dom =3D svc->unit->domain->domain_id; + d.unit =3D svc->unit->unit_id; d.credit_start =3D start_credit; d.credit_end =3D svc->credit; d.multiplier =3D m; @@ -1715,9 +1715,9 @@ void burn_credits(struct csched2_runqueue_data *rqd, { s_time_t delta; =20 - ASSERT(svc =3D=3D csched2_unit(curr_on_cpu(svc->vcpu->processor))); + ASSERT(svc =3D=3D csched2_unit(curr_on_cpu(sched_unit_cpu(svc->unit)))= ); =20 - if ( unlikely(is_idle_vcpu(svc->vcpu)) ) + if ( unlikely(is_idle_unit(svc->unit)) ) { ASSERT(svc->credit =3D=3D CSCHED2_IDLE_CREDIT); return; @@ -1746,12 +1746,12 @@ void burn_credits(struct csched2_runqueue_data *rqd, if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; int credit, budget; int delta; } d; - d.dom =3D svc->vcpu->domain->domain_id; - d.vcpu =3D svc->vcpu->vcpu_id; + d.dom =3D svc->unit->domain->domain_id; + d.unit =3D svc->unit->unit_id; d.credit =3D svc->credit; d.budget =3D has_cap(svc) ? svc->budget : INT_MIN; d.delta =3D delta; @@ -1765,39 +1765,39 @@ void burn_credits(struct csched2_runqueue_data *rqd, * Budget-related code. */ =20 -static void park_vcpu(struct csched2_unit *svc) +static void park_unit(struct csched2_unit *svc) { - struct vcpu *v =3D svc->vcpu; + struct sched_unit *unit =3D svc->unit; =20 ASSERT(spin_is_locked(&svc->sdom->budget_lock)); =20 /* - * It was impossible to find budget for this vCPU, so it has to be + * It was impossible to find budget for this unit, so it has to be * "parked". This implies it is not runnable, so we mark it as such in - * its pause_flags. If the vCPU is currently scheduled (which means we + * its pause_flags. If the unit is currently scheduled (which means we * are here after being called from within csched_schedule()), flagging * is enough, as we'll choose someone else, and then context_saved() * will take care of updating the load properly. * - * If, OTOH, the vCPU is sitting in the runqueue (which means we are h= ere + * If, OTOH, the unit is sitting in the runqueue (which means we are h= ere * after being called from within runq_candidate()), we must go all the * way down to taking it out of there, and updating the load according= ly. * - * In both cases, we also add it to the list of parked vCPUs of the do= main. + * In both cases, we also add it to the list of parked units of the do= main. */ - __set_bit(_VPF_parked, &v->pause_flags); - if ( vcpu_on_runq(svc) ) + sched_set_pause_flags(unit, _VPF_parked); + if ( unit_on_runq(svc) ) { runq_remove(svc); update_load(svc->sdom->dom->cpupool->sched, svc->rqd, svc, -1, NOW= ()); } - list_add(&svc->parked_elem, &svc->sdom->parked_vcpus); + list_add(&svc->parked_elem, &svc->sdom->parked_units); } =20 -static bool vcpu_grab_budget(struct csched2_unit *svc) +static bool unit_grab_budget(struct csched2_unit *svc) { struct csched2_dom *sdom =3D svc->sdom; - unsigned int cpu =3D svc->vcpu->processor; + unsigned int cpu =3D sched_unit_cpu(svc->unit); =20 ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 @@ -1809,9 +1809,9 @@ static bool vcpu_grab_budget(struct csched2_unit *svc) =20 /* * Here, svc->budget is <=3D 0 (as, if it was > 0, we'd have taken the= if - * above!). That basically means the vCPU has overrun a bit --because = of + * above!). That basically means the unit has overrun a bit --because = of * various reasons-- and we want to take that into account. With the += =3D, - * we are actually subtracting the amount of budget the vCPU has + * we are actually subtracting the amount of budget the unit has * overconsumed, from the total domain budget. */ sdom->budget +=3D svc->budget; @@ -1832,7 +1832,7 @@ static bool vcpu_grab_budget(struct csched2_unit *svc) else { svc->budget =3D 0; - park_vcpu(svc); + park_unit(svc); } =20 spin_unlock(&sdom->budget_lock); @@ -1841,10 +1841,10 @@ static bool vcpu_grab_budget(struct csched2_unit *s= vc) } =20 static void -vcpu_return_budget(struct csched2_unit *svc, struct list_head *parked) +unit_return_budget(struct csched2_unit *svc, struct list_head *parked) { struct csched2_dom *sdom =3D svc->sdom; - unsigned int cpu =3D svc->vcpu->processor; + unsigned int cpu =3D sched_unit_cpu(svc->unit); =20 ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); ASSERT(list_empty(parked)); @@ -1853,7 +1853,7 @@ vcpu_return_budget(struct csched2_unit *svc, struct l= ist_head *parked) spin_lock(&sdom->budget_lock); =20 /* - * The vCPU is stopping running (e.g., because it's blocking, or it has + * The unit is stopping running (e.g., because it's blocking, or it has * been preempted). If it hasn't consumed all the budget it got when, * starting to run, put that remaining amount back in the domain's bud= get * pool. @@ -1862,58 +1862,58 @@ vcpu_return_budget(struct csched2_unit *svc, struct= list_head *parked) svc->budget =3D 0; =20 /* - * Making budget available again to the domain means that parked vCPUs - * may be unparked and run. They are, if any, in the domain's parked_v= cpus + * Making budget available again to the domain means that parked units + * may be unparked and run. They are, if any, in the domain's parked_u= nits * list, so we want to go through that and unpark them (so they can try * to get some budget). * * Touching the list requires the budget_lock, which we hold. Let's * therefore put everyone in that list in another, temporary list, whi= ch - * then the caller will traverse, unparking the vCPUs it finds there. + * then the caller will traverse, unparking the units it finds there. * * In fact, we can't do the actual unparking here, because that requir= es - * taking the runqueue lock of the vCPUs being unparked, and we can't + * taking the runqueue lock of the units being unparked, and we can't * take any runqueue locks while we hold a budget_lock. */ if ( sdom->budget > 0 ) - list_splice_init(&sdom->parked_vcpus, parked); + list_splice_init(&sdom->parked_units, parked); =20 spin_unlock(&sdom->budget_lock); } =20 static void -unpark_parked_vcpus(const struct scheduler *ops, struct list_head *vcpus) +unpark_parked_units(const struct scheduler *ops, struct list_head *units) { struct csched2_unit *svc, *tmp; spinlock_t *lock; =20 - list_for_each_entry_safe(svc, tmp, vcpus, parked_elem) + list_for_each_entry_safe ( svc, tmp, units, parked_elem ) { unsigned long flags; s_time_t now; =20 - lock =3D unit_schedule_lock_irqsave(svc->vcpu->sched_unit, &flags); + lock =3D unit_schedule_lock_irqsave(svc->unit, &flags); =20 - __clear_bit(_VPF_parked, &svc->vcpu->pause_flags); + sched_clear_pause_flags(svc->unit, _VPF_parked); if ( unlikely(svc->flags & CSFLAG_scheduled) ) { /* * We end here if a budget replenishment arrived between * csched2_schedule() (and, in particular, after a call to - * vcpu_grab_budget() that returned false), and + * unit_grab_budget() that returned false), and * context_saved(). By setting __CSFLAG_delayed_runq_add, - * we tell context_saved() to put the vCPU back in the + * we tell context_saved() to put the unit back in the * runqueue, from where it will compete with the others * for the newly replenished budget. */ ASSERT( svc->rqd !=3D NULL ); - ASSERT( c2rqd(ops, svc->vcpu->processor) =3D=3D svc->rqd ); + ASSERT( c2rqd(ops, sched_unit_cpu(svc->unit)) =3D=3D svc->rqd = ); __set_bit(__CSFLAG_delayed_runq_add, &svc->flags); } - else if ( vcpu_runnable(svc->vcpu) ) + else if ( unit_runnable(svc->unit) ) { /* - * The vCPU should go back to the runqueue, and compete for + * The unit should go back to the runqueue, and compete for * the newly replenished budget, but only if it is actually * runnable (and was therefore offline only because of the * lack of budget). @@ -1925,7 +1925,7 @@ unpark_parked_vcpus(const struct scheduler *ops, stru= ct list_head *vcpus) } list_del_init(&svc->parked_elem); =20 - unit_schedule_unlock_irqrestore(lock, flags, svc->vcpu->sched_unit= ); + unit_schedule_unlock_irqrestore(lock, flags, svc->unit); } } =20 @@ -1955,7 +1955,7 @@ static void replenish_domain_budget(void* data) * * Even in cases of overrun or delay, however, we expect that in 99% of * cases, doing just one replenishment will be good enough for being a= ble - * to unpark the vCPUs that are waiting for some budget. + * to unpark the units that are waiting for some budget. */ do_replenish(sdom); =20 @@ -1975,7 +1975,7 @@ static void replenish_domain_budget(void* data) } /* * 2) if we overrun by more than tot_budget, then budget+tot_budget is - * still < 0, which means that we can't unpark the vCPUs. Let's bail, + * still < 0, which means that we can't unpark the units. Let's bail, * and wait for future replenishments. */ if ( unlikely(sdom->budget <=3D 0) ) @@ -1989,14 +1989,14 @@ static void replenish_domain_budget(void* data) =20 /* * As above, let's prepare the temporary list, out of the domain's - * parked_vcpus list, now that we hold the budget_lock. Then, drop such + * parked_units list, now that we hold the budget_lock. Then, drop such * lock, and pass the list to the unparking function. */ - list_splice_init(&sdom->parked_vcpus, &parked); + list_splice_init(&sdom->parked_units, &parked); =20 spin_unlock_irqrestore(&sdom->budget_lock, flags); =20 - unpark_parked_vcpus(sdom->dom->cpupool->sched, &parked); + unpark_parked_units(sdom->dom->cpupool->sched, &parked); =20 out: set_timer(&sdom->repl_timer, sdom->next_repl); @@ -2004,37 +2004,36 @@ static void replenish_domain_budget(void* data) =20 #ifndef NDEBUG static inline void -csched2_vcpu_check(struct vcpu *vc) +csched2_unit_check(struct sched_unit *unit) { - struct csched2_unit * const svc =3D csched2_unit(vc->sched_unit); + struct csched2_unit * const svc =3D csched2_unit(unit); struct csched2_dom * const sdom =3D svc->sdom; =20 - BUG_ON( svc->vcpu !=3D vc ); - BUG_ON( sdom !=3D csched2_dom(vc->domain) ); + BUG_ON( svc->unit !=3D unit ); + BUG_ON( sdom !=3D csched2_dom(unit->domain) ); if ( sdom ) { - BUG_ON( is_idle_vcpu(vc) ); - BUG_ON( sdom->dom !=3D vc->domain ); + BUG_ON( is_idle_unit(unit) ); + BUG_ON( sdom->dom !=3D unit->domain ); } else { - BUG_ON( !is_idle_vcpu(vc) ); + BUG_ON( !is_idle_unit(unit) ); } SCHED_STAT_CRANK(unit_check); } -#define CSCHED2_VCPU_CHECK(_vc) (csched2_vcpu_check(_vc)) +#define CSCHED2_UNIT_CHECK(unit) (csched2_unit_check(unit)) #else -#define CSCHED2_VCPU_CHECK(_vc) +#define CSCHED2_UNIT_CHECK(unit) #endif =20 static void * csched2_alloc_vdata(const struct scheduler *ops, struct sched_unit *unit, void *dd) { - struct vcpu *vc =3D unit->vcpu_list; struct csched2_unit *svc; =20 - /* Allocate per-VCPU info */ + /* Allocate per-UNIT info */ svc =3D xzalloc(struct csched2_unit); if ( svc =3D=3D NULL ) return NULL; @@ -2043,10 +2042,10 @@ csched2_alloc_vdata(const struct scheduler *ops, st= ruct sched_unit *unit, INIT_LIST_HEAD(&svc->runq_elem); =20 svc->sdom =3D dd; - svc->vcpu =3D vc; + svc->unit =3D unit; svc->flags =3D 0U; =20 - if ( ! is_idle_vcpu(vc) ) + if ( ! is_idle_unit(unit) ) { ASSERT(svc->sdom !=3D NULL); svc->credit =3D CSCHED2_CREDIT_INIT; @@ -2075,19 +2074,18 @@ csched2_alloc_vdata(const struct scheduler *ops, st= ruct sched_unit *unit, static void csched2_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct csched2_unit * const svc =3D csched2_unit(unit); =20 - ASSERT(!is_idle_vcpu(vc)); + ASSERT(!is_idle_unit(unit)); SCHED_STAT_CRANK(unit_sleep); =20 - if ( curr_on_cpu(vc->processor) =3D=3D unit ) + if ( curr_on_cpu(sched_unit_cpu(unit)) =3D=3D unit ) { - tickle_cpu(vc->processor, svc->rqd); + tickle_cpu(sched_unit_cpu(unit), svc->rqd); } - else if ( vcpu_on_runq(svc) ) + else if ( unit_on_runq(svc) ) { - ASSERT(svc->rqd =3D=3D c2rqd(ops, vc->processor)); + ASSERT(svc->rqd =3D=3D c2rqd(ops, sched_unit_cpu(unit))); update_load(ops, svc->rqd, svc, -1, NOW()); runq_remove(svc); } @@ -2098,14 +2096,13 @@ csched2_unit_sleep(const struct scheduler *ops, str= uct sched_unit *unit) static void csched2_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct csched2_unit * const svc =3D csched2_unit(unit); - unsigned int cpu =3D vc->processor; + unsigned int cpu =3D sched_unit_cpu(unit); s_time_t now; =20 ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 - ASSERT(!is_idle_vcpu(vc)); + ASSERT(!is_idle_unit(unit)); =20 if ( unlikely(curr_on_cpu(cpu) =3D=3D unit) ) { @@ -2113,18 +2110,18 @@ csched2_unit_wake(const struct scheduler *ops, stru= ct sched_unit *unit) goto out; } =20 - if ( unlikely(vcpu_on_runq(svc)) ) + if ( unlikely(unit_on_runq(svc)) ) { SCHED_STAT_CRANK(unit_wake_onrunq); goto out; } =20 - if ( likely(vcpu_runnable(vc)) ) + if ( likely(unit_runnable(unit)) ) SCHED_STAT_CRANK(unit_wake_runnable); else SCHED_STAT_CRANK(unit_wake_not_runnable); =20 - /* If the context hasn't been saved for this vcpu yet, we can't put it= on + /* If the context hasn't been saved for this unit yet, we can't put it= on * another runqueue. Instead, we set a flag so that it will be put on= the runqueue * after the context has been saved. */ if ( unlikely(svc->flags & CSFLAG_scheduled) ) @@ -2135,15 +2132,15 @@ csched2_unit_wake(const struct scheduler *ops, stru= ct sched_unit *unit) =20 /* Add into the new runqueue if necessary */ if ( svc->rqd =3D=3D NULL ) - runq_assign(ops, vc); + runq_assign(ops, unit); else - ASSERT(c2rqd(ops, vc->processor) =3D=3D svc->rqd ); + ASSERT(c2rqd(ops, sched_unit_cpu(unit)) =3D=3D svc->rqd ); =20 now =3D NOW(); =20 update_load(ops, svc->rqd, svc, 1, now); - =20 - /* Put the VCPU on the runq */ + + /* Put the UNIT on the runq */ runq_insert(ops, svc); runq_tickle(ops, svc, now); =20 @@ -2156,49 +2153,48 @@ csched2_unit_yield(const struct scheduler *ops, str= uct sched_unit *unit) { struct csched2_unit * const svc =3D csched2_unit(unit); =20 - __set_bit(__CSFLAG_vcpu_yield, &svc->flags); + __set_bit(__CSFLAG_unit_yield, &svc->flags); } =20 static void csched2_context_saved(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct csched2_unit * const svc =3D csched2_unit(unit); spinlock_t *lock =3D unit_schedule_lock_irq(unit); s_time_t now =3D NOW(); LIST_HEAD(were_parked); =20 - BUG_ON( !is_idle_vcpu(vc) && svc->rqd !=3D c2rqd(ops, vc->processor)); - ASSERT(is_idle_vcpu(vc) || svc->rqd =3D=3D c2rqd(ops, vc->processor)); + BUG_ON( !is_idle_unit(unit) && svc->rqd !=3D c2rqd(ops, sched_unit_cpu= (unit))); + ASSERT(is_idle_unit(unit) || svc->rqd =3D=3D c2rqd(ops, sched_unit_cpu= (unit))); =20 - /* This vcpu is now eligible to be put on the runqueue again */ + /* This unit is now eligible to be put on the runqueue again */ __clear_bit(__CSFLAG_scheduled, &svc->flags); =20 if ( unlikely(has_cap(svc) && svc->budget > 0) ) - vcpu_return_budget(svc, &were_parked); + unit_return_budget(svc, &were_parked); =20 /* If someone wants it on the runqueue, put it there. */ /* * NB: We can get rid of CSFLAG_scheduled by checking for - * vc->is_running and vcpu_on_runq(svc) here. However, + * vc->is_running and unit_on_runq(svc) here. However, * since we're accessing the flags cacheline anyway, * it seems a bit pointless; especially as we have plenty of * bits free. */ if ( __test_and_clear_bit(__CSFLAG_delayed_runq_add, &svc->flags) - && likely(vcpu_runnable(vc)) ) + && likely(unit_runnable(unit)) ) { - ASSERT(!vcpu_on_runq(svc)); + ASSERT(!unit_on_runq(svc)); =20 runq_insert(ops, svc); runq_tickle(ops, svc, now); } - else if ( !is_idle_vcpu(vc) ) + else if ( !is_idle_unit(unit) ) update_load(ops, svc->rqd, svc, -1, now); =20 unit_schedule_unlock_irq(lock, unit); =20 - unpark_parked_vcpus(ops, &were_parked); + unpark_parked_units(ops, &were_parked); } =20 #define MAX_LOAD (STIME_MAX) @@ -2206,9 +2202,8 @@ static struct sched_resource * csched2_res_pick(const struct scheduler *ops, struct sched_unit *unit) { struct csched2_private *prv =3D csched2_priv(ops); - struct vcpu *vc =3D unit->vcpu_list; int i, min_rqi =3D -1, min_s_rqi =3D -1; - unsigned int new_cpu, cpu =3D vc->processor; + unsigned int new_cpu, cpu =3D sched_unit_cpu(unit); struct csched2_unit *svc =3D csched2_unit(unit); s_time_t min_avgload =3D MAX_LOAD, min_s_avgload =3D MAX_LOAD; bool has_soft; @@ -2246,7 +2241,7 @@ csched2_res_pick(const struct scheduler *ops, struct = sched_unit *unit) } =20 cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity, - cpupool_domain_cpumask(vc->domain)); + cpupool_domain_cpumask(unit->domain)); =20 /* * First check to see if we're here because someone else suggested a p= lace @@ -2357,7 +2352,7 @@ csched2_res_pick(const struct scheduler *ops, struct = sched_unit *unit) * We have soft affinity, and we have a candidate runq, so go for = it. * * Note that, to obtain the soft-affinity mask, we "just" put what= we - * have in cpumask_scratch in && with vc->cpu_soft_affinity. This = is + * have in cpumask_scratch in && with unit->cpu_soft_affinity. Thi= s is * ok because: * - we know that unit->cpu_hard_affinity and ->cpu_soft_affinity = have * a non-empty intersection (because has_soft is true); @@ -2380,7 +2375,7 @@ csched2_res_pick(const struct scheduler *ops, struct = sched_unit *unit) * any suitable runq. But we did find one when considering hard * affinity, so go for it. * - * cpumask_scratch already has vc->cpu_hard_affinity & + * cpumask_scratch already has unit->cpu_hard_affinity & * cpupool_domain_cpumask() in it, so it's enough that we filter * with the cpus of the runq. */ @@ -2411,11 +2406,11 @@ csched2_res_pick(const struct scheduler *ops, struc= t sched_unit *unit) { struct { uint64_t b_avgload; - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; unsigned rq_id:16, new_cpu:16; } d; - d.dom =3D vc->domain->domain_id; - d.vcpu =3D vc->vcpu_id; + d.dom =3D unit->domain->domain_id; + d.unit =3D unit->unit_id; d.rq_id =3D min_rqi; d.b_avgload =3D min_avgload; d.new_cpu =3D new_cpu; @@ -2434,10 +2429,10 @@ typedef struct { struct csched2_unit * best_push_svc, *best_pull_svc; /* NB: Read by consider() */ struct csched2_runqueue_data *lrqd; - struct csched2_runqueue_data *orqd; =20 + struct csched2_runqueue_data *orqd; } balance_state_t; =20 -static void consider(balance_state_t *st,=20 +static void consider(balance_state_t *st, struct csched2_unit *push_svc, struct csched2_unit *pull_svc) { @@ -2476,17 +2471,17 @@ static void migrate(const struct scheduler *ops, struct csched2_runqueue_data *trqd, s_time_t now) { - int cpu =3D svc->vcpu->processor; - struct sched_unit *unit =3D svc->vcpu->sched_unit; + struct sched_unit *unit =3D svc->unit; + int cpu =3D sched_unit_cpu(unit); =20 if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; unsigned rqi:16, trqi:16; } d; - d.dom =3D svc->vcpu->domain->domain_id; - d.vcpu =3D svc->vcpu->vcpu_id; + d.dom =3D unit->domain->domain_id; + d.unit =3D unit->unit_id; d.rqi =3D svc->rqd->id; d.trqi =3D trqd->id; __trace_var(TRC_CSCHED2_MIGRATE, 1, @@ -2498,7 +2493,7 @@ static void migrate(const struct scheduler *ops, { /* It's running; mark it to migrate. */ svc->migrate_rqd =3D trqd; - __set_bit(_VPF_migrating, &svc->vcpu->pause_flags); + sched_set_pause_flags(unit, _VPF_migrating); __set_bit(__CSFLAG_runq_migrate_request, &svc->flags); SCHED_STAT_CRANK(migrate_requested); tickle_cpu(cpu, svc->rqd); @@ -2507,7 +2502,7 @@ static void migrate(const struct scheduler *ops, { int on_runq =3D 0; /* It's not running; just move it */ - if ( vcpu_on_runq(svc) ) + if ( unit_on_runq(svc) ) { runq_remove(svc); update_load(ops, svc->rqd, NULL, -1, now); @@ -2516,14 +2511,14 @@ static void migrate(const struct scheduler *ops, _runq_deassign(svc); =20 cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity, - cpupool_domain_cpumask(svc->vcpu->domain)); + cpupool_domain_cpumask(unit->domain)); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), &trqd->active); - svc->vcpu->processor =3D cpumask_cycle(trqd->pick_bias, - cpumask_scratch_cpu(cpu)); - svc->vcpu->sched_unit->res =3D get_sched_res(svc->vcpu->processor); - trqd->pick_bias =3D svc->vcpu->processor; - ASSERT(svc->vcpu->processor < nr_cpu_ids); + sched_set_res(unit, + get_sched_res(cpumask_cycle(trqd->pick_bias, + cpumask_scratch_cpu(cpu)= ))); + trqd->pick_bias =3D sched_unit_cpu(unit); + ASSERT(sched_unit_cpu(unit) < nr_cpu_ids); =20 _runq_assign(svc, trqd); if ( on_runq ) @@ -2543,14 +2538,14 @@ static void migrate(const struct scheduler *ops, * - svc is not already flagged to migrate, * - if svc is allowed to run on at least one of the pcpus of rqd. */ -static bool vcpu_is_migrateable(struct csched2_unit *svc, +static bool unit_is_migrateable(struct csched2_unit *svc, struct csched2_runqueue_data *rqd) { - struct vcpu *v =3D svc->vcpu; - int cpu =3D svc->vcpu->processor; + struct sched_unit *unit =3D svc->unit; + int cpu =3D sched_unit_cpu(unit); =20 - cpumask_and(cpumask_scratch_cpu(cpu), v->sched_unit->cpu_hard_affinity, - cpupool_domain_cpumask(v->domain)); + cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity, + cpupool_domain_cpumask(unit->domain)); =20 return !(svc->flags & CSFLAG_runq_migrate_request) && cpumask_intersects(cpumask_scratch_cpu(cpu), &rqd->active); @@ -2587,7 +2582,7 @@ retry: for_each_cpu(i, &prv->active_queues) { s_time_t delta; - =20 + st.orqd =3D prv->rqd + i; =20 if ( st.orqd =3D=3D st.lrqd @@ -2595,7 +2590,7 @@ retry: continue; =20 update_runq_load(ops, st.orqd, 0, now); - =20 + delta =3D st.lrqd->b_avgload - st.orqd->b_avgload; if ( delta < 0 ) delta =3D -delta; @@ -2618,7 +2613,7 @@ retry: s_time_t load_max; int cpus_max; =20 - =20 + load_max =3D st.lrqd->b_avgload; if ( st.orqd->b_avgload > load_max ) load_max =3D st.orqd->b_avgload; @@ -2657,7 +2652,7 @@ retry: opt_overload_balance_tolerance)= ) ) goto out; } - =20 + /* Try to grab the other runqueue lock; if it's been taken in the * meantime, try the process over again. This can't deadlock * because if it doesn't get any other rqd locks, it will simply @@ -2697,17 +2692,17 @@ retry: =20 update_svc_load(ops, push_svc, 0, now); =20 - if ( !vcpu_is_migrateable(push_svc, st.orqd) ) + if ( !unit_is_migrateable(push_svc, st.orqd) ) continue; =20 list_for_each( pull_iter, &st.orqd->svc ) { struct csched2_unit * pull_svc =3D list_entry(pull_iter, struc= t csched2_unit, rqd_elem); - =20 + if ( !inner_load_updated ) update_svc_load(ops, pull_svc, 0, now); - =20 - if ( !vcpu_is_migrateable(pull_svc, st.lrqd) ) + + if ( !unit_is_migrateable(pull_svc, st.lrqd) ) continue; =20 consider(&st, push_svc, pull_svc); @@ -2722,8 +2717,8 @@ retry: list_for_each( pull_iter, &st.orqd->svc ) { struct csched2_unit * pull_svc =3D list_entry(pull_iter, struct cs= ched2_unit, rqd_elem); - =20 - if ( !vcpu_is_migrateable(pull_svc, st.lrqd) ) + + if ( !unit_is_migrateable(pull_svc, st.lrqd) ) continue; =20 /* Consider pull only */ @@ -2746,8 +2741,7 @@ static void csched2_unit_migrate( const struct scheduler *ops, struct sched_unit *unit, unsigned int new= _cpu) { - struct vcpu *vc =3D unit->vcpu_list; - struct domain *d =3D vc->domain; + struct domain *d =3D unit->domain; struct csched2_unit * const svc =3D csched2_unit(unit); struct csched2_runqueue_data *trqd; s_time_t now =3D NOW(); @@ -2759,25 +2753,24 @@ csched2_unit_migrate( * cpupool. * * And since there indeed is the chance that it is not part of it, all - * we must do is remove _and_ unassign the vCPU from any runqueue, as + * we must do is remove _and_ unassign the unit from any runqueue, as * well as updating v->processor with the target, so that the suspend * process can continue. * * It will then be during resume that a new, meaningful, value for * v->processor will be chosen, and during actual domain unpause that - * the vCPU will be assigned to and added to the proper runqueue. + * the unit will be assigned to and added to the proper runqueue. */ if ( unlikely(!cpumask_test_cpu(new_cpu, cpupool_domain_cpumask(d))) ) { ASSERT(system_state =3D=3D SYS_STATE_suspend); - if ( vcpu_on_runq(svc) ) + if ( unit_on_runq(svc) ) { runq_remove(svc); update_load(ops, svc->rqd, NULL, -1, now); } _runq_deassign(svc); - vc->processor =3D new_cpu; - unit->res =3D get_sched_res(new_cpu); + sched_set_res(unit, get_sched_res(new_cpu)); return; } =20 @@ -2791,17 +2784,14 @@ csched2_unit_migrate( * Do the actual movement toward new_cpu, and update vc->processor. * If we are changing runqueue, migrate() takes care of everything. * If we are not changing runqueue, we need to update vc->processor - * here. In fact, if, for instance, we are here because the vcpu's + * here. In fact, if, for instance, we are here because the unit's * hard affinity changed, we don't want to risk leaving vc->processor * pointing to a pcpu where we can't run any longer. */ if ( trqd !=3D svc->rqd ) migrate(ops, svc, trqd, now); else - { - vc->processor =3D new_cpu; - unit->res =3D get_sched_res(new_cpu); - } + sched_set_res(unit, get_sched_res(new_cpu)); } =20 static int @@ -2813,18 +2803,18 @@ csched2_dom_cntl( struct csched2_dom * const sdom =3D csched2_dom(d); struct csched2_private *prv =3D csched2_priv(ops); unsigned long flags; - struct vcpu *v; + struct sched_unit *unit; int rc =3D 0; =20 /* * Locking: * - we must take the private lock for accessing the weights of the - * vcpus of d, and/or the cap; + * units of d, and/or the cap; * - in the putinfo case, we also need the runqueue lock(s), for * updating the max waight of the runqueue(s). * If changing the cap, we also need the budget_lock, for updating * the value of the domain budget pool (and the runqueue lock, - * for adjusting the parameters and rescheduling any vCPU that is + * for adjusting the parameters and rescheduling any unit that is * running at the time of the change). */ switch ( op->cmd ) @@ -2846,18 +2836,18 @@ csched2_dom_cntl( =20 sdom->weight =3D op->u.credit2.weight; =20 - /* Update weights for vcpus, and max_weight for runqueues on w= hich they reside */ - for_each_vcpu ( d, v ) + /* Update weights for units, and max_weight for runqueues on w= hich they reside */ + for_each_sched_unit ( d, unit ) { - struct csched2_unit *svc =3D csched2_unit(v->sched_unit); - spinlock_t *lock =3D unit_schedule_lock(svc->vcpu->sched_u= nit); + struct csched2_unit *svc =3D csched2_unit(unit); + spinlock_t *lock =3D unit_schedule_lock(unit); =20 - ASSERT(svc->rqd =3D=3D c2rqd(ops, svc->vcpu->processor)); + ASSERT(svc->rqd =3D=3D c2rqd(ops, sched_unit_cpu(unit))); =20 svc->weight =3D sdom->weight; update_max_weight(svc->rqd, svc->weight, old_weight); =20 - unit_schedule_unlock(lock, svc->vcpu->sched_unit); + unit_schedule_unlock(lock, unit); } } /* Cap */ @@ -2866,8 +2856,8 @@ csched2_dom_cntl( struct csched2_unit *svc; spinlock_t *lock; =20 - /* Cap is only valid if it's below 100 * nr_of_vCPUS */ - if ( op->u.credit2.cap > 100 * sdom->nr_vcpus ) + /* Cap is only valid if it's below 100 * nr_of_units */ + if ( op->u.credit2.cap > 100 * sdom->nr_units ) { rc =3D -EINVAL; write_unlock_irqrestore(&prv->lock, flags); @@ -2880,23 +2870,23 @@ csched2_dom_cntl( spin_unlock(&sdom->budget_lock); =20 /* - * When trying to get some budget and run, each vCPU will grab - * from the pool 1/N (with N =3D nr of vCPUs of the domain) of - * the total budget. Roughly speaking, this means each vCPU wi= ll + * When trying to get some budget and run, each unit will grab + * from the pool 1/N (with N =3D nr of units of the domain) of + * the total budget. Roughly speaking, this means each unit wi= ll * have at least one chance to run during every period. */ - for_each_vcpu ( d, v ) + for_each_sched_unit ( d, unit ) { - svc =3D csched2_unit(v->sched_unit); - lock =3D unit_schedule_lock(svc->vcpu->sched_unit); + svc =3D csched2_unit(unit); + lock =3D unit_schedule_lock(unit); /* * Too small quotas would in theory cause a lot of overhea= d, * which then won't happen because, in csched2_runtime(), * CSCHED2_MIN_TIMER is what would be used anyway. */ - svc->budget_quota =3D max(sdom->tot_budget / sdom->nr_vcpu= s, + svc->budget_quota =3D max(sdom->tot_budget / sdom->nr_unit= s, CSCHED2_MIN_TIMER); - unit_schedule_unlock(lock, svc->vcpu->sched_unit); + unit_schedule_unlock(lock, unit); } =20 if ( sdom->cap =3D=3D 0 ) @@ -2906,7 +2896,7 @@ csched2_dom_cntl( * and queue its first replenishment event. * * Since cap is currently disabled for this domain, we - * know no vCPU is messing with the domain's budget, and + * know no unit is messing with the domain's budget, and * the replenishment timer is still off. * For these reasons, it is safe to do the following witho= ut * taking the budget_lock. @@ -2916,42 +2906,42 @@ csched2_dom_cntl( set_timer(&sdom->repl_timer, sdom->next_repl); =20 /* - * Now, let's enable budget accounting for all the vCPUs. + * Now, let's enable budget accounting for all the units. * For making sure that they will start to honour the doma= in's * cap, we set their budget to 0. * This way, as soon as they will try to run, they will ha= ve * to get some budget. * - * For the vCPUs that are already running, we trigger the + * For the units that are already running, we trigger the * scheduler on their pCPU. When, as a consequence of this, * csched2_schedule() will run, it will figure out there is - * no budget, and the vCPU will try to get some (and be pa= rked, + * no budget, and the unit will try to get some (and be pa= rked, * if there's none, and we'll switch to someone else). */ - for_each_vcpu ( d, v ) + for_each_sched_unit ( d, unit ) { - svc =3D csched2_unit(v->sched_unit); - lock =3D unit_schedule_lock(svc->vcpu->sched_unit); - if ( v->sched_unit->is_running ) + svc =3D csched2_unit(unit); + lock =3D unit_schedule_lock(unit); + if ( unit->is_running ) { - unsigned int cpu =3D v->processor; + unsigned int cpu =3D sched_unit_cpu(unit); struct csched2_runqueue_data *rqd =3D c2rqd(ops, c= pu); =20 - ASSERT(curr_on_cpu(cpu)->vcpu_list =3D=3D v); + ASSERT(curr_on_cpu(cpu) =3D=3D unit); =20 /* - * We are triggering a reschedule on the vCPU's + * We are triggering a reschedule on the unit's * pCPU. That will run burn_credits() and, since - * the vCPU is capped now, it would charge all the + * the unit is capped now, it would charge all the * execution time of this last round as budget as - * well. That will make the vCPU budget go negativ= e, + * well. That will make the unit budget go negativ= e, * potentially by a large amount, and it's unfair. * * To avoid that, call burn_credit() here, to do t= he * accounting of this current running instance now, * with budgetting still disabled. This does not * prevent some small amount of budget being charg= ed - * to the vCPU (i.e., the amount of time it runs f= rom + * to the unit (i.e., the amount of time it runs f= rom * now, to when scheduling happens). The budget wi= ll * also go below 0, but a lot less than how it wou= ld * if we don't do this. @@ -2962,7 +2952,7 @@ csched2_dom_cntl( cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); } svc->budget =3D 0; - unit_schedule_unlock(lock, svc->vcpu->sched_unit); + unit_schedule_unlock(lock, unit); } } =20 @@ -2974,30 +2964,30 @@ csched2_dom_cntl( =20 stop_timer(&sdom->repl_timer); =20 - /* Disable budget accounting for all the vCPUs. */ - for_each_vcpu ( d, v ) + /* Disable budget accounting for all the units. */ + for_each_sched_unit ( d, unit ) { - struct csched2_unit *svc =3D csched2_unit(v->sched_unit); - spinlock_t *lock =3D unit_schedule_lock(svc->vcpu->sched_u= nit); + struct csched2_unit *svc =3D csched2_unit(unit); + spinlock_t *lock =3D unit_schedule_lock(unit); =20 svc->budget =3D STIME_MAX; svc->budget_quota =3D 0; =20 - unit_schedule_unlock(lock, svc->vcpu->sched_unit); + unit_schedule_unlock(lock, unit); } sdom->cap =3D 0; /* * We are disabling the cap for this domain, which may have - * vCPUs waiting for a replenishment, so we unpark them all. + * units waiting for a replenishment, so we unpark them all. * Note that, since we have already disabled budget accounting - * for all the vCPUs of the domain, no currently running vCPU - * will be added to the parked vCPUs list any longer. + * for all the units of the domain, no currently running unit + * will be added to the parked units list any longer. */ spin_lock(&sdom->budget_lock); - list_splice_init(&sdom->parked_vcpus, &parked); + list_splice_init(&sdom->parked_units, &parked); spin_unlock(&sdom->budget_lock); =20 - unpark_parked_vcpus(ops, &parked); + unpark_parked_units(ops, &parked); } write_unlock_irqrestore(&prv->lock, flags); break; @@ -3074,12 +3064,12 @@ csched2_alloc_domdata(const struct scheduler *ops, = struct domain *dom) sdom->dom =3D dom; sdom->weight =3D CSCHED2_DEFAULT_WEIGHT; sdom->cap =3D 0U; - sdom->nr_vcpus =3D 0; + sdom->nr_units =3D 0; =20 init_timer(&sdom->repl_timer, replenish_domain_budget, sdom, cpumask_any(cpupool_domain_cpumask(dom))); spin_lock_init(&sdom->budget_lock); - INIT_LIST_HEAD(&sdom->parked_vcpus); + INIT_LIST_HEAD(&sdom->parked_units); =20 write_lock_irqsave(&prv->lock, flags); =20 @@ -3113,34 +3103,32 @@ csched2_free_domdata(const struct scheduler *ops, v= oid *data) static void csched2_unit_insert(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct csched2_unit *svc =3D unit->priv; struct csched2_dom * const sdom =3D svc->sdom; spinlock_t *lock; =20 - ASSERT(!is_idle_vcpu(vc)); + ASSERT(!is_idle_unit(unit)); ASSERT(list_empty(&svc->runq_elem)); =20 /* csched2_res_pick() expects the pcpu lock to be held */ lock =3D unit_schedule_lock_irq(unit); =20 - unit->res =3D csched2_res_pick(ops, unit); - vc->processor =3D unit->res->processor; + sched_set_res(unit, csched2_res_pick(ops, unit)); =20 spin_unlock_irq(lock); =20 lock =3D unit_schedule_lock_irq(unit); =20 - /* Add vcpu to runqueue of initial processor */ - runq_assign(ops, vc); + /* Add unit to runqueue of initial processor */ + runq_assign(ops, unit); =20 unit_schedule_unlock_irq(lock, unit); =20 - sdom->nr_vcpus++; + sdom->nr_units++; =20 SCHED_STAT_CRANK(unit_insert); =20 - CSCHED2_VCPU_CHECK(vc); + CSCHED2_UNIT_CHECK(unit); } =20 static void @@ -3154,11 +3142,10 @@ csched2_free_vdata(const struct scheduler *ops, voi= d *priv) static void csched2_unit_remove(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; struct csched2_unit * const svc =3D csched2_unit(unit); spinlock_t *lock; =20 - ASSERT(!is_idle_vcpu(vc)); + ASSERT(!is_idle_unit(unit)); ASSERT(list_empty(&svc->runq_elem)); =20 SCHED_STAT_CRANK(unit_remove); @@ -3166,14 +3153,14 @@ csched2_unit_remove(const struct scheduler *ops, st= ruct sched_unit *unit) /* Remove from runqueue */ lock =3D unit_schedule_lock_irq(unit); =20 - runq_deassign(ops, vc); + runq_deassign(ops, unit); =20 unit_schedule_unlock_irq(lock, unit); =20 - svc->sdom->nr_vcpus--; + svc->sdom->nr_units--; } =20 -/* How long should we let this vcpu run for? */ +/* How long should we let this unit run for? */ static s_time_t csched2_runtime(const struct scheduler *ops, int cpu, struct csched2_unit *snext, s_time_t now) @@ -3188,7 +3175,7 @@ csched2_runtime(const struct scheduler *ops, int cpu, * If we're idle, just stay so. Others (or external events) * will poke us when necessary. */ - if ( is_idle_vcpu(snext->vcpu) ) + if ( is_idle_unit(snext->unit) ) return -1; =20 /* General algorithm: @@ -3205,8 +3192,8 @@ csched2_runtime(const struct scheduler *ops, int cpu, if ( prv->ratelimit_us ) { s_time_t ratelimit_min =3D MICROSECS(prv->ratelimit_us); - if ( snext->vcpu->sched_unit->is_running ) - ratelimit_min =3D snext->vcpu->sched_unit->state_entry_time + + if ( snext->unit->is_running ) + ratelimit_min =3D snext->unit->state_entry_time + MICROSECS(prv->ratelimit_us) - now; if ( ratelimit_min > min_time ) min_time =3D ratelimit_min; @@ -3223,7 +3210,7 @@ csched2_runtime(const struct scheduler *ops, int cpu, { struct csched2_unit *swait =3D runq_elem(runq->next); =20 - if ( ! is_idle_vcpu(swait->vcpu) + if ( ! is_idle_unit(swait->unit) && swait->credit > 0 ) { rt_credit =3D snext->credit - swait->credit; @@ -3237,7 +3224,7 @@ csched2_runtime(const struct scheduler *ops, int cpu, * * FIXME: See if we can eliminate this conversion if we know time * will be outside (MIN,MAX). Probably requires pre-calculating - * credit values of MIN,MAX per vcpu, since each vcpu burns credit + * credit values of MIN,MAX per unit, since each unit burns credit * at a different rate. */ if ( rt_credit > 0 ) @@ -3285,36 +3272,35 @@ runq_candidate(struct csched2_runqueue_data *rqd, =20 *skipped =3D 0; =20 - if ( unlikely(is_idle_vcpu(scurr->vcpu)) ) + if ( unlikely(is_idle_unit(scurr->unit)) ) { snext =3D scurr; goto check_runq; } =20 - yield =3D __test_and_clear_bit(__CSFLAG_vcpu_yield, &scurr->flags); + yield =3D __test_and_clear_bit(__CSFLAG_unit_yield, &scurr->flags); =20 /* - * Return the current vcpu if it has executed for less than ratelimit. - * Adjuststment for the selected vcpu's credit and decision + * Return the current unit if it has executed for less than ratelimit. + * Adjuststment for the selected unit's credit and decision * for how long it will run will be taken in csched2_runtime. * * Note that, if scurr is yielding, we don't let rate limiting kick in. * In fact, it may be the case that scurr is about to spin, and there's * no point forcing it to do so until rate limiting expires. */ - if ( !yield && prv->ratelimit_us && vcpu_runnable(scurr->vcpu) && - (now - scurr->vcpu->sched_unit->state_entry_time) < - MICROSECS(prv->ratelimit_us) ) + if ( !yield && prv->ratelimit_us && unit_runnable(scurr->unit) && + (now - scurr->unit->state_entry_time) < MICROSECS(prv->ratelimit_= us) ) { if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; unsigned runtime; } d; - d.dom =3D scurr->vcpu->domain->domain_id; - d.vcpu =3D scurr->vcpu->vcpu_id; - d.runtime =3D now - scurr->vcpu->sched_unit->state_entry_time; + d.dom =3D scurr->unit->domain->domain_id; + d.unit =3D scurr->unit->unit_id; + d.runtime =3D now - scurr->unit->state_entry_time; __trace_var(TRC_CSCHED2_RATELIMIT, 1, sizeof(d), (unsigned char *)&d); @@ -3323,13 +3309,13 @@ runq_candidate(struct csched2_runqueue_data *rqd, } =20 /* If scurr has a soft-affinity, let's check whether cpu is part of it= */ - if ( has_soft_affinity(scurr->vcpu->sched_unit) ) + if ( has_soft_affinity(scurr->unit) ) { - affinity_balance_cpumask(scurr->vcpu->sched_unit, BALANCE_SOFT_AFF= INITY, + affinity_balance_cpumask(scurr->unit, BALANCE_SOFT_AFFINITY, cpumask_scratch); if ( unlikely(!cpumask_test_cpu(cpu, cpumask_scratch)) ) { - cpumask_t *online =3D cpupool_domain_cpumask(scurr->vcpu->doma= in); + cpumask_t *online =3D cpupool_domain_cpumask(scurr->unit->doma= in); =20 /* Ok, is any of the pcpus in scurr soft-affinity idle? */ cpumask_and(cpumask_scratch, cpumask_scratch, &rqd->idle); @@ -3357,10 +3343,10 @@ runq_candidate(struct csched2_runqueue_data *rqd, * * Of course, we also default to idle also if scurr is not runnable. */ - if ( vcpu_runnable(scurr->vcpu) && !soft_aff_preempt ) + if ( unit_runnable(scurr->unit) && !soft_aff_preempt ) snext =3D scurr; else - snext =3D csched2_unit(idle_vcpu[cpu]->sched_unit); + snext =3D csched2_unit(sched_idle_unit(cpu)); =20 check_runq: list_for_each_safe( iter, temp, &rqd->runq ) @@ -3370,24 +3356,24 @@ runq_candidate(struct csched2_runqueue_data *rqd, if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; } d; - d.dom =3D svc->vcpu->domain->domain_id; - d.vcpu =3D svc->vcpu->vcpu_id; + d.dom =3D svc->unit->domain->domain_id; + d.unit =3D svc->unit->unit_id; __trace_var(TRC_CSCHED2_RUNQ_CAND_CHECK, 1, sizeof(d), (unsigned char *)&d); } =20 - /* Only consider vcpus that are allowed to run on this processor. = */ - if ( !cpumask_test_cpu(cpu, svc->vcpu->sched_unit->cpu_hard_affini= ty) ) + /* Only consider units that are allowed to run on this processor. = */ + if ( !cpumask_test_cpu(cpu, svc->unit->cpu_hard_affinity) ) { (*skipped)++; continue; } =20 /* - * If a vcpu is meant to be picked up by another processor, and su= ch + * If an unit is meant to be picked up by another processor, and s= uch * processor has not scheduled yet, leave it in the runqueue for h= im. */ if ( svc->tickled_cpu !=3D -1 && svc->tickled_cpu !=3D cpu && @@ -3402,7 +3388,7 @@ runq_candidate(struct csched2_runqueue_data *rqd, * If this is on a different processor, don't pull it unless * its credit is at least CSCHED2_MIGRATE_RESIST higher. */ - if ( svc->vcpu->processor !=3D cpu + if ( sched_unit_cpu(svc->unit) !=3D cpu && snext->credit + CSCHED2_MIGRATE_RESIST > svc->credit ) { (*skipped)++; @@ -3417,7 +3403,7 @@ runq_candidate(struct csched2_runqueue_data *rqd, * some budget, then choose it. */ if ( (yield || svc->credit > snext->credit) && - (!has_cap(svc) || vcpu_grab_budget(svc)) ) + (!has_cap(svc) || unit_grab_budget(svc)) ) snext =3D svc; =20 /* In any case, if we got this far, break. */ @@ -3427,12 +3413,12 @@ runq_candidate(struct csched2_runqueue_data *rqd, if ( unlikely(tb_init_done) ) { struct { - unsigned vcpu:16, dom:16; + unsigned unit:16, dom:16; unsigned tickled_cpu, skipped; int credit; } d; - d.dom =3D snext->vcpu->domain->domain_id; - d.vcpu =3D snext->vcpu->vcpu_id; + d.dom =3D snext->unit->domain->domain_id; + d.unit =3D snext->unit->unit_id; d.credit =3D snext->credit; d.tickled_cpu =3D snext->tickled_cpu; d.skipped =3D *skipped; @@ -3464,14 +3450,15 @@ csched2_schedule( { const int cpu =3D smp_processor_id(); struct csched2_runqueue_data *rqd; - struct csched2_unit * const scurr =3D csched2_unit(current->sched_unit= ); + struct sched_unit *currunit =3D current->sched_unit; + struct csched2_unit * const scurr =3D csched2_unit(currunit); struct csched2_unit *snext =3D NULL; - unsigned int skipped_vcpus =3D 0; + unsigned int skipped_units =3D 0; struct task_slice ret; bool tickled; =20 SCHED_STAT_CRANK(schedule); - CSCHED2_VCPU_CHECK(current); + CSCHED2_UNIT_CHECK(currunit); =20 BUG_ON(!cpumask_test_cpu(cpu, &csched2_priv(ops)->initialized)); =20 @@ -3480,7 +3467,7 @@ csched2_schedule( =20 ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); =20 - BUG_ON(!is_idle_vcpu(scurr->vcpu) && scurr->rqd !=3D rqd); + BUG_ON(!is_idle_unit(currunit) && scurr->rqd !=3D rqd); =20 /* Clear "tickled" bit now that we've been scheduled */ tickled =3D cpumask_test_cpu(cpu, &rqd->tickled); @@ -3500,7 +3487,7 @@ csched2_schedule( d.cpu =3D cpu; d.rq_id =3D c2r(cpu); d.tasklet =3D tasklet_work_scheduled; - d.idle =3D is_idle_vcpu(current); + d.idle =3D is_idle_unit(currunit); d.smt_idle =3D cpumask_test_cpu(cpu, &rqd->smt_idle); d.tickled =3D tickled; __trace_var(TRC_CSCHED2_SCHEDULE, 1, @@ -3514,55 +3501,55 @@ csched2_schedule( /* * Below 0, means that we are capped and we have overrun our budget. * Let's try to get some more but, if we fail (e.g., because of the - * other running vcpus), we will be parked. + * other running units), we will be parked. */ if ( unlikely(scurr->budget <=3D 0) ) - vcpu_grab_budget(scurr); + unit_grab_budget(scurr); =20 /* - * Select next runnable local VCPU (ie top of local runq). + * Select next runnable local UNIT (ie top of local runq). * - * If the current vcpu is runnable, and has higher credit than + * If the current unit is runnable, and has higher credit than * the next guy on the queue (or there is noone else), we want to * run him again. * - * If there's tasklet work to do, we want to chose the idle vcpu + * If there's tasklet work to do, we want to chose the idle unit * for this processor, and mark the current for delayed runqueue * add. * - * If the current vcpu is runnable, and there's another runnable + * If the current unit is runnable, and there's another runnable * candidate, we want to mark current for delayed runqueue add, * and remove the next guy from the queue. * - * If the current vcpu is not runnable, we want to chose the idle - * vcpu for this processor. + * If the current unit is not runnable, we want to chose the idle + * unit for this processor. */ if ( tasklet_work_scheduled ) { - __clear_bit(__CSFLAG_vcpu_yield, &scurr->flags); + __clear_bit(__CSFLAG_unit_yield, &scurr->flags); trace_var(TRC_CSCHED2_SCHED_TASKLET, 1, 0, NULL); - snext =3D csched2_unit(idle_vcpu[cpu]->sched_unit); + snext =3D csched2_unit(sched_idle_unit(cpu)); } else - snext =3D runq_candidate(rqd, scurr, cpu, now, &skipped_vcpus); + snext =3D runq_candidate(rqd, scurr, cpu, now, &skipped_units); =20 - /* If switching from a non-idle runnable vcpu, put it + /* If switching from a non-idle runnable unit, put it * back on the runqueue. */ if ( snext !=3D scurr - && !is_idle_vcpu(scurr->vcpu) - && vcpu_runnable(current) ) + && !is_idle_unit(currunit) + && unit_runnable(currunit) ) __set_bit(__CSFLAG_delayed_runq_add, &scurr->flags); =20 ret.migrated =3D 0; =20 /* Accounting for non-idle tasks */ - if ( !is_idle_vcpu(snext->vcpu) ) + if ( !is_idle_unit(snext->unit) ) { /* If switching, remove this from the runqueue and mark it schedul= ed */ if ( snext !=3D scurr ) { ASSERT(snext->rqd =3D=3D rqd); - ASSERT(!snext->vcpu->sched_unit->is_running); + ASSERT(!snext->unit->is_running); =20 runq_remove(snext); __set_bit(__CSFLAG_scheduled, &snext->flags); @@ -3577,19 +3564,19 @@ csched2_schedule( =20 /* * The reset condition is "has a scheduler epoch come to an end?". - * The way this is enforced is checking whether the vcpu at the top + * The way this is enforced is checking whether the unit at the top * of the runqueue has negative credits. This means the epochs have * variable length, as in one epoch expores when: - * 1) the vcpu at the top of the runqueue has executed for + * 1) the unit at the top of the runqueue has executed for * around 10 ms (with default parameters); - * 2) no other vcpu with higher credits wants to run. + * 2) no other unit with higher credits wants to run. * * Here, where we want to check for reset, we need to make sure the - * proper vcpu is being used. In fact, runqueue_candidate() may ha= ve - * not returned the first vcpu in the runqueue, for various reasons + * proper unit is being used. In fact, runqueue_candidate() may ha= ve + * not returned the first unit in the runqueue, for various reasons * (e.g., affinity). Only trigger a reset when it does. */ - if ( skipped_vcpus =3D=3D 0 && snext->credit <=3D CSCHED2_CREDIT_R= ESET ) + if ( skipped_units =3D=3D 0 && snext->credit <=3D CSCHED2_CREDIT_R= ESET ) { reset_credit(ops, cpu, now, snext); balance_load(ops, cpu, now); @@ -3599,11 +3586,10 @@ csched2_schedule( snext->tickled_cpu =3D -1; =20 /* Safe because lock for old processor is held */ - if ( snext->vcpu->processor !=3D cpu ) + if ( sched_unit_cpu(snext->unit) !=3D cpu ) { snext->credit +=3D CSCHED2_MIGRATE_COMPENSATION; - snext->vcpu->processor =3D cpu; - snext->vcpu->sched_unit->res =3D get_sched_res(cpu); + sched_set_res(snext->unit, get_sched_res(cpu)); SCHED_STAT_CRANK(migrated); ret.migrated =3D 1; } @@ -3637,20 +3623,20 @@ csched2_schedule( * Return task to run next... */ ret.time =3D csched2_runtime(ops, cpu, snext, now); - ret.task =3D snext->vcpu->sched_unit; + ret.task =3D snext->unit; =20 - CSCHED2_VCPU_CHECK(ret.task->vcpu_list); + CSCHED2_UNIT_CHECK(ret.task); return ret; } =20 static void -csched2_dump_vcpu(struct csched2_private *prv, struct csched2_unit *svc) +csched2_dump_unit(struct csched2_private *prv, struct csched2_unit *svc) { printk("[%i.%i] flags=3D%x cpu=3D%i", - svc->vcpu->domain->domain_id, - svc->vcpu->vcpu_id, + svc->unit->domain->domain_id, + svc->unit->unit_id, svc->flags, - svc->vcpu->processor); + sched_unit_cpu(svc->unit)); =20 printk(" credit=3D%" PRIi32" [w=3D%u]", svc->credit, svc->weight); =20 @@ -3675,12 +3661,12 @@ dump_pcpu(const struct scheduler *ops, int cpu) CPUMASK_PR(per_cpu(cpu_sibling_mask, cpu)), CPUMASK_PR(per_cpu(cpu_core_mask, cpu))); =20 - /* current VCPU (nothing to say if that's the idle vcpu) */ + /* current UNIT (nothing to say if that's the idle unit) */ svc =3D csched2_unit(curr_on_cpu(cpu)); - if ( svc && !is_idle_vcpu(svc->vcpu) ) + if ( svc && !is_idle_unit(svc->unit) ) { printk("\trun: "); - csched2_dump_vcpu(prv, svc); + csched2_dump_unit(prv, svc); } } =20 @@ -3737,7 +3723,7 @@ csched2_dump(const struct scheduler *ops) list_for_each( iter_sdom, &prv->sdom ) { struct csched2_dom *sdom; - struct vcpu *v; + struct sched_unit *unit; =20 sdom =3D list_entry(iter_sdom, struct csched2_dom, sdom_elem); =20 @@ -3745,19 +3731,19 @@ csched2_dump(const struct scheduler *ops) sdom->dom->domain_id, sdom->weight, sdom->cap, - sdom->nr_vcpus); + sdom->nr_units); =20 - for_each_vcpu( sdom->dom, v ) + for_each_sched_unit ( sdom->dom, unit ) { - struct csched2_unit * const svc =3D csched2_unit(v->sched_unit= ); + struct csched2_unit * const svc =3D csched2_unit(unit); spinlock_t *lock; =20 - lock =3D unit_schedule_lock(svc->vcpu->sched_unit); + lock =3D unit_schedule_lock(unit); =20 printk("\t%3d: ", ++loop); - csched2_dump_vcpu(prv, svc); + csched2_dump_unit(prv, svc); =20 - unit_schedule_unlock(lock, svc->vcpu->sched_unit); + unit_schedule_unlock(lock, unit); } } =20 @@ -3783,7 +3769,7 @@ csched2_dump(const struct scheduler *ops) if ( svc ) { printk("\t%3d: ", loop++); - csched2_dump_vcpu(prv, svc); + csched2_dump_unit(prv, svc); } } spin_unlock(&rqd->lock); @@ -3886,7 +3872,7 @@ csched2_switch_sched(struct scheduler *new_ops, unsig= ned int cpu, struct sched_resource *sd =3D get_sched_res(cpu); unsigned rqi; =20 - ASSERT(pdata && svc && is_idle_vcpu(svc->vcpu)); + ASSERT(pdata && svc && is_idle_unit(svc->unit)); =20 /* * We own one runqueue lock already (from schedule_cpu_switch()). This @@ -3899,7 +3885,7 @@ csched2_switch_sched(struct scheduler *new_ops, unsig= ned int cpu, ASSERT(!local_irq_is_enabled()); write_lock(&prv->lock); =20 - idle_vcpu[cpu]->sched_unit->priv =3D vdata; + sched_idle_unit(cpu)->priv =3D vdata; =20 rqi =3D init_pdata(prv, pdata, cpu); =20 @@ -3941,7 +3927,7 @@ csched2_deinit_pdata(const struct scheduler *ops, voi= d *pcpu, int cpu) */ ASSERT(spc && spc->runq_id !=3D -1); ASSERT(cpumask_test_cpu(cpu, &prv->initialized)); - =20 + /* Find the old runqueue and remove this cpu from it */ rqd =3D prv->rqd + spc->runq_id; =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362801; cv=none; d=zoho.com; s=zohoarc; b=KRcxKi1yQyLgPQoGLCXnHCOe/h6OygySw9xBSucLDQFSJvxc2yyZuBCurua80ZgCkh0eDvppWggUPtvrrJIDtVpkafdVasMqHb+Yo8u+TR1vkPKbgjqfUc4LOhT1WeBSl8KzGyJt8HUXK4v2D5FYV2qUCp2tyP5MBJNLyns8wo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362801; 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=ki9lyflG6FPbNpkQ1c4Mxynjz0wNQV/EHPI6MjyUs74=; b=N/GIskcR81EpyJNEXut4Qui5haRIXaMYv9fA1XkdXaadFITRbDfnU7/u8k+R7vN+GM8G4e+2l4+QHteNmtmv/gpfb8t9iE8Uef5ZTm/RI6e/vQezn32w5drGnNrTLh/HBXLRheL+DajByvIhxmttk9QTPkHZs4VBNi7h+pVHzHQ= 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 1565362801563126.77706993657523; Fri, 9 Aug 2019 08:00:01 -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 1hw6Lx-0006Tu-PU; Fri, 09 Aug 2019 14:58:49 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6Lv-0006RW-Kc for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:47 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2ee527a1-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:45 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id F3CB0B0B3; Fri, 9 Aug 2019 14:58:43 +0000 (UTC) X-Inumbo-ID: 2ee527a1-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:03 +0200 Message-Id: <20190809145833.1020-19-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 18/48] xen/sched: make arinc653 scheduler vcpu agnostic. 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 , George Dunlap , Josh Whitehead , Robert VanVossen , Dario Faggioli 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" Switch arinc653 scheduler completely from vcpu to sched_unit usage. Signed-off-by: Juergen Gross --- xen/common/sched_arinc653.c | 208 +++++++++++++++++++++-------------------= ---- 1 file changed, 101 insertions(+), 107 deletions(-) diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c index 4136c33e2d..213bc960ef 100644 --- a/xen/common/sched_arinc653.c +++ b/xen/common/sched_arinc653.c @@ -45,15 +45,15 @@ #define DEFAULT_TIMESLICE MILLISECS(10) =20 /** - * Retrieve the idle VCPU for a given physical CPU + * Retrieve the idle UNIT for a given physical CPU */ -#define IDLETASK(cpu) (idle_vcpu[cpu]) +#define IDLETASK(cpu) (sched_idle_unit(cpu)) =20 /** * Return a pointer to the ARINC 653-specific scheduler data information - * associated with the given VCPU (vc) + * associated with the given UNIT (unit) */ -#define AVCPU(vc) ((arinc653_vcpu_t *)(vc)->sched_unit->priv) +#define AUNIT(unit) ((arinc653_unit_t *)(unit)->priv) =20 /** * Return the global scheduler private data given the scheduler ops pointer @@ -65,20 +65,20 @@ *************************************************************************= */ =20 /** - * The arinc653_vcpu_t structure holds ARINC 653-scheduler-specific - * information for all non-idle VCPUs + * The arinc653_unit_t structure holds ARINC 653-scheduler-specific + * information for all non-idle UNITs */ -typedef struct arinc653_vcpu_s +typedef struct arinc653_unit_s { - /* vc points to Xen's struct vcpu so we can get to it from an - * arinc653_vcpu_t pointer. */ - struct vcpu * vc; - /* awake holds whether the VCPU has been woken with vcpu_wake() */ + /* unit points to Xen's struct sched_unit so we can get to it from an + * arinc653_unit_t pointer. */ + struct sched_unit * unit; + /* awake holds whether the UNIT has been woken with vcpu_wake() */ bool_t awake; - /* list holds the linked list information for the list this VCPU + /* list holds the linked list information for the list this UNIT * is stored in */ struct list_head list; -} arinc653_vcpu_t; +} arinc653_unit_t; =20 /** * The sched_entry_t structure holds a single entry of the @@ -89,14 +89,14 @@ typedef struct sched_entry_s /* dom_handle holds the handle ("UUID") for the domain that this * schedule entry refers to. */ xen_domain_handle_t dom_handle; - /* vcpu_id holds the VCPU number for the VCPU that this schedule + /* unit_id holds the UNIT number for the UNIT that this schedule * entry refers to. */ - int vcpu_id; - /* runtime holds the number of nanoseconds that the VCPU for this + int unit_id; + /* runtime holds the number of nanoseconds that the UNIT for this * schedule entry should be allowed to run per major frame. */ s_time_t runtime; - /* vc holds a pointer to the Xen VCPU structure */ - struct vcpu * vc; + /* unit holds a pointer to the Xen sched_unit structure */ + struct sched_unit * unit; } sched_entry_t; =20 /** @@ -110,9 +110,9 @@ typedef struct a653sched_priv_s /** * This array holds the active ARINC 653 schedule. * - * When the system tries to start a new VCPU, this schedule is scanned - * to look for a matching (handle, VCPU #) pair. If both the handle (U= UID) - * and VCPU number match, then the VCPU is allowed to run. Its run time + * When the system tries to start a new UNIT, this schedule is scanned + * to look for a matching (handle, UNIT #) pair. If both the handle (U= UID) + * and UNIT number match, then the UNIT is allowed to run. Its run time * (per major frame) is given in the third entry of the schedule. */ sched_entry_t schedule[ARINC653_MAX_DOMAINS_PER_SCHEDULE]; @@ -123,8 +123,8 @@ typedef struct a653sched_priv_s * * This is not necessarily the same as the number of domains in the * schedule. A domain could be listed multiple times within the schedu= le, - * or a domain with multiple VCPUs could have a different - * schedule entry for each VCPU. + * or a domain with multiple UNITs could have a different + * schedule entry for each UNIT. */ unsigned int num_schedule_entries; =20 @@ -139,9 +139,9 @@ typedef struct a653sched_priv_s s_time_t next_major_frame; =20 /** - * pointers to all Xen VCPU structures for iterating through + * pointers to all Xen UNIT structures for iterating through */ - struct list_head vcpu_list; + struct list_head unit_list; } a653sched_priv_t; =20 /************************************************************************** @@ -167,50 +167,50 @@ static int dom_handle_cmp(const xen_domain_handle_t h= 1, } =20 /** - * This function searches the vcpu list to find a VCPU that matches - * the domain handle and VCPU ID specified. + * This function searches the unit list to find a UNIT that matches + * the domain handle and UNIT ID specified. * * @param ops Pointer to this instance of the scheduler structure * @param handle Pointer to handler - * @param vcpu_id VCPU ID + * @param unit_id UNIT ID * * @return
    - *
  • Pointer to the matching VCPU if one is found + *
  • Pointer to the matching UNIT if one is found *
  • NULL otherwise *
*/ -static struct vcpu *find_vcpu( +static struct sched_unit *find_unit( const struct scheduler *ops, xen_domain_handle_t handle, - int vcpu_id) + int unit_id) { - arinc653_vcpu_t *avcpu; + arinc653_unit_t *aunit; =20 - /* loop through the vcpu_list looking for the specified VCPU */ - list_for_each_entry ( avcpu, &SCHED_PRIV(ops)->vcpu_list, list ) - if ( (dom_handle_cmp(avcpu->vc->domain->handle, handle) =3D=3D 0) - && (vcpu_id =3D=3D avcpu->vc->vcpu_id) ) - return avcpu->vc; + /* loop through the unit_list looking for the specified UNIT */ + list_for_each_entry ( aunit, &SCHED_PRIV(ops)->unit_list, list ) + if ( (dom_handle_cmp(aunit->unit->domain->handle, handle) =3D=3D 0) + && (unit_id =3D=3D aunit->unit->unit_id) ) + return aunit->unit; =20 return NULL; } =20 /** - * This function updates the pointer to the Xen VCPU structure for each en= try + * This function updates the pointer to the Xen UNIT structure for each en= try * in the ARINC 653 schedule. * * @param ops Pointer to this instance of the scheduler structure * @return */ -static void update_schedule_vcpus(const struct scheduler *ops) +static void update_schedule_units(const struct scheduler *ops) { unsigned int i, n_entries =3D SCHED_PRIV(ops)->num_schedule_entries; =20 for ( i =3D 0; i < n_entries; i++ ) - SCHED_PRIV(ops)->schedule[i].vc =3D - find_vcpu(ops, + SCHED_PRIV(ops)->schedule[i].unit =3D + find_unit(ops, SCHED_PRIV(ops)->schedule[i].dom_handle, - SCHED_PRIV(ops)->schedule[i].vcpu_id); + SCHED_PRIV(ops)->schedule[i].unit_id); } =20 /** @@ -268,12 +268,12 @@ arinc653_sched_set( memcpy(sched_priv->schedule[i].dom_handle, schedule->sched_entries[i].dom_handle, sizeof(sched_priv->schedule[i].dom_handle)); - sched_priv->schedule[i].vcpu_id =3D + sched_priv->schedule[i].unit_id =3D schedule->sched_entries[i].vcpu_id; sched_priv->schedule[i].runtime =3D schedule->sched_entries[i].runtime; } - update_schedule_vcpus(ops); + update_schedule_units(ops); =20 /* * The newly-installed schedule takes effect immediately. We do not ev= en @@ -319,7 +319,7 @@ arinc653_sched_get( memcpy(schedule->sched_entries[i].dom_handle, sched_priv->schedule[i].dom_handle, sizeof(sched_priv->schedule[i].dom_handle)); - schedule->sched_entries[i].vcpu_id =3D sched_priv->schedule[i].vcp= u_id; + schedule->sched_entries[i].vcpu_id =3D sched_priv->schedule[i].uni= t_id; schedule->sched_entries[i].runtime =3D sched_priv->schedule[i].run= time; } =20 @@ -355,7 +355,7 @@ a653sched_init(struct scheduler *ops) =20 prv->next_major_frame =3D 0; spin_lock_init(&prv->lock); - INIT_LIST_HEAD(&prv->vcpu_list); + INIT_LIST_HEAD(&prv->unit_list); =20 return 0; } @@ -373,7 +373,7 @@ a653sched_deinit(struct scheduler *ops) } =20 /** - * This function allocates scheduler-specific data for a VCPU + * This function allocates scheduler-specific data for a UNIT * * @param ops Pointer to this instance of the scheduler structure * @param unit Pointer to struct sched_unit @@ -385,35 +385,34 @@ a653sched_alloc_vdata(const struct scheduler *ops, st= ruct sched_unit *unit, void *dd) { a653sched_priv_t *sched_priv =3D SCHED_PRIV(ops); - struct vcpu *vc =3D unit->vcpu_list; - arinc653_vcpu_t *svc; + arinc653_unit_t *svc; unsigned int entry; unsigned long flags; =20 /* * Allocate memory for the ARINC 653-specific scheduler data informati= on - * associated with the given VCPU (vc). + * associated with the given UNIT (unit). */ - svc =3D xmalloc(arinc653_vcpu_t); + svc =3D xmalloc(arinc653_unit_t); if ( svc =3D=3D NULL ) return NULL; =20 spin_lock_irqsave(&sched_priv->lock, flags); =20 - /*=20 - * Add every one of dom0's vcpus to the schedule, as long as there are + /* + * Add every one of dom0's units to the schedule, as long as there are * slots available. */ - if ( vc->domain->domain_id =3D=3D 0 ) + if ( unit->domain->domain_id =3D=3D 0 ) { entry =3D sched_priv->num_schedule_entries; =20 if ( entry < ARINC653_MAX_DOMAINS_PER_SCHEDULE ) { sched_priv->schedule[entry].dom_handle[0] =3D '\0'; - sched_priv->schedule[entry].vcpu_id =3D vc->vcpu_id; + sched_priv->schedule[entry].unit_id =3D unit->unit_id; sched_priv->schedule[entry].runtime =3D DEFAULT_TIMESLICE; - sched_priv->schedule[entry].vc =3D vc; + sched_priv->schedule[entry].unit =3D unit; =20 sched_priv->major_frame +=3D DEFAULT_TIMESLICE; ++sched_priv->num_schedule_entries; @@ -421,16 +420,16 @@ a653sched_alloc_vdata(const struct scheduler *ops, st= ruct sched_unit *unit, } =20 /* - * Initialize our ARINC 653 scheduler-specific information for the VCP= U. - * The VCPU starts "asleep." When Xen is ready for the VCPU to run, it + * Initialize our ARINC 653 scheduler-specific information for the UNI= T. + * The UNIT starts "asleep." When Xen is ready for the UNIT to run, it * will call the vcpu_wake scheduler callback function and our schedul= er - * will mark the VCPU awake. + * will mark the UNIT awake. */ - svc->vc =3D vc; + svc->unit =3D unit; svc->awake =3D 0; - if ( !is_idle_vcpu(vc) ) - list_add(&svc->list, &SCHED_PRIV(ops)->vcpu_list); - update_schedule_vcpus(ops); + if ( !is_idle_unit(unit) ) + list_add(&svc->list, &SCHED_PRIV(ops)->unit_list); + update_schedule_units(ops); =20 spin_unlock_irqrestore(&sched_priv->lock, flags); =20 @@ -438,27 +437,27 @@ a653sched_alloc_vdata(const struct scheduler *ops, st= ruct sched_unit *unit, } =20 /** - * This function frees scheduler-specific VCPU data + * This function frees scheduler-specific UNIT data * * @param ops Pointer to this instance of the scheduler structure */ static void a653sched_free_vdata(const struct scheduler *ops, void *priv) { - arinc653_vcpu_t *av =3D priv; + arinc653_unit_t *av =3D priv; =20 if (av =3D=3D NULL) return; =20 - if ( !is_idle_vcpu(av->vc) ) + if ( !is_idle_unit(av->unit) ) list_del(&av->list); =20 xfree(av); - update_schedule_vcpus(ops); + update_schedule_units(ops); } =20 /** - * Xen scheduler callback function to sleep a VCPU + * Xen scheduler callback function to sleep a UNIT * * @param ops Pointer to this instance of the scheduler structure * @param unit Pointer to struct sched_unit @@ -466,21 +465,19 @@ a653sched_free_vdata(const struct scheduler *ops, voi= d *priv) static void a653sched_unit_sleep(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; - - if ( AVCPU(vc) !=3D NULL ) - AVCPU(vc)->awake =3D 0; + if ( AUNIT(unit) !=3D NULL ) + AUNIT(unit)->awake =3D 0; =20 /* - * If the VCPU being put to sleep is the same one that is currently + * If the UNIT being put to sleep is the same one that is currently * running, raise a softirq to invoke the scheduler to switch domains. */ - if ( get_sched_res(vc->processor)->curr =3D=3D unit ) - cpu_raise_softirq(vc->processor, SCHEDULE_SOFTIRQ); + if ( get_sched_res(sched_unit_cpu(unit))->curr =3D=3D unit ) + cpu_raise_softirq(sched_unit_cpu(unit), SCHEDULE_SOFTIRQ); } =20 /** - * Xen scheduler callback function to wake up a VCPU + * Xen scheduler callback function to wake up a UNIT * * @param ops Pointer to this instance of the scheduler structure * @param unit Pointer to struct sched_unit @@ -488,24 +485,22 @@ a653sched_unit_sleep(const struct scheduler *ops, str= uct sched_unit *unit) static void a653sched_unit_wake(const struct scheduler *ops, struct sched_unit *unit) { - struct vcpu *vc =3D unit->vcpu_list; + if ( AUNIT(unit) !=3D NULL ) + AUNIT(unit)->awake =3D 1; =20 - if ( AVCPU(vc) !=3D NULL ) - AVCPU(vc)->awake =3D 1; - - cpu_raise_softirq(vc->processor, SCHEDULE_SOFTIRQ); + cpu_raise_softirq(sched_unit_cpu(unit), SCHEDULE_SOFTIRQ); } =20 /** - * Xen scheduler callback function to select a VCPU to run. + * Xen scheduler callback function to select a UNIT to run. * This is the main scheduler routine. * * @param ops Pointer to this instance of the scheduler structure * @param now Current time * - * @return Address of the VCPU structure scheduled to be run next - * Amount of time to execute the returned VCPU - * Flag for whether the VCPU was migrated + * @return Address of the UNIT structure scheduled to be run next + * Amount of time to execute the returned UNIT + * Flag for whether the UNIT was migrated */ static struct task_slice a653sched_do_schedule( @@ -514,7 +509,7 @@ a653sched_do_schedule( bool_t tasklet_work_scheduled) { struct task_slice ret; /* hold the chosen domain = */ - struct vcpu * new_task =3D NULL; + struct sched_unit *new_task =3D NULL; static unsigned int sched_index =3D 0; static s_time_t next_switch_time; a653sched_priv_t *sched_priv =3D SCHED_PRIV(ops); @@ -559,14 +554,14 @@ a653sched_do_schedule( * sched_unit structure. */ new_task =3D (sched_index < sched_priv->num_schedule_entries) - ? sched_priv->schedule[sched_index].vc + ? sched_priv->schedule[sched_index].unit : IDLETASK(cpu); =20 /* Check to see if the new task can be run (awake & runnable). */ if ( !((new_task !=3D NULL) - && (AVCPU(new_task) !=3D NULL) - && AVCPU(new_task)->awake - && vcpu_runnable(new_task)) ) + && (AUNIT(new_task) !=3D NULL) + && AUNIT(new_task)->awake + && unit_runnable(new_task)) ) new_task =3D IDLETASK(cpu); BUG_ON(new_task =3D=3D NULL); =20 @@ -578,21 +573,21 @@ a653sched_do_schedule( =20 spin_unlock_irqrestore(&sched_priv->lock, flags); =20 - /* Tasklet work (which runs in idle VCPU context) overrides all else. = */ + /* Tasklet work (which runs in idle UNIT context) overrides all else. = */ if ( tasklet_work_scheduled ) new_task =3D IDLETASK(cpu); =20 /* Running this task would result in a migration */ - if ( !is_idle_vcpu(new_task) - && (new_task->processor !=3D cpu) ) + if ( !is_idle_unit(new_task) + && (sched_unit_cpu(new_task) !=3D cpu) ) new_task =3D IDLETASK(cpu); =20 /* * Return the amount of time the next domain has to run and the address - * of the selected task's VCPU structure. + * of the selected task's UNIT structure. */ ret.time =3D next_switch_time - now; - ret.task =3D new_task->sched_unit; + ret.task =3D new_task; ret.migrated =3D 0; =20 BUG_ON(ret.time <=3D 0); @@ -601,7 +596,7 @@ a653sched_do_schedule( } =20 /** - * Xen scheduler callback function to select a resource for the VCPU to ru= n on + * Xen scheduler callback function to select a resource for the UNIT to ru= n on * * @param ops Pointer to this instance of the scheduler structure * @param unit Pointer to struct sched_unit @@ -611,21 +606,20 @@ a653sched_do_schedule( static struct sched_resource * a653sched_pick_resource(const struct scheduler *ops, struct sched_unit *un= it) { - struct vcpu *vc =3D unit->vcpu_list; cpumask_t *online; unsigned int cpu; =20 - /*=20 - * If present, prefer vc's current processor, else - * just find the first valid vcpu . + /* + * If present, prefer unit's current processor, else + * just find the first valid unit. */ - online =3D cpupool_domain_cpumask(vc->domain); + online =3D cpupool_domain_cpumask(unit->domain); =20 cpu =3D cpumask_first(online); =20 - if ( cpumask_test_cpu(vc->processor, online) + if ( cpumask_test_cpu(sched_unit_cpu(unit), online) || (cpu >=3D nr_cpu_ids) ) - cpu =3D vc->processor; + cpu =3D sched_unit_cpu(unit); =20 return get_sched_res(cpu); } @@ -636,18 +630,18 @@ a653sched_pick_resource(const struct scheduler *ops, = struct sched_unit *unit) * @param new_ops Pointer to this instance of the scheduler structure * @param cpu The cpu that is changing scheduler * @param pdata scheduler specific PCPU data (we don't have any) - * @param vdata scheduler specific VCPU data of the idle vcpu + * @param vdata scheduler specific UNIT data of the idle unit */ static spinlock_t * a653_switch_sched(struct scheduler *new_ops, unsigned int cpu, void *pdata, void *vdata) { struct sched_resource *sd =3D get_sched_res(cpu); - arinc653_vcpu_t *svc =3D vdata; + arinc653_unit_t *svc =3D vdata; =20 - ASSERT(!pdata && svc && is_idle_vcpu(svc->vc)); + ASSERT(!pdata && svc && is_idle_unit(svc->unit)); =20 - idle_vcpu[cpu]->sched_unit->priv =3D vdata; + sched_idle_unit(cpu)->priv =3D vdata; =20 return &sd->_lock; } --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362781; cv=none; d=zoho.com; s=zohoarc; b=RGJXHGvVuJcLpbpy/4Q026mheKYzXGPOi5ud7RmZdXMRzRgpghNm+ddExegwQ9xVPKgMHCXwWKcjlnJhO8YxdnyFc5ooD5bWKi3C3dh+mJ7Aq2sFvNcskNIp6JDbvD60DzcRgtzr91ZntZIJkZ/Pj1zEYpQj6ix37/B7H3fbla4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362781; 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=Ckc33LnEQ+dHtxvGUQ82yP9mFVYtu9G/7OJ78sbyVpk=; b=SaKdUXSPjvgExYHRewTawJZnYHq+EMN/n+676RR+3S+H+UCNz8GnSwZtuA94alIFIDx+quTz9Z26mjWK5/uNuKJvH+HH6fFFBx5c6FhcIqeecksroH+qSJdDAlHjgzCtisjVVlUqvGRYsv2jCAHnkga9YutTE5Tcy9xPTr4tfQA= 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 1565362781503530.6145081994669; Fri, 9 Aug 2019 07:59:41 -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 1hw6MF-00073w-D1; Fri, 09 Aug 2019 14:59:07 +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 1hw6M2-0006cU-RU for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:54 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2f3ddd4a-bab6-11e9-b5aa-0fc1553e8ba5; Fri, 09 Aug 2019 14:58:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6DDF5AFCE; Fri, 9 Aug 2019 14:58:44 +0000 (UTC) X-Inumbo-ID: 2f3ddd4a-bab6-11e9-b5aa-0fc1553e8ba5 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:04 +0200 Message-Id: <20190809145833.1020-20-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 19/48] xen: add sched_unit_pause_nosync() and sched_unit_unpause() 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" The credit scheduler calls vcpu_pause_nosync() and vcpu_unpause() today. Add sched_unit_pause_nosync() and sched_unit_unpause() to perform the same operations on scheduler units instead. Signed-off-by: Juergen Gross --- xen/common/sched_credit.c | 6 +++--- xen/include/xen/sched-if.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 60eb4d3244..4ce0f7668a 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1065,7 +1065,7 @@ csched_unit_remove(const struct scheduler *ops, struc= t sched_unit *unit) if ( test_and_clear_bit(CSCHED_FLAG_UNIT_PARKED, &svc->flags) ) { SCHED_STAT_CRANK(unit_unpark); - vcpu_unpause(svc->unit->vcpu_list); + sched_unit_unpause(svc->unit); } =20 spin_lock_irq(&prv->lock); @@ -1515,7 +1515,7 @@ csched_acct(void* dummy) !test_and_set_bit(CSCHED_FLAG_UNIT_PARKED, &svc->flag= s) ) { SCHED_STAT_CRANK(unit_park); - vcpu_pause_nosync(svc->unit->vcpu_list); + sched_unit_pause_nosync(svc->unit); } =20 /* Lower bound on credits */ @@ -1539,7 +1539,7 @@ csched_acct(void* dummy) * if it is woken up here. */ SCHED_STAT_CRANK(unit_unpark); - vcpu_unpause(svc->unit->vcpu_list); + sched_unit_unpause(svc->unit); clear_bit(CSCHED_FLAG_UNIT_PARKED, &svc->flags); } =20 diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 65fa853e90..a945fc748d 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -431,6 +431,16 @@ static inline int sched_adjust_cpupool(const struct sc= heduler *s, return s->adjust_global ? s->adjust_global(s, op) : 0; } =20 +static inline void sched_unit_pause_nosync(struct sched_unit *unit) +{ + vcpu_pause_nosync(unit->vcpu_list); +} + +static inline void sched_unit_unpause(struct sched_unit *unit) +{ + vcpu_unpause(unit->vcpu_list); +} + #define REGISTER_SCHEDULER(x) static const struct scheduler *x##_entry \ __used_section(".data.schedulers") =3D &x; =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565363056; cv=none; d=zoho.com; s=zohoarc; b=jJ81EY8flq3ZWOHXnT8+sBSCLyOWoi4v5otl+/sSUhHXE9PFtyoKiszZKPer8h1BAmoWUCYppz99l2OUCz/0DnIxgm+oHXXSzobLYf4UTUhAq3T+d1yMnB9xsNFKV8PRwbDt0kNgV0ZUXC1PoKfFOK53N0h1GjVLWtgmw8SBNyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565363056; 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=Ec/i0sHha/ugAWHMu+jA9Li3NR4mKJU0XhLpuee9De4=; b=i//5PJyx5auGXRxqLKZzL6AQc3dxu7v50+91nb9QBKj2LwYSPHy9ebSMJN4LcMVI6QhyB1Y1WOEu/fCnlBSwcUVx8XPYI3u0hMUhXdnJ+BkEK//rlVKB07qkvT5rhFXfPdNcxc4hlvfV3reSWZGV4++J/MkXozJ99XfKrmGtJ9U= 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 1565363056005666.0659944895062; Fri, 9 Aug 2019 08:04:16 -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 1hw6Qa-00041n-HD; Fri, 09 Aug 2019 15:03:36 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6QZ-00041I-H5 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 15:03:35 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2f4bfafe-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:45 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D790DB035; Fri, 9 Aug 2019 14:58:44 +0000 (UTC) X-Inumbo-ID: 2f4bfafe-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:05 +0200 Message-Id: <20190809145833.1020-21-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 20/48] xen: let vcpu_create() select processor 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= 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" Today there are two distinct scenarios for vcpu_create(): either for creation of idle-domain vcpus (vcpuid =3D=3D processor) or for creation of "normal" domain vcpus (including dom0), where the caller selects the initial processor on a round-robin scheme of the allowed processors (allowed being based on cpupool and affinities). Instead of passing the initial processor to vcpu_create() and passing on to sched_init_vcpu() let sched_init_vcpu() do the processor selection. For supporting dom0 vcpu creation use the node_affinity of the domain as a base for selecting the processors. User domains will have initially all nodes set, so this is no different behavior compared to today. In theory this is not guaranteed as vcpus are created only with XEN_DOMCTL_max_vcpus being called, but this call is going to be removed in future and the toolstack doesn't call XEN_DOMCTL_setnodeaffinity before calling XEN_DOMCTL_max_vcpus. To be able to use const struct domain * make cpupool_domain_cpumask() take a const domain pointer, too. Signed-off-by: Juergen Gross Acked-by: Andrew Cooper Acked-by: Julien Grall --- RFC V2: add ASSERT(), modify error message (Andrew Cooper) V1: constify pointers, avoid cpumask on stack (Jan Beulich) --- xen/arch/arm/domain_build.c | 13 ++++++------ xen/arch/x86/dom0_build.c | 10 +++------ xen/arch/x86/hvm/dom0_build.c | 9 ++------ xen/arch/x86/pv/dom0_build.c | 10 ++------- xen/common/domain.c | 5 ++--- xen/common/domctl.c | 10 ++------- xen/common/schedule.c | 44 ++++++++++++++++++++++++++++++++++++= +--- xen/include/asm-x86/dom0_build.h | 3 +-- xen/include/xen/domain.h | 3 +-- xen/include/xen/sched-if.h | 2 +- xen/include/xen/sched.h | 2 +- 11 files changed, 62 insertions(+), 49 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 4c8404155a..2703611b46 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -80,7 +80,7 @@ unsigned int __init dom0_max_vcpus(void) =20 struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0) { - return vcpu_create(dom0, 0, 0); + return vcpu_create(dom0, 0); } =20 static unsigned int __init get_allocation_size(paddr_t size) @@ -1938,7 +1938,7 @@ static void __init find_gnttab_region(struct domain *= d, =20 static int __init construct_domain(struct domain *d, struct kernel_info *k= info) { - int i, cpu; + int i; struct vcpu *v =3D d->vcpu[0]; struct cpu_user_regs *regs =3D &v->arch.cpu_info->guest_cpu_user_regs; =20 @@ -2001,12 +2001,11 @@ static int __init construct_domain(struct domain *d= , struct kernel_info *kinfo) } #endif =20 - for ( i =3D 1, cpu =3D 0; i < d->max_vcpus; i++ ) + for ( i =3D 1; i < d->max_vcpus; i++ ) { - cpu =3D cpumask_cycle(cpu, &cpu_online_map); - if ( vcpu_create(d, i, cpu) =3D=3D NULL ) + if ( vcpu_create(d, i) =3D=3D NULL ) { - printk("Failed to allocate dom0 vcpu %d on pcpu %d\n", i, cpu); + printk("Failed to allocate d0v%u\n", i); break; } =20 @@ -2041,7 +2040,7 @@ static int __init construct_domU(struct domain *d, =20 kinfo.vpl011 =3D dt_property_read_bool(node, "vpl011"); =20 - if ( vcpu_create(d, 0, 0) =3D=3D NULL ) + if ( vcpu_create(d, 0) =3D=3D NULL ) return -ENOMEM; d->max_pages =3D ~0U; =20 diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index c69570920c..6265dd4a1c 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -198,12 +198,9 @@ custom_param("dom0_nodes", parse_dom0_nodes); =20 static cpumask_t __initdata dom0_cpus; =20 -struct vcpu *__init dom0_setup_vcpu(struct domain *d, - unsigned int vcpu_id, - unsigned int prev_cpu) +struct vcpu *__init dom0_setup_vcpu(struct domain *d, unsigned int vcpu_id) { - unsigned int cpu =3D cpumask_cycle(prev_cpu, &dom0_cpus); - struct vcpu *v =3D vcpu_create(d, vcpu_id, cpu); + struct vcpu *v =3D vcpu_create(d, vcpu_id); =20 if ( v ) { @@ -273,8 +270,7 @@ struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom= 0) dom0->node_affinity =3D dom0_nodes; dom0->auto_node_affinity =3D !dom0_nr_pxms; =20 - return dom0_setup_vcpu(dom0, 0, - cpumask_last(&dom0_cpus) /* so it wraps around = to first pcpu */); + return dom0_setup_vcpu(dom0, 0); } =20 #ifdef CONFIG_SHADOW_PAGING diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 8845399ae9..fd8d9609b1 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -614,7 +614,7 @@ static int __init pvh_setup_cpus(struct domain *d, padd= r_t entry, paddr_t start_info) { struct vcpu *v =3D d->vcpu[0]; - unsigned int cpu =3D v->processor, i; + unsigned int i; int rc; /* * This sets the vCPU state according to the state described in @@ -636,12 +636,7 @@ static int __init pvh_setup_cpus(struct domain *d, pad= dr_t entry, }; =20 for ( i =3D 1; i < d->max_vcpus; i++ ) - { - const struct vcpu *p =3D dom0_setup_vcpu(d, i, cpu); - - if ( p ) - cpu =3D p->processor; - } + dom0_setup_vcpu(d, i); =20 domain_update_node_affinity(d); =20 diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 1bd53e9c08..565c6c8b44 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -285,7 +285,7 @@ int __init dom0_construct_pv(struct domain *d, module_t *initrd, char *cmdline) { - int i, cpu, rc, compatible, order, machine; + int i, rc, compatible, order, machine; struct cpu_user_regs *regs; unsigned long pfn, mfn; unsigned long nr_pages; @@ -694,14 +694,8 @@ int __init dom0_construct_pv(struct domain *d, =20 printk("Dom%u has maximum %u VCPUs\n", d->domain_id, d->max_vcpus); =20 - cpu =3D v->processor; for ( i =3D 1; i < d->max_vcpus; i++ ) - { - const struct vcpu *p =3D dom0_setup_vcpu(d, i, cpu); - - if ( p ) - cpu =3D p->processor; - } + dom0_setup_vcpu(d, i); =20 domain_update_node_affinity(d); d->arch.paging.mode =3D 0; diff --git a/xen/common/domain.c b/xen/common/domain.c index 5aa40929c0..19d881b0c3 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -135,8 +135,7 @@ static void vcpu_destroy(struct vcpu *v) free_vcpu_struct(v); } =20 -struct vcpu *vcpu_create( - struct domain *d, unsigned int vcpu_id, unsigned int cpu_id) +struct vcpu *vcpu_create(struct domain *d, unsigned int vcpu_id) { struct vcpu *v; =20 @@ -168,7 +167,7 @@ struct vcpu *vcpu_create( init_waitqueue_vcpu(v); } =20 - if ( sched_init_vcpu(v, cpu_id) !=3D 0 ) + if ( sched_init_vcpu(v) !=3D 0 ) goto fail_wq; =20 if ( arch_vcpu_create(v) !=3D 0 ) diff --git a/xen/common/domctl.c b/xen/common/domctl.c index ebb37a138e..cf70671d2d 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -532,8 +532,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) =20 case XEN_DOMCTL_max_vcpus: { - unsigned int i, max =3D op->u.max_vcpus.max, cpu; - cpumask_t *online; + unsigned int i, max =3D op->u.max_vcpus.max; =20 ret =3D -EINVAL; if ( (d =3D=3D current->domain) || /* no domain_pause() */ @@ -544,18 +543,13 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u= _domctl) domain_pause(d); =20 ret =3D -ENOMEM; - online =3D cpupool_domain_cpumask(d); =20 for ( i =3D 0; i < max; i++ ) { if ( d->vcpu[i] !=3D NULL ) continue; =20 - cpu =3D (i =3D=3D 0) ? - cpumask_any(online) : - cpumask_cycle(d->vcpu[i-1]->processor, online); - - if ( vcpu_create(d, i, cpu) =3D=3D NULL ) + if ( vcpu_create(d, i) =3D=3D NULL ) goto maxvcpu_out; } =20 diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 03119af25c..6281e884cf 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -368,14 +368,52 @@ static struct sched_unit *sched_alloc_unit(struct vcp= u *v) return NULL; } =20 -int sched_init_vcpu(struct vcpu *v, unsigned int processor) +static unsigned int sched_select_initial_cpu(const struct vcpu *v) +{ + const struct domain *d =3D v->domain; + nodeid_t node; + spinlock_t *lock; + unsigned long flags; + unsigned int cpu_ret, cpu =3D smp_processor_id(); + cpumask_t *cpus =3D cpumask_scratch_cpu(cpu); + + lock =3D pcpu_schedule_lock_irqsave(cpu, &flags); + cpumask_clear(cpus); + for_each_node_mask ( node, d->node_affinity ) + cpumask_or(cpus, cpus, &node_to_cpumask(node)); + cpumask_and(cpus, cpus, cpupool_domain_cpumask(d)); + if ( cpumask_empty(cpus) ) + cpumask_copy(cpus, cpupool_domain_cpumask(d)); + + if ( v->vcpu_id =3D=3D 0 ) + cpu_ret =3D cpumask_first(cpus); + else + { + /* We can rely on previous vcpu being available. */ + ASSERT(!is_idle_domain(d)); + + cpu_ret =3D cpumask_cycle(d->vcpu[v->vcpu_id - 1]->processor, cpus= ); + } + + pcpu_schedule_unlock_irqrestore(lock, flags, cpu); + + return cpu_ret; +} + +int sched_init_vcpu(struct vcpu *v) { struct domain *d =3D v->domain; struct sched_unit *unit; + unsigned int processor; =20 if ( (unit =3D sched_alloc_unit(v)) =3D=3D NULL ) return 1; =20 + if ( is_idle_domain(d) ) + processor =3D v->vcpu_id; + else + processor =3D sched_select_initial_cpu(v); + sched_set_res(unit, get_sched_res(processor)); =20 /* Initialise the per-vcpu timers. */ @@ -1753,7 +1791,7 @@ static int cpu_schedule_up(unsigned int cpu) return 0; =20 if ( idle_vcpu[cpu] =3D=3D NULL ) - vcpu_create(idle_vcpu[0]->domain, cpu, cpu); + vcpu_create(idle_vcpu[0]->domain, cpu); else idle_vcpu[cpu]->sched_unit->res =3D sd; =20 @@ -1932,7 +1970,7 @@ void __init scheduler_init(void) BUG_ON(nr_cpu_ids > ARRAY_SIZE(idle_vcpu)); idle_domain->vcpu =3D idle_vcpu; idle_domain->max_vcpus =3D nr_cpu_ids; - if ( vcpu_create(idle_domain, 0, 0) =3D=3D NULL ) + if ( vcpu_create(idle_domain, 0) =3D=3D NULL ) BUG(); get_sched_res(0)->curr =3D idle_vcpu[0]->sched_unit; } diff --git a/xen/include/asm-x86/dom0_build.h b/xen/include/asm-x86/dom0_bu= ild.h index 33a5483739..3eb4b036e1 100644 --- a/xen/include/asm-x86/dom0_build.h +++ b/xen/include/asm-x86/dom0_build.h @@ -11,8 +11,7 @@ extern unsigned int dom0_memflags; unsigned long dom0_compute_nr_pages(struct domain *d, struct elf_dom_parms *parms, unsigned long initrd_len); -struct vcpu *dom0_setup_vcpu(struct domain *d, unsigned int vcpu_id, - unsigned int cpu); +struct vcpu *dom0_setup_vcpu(struct domain *d, unsigned int vcpu_id); int dom0_setup_permissions(struct domain *d); =20 int dom0_construct_pv(struct domain *d, const module_t *image, diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 3f09cb66c0..4ca3db5a18 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -13,8 +13,7 @@ typedef union { struct compat_vcpu_guest_context *cmp; } vcpu_guest_context_u __attribute__((__transparent_union__)); =20 -struct vcpu *vcpu_create( - struct domain *d, unsigned int vcpu_id, unsigned int cpu_id); +struct vcpu *vcpu_create(struct domain *d, unsigned int vcpu_id); =20 unsigned int dom0_max_vcpus(void); struct vcpu *alloc_dom0_vcpu0(struct domain *dom0); diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index a945fc748d..1440055250 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -457,7 +457,7 @@ struct cpupool #define cpupool_online_cpumask(_pool) \ (((_pool) =3D=3D NULL) ? &cpu_online_map : (_pool)->cpu_valid) =20 -static inline cpumask_t* cpupool_domain_cpumask(struct domain *d) +static inline cpumask_t* cpupool_domain_cpumask(const struct domain *d) { /* * d->cpupool is NULL only for the idle domain, and no one should diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index f506c0cbd4..f639b164b5 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -662,7 +662,7 @@ void __domain_crash(struct domain *d); void noreturn asm_domain_crash_synchronous(unsigned long addr); =20 void scheduler_init(void); -int sched_init_vcpu(struct vcpu *v, unsigned int processor); +int sched_init_vcpu(struct vcpu *v); void sched_destroy_vcpu(struct vcpu *v); int sched_init_domain(struct domain *d, int poolid); void sched_destroy_domain(struct domain *d); --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362776; cv=none; d=zoho.com; s=zohoarc; b=IkdmoA5bWwwyYDeahfcRPsgUNhyWSGLOzDqIQsdNSGzbvnbMY6S7qycVwzRrqoRkj0MNsCRZX1KHwrYSN6qMIWSpDxXvwwLETlNEVqXrbe8DK6opPmmWLPzErDVfKapyHoTMzRjcHKIez8lJHMkRI8aJ9RUD0W8OY1xPwnOdtEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362776; 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=Qv6CpS0wA+2omzJb6f4rsurEWViV/38cyt8Q+QPCBCA=; b=XiCNwntPlnrjG0QIDmHnIPnMvQVLem/epdE3gEUPG27e5qVyJQNF0YvzRwbHutogaSN1B4ZNeRE4ca1wxxg15WsFZmReKFDsFaxpse4asUIZDVFT52ih4/yrKxw/VuWs/3bHPQJoZM4ECx1s7WnBkHdULvL2ASbZjI/TdOfotMg= 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 15653627764681015.2377031625907; Fri, 9 Aug 2019 07:59:36 -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 1hw6M4-0006gD-NW; Fri, 09 Aug 2019 14:58:56 +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 1hw6Lz-0006XE-T9 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:51 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 30110ce2-bab6-11e9-bdd9-7fc645eeb30a; Fri, 09 Aug 2019 14:58:46 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5BEC7B0B6; Fri, 9 Aug 2019 14:58:45 +0000 (UTC) X-Inumbo-ID: 30110ce2-bab6-11e9-bdd9-7fc645eeb30a X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:06 +0200 Message-Id: <20190809145833.1020-22-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 21/48] xen/sched: use sched_resource cpu instead smp_processor_id in schedulers 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 , Robert VanVossen , Dario Faggioli , Julien Grall , Josh Whitehead , Meng Xu , 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" Especially in the do_schedule() functions of the different schedulers using smp_processor_id() for the local cpu number is correct only if the sched_unit is a single vcpu. As soon as larger sched_units are used most uses should be replaced by the cpu number of the local sched_resource instead. Add a helper to get that sched_resource cpu and modify the schedulers to use it in a correct way. Signed-off-by: Juergen Gross --- xen/common/sched_arinc653.c | 2 +- xen/common/sched_credit.c | 21 +++++++++--------- xen/common/sched_credit2.c | 53 +++++++++++++++++++++++------------------= ---- xen/common/sched_null.c | 17 ++++++++------- xen/common/sched_rt.c | 17 ++++++++------- xen/common/schedule.c | 2 +- xen/include/xen/sched-if.h | 5 +++++ 7 files changed, 63 insertions(+), 54 deletions(-) diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c index 213bc960ef..e48f2b2eb9 100644 --- a/xen/common/sched_arinc653.c +++ b/xen/common/sched_arinc653.c @@ -513,7 +513,7 @@ a653sched_do_schedule( static unsigned int sched_index =3D 0; static s_time_t next_switch_time; a653sched_priv_t *sched_priv =3D SCHED_PRIV(ops); - const unsigned int cpu =3D smp_processor_id(); + const unsigned int cpu =3D sched_get_resource_cpu(smp_processor_id()); unsigned long flags; =20 spin_lock_irqsave(&sched_priv->lock, flags); diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 4ce0f7668a..87cb62c632 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1684,7 +1684,7 @@ csched_load_balance(struct csched_private *prv, int c= pu, int peer_cpu, first_cpu, peer_node, bstep; int node =3D cpu_to_node(cpu); =20 - BUG_ON( cpu !=3D sched_unit_cpu(snext->unit) ); + BUG_ON( sched_get_resource_cpu(cpu) !=3D sched_unit_cpu(snext->unit) ); online =3D cpupool_online_cpumask(c); =20 /* @@ -1825,8 +1825,9 @@ static struct task_slice csched_schedule( const struct scheduler *ops, s_time_t now, bool_t tasklet_work_schedul= ed) { - const int cpu =3D smp_processor_id(); - struct list_head * const runq =3D RUNQ(cpu); + const unsigned int cpu =3D smp_processor_id(); + const unsigned int sched_cpu =3D sched_get_resource_cpu(cpu); + struct list_head * const runq =3D RUNQ(sched_cpu); struct sched_unit *unit =3D current->sched_unit; struct csched_unit * const scurr =3D CSCHED_UNIT(unit); struct csched_private *prv =3D CSCHED_PRIV(ops); @@ -1937,7 +1938,7 @@ csched_schedule( { BUG_ON( is_idle_unit(unit) || list_empty(runq) ); /* Current has blocked. Update the runnable counter for this cpu. = */ - dec_nr_runnable(cpu); + dec_nr_runnable(sched_cpu); } =20 snext =3D __runq_elem(runq->next); @@ -1947,7 +1948,7 @@ csched_schedule( if ( tasklet_work_scheduled ) { TRACE_0D(TRC_CSCHED_SCHED_TASKLET); - snext =3D CSCHED_UNIT(sched_idle_unit(cpu)); + snext =3D CSCHED_UNIT(sched_idle_unit(sched_cpu)); snext->pri =3D CSCHED_PRI_TS_BOOST; } =20 @@ -1967,7 +1968,7 @@ csched_schedule( if ( snext->pri > CSCHED_PRI_TS_OVER ) __runq_remove(snext); else - snext =3D csched_load_balance(prv, cpu, snext, &ret.migrated); + snext =3D csched_load_balance(prv, sched_cpu, snext, &ret.migrated= ); =20 /* * Update idlers mask if necessary. When we're idling, other CPUs @@ -1975,12 +1976,12 @@ csched_schedule( */ if ( !tasklet_work_scheduled && snext->pri =3D=3D CSCHED_PRI_IDLE ) { - if ( !cpumask_test_cpu(cpu, prv->idlers) ) - cpumask_set_cpu(cpu, prv->idlers); + if ( !cpumask_test_cpu(sched_cpu, prv->idlers) ) + cpumask_set_cpu(sched_cpu, prv->idlers); } - else if ( cpumask_test_cpu(cpu, prv->idlers) ) + else if ( cpumask_test_cpu(sched_cpu, prv->idlers) ) { - cpumask_clear_cpu(cpu, prv->idlers); + cpumask_clear_cpu(sched_cpu, prv->idlers); } =20 if ( !is_idle_unit(snext->unit) ) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index e3ac9c5460..548b87af8b 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -3448,7 +3448,8 @@ static struct task_slice csched2_schedule( const struct scheduler *ops, s_time_t now, bool tasklet_work_scheduled) { - const int cpu =3D smp_processor_id(); + const unsigned int cpu =3D smp_processor_id(); + const unsigned int sched_cpu =3D sched_get_resource_cpu(cpu); struct csched2_runqueue_data *rqd; struct sched_unit *currunit =3D current->sched_unit; struct csched2_unit * const scurr =3D csched2_unit(currunit); @@ -3460,22 +3461,22 @@ csched2_schedule( SCHED_STAT_CRANK(schedule); CSCHED2_UNIT_CHECK(currunit); =20 - BUG_ON(!cpumask_test_cpu(cpu, &csched2_priv(ops)->initialized)); + BUG_ON(!cpumask_test_cpu(sched_cpu, &csched2_priv(ops)->initialized)); =20 - rqd =3D c2rqd(ops, cpu); - BUG_ON(!cpumask_test_cpu(cpu, &rqd->active)); + rqd =3D c2rqd(ops, sched_cpu); + BUG_ON(!cpumask_test_cpu(sched_cpu, &rqd->active)); =20 - ASSERT(spin_is_locked(get_sched_res(cpu)->schedule_lock)); + ASSERT(spin_is_locked(get_sched_res(sched_cpu)->schedule_lock)); =20 BUG_ON(!is_idle_unit(currunit) && scurr->rqd !=3D rqd); =20 /* Clear "tickled" bit now that we've been scheduled */ - tickled =3D cpumask_test_cpu(cpu, &rqd->tickled); + tickled =3D cpumask_test_cpu(sched_cpu, &rqd->tickled); if ( tickled ) { - __cpumask_clear_cpu(cpu, &rqd->tickled); + __cpumask_clear_cpu(sched_cpu, &rqd->tickled); cpumask_andnot(cpumask_scratch, &rqd->idle, &rqd->tickled); - smt_idle_mask_set(cpu, cpumask_scratch, &rqd->smt_idle); + smt_idle_mask_set(sched_cpu, cpumask_scratch, &rqd->smt_idle); } =20 if ( unlikely(tb_init_done) ) @@ -3485,10 +3486,10 @@ csched2_schedule( unsigned tasklet:8, idle:8, smt_idle:8, tickled:8; } d; d.cpu =3D cpu; - d.rq_id =3D c2r(cpu); + d.rq_id =3D c2r(sched_cpu); d.tasklet =3D tasklet_work_scheduled; d.idle =3D is_idle_unit(currunit); - d.smt_idle =3D cpumask_test_cpu(cpu, &rqd->smt_idle); + d.smt_idle =3D cpumask_test_cpu(sched_cpu, &rqd->smt_idle); d.tickled =3D tickled; __trace_var(TRC_CSCHED2_SCHEDULE, 1, sizeof(d), @@ -3528,10 +3529,10 @@ csched2_schedule( { __clear_bit(__CSFLAG_unit_yield, &scurr->flags); trace_var(TRC_CSCHED2_SCHED_TASKLET, 1, 0, NULL); - snext =3D csched2_unit(sched_idle_unit(cpu)); + snext =3D csched2_unit(sched_idle_unit(sched_cpu)); } else - snext =3D runq_candidate(rqd, scurr, cpu, now, &skipped_units); + snext =3D runq_candidate(rqd, scurr, sched_cpu, now, &skipped_unit= s); =20 /* If switching from a non-idle runnable unit, put it * back on the runqueue. */ @@ -3556,10 +3557,10 @@ csched2_schedule( } =20 /* Clear the idle mask if necessary */ - if ( cpumask_test_cpu(cpu, &rqd->idle) ) + if ( cpumask_test_cpu(sched_cpu, &rqd->idle) ) { - __cpumask_clear_cpu(cpu, &rqd->idle); - smt_idle_mask_clear(cpu, &rqd->smt_idle); + __cpumask_clear_cpu(sched_cpu, &rqd->idle); + smt_idle_mask_clear(sched_cpu, &rqd->smt_idle); } =20 /* @@ -3578,18 +3579,18 @@ csched2_schedule( */ if ( skipped_units =3D=3D 0 && snext->credit <=3D CSCHED2_CREDIT_R= ESET ) { - reset_credit(ops, cpu, now, snext); - balance_load(ops, cpu, now); + reset_credit(ops, sched_cpu, now, snext); + balance_load(ops, sched_cpu, now); } =20 snext->start_time =3D now; snext->tickled_cpu =3D -1; =20 /* Safe because lock for old processor is held */ - if ( sched_unit_cpu(snext->unit) !=3D cpu ) + if ( sched_unit_cpu(snext->unit) !=3D sched_cpu ) { snext->credit +=3D CSCHED2_MIGRATE_COMPENSATION; - sched_set_res(snext->unit, get_sched_res(cpu)); + sched_set_res(snext->unit, get_sched_res(sched_cpu)); SCHED_STAT_CRANK(migrated); ret.migrated =3D 1; } @@ -3602,17 +3603,17 @@ csched2_schedule( */ if ( tasklet_work_scheduled ) { - if ( cpumask_test_cpu(cpu, &rqd->idle) ) + if ( cpumask_test_cpu(sched_cpu, &rqd->idle) ) { - __cpumask_clear_cpu(cpu, &rqd->idle); - smt_idle_mask_clear(cpu, &rqd->smt_idle); + __cpumask_clear_cpu(sched_cpu, &rqd->idle); + smt_idle_mask_clear(sched_cpu, &rqd->smt_idle); } } - else if ( !cpumask_test_cpu(cpu, &rqd->idle) ) + else if ( !cpumask_test_cpu(sched_cpu, &rqd->idle) ) { - __cpumask_set_cpu(cpu, &rqd->idle); + __cpumask_set_cpu(sched_cpu, &rqd->idle); cpumask_andnot(cpumask_scratch, &rqd->idle, &rqd->tickled); - smt_idle_mask_set(cpu, cpumask_scratch, &rqd->smt_idle); + smt_idle_mask_set(sched_cpu, cpumask_scratch, &rqd->smt_idle); } /* Make sure avgload gets updated periodically even * if there's no activity */ @@ -3622,7 +3623,7 @@ csched2_schedule( /* * Return task to run next... */ - ret.time =3D csched2_runtime(ops, cpu, snext, now); + ret.time =3D csched2_runtime(ops, sched_cpu, snext, now); ret.task =3D snext->unit; =20 CSCHED2_UNIT_CHECK(ret.task); diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index a630951110..56ef078c5a 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -785,6 +785,7 @@ static struct task_slice null_schedule(const struct sch= eduler *ops, { unsigned int bs; const unsigned int cpu =3D smp_processor_id(); + const unsigned int sched_cpu =3D sched_get_resource_cpu(cpu); struct null_private *prv =3D null_priv(ops); struct null_unit *wvc; struct task_slice ret; @@ -800,14 +801,14 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, } d; d.cpu =3D cpu; d.tasklet =3D tasklet_work_scheduled; - if ( per_cpu(npc, cpu).unit =3D=3D NULL ) + if ( per_cpu(npc, sched_cpu).unit =3D=3D NULL ) { d.unit =3D d.dom =3D -1; } else { - d.unit =3D per_cpu(npc, cpu).unit->unit_id; - d.dom =3D per_cpu(npc, cpu).unit->domain->domain_id; + d.unit =3D per_cpu(npc, sched_cpu).unit->unit_id; + d.dom =3D per_cpu(npc, sched_cpu).unit->domain->domain_id; } __trace_var(TRC_SNULL_SCHEDULE, 1, sizeof(d), &d); } @@ -815,10 +816,10 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, if ( tasklet_work_scheduled ) { trace_var(TRC_SNULL_TASKLET, 1, 0, NULL); - ret.task =3D sched_idle_unit(cpu); + ret.task =3D sched_idle_unit(sched_cpu); } else - ret.task =3D per_cpu(npc, cpu).unit; + ret.task =3D per_cpu(npc, sched_cpu).unit; ret.migrated =3D 0; ret.time =3D -1; =20 @@ -849,9 +850,9 @@ static struct task_slice null_schedule(const struct sch= eduler *ops, !has_soft_affinity(wvc->unit) ) continue; =20 - if ( unit_check_affinity(wvc->unit, cpu, bs) ) + if ( unit_check_affinity(wvc->unit, sched_cpu, bs) ) { - unit_assign(prv, wvc->unit, cpu); + unit_assign(prv, wvc->unit, sched_cpu); list_del_init(&wvc->waitq_elem); ret.task =3D wvc->unit; goto unlock; @@ -866,7 +867,7 @@ static struct task_slice null_schedule(const struct sch= eduler *ops, } =20 if ( unlikely(ret.task =3D=3D NULL || !unit_runnable(ret.task)) ) - ret.task =3D sched_idle_unit(cpu); + ret.task =3D sched_idle_unit(sched_cpu); =20 NULL_UNIT_CHECK(ret.task); return ret; diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index 95262aff95..7b9d25f138 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -1057,7 +1057,8 @@ runq_pick(const struct scheduler *ops, const cpumask_= t *mask) static struct task_slice rt_schedule(const struct scheduler *ops, s_time_t now, bool_t tasklet_work= _scheduled) { - const int cpu =3D smp_processor_id(); + const unsigned int cpu =3D smp_processor_id(); + const unsigned int sched_cpu =3D sched_get_resource_cpu(cpu); struct rt_private *prv =3D rt_priv(ops); struct rt_unit *const scurr =3D rt_unit(current->sched_unit); struct rt_unit *snext =3D NULL; @@ -1071,7 +1072,7 @@ rt_schedule(const struct scheduler *ops, s_time_t now= , bool_t tasklet_work_sched } d; d.cpu =3D cpu; d.tasklet =3D tasklet_work_scheduled; - d.tickled =3D cpumask_test_cpu(cpu, &prv->tickled); + d.tickled =3D cpumask_test_cpu(sched_cpu, &prv->tickled); d.idle =3D is_idle_unit(currunit); trace_var(TRC_RTDS_SCHEDULE, 1, sizeof(d), @@ -1079,7 +1080,7 @@ rt_schedule(const struct scheduler *ops, s_time_t now= , bool_t tasklet_work_sched } =20 /* clear ticked bit now that we've been scheduled */ - cpumask_clear_cpu(cpu, &prv->tickled); + cpumask_clear_cpu(sched_cpu, &prv->tickled); =20 /* burn_budget would return for IDLE UNIT */ burn_budget(ops, scurr, now); @@ -1087,13 +1088,13 @@ rt_schedule(const struct scheduler *ops, s_time_t n= ow, bool_t tasklet_work_sched if ( tasklet_work_scheduled ) { trace_var(TRC_RTDS_SCHED_TASKLET, 1, 0, NULL); - snext =3D rt_unit(sched_idle_unit(cpu)); + snext =3D rt_unit(sched_idle_unit(sched_cpu)); } else { - snext =3D runq_pick(ops, cpumask_of(cpu)); + snext =3D runq_pick(ops, cpumask_of(sched_cpu)); if ( snext =3D=3D NULL ) - snext =3D rt_unit(sched_idle_unit(cpu)); + snext =3D rt_unit(sched_idle_unit(sched_cpu)); =20 /* if scurr has higher priority and budget, still pick scurr */ if ( !is_idle_unit(currunit) && @@ -1118,9 +1119,9 @@ rt_schedule(const struct scheduler *ops, s_time_t now= , bool_t tasklet_work_sched q_remove(snext); __set_bit(__RTDS_scheduled, &snext->flags); } - if ( sched_unit_cpu(snext->unit) !=3D cpu ) + if ( sched_unit_cpu(snext->unit) !=3D sched_cpu ) { - sched_set_res(snext->unit, get_sched_res(cpu)); + sched_set_res(snext->unit, get_sched_res(sched_cpu)); ret.migrated =3D 1; } ret.time =3D snext->cur_budget; /* invoke the scheduler next time = */ diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 6281e884cf..d8402878d4 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -112,7 +112,7 @@ static struct task_slice sched_idle_schedule( const unsigned int cpu =3D smp_processor_id(); struct task_slice ret =3D { .time =3D -1 }; =20 - ret.task =3D sched_idle_unit(cpu); + ret.task =3D sched_idle_unit(sched_get_resource_cpu(cpu)); return ret; } =20 diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 1440055250..1a3981e78a 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -115,6 +115,11 @@ static inline struct sched_unit *sched_idle_unit(unsig= ned int cpu) return idle_vcpu[cpu]->sched_unit; } =20 +static inline unsigned int sched_get_resource_cpu(unsigned int cpu) +{ + return get_sched_res(cpu)->processor; +} + /* * Scratch space, for avoiding having too many cpumask_t on the stack. * Within each scheduler, when using the scratch mask of one pCPU: --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362802; cv=none; d=zoho.com; s=zohoarc; b=N5mKMIo9oDjSMET89nLy6omKay7ggJBS7c64KwaIF/BJvMnkpQoRv/1MRg7NblfNl/UhTWlIFPpZEALBN/oFyCxZOGrZCoxa6SqLgPG71jDSEAsCQxTTyKQEK3SvJvgGt5KEe9/J1mV5dFMgMtZ1Hp2goL0xneWk65rWMTtMi3s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362802; 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=5z9PN9BKMNx7A0IX3gj4lrFZDIf/d8nMPysi7gI+qcU=; b=ieFQxwQwTuAHrkzOkxIxt1BiMBAEl2nYtOE2aOwj96K3Ubkqv7zMuQYsRnVzFF1W1XT4KnjA1h3sKhKe/RKtlLzWYeANrDX93OlcmZmkkxDWyI2IuQOFfbvPGQ6mV1TjlJogCEqo6/+G0DDjwXvTABTn+skA6ejVQ3LiC9JZBeU= 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 1565362802098887.9376846111236; Fri, 9 Aug 2019 08:00:02 -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 1hw6M2-0006bC-0Z; Fri, 09 Aug 2019 14:58:54 +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 1hw6Ly-0006V1-KR for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:50 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3012e53a-bab6-11e9-83be-dbc95973f017; Fri, 09 Aug 2019 14:58:46 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 84C83B0B7; Fri, 9 Aug 2019 14:58:45 +0000 (UTC) X-Inumbo-ID: 3012e53a-bab6-11e9-83be-dbc95973f017 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:07 +0200 Message-Id: <20190809145833.1020-23-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 22/48] xen/sched: switch schedule() from vcpus to sched_units 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 , George Dunlap , Dario Faggioli 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" Use sched_units instead of vcpus in schedule(). This includes the introduction of sched_unit_runstate_change() as a replacement of vcpu_runstate_change() in schedule(). Signed-off-by: Juergen Gross --- xen/common/schedule.c | 68 +++++++++++++++++++++++++++++------------------= ---- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index d8402878d4..b87aec74b7 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -248,6 +248,20 @@ static inline void vcpu_runstate_change( v->runstate.state =3D new_state; } =20 +static inline void sched_unit_runstate_change(struct sched_unit *unit, + bool running, s_time_t new_entry_time) +{ + struct vcpu *v =3D unit->vcpu_list; + + if ( running ) + vcpu_runstate_change(v, RUNSTATE_running, new_entry_time); + else + vcpu_runstate_change(v, + ((v->pause_flags & VPF_blocked) ? RUNSTATE_blocked : + (vcpu_runnable(v) ? RUNSTATE_runnable : RUNSTATE_offline)), + new_entry_time); +} + void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate) { spinlock_t *lock =3D likely(v =3D=3D current) @@ -1613,7 +1627,7 @@ static void vcpu_periodic_timer_work(struct vcpu *v) */ static void schedule(void) { - struct vcpu *prev =3D current, *next =3D NULL; + struct sched_unit *prev =3D current->sched_unit, *next =3D NULL; s_time_t now; struct scheduler *sched; unsigned long *tasklet_work =3D &this_cpu(tasklet_work_to_do); @@ -1657,9 +1671,9 @@ static void schedule(void) sched =3D this_cpu(scheduler); next_slice =3D sched->do_schedule(sched, now, tasklet_work_scheduled); =20 - next =3D next_slice.task->vcpu_list; + next =3D next_slice.task; =20 - sd->curr =3D next->sched_unit; + sd->curr =3D next; =20 if ( next_slice.time >=3D 0 ) /* -ve means no limit */ set_timer(&sd->s_timer, now + next_slice.time); @@ -1668,59 +1682,55 @@ static void schedule(void) { pcpu_schedule_unlock_irq(lock, cpu); TRACE_4D(TRC_SCHED_SWITCH_INFCONT, - next->domain->domain_id, next->vcpu_id, - now - prev->runstate.state_entry_time, + next->domain->domain_id, next->unit_id, + now - prev->state_entry_time, next_slice.time); - trace_continue_running(next); - return continue_running(prev); + trace_continue_running(next->vcpu_list); + return continue_running(prev->vcpu_list); } =20 TRACE_3D(TRC_SCHED_SWITCH_INFPREV, - prev->domain->domain_id, prev->vcpu_id, - now - prev->runstate.state_entry_time); + prev->domain->domain_id, prev->unit_id, + now - prev->state_entry_time); TRACE_4D(TRC_SCHED_SWITCH_INFNEXT, - next->domain->domain_id, next->vcpu_id, - (next->runstate.state =3D=3D RUNSTATE_runnable) ? - (now - next->runstate.state_entry_time) : 0, + next->domain->domain_id, next->unit_id, + (next->vcpu_list->runstate.state =3D=3D RUNSTATE_runnable) ? + (now - next->state_entry_time) : 0, next_slice.time); =20 - ASSERT(prev->runstate.state =3D=3D RUNSTATE_running); + ASSERT(prev->vcpu_list->runstate.state =3D=3D RUNSTATE_running); =20 TRACE_4D(TRC_SCHED_SWITCH, - prev->domain->domain_id, prev->vcpu_id, - next->domain->domain_id, next->vcpu_id); + prev->domain->domain_id, prev->unit_id, + next->domain->domain_id, next->unit_id); =20 - vcpu_runstate_change( - prev, - ((prev->pause_flags & VPF_blocked) ? RUNSTATE_blocked : - (vcpu_runnable(prev) ? RUNSTATE_runnable : RUNSTATE_offline)), - now); + sched_unit_runstate_change(prev, false, now); =20 - ASSERT(next->runstate.state !=3D RUNSTATE_running); - vcpu_runstate_change(next, RUNSTATE_running, now); + ASSERT(next->vcpu_list->runstate.state !=3D RUNSTATE_running); + sched_unit_runstate_change(next, true, now); =20 /* * NB. Don't add any trace records from here until the actual context * switch, else lost_records resume will not work properly. */ =20 - ASSERT(!next->sched_unit->is_running); + ASSERT(!next->is_running); + next->vcpu_list->is_running =3D 1; next->is_running =3D 1; - next->sched_unit->is_running =3D 1; - next->sched_unit->state_entry_time =3D now; + next->state_entry_time =3D now; =20 pcpu_schedule_unlock_irq(lock, cpu); =20 SCHED_STAT_CRANK(sched_ctx); =20 - stop_timer(&prev->periodic_timer); + stop_timer(&prev->vcpu_list->periodic_timer); =20 if ( next_slice.migrated ) - sched_move_irqs(next); + sched_move_irqs(next->vcpu_list); =20 - vcpu_periodic_timer_work(next); + vcpu_periodic_timer_work(next->vcpu_list); =20 - context_switch(prev, next); + context_switch(prev->vcpu_list, next->vcpu_list); } =20 void context_saved(struct vcpu *prev) --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362778; cv=none; d=zoho.com; s=zohoarc; b=KJoL9dDmesTnWkuvU2Gf/SgGjt04O7nIndUrKBu6yrAhxNXJQDhFH8hY45MoGwbl8ekK2STIv/9utNmtHmxGtOT6LUH2aKoktSKcJ25sEuCHCAtbZ2alWVDSdDcRvXEe0krLNQMw6+rYBjvfy6unMx+L312mymcqWKKh96/8lYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362778; 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=PVVATTT3P8C8uTCF40ycpAx/J4neWUVVNenMGpwiTqQ=; b=SWqLKHDVafvwljO6ALmGCmNlVXQdQxiuAUm8rF7pPla4HDcrS85no8ufnwe3t3AqUwxJ9xFuIeYm3NNLZOlhzymPphYASRDcQfTMEWqah/WmeRSIu5eP4tHuF4UVWO02WGDj6r8ukSRpYLISFVC5SUkCy+OpU5qbE/UCpGfDlr8= 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 1565362778042738.9579433647648; Fri, 9 Aug 2019 07:59:38 -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 1hw6M9-0006pP-7W; Fri, 09 Aug 2019 14:59:01 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M0-0006Yd-Nz for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:52 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 30bbe6ef-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:48 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B76C4B0BA; Fri, 9 Aug 2019 14:58:45 +0000 (UTC) X-Inumbo-ID: 30bbe6ef-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:08 +0200 Message-Id: <20190809145833.1020-24-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 23/48] xen/sched: switch sched_move_irqs() to take sched_unit as parameter 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 , George Dunlap , Dario Faggioli 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" sched_move_irqs() should work on a sched_unit as that is the unit moved between cpus. Rename the current function to vcpu_move_irqs() as it is still needed in schedule(). Signed-off-by: Juergen Gross --- xen/common/schedule.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index b87aec74b7..fcd083d31d 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -470,12 +470,20 @@ int sched_init_vcpu(struct vcpu *v) return 0; } =20 -static void sched_move_irqs(struct vcpu *v) +static void vcpu_move_irqs(struct vcpu *v) { arch_move_irqs(v); evtchn_move_pirqs(v); } =20 +static void sched_move_irqs(struct sched_unit *unit) +{ + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + vcpu_move_irqs(v); +} + int sched_move_domain(struct domain *d, struct cpupool *c) { struct vcpu *v; @@ -555,7 +563,7 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) =20 v->sched_unit->priv =3D vcpu_priv[v->vcpu_id]; if ( !d->is_dying ) - sched_move_irqs(v); + sched_move_irqs(v->sched_unit); =20 new_p =3D cpumask_cycle(new_p, c->cpu_valid); =20 @@ -848,7 +856,7 @@ static void vcpu_migrate_finish(struct vcpu *v) sched_spin_unlock_double(old_lock, new_lock, flags); =20 if ( old_cpu !=3D new_cpu ) - sched_move_irqs(v); + sched_move_irqs(v->sched_unit); =20 /* Wake on new CPU. */ vcpu_wake(v); @@ -931,7 +939,7 @@ void restore_vcpu_affinity(struct domain *d) spin_unlock_irq(lock); =20 if ( old_cpu !=3D v->processor ) - sched_move_irqs(v); + sched_move_irqs(v->sched_unit); } =20 domain_update_node_affinity(d); @@ -1726,7 +1734,7 @@ static void schedule(void) stop_timer(&prev->vcpu_list->periodic_timer); =20 if ( next_slice.migrated ) - sched_move_irqs(next->vcpu_list); + vcpu_move_irqs(next->vcpu_list); =20 vcpu_periodic_timer_work(next->vcpu_list); =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362778; cv=none; d=zoho.com; s=zohoarc; b=ZQqjt0mRV7sBf2kvYAULDIMaoduiWwqKqR4SnOGdJvjgqflfmSi91OWXaayOMHY6iLiWPxW0o7YuNTdMbG/xVS+DWElTBYo1rTJThwNHtg4eQc832/nx45tIcHmTVrtT6Pm3Bh2c16phQilk3gCQtJymxe9nfIpXBnpWd8RAKk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362778; 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=OvUxWompHdGZYAXAHEaxlrXBFfcc10rTQsppxV/g/hU=; b=KstHRJJsxuyGX0UpQee/2p+61KMGv33MbOdiQPJCbhvwcohmeHduyuBI8aJhEaAvD0rPh/ep7fwSr2ua9UdaQmhqxhyAw8cLomGBGCbbFN8KrqJ5lKuT8ZFAxd7ps5KAu4sL41aefSQDZ+WesesLRZuNm8uRe+4gMn3FiCM/MDQ= 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 1565362778759186.22983023217307; Fri, 9 Aug 2019 07:59:38 -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 1hw6MA-0006sH-Jh; Fri, 09 Aug 2019 14:59:02 +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 1hw6M1-0006Zs-5C for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:53 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 30b54280-bab6-11e9-a115-7fe23f49e647; Fri, 09 Aug 2019 14:58:48 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2D5E1B0BE; Fri, 9 Aug 2019 14:58:46 +0000 (UTC) X-Inumbo-ID: 30b54280-bab6-11e9-a115-7fe23f49e647 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:09 +0200 Message-Id: <20190809145833.1020-25-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 24/48] xen: switch from for_each_vcpu() to for_each_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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli 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" Where appropriate switch from for_each_vcpu() to for_each_sched_unit() in order to prepare core scheduling. As it is beneficial once here and for sure in future add a unit_scheduler() helper and let vcpu_scheduler() use it. Signed-off-by: Juergen Gross --- V2: - handle affinity_broken correctly (Jan Beulich) - add unit_scheduler() (Jan Beulich) --- xen/common/domain.c | 9 ++- xen/common/schedule.c | 148 ++++++++++++++++++++++++++++++----------------= ---- 2 files changed, 93 insertions(+), 64 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 19d881b0c3..91b01c220e 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -550,7 +550,7 @@ void domain_update_node_affinity(struct domain *d) cpumask_var_t dom_cpumask, dom_cpumask_soft; cpumask_t *dom_affinity; const cpumask_t *online; - struct vcpu *v; + struct sched_unit *unit; unsigned int cpu; =20 /* Do we have vcpus already? If not, no need to update node-affinity. = */ @@ -583,12 +583,11 @@ void domain_update_node_affinity(struct domain *d) * and the full mask of where it would prefer to run (the union of * the soft affinity of all its various vcpus). Let's build them. */ - for_each_vcpu ( d, v ) + for_each_sched_unit ( d, unit ) { - cpumask_or(dom_cpumask, dom_cpumask, - v->sched_unit->cpu_hard_affinity); + cpumask_or(dom_cpumask, dom_cpumask, unit->cpu_hard_affinity); cpumask_or(dom_cpumask_soft, dom_cpumask_soft, - v->sched_unit->cpu_soft_affinity); + unit->cpu_soft_affinity); } /* Filter out non-online cpus */ cpumask_and(dom_cpumask, dom_cpumask, online); diff --git a/xen/common/schedule.c b/xen/common/schedule.c index fcd083d31d..7b0ff8395e 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -147,26 +147,32 @@ static inline struct scheduler *dom_scheduler(const s= truct domain *d) return &ops; } =20 -static inline struct scheduler *vcpu_scheduler(const struct vcpu *v) +static inline struct scheduler *unit_scheduler(const struct sched_unit *un= it) { - struct domain *d =3D v->domain; + struct domain *d =3D unit->domain; =20 if ( likely(d->cpupool !=3D NULL) ) return d->cpupool->sched; =20 /* - * If d->cpupool is NULL, this is a vCPU of the idle domain. And this + * If d->cpupool is NULL, this is a unit of the idle domain. And this * case is special because the idle domain does not really belong to * a cpupool and, hence, doesn't really have a scheduler). In fact, its - * vCPUs (may) run on pCPUs which are in different pools, with differe= nt + * units (may) run on pCPUs which are in different pools, with differe= nt * schedulers. * * What we want, in this case, is the scheduler of the pCPU where this - * particular idle vCPU is running. And, since v->processor never chan= ges - * for idle vCPUs, it is safe to use it, with no locks, to figure that= out. + * particular idle unit is running. And, since unit->res never changes + * for idle units, it is safe to use it, with no locks, to figure that= out. */ + ASSERT(is_idle_domain(d)); - return per_cpu(scheduler, v->processor); + return per_cpu(scheduler, unit->res->processor); +} + +static inline struct scheduler *vcpu_scheduler(const struct vcpu *v) +{ + return unit_scheduler(v->sched_unit); } #define VCPU2ONLINE(_v) cpupool_domain_cpumask((_v)->domain) =20 @@ -487,10 +493,11 @@ static void sched_move_irqs(struct sched_unit *unit) int sched_move_domain(struct domain *d, struct cpupool *c) { struct vcpu *v; + struct sched_unit *unit; unsigned int new_p; - void **vcpu_priv; + void **unit_priv; void *domdata; - void *vcpudata; + void *unitdata; struct scheduler *old_ops; void *old_domdata; =20 @@ -504,22 +511,21 @@ int sched_move_domain(struct domain *d, struct cpupoo= l *c) if ( IS_ERR(domdata) ) return PTR_ERR(domdata); =20 - vcpu_priv =3D xzalloc_array(void *, d->max_vcpus); - if ( vcpu_priv =3D=3D NULL ) + unit_priv =3D xzalloc_array(void *, d->max_vcpus); + if ( unit_priv =3D=3D NULL ) { sched_free_domdata(c->sched, domdata); return -ENOMEM; } =20 - for_each_vcpu ( d, v ) + for_each_sched_unit ( d, unit ) { - vcpu_priv[v->vcpu_id] =3D sched_alloc_vdata(c->sched, v->sched_uni= t, - domdata); - if ( vcpu_priv[v->vcpu_id] =3D=3D NULL ) + unit_priv[unit->unit_id] =3D sched_alloc_vdata(c->sched, unit, dom= data); + if ( unit_priv[unit->unit_id] =3D=3D NULL ) { - for_each_vcpu ( d, v ) - xfree(vcpu_priv[v->vcpu_id]); - xfree(vcpu_priv); + for_each_sched_unit ( d, unit ) + xfree(unit_priv[unit->unit_id]); + xfree(unit_priv); sched_free_domdata(c->sched, domdata); return -ENOMEM; } @@ -530,30 +536,35 @@ int sched_move_domain(struct domain *d, struct cpupoo= l *c) old_ops =3D dom_scheduler(d); old_domdata =3D d->sched_priv; =20 - for_each_vcpu ( d, v ) + for_each_sched_unit ( d, unit ) { - sched_remove_unit(old_ops, v->sched_unit); + sched_remove_unit(old_ops, unit); } =20 d->cpupool =3D c; d->sched_priv =3D domdata; =20 new_p =3D cpumask_first(c->cpu_valid); - for_each_vcpu ( d, v ) + for_each_sched_unit ( d, unit ) { spinlock_t *lock; + unsigned int unit_p =3D new_p; =20 - vcpudata =3D v->sched_unit->priv; + unitdata =3D unit->priv; =20 - migrate_timer(&v->periodic_timer, new_p); - migrate_timer(&v->singleshot_timer, new_p); - migrate_timer(&v->poll_timer, new_p); + for_each_sched_unit_vcpu ( unit, v ) + { + migrate_timer(&v->periodic_timer, new_p); + migrate_timer(&v->singleshot_timer, new_p); + migrate_timer(&v->poll_timer, new_p); + new_p =3D cpumask_cycle(new_p, c->cpu_valid); + } =20 - lock =3D unit_schedule_lock_irq(v->sched_unit); + lock =3D unit_schedule_lock_irq(unit); =20 - sched_set_affinity(v, &cpumask_all, &cpumask_all); + sched_set_affinity(unit->vcpu_list, &cpumask_all, &cpumask_all); =20 - sched_set_res(v->sched_unit, get_sched_res(new_p)); + sched_set_res(unit, get_sched_res(unit_p)); /* * With v->processor modified we must not * - make any further changes assuming we hold the scheduler lock, @@ -561,15 +572,13 @@ int sched_move_domain(struct domain *d, struct cpupoo= l *c) */ spin_unlock_irq(lock); =20 - v->sched_unit->priv =3D vcpu_priv[v->vcpu_id]; + unit->priv =3D unit_priv[unit->unit_id]; if ( !d->is_dying ) - sched_move_irqs(v->sched_unit); - - new_p =3D cpumask_cycle(new_p, c->cpu_valid); + sched_move_irqs(unit); =20 - sched_insert_unit(c->sched, v->sched_unit); + sched_insert_unit(c->sched, unit); =20 - sched_free_vdata(old_ops, vcpudata); + sched_free_vdata(old_ops, unitdata); } =20 domain_update_node_affinity(d); @@ -578,7 +587,7 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) =20 sched_free_domdata(old_ops, old_domdata); =20 - xfree(vcpu_priv); + xfree(unit_priv); =20 return 0; } @@ -880,18 +889,36 @@ void vcpu_force_reschedule(struct vcpu *v) vcpu_migrate_finish(v); } =20 +static bool sched_check_affinity_broken(struct sched_unit *unit) +{ + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + if ( v->affinity_broken ) + return true; + + return false; +} + +static void sched_reset_affinity_broken(struct sched_unit *unit) +{ + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + v->affinity_broken =3D false; +} + void restore_vcpu_affinity(struct domain *d) { unsigned int cpu =3D smp_processor_id(); - struct vcpu *v; + struct sched_unit *unit; =20 ASSERT(system_state =3D=3D SYS_STATE_resume); =20 - for_each_vcpu ( d, v ) + for_each_sched_unit ( d, unit ) { spinlock_t *lock; - unsigned int old_cpu =3D v->processor; - struct sched_unit *unit =3D v->sched_unit; + unsigned int old_cpu =3D sched_unit_cpu(unit); struct sched_resource *res; =20 ASSERT(!unit_runnable(unit)); @@ -910,18 +937,20 @@ void restore_vcpu_affinity(struct domain *d) cpupool_domain_cpumask(d)); if ( cpumask_empty(cpumask_scratch_cpu(cpu)) ) { - if ( v->affinity_broken ) + if ( sched_check_affinity_broken(unit) ) { - sched_set_affinity(v, unit->cpu_hard_affinity_saved, NULL); - v->affinity_broken =3D 0; + sched_set_affinity(unit->vcpu_list, + unit->cpu_hard_affinity_saved, NULL); + sched_reset_affinity_broken(unit); cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affin= ity, cpupool_domain_cpumask(d)); } =20 if ( cpumask_empty(cpumask_scratch_cpu(cpu)) ) { - printk(XENLOG_DEBUG "Breaking affinity for %pv\n", v); - sched_set_affinity(v, &cpumask_all, NULL); + printk(XENLOG_DEBUG "Breaking affinity for %pv\n", + unit->vcpu_list); + sched_set_affinity(unit->vcpu_list, &cpumask_all, NULL); cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affin= ity, cpupool_domain_cpumask(d)); } @@ -934,12 +963,12 @@ void restore_vcpu_affinity(struct domain *d) =20 /* v->processor might have changed, so reacquire the lock. */ lock =3D unit_schedule_lock_irq(unit); - res =3D sched_pick_resource(vcpu_scheduler(v), unit); + res =3D sched_pick_resource(unit_scheduler(unit), unit); sched_set_res(unit, res); spin_unlock_irq(lock); =20 - if ( old_cpu !=3D v->processor ) - sched_move_irqs(v->sched_unit); + if ( old_cpu !=3D sched_unit_cpu(unit) ) + sched_move_irqs(unit); } =20 domain_update_node_affinity(d); @@ -953,7 +982,6 @@ void restore_vcpu_affinity(struct domain *d) int cpu_disable_scheduler(unsigned int cpu) { struct domain *d; - struct vcpu *v; struct cpupool *c; cpumask_t online_affinity; int ret =3D 0; @@ -964,17 +992,18 @@ int cpu_disable_scheduler(unsigned int cpu) =20 for_each_domain_in_cpupool ( d, c ) { - for_each_vcpu ( d, v ) + struct sched_unit *unit; + + for_each_sched_unit ( d, unit ) { unsigned long flags; - struct sched_unit *unit =3D v->sched_unit; spinlock_t *lock =3D unit_schedule_lock_irqsave(unit, &flags); =20 cpumask_and(&online_affinity, unit->cpu_hard_affinity, c->cpu_= valid); if ( cpumask_empty(&online_affinity) && cpumask_test_cpu(cpu, unit->cpu_hard_affinity) ) { - if ( v->affinity_broken ) + if ( unit->vcpu_list->affinity_broken ) { /* The vcpu is temporarily pinned, can't move it. */ unit_schedule_unlock_irqrestore(lock, flags, unit); @@ -982,14 +1011,15 @@ int cpu_disable_scheduler(unsigned int cpu) break; } =20 - printk(XENLOG_DEBUG "Breaking affinity for %pv\n", v); + printk(XENLOG_DEBUG "Breaking affinity for %pv\n", + unit->vcpu_list); =20 - sched_set_affinity(v, &cpumask_all, NULL); + sched_set_affinity(unit->vcpu_list, &cpumask_all, NULL); } =20 - if ( v->processor !=3D cpu ) + if ( sched_unit_cpu(unit) !=3D sched_get_resource_cpu(cpu) ) { - /* The vcpu is not on this cpu, so we can move on. */ + /* The unit is not on this cpu, so we can move on. */ unit_schedule_unlock_irqrestore(lock, flags, unit); continue; } @@ -1002,17 +1032,17 @@ int cpu_disable_scheduler(unsigned int cpu) * * the scheduler will always find a suitable solution, or * things would have failed before getting in here. */ - vcpu_migrate_start(v); + vcpu_migrate_start(unit->vcpu_list); unit_schedule_unlock_irqrestore(lock, flags, unit); =20 - vcpu_migrate_finish(v); + vcpu_migrate_finish(unit->vcpu_list); =20 /* * The only caveat, in this case, is that if a vcpu active in * the hypervisor isn't migratable. In this case, the caller * should try again after releasing and reaquiring all locks. */ - if ( v->processor =3D=3D cpu ) + if ( sched_unit_cpu(unit) =3D=3D sched_get_resource_cpu(cpu) ) ret =3D -EAGAIN; } } @@ -1023,8 +1053,8 @@ int cpu_disable_scheduler(unsigned int cpu) static int cpu_disable_scheduler_check(unsigned int cpu) { struct domain *d; - struct vcpu *v; struct cpupool *c; + struct vcpu *v; =20 c =3D per_cpu(cpupool, cpu); if ( c =3D=3D NULL ) --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362774; cv=none; d=zoho.com; s=zohoarc; b=B7NjoA6D3JdXTmXyHgw3VlD6pxDgiG2gHhMZmWp7Urkod3ZjFvjCcMptIIixiP4wyGMQHfIbVKEIr+wEbraTizEOxC2U0dX0XamHngylCwfvwWbL0QWaHqE224V7vDbXqBvrwdbFIiwoAoiXXtKL0DIUnmvJX87pweYvnAT/Jhg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362774; 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=hZvmKiaoWd9obBgTAgCjiga5PW0xuleBeiA3Ew4d6og=; b=hETbLZDksX4H0+8c6jQun2XM04nBJaBtuIwioN3XBVqq0pO+aRL0PNhll1xZBKq4SWKkfyyB0lpwX5kptifs9mXbgvubrJFszbvjfHNsRsUjEhKAaqk2LGMBNR4DKhWoAS+JG1LFZlWqNHqWWWs/9UJ3kxPf/dtH27Fi3KNVMC0= 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 1565362774365377.52573663209523; Fri, 9 Aug 2019 07:59:34 -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 1hw6M5-0006hB-6u; Fri, 09 Aug 2019 14:58:57 +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 1hw6Lz-0006XD-Sv for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:51 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 30beabfe-bab6-11e9-bdfd-ebfd36c8b797; Fri, 09 Aug 2019 14:58:48 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 92DD7B0CC; Fri, 9 Aug 2019 14:58:46 +0000 (UTC) X-Inumbo-ID: 30beabfe-bab6-11e9-bdfd-ebfd36c8b797 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:10 +0200 Message-Id: <20190809145833.1020-26-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 25/48] xen/sched: add runstate counters to 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" Add counters to struct sched_unit summing up runstates of associated vcpus. Signed-off-by: Juergen Gross --- RFC V2: add counters for each possible runstate --- xen/common/schedule.c | 5 +++++ xen/include/xen/sched.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 7b0ff8395e..3f8fffc329 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -236,6 +236,7 @@ static inline void vcpu_runstate_change( struct vcpu *v, int new_state, s_time_t new_entry_time) { s_time_t delta; + struct sched_unit *unit =3D v->sched_unit; =20 ASSERT(v->runstate.state !=3D new_state); ASSERT(spin_is_locked(get_sched_res(v->processor)->schedule_lock)); @@ -244,6 +245,9 @@ static inline void vcpu_runstate_change( =20 trace_runstate_change(v, new_state); =20 + unit->runstate_cnt[v->runstate.state]--; + unit->runstate_cnt[new_state]++; + delta =3D new_entry_time - v->runstate.state_entry_time; if ( delta > 0 ) { @@ -366,6 +370,7 @@ static struct sched_unit *sched_alloc_unit(struct vcpu = *v) unit->vcpu_list =3D v; unit->unit_id =3D v->vcpu_id; unit->domain =3D d; + unit->runstate_cnt[v->runstate.state]++; =20 for ( prev_unit =3D &d->sched_unit_list; *prev_unit; prev_unit =3D &(*prev_unit)->next_in_list ) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index f639b164b5..0cece3b921 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -274,6 +274,8 @@ struct sched_unit { =20 /* Last time unit got (de-)scheduled. */ uint64_t state_entry_time; + /* Vcpu state summary. */ + unsigned int runstate_cnt[4]; =20 /* Currently running on a CPU? */ bool is_running; --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362785; cv=none; d=zoho.com; s=zohoarc; b=OR4tFYut1ji5RkEVSD7jwZFBiFKNZ2MjVk03cav2n4MkPD1Z02CU5+PXWr3fAqtTCZZTrNTRkfMY5nlxIha26ZSQgjufqUwB+CmIRECDl+J6lpQYIkk8v/0ZPMPdxT74hbnrwf55LUVxyqc8NYQj1xqjD3AqpyB6bFfSXDc98Lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362785; 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=kiMlfv/wMwvWbGN9QGawV1uhdKAUu3qKO5aen6YZkxg=; b=d8HopgaCV4EpHXjBEsrIM4bYT2/L435eu4F+u1jjBhbbNe22VEjBJdfoknwkmiByMZVR6/VucqnMq5HDjA7nOKJ+UaSEG9hBHcBdNhOqkJOK9gsFqLEhnoYNdb6c8/QTBjnvebhFJ+9piaHESQmNp11RsGVvtNGN2zMtgkWyM4o= 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 1565362785814635.1086925372367; Fri, 9 Aug 2019 07:59:45 -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 1hw6MD-0006zU-K1; Fri, 09 Aug 2019 14:59:05 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M1-0006b6-Ve for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:54 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 30c52eff-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:48 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0BA97B0E5; Fri, 9 Aug 2019 14:58:47 +0000 (UTC) X-Inumbo-ID: 30c52eff-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:11 +0200 Message-Id: <20190809145833.1020-27-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 26/48] xen/sched: rework and rename vcpu_force_reschedule() 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= 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" vcpu_force_reschedule() is only used for modifying the periodic timer of a vcpu. Forcing a vcpu to give up the physical cpu for that purpose is kind of brutal. So instead of doing the reschedule dance just operate on the timer directly. In case we are modifying the timer of the currently running vcpu we can just do that. In case it is for a foreign vcpu we should pause it for that purpose like we do for all other vcpu state modifications. Rename the function to vcpu_set_periodic_timer() as this now reflects the functionality. Signed-off-by: Juergen Gross --- V1: latch NOW() only after stopping the timer (Jan Beulich) --- xen/arch/x86/pv/shim.c | 4 +--- xen/common/domain.c | 6 ++---- xen/common/schedule.c | 24 ++++++++++++++---------- xen/include/xen/sched.h | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index 324ca27f93..5edbcd9ac5 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -410,7 +410,7 @@ int pv_shim_shutdown(uint8_t reason) unmap_vcpu_info(v); =20 /* Reset the periodic timer to the default value. */ - v->periodic_period =3D MILLISECS(10); + vcpu_set_periodic_timer(v, MILLISECS(10)); /* Stop the singleshot timer. */ stop_timer(&v->singleshot_timer); =20 @@ -419,8 +419,6 @@ int pv_shim_shutdown(uint8_t reason) =20 if ( v !=3D current ) vcpu_unpause_by_systemcontroller(v); - else - vcpu_force_reschedule(v); } =20 return 0; diff --git a/xen/common/domain.c b/xen/common/domain.c index 91b01c220e..863b7cae35 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1479,15 +1479,13 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_G= UEST_HANDLE_PARAM(void) arg) if ( set.period_ns > STIME_DELTA_MAX ) return -EINVAL; =20 - v->periodic_period =3D set.period_ns; - vcpu_force_reschedule(v); + vcpu_set_periodic_timer(v, set.period_ns); =20 break; } =20 case VCPUOP_stop_periodic_timer: - v->periodic_period =3D 0; - vcpu_force_reschedule(v); + vcpu_set_periodic_timer(v, 0); break; =20 case VCPUOP_set_singleshot_timer: diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 3f8fffc329..4c488ddde0 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -877,21 +877,25 @@ static void vcpu_migrate_finish(struct vcpu *v) } =20 /* - * Force a VCPU through a deschedule/reschedule path. - * For example, using this when setting the periodic timer period means th= at - * most periodic-timer state need only be touched from within the scheduler - * which can thus be done without need for synchronisation. + * Set the periodic timer of a vcpu. */ -void vcpu_force_reschedule(struct vcpu *v) +void vcpu_set_periodic_timer(struct vcpu *v, s_time_t value) { - spinlock_t *lock =3D unit_schedule_lock_irq(v->sched_unit); + s_time_t now; =20 - if ( v->sched_unit->is_running ) - vcpu_migrate_start(v); + if ( v !=3D current ) + vcpu_pause(v); + else + stop_timer(&v->periodic_timer); =20 - unit_schedule_unlock_irq(lock, v->sched_unit); + now =3D NOW(); + v->periodic_period =3D value; + v->periodic_last_event =3D now; =20 - vcpu_migrate_finish(v); + if ( v !=3D current ) + vcpu_unpause(v); + else if ( value !=3D 0 ) + set_timer(&v->periodic_timer, now + value); } =20 static bool sched_check_affinity_broken(struct sched_unit *unit) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 0cece3b921..7f84b823cb 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -896,7 +896,7 @@ struct scheduler *scheduler_get_default(void); struct scheduler *scheduler_alloc(unsigned int sched_id, int *perr); void scheduler_free(struct scheduler *sched); int schedule_cpu_switch(unsigned int cpu, struct cpupool *c); -void vcpu_force_reschedule(struct vcpu *v); +void vcpu_set_periodic_timer(struct vcpu *v, s_time_t value); int cpu_disable_scheduler(unsigned int cpu); /* We need it in dom0_setup_vcpu */ void sched_set_affinity(struct vcpu *v, const cpumask_t *hard, --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362796; cv=none; d=zoho.com; s=zohoarc; b=Yqgbtmf1QL5uIFOg4GP5wMxd2FfXuA4xJXt71hXAriB7dIyBXmXJSHp0oQXCWKuvgHzC0/EzMRaZT7Ph5Eabq/6T266cJsAGYNJGjlvHoMnVS3FdU/pBtTxhGKIH++TNEkbkW0o/BzEtoHRYuahXJ1hggAwoRTI5If5KMIptemY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362796; 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=w3/f+xXR9GYnkKJGL2nTOiaFnQq/AmfFPywEQ6HWEb0=; b=KkX1lAitimF3N1Ub6OsDMtK7OO0S5kWejUSAfZklDNZETJnJInII2ODvXHZ+gXef1ALkcDzIUrx7Et99IFP3pIiuoYaiTBO3IUmMK5uqXFnICMhT6JlR+DA45W4bcB0CPm7zrG+WBQAOiwsSAhs1vAbH1pQ8uShPAR/2tj2gLUc= 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 1565362796429152.52825892006217; Fri, 9 Aug 2019 07:59:56 -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 1hw6MJ-0007D0-Jc; Fri, 09 Aug 2019 14:59:11 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M3-0006dj-Et for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:55 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 3145821f-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3218EB0E6; Fri, 9 Aug 2019 14:58:47 +0000 (UTC) X-Inumbo-ID: 3145821f-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:12 +0200 Message-Id: <20190809145833.1020-28-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 27/48] xen/sched: Change vcpu_migrate_*() to operate on schedule 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 , George Dunlap , Dario Faggioli 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" Now that vcpu_migrate_start() and vcpu_migrate_finish() are used only to ensure a vcpu is running on a suitable processor they can be switched to operate on schedule units instead of vcpus. While doing that rename them accordingly and make the _start() variant static. As it is needed anyway call vcpu_sync_execstate() for each vcpu of the unit when changing processors. vcpu_move_locked() is switched to schedule unit, too. Signed-off-by: Juergen Gross --- xen/common/schedule.c | 106 ++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 63 insertions(+), 43 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 4c488ddde0..e4d0dd4b65 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -733,35 +733,40 @@ void vcpu_unblock(struct vcpu *v) } =20 /* - * Do the actual movement of a vcpu from old to new CPU. Locks for *both* + * Do the actual movement of an unit from old to new CPU. Locks for *both* * CPUs needs to have been taken already when calling this! */ -static void vcpu_move_locked(struct vcpu *v, unsigned int new_cpu) +static void sched_unit_move_locked(struct sched_unit *unit, + unsigned int new_cpu) { - unsigned int old_cpu =3D v->processor; + unsigned int old_cpu =3D unit->res->processor; + struct vcpu *v; =20 /* * Transfer urgency status to new CPU before switching CPUs, as * once the switch occurs, v->is_urgent is no longer protected by * the per-CPU scheduler lock we are holding. */ - if ( unlikely(v->is_urgent) && (old_cpu !=3D new_cpu) ) + for_each_sched_unit_vcpu ( unit, v ) { - atomic_inc(&get_sched_res(new_cpu)->urgent_count); - atomic_dec(&get_sched_res(old_cpu)->urgent_count); + if ( unlikely(v->is_urgent) && (old_cpu !=3D new_cpu) ) + { + atomic_inc(&get_sched_res(new_cpu)->urgent_count); + atomic_dec(&get_sched_res(old_cpu)->urgent_count); + } } =20 /* * Actual CPU switch to new CPU. This is safe because the lock * pointer can't change while the current lock is held. */ - sched_migrate(vcpu_scheduler(v), v->sched_unit, new_cpu); + sched_migrate(unit_scheduler(unit), unit, new_cpu); } =20 /* * Initiating migration * - * In order to migrate, we need the vcpu in question to have stopped + * In order to migrate, we need the unit in question to have stopped * running and had sched_sleep() called (to take it off any * runqueues, for instance); and if it is currently running, it needs * to be scheduled out. Finally, we need to hold the scheduling locks @@ -777,37 +782,45 @@ static void vcpu_move_locked(struct vcpu *v, unsigned= int new_cpu) * should be called like this: * * lock =3D unit_schedule_lock_irq(unit); - * vcpu_migrate_start(v); + * sched_unit_migrate_start(unit); * unit_schedule_unlock_irq(lock, unit) - * vcpu_migrate_finish(v); + * sched_unit_migrate_finish(unit); * - * vcpu_migrate_finish() will do the work now if it can, or simply - * return if it can't (because v is still running); in that case - * vcpu_migrate_finish() will be called by context_saved(). + * sched_unit_migrate_finish() will do the work now if it can, or simply + * return if it can't (because unit is still running); in that case + * sched_unit_migrate_finish() will be called by context_saved(). */ -static void vcpu_migrate_start(struct vcpu *v) +static void sched_unit_migrate_start(struct sched_unit *unit) { - set_bit(_VPF_migrating, &v->pause_flags); - vcpu_sleep_nosync_locked(v); + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + { + set_bit(_VPF_migrating, &v->pause_flags); + vcpu_sleep_nosync_locked(v); + } } =20 -static void vcpu_migrate_finish(struct vcpu *v) +static void sched_unit_migrate_finish(struct sched_unit *unit) { unsigned long flags; unsigned int old_cpu, new_cpu; spinlock_t *old_lock, *new_lock; bool_t pick_called =3D 0; + struct vcpu *v; =20 /* - * If the vcpu is currently running, this will be handled by + * If the unit is currently running, this will be handled by * context_saved(); and in any case, if the bit is cleared, then * someone else has already done the work so we don't need to. */ - if ( v->sched_unit->is_running || - !test_bit(_VPF_migrating, &v->pause_flags) ) - return; + for_each_sched_unit_vcpu ( unit, v ) + { + if ( unit->is_running || !test_bit(_VPF_migrating, &v->pause_flags= ) ) + return; + } =20 - old_cpu =3D new_cpu =3D v->processor; + old_cpu =3D new_cpu =3D unit->res->processor; for ( ; ; ) { /* @@ -820,7 +833,7 @@ static void vcpu_migrate_finish(struct vcpu *v) =20 sched_spin_lock_double(old_lock, new_lock, &flags); =20 - old_cpu =3D v->processor; + old_cpu =3D unit->res->processor; if ( old_lock =3D=3D get_sched_res(old_cpu)->schedule_lock ) { /* @@ -829,15 +842,15 @@ static void vcpu_migrate_finish(struct vcpu *v) */ if ( pick_called && (new_lock =3D=3D get_sched_res(new_cpu)->schedule_lock) && - cpumask_test_cpu(new_cpu, v->sched_unit->cpu_hard_affinit= y) && - cpumask_test_cpu(new_cpu, v->domain->cpupool->cpu_valid) ) + cpumask_test_cpu(new_cpu, unit->cpu_hard_affinity) && + cpumask_test_cpu(new_cpu, unit->domain->cpupool->cpu_vali= d) ) break; =20 /* Select a new CPU. */ - new_cpu =3D sched_pick_resource(vcpu_scheduler(v), - v->sched_unit)->processor; + new_cpu =3D sched_pick_resource(unit_scheduler(unit), + unit)->processor; if ( (new_lock =3D=3D get_sched_res(new_cpu)->schedule_lock) && - cpumask_test_cpu(new_cpu, v->domain->cpupool->cpu_valid) ) + cpumask_test_cpu(new_cpu, unit->domain->cpupool->cpu_vali= d) ) break; pick_called =3D 1; } @@ -858,22 +871,30 @@ static void vcpu_migrate_finish(struct vcpu *v) * because they both happen in (different) spinlock regions, and those * regions are strictly serialised. */ - if ( v->sched_unit->is_running || - !test_and_clear_bit(_VPF_migrating, &v->pause_flags) ) + for_each_sched_unit_vcpu ( unit, v ) { - sched_spin_unlock_double(old_lock, new_lock, flags); - return; + if ( unit->is_running || + !test_and_clear_bit(_VPF_migrating, &v->pause_flags) ) + { + sched_spin_unlock_double(old_lock, new_lock, flags); + return; + } } =20 - vcpu_move_locked(v, new_cpu); + sched_unit_move_locked(unit, new_cpu); =20 sched_spin_unlock_double(old_lock, new_lock, flags); =20 if ( old_cpu !=3D new_cpu ) - sched_move_irqs(v->sched_unit); + { + for_each_sched_unit_vcpu ( unit, v ) + sync_vcpu_execstate(v); + sched_move_irqs(unit); + } =20 /* Wake on new CPU. */ - vcpu_wake(v); + for_each_sched_unit_vcpu ( unit, v ) + vcpu_wake(v); } =20 /* @@ -1041,10 +1062,9 @@ int cpu_disable_scheduler(unsigned int cpu) * * the scheduler will always find a suitable solution, or * things would have failed before getting in here. */ - vcpu_migrate_start(unit->vcpu_list); + sched_unit_migrate_start(unit); unit_schedule_unlock_irqrestore(lock, flags, unit); - - vcpu_migrate_finish(unit->vcpu_list); + sched_unit_migrate_finish(unit); =20 /* * The only caveat, in this case, is that if a vcpu active in @@ -1128,14 +1148,14 @@ static int vcpu_set_affinity( ASSERT(which =3D=3D unit->cpu_soft_affinity); sched_set_affinity(v, NULL, affinity); } - vcpu_migrate_start(v); + sched_unit_migrate_start(unit); } =20 unit_schedule_unlock_irq(lock, unit); =20 domain_update_node_affinity(v->domain); =20 - vcpu_migrate_finish(v); + sched_unit_migrate_finish(unit); =20 return ret; } @@ -1396,12 +1416,12 @@ int vcpu_temporary_affinity(struct vcpu *v, unsigne= d int cpu, uint8_t reason) =20 migrate =3D !ret && !cpumask_test_cpu(v->processor, unit->cpu_hard_aff= inity); if ( migrate ) - vcpu_migrate_start(v); + sched_unit_migrate_start(unit); =20 unit_schedule_unlock_irq(lock, unit); =20 if ( migrate ) - vcpu_migrate_finish(v); + sched_unit_migrate_finish(unit); =20 return ret; } @@ -1794,7 +1814,7 @@ void context_saved(struct vcpu *prev) =20 sched_context_saved(vcpu_scheduler(prev), prev->sched_unit); =20 - vcpu_migrate_finish(prev); + sched_unit_migrate_finish(prev->sched_unit); } =20 /* The scheduler timer: force a run through the scheduler */ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362792; cv=none; d=zoho.com; s=zohoarc; b=Q7PCgpdR8KG2pLTWAiWZqGh7s7+VVmcbRtlumNvcQfYGeIu0rsft7s9W2PC4L6b+Q8ZyzbATrLA5ajbNRrjHIasxAoUMdQeKDz8KIeRlKxEdL5a8Mu9Mxn65CJ/pQ95DT8+eEBrW279v1F1elnIaNiftu98KG5qD+0G1jNhqW5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362792; 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=zyXpImAxA+r78GrOWTJHlb0Hcj9tnn671HE3ZrsY9jk=; b=f6+fM31LHtuDYXEQ2Fu5Xx7C/RpA2zMVsTiOn2XJ76ptvfkwaVoXZo9CAzf4G6yZdGq3KGIzJRU/ZXiKrtQ8IhJIEZMffHCzhhAKes7Pqhwnk/4PM8UbZRF8QlCbUHovo0ECWYPpIMJQ5paooC6XGhZSsHf0fbDDexGkQ5vVUYM= 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 1565362792680358.12677323093203; Fri, 9 Aug 2019 07:59:52 -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 1hw6ML-0007Hy-Nf; Fri, 09 Aug 2019 14:59:13 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M3-0006eU-R9 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:55 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 3147b20c-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AEA26AF38; Fri, 9 Aug 2019 14:58:47 +0000 (UTC) X-Inumbo-ID: 3147b20c-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:13 +0200 Message-Id: <20190809145833.1020-29-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 28/48] xen/sched: move struct task_slice into 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 , Robert VanVossen , Dario Faggioli , Julien Grall , Josh Whitehead , Meng Xu , 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 prepare for multiple vcpus per schedule unit move struct task_slice in schedule() from the local stack into struct sched_unit of the currently running unit. To make access easier for the single schedulers add the pointer of the currently running unit as a parameter of do_schedule(). While at it switch the tasklet_work_scheduled parameter of do_schedule() from bool_t to bool. As struct task_slice is only ever modified with the local schedule lock held it is safe to directly set the different units in struct sched_unit instead of using an on-stack copy for returning the data. Signed-off-by: Juergen Gross --- xen/common/sched_arinc653.c | 20 +++++++------------- xen/common/sched_credit.c | 25 +++++++++++-------------- xen/common/sched_credit2.c | 21 +++++++++------------ xen/common/sched_null.c | 29 ++++++++++++++--------------- xen/common/sched_rt.c | 22 +++++++++++----------- xen/common/schedule.c | 32 ++++++++++++++------------------ xen/include/xen/sched-if.h | 11 +++-------- xen/include/xen/sched.h | 6 ++++++ 8 files changed, 75 insertions(+), 91 deletions(-) diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c index e48f2b2eb9..34efcc07c9 100644 --- a/xen/common/sched_arinc653.c +++ b/xen/common/sched_arinc653.c @@ -497,18 +497,14 @@ a653sched_unit_wake(const struct scheduler *ops, stru= ct sched_unit *unit) * * @param ops Pointer to this instance of the scheduler structure * @param now Current time - * - * @return Address of the UNIT structure scheduled to be run next - * Amount of time to execute the returned UNIT - * Flag for whether the UNIT was migrated */ -static struct task_slice +static void a653sched_do_schedule( const struct scheduler *ops, + struct sched_unit *prev, s_time_t now, - bool_t tasklet_work_scheduled) + bool tasklet_work_scheduled) { - struct task_slice ret; /* hold the chosen domain = */ struct sched_unit *new_task =3D NULL; static unsigned int sched_index =3D 0; static s_time_t next_switch_time; @@ -586,13 +582,11 @@ a653sched_do_schedule( * Return the amount of time the next domain has to run and the address * of the selected task's UNIT structure. */ - ret.time =3D next_switch_time - now; - ret.task =3D new_task; - ret.migrated =3D 0; - - BUG_ON(ret.time <=3D 0); + prev->next_time =3D next_switch_time - now; + prev->next_task =3D new_task; + new_task->migrated =3D false; =20 - return ret; + BUG_ON(prev->next_time <=3D 0); } =20 /** diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 87cb62c632..f1675fd52e 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1675,7 +1675,7 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, int= balance_step) =20 static struct csched_unit * csched_load_balance(struct csched_private *prv, int cpu, - struct csched_unit *snext, bool_t *stolen) + struct csched_unit *snext, bool *stolen) { struct cpupool *c =3D per_cpu(cpupool, cpu); struct csched_unit *speer; @@ -1791,7 +1791,7 @@ csched_load_balance(struct csched_private *prv, int c= pu, /* As soon as one unit is found, balancing ends */ if ( speer !=3D NULL ) { - *stolen =3D 1; + *stolen =3D true; /* * Next time we'll look for work to steal on this node= , we * will start from the next pCPU, with respect to this= one, @@ -1821,19 +1821,18 @@ csched_load_balance(struct csched_private *prv, int= cpu, * This function is in the critical path. It is designed to be simple and * fast for the common case. */ -static struct task_slice -csched_schedule( - const struct scheduler *ops, s_time_t now, bool_t tasklet_work_schedul= ed) +static void csched_schedule( + const struct scheduler *ops, struct sched_unit *unit, s_time_t now, + bool tasklet_work_scheduled) { const unsigned int cpu =3D smp_processor_id(); const unsigned int sched_cpu =3D sched_get_resource_cpu(cpu); struct list_head * const runq =3D RUNQ(sched_cpu); - struct sched_unit *unit =3D current->sched_unit; struct csched_unit * const scurr =3D CSCHED_UNIT(unit); struct csched_private *prv =3D CSCHED_PRIV(ops); struct csched_unit *snext; - struct task_slice ret; s_time_t runtime, tslice; + bool migrated =3D false; =20 SCHED_STAT_CRANK(schedule); CSCHED_UNIT_CHECK(unit); @@ -1924,7 +1923,6 @@ csched_schedule( (unsigned char *)&d); } =20 - ret.migrated =3D 0; goto out; } tslice =3D prv->tslice; @@ -1942,7 +1940,6 @@ csched_schedule( } =20 snext =3D __runq_elem(runq->next); - ret.migrated =3D 0; =20 /* Tasklet work (which runs in idle UNIT context) overrides all else. = */ if ( tasklet_work_scheduled ) @@ -1968,7 +1965,7 @@ csched_schedule( if ( snext->pri > CSCHED_PRI_TS_OVER ) __runq_remove(snext); else - snext =3D csched_load_balance(prv, sched_cpu, snext, &ret.migrated= ); + snext =3D csched_load_balance(prv, sched_cpu, snext, &migrated); =20 /* * Update idlers mask if necessary. When we're idling, other CPUs @@ -1991,12 +1988,12 @@ out: /* * Return task to run next... */ - ret.time =3D (is_idle_unit(snext->unit) ? + unit->next_time =3D (is_idle_unit(snext->unit) ? -1 : tslice); - ret.task =3D snext->unit; + unit->next_task =3D snext->unit; + snext->unit->migrated =3D migrated; =20 - CSCHED_UNIT_CHECK(ret.task); - return ret; + CSCHED_UNIT_CHECK(unit->next_task); } =20 static void diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 548b87af8b..98ef48d6f4 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -3444,19 +3444,18 @@ runq_candidate(struct csched2_runqueue_data *rqd, * This function is in the critical path. It is designed to be simple and * fast for the common case. */ -static struct task_slice -csched2_schedule( - const struct scheduler *ops, s_time_t now, bool tasklet_work_scheduled) +static void csched2_schedule( + const struct scheduler *ops, struct sched_unit *currunit, s_time_t now, + bool tasklet_work_scheduled) { const unsigned int cpu =3D smp_processor_id(); const unsigned int sched_cpu =3D sched_get_resource_cpu(cpu); struct csched2_runqueue_data *rqd; - struct sched_unit *currunit =3D current->sched_unit; struct csched2_unit * const scurr =3D csched2_unit(currunit); struct csched2_unit *snext =3D NULL; unsigned int skipped_units =3D 0; - struct task_slice ret; bool tickled; + bool migrated =3D false; =20 SCHED_STAT_CRANK(schedule); CSCHED2_UNIT_CHECK(currunit); @@ -3541,8 +3540,6 @@ csched2_schedule( && unit_runnable(currunit) ) __set_bit(__CSFLAG_delayed_runq_add, &scurr->flags); =20 - ret.migrated =3D 0; - /* Accounting for non-idle tasks */ if ( !is_idle_unit(snext->unit) ) { @@ -3592,7 +3589,7 @@ csched2_schedule( snext->credit +=3D CSCHED2_MIGRATE_COMPENSATION; sched_set_res(snext->unit, get_sched_res(sched_cpu)); SCHED_STAT_CRANK(migrated); - ret.migrated =3D 1; + migrated =3D true; } } else @@ -3623,11 +3620,11 @@ csched2_schedule( /* * Return task to run next... */ - ret.time =3D csched2_runtime(ops, sched_cpu, snext, now); - ret.task =3D snext->unit; + currunit->next_time =3D csched2_runtime(ops, sched_cpu, snext, now); + currunit->next_task =3D snext->unit; + snext->unit->migrated =3D migrated; =20 - CSCHED2_UNIT_CHECK(ret.task); - return ret; + CSCHED2_UNIT_CHECK(currunit->next_task); } =20 static void diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index 56ef078c5a..397edcbc83 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -779,16 +779,14 @@ static inline void null_unit_check(struct sched_unit = *unit) * - the unit assigned to the pCPU, if there's one and it can run; * - the idle unit, otherwise. */ -static struct task_slice null_schedule(const struct scheduler *ops, - s_time_t now, - bool_t tasklet_work_scheduled) +static void null_schedule(const struct scheduler *ops, struct sched_unit *= prev, + s_time_t now, bool tasklet_work_scheduled) { unsigned int bs; const unsigned int cpu =3D smp_processor_id(); const unsigned int sched_cpu =3D sched_get_resource_cpu(cpu); struct null_private *prv =3D null_priv(ops); struct null_unit *wvc; - struct task_slice ret; =20 SCHED_STAT_CRANK(schedule); NULL_UNIT_CHECK(current->sched_unit); @@ -816,19 +814,18 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, if ( tasklet_work_scheduled ) { trace_var(TRC_SNULL_TASKLET, 1, 0, NULL); - ret.task =3D sched_idle_unit(sched_cpu); + prev->next_task =3D sched_idle_unit(sched_cpu); } else - ret.task =3D per_cpu(npc, sched_cpu).unit; - ret.migrated =3D 0; - ret.time =3D -1; + prev->next_task =3D per_cpu(npc, sched_cpu).unit; + prev->next_time =3D -1; =20 /* * We may be new in the cpupool, or just coming back online. In which * case, there may be units in the waitqueue that we can assign to us * and run. */ - if ( unlikely(ret.task =3D=3D NULL) ) + if ( unlikely(prev->next_task =3D=3D NULL) ) { spin_lock(&prv->waitq_lock); =20 @@ -854,7 +851,7 @@ static struct task_slice null_schedule(const struct sch= eduler *ops, { unit_assign(prv, wvc->unit, sched_cpu); list_del_init(&wvc->waitq_elem); - ret.task =3D wvc->unit; + prev->next_task =3D wvc->unit; goto unlock; } } @@ -862,15 +859,17 @@ static struct task_slice null_schedule(const struct s= cheduler *ops, unlock: spin_unlock(&prv->waitq_lock); =20 - if ( ret.task =3D=3D NULL && !cpumask_test_cpu(cpu, &prv->cpus_fre= e) ) + if ( prev->next_task =3D=3D NULL && + !cpumask_test_cpu(cpu, &prv->cpus_free) ) cpumask_set_cpu(cpu, &prv->cpus_free); } =20 - if ( unlikely(ret.task =3D=3D NULL || !unit_runnable(ret.task)) ) - ret.task =3D sched_idle_unit(sched_cpu); + if ( unlikely(prev->next_task =3D=3D NULL || !unit_runnable(prev->next= _task)) ) + prev->next_task =3D sched_idle_unit(sched_cpu); =20 - NULL_UNIT_CHECK(ret.task); - return ret; + NULL_UNIT_CHECK(prev->next_task); + + prev->next_task->migrated =3D false; } =20 static inline void dump_unit(struct null_private *prv, struct null_unit *n= vc) diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index 7b9d25f138..fcbfa528f4 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -1054,16 +1054,16 @@ runq_pick(const struct scheduler *ops, const cpumas= k_t *mask) * schedule function for rt scheduler. * The lock is already grabbed in schedule.c, no need to lock here */ -static struct task_slice -rt_schedule(const struct scheduler *ops, s_time_t now, bool_t tasklet_work= _scheduled) +static void +rt_schedule(const struct scheduler *ops, struct sched_unit *currunit, + s_time_t now, bool tasklet_work_scheduled) { const unsigned int cpu =3D smp_processor_id(); const unsigned int sched_cpu =3D sched_get_resource_cpu(cpu); struct rt_private *prv =3D rt_priv(ops); - struct rt_unit *const scurr =3D rt_unit(current->sched_unit); + struct rt_unit *const scurr =3D rt_unit(currunit); struct rt_unit *snext =3D NULL; - struct task_slice ret =3D { .migrated =3D 0 }; - struct sched_unit *currunit =3D current->sched_unit; + bool migrated =3D false; =20 /* TRACE */ { @@ -1111,7 +1111,7 @@ rt_schedule(const struct scheduler *ops, s_time_t now= , bool_t tasklet_work_sched __set_bit(__RTDS_delayed_runq_add, &scurr->flags); =20 snext->last_start =3D now; - ret.time =3D -1; /* if an idle unit is picked */ + currunit->next_time =3D -1; /* if an idle unit is picked */ if ( !is_idle_unit(snext->unit) ) { if ( snext !=3D scurr ) @@ -1122,13 +1122,13 @@ rt_schedule(const struct scheduler *ops, s_time_t n= ow, bool_t tasklet_work_sched if ( sched_unit_cpu(snext->unit) !=3D sched_cpu ) { sched_set_res(snext->unit, get_sched_res(sched_cpu)); - ret.migrated =3D 1; + migrated =3D true; } - ret.time =3D snext->cur_budget; /* invoke the scheduler next time = */ + /* Invoke the scheduler next time. */ + currunit->next_time =3D snext->cur_budget; } - ret.task =3D snext->unit; - - return ret; + currunit->next_task =3D snext->unit; + snext->unit->migrated =3D migrated; } =20 /* diff --git a/xen/common/schedule.c b/xen/common/schedule.c index e4d0dd4b65..d2fc89d983 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -105,15 +105,14 @@ sched_idle_free_vdata(const struct scheduler *ops, vo= id *priv) { } =20 -static struct task_slice sched_idle_schedule( - const struct scheduler *ops, s_time_t now, +static void sched_idle_schedule( + const struct scheduler *ops, struct sched_unit *unit, s_time_t now, bool tasklet_work_scheduled) { const unsigned int cpu =3D smp_processor_id(); - struct task_slice ret =3D { .time =3D -1 }; =20 - ret.task =3D sched_idle_unit(sched_get_resource_cpu(cpu)); - return ret; + unit->next_time =3D -1; + unit->next_task =3D sched_idle_unit(sched_get_resource_cpu(cpu)); } =20 static struct scheduler sched_idle_ops =3D { @@ -1698,10 +1697,9 @@ static void schedule(void) s_time_t now; struct scheduler *sched; unsigned long *tasklet_work =3D &this_cpu(tasklet_work_to_do); - bool_t tasklet_work_scheduled =3D 0; + bool tasklet_work_scheduled =3D false; struct sched_resource *sd; spinlock_t *lock; - struct task_slice next_slice; int cpu =3D smp_processor_id(); =20 ASSERT_NOT_IN_ATOMIC(); @@ -1717,12 +1715,12 @@ static void schedule(void) set_bit(_TASKLET_scheduled, tasklet_work); /* fallthrough */ case TASKLET_enqueued|TASKLET_scheduled: - tasklet_work_scheduled =3D 1; + tasklet_work_scheduled =3D true; break; case TASKLET_scheduled: clear_bit(_TASKLET_scheduled, tasklet_work); case 0: - /*tasklet_work_scheduled =3D 0;*/ + /*tasklet_work_scheduled =3D false;*/ break; default: BUG(); @@ -1736,14 +1734,14 @@ static void schedule(void) =20 /* get policy-specific decision on scheduling... */ sched =3D this_cpu(scheduler); - next_slice =3D sched->do_schedule(sched, now, tasklet_work_scheduled); + sched->do_schedule(sched, prev, now, tasklet_work_scheduled); =20 - next =3D next_slice.task; + next =3D prev->next_task; =20 sd->curr =3D next; =20 - if ( next_slice.time >=3D 0 ) /* -ve means no limit */ - set_timer(&sd->s_timer, now + next_slice.time); + if ( prev->next_time >=3D 0 ) /* -ve means no limit */ + set_timer(&sd->s_timer, now + prev->next_time); =20 if ( unlikely(prev =3D=3D next) ) { @@ -1751,9 +1749,7 @@ static void schedule(void) TRACE_4D(TRC_SCHED_SWITCH_INFCONT, next->domain->domain_id, next->unit_id, now - prev->state_entry_time, - next_slice.time); - trace_continue_running(next->vcpu_list); - return continue_running(prev->vcpu_list); + prev->next_time); } =20 TRACE_3D(TRC_SCHED_SWITCH_INFPREV, @@ -1763,7 +1759,7 @@ static void schedule(void) next->domain->domain_id, next->unit_id, (next->vcpu_list->runstate.state =3D=3D RUNSTATE_runnable) ? (now - next->state_entry_time) : 0, - next_slice.time); + prev->next_time); =20 ASSERT(prev->vcpu_list->runstate.state =3D=3D RUNSTATE_running); =20 @@ -1792,7 +1788,7 @@ static void schedule(void) =20 stop_timer(&prev->vcpu_list->periodic_timer); =20 - if ( next_slice.migrated ) + if ( next->migrated ) vcpu_move_irqs(next->vcpu_list); =20 vcpu_periodic_timer_work(next->vcpu_list); diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 1a3981e78a..ba91c3a680 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -195,12 +195,6 @@ static inline spinlock_t *pcpu_schedule_trylock(unsign= ed int cpu) return NULL; } =20 -struct task_slice { - struct sched_unit *task; - s_time_t time; - bool_t migrated; -}; - struct scheduler { char *name; /* full name for this scheduler */ char *opt_name; /* option name for this scheduler */ @@ -243,8 +237,9 @@ struct scheduler { void (*context_saved) (const struct scheduler *, struct sched_unit *); =20 - struct task_slice (*do_schedule) (const struct scheduler *, s_time_t, - bool_t tasklet_work_scheduled); + void (*do_schedule) (const struct scheduler *, + struct sched_unit *, s_time_t, + bool tasklet_work_scheduled); =20 struct sched_resource * (*pick_resource) (const struct scheduler *, struct sched_unit *); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 7f84b823cb..9a17962132 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -281,12 +281,18 @@ struct sched_unit { bool is_running; /* Does soft affinity actually play a role (given hard affinity)? */ bool soft_aff_effective; + /* Item has been migrated to other cpu(s). */ + bool migrated; /* Bitmask of CPUs on which this VCPU may run. */ cpumask_var_t cpu_hard_affinity; /* Used to save affinity during temporary pinning. */ cpumask_var_t cpu_hard_affinity_saved; /* Bitmask of CPUs on which this VCPU prefers to run. */ cpumask_var_t cpu_soft_affinity; + + /* Next unit to run. */ + struct sched_unit *next_task; + s_time_t next_time; }; =20 #define for_each_sched_unit(d, e) \ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362786; cv=none; d=zoho.com; s=zohoarc; b=npzWei3tq1BAgY3R7Hf9jOka5SKYDgUIOqKBTCqrEKMfQZ3369rqAdsLPg1LEWpCeRqIcbPfIzFJTsaQK9gDpJV6mF1B1FnCzg5V5tmkicb/ze45Lyf9c+iCFKyBbMlhz7nHLvxdRI/eFdooyHAYcFT3vL9HBe8u1hIUjlDVIEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362786; 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=GBnMdbhKp1fmabzeeJx6iv7BXPCTBlst6+0PeIoeAXg=; b=N7qx4Jnchwj6GjOVhG3UOjBwdAJotyO4tCAVQ5EE1vMSStq5HMUtX584U3MyfPDGXEFWPsGJbPYhWkNjwOCyrt2z4P5v3M3tVyk/cZdkABDNeMHmuxfvDaSPT4RV6kKQc2p8fqMqDo7wfQ6ZucmN/OfAVdvH6wjPCrrbAnnKbqg= 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 1565362786892107.27123730835763; Fri, 9 Aug 2019 07:59:46 -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 1hw6MG-00075O-7w; Fri, 09 Aug 2019 14:59:08 +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 1hw6M2-0006bs-Iu for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:54 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 31558a10-bab6-11e9-b0c9-87196e65e4e6; Fri, 09 Aug 2019 14:58:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2AF61B008; Fri, 9 Aug 2019 14:58:48 +0000 (UTC) X-Inumbo-ID: 31558a10-bab6-11e9-b0c9-87196e65e4e6 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:14 +0200 Message-Id: <20190809145833.1020-30-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 29/48] xen/sched: add code to sync scheduling of all vcpus of a 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= 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" When switching sched units synchronize all vcpus of the new unit to be scheduled at the same time. A variable sched_granularity is added which holds the number of vcpus per schedule unit. As tasklets require to schedule the idle unit it is required to set the tasklet_work_scheduled parameter of do_schedule() to true if any cpu covered by the current schedule() call has any pending tasklet work. For joining other vcpus of the schedule unit we need to add a new softirq SCHED_SLAVE_SOFTIRQ in order to have a way to initiate a context switch without calling the generic schedule() function selecting the vcpu to switch to, as we already know which vcpu we want to run. This has the other advantage not to loose any other concurrent SCHEDULE_SOFTIRQ events. Signed-off-by: Juergen Gross --- RFC V2: - move syncing after context_switch() to schedule.c V2: - don't run tasklets directly from sched_wait_rendezvous_in() --- xen/arch/arm/domain.c | 2 +- xen/arch/x86/domain.c | 3 +- xen/common/schedule.c | 338 +++++++++++++++++++++++++++++++++++------= ---- xen/common/softirq.c | 6 +- xen/include/xen/sched-if.h | 1 + xen/include/xen/sched.h | 16 ++- xen/include/xen/softirq.h | 1 + 7 files changed, 284 insertions(+), 83 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 941bbff4fe..40dcbce675 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -315,7 +315,7 @@ static void schedule_tail(struct vcpu *prev) =20 local_irq_enable(); =20 - context_saved(prev); + sched_context_switched(prev, current); =20 update_runstate_area(current); =20 diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 5e69287f87..c45bec8864 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1766,7 +1766,6 @@ static void __context_switch(void) per_cpu(curr_vcpu, cpu) =3D n; } =20 - void context_switch(struct vcpu *prev, struct vcpu *next) { unsigned int cpu =3D smp_processor_id(); @@ -1842,7 +1841,7 @@ void context_switch(struct vcpu *prev, struct vcpu *n= ext) } } =20 - context_saved(prev); + sched_context_switched(prev, next); =20 _update_runstate_area(next); /* Must be done with interrupts enabled */ diff --git a/xen/common/schedule.c b/xen/common/schedule.c index d2fc89d983..0160c30465 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -55,6 +55,9 @@ boolean_param("sched_smt_power_savings", sched_smt_power_= savings); int sched_ratelimit_us =3D SCHED_DEFAULT_RATELIMIT_US; integer_param("sched_ratelimit_us", sched_ratelimit_us); =20 +/* Number of vcpus per struct sched_unit. */ +static unsigned int __read_mostly sched_granularity =3D 1; + /* Common lock for free cpus. */ static DEFINE_SPINLOCK(sched_free_cpu_lock); =20 @@ -1686,131 +1689,318 @@ static void vcpu_periodic_timer_work(struct vcpu = *v) set_timer(&v->periodic_timer, periodic_next_event); } =20 -/* - * The main function - * - deschedule the current domain (scheduler independent). - * - pick a new domain (scheduler dependent). - */ -static void schedule(void) +static void sched_switch_units(struct sched_resource *sd, + struct sched_unit *next, struct sched_unit = *prev, + s_time_t now) { - struct sched_unit *prev =3D current->sched_unit, *next =3D NULL; - s_time_t now; - struct scheduler *sched; - unsigned long *tasklet_work =3D &this_cpu(tasklet_work_to_do); - bool tasklet_work_scheduled =3D false; - struct sched_resource *sd; - spinlock_t *lock; - int cpu =3D smp_processor_id(); + sd->curr =3D next; =20 - ASSERT_NOT_IN_ATOMIC(); + TRACE_3D(TRC_SCHED_SWITCH_INFPREV, prev->domain->domain_id, prev->unit= _id, + now - prev->state_entry_time); + TRACE_4D(TRC_SCHED_SWITCH_INFNEXT, next->domain->domain_id, next->unit= _id, + (next->vcpu_list->runstate.state =3D=3D RUNSTATE_runnable) ? + (now - next->state_entry_time) : 0, prev->next_time); =20 - SCHED_STAT_CRANK(sched_run); + ASSERT(prev->vcpu_list->runstate.state =3D=3D RUNSTATE_running); =20 - sd =3D get_sched_res(cpu); + TRACE_4D(TRC_SCHED_SWITCH, prev->domain->domain_id, prev->unit_id, + next->domain->domain_id, next->unit_id); + + sched_unit_runstate_change(prev, false, now); + + ASSERT(next->vcpu_list->runstate.state !=3D RUNSTATE_running); + sched_unit_runstate_change(next, true, now); + + /* + * NB. Don't add any trace records from here until the actual context + * switch, else lost_records resume will not work properly. + */ + + ASSERT(!next->is_running); + next->vcpu_list->is_running =3D 1; + next->is_running =3D 1; +} + +static bool sched_tasklet_check_cpu(unsigned int cpu) +{ + unsigned long *tasklet_work =3D &per_cpu(tasklet_work_to_do, cpu); =20 - /* Update tasklet scheduling status. */ switch ( *tasklet_work ) { case TASKLET_enqueued: set_bit(_TASKLET_scheduled, tasklet_work); /* fallthrough */ case TASKLET_enqueued|TASKLET_scheduled: - tasklet_work_scheduled =3D true; + return true; break; case TASKLET_scheduled: clear_bit(_TASKLET_scheduled, tasklet_work); + /* fallthrough */ case 0: - /*tasklet_work_scheduled =3D false;*/ + /* return false; */ break; default: BUG(); } =20 - lock =3D pcpu_schedule_lock_irq(cpu); + return false; +} =20 - now =3D NOW(); +static bool sched_tasklet_check(unsigned int cpu) +{ + bool tasklet_work_scheduled =3D false; + const cpumask_t *mask =3D get_sched_res(cpu)->cpus; + int cpu_iter; =20 - stop_timer(&sd->s_timer); + for_each_cpu ( cpu_iter, mask ) + if ( sched_tasklet_check_cpu(cpu_iter) ) + tasklet_work_scheduled =3D true; + + return tasklet_work_scheduled; +} + +static struct sched_unit *do_schedule(struct sched_unit *prev, s_time_t no= w, + unsigned int cpu) +{ + struct scheduler *sched =3D per_cpu(scheduler, cpu); + struct sched_resource *sd =3D get_sched_res(cpu); + struct sched_unit *next; =20 /* get policy-specific decision on scheduling... */ - sched =3D this_cpu(scheduler); - sched->do_schedule(sched, prev, now, tasklet_work_scheduled); + sched->do_schedule(sched, prev, now, sched_tasklet_check(cpu)); =20 next =3D prev->next_task; =20 - sd->curr =3D next; - if ( prev->next_time >=3D 0 ) /* -ve means no limit */ set_timer(&sd->s_timer, now + prev->next_time); =20 - if ( unlikely(prev =3D=3D next) ) + if ( likely(prev !=3D next) ) + sched_switch_units(sd, next, prev, now); + + return next; +} + +static void context_saved(struct vcpu *prev) +{ + struct sched_unit *unit =3D prev->sched_unit; + + /* Clear running flag /after/ writing context to memory. */ + smp_wmb(); + + prev->is_running =3D 0; + unit->is_running =3D 0; + unit->state_entry_time =3D NOW(); + + /* Check for migration request /after/ clearing running flag. */ + smp_mb(); + + sched_context_saved(vcpu_scheduler(prev), unit); + + sched_unit_migrate_finish(unit); +} + +/* + * Rendezvous on end of context switch. + * As no lock is protecting this rendezvous function we need to use atomic + * access functions on the counter. + * The counter will be 0 in case no rendezvous is needed. For the rendezvo= us + * case it is initialised to the number of cpus to rendezvous plus 1. Each + * member entering decrements the counter. The last one will decrement it = to + * 1 and perform the final needed action in that case (call of context_sav= ed() + * if vcpu was switched), and then set the counter to zero. The other memb= ers + * will wait until the counter becomes zero until they proceed. + */ +void sched_context_switched(struct vcpu *vprev, struct vcpu *vnext) +{ + struct sched_unit *next =3D vnext->sched_unit; + + if ( atomic_read(&next->rendezvous_out_cnt) ) + { + int cnt =3D atomic_dec_return(&next->rendezvous_out_cnt); + + /* Call context_saved() before releasing other waiters. */ + if ( cnt =3D=3D 1 ) + { + if ( vprev !=3D vnext ) + context_saved(vprev); + atomic_set(&next->rendezvous_out_cnt, 0); + } + else + while ( atomic_read(&next->rendezvous_out_cnt) ) + cpu_relax(); + } + else if ( vprev !=3D vnext ) + context_saved(vprev); +} + +static void sched_context_switch(struct vcpu *vprev, struct vcpu *vnext, + s_time_t now) +{ + if ( unlikely(vprev =3D=3D vnext) ) { - pcpu_schedule_unlock_irq(lock, cpu); TRACE_4D(TRC_SCHED_SWITCH_INFCONT, - next->domain->domain_id, next->unit_id, - now - prev->state_entry_time, - prev->next_time); + vnext->domain->domain_id, vnext->sched_unit->unit_id, + now - vprev->runstate.state_entry_time, + vprev->sched_unit->next_time); + sched_context_switched(vprev, vnext); + trace_continue_running(vnext); + return continue_running(vprev); } =20 - TRACE_3D(TRC_SCHED_SWITCH_INFPREV, - prev->domain->domain_id, prev->unit_id, - now - prev->state_entry_time); - TRACE_4D(TRC_SCHED_SWITCH_INFNEXT, - next->domain->domain_id, next->unit_id, - (next->vcpu_list->runstate.state =3D=3D RUNSTATE_runnable) ? - (now - next->state_entry_time) : 0, - prev->next_time); + SCHED_STAT_CRANK(sched_ctx); =20 - ASSERT(prev->vcpu_list->runstate.state =3D=3D RUNSTATE_running); + stop_timer(&vprev->periodic_timer); =20 - TRACE_4D(TRC_SCHED_SWITCH, - prev->domain->domain_id, prev->unit_id, - next->domain->domain_id, next->unit_id); + if ( vnext->sched_unit->migrated ) + vcpu_move_irqs(vnext); =20 - sched_unit_runstate_change(prev, false, now); + vcpu_periodic_timer_work(vnext); =20 - ASSERT(next->vcpu_list->runstate.state !=3D RUNSTATE_running); - sched_unit_runstate_change(next, true, now); + context_switch(vprev, vnext); +} =20 - /* - * NB. Don't add any trace records from here until the actual context - * switch, else lost_records resume will not work properly. - */ +/* + * Rendezvous before taking a scheduling decision. + * Called with schedule lock held, so all accesses to the rendezvous count= er + * can be normal ones (no atomic accesses needed). + * The counter is initialized to the number of cpus to rendezvous initiall= y. + * Each cpu entering will decrement the counter. In case the counter becom= es + * zero do_schedule() is called and the rendezvous counter for leaving + * context_switch() is set. All other members will wait until the counter = is + * becoming zero, dropping the schedule lock in between. + */ +static struct sched_unit *sched_wait_rendezvous_in(struct sched_unit *prev, + spinlock_t **lock, int = cpu, + s_time_t now) +{ + struct sched_unit *next; =20 - ASSERT(!next->is_running); - next->vcpu_list->is_running =3D 1; - next->is_running =3D 1; - next->state_entry_time =3D now; + if ( !--prev->rendezvous_in_cnt ) + { + next =3D do_schedule(prev, now, cpu); + atomic_set(&next->rendezvous_out_cnt, sched_granularity + 1); + return next; + } =20 - pcpu_schedule_unlock_irq(lock, cpu); + while ( prev->rendezvous_in_cnt ) + { + /* + * Coming from idle might need to do tasklet work. + * In order to avoid deadlocks we can't do that here, but have to + * continue the idle loop. + * Undo the rendezvous_in_cnt decrement and schedule another call = of + * sched_slave(). + */ + if ( is_idle_unit(prev) && sched_tasklet_check_cpu(cpu) ) + { + struct vcpu *vprev =3D current; =20 - SCHED_STAT_CRANK(sched_ctx); + prev->rendezvous_in_cnt++; + atomic_set(&prev->rendezvous_out_cnt, 0); + + pcpu_schedule_unlock_irq(*lock, cpu); + + raise_softirq(SCHED_SLAVE_SOFTIRQ); + sched_context_switch(vprev, vprev, now); + } =20 - stop_timer(&prev->vcpu_list->periodic_timer); + pcpu_schedule_unlock_irq(*lock, cpu); =20 - if ( next->migrated ) - vcpu_move_irqs(next->vcpu_list); + cpu_relax(); =20 - vcpu_periodic_timer_work(next->vcpu_list); + *lock =3D pcpu_schedule_lock_irq(cpu); + } =20 - context_switch(prev->vcpu_list, next->vcpu_list); + return prev->next_task; } =20 -void context_saved(struct vcpu *prev) +static void sched_slave(void) { - /* Clear running flag /after/ writing context to memory. */ - smp_wmb(); + struct vcpu *vprev =3D current; + struct sched_unit *prev =3D vprev->sched_unit, *next; + s_time_t now; + spinlock_t *lock; + int cpu =3D smp_processor_id(); =20 - prev->is_running =3D 0; - prev->sched_unit->is_running =3D 0; - prev->sched_unit->state_entry_time =3D NOW(); + ASSERT_NOT_IN_ATOMIC(); =20 - /* Check for migration request /after/ clearing running flag. */ - smp_mb(); + lock =3D pcpu_schedule_lock_irq(cpu); + + now =3D NOW(); + + if ( !prev->rendezvous_in_cnt ) + { + pcpu_schedule_unlock_irq(lock, cpu); + return; + } + + stop_timer(&get_sched_res(cpu)->s_timer); + + next =3D sched_wait_rendezvous_in(prev, &lock, cpu, now); + + pcpu_schedule_unlock_irq(lock, cpu); + + sched_context_switch(vprev, next->vcpu_list, now); +} + +/* + * The main function + * - deschedule the current domain (scheduler independent). + * - pick a new domain (scheduler dependent). + */ +static void schedule(void) +{ + struct vcpu *vnext, *vprev =3D current; + struct sched_unit *prev =3D vprev->sched_unit, *next =3D NULL; + s_time_t now; + struct sched_resource *sd; + spinlock_t *lock; + int cpu =3D smp_processor_id(); + + ASSERT_NOT_IN_ATOMIC(); + + SCHED_STAT_CRANK(sched_run); + + sd =3D get_sched_res(cpu); + + lock =3D pcpu_schedule_lock_irq(cpu); + + if ( prev->rendezvous_in_cnt ) + { + /* + * We have a race: sched_slave() should be called, so raise a soft= irq + * in order to re-enter schedule() later and call sched_slave() no= w. + */ + pcpu_schedule_unlock_irq(lock, cpu); + + raise_softirq(SCHEDULE_SOFTIRQ); + return sched_slave(); + } + + now =3D NOW(); =20 - sched_context_saved(vcpu_scheduler(prev), prev->sched_unit); + stop_timer(&sd->s_timer); + + if ( sched_granularity > 1 ) + { + cpumask_t mask; =20 - sched_unit_migrate_finish(prev->sched_unit); + prev->rendezvous_in_cnt =3D sched_granularity; + cpumask_andnot(&mask, sd->cpus, cpumask_of(cpu)); + cpumask_raise_softirq(&mask, SCHED_SLAVE_SOFTIRQ); + next =3D sched_wait_rendezvous_in(prev, &lock, cpu, now); + } + else + { + prev->rendezvous_in_cnt =3D 0; + next =3D do_schedule(prev, now, cpu); + atomic_set(&next->rendezvous_out_cnt, 0); + } + + pcpu_schedule_unlock_irq(lock, cpu); + + vnext =3D next->vcpu_list; + sched_context_switch(vprev, vnext, now); } =20 /* The scheduler timer: force a run through the scheduler */ @@ -1851,6 +2041,7 @@ static int cpu_schedule_up(unsigned int cpu) if ( sd =3D=3D NULL ) return -ENOMEM; sd->processor =3D cpu; + sd->cpus =3D cpumask_of(cpu); set_sched_res(cpu, sd); =20 per_cpu(scheduler, cpu) =3D &sched_idle_ops; @@ -1871,6 +2062,8 @@ static int cpu_schedule_up(unsigned int cpu) if ( idle_vcpu[cpu] =3D=3D NULL ) return -ENOMEM; =20 + idle_vcpu[cpu]->sched_unit->rendezvous_in_cnt =3D 0; + /* * No need to allocate any scheduler data, as cpus coming online are * free initially and the idle scheduler doesn't need any data areas @@ -1971,6 +2164,7 @@ void __init scheduler_init(void) int i; =20 open_softirq(SCHEDULE_SOFTIRQ, schedule); + open_softirq(SCHED_SLAVE_SOFTIRQ, sched_slave); =20 for ( i =3D 0; i < NUM_SCHEDULERS; i++) { diff --git a/xen/common/softirq.c b/xen/common/softirq.c index 83c3c09bd5..2d66193203 100644 --- a/xen/common/softirq.c +++ b/xen/common/softirq.c @@ -33,8 +33,8 @@ static void __do_softirq(unsigned long ignore_mask) for ( ; ; ) { /* - * Initialise @cpu on every iteration: SCHEDULE_SOFTIRQ may move - * us to another processor. + * Initialise @cpu on every iteration: SCHEDULE_SOFTIRQ or + * SCHED_SLAVE_SOFTIRQ may move us to another processor. */ cpu =3D smp_processor_id(); =20 @@ -55,7 +55,7 @@ void process_pending_softirqs(void) { ASSERT(!in_irq() && local_irq_is_enabled()); /* Do not enter scheduler as it can preempt the calling context. */ - __do_softirq(1ul<curr) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 9a17962132..8f4e389b3b 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -293,6 +293,12 @@ struct sched_unit { /* Next unit to run. */ struct sched_unit *next_task; s_time_t next_time; + + /* Number of vcpus not yet joined for context switch. */ + unsigned int rendezvous_in_cnt; + + /* Number of vcpus not yet finished with context switch. */ + atomic_t rendezvous_out_cnt; }; =20 #define for_each_sched_unit(d, e) \ @@ -697,10 +703,10 @@ void sync_local_execstate(void); =20 /* * Called by the scheduler to switch to another VCPU. This function must - * call context_saved(@prev) when the local CPU is no longer running in - * @prev's context, and that context is saved to memory. Alternatively, if - * implementing lazy context switching, it suffices to ensure that invoking - * sync_vcpu_execstate() will switch and commit @prev's state. + * call sched_context_switched(@prev, @next) when the local CPU is no long= er + * running in @prev's context, and that context is saved to memory. + * Alternatively, if implementing lazy context switching, it suffices to e= nsure + * that invoking sync_vcpu_execstate() will switch and commit @prev's stat= e. */ void context_switch( struct vcpu *prev, @@ -712,7 +718,7 @@ void context_switch( * saved to memory. Alternatively, if implementing lazy context switching, * ensure that invoking sync_vcpu_execstate() will switch and commit @prev. */ -void context_saved(struct vcpu *prev); +void sched_context_switched(struct vcpu *prev, struct vcpu *vnext); =20 /* Called by the scheduler to continue running the current VCPU. */ void continue_running( diff --git a/xen/include/xen/softirq.h b/xen/include/xen/softirq.h index c327c9b6cd..d7273b389b 100644 --- a/xen/include/xen/softirq.h +++ b/xen/include/xen/softirq.h @@ -4,6 +4,7 @@ /* Low-latency softirqs come first in the following list. */ enum { TIMER_SOFTIRQ =3D 0, + SCHED_SLAVE_SOFTIRQ, SCHEDULE_SOFTIRQ, NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, RCU_SOFTIRQ, --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362783; cv=none; d=zoho.com; s=zohoarc; b=ALdPC4OiwiTqFKeEmjmS+UkA36tvZ1QC0eAXNAxUGoCXAZYWvH8WEuhkfwteC+6TmPpdZusiyr5nDuolVSWW95wDm4Dj2JPi/RJQLxDDg2TVJB/aSt71l6TEmxBZMD15EhhQSQ+Vtj9Oc1cZXUID9pAuEbLarMX6/9NWCbLkveM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362783; 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=YAgLAICmZvTfzDqsaIoQAISMAIZEmnkyiumtFtiTuMw=; b=RVyFjrfaZ26+oDngEzBf69k8Lzmt6nqtf4s2BlMHPYo55VS/gSu9RcXeFsb1xdn+QqNVkXq83lJPeuwEU7jU1tc5RSZa97C6TH5KU4g7RMcH4Ay7soMMJhCj97lU8rK2CTjJ0lLZfxRiXiZdVhtL/GojmQUMBSlRmQENFe9pFug= 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 1565362783346171.58236882567746; Fri, 9 Aug 2019 07:59:43 -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 1hw6ME-00072J-MO; Fri, 09 Aug 2019 14:59:06 +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 1hw6M2-0006bq-Hu for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:54 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 31890fb6-bab6-11e9-b2d1-e3da5eae404c; Fri, 09 Aug 2019 14:58:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A213EAF2A; Fri, 9 Aug 2019 14:58:48 +0000 (UTC) X-Inumbo-ID: 31890fb6-bab6-11e9-b2d1-e3da5eae404c X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:15 +0200 Message-Id: <20190809145833.1020-31-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 30/48] xen/sched: introduce unit_runnable_state() 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Robert VanVossen , Tim Deegan , Julien Grall , Josh Whitehead , Meng Xu , Jan Beulich , Dario Faggioli 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" Today the vcpu runstate of a new scheduled vcpu is always set to "running" even if at that time vcpu_runnable() is already returning false due to a race (e.g. with pausing the vcpu). With core scheduling this can no longer work as not all vcpus of a schedule unit have to be "running" when being scheduled. So the vcpu's new runstate has to be selected at the same time as the runnability of the related schedule unit is probed. For this purpose introduce a new helper unit_runnable_state() which will save the new runstate of all tested vcpus in a new field of the vcpu struct. Signed-off-by: Juergen Gross --- RFC V2: new patch --- xen/common/domain.c | 1 + xen/common/sched_arinc653.c | 2 +- xen/common/sched_credit.c | 49 ++++++++++++++++++++++++-----------------= ---- xen/common/sched_credit2.c | 7 ++++--- xen/common/sched_null.c | 3 ++- xen/common/sched_rt.c | 8 +++++++- xen/common/schedule.c | 2 +- xen/include/xen/sched-if.h | 14 +++++++++++++ xen/include/xen/sched.h | 1 + 9 files changed, 57 insertions(+), 30 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 863b7cae35..3797f954f5 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -157,6 +157,7 @@ struct vcpu *vcpu_create(struct domain *d, unsigned int= vcpu_id) if ( is_idle_domain(d) ) { v->runstate.state =3D RUNSTATE_running; + v->new_state =3D RUNSTATE_running; } else { diff --git a/xen/common/sched_arinc653.c b/xen/common/sched_arinc653.c index 34efcc07c9..759c42ab73 100644 --- a/xen/common/sched_arinc653.c +++ b/xen/common/sched_arinc653.c @@ -557,7 +557,7 @@ a653sched_do_schedule( if ( !((new_task !=3D NULL) && (AUNIT(new_task) !=3D NULL) && AUNIT(new_task)->awake - && unit_runnable(new_task)) ) + && unit_runnable_state(new_task)) ) new_task =3D IDLETASK(cpu); BUG_ON(new_task =3D=3D NULL); =20 diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index f1675fd52e..aeb659577e 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1894,7 +1894,7 @@ static void csched_schedule( if ( !test_bit(CSCHED_FLAG_UNIT_YIELD, &scurr->flags) && !tasklet_work_scheduled && prv->ratelimit - && unit_runnable(unit) + && unit_runnable_state(unit) && !is_idle_unit(unit) && runtime < prv->ratelimit ) { @@ -1939,33 +1939,36 @@ static void csched_schedule( dec_nr_runnable(sched_cpu); } =20 - snext =3D __runq_elem(runq->next); - - /* Tasklet work (which runs in idle UNIT context) overrides all else. = */ - if ( tasklet_work_scheduled ) - { - TRACE_0D(TRC_CSCHED_SCHED_TASKLET); - snext =3D CSCHED_UNIT(sched_idle_unit(sched_cpu)); - snext->pri =3D CSCHED_PRI_TS_BOOST; - } - /* * Clear YIELD flag before scheduling out */ clear_bit(CSCHED_FLAG_UNIT_YIELD, &scurr->flags); =20 - /* - * SMP Load balance: - * - * If the next highest priority local runnable UNIT has already eaten - * through its credits, look on other PCPUs to see if we have more - * urgent work... If not, csched_load_balance() will return snext, but - * already removed from the runq. - */ - if ( snext->pri > CSCHED_PRI_TS_OVER ) - __runq_remove(snext); - else - snext =3D csched_load_balance(prv, sched_cpu, snext, &migrated); + do { + snext =3D __runq_elem(runq->next); + + /* Tasklet work (which runs in idle UNIT context) overrides all el= se. */ + if ( tasklet_work_scheduled ) + { + TRACE_0D(TRC_CSCHED_SCHED_TASKLET); + snext =3D CSCHED_UNIT(sched_idle_unit(sched_cpu)); + snext->pri =3D CSCHED_PRI_TS_BOOST; + } + + /* + * SMP Load balance: + * + * If the next highest priority local runnable UNIT has already ea= ten + * through its credits, look on other PCPUs to see if we have more + * urgent work... If not, csched_load_balance() will return snext,= but + * already removed from the runq. + */ + if ( snext->pri > CSCHED_PRI_TS_OVER ) + __runq_remove(snext); + else + snext =3D csched_load_balance(prv, sched_cpu, snext, &migrated= ); + + } while ( !unit_runnable_state(snext->unit) ); =20 /* * Update idlers mask if necessary. When we're idling, other CPUs diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 98ef48d6f4..af06d02056 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -3289,7 +3289,7 @@ runq_candidate(struct csched2_runqueue_data *rqd, * In fact, it may be the case that scurr is about to spin, and there's * no point forcing it to do so until rate limiting expires. */ - if ( !yield && prv->ratelimit_us && unit_runnable(scurr->unit) && + if ( !yield && prv->ratelimit_us && unit_runnable_state(scurr->unit) && (now - scurr->unit->state_entry_time) < MICROSECS(prv->ratelimit_= us) ) { if ( unlikely(tb_init_done) ) @@ -3343,7 +3343,7 @@ runq_candidate(struct csched2_runqueue_data *rqd, * * Of course, we also default to idle also if scurr is not runnable. */ - if ( unit_runnable(scurr->unit) && !soft_aff_preempt ) + if ( unit_runnable_state(scurr->unit) && !soft_aff_preempt ) snext =3D scurr; else snext =3D csched2_unit(sched_idle_unit(cpu)); @@ -3403,7 +3403,8 @@ runq_candidate(struct csched2_runqueue_data *rqd, * some budget, then choose it. */ if ( (yield || svc->credit > snext->credit) && - (!has_cap(svc) || unit_grab_budget(svc)) ) + (!has_cap(svc) || unit_grab_budget(svc)) && + unit_runnable_state(svc->unit) ) snext =3D svc; =20 /* In any case, if we got this far, break. */ diff --git a/xen/common/sched_null.c b/xen/common/sched_null.c index 397edcbc83..755d3e448c 100644 --- a/xen/common/sched_null.c +++ b/xen/common/sched_null.c @@ -864,7 +864,8 @@ static void null_schedule(const struct scheduler *ops, = struct sched_unit *prev, cpumask_set_cpu(cpu, &prv->cpus_free); } =20 - if ( unlikely(prev->next_task =3D=3D NULL || !unit_runnable(prev->next= _task)) ) + if ( unlikely(prev->next_task =3D=3D NULL || + !unit_runnable_state(prev->next_task)) ) prev->next_task =3D sched_idle_unit(sched_cpu); =20 NULL_UNIT_CHECK(prev->next_task); diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index fcbfa528f4..205ff13c09 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -1093,12 +1093,18 @@ rt_schedule(const struct scheduler *ops, struct sch= ed_unit *currunit, else { snext =3D runq_pick(ops, cpumask_of(sched_cpu)); + if ( snext =3D=3D NULL ) snext =3D rt_unit(sched_idle_unit(sched_cpu)); + else if ( !unit_runnable_state(snext->unit) ) + { + q_remove(snext); + snext =3D rt_unit(sched_idle_unit(sched_cpu)); + } =20 /* if scurr has higher priority and budget, still pick scurr */ if ( !is_idle_unit(currunit) && - unit_runnable(currunit) && + unit_runnable_state(currunit) && scurr->cur_budget > 0 && ( is_idle_unit(snext->unit) || compare_unit_priority(scurr, snext) > 0 ) ) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 0160c30465..2ecb76e3b9 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -266,7 +266,7 @@ static inline void sched_unit_runstate_change(struct sc= hed_unit *unit, struct vcpu *v =3D unit->vcpu_list; =20 if ( running ) - vcpu_runstate_change(v, RUNSTATE_running, new_entry_time); + vcpu_runstate_change(v, v->new_state, new_entry_time); else vcpu_runstate_change(v, ((v->pause_flags & VPF_blocked) ? RUNSTATE_blocked : diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index f810a9fba1..aa896f49ef 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -75,6 +75,20 @@ static inline bool unit_runnable(const struct sched_unit= *unit) return vcpu_runnable(unit->vcpu_list); } =20 +static inline bool unit_runnable_state(const struct sched_unit *unit) +{ + struct vcpu *v; + bool runnable; + + v =3D unit->vcpu_list; + runnable =3D vcpu_runnable(v); + + v->new_state =3D runnable ? RUNSTATE_running + : (v->pause_flags & VPF_blocked) + ? RUNSTATE_blocked : RUNSTATE_offline; + return runnable; +} + static inline void sched_set_res(struct sched_unit *unit, struct sched_resource *res) { diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 8f4e389b3b..7585bd81a2 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -174,6 +174,7 @@ struct vcpu XEN_GUEST_HANDLE(vcpu_runstate_info_compat_t) compat; } runstate_guest; /* guest address */ #endif + int new_state; =20 /* Has the FPU been initialised? */ bool fpu_initialised; --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362789; cv=none; d=zoho.com; s=zohoarc; b=iCIBaJUk8+5hG6625SPThfdrykbEyQFSDQShTHPEcXe7Br8mVptr+B4Ea5x7vHivYTiUXvNcpfjv3uzBuBtWBNxDbUE1nT7+OEpEXd2JnfJHcpm1GtgzsASb8SWXrjbF0gY182rt1iKnUXpQG8lgGD4ZxottjhTDFw7/qoTeOMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362789; 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=Jkh1BCnFTk0FTR9NJ2C45+vAdf2Ug3WhsOz1QTeTKlc=; b=UfKUJvjI2DL+JV0oiRF1YDRhI4cswDDm+qaU95o8tkO1sixXXYRcTJjMueokfMVQtAgR6hFmSM4tCKkI/1pZtPCXmQbP2tcSYZZ8GLQisHSrLolEs5XgbQPAZJdVBgxrFmqNYj9JKdJUoaEjQaiIh3UzFAaC9oXRzfEs32DtC+I= 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 1565362789453803.5889662571369; Fri, 9 Aug 2019 07:59:49 -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 1hw6MI-00079v-Cx; Fri, 09 Aug 2019 14:59:10 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M3-0006dm-Fr for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:55 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 32095c19-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:50 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 12AAAB016; Fri, 9 Aug 2019 14:58:49 +0000 (UTC) X-Inumbo-ID: 32095c19-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:16 +0200 Message-Id: <20190809145833.1020-32-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 31/48] xen/sched: add support for multiple vcpus per sched unit where missing 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli 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 several places there is support for multiple vcpus per sched unit missing. Add that missing support (with the exception of initial allocation) and missing helpers for that. Signed-off-by: Juergen Gross --- RFC V2: - fix vcpu_runstate_helper() V1: - add special handling for idle unit in unit_runnable() and unit_runnable_state() V2: - handle affinity_broken correctly (Jan Beulich) --- xen/common/domain.c | 5 ++- xen/common/schedule.c | 36 ++++++++++--------- xen/include/xen/sched-if.h | 88 +++++++++++++++++++++++++++++++++++++-----= ---- 3 files changed, 95 insertions(+), 34 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 3797f954f5..0c763ceb25 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1255,7 +1255,10 @@ int vcpu_reset(struct vcpu *v) v->async_exception_mask =3D 0; memset(v->async_exception_state, 0, sizeof(v->async_exception_state)); #endif - v->affinity_broken =3D 0; + if ( v->affinity_broken & VCPU_AFFINITY_OVERRIDE ) + vcpu_temporary_affinity(v, NR_CPUS, VCPU_AFFINITY_OVERRIDE); + if ( v->affinity_broken & VCPU_AFFINITY_WAIT ) + vcpu_temporary_affinity(v, NR_CPUS, VCPU_AFFINITY_WAIT); clear_bit(_VPF_blocked, &v->pause_flags); clear_bit(_VPF_in_reset, &v->pause_flags); =20 diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 2ecb76e3b9..1f45fc7373 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -240,8 +240,9 @@ static inline void vcpu_runstate_change( s_time_t delta; struct sched_unit *unit =3D v->sched_unit; =20 - ASSERT(v->runstate.state !=3D new_state); ASSERT(spin_is_locked(get_sched_res(v->processor)->schedule_lock)); + if ( v->runstate.state =3D=3D new_state ) + return; =20 vcpu_urgent_count_update(v); =20 @@ -263,15 +264,16 @@ static inline void vcpu_runstate_change( static inline void sched_unit_runstate_change(struct sched_unit *unit, bool running, s_time_t new_entry_time) { - struct vcpu *v =3D unit->vcpu_list; + struct vcpu *v; =20 - if ( running ) - vcpu_runstate_change(v, v->new_state, new_entry_time); - else - vcpu_runstate_change(v, - ((v->pause_flags & VPF_blocked) ? RUNSTATE_blocked : - (vcpu_runnable(v) ? RUNSTATE_runnable : RUNSTATE_offline)), - new_entry_time); + for_each_sched_unit_vcpu ( unit, v ) + if ( running ) + vcpu_runstate_change(v, v->new_state, new_entry_time); + else + vcpu_runstate_change(v, + ((v->pause_flags & VPF_blocked) ? RUNSTATE_blocked : + (vcpu_runnable(v) ? RUNSTATE_runnable : RUNSTATE_offline)= ), + new_entry_time); } =20 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate) @@ -1035,9 +1037,9 @@ int cpu_disable_scheduler(unsigned int cpu) if ( cpumask_empty(&online_affinity) && cpumask_test_cpu(cpu, unit->cpu_hard_affinity) ) { - if ( unit->vcpu_list->affinity_broken ) + if ( sched_check_affinity_broken(unit) ) { - /* The vcpu is temporarily pinned, can't move it. */ + /* The unit is temporarily pinned, can't move it. */ unit_schedule_unlock_irqrestore(lock, flags, unit); ret =3D -EADDRINUSE; break; @@ -1395,17 +1397,17 @@ int vcpu_temporary_affinity(struct vcpu *v, unsigne= d int cpu, uint8_t reason) ret =3D 0; v->affinity_broken &=3D ~reason; } - if ( !ret && !v->affinity_broken ) + if ( !ret && !sched_check_affinity_broken(unit) ) sched_set_affinity(v, unit->cpu_hard_affinity_saved, NULL); } else if ( cpu < nr_cpu_ids ) { if ( (v->affinity_broken & reason) || - (v->affinity_broken && v->processor !=3D cpu) ) + (sched_check_affinity_broken(unit) && v->processor !=3D cpu) ) ret =3D -EBUSY; else if ( cpumask_test_cpu(cpu, VCPU2ONLINE(v)) ) { - if ( !v->affinity_broken ) + if ( !sched_check_affinity_broken(unit) ) { cpumask_copy(unit->cpu_hard_affinity_saved, unit->cpu_hard_affinity); @@ -1701,14 +1703,14 @@ static void sched_switch_units(struct sched_resourc= e *sd, (next->vcpu_list->runstate.state =3D=3D RUNSTATE_runnable) ? (now - next->state_entry_time) : 0, prev->next_time); =20 - ASSERT(prev->vcpu_list->runstate.state =3D=3D RUNSTATE_running); + ASSERT(unit_running(prev)); =20 TRACE_4D(TRC_SCHED_SWITCH, prev->domain->domain_id, prev->unit_id, next->domain->domain_id, next->unit_id); =20 sched_unit_runstate_change(prev, false, now); =20 - ASSERT(next->vcpu_list->runstate.state !=3D RUNSTATE_running); + ASSERT(!unit_running(next)); sched_unit_runstate_change(next, true, now); =20 /* @@ -1829,7 +1831,7 @@ void sched_context_switched(struct vcpu *vprev, struc= t vcpu *vnext) while ( atomic_read(&next->rendezvous_out_cnt) ) cpu_relax(); } - else if ( vprev !=3D vnext ) + else if ( vprev !=3D vnext && sched_granularity =3D=3D 1 ) context_saved(vprev); } =20 diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index aa896f49ef..e1d61a05b7 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -67,32 +67,70 @@ static inline bool is_idle_unit(const struct sched_unit= *unit) =20 static inline bool is_unit_online(const struct sched_unit *unit) { - return is_vcpu_online(unit->vcpu_list); + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + if ( is_vcpu_online(v) ) + return true; + + return false; +} + +static inline unsigned int unit_running(const struct sched_unit *unit) +{ + return unit->runstate_cnt[RUNSTATE_running]; } =20 static inline bool unit_runnable(const struct sched_unit *unit) { - return vcpu_runnable(unit->vcpu_list); + struct vcpu *v; + + if ( is_idle_unit(unit) ) + return true; + + for_each_sched_unit_vcpu ( unit, v ) + if ( vcpu_runnable(v) ) + return true; + + return false; } =20 static inline bool unit_runnable_state(const struct sched_unit *unit) { struct vcpu *v; - bool runnable; + bool runnable, ret =3D false; + + if ( is_idle_unit(unit) ) + return true; + + for_each_sched_unit_vcpu ( unit, v ) + { + runnable =3D vcpu_runnable(v); + + v->new_state =3D runnable ? RUNSTATE_running + : (v->pause_flags & VPF_blocked) + ? RUNSTATE_blocked : RUNSTATE_offline; =20 - v =3D unit->vcpu_list; - runnable =3D vcpu_runnable(v); + if ( runnable ) + ret =3D true; + } =20 - v->new_state =3D runnable ? RUNSTATE_running - : (v->pause_flags & VPF_blocked) - ? RUNSTATE_blocked : RUNSTATE_offline; - return runnable; + return ret; } =20 static inline void sched_set_res(struct sched_unit *unit, struct sched_resource *res) { - unit->vcpu_list->processor =3D res->processor; + int cpu =3D cpumask_first(res->cpus); + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + { + ASSERT(cpu < nr_cpu_ids); + v->processor =3D cpu; + cpu =3D cpumask_next(cpu, res->cpus); + } + unit->res =3D res; } =20 @@ -104,25 +142,37 @@ static inline unsigned int sched_unit_cpu(struct sche= d_unit *unit) static inline void sched_set_pause_flags(struct sched_unit *unit, unsigned int bit) { - __set_bit(bit, &unit->vcpu_list->pause_flags); + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + __set_bit(bit, &v->pause_flags); } =20 static inline void sched_clear_pause_flags(struct sched_unit *unit, unsigned int bit) { - __clear_bit(bit, &unit->vcpu_list->pause_flags); + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + __clear_bit(bit, &v->pause_flags); } =20 static inline void sched_set_pause_flags_atomic(struct sched_unit *unit, unsigned int bit) { - set_bit(bit, &unit->vcpu_list->pause_flags); + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + set_bit(bit, &v->pause_flags); } =20 static inline void sched_clear_pause_flags_atomic(struct sched_unit *unit, unsigned int bit) { - clear_bit(bit, &unit->vcpu_list->pause_flags); + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + clear_bit(bit, &v->pause_flags); } =20 static inline struct sched_unit *sched_idle_unit(unsigned int cpu) @@ -448,12 +498,18 @@ static inline int sched_adjust_cpupool(const struct s= cheduler *s, =20 static inline void sched_unit_pause_nosync(struct sched_unit *unit) { - vcpu_pause_nosync(unit->vcpu_list); + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + vcpu_pause_nosync(v); } =20 static inline void sched_unit_unpause(struct sched_unit *unit) { - vcpu_unpause(unit->vcpu_list); + struct vcpu *v; + + for_each_sched_unit_vcpu ( unit, v ) + vcpu_unpause(v); } =20 #define REGISTER_SCHEDULER(x) static const struct scheduler *x##_entry \ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362801; cv=none; d=zoho.com; s=zohoarc; b=KZHRgvAmTKdYupVa3tExvye3k0TzosmIn7Ka4+rYM6glsSO7d5yc2VSesY0M9A0b25iVz6A3wPZTyG41M2ie8R+hSDzdsqBNV9ao2HNTQMwc3IAxp/rZ2/l6yvRGYfaiZpK97yk29DKhlLMhWZj7g496MQk+ayGlfKiHB3gEAEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362801; 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=lI57QIx4Tmy8+5xFZCh0eY4h8Zr3E4Fp8Sh0kGWMcVY=; b=mjWWlkR6ngeIgnlsjYzLyfVLhbGQQpIegwOT1vfaa/iKRuSztXrrLSZ9hst0MmDCwrWXYW9XGFkfKONyc3wN8fi71NY4oWDrJwjT7/DSK2/fXjwEOaL64kqn7Epk/ZKRsrVpzqfiwX/8vZrUVQvZfQkJoxm+/XfVX29ggT9Ojiw= 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 1565362801504247.64746902539503; Fri, 9 Aug 2019 08:00:01 -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 1hw6MU-0007bC-0B; Fri, 09 Aug 2019 14:59:22 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M5-0006ia-Uq for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:57 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 320972a6-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:55 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 738CBB034; Fri, 9 Aug 2019 14:58:49 +0000 (UTC) X-Inumbo-ID: 320972a6-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:17 +0200 Message-Id: <20190809145833.1020-33-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 32/48] xen/sched: modify cpupool_domain_cpumask() to be an unit mask 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" cpupool_domain_cpumask() is used by scheduling to select cpus or to iterate over cpus. In order to support scheduling units spanning multiple cpus let cpupool_domain_cpumask() return a cpumask with only one bit set per scheduling resource. Signed-off-by: Juergen Gross --- xen/common/cpupool.c | 29 ++++++++++++++++++++--------- xen/common/schedule.c | 5 +++-- xen/include/xen/sched-if.h | 5 ++++- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c index e0f8eec57b..17d671585a 100644 --- a/xen/common/cpupool.c +++ b/xen/common/cpupool.c @@ -38,26 +38,35 @@ DEFINE_PER_CPU(struct cpupool *, cpupool); =20 #define cpupool_dprintk(x...) ((void)0) =20 +static void free_cpupool_struct(struct cpupool *c) +{ + if ( c ) + { + free_cpumask_var(c->res_valid); + free_cpumask_var(c->cpu_valid); + } + xfree(c); +} + static struct cpupool *alloc_cpupool_struct(void) { struct cpupool *c =3D xzalloc(struct cpupool); =20 - if ( !c || !zalloc_cpumask_var(&c->cpu_valid) ) + if ( !c ) + return NULL; + + zalloc_cpumask_var(&c->cpu_valid); + zalloc_cpumask_var(&c->res_valid); + + if ( !c->cpu_valid || !c->res_valid ) { - xfree(c); + free_cpupool_struct(c); c =3D NULL; } =20 return c; } =20 -static void free_cpupool_struct(struct cpupool *c) -{ - if ( c ) - free_cpumask_var(c->cpu_valid); - xfree(c); -} - /* * find a cpupool by it's id. to be called with cpupool lock held * if exact is not specified, the first cpupool with an id larger or equal= to @@ -271,6 +280,7 @@ static int cpupool_assign_cpu_locked(struct cpupool *c,= unsigned int cpu) cpupool_cpu_moving =3D NULL; } cpumask_set_cpu(cpu, c->cpu_valid); + cpumask_and(c->res_valid, c->cpu_valid, sched_res_mask); =20 rcu_read_lock(&domlist_read_lock); for_each_domain_in_cpupool(d, c) @@ -365,6 +375,7 @@ static int cpupool_unassign_cpu_prologue(struct cpupool= *c, unsigned int cpu) atomic_inc(&c->refcnt); cpupool_cpu_moving =3D c; cpumask_clear_cpu(cpu, c->cpu_valid); + cpumask_and(c->res_valid, c->cpu_valid, sched_res_mask); =20 out: spin_unlock(&cpupool_lock); diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 1f45fc7373..bbc9eb90e4 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -57,6 +57,7 @@ integer_param("sched_ratelimit_us", sched_ratelimit_us); =20 /* Number of vcpus per struct sched_unit. */ static unsigned int __read_mostly sched_granularity =3D 1; +const cpumask_t *sched_res_mask =3D &cpumask_all; =20 /* Common lock for free cpus. */ static DEFINE_SPINLOCK(sched_free_cpu_lock); @@ -410,9 +411,9 @@ static unsigned int sched_select_initial_cpu(const stru= ct vcpu *v) cpumask_clear(cpus); for_each_node_mask ( node, d->node_affinity ) cpumask_or(cpus, cpus, &node_to_cpumask(node)); - cpumask_and(cpus, cpus, cpupool_domain_cpumask(d)); + cpumask_and(cpus, cpus, d->cpupool->cpu_valid); if ( cpumask_empty(cpus) ) - cpumask_copy(cpus, cpupool_domain_cpumask(d)); + cpumask_copy(cpus, d->cpupool->cpu_valid); =20 if ( v->vcpu_id =3D=3D 0 ) cpu_ret =3D cpumask_first(cpus); diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index e1d61a05b7..ae46b5395f 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -22,6 +22,8 @@ extern cpumask_t cpupool_free_cpus; #define SCHED_DEFAULT_RATELIMIT_US 1000 extern int sched_ratelimit_us; =20 +/* Scheduling resource mask. */ +extern const cpumask_t *sched_res_mask; =20 /* * In order to allow a scheduler to remap the lock->cpu mapping, @@ -520,6 +522,7 @@ struct cpupool int cpupool_id; unsigned int n_dom; cpumask_var_t cpu_valid; /* all cpus assigned to pool */ + cpumask_var_t res_valid; /* all scheduling resources of pool */ struct cpupool *next; struct scheduler *sched; atomic_t refcnt; @@ -535,7 +538,7 @@ static inline cpumask_t* cpupool_domain_cpumask(const s= truct domain *d) * be interested in calling this for the idle domain. */ ASSERT(d->cpupool !=3D NULL); - return d->cpupool->cpu_valid; + return d->cpupool->res_valid; } =20 /* --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362795; cv=none; d=zoho.com; s=zohoarc; b=Xskq4J6HazUtXJBkNdFlhuvKAujBWWzsDiKlPYQwXfk3use1k0ej+1MokmG6tCgkYU9TVpdUpEBFrzzHLv0DjvePCwYkBYXSxIx1iNYquAr9BnClT6yd0Duj8JmXZOQAUGZ3bTCiM/QfxACbnwo/3RMPCxcjBfzcxGg5X4VeTHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362795; 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=I7f9wKevQUIU/KZ2NrK1cFGowNLlybNbUXX2FpNIE8A=; b=Db+CnE+4YSDSxAQcfcLhv8KL22I9zKkcImZm70wxXQ69ASHx8yT1U3YuioiuKBcSX7MyndTrqpRJPtNuHPI9Am4onFIeIniwedYkMD4DcXny331g4eI1873CpAbnynYfRxRlheionwHxKXdmjiO8NuxCLNV5GZc2rqH5gauKrq8= 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 1565362795777404.2311401872063; Fri, 9 Aug 2019 07:59:55 -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 1hw6MO-0007Nb-7T; Fri, 09 Aug 2019 14:59:16 +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 1hw6M4-0006f9-3F for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:56 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 323b95aa-bab6-11e9-9a46-c7632f194d8c; Fri, 09 Aug 2019 14:58:50 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A2CF6B05E; Fri, 9 Aug 2019 14:58:49 +0000 (UTC) X-Inumbo-ID: 323b95aa-bab6-11e9-9a46-c7632f194d8c X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:18 +0200 Message-Id: <20190809145833.1020-34-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 33/48] xen/sched: support allocating multiple vcpus into one 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 , George Dunlap , Dario Faggioli 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" With a scheduling granularity greater than 1 multiple vcpus share the same struct sched_unit. Support that. Setting the initial processor must be done carefully: we can't use sched_set_res() as that relies on for_each_sched_unit_vcpu() which in turn needs the vcpu already as a member of the domain's vcpu linked list, which isn't the case. Signed-off-by: Juergen Gross --- xen/common/schedule.c | 85 +++++++++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 65 insertions(+), 20 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index bbc9eb90e4..c6cd357bc8 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -335,10 +335,26 @@ static void sched_spin_unlock_double(spinlock_t *lock= 1, spinlock_t *lock2, spin_unlock_irqrestore(lock1, flags); } =20 -static void sched_free_unit(struct sched_unit *unit) +static void sched_free_unit(struct sched_unit *unit, struct vcpu *v) { struct sched_unit *prev_unit; struct domain *d =3D unit->domain; + struct vcpu *vunit; + unsigned int cnt =3D 0; + + /* Don't count to be released vcpu, might be not in vcpu list yet. */ + for_each_sched_unit_vcpu ( unit, vunit ) + if ( vunit !=3D v ) + cnt++; + + v->sched_unit =3D NULL; + unit->runstate_cnt[v->runstate.state]--; + + if ( cnt ) + return; + + if ( unit->vcpu_list =3D=3D v ) + unit->vcpu_list =3D v->next_in_list; =20 if ( d->sched_unit_list =3D=3D unit ) d->sched_unit_list =3D unit->next_in_list; @@ -354,8 +370,6 @@ static void sched_free_unit(struct sched_unit *unit) } } =20 - unit->vcpu_list->sched_unit =3D NULL; - free_cpumask_var(unit->cpu_hard_affinity); free_cpumask_var(unit->cpu_hard_affinity_saved); free_cpumask_var(unit->cpu_soft_affinity); @@ -363,19 +377,38 @@ static void sched_free_unit(struct sched_unit *unit) xfree(unit); } =20 +static void sched_unit_add_vcpu(struct sched_unit *unit, struct vcpu *v) +{ + v->sched_unit =3D unit; + if ( !unit->vcpu_list || unit->vcpu_list->vcpu_id > v->vcpu_id ) + { + unit->vcpu_list =3D v; + unit->unit_id =3D v->vcpu_id; + } + unit->runstate_cnt[v->runstate.state]++; +} + static struct sched_unit *sched_alloc_unit(struct vcpu *v) { struct sched_unit *unit, **prev_unit; struct domain *d =3D v->domain; =20 + for_each_sched_unit ( d, unit ) + if ( unit->vcpu_list->vcpu_id / sched_granularity =3D=3D + v->vcpu_id / sched_granularity ) + break; + + if ( unit ) + { + sched_unit_add_vcpu(unit, v); + return unit; + } + if ( (unit =3D xzalloc(struct sched_unit)) =3D=3D NULL ) return NULL; =20 - v->sched_unit =3D unit; - unit->vcpu_list =3D v; - unit->unit_id =3D v->vcpu_id; + sched_unit_add_vcpu(unit, v); unit->domain =3D d; - unit->runstate_cnt[v->runstate.state]++; =20 for ( prev_unit =3D &d->sched_unit_list; *prev_unit; prev_unit =3D &(*prev_unit)->next_in_list ) @@ -394,7 +427,7 @@ static struct sched_unit *sched_alloc_unit(struct vcpu = *v) return unit; =20 fail: - sched_free_unit(unit); + sched_free_unit(unit, v); return NULL; } =20 @@ -444,20 +477,25 @@ int sched_init_vcpu(struct vcpu *v) else processor =3D sched_select_initial_cpu(v); =20 - sched_set_res(unit, get_sched_res(processor)); - /* Initialise the per-vcpu timers. */ - init_timer(&v->periodic_timer, vcpu_periodic_timer_fn, - v, v->processor); - init_timer(&v->singleshot_timer, vcpu_singleshot_timer_fn, - v, v->processor); - init_timer(&v->poll_timer, poll_timer_fn, - v, v->processor); + init_timer(&v->periodic_timer, vcpu_periodic_timer_fn, v, processor); + init_timer(&v->singleshot_timer, vcpu_singleshot_timer_fn, v, processo= r); + init_timer(&v->poll_timer, poll_timer_fn, v, processor); + + /* If this is not the first vcpu of the unit we are done. */ + if ( unit->priv !=3D NULL ) + { + v->processor =3D processor; + return 0; + } + + /* The first vcpu of an unit can be set via sched_set_res(). */ + sched_set_res(unit, get_sched_res(processor)); =20 unit->priv =3D sched_alloc_vdata(dom_scheduler(d), unit, d->sched_priv= ); if ( unit->priv =3D=3D NULL ) { - sched_free_unit(unit); + sched_free_unit(unit, v); return 1; } =20 @@ -611,9 +649,16 @@ void sched_destroy_vcpu(struct vcpu *v) kill_timer(&v->poll_timer); if ( test_and_clear_bool(v->is_urgent) ) atomic_dec(&get_sched_res(v->processor)->urgent_count); - sched_remove_unit(vcpu_scheduler(v), unit); - sched_free_vdata(vcpu_scheduler(v), unit->priv); - sched_free_unit(unit); + /* + * Vcpus are being destroyed top-down. So being the first vcpu of an u= nit + * is the same as being the only one. + */ + if ( unit->vcpu_list =3D=3D v ) + { + sched_remove_unit(vcpu_scheduler(v), unit); + sched_free_vdata(vcpu_scheduler(v), unit->priv); + sched_free_unit(unit, v); + } } =20 int sched_init_domain(struct domain *d, int poolid) --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362774; cv=none; d=zoho.com; s=zohoarc; b=m6x7bPzGdPT5j/fvEdsw1tTSfvg6LGjbn3hB4llY56bfcsgbdLsolfLZIjQ5mEbtBRCHLfYRmEfT67xxBwnLLbhVuYv21DrtNBcXzILj9lUHgsKtToa/75r+9MXPFHw2sfi7SRdS1obuUpLpVFUSONZiB31eRPEWGPC7MzgneJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362774; 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=jv6Mn0+FaR6+1Ws2eg3WKB5YAHYwrMJeT2eg/gWEP6c=; b=kSR2Ufif5LEE1jm4x2YZawoBEaCnisyooOJiYcooEm4oXB5OAfPWZIROW/nlL4d+0jGNGtnQ+CZ2JPCAh3TellFiKz83MljBFkn47+bAQ/VKacHEd7KTdprSM1d8aDBK9h+GgScaoQnZfbth+yfXDoBrSvWYMIdmUYMdPZnwKH0= 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 1565362774603647.772554665966; Fri, 9 Aug 2019 07:59:34 -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 1hw6M6-0006kV-Q0; Fri, 09 Aug 2019 14:58:58 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M0-0006Y8-B3 for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:52 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 32421352-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:50 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D79DEB0B3; Fri, 9 Aug 2019 14:58:49 +0000 (UTC) X-Inumbo-ID: 32421352-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:19 +0200 Message-Id: <20190809145833.1020-35-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 34/48] xen/sched: add a percpu resource index 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 , George Dunlap , Dario Faggioli 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" Add a percpu variable holding the index of the cpu in the current sched_resource structure. This index is used to get the correct vcpu of a sched_unit on a specific cpu. For now this index will be zero for all cpus, but with core scheduling it will be possible to have higher values, too. Signed-off-by: Juergen Gross --- RFC V2: new patch (carved out from RFC V1 patch 49) --- xen/common/schedule.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index c6cd357bc8..13d3392640 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -71,6 +71,7 @@ static void poll_timer_fn(void *data); /* This is global for now so that private implementations can reach it */ DEFINE_PER_CPU(struct scheduler *, scheduler); DEFINE_PER_CPU_READ_MOSTLY(struct sched_resource *, sched_res); +static DEFINE_PER_CPU_READ_MOSTLY(unsigned int, sched_res_idx); =20 /* Scratch space for cpumasks. */ DEFINE_PER_CPU(cpumask_t, cpumask_scratch); @@ -132,6 +133,12 @@ static struct scheduler sched_idle_ops =3D { .switch_sched =3D sched_idle_switch_sched, }; =20 +static inline struct vcpu *sched_unit2vcpu_cpu(struct sched_unit *unit, + unsigned int cpu) +{ + return unit->domain->vcpu[unit->unit_id + per_cpu(sched_res_idx, cpu)]; +} + static inline struct scheduler *dom_scheduler(const struct domain *d) { if ( likely(d->cpupool !=3D NULL) ) @@ -1988,7 +1995,7 @@ static void sched_slave(void) =20 pcpu_schedule_unlock_irq(lock, cpu); =20 - sched_context_switch(vprev, next->vcpu_list, now); + sched_context_switch(vprev, sched_unit2vcpu_cpu(next, cpu), now); } =20 /* @@ -2047,7 +2054,7 @@ static void schedule(void) =20 pcpu_schedule_unlock_irq(lock, cpu); =20 - vnext =3D next->vcpu_list; + vnext =3D sched_unit2vcpu_cpu(next, cpu); sched_context_switch(vprev, vnext, now); } =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362807; cv=none; d=zoho.com; s=zohoarc; b=UVIkMKXEJjbSa1wtr3KNxe0hsiQCoSDyfUqMIE93Mwnh6PJ4IOBHjhZvpeNRLoVCAQvOv/NCEpvOwvflkLcQGVEiQm0QE+EWuRfiXKT4NzYSWT5Afuex7Z2GyUIJaO1cjSo+l8t9c6ADCRz60jS0gPpbC5A65V7Xigfj4mNpTQs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362807; 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=6ROOZQzno1T1IwzX6F4zyrGlTFLjmA7/fFDSrYM/FoI=; b=FdajTwPsWoSadT1rfzZWbx0I5CPFJVvjy1JhF62aReTwdfTwgGxQmBTXeM3X3uuHqh+6sBTrDDRTXRZZRVI+N1f5O6R98JCJx373usvOG/DYxSYu9kBkIqD88UeKnEEqi0aWKdWUpGtFxF2qK+h1TFlfJxMTWq+pY+nLRPE98xs= 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 1565362807069999.2112169482045; Fri, 9 Aug 2019 08:00:07 -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 1hw6MV-0007f7-M4; Fri, 09 Aug 2019 14:59:23 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M6-0006j6-9G for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:58 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 3290b7ba-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:51 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 57F5AAFF3; Fri, 9 Aug 2019 14:58:50 +0000 (UTC) X-Inumbo-ID: 3290b7ba-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:20 +0200 Message-Id: <20190809145833.1020-36-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 35/48] xen/sched: add fall back to idle vcpu when scheduling 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= 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" When scheduling an unit with multiple vcpus there is no guarantee all vcpus are available (e.g. above maxvcpus or vcpu offline). Fall back to idle vcpu of the current cpu in that case. This requires to store the correct schedule_unit pointer in the idle vcpu as long as it used as fallback vcpu. In order to modify the runstates of the correct vcpus when switching schedule units merge sched_unit_runstate_change() into sched_switch_units() and loop over the affected physical cpus instead of the unit's vcpus. This in turn requires an access function to the current variable of other cpus. Today context_saved() is called in case previous and next vcpus differ when doing a context switch. With an idle vcpu being capable to be a substitute for an offline vcpu this is problematic when switching to an idle scheduling unit. An idle previous vcpu leaves us in doubt which schedule unit was active previously, so save the previous unit pointer in the per-schedule resource area and use its value being non-NULL as a hint whether context_saved() should be called. When running an idle vcpu in a non-idle scheduling unit use a specific guest idle loop not performing any tasklets and livepatching in order to avoid populating the cpu caches with memory used by other domains (as far as possible). Softirqs are considered to be save. In order to avoid livepatching when going to guest idle another variant of reset_stack_and_jump() not calling check_for_livepatch_work is needed. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- RFC V2: - new patch (Andrew Cooper) V1: - use urgent_count to select correct idle routine (Jan Beulich) V2: - set vcpu->is_running in context_saved() - introduce reset_stack_and_jump_nolp() (Jan Beulich) - readd scrubbing (Jan Beulich, Andrew Cooper) - get_cpu_current() _NOT_ moved to include/asm-x86/current.h as the needed reference of stack_base[] results in a #include hell --- xen/arch/x86/domain.c | 23 ++++++ xen/common/schedule.c | 169 ++++++++++++++++++++++++++++++--------= ---- xen/include/asm-arm/current.h | 1 + xen/include/asm-x86/current.h | 19 ++++- xen/include/asm-x86/smp.h | 3 + xen/include/xen/sched-if.h | 4 +- xen/include/xen/sched.h | 1 + 7 files changed, 166 insertions(+), 54 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index c45bec8864..7b24d8fa48 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -159,6 +159,25 @@ static void idle_loop(void) } } =20 +/* + * Idle loop for siblings in active schedule units. + * We don't do any standard idle work like tasklets or livepatching. + */ +static void guest_idle_loop(void) +{ + unsigned int cpu =3D smp_processor_id(); + + for ( ; ; ) + { + ASSERT(!cpu_is_offline(cpu)); + + if ( !softirq_pending(cpu) && !scrub_free_pages() && + !softirq_pending(cpu)) + sched_guest_idle(pm_idle, cpu); + do_softirq(); + } +} + void startup_cpu_idle_loop(void) { struct vcpu *v =3D current; @@ -172,6 +191,10 @@ void startup_cpu_idle_loop(void) =20 static void noreturn continue_idle_domain(struct vcpu *v) { + /* Idle vcpus might be attached to non-idle units! */ + if ( !is_idle_domain(v->sched_unit->domain) ) + reset_stack_and_jump_nolp(guest_idle_loop); + reset_stack_and_jump(idle_loop); } =20 diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 13d3392640..5cd7d2d857 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -133,10 +133,21 @@ static struct scheduler sched_idle_ops =3D { .switch_sched =3D sched_idle_switch_sched, }; =20 +static inline struct vcpu *unit2vcpu_cpu(struct sched_unit *unit, + unsigned int cpu) +{ + unsigned int idx =3D unit->unit_id + per_cpu(sched_res_idx, cpu); + const struct domain *d =3D unit->domain; + + return (idx < d->max_vcpus) ? d->vcpu[idx] : NULL; +} + static inline struct vcpu *sched_unit2vcpu_cpu(struct sched_unit *unit, unsigned int cpu) { - return unit->domain->vcpu[unit->unit_id + per_cpu(sched_res_idx, cpu)]; + struct vcpu *v =3D unit2vcpu_cpu(unit, cpu); + + return (v && v->new_state =3D=3D RUNSTATE_running) ? v : idle_vcpu[cpu= ]; } =20 static inline struct scheduler *dom_scheduler(const struct domain *d) @@ -256,8 +267,11 @@ static inline void vcpu_runstate_change( =20 trace_runstate_change(v, new_state); =20 - unit->runstate_cnt[v->runstate.state]--; - unit->runstate_cnt[new_state]++; + if ( !is_idle_vcpu(v) ) + { + unit->runstate_cnt[v->runstate.state]--; + unit->runstate_cnt[new_state]++; + } =20 delta =3D new_entry_time - v->runstate.state_entry_time; if ( delta > 0 ) @@ -269,19 +283,11 @@ static inline void vcpu_runstate_change( v->runstate.state =3D new_state; } =20 -static inline void sched_unit_runstate_change(struct sched_unit *unit, - bool running, s_time_t new_entry_time) +void sched_guest_idle(void (*idle) (void), unsigned int cpu) { - struct vcpu *v; - - for_each_sched_unit_vcpu ( unit, v ) - if ( running ) - vcpu_runstate_change(v, v->new_state, new_entry_time); - else - vcpu_runstate_change(v, - ((v->pause_flags & VPF_blocked) ? RUNSTATE_blocked : - (vcpu_runnable(v) ? RUNSTATE_runnable : RUNSTATE_offline)= ), - new_entry_time); + atomic_inc(&get_sched_res(cpu)->urgent_count); + idle(); + atomic_dec(&get_sched_res(cpu)->urgent_count); } =20 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate) @@ -519,6 +525,7 @@ int sched_init_vcpu(struct vcpu *v) if ( is_idle_domain(d) ) { get_sched_res(v->processor)->curr =3D unit; + get_sched_res(v->processor)->sched_unit_idle =3D unit; v->is_running =3D 1; unit->is_running =3D 1; unit->state_entry_time =3D NOW(); @@ -1748,32 +1755,65 @@ static void sched_switch_units(struct sched_resourc= e *sd, struct sched_unit *next, struct sched_unit = *prev, s_time_t now) { - sd->curr =3D next; - - TRACE_3D(TRC_SCHED_SWITCH_INFPREV, prev->domain->domain_id, prev->unit= _id, - now - prev->state_entry_time); - TRACE_4D(TRC_SCHED_SWITCH_INFNEXT, next->domain->domain_id, next->unit= _id, - (next->vcpu_list->runstate.state =3D=3D RUNSTATE_runnable) ? - (now - next->state_entry_time) : 0, prev->next_time); + int cpu; =20 ASSERT(unit_running(prev)); =20 - TRACE_4D(TRC_SCHED_SWITCH, prev->domain->domain_id, prev->unit_id, - next->domain->domain_id, next->unit_id); + if ( prev !=3D next ) + { + sd->curr =3D next; + sd->prev =3D prev; =20 - sched_unit_runstate_change(prev, false, now); + TRACE_3D(TRC_SCHED_SWITCH_INFPREV, prev->domain->domain_id, + prev->unit_id, now - prev->state_entry_time); + TRACE_4D(TRC_SCHED_SWITCH_INFNEXT, next->domain->domain_id, + next->unit_id, + (next->vcpu_list->runstate.state =3D=3D RUNSTATE_runnable= ) ? + (now - next->state_entry_time) : 0, prev->next_time); + TRACE_4D(TRC_SCHED_SWITCH, prev->domain->domain_id, prev->unit_id, + next->domain->domain_id, next->unit_id); =20 - ASSERT(!unit_running(next)); - sched_unit_runstate_change(next, true, now); + ASSERT(!unit_running(next)); =20 - /* - * NB. Don't add any trace records from here until the actual context - * switch, else lost_records resume will not work properly. - */ + /* + * NB. Don't add any trace records from here until the actual cont= ext + * switch, else lost_records resume will not work properly. + */ =20 - ASSERT(!next->is_running); - next->vcpu_list->is_running =3D 1; - next->is_running =3D 1; + ASSERT(!next->is_running); + next->is_running =3D 1; + + if ( is_idle_unit(prev) ) + { + prev->runstate_cnt[RUNSTATE_running] =3D 0; + prev->runstate_cnt[RUNSTATE_runnable] =3D sched_granularity; + } + if ( is_idle_unit(next) ) + { + next->runstate_cnt[RUNSTATE_running] =3D sched_granularity; + next->runstate_cnt[RUNSTATE_runnable] =3D 0; + } + } + + for_each_cpu ( cpu, sd->cpus ) + { + struct vcpu *vprev =3D get_cpu_current(cpu); + struct vcpu *vnext =3D sched_unit2vcpu_cpu(next, cpu); + + if ( vprev !=3D vnext || vprev->runstate.state !=3D vnext->new_sta= te ) + { + vcpu_runstate_change(vprev, + ((vprev->pause_flags & VPF_blocked) ? RUNSTATE_blocked : + (vcpu_runnable(vprev) ? RUNSTATE_runnable : RUNSTATE_offl= ine)), + now); + vcpu_runstate_change(vnext, vnext->new_state, now); + } + + vnext->is_running =3D 1; + + if ( is_idle_vcpu(vnext) ) + vnext->sched_unit =3D next; + } } =20 static bool sched_tasklet_check_cpu(unsigned int cpu) @@ -1829,29 +1869,48 @@ static struct sched_unit *do_schedule(struct sched_= unit *prev, s_time_t now, if ( prev->next_time >=3D 0 ) /* -ve means no limit */ set_timer(&sd->s_timer, now + prev->next_time); =20 - if ( likely(prev !=3D next) ) - sched_switch_units(sd, next, prev, now); + sched_switch_units(sd, next, prev, now); =20 return next; } =20 -static void context_saved(struct vcpu *prev) +static void context_saved(struct sched_resource *sd, struct vcpu *vprev, + struct vcpu *vnext) { - struct sched_unit *unit =3D prev->sched_unit; + struct sched_unit *unit =3D sd->prev; + int cpu; =20 /* Clear running flag /after/ writing context to memory. */ smp_wmb(); =20 - prev->is_running =3D 0; + if ( !sd->prev ) + { + if ( vprev !=3D vnext ) + vprev->is_running =3D 0; + return; + } + + for_each_cpu ( cpu, sd->cpus ) + { + struct vcpu *v =3D unit2vcpu_cpu(unit, cpu); + + if ( !v || !v->is_running ) + v =3D idle_vcpu[cpu]; + if ( v !=3D vnext ) + v->is_running =3D 0; + } unit->is_running =3D 0; unit->state_entry_time =3D NOW(); + sd->prev =3D NULL; =20 /* Check for migration request /after/ clearing running flag. */ smp_mb(); =20 - sched_context_saved(vcpu_scheduler(prev), unit); + sched_context_saved(unit_scheduler(unit), unit); =20 - sched_unit_migrate_finish(unit); + /* Idle never migrates and idle vcpus might belong to other units. */ + if ( !is_idle_unit(unit) ) + sched_unit_migrate_finish(unit); } =20 /* @@ -1868,6 +1927,7 @@ static void context_saved(struct vcpu *prev) void sched_context_switched(struct vcpu *vprev, struct vcpu *vnext) { struct sched_unit *next =3D vnext->sched_unit; + struct sched_resource *sd =3D get_sched_res(smp_processor_id()); =20 if ( atomic_read(&next->rendezvous_out_cnt) ) { @@ -1876,20 +1936,22 @@ void sched_context_switched(struct vcpu *vprev, str= uct vcpu *vnext) /* Call context_saved() before releasing other waiters. */ if ( cnt =3D=3D 1 ) { - if ( vprev !=3D vnext ) - context_saved(vprev); + context_saved(sd, vprev, vnext); atomic_set(&next->rendezvous_out_cnt, 0); } else while ( atomic_read(&next->rendezvous_out_cnt) ) cpu_relax(); } - else if ( vprev !=3D vnext && sched_granularity =3D=3D 1 ) - context_saved(vprev); + else + context_saved(sd, vprev, vnext); + + if ( is_idle_vcpu(vprev) && vprev !=3D vnext ) + vprev->sched_unit =3D sd->sched_unit_idle; } =20 static void sched_context_switch(struct vcpu *vprev, struct vcpu *vnext, - s_time_t now) + bool reset_idle_unit, s_time_t now) { if ( unlikely(vprev =3D=3D vnext) ) { @@ -1898,6 +1960,11 @@ static void sched_context_switch(struct vcpu *vprev,= struct vcpu *vnext, now - vprev->runstate.state_entry_time, vprev->sched_unit->next_time); sched_context_switched(vprev, vnext); + + if ( reset_idle_unit ) + vnext->sched_unit =3D + get_sched_res(smp_processor_id())->sched_unit_idle; + trace_continue_running(vnext); return continue_running(vprev); } @@ -1956,7 +2023,7 @@ static struct sched_unit *sched_wait_rendezvous_in(st= ruct sched_unit *prev, pcpu_schedule_unlock_irq(*lock, cpu); =20 raise_softirq(SCHED_SLAVE_SOFTIRQ); - sched_context_switch(vprev, vprev, now); + sched_context_switch(vprev, vprev, false, now); } =20 pcpu_schedule_unlock_irq(*lock, cpu); @@ -1995,7 +2062,8 @@ static void sched_slave(void) =20 pcpu_schedule_unlock_irq(lock, cpu); =20 - sched_context_switch(vprev, sched_unit2vcpu_cpu(next, cpu), now); + sched_context_switch(vprev, sched_unit2vcpu_cpu(next, cpu), + is_idle_unit(next) && !is_idle_unit(prev), now); } =20 /* @@ -2055,7 +2123,8 @@ static void schedule(void) pcpu_schedule_unlock_irq(lock, cpu); =20 vnext =3D sched_unit2vcpu_cpu(next, cpu); - sched_context_switch(vprev, vnext, now); + sched_context_switch(vprev, vnext, + !is_idle_unit(prev) && is_idle_unit(next), now); } =20 /* The scheduler timer: force a run through the scheduler */ @@ -2126,6 +2195,7 @@ static int cpu_schedule_up(unsigned int cpu) */ =20 sd->curr =3D idle_vcpu[cpu]->sched_unit; + sd->sched_unit_idle =3D idle_vcpu[cpu]->sched_unit; =20 sd->sched_priv =3D NULL; =20 @@ -2295,6 +2365,7 @@ void __init scheduler_init(void) if ( vcpu_create(idle_domain, 0) =3D=3D NULL ) BUG(); get_sched_res(0)->curr =3D idle_vcpu[0]->sched_unit; + get_sched_res(0)->sched_unit_idle =3D idle_vcpu[0]->sched_unit; } =20 /* diff --git a/xen/include/asm-arm/current.h b/xen/include/asm-arm/current.h index 1653e89d30..88beb4645a 100644 --- a/xen/include/asm-arm/current.h +++ b/xen/include/asm-arm/current.h @@ -18,6 +18,7 @@ DECLARE_PER_CPU(struct vcpu *, curr_vcpu); =20 #define current (this_cpu(curr_vcpu)) #define set_current(vcpu) do { current =3D (vcpu); } while (0) +#define get_cpu_current(cpu) (per_cpu(curr_vcpu, cpu)) =20 /* Per-VCPU state that lives at the top of the stack */ struct cpu_info { diff --git a/xen/include/asm-x86/current.h b/xen/include/asm-x86/current.h index f3508c3c08..0b47485337 100644 --- a/xen/include/asm-x86/current.h +++ b/xen/include/asm-x86/current.h @@ -77,6 +77,11 @@ struct cpu_info { /* get_stack_bottom() must be 16-byte aligned */ }; =20 +static inline struct cpu_info *get_cpu_info_from_stack(unsigned long sp) +{ + return (struct cpu_info *)((sp | (STACK_SIZE - 1)) + 1) - 1; +} + static inline struct cpu_info *get_cpu_info(void) { #ifdef __clang__ @@ -87,7 +92,7 @@ static inline struct cpu_info *get_cpu_info(void) register unsigned long sp asm("rsp"); #endif =20 - return (struct cpu_info *)((sp | (STACK_SIZE - 1)) + 1) - 1; + return get_cpu_info_from_stack(sp); } =20 #define get_current() (get_cpu_info()->current_vcpu) @@ -124,16 +129,22 @@ unsigned long get_stack_dump_bottom (unsigned long sp= ); # define CHECK_FOR_LIVEPATCH_WORK "" #endif =20 -#define reset_stack_and_jump(__fn) \ +#define switch_stack_and_jump(fn, instr) \ ({ \ __asm__ __volatile__ ( \ "mov %0,%%"__OP"sp;" \ - CHECK_FOR_LIVEPATCH_WORK \ + instr \ "jmp %c1" \ - : : "r" (guest_cpu_user_regs()), "i" (__fn) : "memory" ); \ + : : "r" (guest_cpu_user_regs()), "i" (fn) : "memory" ); \ unreachable(); \ }) =20 +#define reset_stack_and_jump(fn) \ + switch_stack_and_jump(fn, CHECK_FOR_LIVEPATCH_WORK) + +#define reset_stack_and_jump_nolp(fn) \ + switch_stack_and_jump(fn, "") + /* * Which VCPU's state is currently running on each CPU? * This is not necesasrily the same as 'current' as a CPU may be diff --git a/xen/include/asm-x86/smp.h b/xen/include/asm-x86/smp.h index 9f533f9072..51a31ab00a 100644 --- a/xen/include/asm-x86/smp.h +++ b/xen/include/asm-x86/smp.h @@ -76,6 +76,9 @@ void set_nr_sockets(void); /* Representing HT and core siblings in each socket. */ extern cpumask_t **socket_cpumask; =20 +#define get_cpu_current(cpu) \ + (get_cpu_info_from_stack((unsigned long)stack_base[cpu])->current_vcpu) + #endif /* !__ASSEMBLY__ */ =20 #endif diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index ae46b5395f..3ac7757c0d 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -39,6 +39,8 @@ struct sched_resource { spinlock_t *schedule_lock, _lock; struct sched_unit *curr; /* current task = */ + struct sched_unit *sched_unit_idle; + struct sched_unit *prev; /* previous task = */ void *sched_priv; struct timer s_timer; /* scheduling timer = */ atomic_t urgent_count; /* how many urgent vcpus = */ @@ -179,7 +181,7 @@ static inline void sched_clear_pause_flags_atomic(struc= t sched_unit *unit, =20 static inline struct sched_unit *sched_idle_unit(unsigned int cpu) { - return idle_vcpu[cpu]->sched_unit; + return get_sched_res(cpu)->sched_unit_idle; } =20 static inline unsigned int sched_get_resource_cpu(unsigned int cpu) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 7585bd81a2..ed0535946f 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -922,6 +922,7 @@ void restore_vcpu_affinity(struct domain *d); void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate= ); uint64_t get_cpu_idle_time(unsigned int cpu); bool sched_has_urgent_vcpu(void); +void sched_guest_idle(void (*idle) (void), unsigned int cpu); =20 /* * Used by idle loop to decide whether there is work to do: --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362777; cv=none; d=zoho.com; s=zohoarc; b=KljS3m5c06bymVOaMmUCObwfkMkTyCCQltvw4EdXRIB2KymKW5XyYZVErmXMZ+Pry7zZswJ+36lmlhut/wZLTIfSuEUlg+xIVyZW5K2KPsKOKxZLAtadeM5aj4ytF0xYlO3ikbdhzTR5+ochHXEv6/Q59af8OMPQiwgmCKJDxT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362777; 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=qGqfd9Q8fG20ONhFcKb1BMP8czsvFRKLbiuHW0dwS+0=; b=Cf/YER9dNtutphWKnR0o9IIuGxW5yN6tELFnEPTmYpEIdavcGq9pUZUmvba9znfrojdbhy9iTcxjMab7v33oB89AbepfjtEey4pZV1Sn3W8g9eRvzP7DQBesYxIbZTDBVRs2gF+iTzgATG08m+RmouucbbqaIqkS8fiaxdXPlC4= 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 1565362777076189.52053683038616; Fri, 9 Aug 2019 07:59:37 -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 1hw6M5-0006iU-Ty; Fri, 09 Aug 2019 14:58:57 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M0-0006YS-Ga for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:52 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 32cc028f-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:51 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B9C04B077; Fri, 9 Aug 2019 14:58:50 +0000 (UTC) X-Inumbo-ID: 32cc028f-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:21 +0200 Message-Id: <20190809145833.1020-37-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 36/48] xen/sched: make vcpu_wake() and vcpu_sleep() core scheduling aware 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" vcpu_wake() and vcpu_sleep() need to be made core scheduling aware: they might need to switch a single vcpu of an already scheduled unit between running and not running. Especially when vcpu_sleep() for a vcpu is being called by a vcpu of the same scheduling unit special care must be taken in order to avoid a deadlock: the vcpu to be put asleep must be forced through a context switch without doing so for the calling vcpu. For this purpose add a vcpu flag handled in sched_slave() and in sched_wait_rendezvous_in() allowing a vcpu of the currently running unit to switch state at a higher priority than a normal schedule event. Use the same mechanism when waking up a vcpu of a currently active unit. While at it make vcpu_sleep_nosync_locked() static as it is used in schedule.c only. Signed-off-by: Juergen Gross --- RFC V2: add vcpu_sleep() handling and force_context_switch flag V2: fix runstate change in sched_force_context_switch() --- xen/common/schedule.c | 125 +++++++++++++++++++++++++++++++++++++++++= +--- xen/include/xen/sched-if.h | 9 ++-- xen/include/xen/sched.h | 2 + 3 files changed, 127 insertions(+), 9 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 5cd7d2d857..fe7ab1b4de 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -714,8 +714,10 @@ void sched_destroy_domain(struct domain *d) } } =20 -void vcpu_sleep_nosync_locked(struct vcpu *v) +static void vcpu_sleep_nosync_locked(struct vcpu *v) { + struct sched_unit *unit =3D v->sched_unit; + ASSERT(spin_is_locked(get_sched_res(v->processor)->schedule_lock)); =20 if ( likely(!vcpu_runnable(v)) ) @@ -723,7 +725,14 @@ void vcpu_sleep_nosync_locked(struct vcpu *v) if ( v->runstate.state =3D=3D RUNSTATE_runnable ) vcpu_runstate_change(v, RUNSTATE_offline, NOW()); =20 - sched_sleep(vcpu_scheduler(v), v->sched_unit); + if ( likely(!unit_runnable(unit)) ) + sched_sleep(vcpu_scheduler(v), unit); + else if ( unit_running(unit) > 1 && v->is_running && + !v->force_context_switch ) + { + v->force_context_switch =3D true; + cpu_raise_softirq(v->processor, SCHED_SLAVE_SOFTIRQ); + } } } =20 @@ -755,16 +764,22 @@ void vcpu_wake(struct vcpu *v) { unsigned long flags; spinlock_t *lock; + struct sched_unit *unit =3D v->sched_unit; =20 TRACE_2D(TRC_SCHED_WAKE, v->domain->domain_id, v->vcpu_id); =20 - lock =3D unit_schedule_lock_irqsave(v->sched_unit, &flags); + lock =3D unit_schedule_lock_irqsave(unit, &flags); =20 if ( likely(vcpu_runnable(v)) ) { if ( v->runstate.state >=3D RUNSTATE_blocked ) vcpu_runstate_change(v, RUNSTATE_runnable, NOW()); - sched_wake(vcpu_scheduler(v), v->sched_unit); + sched_wake(vcpu_scheduler(v), unit); + if ( unit->is_running && !v->is_running && !v->force_context_switc= h ) + { + v->force_context_switch =3D true; + cpu_raise_softirq(v->processor, SCHED_SLAVE_SOFTIRQ); + } } else if ( !(v->pause_flags & VPF_blocked) ) { @@ -772,7 +787,7 @@ void vcpu_wake(struct vcpu *v) vcpu_runstate_change(v, RUNSTATE_offline, NOW()); } =20 - unit_schedule_unlock_irqrestore(lock, flags, v->sched_unit); + unit_schedule_unlock_irqrestore(lock, flags, unit); } =20 void vcpu_unblock(struct vcpu *v) @@ -1981,6 +1996,62 @@ static void sched_context_switch(struct vcpu *vprev,= struct vcpu *vnext, context_switch(vprev, vnext); } =20 +/* + * Force a context switch of a single vcpu of an unit. + * Might be called either if a vcpu of an already running unit is woken up + * or if a vcpu of a running unit is put asleep with other vcpus of the sa= me + * unit still running. + */ +static struct vcpu *sched_force_context_switch(struct vcpu *vprev, + struct vcpu *v, + int cpu, s_time_t now) +{ + v->force_context_switch =3D false; + + if ( vcpu_runnable(v) =3D=3D v->is_running ) + return NULL; + + if ( vcpu_runnable(v) ) + { + if ( is_idle_vcpu(vprev) ) + { + vcpu_runstate_change(vprev, RUNSTATE_runnable, now); + vprev->sched_unit =3D get_sched_res(cpu)->sched_unit_idle; + } + vcpu_runstate_change(v, RUNSTATE_running, now); + } + else + { + /* Make sure not to switch last vcpu of an unit away. */ + if ( unit_running(v->sched_unit) =3D=3D 1 ) + return NULL; + + v->new_state =3D vcpu_runstate_blocked(v); + vcpu_runstate_change(v, v->new_state, now); + v =3D sched_unit2vcpu_cpu(vprev->sched_unit, cpu); + if ( v !=3D vprev ) + { + if ( is_idle_vcpu(vprev) ) + { + vcpu_runstate_change(vprev, RUNSTATE_runnable, now); + vprev->sched_unit =3D get_sched_res(cpu)->sched_unit_idle; + } + else + { + v->sched_unit =3D vprev->sched_unit; + vcpu_runstate_change(v, RUNSTATE_running, now); + } + } + } + + v->is_running =3D 1; + + /* Make sure not to loose another slave call. */ + raise_softirq(SCHED_SLAVE_SOFTIRQ); + + return v; +} + /* * Rendezvous before taking a scheduling decision. * Called with schedule lock held, so all accesses to the rendezvous count= er @@ -1996,6 +2067,7 @@ static struct sched_unit *sched_wait_rendezvous_in(st= ruct sched_unit *prev, s_time_t now) { struct sched_unit *next; + struct vcpu *v; =20 if ( !--prev->rendezvous_in_cnt ) { @@ -2004,8 +2076,28 @@ static struct sched_unit *sched_wait_rendezvous_in(s= truct sched_unit *prev, return next; } =20 + v =3D unit2vcpu_cpu(prev, cpu); while ( prev->rendezvous_in_cnt ) { + if ( v && v->force_context_switch ) + { + struct vcpu *vprev =3D current; + + v =3D sched_force_context_switch(vprev, v, cpu, now); + + if ( v ) + { + /* We'll come back another time, so adjust rendezvous_in_c= nt. */ + prev->rendezvous_in_cnt++; + atomic_set(&prev->rendezvous_out_cnt, 0); + + pcpu_schedule_unlock_irq(*lock, cpu); + + sched_context_switch(vprev, v, false, now); + } + + v =3D unit2vcpu_cpu(prev, cpu); + } /* * Coming from idle might need to do tasklet work. * In order to avoid deadlocks we can't do that here, but have to @@ -2038,10 +2130,11 @@ static struct sched_unit *sched_wait_rendezvous_in(= struct sched_unit *prev, =20 static void sched_slave(void) { - struct vcpu *vprev =3D current; + struct vcpu *v, *vprev =3D current; struct sched_unit *prev =3D vprev->sched_unit, *next; s_time_t now; spinlock_t *lock; + bool do_softirq =3D false; int cpu =3D smp_processor_id(); =20 ASSERT_NOT_IN_ATOMIC(); @@ -2050,9 +2143,29 @@ static void sched_slave(void) =20 now =3D NOW(); =20 + v =3D unit2vcpu_cpu(prev, cpu); + if ( v && v->force_context_switch ) + { + v =3D sched_force_context_switch(vprev, v, cpu, now); + + if ( v ) + { + pcpu_schedule_unlock_irq(lock, cpu); + + sched_context_switch(vprev, v, false, now); + } + + do_softirq =3D true; + } + if ( !prev->rendezvous_in_cnt ) { pcpu_schedule_unlock_irq(lock, cpu); + + /* Check for failed forced context switch. */ + if ( do_softirq ) + raise_softirq(SCHEDULE_SOFTIRQ); + return; } =20 diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 3ac7757c0d..eb6b9ef55c 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -99,6 +99,11 @@ static inline bool unit_runnable(const struct sched_unit= *unit) return false; } =20 +static inline int vcpu_runstate_blocked(struct vcpu *v) +{ + return (v->pause_flags & VPF_blocked) ? RUNSTATE_blocked : RUNSTATE_of= fline; +} + static inline bool unit_runnable_state(const struct sched_unit *unit) { struct vcpu *v; @@ -111,9 +116,7 @@ static inline bool unit_runnable_state(const struct sch= ed_unit *unit) { runnable =3D vcpu_runnable(v); =20 - v->new_state =3D runnable ? RUNSTATE_running - : (v->pause_flags & VPF_blocked) - ? RUNSTATE_blocked : RUNSTATE_offline; + v->new_state =3D runnable ? RUNSTATE_running : vcpu_runstate_block= ed(v); =20 if ( runnable ) ret =3D true; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index ed0535946f..e868646f0e 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -186,6 +186,8 @@ struct vcpu bool is_running; /* VCPU should wake fast (do not deep sleep the CPU). */ bool is_urgent; + /* VCPU must context_switch without scheduling unit. */ + bool force_context_switch; =20 #ifdef VCPU_TRAP_LAST #define VCPU_TRAP_NONE 0 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362776; cv=none; d=zoho.com; s=zohoarc; b=lK/pPuxFooWPQbCxaMD0HvzKEQSuKDc6BtIWIzjaV8Db+NGxd4cX0ZU5PA7Q641Uz5wqhwzlvr4H7hAeR8j8ZINQN3wKFrbzbzhhYXdNJS1Q82T+Fmjdogb2YAy8e2Mz63ZcyVg6UkhPDiPVicjISg9641S1SkJDhXMXkg+ITsE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362776; 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=2Lws+WxQT0zdW2r8eY1eCswEywpL4fUqxSUhUBMu+ZA=; b=Von9oSDw/iiQ4L5XyhFKtoemLPPVorU4MaqGRbO0B3w3vAMtXIIDRrl6EJQ9A+N5TkgyPbqms4RpK0ACp7uYlNnXaKWGIBxlA/+WvVlHaf6ktEe207kwsNVpWzlLh0gw1AN5BCMPhNJkm0C5KJU+vMlQOrqadtWC14sslDsMklU= 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 1565362776133284.6399567642751; Fri, 9 Aug 2019 07:59:36 -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 1hw6M7-0006mK-Oj; Fri, 09 Aug 2019 14:58:59 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M0-0006YU-Hh for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:52 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 32e650c0-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:51 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id EB27FB04C; Fri, 9 Aug 2019 14:58:50 +0000 (UTC) X-Inumbo-ID: 32e650c0-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:22 +0200 Message-Id: <20190809145833.1020-38-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 37/48] xen/sched: carve out freeing sched_unit memory into dedicated function 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 , George Dunlap , Dario Faggioli 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" We'll need a way to free a sched_unit structure without side effects in a later patch. Signed-off-by: Juergen Gross --- RFC V2: new patch, carved out from RFC V1 patch 49 --- xen/common/schedule.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index fe7ab1b4de..be5f03b626 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -348,26 +348,10 @@ static void sched_spin_unlock_double(spinlock_t *lock= 1, spinlock_t *lock2, spin_unlock_irqrestore(lock1, flags); } =20 -static void sched_free_unit(struct sched_unit *unit, struct vcpu *v) +static void sched_free_unit_mem(struct sched_unit *unit) { struct sched_unit *prev_unit; struct domain *d =3D unit->domain; - struct vcpu *vunit; - unsigned int cnt =3D 0; - - /* Don't count to be released vcpu, might be not in vcpu list yet. */ - for_each_sched_unit_vcpu ( unit, vunit ) - if ( vunit !=3D v ) - cnt++; - - v->sched_unit =3D NULL; - unit->runstate_cnt[v->runstate.state]--; - - if ( cnt ) - return; - - if ( unit->vcpu_list =3D=3D v ) - unit->vcpu_list =3D v->next_in_list; =20 if ( d->sched_unit_list =3D=3D unit ) d->sched_unit_list =3D unit->next_in_list; @@ -390,6 +374,26 @@ static void sched_free_unit(struct sched_unit *unit, s= truct vcpu *v) xfree(unit); } =20 +static void sched_free_unit(struct sched_unit *unit, struct vcpu *v) +{ + struct vcpu *vunit; + unsigned int cnt =3D 0; + + /* Don't count to be released vcpu, might be not in vcpu list yet. */ + for_each_sched_unit_vcpu ( unit, vunit ) + if ( vunit !=3D v ) + cnt++; + + v->sched_unit =3D NULL; + unit->runstate_cnt[v->runstate.state]--; + + if ( unit->vcpu_list =3D=3D v ) + unit->vcpu_list =3D v->next_in_list; + + if ( !cnt ) + sched_free_unit_mem(unit); +} + static void sched_unit_add_vcpu(struct sched_unit *unit, struct vcpu *v) { v->sched_unit =3D unit; --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362799; cv=none; d=zoho.com; s=zohoarc; b=WoYhfSrbSdu+clGe4vj90a6pXBeJ99+YONDfCJciBGGceNHmkQmZAGoINh2YJ7D2HLqrBL6t8QVvAm0+n1M4AQ0sYb0RE/ox4L18oI0zYnQuZGR5MDrs9DAB+MPDIrez6ngSR3pN+xyEDmar9YIdcU9njDtaRJ/2CwRgvhlNsdw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362799; 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=IT/14STFusTandntdajNM2fADF92zIDWC4/qKThgJQo=; b=Rez2GB7Y/iSU7mVg8809oHgqQKJ0rrBbAIzTwrhGnJ8JG70GWiBGXcLHC5DP5qzSjlKn3/XbbiH2OkMgINXW/DITZMcQF1zRD96Z65XOSgLPCjddrK1kwv8E6rPXPQr2UqDSD1/Z42XPU1AeazOtRMlRsuJaI8dpW2g4JPMJ8AY= 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 1565362799780971.7530493924897; Fri, 9 Aug 2019 07:59:59 -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 1hw6MK-0007FY-Kr; Fri, 09 Aug 2019 14:59:12 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M3-0006eT-QY for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:55 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 332b17b5-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:52 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5BB57B0B6; Fri, 9 Aug 2019 14:58:51 +0000 (UTC) X-Inumbo-ID: 332b17b5-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:23 +0200 Message-Id: <20190809145833.1020-39-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 38/48] xen/sched: move per-cpu variable scheduler to 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 , 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" Having a pointer to struct scheduler in struct sched_resource instead of per cpu is enough. Signed-off-by: Juergen Gross --- V1: new patch --- xen/common/sched_credit.c | 18 +++++++++++------- xen/common/sched_credit2.c | 3 ++- xen/common/schedule.c | 15 +++++++-------- xen/include/xen/sched-if.h | 2 +- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index aeb659577e..a65751068d 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -352,9 +352,10 @@ DEFINE_PER_CPU(unsigned int, last_tickle_cpu); static inline void __runq_tickle(struct csched_unit *new) { unsigned int cpu =3D sched_unit_cpu(new->unit); + struct sched_resource *sd =3D get_sched_res(cpu); struct sched_unit *unit =3D new->unit; struct csched_unit * const cur =3D CSCHED_UNIT(curr_on_cpu(cpu)); - struct csched_private *prv =3D CSCHED_PRIV(per_cpu(scheduler, cpu)); + struct csched_private *prv =3D CSCHED_PRIV(sd->scheduler); cpumask_t mask, idle_mask, *online; int balance_step, idlers_empty; =20 @@ -931,7 +932,8 @@ csched_unit_acct(struct csched_private *prv, unsigned i= nt cpu) { struct sched_unit *currunit =3D current->sched_unit; struct csched_unit * const svc =3D CSCHED_UNIT(currunit); - const struct scheduler *ops =3D per_cpu(scheduler, cpu); + struct sched_resource *sd =3D get_sched_res(cpu); + const struct scheduler *ops =3D sd->scheduler; =20 ASSERT( sched_unit_cpu(currunit) =3D=3D cpu ); ASSERT( svc->sdom !=3D NULL ); @@ -987,8 +989,7 @@ csched_unit_acct(struct csched_private *prv, unsigned i= nt cpu) * idlers. But, if we are here, it means there is someone runn= ing * on it, and hence the bit must be zero already. */ - ASSERT(!cpumask_test_cpu(cpu, - CSCHED_PRIV(per_cpu(scheduler, cpu))-= >idlers)); + ASSERT(!cpumask_test_cpu(cpu, CSCHED_PRIV(sd->scheduler)->idle= rs)); cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); } } @@ -1083,6 +1084,7 @@ csched_unit_sleep(const struct scheduler *ops, struct= sched_unit *unit) { struct csched_unit * const svc =3D CSCHED_UNIT(unit); unsigned int cpu =3D sched_unit_cpu(unit); + struct sched_resource *sd =3D get_sched_res(cpu); =20 SCHED_STAT_CRANK(unit_sleep); =20 @@ -1095,7 +1097,7 @@ csched_unit_sleep(const struct scheduler *ops, struct= sched_unit *unit) * But, we are here because unit is going to sleep while running o= n cpu, * so the bit must be zero already. */ - ASSERT(!cpumask_test_cpu(cpu, CSCHED_PRIV(per_cpu(scheduler, cpu))= ->idlers)); + ASSERT(!cpumask_test_cpu(cpu, CSCHED_PRIV(sd->scheduler)->idlers)); cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); } else if ( __unit_on_runq(svc) ) @@ -1575,8 +1577,9 @@ static void csched_tick(void *_cpu) { unsigned int cpu =3D (unsigned long)_cpu; + struct sched_resource *sd =3D get_sched_res(cpu); struct csched_pcpu *spc =3D CSCHED_PCPU(cpu); - struct csched_private *prv =3D CSCHED_PRIV(per_cpu(scheduler, cpu)); + struct csched_private *prv =3D CSCHED_PRIV(sd->scheduler); =20 spc->tick++; =20 @@ -1601,7 +1604,8 @@ csched_tick(void *_cpu) static struct csched_unit * csched_runq_steal(int peer_cpu, int cpu, int pri, int balance_step) { - const struct csched_private * const prv =3D CSCHED_PRIV(per_cpu(schedu= ler, cpu)); + struct sched_resource *sd =3D get_sched_res(cpu); + const struct csched_private * const prv =3D CSCHED_PRIV(sd->scheduler); const struct csched_pcpu * const peer_pcpu =3D CSCHED_PCPU(peer_cpu); struct csched_unit *speer; struct list_head *iter; diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index af06d02056..19fd0e008c 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -3266,8 +3266,9 @@ runq_candidate(struct csched2_runqueue_data *rqd, unsigned int *skipped) { struct list_head *iter, *temp; + struct sched_resource *sd =3D get_sched_res(cpu); struct csched2_unit *snext =3D NULL; - struct csched2_private *prv =3D csched2_priv(per_cpu(scheduler, cpu)); + struct csched2_private *prv =3D csched2_priv(sd->scheduler); bool yield =3D false, soft_aff_preempt =3D false; =20 *skipped =3D 0; diff --git a/xen/common/schedule.c b/xen/common/schedule.c index be5f03b626..635ee88c31 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -69,7 +69,6 @@ static void vcpu_singleshot_timer_fn(void *data); static void poll_timer_fn(void *data); =20 /* This is global for now so that private implementations can reach it */ -DEFINE_PER_CPU(struct scheduler *, scheduler); DEFINE_PER_CPU_READ_MOSTLY(struct sched_resource *, sched_res); static DEFINE_PER_CPU_READ_MOSTLY(unsigned int, sched_res_idx); =20 @@ -188,7 +187,7 @@ static inline struct scheduler *unit_scheduler(const st= ruct sched_unit *unit) */ =20 ASSERT(is_idle_domain(d)); - return per_cpu(scheduler, unit->res->processor); + return unit->res->scheduler; } =20 static inline struct scheduler *vcpu_scheduler(const struct vcpu *v) @@ -1876,8 +1875,8 @@ static bool sched_tasklet_check(unsigned int cpu) static struct sched_unit *do_schedule(struct sched_unit *prev, s_time_t no= w, unsigned int cpu) { - struct scheduler *sched =3D per_cpu(scheduler, cpu); struct sched_resource *sd =3D get_sched_res(cpu); + struct scheduler *sched =3D sd->scheduler; struct sched_unit *next; =20 /* get policy-specific decision on scheduling... */ @@ -2285,7 +2284,7 @@ static int cpu_schedule_up(unsigned int cpu) sd->cpus =3D cpumask_of(cpu); set_sched_res(cpu, sd); =20 - per_cpu(scheduler, cpu) =3D &sched_idle_ops; + sd->scheduler =3D &sched_idle_ops; spin_lock_init(&sd->_lock); sd->schedule_lock =3D &sched_free_cpu_lock; init_timer(&sd->s_timer, s_timer_fn, NULL, cpu); @@ -2496,7 +2495,7 @@ int schedule_cpu_switch(unsigned int cpu, struct cpup= ool *c) { struct vcpu *idle; void *ppriv, *ppriv_old, *vpriv, *vpriv_old; - struct scheduler *old_ops =3D per_cpu(scheduler, cpu); + struct scheduler *old_ops =3D get_sched_res(cpu)->scheduler; struct scheduler *new_ops =3D (c =3D=3D NULL) ? &sched_idle_ops : c->s= ched; struct cpupool *old_pool =3D per_cpu(cpupool, cpu); struct sched_resource *sd =3D get_sched_res(cpu); @@ -2560,7 +2559,7 @@ int schedule_cpu_switch(unsigned int cpu, struct cpup= ool *c) ppriv_old =3D sd->sched_priv; new_lock =3D sched_switch_sched(new_ops, cpu, ppriv, vpriv); =20 - per_cpu(scheduler, cpu) =3D new_ops; + sd->scheduler =3D new_ops; sd->sched_priv =3D ppriv; =20 /* @@ -2660,7 +2659,7 @@ void sched_tick_suspend(void) struct scheduler *sched; unsigned int cpu =3D smp_processor_id(); =20 - sched =3D per_cpu(scheduler, cpu); + sched =3D get_sched_res(cpu)->scheduler; sched_do_tick_suspend(sched, cpu); rcu_idle_enter(cpu); rcu_idle_timer_start(); @@ -2673,7 +2672,7 @@ void sched_tick_resume(void) =20 rcu_idle_timer_stop(); rcu_idle_exit(cpu); - sched =3D per_cpu(scheduler, cpu); + sched =3D get_sched_res(cpu)->scheduler; sched_do_tick_resume(sched, cpu); } =20 diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index eb6b9ef55c..94057ea9dd 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -36,6 +36,7 @@ extern const cpumask_t *sched_res_mask; * as the rest of the struct. Just have the scheduler point to the * one it wants (This may be the one right in front of it).*/ struct sched_resource { + struct scheduler *scheduler; spinlock_t *schedule_lock, _lock; struct sched_unit *curr; /* current task = */ @@ -50,7 +51,6 @@ struct sched_resource { =20 #define curr_on_cpu(c) (get_sched_res(c)->curr) =20 -DECLARE_PER_CPU(struct scheduler *, scheduler); DECLARE_PER_CPU(struct cpupool *, cpupool); DECLARE_PER_CPU(struct sched_resource *, sched_res); =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362789; cv=none; d=zoho.com; s=zohoarc; b=Vr2UzvABxh01JQ4+h0r1x2ztSVJaPGwsXJKhuYLTjocjtKuXIxl13jtGtXgb9eEF0Pb5/HhjXctn2lbgf/Mty9qaoDgt2UMW7Y2jk2Bmi6umYnsc/g5lr7msnakje25/4NYt1WHiG6RLAT9Vd2fDygknHYdokl411aQqrsAUogI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362789; 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=swb4FYhu08lN6CBBlIB2czYg8QkReHIhcXMuvfebsvI=; b=ilw1tAHAz2oIV2Iq3I1u5Z2XPcskV9LuHBSzmxa3cHA7q+fVn87Uc094HPt2b3pc+gsdaMn6Ce2zbAu7gKMxZ42dVZzxsj33lALY7oVRHNE71sLjzpf5CdrxAxj62q8FhAxjDINF/6bGwSdshGI955ihew7KMEzB1ux0NzfmUl0= 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 1565362789873663.6767155453628; Fri, 9 Aug 2019 07:59:49 -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 1hw6MN-0007KY-0G; Fri, 09 Aug 2019 14:59:15 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M4-0006f8-3H for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:56 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 336738f2-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:52 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BF8A0B0CC; Fri, 9 Aug 2019 14:58:51 +0000 (UTC) X-Inumbo-ID: 336738f2-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:24 +0200 Message-Id: <20190809145833.1020-40-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 39/48] xen/sched: move per-cpu variable cpupool to 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Having a pointer to struct cpupool in struct sched_resource instead of per cpu is enough. Signed-off-by: Juergen Gross --- V1: new patch --- xen/common/cpupool.c | 4 +--- xen/common/sched_credit.c | 2 +- xen/common/sched_rt.c | 2 +- xen/common/schedule.c | 8 ++++---- xen/include/xen/sched-if.h | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c index 17d671585a..bace684464 100644 --- a/xen/common/cpupool.c +++ b/xen/common/cpupool.c @@ -34,8 +34,6 @@ static cpumask_t cpupool_locked_cpus; =20 static DEFINE_SPINLOCK(cpupool_lock); =20 -DEFINE_PER_CPU(struct cpupool *, cpupool); - #define cpupool_dprintk(x...) ((void)0) =20 static void free_cpupool_struct(struct cpupool *c) @@ -510,7 +508,7 @@ static int cpupool_cpu_add(unsigned int cpu) * (or unplugging would have failed) and that is the default behavior * anyway. */ - per_cpu(cpupool, cpu) =3D NULL; + get_sched_res(cpu)->cpupool =3D NULL; ret =3D cpupool_assign_cpu_locked(cpupool0, cpu); =20 spin_unlock(&cpupool_lock); diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index a65751068d..d14c997d9d 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1681,7 +1681,7 @@ static struct csched_unit * csched_load_balance(struct csched_private *prv, int cpu, struct csched_unit *snext, bool *stolen) { - struct cpupool *c =3D per_cpu(cpupool, cpu); + struct cpupool *c =3D get_sched_res(cpu)->cpupool; struct csched_unit *speer; cpumask_t workers; cpumask_t *online; diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index 205ff13c09..a252e1d82d 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -775,7 +775,7 @@ rt_deinit_pdata(const struct scheduler *ops, void *pcpu= , int cpu) =20 if ( prv->repl_timer.cpu =3D=3D cpu ) { - struct cpupool *c =3D per_cpu(cpupool, cpu); + struct cpupool *c =3D get_sched_res(cpu)->cpupool; unsigned int new_cpu =3D cpumask_cycle(cpu, cpupool_online_cpumask= (c)); =20 /* diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 635ee88c31..afd4170730 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -1098,7 +1098,7 @@ int cpu_disable_scheduler(unsigned int cpu) cpumask_t online_affinity; int ret =3D 0; =20 - c =3D per_cpu(cpupool, cpu); + c =3D get_sched_res(cpu)->cpupool; if ( c =3D=3D NULL ) return ret; =20 @@ -1167,7 +1167,7 @@ static int cpu_disable_scheduler_check(unsigned int c= pu) struct cpupool *c; struct vcpu *v; =20 - c =3D per_cpu(cpupool, cpu); + c =3D get_sched_res(cpu)->cpupool; if ( c =3D=3D NULL ) return 0; =20 @@ -2497,8 +2497,8 @@ int schedule_cpu_switch(unsigned int cpu, struct cpup= ool *c) void *ppriv, *ppriv_old, *vpriv, *vpriv_old; struct scheduler *old_ops =3D get_sched_res(cpu)->scheduler; struct scheduler *new_ops =3D (c =3D=3D NULL) ? &sched_idle_ops : c->s= ched; - struct cpupool *old_pool =3D per_cpu(cpupool, cpu); struct sched_resource *sd =3D get_sched_res(cpu); + struct cpupool *old_pool =3D sd->cpupool; spinlock_t *old_lock, *new_lock; unsigned long flags; =20 @@ -2580,7 +2580,7 @@ int schedule_cpu_switch(unsigned int cpu, struct cpup= ool *c) sched_free_vdata(old_ops, vpriv_old); sched_free_pdata(old_ops, ppriv_old, cpu); =20 - per_cpu(cpupool, cpu) =3D c; + get_sched_res(cpu)->cpupool =3D c; /* When a cpu is added to a pool, trigger it to go pick up some work */ if ( c !=3D NULL ) cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 94057ea9dd..73b19a2763 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -37,6 +37,7 @@ extern const cpumask_t *sched_res_mask; * one it wants (This may be the one right in front of it).*/ struct sched_resource { struct scheduler *scheduler; + struct cpupool *cpupool; spinlock_t *schedule_lock, _lock; struct sched_unit *curr; /* current task = */ @@ -51,7 +52,6 @@ struct sched_resource { =20 #define curr_on_cpu(c) (get_sched_res(c)->curr) =20 -DECLARE_PER_CPU(struct cpupool *, cpupool); DECLARE_PER_CPU(struct sched_resource *, sched_res); =20 static inline struct sched_resource *get_sched_res(unsigned int cpu) --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362800; cv=none; d=zoho.com; s=zohoarc; b=WIZIFqB16kDleDwxbj1H/JOt7CpZQjtEUQ+cV/v8LkVEsdWE1HwgyBqgRA+a6rSGj8HE7m6FX/byjKahTWZoySvSbR5LhlV69tWZ4xNFGDE/dFYNTvsFMsSaMAuVDJuqh4u8unBx4fh2VnmCP5LyfxItBEFpT12jQb2BJySMGEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362800; 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=AWU8I7X6nw82MYcL1uUYN8diCrNVI4GDe+KEv9E2pY8=; b=btUvflFP+JGezCjp7z/IQcw7fxRmxTfT22KEvylFytgldJGdn0wBXz4x5G6qqrOtYg4yC3sYnmFvQVWFVfsEt9d550qR6ZNG3EGxGpnxFOY5HHGofecYNHhdrfLJyBZqv1+K6G1jRT/E1JZCLSjZvhdcpJTsF7h+a+IlmTuHupI= 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 1565362800290445.289301600293; Fri, 9 Aug 2019 08:00:00 -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 1hw6MS-0007Y2-Oc; Fri, 09 Aug 2019 14:59:20 +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 1hw6M5-0006ho-Jp for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:57 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 33a324ee-bab6-11e9-bc22-bbc3309160c5; Fri, 09 Aug 2019 14:58:52 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 325D6B08C; Fri, 9 Aug 2019 14:58:52 +0000 (UTC) X-Inumbo-ID: 33a324ee-bab6-11e9-bc22-bbc3309160c5 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:25 +0200 Message-Id: <20190809145833.1020-41-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 40/48] xen/sched: reject switching smt on/off with core scheduling active 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= 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" When core or socket scheduling are active enabling or disabling smt is not possible as that would require a major host reconfiguration. Add a bool sched_disable_smt_switching which will be set for core or socket scheduling. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- V1: - new patch V2: - EBUSY as return code (Jan Beulich, Dario Faggioli) - __read_mostly for sched_disable_smt_switching (Jan Beulich) --- xen/arch/x86/sysctl.c | 5 +++++ xen/common/schedule.c | 1 + xen/include/xen/sched.h | 1 + 3 files changed, 7 insertions(+) diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index c50d910a1c..a4c4d868b6 100644 --- a/xen/arch/x86/sysctl.c +++ b/xen/arch/x86/sysctl.c @@ -204,6 +204,11 @@ long arch_do_sysctl( ret =3D -EOPNOTSUPP; break; } + if ( sched_disable_smt_switching ) + { + ret =3D -EBUSY; + break; + } plug =3D op =3D=3D XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE; fn =3D smt_up_down_helper; hcpu =3D _p(plug); diff --git a/xen/common/schedule.c b/xen/common/schedule.c index afd4170730..b94fd2431a 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -57,6 +57,7 @@ integer_param("sched_ratelimit_us", sched_ratelimit_us); =20 /* Number of vcpus per struct sched_unit. */ static unsigned int __read_mostly sched_granularity =3D 1; +bool __read_mostly sched_disable_smt_switching; const cpumask_t *sched_res_mask =3D &cpumask_all; =20 /* Common lock for free cpus. */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index e868646f0e..39355f5d67 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -1021,6 +1021,7 @@ static inline bool is_vcpu_online(const struct vcpu *= v) } =20 extern bool sched_smt_power_savings; +extern bool sched_disable_smt_switching; =20 extern enum cpufreq_controller { FREQCTL_none, FREQCTL_dom0_kernel, FREQCTL_xen --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362800; cv=none; d=zoho.com; s=zohoarc; b=RKRHhsg1yj6R5pe8WpslMXLOJbfJn0S8s1Y5eA7wcDup/zEiUuFH3fSU3eka5tEFTJTpqcHD/OlMojFXJtb305C2+Zr+jpvoVHWnAz0c5aY5AFHY3VnoDfezmamimnbxKfsOkRrgnhzOR78thRv2AonuHcl7qXIRsvUgtIbFPEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362800; 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=HoRRweGX2HOoKBm22lYiVwFcDE3jQGMC3jMtZd6XrGk=; b=JEXOiC2pVfjeCkFBb2VxMrl+vEjNw0+5QxcjXKOmwGk4Km8HvZcvx6D3CusLvvEQNVAxDloTuyHSyoZfM1ns1L+BL+LqXxf4lYGp/kBFBqu3lBIz3vOvi2RHDgkENuZ/gdDQITs0aipQ0hJLzXWJctszrUAz2QnBfnY7peHAbP4= 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 1565362800064967.460717784222; Fri, 9 Aug 2019 08:00:00 -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 1hw6MQ-0007SR-CX; Fri, 09 Aug 2019 14:59:18 +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 1hw6M5-0006hp-LY for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:57 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 33e2c9d2-bab6-11e9-a3d6-8bce01c347c5; Fri, 09 Aug 2019 14:58:53 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9A21CB03C; Fri, 9 Aug 2019 14:58:52 +0000 (UTC) X-Inumbo-ID: 33e2c9d2-bab6-11e9-a3d6-8bce01c347c5 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:26 +0200 Message-Id: <20190809145833.1020-42-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 41/48] xen/sched: prepare per-cpupool scheduling granularity 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" On- and offlining cpus with core scheduling is rather complicated as the cpus are taken on- or offline one by one, but scheduling wants them rather to be handled per core. As the future plan is to be able to select scheduling granularity per cpupool prepare that by storing the granularity in struct cpupool and struct sched_resource (we need it there for free cpus which are not associated to any cpupool). Free cpus will always use granularity 1. Store the selected granularity option (cpu, core or socket) in the cpupool as well, as we will need it to select the appropriate cpu mask when populating the cpupool with cpus. This will make on- and offlining of cpus much easier and avoids writing code which would needed to be thrown away later. Signed-off-by: Juergen Gross --- V1: new patch --- xen/common/cpupool.c | 2 ++ xen/common/schedule.c | 23 +++++++++++++++-------- xen/include/xen/sched-if.h | 12 ++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c index bace684464..8789fde3c4 100644 --- a/xen/common/cpupool.c +++ b/xen/common/cpupool.c @@ -177,6 +177,8 @@ static struct cpupool *cpupool_create( return NULL; } } + c->granularity =3D sched_granularity; + c->opt_granularity =3D opt_sched_granularity; =20 *q =3D c; =20 diff --git a/xen/common/schedule.c b/xen/common/schedule.c index b94fd2431a..7823b48e32 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -56,7 +56,8 @@ int sched_ratelimit_us =3D SCHED_DEFAULT_RATELIMIT_US; integer_param("sched_ratelimit_us", sched_ratelimit_us); =20 /* Number of vcpus per struct sched_unit. */ -static unsigned int __read_mostly sched_granularity =3D 1; +enum sched_gran __read_mostly opt_sched_granularity =3D SCHED_GRAN_cpu; +unsigned int __read_mostly sched_granularity =3D 1; bool __read_mostly sched_disable_smt_switching; const cpumask_t *sched_res_mask =3D &cpumask_all; =20 @@ -409,10 +410,10 @@ static struct sched_unit *sched_alloc_unit(struct vcp= u *v) { struct sched_unit *unit, **prev_unit; struct domain *d =3D v->domain; + unsigned int gran =3D d->cpupool ? d->cpupool->granularity : 1; =20 for_each_sched_unit ( d, unit ) - if ( unit->vcpu_list->vcpu_id / sched_granularity =3D=3D - v->vcpu_id / sched_granularity ) + if ( unit->vcpu_list->vcpu_id / gran =3D=3D v->vcpu_id / gran ) break; =20 if ( unit ) @@ -1805,11 +1806,11 @@ static void sched_switch_units(struct sched_resourc= e *sd, if ( is_idle_unit(prev) ) { prev->runstate_cnt[RUNSTATE_running] =3D 0; - prev->runstate_cnt[RUNSTATE_runnable] =3D sched_granularity; + prev->runstate_cnt[RUNSTATE_runnable] =3D sd->granularity; } if ( is_idle_unit(next) ) { - next->runstate_cnt[RUNSTATE_running] =3D sched_granularity; + next->runstate_cnt[RUNSTATE_running] =3D sd->granularity; next->runstate_cnt[RUNSTATE_runnable] =3D 0; } } @@ -2072,11 +2073,12 @@ static struct sched_unit *sched_wait_rendezvous_in(= struct sched_unit *prev, { struct sched_unit *next; struct vcpu *v; + unsigned int gran =3D get_sched_res(cpu)->granularity; =20 if ( !--prev->rendezvous_in_cnt ) { next =3D do_schedule(prev, now, cpu); - atomic_set(&next->rendezvous_out_cnt, sched_granularity + 1); + atomic_set(&next->rendezvous_out_cnt, gran + 1); return next; } =20 @@ -2196,6 +2198,7 @@ static void schedule(void) struct sched_resource *sd; spinlock_t *lock; int cpu =3D smp_processor_id(); + unsigned int gran =3D get_sched_res(cpu)->granularity; =20 ASSERT_NOT_IN_ATOMIC(); =20 @@ -2221,11 +2224,11 @@ static void schedule(void) =20 stop_timer(&sd->s_timer); =20 - if ( sched_granularity > 1 ) + if ( gran > 1 ) { cpumask_t mask; =20 - prev->rendezvous_in_cnt =3D sched_granularity; + prev->rendezvous_in_cnt =3D gran; cpumask_andnot(&mask, sd->cpus, cpumask_of(cpu)); cpumask_raise_softirq(&mask, SCHED_SLAVE_SOFTIRQ); next =3D sched_wait_rendezvous_in(prev, &lock, cpu, now); @@ -2291,6 +2294,9 @@ static int cpu_schedule_up(unsigned int cpu) init_timer(&sd->s_timer, s_timer_fn, NULL, cpu); atomic_set(&sd->urgent_count, 0); =20 + /* We start with cpu granularity. */ + sd->granularity =3D 1; + /* Boot CPU is dealt with later in scheduler_init(). */ if ( cpu =3D=3D 0 ) return 0; @@ -2581,6 +2587,7 @@ int schedule_cpu_switch(unsigned int cpu, struct cpup= ool *c) sched_free_vdata(old_ops, vpriv_old); sched_free_pdata(old_ops, ppriv_old, cpu); =20 + get_sched_res(cpu)->granularity =3D c ? c->granularity : 1; get_sched_res(cpu)->cpupool =3D c; /* When a cpu is added to a pool, trigger it to go pick up some work */ if ( c !=3D NULL ) diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 73b19a2763..606a0d4a25 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -25,6 +25,15 @@ extern int sched_ratelimit_us; /* Scheduling resource mask. */ extern const cpumask_t *sched_res_mask; =20 +/* Number of vcpus per struct sched_unit. */ +enum sched_gran { + SCHED_GRAN_cpu, + SCHED_GRAN_core, + SCHED_GRAN_socket +}; +extern enum sched_gran opt_sched_granularity; +extern unsigned int sched_granularity; + /* * In order to allow a scheduler to remap the lock->cpu mapping, * we have a per-cpu pointer, along with a pre-allocated set of @@ -47,6 +56,7 @@ struct sched_resource { struct timer s_timer; /* scheduling timer = */ atomic_t urgent_count; /* how many urgent vcpus = */ unsigned int processor; + unsigned int granularity; const cpumask_t *cpus; /* cpus covered by this struct = */ }; =20 @@ -531,6 +541,8 @@ struct cpupool struct cpupool *next; struct scheduler *sched; atomic_t refcnt; + unsigned int granularity; + enum sched_gran opt_granularity; }; =20 #define cpupool_online_cpumask(_pool) \ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362806; cv=none; d=zoho.com; s=zohoarc; b=onGBtKh2GByLNbptIuiD0RP03fhkpbRvx0lZ4GM4NNjYXPxWdsrbVjFd2Kxy/mczghCX3lCCXZ3e/z6i7IKrB6n81xutg8ORbZ/Nz09SOaqzUGgJTFJmOdmq616StIZ/GPbd4xSZOam2KN/GnP7T5c2OYDIY3wKrgMMNQ5yiL0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362806; 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=inLER6FZ+TVZNGk8zzQv7pQpCxlpotxLUwUo3C7Mf3c=; b=R84JDf6g5XYRJM2nmSrty7OvoVUCkAQtAesQckW6wwMjVRD/BK5+K9PyQ86D8P6XrENG2OdBqCI9BqLqs9quaJXdeQbKtLjGXbb8iYs/v0++TXQKrl9gJvPXK9JDpgau0tBL86XplHyhjnetU01/RUShbHVmFB0yxi6gPVWsKE4= 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 1565362806132630.0769655612107; Fri, 9 Aug 2019 08:00:06 -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 1hw6MR-0007Uv-BZ; Fri, 09 Aug 2019 14:59:19 +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 1hw6M5-0006iR-Rm for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:57 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 341edf1c-bab6-11e9-96bc-2b99beb2db5d; Fri, 09 Aug 2019 14:58:53 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 06C01B035; Fri, 9 Aug 2019 14:58:53 +0000 (UTC) X-Inumbo-ID: 341edf1c-bab6-11e9-96bc-2b99beb2db5d X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:27 +0200 Message-Id: <20190809145833.1020-43-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 42/48] xen/sched: split schedule_cpu_switch() 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" Instead of letting schedule_cpu_switch() handle moving cpus from and to cpupools, split it into schedule_cpu_add() and schedule_cpu_rm(). This will allow us to drop allocating/freeing scheduler data for free cpus as the idle scheduler doesn't need such data. Signed-off-by: Juergen Gross --- V1: new patch --- xen/common/cpupool.c | 4 +- xen/common/schedule.c | 125 +++++++++++++++++++++++++++-----------------= ---- xen/include/xen/sched.h | 3 +- 3 files changed, 74 insertions(+), 58 deletions(-) diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c index 8789fde3c4..4749ead846 100644 --- a/xen/common/cpupool.c +++ b/xen/common/cpupool.c @@ -268,7 +268,7 @@ static int cpupool_assign_cpu_locked(struct cpupool *c,= unsigned int cpu) =20 if ( (cpupool_moving_cpu =3D=3D cpu) && (c !=3D cpupool_cpu_moving) ) return -EADDRNOTAVAIL; - ret =3D schedule_cpu_switch(cpu, c); + ret =3D schedule_cpu_add(cpu, c); if ( ret ) return ret; =20 @@ -318,7 +318,7 @@ static int cpupool_unassign_cpu_epilogue(struct cpupool= *c) */ if ( !ret ) { - ret =3D schedule_cpu_switch(cpu, NULL); + ret =3D schedule_cpu_rm(cpu); if ( ret ) cpumask_clear_cpu(cpu, &cpupool_free_cpus); else diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 7823b48e32..999f6e347b 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -83,15 +83,6 @@ extern const struct scheduler *__start_schedulers_array[= ], *__end_schedulers_arr =20 static struct scheduler __read_mostly ops; =20 -static spinlock_t * -sched_idle_switch_sched(struct scheduler *new_ops, unsigned int cpu, - void *pdata, void *vdata) -{ - sched_idle_unit(cpu)->priv =3D NULL; - - return &sched_free_cpu_lock; -} - static struct sched_resource * sched_idle_res_pick(const struct scheduler *ops, struct sched_unit *unit) { @@ -131,7 +122,6 @@ static struct scheduler sched_idle_ops =3D { =20 .alloc_vdata =3D sched_idle_alloc_vdata, .free_vdata =3D sched_idle_free_vdata, - .switch_sched =3D sched_idle_switch_sched, }; =20 static inline struct vcpu *unit2vcpu_cpu(struct sched_unit *unit, @@ -2492,36 +2482,22 @@ void __init scheduler_init(void) } =20 /* - * Move a pCPU outside of the influence of the scheduler of its current - * cpupool, or subject it to the scheduler of a new cpupool. - * - * For the pCPUs that are removed from their cpupool, their scheduler beco= mes - * &sched_idle_ops (the idle scheduler). + * Move a pCPU from free cpus (running the idle scheduler) to a cpupool + * using any "real" scheduler. + * The cpu is still marked as "free" and not yet valid for its cpupool. */ -int schedule_cpu_switch(unsigned int cpu, struct cpupool *c) +int schedule_cpu_add(unsigned int cpu, struct cpupool *c) { struct vcpu *idle; - void *ppriv, *ppriv_old, *vpriv, *vpriv_old; - struct scheduler *old_ops =3D get_sched_res(cpu)->scheduler; - struct scheduler *new_ops =3D (c =3D=3D NULL) ? &sched_idle_ops : c->s= ched; + void *ppriv, *vpriv; + struct scheduler *new_ops =3D c->sched; struct sched_resource *sd =3D get_sched_res(cpu); - struct cpupool *old_pool =3D sd->cpupool; spinlock_t *old_lock, *new_lock; unsigned long flags; =20 - /* - * pCPUs only move from a valid cpupool to free (i.e., out of any pool= ), - * or from free to a valid cpupool. In the former case (which happens = when - * c is NULL), we want the CPU to have been marked as free already, as - * well as to not be valid for the source pool any longer, when we get= to - * here. In the latter case (which happens when c is a valid cpupool),= we - * want the CPU to still be marked as free, as well as to not yet be v= alid - * for the destination pool. - */ - ASSERT(c !=3D old_pool && (c !=3D NULL || old_pool !=3D NULL)); ASSERT(cpumask_test_cpu(cpu, &cpupool_free_cpus)); - ASSERT((c =3D=3D NULL && !cpumask_test_cpu(cpu, old_pool->cpu_valid)) = || - (c !=3D NULL && !cpumask_test_cpu(cpu, c->cpu_valid))); + ASSERT(!cpumask_test_cpu(cpu, c->cpu_valid)); + ASSERT(get_sched_res(cpu)->cpupool =3D=3D NULL); =20 /* * To setup the cpu for the new scheduler we need: @@ -2546,52 +2522,91 @@ int schedule_cpu_switch(unsigned int cpu, struct cp= upool *c) return -ENOMEM; } =20 - sched_do_tick_suspend(old_ops, cpu); - /* - * The actual switch, including (if necessary) the rerouting of the - * scheduler lock to whatever new_ops prefers, needs to happen in one - * critical section, protected by old_ops' lock, or races are possible. - * It is, in fact, the lock of another scheduler that we are taking (t= he - * scheduler of the cpupool that cpu still belongs to). But that is ok - * as, anyone trying to schedule on this cpu will spin until when we - * release that lock (bottom of this function). When he'll get the lock - * --thanks to the loop inside *_schedule_lock() functions-- he'll not= ice - * that the lock itself changed, and retry acquiring the new one (which - * will be the correct, remapped one, at that point). + * The actual switch, including the rerouting of the scheduler lock to + * whatever new_ops prefers, needs to happen in one critical section, + * protected by old_ops' lock, or races are possible. + * It is, in fact, the lock of the idle scheduler that we are taking. + * But that is ok as anyone trying to schedule on this cpu will spin u= ntil + * when we release that lock (bottom of this function). When he'll get= the + * lock --thanks to the loop inside *_schedule_lock() functions-- he'll + * notice that the lock itself changed, and retry acquiring the new one + * (which will be the correct, remapped one, at that point). */ old_lock =3D pcpu_schedule_lock_irqsave(cpu, &flags); =20 - vpriv_old =3D idle->sched_unit->priv; - ppriv_old =3D sd->sched_priv; new_lock =3D sched_switch_sched(new_ops, cpu, ppriv, vpriv); =20 sd->scheduler =3D new_ops; sd->sched_priv =3D ppriv; =20 /* - * The data above is protected under new_lock, which may be unlocked. - * Another CPU can take new_lock as soon as sd->schedule_lock is visib= le, - * and must observe all prior initialisation. + * Reroute the lock to the per pCPU lock as /last/ thing. In fact, + * if it is free (and it can be) we want that anyone that manages + * taking it, finds all the initializations we've done above in place. */ smp_wmb(); sd->schedule_lock =3D new_lock; =20 - /* _Not_ pcpu_schedule_unlock(): schedule_lock may have changed! */ + /* _Not_ pcpu_schedule_unlock(): schedule_lock has changed! */ spin_unlock_irqrestore(old_lock, flags); =20 sched_do_tick_resume(new_ops, cpu); =20 + sd->granularity =3D c->granularity; + sd->cpupool =3D c; + /* The cpu is added to a pool, trigger it to go pick up some work */ + cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); + + return 0; +} + +/* + * Remove a pCPU from its cpupool. Its scheduler becomes &sched_idle_ops + * (the idle scheduler). + * The cpu is already marked as "free" and not valid any longer for its + * cpupool. + */ +int schedule_cpu_rm(unsigned int cpu) +{ + struct vcpu *idle; + void *ppriv_old, *vpriv_old; + struct sched_resource *sd =3D get_sched_res(cpu); + struct scheduler *old_ops =3D sd->scheduler; + spinlock_t *old_lock; + unsigned long flags; + + ASSERT(sd->cpupool !=3D NULL); + ASSERT(cpumask_test_cpu(cpu, &cpupool_free_cpus)); + ASSERT(!cpumask_test_cpu(cpu, sd->cpupool->cpu_valid)); + + idle =3D idle_vcpu[cpu]; + + sched_do_tick_suspend(old_ops, cpu); + + /* See comment in schedule_cpu_add() regarding lock switching. */ + old_lock =3D pcpu_schedule_lock_irqsave(cpu, &flags); + + vpriv_old =3D idle->sched_unit->priv; + ppriv_old =3D sd->sched_priv; + + idle->sched_unit->priv =3D NULL; + sd->scheduler =3D &sched_idle_ops; + sd->sched_priv =3D NULL; + + smp_mb(); + sd->schedule_lock =3D &sched_free_cpu_lock; + + /* _Not_ pcpu_schedule_unlock(): schedule_lock may have changed! */ + spin_unlock_irqrestore(old_lock, flags); + sched_deinit_pdata(old_ops, ppriv_old, cpu); =20 sched_free_vdata(old_ops, vpriv_old); sched_free_pdata(old_ops, ppriv_old, cpu); =20 - get_sched_res(cpu)->granularity =3D c ? c->granularity : 1; - get_sched_res(cpu)->cpupool =3D c; - /* When a cpu is added to a pool, trigger it to go pick up some work */ - if ( c !=3D NULL ) - cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); + sd->granularity =3D 1; + sd->cpupool =3D NULL; =20 return 0; } diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 39355f5d67..346e564e05 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -910,7 +910,8 @@ struct scheduler; struct scheduler *scheduler_get_default(void); struct scheduler *scheduler_alloc(unsigned int sched_id, int *perr); void scheduler_free(struct scheduler *sched); -int schedule_cpu_switch(unsigned int cpu, struct cpupool *c); +int schedule_cpu_add(unsigned int cpu, struct cpupool *c); +int schedule_cpu_rm(unsigned int cpu); void vcpu_set_periodic_timer(struct vcpu *v, s_time_t value); int cpu_disable_scheduler(unsigned int cpu); /* We need it in dom0_setup_vcpu */ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362828; cv=none; d=zoho.com; s=zohoarc; b=QKwZlrV0jXtl0IDzbUWNsxbfLkjIJ8av39Zvr8bs7vVoPVT8Lu+5Wsjm1+H4DxLN9vKZJZB0+lg06DJ4xJQcRnryAE2yrs+uUg0heOV7C3VTu8ODMlgpM7uAleiUwav5deN4fMk3H82n/lo/mNWYW7t8U2j310cfxu7Lx/Yx82Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362828; 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=hdOmgpXPPvcS9IDz35ufX1MJXzXP4dOEWVwhl8R+WJI=; b=ATPNIfNyP50635S3r4hFDUAUJeWLeo9qJa1pEwaO+1lzZQvDMqB0iruVv8UuuPlYpEbwzWlDjvYTtR46N4I+wVKyqRuOZenEZuWm3tAdL2B+E2jYXKMcohMn2WEg9JEEc6IBcXm5rQWOz4wcM62vKJdckuyEgVL7wDDB6kSsbMI= 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 156536282895616.658986457525998; Fri, 9 Aug 2019 08:00:28 -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 1hw6Mk-0008FX-Mm; Fri, 09 Aug 2019 14:59:38 +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 1hw6M9-0006pV-Ay for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:59:01 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 346050c8-bab6-11e9-be81-a7e08683c8b0; Fri, 09 Aug 2019 14:58:54 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6C26CB0B7; Fri, 9 Aug 2019 14:58:53 +0000 (UTC) X-Inumbo-ID: 346050c8-bab6-11e9-be81-a7e08683c8b0 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:28 +0200 Message-Id: <20190809145833.1020-44-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 43/48] xen/sched: protect scheduling resource via rcu 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 be able to move cpus to cpupools with core scheduling active it is mandatory to merge multiple cpus into one scheduling resource or to split a scheduling resource with multiple cpus in it into multiple scheduling resources. This in turn requires to modify the cpu <-> scheduling resource relation. In order to be able to free unused resources protect struct sched_resource via RCU. This ensures there are no users left when freeing such a resource. Signed-off-by: Juergen Gross --- V1: new patch --- xen/common/cpupool.c | 4 + xen/common/schedule.c | 201 ++++++++++++++++++++++++++++++++++++++++-= ---- xen/include/xen/sched-if.h | 7 +- 3 files changed, 191 insertions(+), 21 deletions(-) diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c index 4749ead846..5d5c8d5430 100644 --- a/xen/common/cpupool.c +++ b/xen/common/cpupool.c @@ -510,8 +510,10 @@ static int cpupool_cpu_add(unsigned int cpu) * (or unplugging would have failed) and that is the default behavior * anyway. */ + rcu_read_lock(&sched_res_rculock); get_sched_res(cpu)->cpupool =3D NULL; ret =3D cpupool_assign_cpu_locked(cpupool0, cpu); + rcu_read_unlock(&sched_res_rculock); =20 spin_unlock(&cpupool_lock); =20 @@ -596,7 +598,9 @@ static void cpupool_cpu_remove_forced(unsigned int cpu) } } =20 + rcu_read_lock(&sched_res_rculock); sched_rm_cpu(cpu); + rcu_read_unlock(&sched_res_rculock); } =20 /* diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 999f6e347b..f95d346330 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -73,6 +73,7 @@ static void poll_timer_fn(void *data); /* This is global for now so that private implementations can reach it */ DEFINE_PER_CPU_READ_MOSTLY(struct sched_resource *, sched_res); static DEFINE_PER_CPU_READ_MOSTLY(unsigned int, sched_res_idx); +DEFINE_RCU_READ_LOCK(sched_res_rculock); =20 /* Scratch space for cpumasks. */ DEFINE_PER_CPU(cpumask_t, cpumask_scratch); @@ -276,17 +277,25 @@ static inline void vcpu_runstate_change( =20 void sched_guest_idle(void (*idle) (void), unsigned int cpu) { + rcu_read_lock(&sched_res_rculock); atomic_inc(&get_sched_res(cpu)->urgent_count); + rcu_read_unlock(&sched_res_rculock); + idle(); + + rcu_read_lock(&sched_res_rculock); atomic_dec(&get_sched_res(cpu)->urgent_count); + rcu_read_unlock(&sched_res_rculock); } =20 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate) { - spinlock_t *lock =3D likely(v =3D=3D current) - ? NULL : unit_schedule_lock_irq(v->sched_unit); + spinlock_t *lock; s_time_t delta; =20 + rcu_read_lock(&sched_res_rculock); + + lock =3D likely(v =3D=3D current) ? NULL : unit_schedule_lock_irq(v->s= ched_unit); memcpy(runstate, &v->runstate, sizeof(*runstate)); delta =3D NOW() - runstate->state_entry_time; if ( delta > 0 ) @@ -294,6 +303,8 @@ void vcpu_runstate_get(struct vcpu *v, struct vcpu_runs= tate_info *runstate) =20 if ( unlikely(lock !=3D NULL) ) unit_schedule_unlock_irq(lock, v->sched_unit); + + rcu_read_unlock(&sched_res_rculock); } =20 uint64_t get_cpu_idle_time(unsigned int cpu) @@ -497,6 +508,8 @@ int sched_init_vcpu(struct vcpu *v) return 0; } =20 + rcu_read_lock(&sched_res_rculock); + /* The first vcpu of an unit can be set via sched_set_res(). */ sched_set_res(unit, get_sched_res(processor)); =20 @@ -504,6 +517,7 @@ int sched_init_vcpu(struct vcpu *v) if ( unit->priv =3D=3D NULL ) { sched_free_unit(unit, v); + rcu_read_unlock(&sched_res_rculock); return 1; } =20 @@ -530,6 +544,8 @@ int sched_init_vcpu(struct vcpu *v) sched_insert_unit(dom_scheduler(d), unit); } =20 + rcu_read_unlock(&sched_res_rculock); + return 0; } =20 @@ -557,6 +573,7 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) void *unitdata; struct scheduler *old_ops; void *old_domdata; + int ret =3D 0; =20 for_each_vcpu ( d, v ) { @@ -564,15 +581,21 @@ int sched_move_domain(struct domain *d, struct cpupoo= l *c) return -EBUSY; } =20 + rcu_read_lock(&sched_res_rculock); + domdata =3D sched_alloc_domdata(c->sched, d); if ( IS_ERR(domdata) ) - return PTR_ERR(domdata); + { + ret =3D PTR_ERR(domdata); + goto out; + } =20 unit_priv =3D xzalloc_array(void *, d->max_vcpus); if ( unit_priv =3D=3D NULL ) { sched_free_domdata(c->sched, domdata); - return -ENOMEM; + ret =3D -ENOMEM; + goto out; } =20 for_each_sched_unit ( d, unit ) @@ -584,7 +607,8 @@ int sched_move_domain(struct domain *d, struct cpupool = *c) xfree(unit_priv[unit->unit_id]); xfree(unit_priv); sched_free_domdata(c->sched, domdata); - return -ENOMEM; + ret =3D -ENOMEM; + goto out; } } =20 @@ -646,7 +670,10 @@ int sched_move_domain(struct domain *d, struct cpupool= *c) =20 xfree(unit_priv); =20 - return 0; +out: + rcu_read_unlock(&sched_res_rculock); + + return ret; } =20 void sched_destroy_vcpu(struct vcpu *v) @@ -664,9 +691,13 @@ void sched_destroy_vcpu(struct vcpu *v) */ if ( unit->vcpu_list =3D=3D v ) { + rcu_read_lock(&sched_res_rculock); + sched_remove_unit(vcpu_scheduler(v), unit); sched_free_vdata(vcpu_scheduler(v), unit->priv); sched_free_unit(unit, v); + + rcu_read_unlock(&sched_res_rculock); } } =20 @@ -684,7 +715,12 @@ int sched_init_domain(struct domain *d, int poolid) SCHED_STAT_CRANK(dom_init); TRACE_1D(TRC_SCHED_DOM_ADD, d->domain_id); =20 + rcu_read_lock(&sched_res_rculock); + sdom =3D sched_alloc_domdata(dom_scheduler(d), d); + + rcu_read_unlock(&sched_res_rculock); + if ( IS_ERR(sdom) ) return PTR_ERR(sdom); =20 @@ -702,9 +738,13 @@ void sched_destroy_domain(struct domain *d) SCHED_STAT_CRANK(dom_destroy); TRACE_1D(TRC_SCHED_DOM_REM, d->domain_id); =20 + rcu_read_lock(&sched_res_rculock); + sched_free_domdata(dom_scheduler(d), d->sched_priv); d->sched_priv =3D NULL; =20 + rcu_read_unlock(&sched_res_rculock); + cpupool_rm_domain(d); } } @@ -738,11 +778,15 @@ void vcpu_sleep_nosync(struct vcpu *v) =20 TRACE_2D(TRC_SCHED_SLEEP, v->domain->domain_id, v->vcpu_id); =20 + rcu_read_lock(&sched_res_rculock); + lock =3D unit_schedule_lock_irqsave(v->sched_unit, &flags); =20 vcpu_sleep_nosync_locked(v); =20 unit_schedule_unlock_irqrestore(lock, flags, v->sched_unit); + + rcu_read_unlock(&sched_res_rculock); } =20 void vcpu_sleep_sync(struct vcpu *v) @@ -763,6 +807,8 @@ void vcpu_wake(struct vcpu *v) =20 TRACE_2D(TRC_SCHED_WAKE, v->domain->domain_id, v->vcpu_id); =20 + rcu_read_lock(&sched_res_rculock); + lock =3D unit_schedule_lock_irqsave(unit, &flags); =20 if ( likely(vcpu_runnable(v)) ) @@ -783,6 +829,8 @@ void vcpu_wake(struct vcpu *v) } =20 unit_schedule_unlock_irqrestore(lock, flags, unit); + + rcu_read_unlock(&sched_res_rculock); } =20 void vcpu_unblock(struct vcpu *v) @@ -816,6 +864,8 @@ static void sched_unit_move_locked(struct sched_unit *u= nit, unsigned int old_cpu =3D unit->res->processor; struct vcpu *v; =20 + rcu_read_lock(&sched_res_rculock); + /* * Transfer urgency status to new CPU before switching CPUs, as * once the switch occurs, v->is_urgent is no longer protected by @@ -835,6 +885,8 @@ static void sched_unit_move_locked(struct sched_unit *u= nit, * pointer can't change while the current lock is held. */ sched_migrate(unit_scheduler(unit), unit, new_cpu); + + rcu_read_unlock(&sched_res_rculock); } =20 /* @@ -1019,6 +1071,8 @@ void restore_vcpu_affinity(struct domain *d) =20 ASSERT(system_state =3D=3D SYS_STATE_resume); =20 + rcu_read_lock(&sched_res_rculock); + for_each_sched_unit ( d, unit ) { spinlock_t *lock; @@ -1075,6 +1129,8 @@ void restore_vcpu_affinity(struct domain *d) sched_move_irqs(unit); } =20 + rcu_read_unlock(&sched_res_rculock); + domain_update_node_affinity(d); } =20 @@ -1090,9 +1146,11 @@ int cpu_disable_scheduler(unsigned int cpu) cpumask_t online_affinity; int ret =3D 0; =20 + rcu_read_lock(&sched_res_rculock); + c =3D get_sched_res(cpu)->cpupool; if ( c =3D=3D NULL ) - return ret; + goto out; =20 for_each_domain_in_cpupool ( d, c ) { @@ -1150,6 +1208,9 @@ int cpu_disable_scheduler(unsigned int cpu) } } =20 +out: + rcu_read_unlock(&sched_res_rculock); + return ret; } =20 @@ -1183,7 +1244,9 @@ void sched_set_affinity( { struct sched_unit *unit =3D v->sched_unit; =20 + rcu_read_lock(&sched_res_rculock); sched_adjust_affinity(dom_scheduler(unit->domain), unit, hard, soft); + rcu_read_unlock(&sched_res_rculock); =20 if ( hard ) cpumask_copy(unit->cpu_hard_affinity, hard); @@ -1203,6 +1266,8 @@ static int vcpu_set_affinity( spinlock_t *lock; int ret =3D 0; =20 + rcu_read_lock(&sched_res_rculock); + lock =3D unit_schedule_lock_irq(unit); =20 if ( v->affinity_broken ) @@ -1231,6 +1296,8 @@ static int vcpu_set_affinity( =20 sched_unit_migrate_finish(unit); =20 + rcu_read_unlock(&sched_res_rculock); + return ret; } =20 @@ -1357,11 +1424,16 @@ static long do_poll(struct sched_poll *sched_poll) long vcpu_yield(void) { struct vcpu * v=3Dcurrent; - spinlock_t *lock =3D unit_schedule_lock_irq(v->sched_unit); + spinlock_t *lock; =20 + rcu_read_lock(&sched_res_rculock); + + lock =3D unit_schedule_lock_irq(v->sched_unit); sched_yield(vcpu_scheduler(v), v->sched_unit); unit_schedule_unlock_irq(lock, v->sched_unit); =20 + rcu_read_unlock(&sched_res_rculock); + SCHED_STAT_CRANK(vcpu_yield); =20 TRACE_2D(TRC_SCHED_YIELD, current->domain->domain_id, current->vcpu_id= ); @@ -1458,6 +1530,8 @@ int vcpu_temporary_affinity(struct vcpu *v, unsigned = int cpu, uint8_t reason) int ret =3D -EINVAL; bool migrate; =20 + rcu_read_lock(&sched_res_rculock); + lock =3D unit_schedule_lock_irq(unit); =20 if ( cpu =3D=3D NR_CPUS ) @@ -1497,6 +1571,8 @@ int vcpu_temporary_affinity(struct vcpu *v, unsigned = int cpu, uint8_t reason) if ( migrate ) sched_unit_migrate_finish(unit); =20 + rcu_read_unlock(&sched_res_rculock); + return ret; } =20 @@ -1708,9 +1784,13 @@ long sched_adjust(struct domain *d, struct xen_domct= l_scheduler_op *op) =20 /* NB: the pluggable scheduler code needs to take care * of locking by itself. */ + rcu_read_lock(&sched_res_rculock); + if ( (ret =3D sched_adjust_dom(dom_scheduler(d), d, op)) =3D=3D 0 ) TRACE_1D(TRC_SCHED_ADJDOM, d->domain_id); =20 + rcu_read_unlock(&sched_res_rculock); + return ret; } =20 @@ -1731,9 +1811,13 @@ long sched_adjust_global(struct xen_sysctl_scheduler= _op *op) if ( pool =3D=3D NULL ) return -ESRCH; =20 + rcu_read_lock(&sched_res_rculock); + rc =3D ((op->sched_id =3D=3D pool->sched->sched_id) ? sched_adjust_cpupool(pool->sched, op) : -EINVAL); =20 + rcu_read_unlock(&sched_res_rculock); + cpupool_put(pool); =20 return rc; @@ -1937,7 +2021,11 @@ static void context_saved(struct sched_resource *sd,= struct vcpu *vprev, void sched_context_switched(struct vcpu *vprev, struct vcpu *vnext) { struct sched_unit *next =3D vnext->sched_unit; - struct sched_resource *sd =3D get_sched_res(smp_processor_id()); + struct sched_resource *sd; + + rcu_read_lock(&sched_res_rculock); + + sd =3D get_sched_res(smp_processor_id()); =20 if ( atomic_read(&next->rendezvous_out_cnt) ) { @@ -1958,6 +2046,8 @@ void sched_context_switched(struct vcpu *vprev, struc= t vcpu *vnext) =20 if ( is_idle_vcpu(vprev) && vprev !=3D vnext ) vprev->sched_unit =3D sd->sched_unit_idle; + + rcu_read_unlock(&sched_res_rculock); } =20 static void sched_context_switch(struct vcpu *vprev, struct vcpu *vnext, @@ -1975,6 +2065,8 @@ static void sched_context_switch(struct vcpu *vprev, = struct vcpu *vnext, vnext->sched_unit =3D get_sched_res(smp_processor_id())->sched_unit_idle; =20 + rcu_read_unlock(&sched_res_rculock); + trace_continue_running(vnext); return continue_running(vprev); } @@ -1988,6 +2080,8 @@ static void sched_context_switch(struct vcpu *vprev, = struct vcpu *vnext, =20 vcpu_periodic_timer_work(vnext); =20 + rcu_read_unlock(&sched_res_rculock); + context_switch(vprev, vnext); } =20 @@ -2135,6 +2229,8 @@ static void sched_slave(void) =20 ASSERT_NOT_IN_ATOMIC(); =20 + rcu_read_lock(&sched_res_rculock); + lock =3D pcpu_schedule_lock_irq(cpu); =20 now =3D NOW(); @@ -2158,6 +2254,8 @@ static void sched_slave(void) { pcpu_schedule_unlock_irq(lock, cpu); =20 + rcu_read_unlock(&sched_res_rculock); + /* Check for failed forced context switch. */ if ( do_softirq ) raise_softirq(SCHEDULE_SOFTIRQ); @@ -2188,13 +2286,16 @@ static void schedule(void) struct sched_resource *sd; spinlock_t *lock; int cpu =3D smp_processor_id(); - unsigned int gran =3D get_sched_res(cpu)->granularity; + unsigned int gran; =20 ASSERT_NOT_IN_ATOMIC(); =20 SCHED_STAT_CRANK(sched_run); =20 + rcu_read_lock(&sched_res_rculock); + sd =3D get_sched_res(cpu); + gran =3D sd->granularity; =20 lock =3D pcpu_schedule_lock_irq(cpu); =20 @@ -2206,6 +2307,8 @@ static void schedule(void) */ pcpu_schedule_unlock_irq(lock, cpu); =20 + rcu_read_unlock(&sched_res_rculock); + raise_softirq(SCHEDULE_SOFTIRQ); return sched_slave(); } @@ -2315,14 +2418,27 @@ static int cpu_schedule_up(unsigned int cpu) return 0; } =20 +static void sched_res_free(struct rcu_head *head) +{ + struct sched_resource *sd =3D container_of(head, struct sched_resource= , rcu); + + xfree(sd); +} + static void cpu_schedule_down(unsigned int cpu) { - struct sched_resource *sd =3D get_sched_res(cpu); + struct sched_resource *sd; + + rcu_read_lock(&sched_res_rculock); + + sd =3D get_sched_res(cpu); =20 kill_timer(&sd->s_timer); =20 set_sched_res(cpu, NULL); - xfree(sd); + call_rcu(&sd->rcu, sched_res_free); + + rcu_read_unlock(&sched_res_rculock); } =20 void sched_rm_cpu(unsigned int cpu) @@ -2342,6 +2458,8 @@ static int cpu_schedule_callback( unsigned int cpu =3D (unsigned long)hcpu; int rc =3D 0; =20 + rcu_read_lock(&sched_res_rculock); + /* * From the scheduler perspective, bringing up a pCPU requires * allocating and initializing the per-pCPU scheduler specific data, @@ -2388,6 +2506,8 @@ static int cpu_schedule_callback( break; } =20 + rcu_read_unlock(&sched_res_rculock); + return !rc ? NOTIFY_DONE : notifier_from_errno(rc); } =20 @@ -2477,8 +2597,13 @@ void __init scheduler_init(void) idle_domain->max_vcpus =3D nr_cpu_ids; if ( vcpu_create(idle_domain, 0) =3D=3D NULL ) BUG(); + + rcu_read_lock(&sched_res_rculock); + get_sched_res(0)->curr =3D idle_vcpu[0]->sched_unit; get_sched_res(0)->sched_unit_idle =3D idle_vcpu[0]->sched_unit; + + rcu_read_unlock(&sched_res_rculock); } =20 /* @@ -2491,9 +2616,14 @@ int schedule_cpu_add(unsigned int cpu, struct cpupoo= l *c) struct vcpu *idle; void *ppriv, *vpriv; struct scheduler *new_ops =3D c->sched; - struct sched_resource *sd =3D get_sched_res(cpu); + struct sched_resource *sd; spinlock_t *old_lock, *new_lock; unsigned long flags; + int ret =3D 0; + + rcu_read_lock(&sched_res_rculock); + + sd =3D get_sched_res(cpu); =20 ASSERT(cpumask_test_cpu(cpu, &cpupool_free_cpus)); ASSERT(!cpumask_test_cpu(cpu, c->cpu_valid)); @@ -2513,13 +2643,18 @@ int schedule_cpu_add(unsigned int cpu, struct cpupo= ol *c) idle =3D idle_vcpu[cpu]; ppriv =3D sched_alloc_pdata(new_ops, cpu); if ( IS_ERR(ppriv) ) - return PTR_ERR(ppriv); + { + ret =3D PTR_ERR(ppriv); + goto out; + } + vpriv =3D sched_alloc_vdata(new_ops, idle->sched_unit, idle->domain->sched_priv); if ( vpriv =3D=3D NULL ) { sched_free_pdata(new_ops, ppriv, cpu); - return -ENOMEM; + ret =3D -ENOMEM; + goto out; } =20 /* @@ -2558,7 +2693,10 @@ int schedule_cpu_add(unsigned int cpu, struct cpupoo= l *c) /* The cpu is added to a pool, trigger it to go pick up some work */ cpu_raise_softirq(cpu, SCHEDULE_SOFTIRQ); =20 - return 0; +out: + rcu_read_unlock(&sched_res_rculock); + + return ret; } =20 /* @@ -2571,11 +2709,16 @@ int schedule_cpu_rm(unsigned int cpu) { struct vcpu *idle; void *ppriv_old, *vpriv_old; - struct sched_resource *sd =3D get_sched_res(cpu); - struct scheduler *old_ops =3D sd->scheduler; + struct sched_resource *sd; + struct scheduler *old_ops; spinlock_t *old_lock; unsigned long flags; =20 + rcu_read_lock(&sched_res_rculock); + + sd =3D get_sched_res(cpu); + old_ops =3D sd->scheduler; + ASSERT(sd->cpupool !=3D NULL); ASSERT(cpumask_test_cpu(cpu, &cpupool_free_cpus)); ASSERT(!cpumask_test_cpu(cpu, sd->cpupool->cpu_valid)); @@ -2608,6 +2751,8 @@ int schedule_cpu_rm(unsigned int cpu) sd->granularity =3D 1; sd->cpupool =3D NULL; =20 + rcu_read_unlock(&sched_res_rculock); + return 0; } =20 @@ -2656,6 +2801,8 @@ void schedule_dump(struct cpupool *c) =20 /* Locking, if necessary, must be handled withing each scheduler */ =20 + rcu_read_lock(&sched_res_rculock); + if ( c !=3D NULL ) { sched =3D c->sched; @@ -2675,6 +2822,8 @@ void schedule_dump(struct cpupool *c) for_each_cpu (i, cpus) sched_dump_cpu_state(sched, i); } + + rcu_read_unlock(&sched_res_rculock); } =20 void sched_tick_suspend(void) @@ -2682,10 +2831,14 @@ void sched_tick_suspend(void) struct scheduler *sched; unsigned int cpu =3D smp_processor_id(); =20 + rcu_read_lock(&sched_res_rculock); + sched =3D get_sched_res(cpu)->scheduler; sched_do_tick_suspend(sched, cpu); rcu_idle_enter(cpu); rcu_idle_timer_start(); + + rcu_read_unlock(&sched_res_rculock); } =20 void sched_tick_resume(void) @@ -2693,10 +2846,14 @@ void sched_tick_resume(void) struct scheduler *sched; unsigned int cpu =3D smp_processor_id(); =20 + rcu_read_lock(&sched_res_rculock); + rcu_idle_timer_stop(); rcu_idle_exit(cpu); sched =3D get_sched_res(cpu)->scheduler; sched_do_tick_resume(sched, cpu); + + rcu_read_unlock(&sched_res_rculock); } =20 void wait(void) @@ -2711,7 +2868,13 @@ void wait(void) */ bool sched_has_urgent_vcpu(void) { - return atomic_read(&get_sched_res(smp_processor_id())->urgent_count); + int val; + + rcu_read_lock(&sched_res_rculock); + val =3D atomic_read(&get_sched_res(smp_processor_id())->urgent_count); + rcu_read_unlock(&sched_res_rculock); + + return val; } =20 #ifdef CONFIG_COMPAT diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 606a0d4a25..de50b4ebca 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -10,6 +10,7 @@ =20 #include #include +#include =20 /* A global pointer to the initial cpupool (POOL0). */ extern struct cpupool *cpupool0; @@ -58,20 +59,22 @@ struct sched_resource { unsigned int processor; unsigned int granularity; const cpumask_t *cpus; /* cpus covered by this struct = */ + struct rcu_head rcu; }; =20 #define curr_on_cpu(c) (get_sched_res(c)->curr) =20 DECLARE_PER_CPU(struct sched_resource *, sched_res); +extern rcu_read_lock_t sched_res_rculock; =20 static inline struct sched_resource *get_sched_res(unsigned int cpu) { - return per_cpu(sched_res, cpu); + return rcu_dereference(per_cpu(sched_res, cpu)); } =20 static inline void set_sched_res(unsigned int cpu, struct sched_resource *= res) { - per_cpu(sched_res, cpu) =3D res; + rcu_assign_pointer(per_cpu(sched_res, cpu), res); } =20 static inline bool is_idle_unit(const struct sched_unit *unit) --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362791; cv=none; d=zoho.com; s=zohoarc; b=m2F3RrCrVwuqeCqe+ZANVbR5JzjF5Am0hWk/ROE2afY7n3Yg9r8OHkL7rJZbPm7cU1+fZeNZcQivb/lJoJ8ihmQ9/Fgzyr4SpQVKrFAbe8DbqMmhaedbs9iLSKzR6rfTnbEnK2l3+FX3/3mTG1HwQbPQP+UhPmf4z6TAy6uMd+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362791; 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=3iqPojdLEjaLgwLgc83KmRAW/z8oRKFJU1eTO1AjgN4=; b=mxEz4iPbolqhGl37AgfptFkIeVo/l0y/7DTPZdNvqvn5aa6GxQmfTic2YrsG69E9mx0KY5oUZmGXW1SCtpGS2bmkgSsGPNHb8kSYEQUyNSwi7H0y7vwcBLCwBTtrPmkxezNqi5W5dvffOoYTRXlGvkBdiRJjfc4Pw/pmh0AdCDk= 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 1565362791566269.4376300529234; Fri, 9 Aug 2019 07:59:51 -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 1hw6MP-0007Q8-8T; Fri, 09 Aug 2019 14:59:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw6M5-0006hN-Cv for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:57 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 34a66604-bab6-11e9-8980-bc764e045a96; Fri, 09 Aug 2019 14:58:54 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D4B03B061; Fri, 9 Aug 2019 14:58:53 +0000 (UTC) X-Inumbo-ID: 34a66604-bab6-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:29 +0200 Message-Id: <20190809145833.1020-45-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 44/48] xen/sched: support multiple cpus per scheduling 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 , 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" Prepare supporting multiple cpus per scheduling resource by allocating the cpumask per resource dynamically. Modify sched_res_mask to have only one bit per scheduling resource set. Signed-off-by: Juergen Gross --- V1: new patch (carved out from other patch) --- xen/common/schedule.c | 16 ++++++++++++++-- xen/include/xen/sched-if.h | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index f95d346330..948fe1b838 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -59,7 +59,7 @@ integer_param("sched_ratelimit_us", sched_ratelimit_us); enum sched_gran __read_mostly opt_sched_granularity =3D SCHED_GRAN_cpu; unsigned int __read_mostly sched_granularity =3D 1; bool __read_mostly sched_disable_smt_switching; -const cpumask_t *sched_res_mask =3D &cpumask_all; +cpumask_var_t sched_res_mask; =20 /* Common lock for free cpus. */ static DEFINE_SPINLOCK(sched_free_cpu_lock); @@ -2377,8 +2377,14 @@ static int cpu_schedule_up(unsigned int cpu) sd =3D xzalloc(struct sched_resource); if ( sd =3D=3D NULL ) return -ENOMEM; + if ( !zalloc_cpumask_var(&sd->cpus) ) + { + xfree(sd); + return -ENOMEM; + } + sd->processor =3D cpu; - sd->cpus =3D cpumask_of(cpu); + cpumask_copy(sd->cpus, cpumask_of(cpu)); set_sched_res(cpu, sd); =20 sd->scheduler =3D &sched_idle_ops; @@ -2390,6 +2396,8 @@ static int cpu_schedule_up(unsigned int cpu) /* We start with cpu granularity. */ sd->granularity =3D 1; =20 + cpumask_set_cpu(cpu, sched_res_mask); + /* Boot CPU is dealt with later in scheduler_init(). */ if ( cpu =3D=3D 0 ) return 0; @@ -2422,6 +2430,7 @@ static void sched_res_free(struct rcu_head *head) { struct sched_resource *sd =3D container_of(head, struct sched_resource= , rcu); =20 + free_cpumask_var(sd->cpus); xfree(sd); } =20 @@ -2570,6 +2579,9 @@ void __init scheduler_init(void) printk("Using '%s' (%s)\n", ops.name, ops.opt_name); } =20 + if ( !zalloc_cpumask_var(&sched_res_mask) ) + BUG(); + if ( cpu_schedule_up(0) ) BUG(); register_cpu_notifier(&cpu_schedule_nfb); diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index de50b4ebca..5a93ba3686 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -24,7 +24,7 @@ extern cpumask_t cpupool_free_cpus; extern int sched_ratelimit_us; =20 /* Scheduling resource mask. */ -extern const cpumask_t *sched_res_mask; +extern cpumask_var_t sched_res_mask; =20 /* Number of vcpus per struct sched_unit. */ enum sched_gran { @@ -58,7 +58,7 @@ struct sched_resource { atomic_t urgent_count; /* how many urgent vcpus = */ unsigned int processor; unsigned int granularity; - const cpumask_t *cpus; /* cpus covered by this struct = */ + cpumask_var_t cpus; /* cpus covered by this struct = */ struct rcu_head rcu; }; =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362809; cv=none; d=zoho.com; s=zohoarc; b=F8WRbhojIQO3T0tH7/m6IPzAqoKVO3L1diynHB6ZTqlkwU7dZvemNldcivm94CSA9qr7+bP17Df969dG6h94dxlYJU7TJsorAsF40a1McR27qJ1zDwBS7G9YIiGtitA0cDEnYn5fvLFu7+rQpLoYfep5AK7boDwgphcTRv/oLos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362809; 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=/3eTw08YKCe+gZoirblctVzahQXJiBcZwMnm6UZGnAc=; b=Ov105rDrQ9I/zR976MElDojgxUUsgizg2+7mG/Lg3vC5EIFvQ97xCRQHlxvbzMsw7N9jewkccGLVNx5immSTRVR0h+RaCAB4jMXAf0dyYfuh+7iQsb96j/EI7W0ed9/ViiLUVmlWOyUdDndYxEgF/b4esFQNQYTGN9g6YE8XYv8= 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 1565362809529563.8072967724277; Fri, 9 Aug 2019 08:00:09 -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 1hw6Me-00081b-Vw; Fri, 09 Aug 2019 14:59:32 +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 1hw6M7-0006lz-Lx for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:59 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 34b81f4c-bab6-11e9-8314-cfb7583ac403; Fri, 09 Aug 2019 14:58:54 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0D1B4B0B3; Fri, 9 Aug 2019 14:58:54 +0000 (UTC) X-Inumbo-ID: 34b81f4c-bab6-11e9-8314-cfb7583ac403 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:30 +0200 Message-Id: <20190809145833.1020-46-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 45/48] xen/sched: support differing granularity in schedule_cpu_[add/rm]() 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 , George Dunlap , Dario Faggioli 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" With core scheduling active schedule_cpu_[add/rm]() has to cope with different scheduling granularity: a cpu not in any cpupool is subject to granularity 1 (cpu scheduling), while a cpu in a cpupool might be in a scheduling resource with more than one cpu. Handle that by having arrays of old/new pdata and vdata and loop over those where appropriate. Additionally the scheduling resource(s) must either be merged or split. Signed-off-by: Juergen Gross --- xen/common/cpupool.c | 18 ++-- xen/common/schedule.c | 226 +++++++++++++++++++++++++++++++++++++++++++---= ---- 2 files changed, 204 insertions(+), 40 deletions(-) diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c index 5d5c8d5430..41d594dace 100644 --- a/xen/common/cpupool.c +++ b/xen/common/cpupool.c @@ -535,6 +535,7 @@ static void cpupool_cpu_remove(unsigned int cpu) ret =3D cpupool_unassign_cpu_epilogue(cpupool0); BUG_ON(ret); } + cpumask_clear_cpu(cpu, &cpupool_free_cpus); } =20 /* @@ -584,20 +585,19 @@ static void cpupool_cpu_remove_forced(unsigned int cp= u) struct cpupool **c; int ret; =20 - if ( cpumask_test_cpu(cpu, &cpupool_free_cpus) ) - cpumask_clear_cpu(cpu, &cpupool_free_cpus); - else + for_each_cpupool ( c ) { - for_each_cpupool(c) + if ( cpumask_test_cpu(cpu, (*c)->cpu_valid) ) { - if ( cpumask_test_cpu(cpu, (*c)->cpu_valid) ) - { - ret =3D cpupool_unassign_cpu(*c, cpu); - BUG_ON(ret); - } + ret =3D cpupool_unassign_cpu_prologue(*c, cpu); + BUG_ON(ret); + ret =3D cpupool_unassign_cpu_epilogue(*c); + BUG_ON(ret); } } =20 + cpumask_clear_cpu(cpu, &cpupool_free_cpus); + rcu_read_lock(&sched_res_rculock); sched_rm_cpu(cpu); rcu_read_unlock(&sched_res_rculock); diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 948fe1b838..a4555fd0fa 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -407,26 +407,29 @@ static void sched_unit_add_vcpu(struct sched_unit *un= it, struct vcpu *v) unit->runstate_cnt[v->runstate.state]++; } =20 -static struct sched_unit *sched_alloc_unit(struct vcpu *v) +static struct sched_unit *sched_alloc_unit_mem(void) { - struct sched_unit *unit, **prev_unit; - struct domain *d =3D v->domain; - unsigned int gran =3D d->cpupool ? d->cpupool->granularity : 1; + struct sched_unit *unit; =20 - for_each_sched_unit ( d, unit ) - if ( unit->vcpu_list->vcpu_id / gran =3D=3D v->vcpu_id / gran ) - break; + unit =3D xzalloc(struct sched_unit); + if ( !unit ) + return NULL; =20 - if ( unit ) + if ( !zalloc_cpumask_var(&unit->cpu_hard_affinity) || + !zalloc_cpumask_var(&unit->cpu_hard_affinity_saved) || + !zalloc_cpumask_var(&unit->cpu_soft_affinity) ) { - sched_unit_add_vcpu(unit, v); - return unit; + sched_free_unit_mem(unit); + unit =3D NULL; } =20 - if ( (unit =3D xzalloc(struct sched_unit)) =3D=3D NULL ) - return NULL; + return unit; +} + +static void sched_domain_insert_unit(struct sched_unit *unit, struct domai= n *d) +{ + struct sched_unit **prev_unit; =20 - sched_unit_add_vcpu(unit, v); unit->domain =3D d; =20 for ( prev_unit =3D &d->sched_unit_list; *prev_unit; @@ -437,17 +440,31 @@ static struct sched_unit *sched_alloc_unit(struct vcp= u *v) =20 unit->next_in_list =3D *prev_unit; *prev_unit =3D unit; +} =20 - if ( !zalloc_cpumask_var(&unit->cpu_hard_affinity) || - !zalloc_cpumask_var(&unit->cpu_hard_affinity_saved) || - !zalloc_cpumask_var(&unit->cpu_soft_affinity) ) - goto fail; +static struct sched_unit *sched_alloc_unit(struct vcpu *v) +{ + struct sched_unit *unit; + struct domain *d =3D v->domain; + unsigned int gran =3D d->cpupool ? d->cpupool->granularity : 1; =20 - return unit; + for_each_sched_unit ( d, unit ) + if ( unit->vcpu_list->vcpu_id / gran =3D=3D v->vcpu_id / gran ) + break; =20 - fail: - sched_free_unit(unit, v); - return NULL; + if ( unit ) + { + sched_unit_add_vcpu(unit, v); + return unit; + } + + if ( (unit =3D sched_alloc_unit_mem()) =3D=3D NULL ) + return NULL; + + sched_unit_add_vcpu(unit, v); + sched_domain_insert_unit(unit, d); + + return unit; } =20 static unsigned int sched_select_initial_cpu(const struct vcpu *v) @@ -2370,18 +2387,28 @@ static void poll_timer_fn(void *data) vcpu_unblock(v); } =20 -static int cpu_schedule_up(unsigned int cpu) +static struct sched_resource *sched_alloc_res(void) { struct sched_resource *sd; =20 sd =3D xzalloc(struct sched_resource); if ( sd =3D=3D NULL ) - return -ENOMEM; + return NULL; if ( !zalloc_cpumask_var(&sd->cpus) ) { xfree(sd); - return -ENOMEM; + return NULL; } + return sd; +} + +static int cpu_schedule_up(unsigned int cpu) +{ + struct sched_resource *sd; + + sd =3D sched_alloc_res(); + if ( sd =3D=3D NULL ) + return -ENOMEM; =20 sd->processor =3D cpu; cpumask_copy(sd->cpus, cpumask_of(cpu)); @@ -2431,6 +2458,8 @@ static void sched_res_free(struct rcu_head *head) struct sched_resource *sd =3D container_of(head, struct sched_resource= , rcu); =20 free_cpumask_var(sd->cpus); + if ( sd->sched_unit_idle ) + sched_free_unit_mem(sd->sched_unit_idle); xfree(sd); } =20 @@ -2445,6 +2474,8 @@ static void cpu_schedule_down(unsigned int cpu) kill_timer(&sd->s_timer); =20 set_sched_res(cpu, NULL); + /* Keep idle unit. */ + sd->sched_unit_idle =3D NULL; call_rcu(&sd->rcu, sched_res_free); =20 rcu_read_unlock(&sched_res_rculock); @@ -2524,6 +2555,30 @@ static struct notifier_block cpu_schedule_nfb =3D { .notifier_call =3D cpu_schedule_callback }; =20 +static const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, + unsigned int cpu) +{ + const cpumask_t *mask; + + switch ( opt ) + { + case SCHED_GRAN_cpu: + mask =3D cpumask_of(cpu); + break; + case SCHED_GRAN_core: + mask =3D per_cpu(cpu_sibling_mask, cpu); + break; + case SCHED_GRAN_socket: + mask =3D per_cpu(cpu_core_mask, cpu); + break; + default: + ASSERT_UNREACHABLE(); + return NULL; + } + + return mask; +} + /* Initialise the data structures. */ void __init scheduler_init(void) { @@ -2682,6 +2737,46 @@ int schedule_cpu_add(unsigned int cpu, struct cpupoo= l *c) */ old_lock =3D pcpu_schedule_lock_irqsave(cpu, &flags); =20 + if ( c->granularity > 1 ) + { + const cpumask_t *mask; + unsigned int cpu_iter, idx =3D 0; + struct sched_unit *old_unit, *master_unit; + struct sched_resource *sd_old; + + /* + * We need to merge multiple idle_vcpu units and sched_resource st= ructs + * into one. As the free cpus all share the same lock we are fine = doing + * that now. The worst which could happen would be someone waiting= for + * the lock, thus dereferencing sched_res->schedule_lock. This is = the + * reason we are freeing struct sched_res via call_rcu() to avoid = the + * lock pointer suddenly disappearing. + */ + mask =3D sched_get_opt_cpumask(c->opt_granularity, cpu); + master_unit =3D idle_vcpu[cpu]->sched_unit; + + for_each_cpu ( cpu_iter, mask ) + { + if ( idx ) + cpumask_clear_cpu(cpu_iter, sched_res_mask); + + per_cpu(sched_res_idx, cpu_iter) =3D idx++; + + if ( cpu =3D=3D cpu_iter ) + continue; + + old_unit =3D idle_vcpu[cpu_iter]->sched_unit; + sd_old =3D get_sched_res(cpu_iter); + kill_timer(&sd_old->s_timer); + idle_vcpu[cpu_iter]->sched_unit =3D master_unit; + master_unit->runstate_cnt[RUNSTATE_running]++; + set_sched_res(cpu_iter, sd); + cpumask_set_cpu(cpu_iter, sd->cpus); + + call_rcu(&sd_old->rcu, sched_res_free); + } + } + new_lock =3D sched_switch_sched(new_ops, cpu, ppriv, vpriv); =20 sd->scheduler =3D new_ops; @@ -2719,33 +2814,100 @@ out: */ int schedule_cpu_rm(unsigned int cpu) { - struct vcpu *idle; void *ppriv_old, *vpriv_old; - struct sched_resource *sd; + struct sched_resource *sd, **sd_new =3D NULL; + struct sched_unit *unit; struct scheduler *old_ops; spinlock_t *old_lock; unsigned long flags; + int idx, ret =3D -ENOMEM; + unsigned int cpu_iter; =20 rcu_read_lock(&sched_res_rculock); =20 sd =3D get_sched_res(cpu); old_ops =3D sd->scheduler; =20 + if ( sd->granularity > 1 ) + { + sd_new =3D xmalloc_array(struct sched_resource *, sd->granularity = - 1); + if ( !sd_new ) + goto out; + for ( idx =3D 0; idx < sd->granularity - 1; idx++ ) + { + sd_new[idx] =3D sched_alloc_res(); + if ( sd_new[idx] ) + { + sd_new[idx]->sched_unit_idle =3D sched_alloc_unit_mem(); + if ( !sd_new[idx]->sched_unit_idle ) + { + sched_res_free(&sd_new[idx]->rcu); + sd_new[idx] =3D NULL; + } + } + if ( !sd_new[idx] ) + { + for ( idx--; idx >=3D 0; idx-- ) + sched_res_free(&sd_new[idx]->rcu); + goto out; + } + sd_new[idx]->curr =3D sd_new[idx]->sched_unit_idle; + sd_new[idx]->scheduler =3D &sched_idle_ops; + sd_new[idx]->granularity =3D 1; + + /* We want the lock not to change when replacing the resource.= */ + sd_new[idx]->schedule_lock =3D sd->schedule_lock; + } + } + + ret =3D 0; ASSERT(sd->cpupool !=3D NULL); ASSERT(cpumask_test_cpu(cpu, &cpupool_free_cpus)); ASSERT(!cpumask_test_cpu(cpu, sd->cpupool->cpu_valid)); =20 - idle =3D idle_vcpu[cpu]; - sched_do_tick_suspend(old_ops, cpu); =20 /* See comment in schedule_cpu_add() regarding lock switching. */ old_lock =3D pcpu_schedule_lock_irqsave(cpu, &flags); =20 - vpriv_old =3D idle->sched_unit->priv; + vpriv_old =3D idle_vcpu[cpu]->sched_unit->priv; ppriv_old =3D sd->sched_priv; =20 - idle->sched_unit->priv =3D NULL; + idx =3D 0; + for_each_cpu ( cpu_iter, sd->cpus ) + { + per_cpu(sched_res_idx, cpu_iter) =3D 0; + if ( cpu_iter =3D=3D cpu ) + { + idle_vcpu[cpu_iter]->sched_unit->priv =3D NULL; + } + else + { + /* Initialize unit. */ + unit =3D sd_new[idx]->sched_unit_idle; + unit->res =3D sd_new[idx]; + unit->is_running =3D true; + sched_unit_add_vcpu(unit, idle_vcpu[cpu_iter]); + sched_domain_insert_unit(unit, idle_vcpu[cpu_iter]->domain); + + /* Adjust cpu masks of resources (old and new). */ + cpumask_clear_cpu(cpu_iter, sd->cpus); + cpumask_set_cpu(cpu_iter, sd_new[idx]->cpus); + + /* Init timer. */ + init_timer(&sd_new[idx]->s_timer, s_timer_fn, NULL, cpu_iter); + + /* Last resource initializations and insert resource pointer. = */ + sd_new[idx]->processor =3D cpu_iter; + set_sched_res(cpu_iter, sd_new[idx]); + + /* Last action: set the new lock pointer. */ + smp_mb(); + sd_new[idx]->schedule_lock =3D &sched_free_cpu_lock; + + idx++; + } + } sd->scheduler =3D &sched_idle_ops; sd->sched_priv =3D NULL; =20 @@ -2763,9 +2925,11 @@ int schedule_cpu_rm(unsigned int cpu) sd->granularity =3D 1; sd->cpupool =3D NULL; =20 +out: rcu_read_unlock(&sched_res_rculock); + xfree(sd_new); =20 - return 0; + return ret; } =20 struct scheduler *scheduler_get_default(void) --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362835; cv=none; d=zoho.com; s=zohoarc; b=frDnAoD2SG+bpnjE2cKcUdUJjrLqXWcJI/Shsi1S80riLKlVoInjrIsewIowrHuG/LPNpjVoMhKtp2Rl6r956eug3Qvp4IOONoj2hYeE7z3dgwKSBvc7PzF3GB4PlY5uESunl1Wvoy5PwPffeOob9WB2YOKSS/444JQBv/duEeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362835; 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=JoBcocbgxEr7mil4xTw1Sg/zEJqBGJhNOgbyJakh19U=; b=XAYTxNU+PlmvqwY3o+3WKmDyZ6M/dTt/bQ2vVfmxfpo0vbJf6YJYCgNsSM2kSZqT3E/CFywd4xan1fI0H30wwVFShetXqNuroVdpqqDnzSY4iimDmnMykWGbpVNVdTB6VapLmiJKvvXZ/NNy9cd9oOKbSzbQlyvEl87DJlVJ0mg= 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 1565362835268272.88176712130064; Fri, 9 Aug 2019 08:00:35 -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 1hw6Mp-0008Ow-AJ; Fri, 09 Aug 2019 14:59:43 +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 1hw6MB-0006t3-4E for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:59:03 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 34fd25a6-bab6-11e9-b716-dbbe3c07e572; Fri, 09 Aug 2019 14:58:59 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 7525FB077; Fri, 9 Aug 2019 14:58:54 +0000 (UTC) X-Inumbo-ID: 34fd25a6-bab6-11e9-b716-dbbe3c07e572 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:31 +0200 Message-Id: <20190809145833.1020-47-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 46/48] xen/sched: support core scheduling for moving cpus to/from cpupools 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" With core scheduling active it is necessary to move multiple cpus at the same time to or from a cpupool in order to avoid split scheduling resources in between. Signed-off-by: Juergen Gross --- V1: new patch --- xen/common/cpupool.c | 100 +++++++++++++++++++++++++++++++++--------= ---- xen/common/schedule.c | 3 +- xen/include/xen/sched-if.h | 1 + 3 files changed, 76 insertions(+), 28 deletions(-) diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c index 41d594dace..6917488210 100644 --- a/xen/common/cpupool.c +++ b/xen/common/cpupool.c @@ -265,23 +265,30 @@ static int cpupool_assign_cpu_locked(struct cpupool *= c, unsigned int cpu) { int ret; struct domain *d; + const cpumask_t *cpus; + + cpus =3D sched_get_opt_cpumask(c->opt_granularity, cpu); =20 if ( (cpupool_moving_cpu =3D=3D cpu) && (c !=3D cpupool_cpu_moving) ) return -EADDRNOTAVAIL; - ret =3D schedule_cpu_add(cpu, c); + ret =3D schedule_cpu_add(cpumask_first(cpus), c); if ( ret ) return ret; =20 - cpumask_clear_cpu(cpu, &cpupool_free_cpus); + rcu_read_lock(&sched_res_rculock); + + cpumask_andnot(&cpupool_free_cpus, &cpupool_free_cpus, cpus); if (cpupool_moving_cpu =3D=3D cpu) { cpupool_moving_cpu =3D -1; cpupool_put(cpupool_cpu_moving); cpupool_cpu_moving =3D NULL; } - cpumask_set_cpu(cpu, c->cpu_valid); + cpumask_or(c->cpu_valid, c->cpu_valid, cpus); cpumask_and(c->res_valid, c->cpu_valid, sched_res_mask); =20 + rcu_read_unlock(&sched_res_rculock); + rcu_read_lock(&domlist_read_lock); for_each_domain_in_cpupool(d, c) { @@ -295,6 +302,7 @@ static int cpupool_assign_cpu_locked(struct cpupool *c,= unsigned int cpu) static int cpupool_unassign_cpu_epilogue(struct cpupool *c) { int cpu =3D cpupool_moving_cpu; + const cpumask_t *cpus; struct domain *d; int ret; =20 @@ -307,7 +315,10 @@ static int cpupool_unassign_cpu_epilogue(struct cpupoo= l *c) */ rcu_read_lock(&domlist_read_lock); ret =3D cpu_disable_scheduler(cpu); - cpumask_set_cpu(cpu, &cpupool_free_cpus); + + rcu_read_lock(&sched_res_rculock); + cpus =3D get_sched_res(cpu)->cpus; + cpumask_or(&cpupool_free_cpus, &cpupool_free_cpus, cpus); =20 /* * cpu_disable_scheduler() returning an error doesn't require resetting @@ -320,7 +331,7 @@ static int cpupool_unassign_cpu_epilogue(struct cpupool= *c) { ret =3D schedule_cpu_rm(cpu); if ( ret ) - cpumask_clear_cpu(cpu, &cpupool_free_cpus); + cpumask_andnot(&cpupool_free_cpus, &cpupool_free_cpus, cpus); else { cpupool_moving_cpu =3D -1; @@ -328,6 +339,7 @@ static int cpupool_unassign_cpu_epilogue(struct cpupool= *c) cpupool_cpu_moving =3D NULL; } } + rcu_read_unlock(&sched_res_rculock); =20 for_each_domain_in_cpupool(d, c) { @@ -342,6 +354,7 @@ static int cpupool_unassign_cpu_prologue(struct cpupool= *c, unsigned int cpu) { int ret; struct domain *d; + const cpumask_t *cpus; =20 spin_lock(&cpupool_lock); ret =3D -EADDRNOTAVAIL; @@ -352,7 +365,11 @@ static int cpupool_unassign_cpu_prologue(struct cpupoo= l *c, unsigned int cpu) if ( !cpumask_test_cpu(cpu, c->cpu_valid) && (cpu !=3D cpupool_moving_= cpu) ) goto out; =20 - if ( (c->n_dom > 0) && (cpumask_weight(c->cpu_valid) =3D=3D 1) && + rcu_read_lock(&sched_res_rculock); + cpus =3D get_sched_res(cpu)->cpus; + + if ( (c->n_dom > 0) && + (cpumask_weight(c->cpu_valid) =3D=3D cpumask_weight(cpus)) && (cpu !=3D cpupool_moving_cpu) ) { rcu_read_lock(&domlist_read_lock); @@ -374,9 +391,10 @@ static int cpupool_unassign_cpu_prologue(struct cpupoo= l *c, unsigned int cpu) cpupool_moving_cpu =3D cpu; atomic_inc(&c->refcnt); cpupool_cpu_moving =3D c; - cpumask_clear_cpu(cpu, c->cpu_valid); + cpumask_andnot(c->cpu_valid, c->cpu_valid, cpus); cpumask_and(c->res_valid, c->cpu_valid, sched_res_mask); =20 + rcu_read_unlock(&domlist_read_lock); out: spin_unlock(&cpupool_lock); =20 @@ -416,11 +434,13 @@ static int cpupool_unassign_cpu(struct cpupool *c, un= signed int cpu) { int work_cpu; int ret; + unsigned int master_cpu; =20 cpupool_dprintk("cpupool_unassign_cpu(pool=3D%d,cpu=3D%d)\n", c->cpupool_id, cpu); =20 - ret =3D cpupool_unassign_cpu_prologue(c, cpu); + master_cpu =3D sched_get_resource_cpu(cpu); + ret =3D cpupool_unassign_cpu_prologue(c, master_cpu); if ( ret ) { cpupool_dprintk("cpupool_unassign_cpu(pool=3D%d,cpu=3D%d) ret %d\n= ", @@ -428,12 +448,12 @@ static int cpupool_unassign_cpu(struct cpupool *c, un= signed int cpu) return ret; } =20 - work_cpu =3D smp_processor_id(); - if ( work_cpu =3D=3D cpu ) + work_cpu =3D sched_get_resource_cpu(smp_processor_id()); + if ( work_cpu =3D=3D master_cpu ) { work_cpu =3D cpumask_first(cpupool0->cpu_valid); - if ( work_cpu =3D=3D cpu ) - work_cpu =3D cpumask_next(cpu, cpupool0->cpu_valid); + if ( work_cpu =3D=3D master_cpu ) + work_cpu =3D cpumask_last(cpupool0->cpu_valid); } return continue_hypercall_on_cpu(work_cpu, cpupool_unassign_cpu_helper= , c); } @@ -499,6 +519,7 @@ void cpupool_rm_domain(struct domain *d) static int cpupool_cpu_add(unsigned int cpu) { int ret =3D 0; + const cpumask_t *cpus; =20 spin_lock(&cpupool_lock); cpumask_clear_cpu(cpu, &cpupool_locked_cpus); @@ -512,7 +533,11 @@ static int cpupool_cpu_add(unsigned int cpu) */ rcu_read_lock(&sched_res_rculock); get_sched_res(cpu)->cpupool =3D NULL; - ret =3D cpupool_assign_cpu_locked(cpupool0, cpu); + + cpus =3D sched_get_opt_cpumask(cpupool0->opt_granularity, cpu); + if ( cpumask_subset(cpus, &cpupool_free_cpus) ) + ret =3D cpupool_assign_cpu_locked(cpupool0, cpu); + rcu_read_unlock(&sched_res_rculock); =20 spin_unlock(&cpupool_lock); @@ -547,27 +572,33 @@ static void cpupool_cpu_remove(unsigned int cpu) static int cpupool_cpu_remove_prologue(unsigned int cpu) { int ret =3D 0; + cpumask_t *cpus; + unsigned int master_cpu; =20 spin_lock(&cpupool_lock); =20 - if ( cpumask_test_cpu(cpu, &cpupool_locked_cpus) ) + rcu_read_lock(&sched_res_rculock); + cpus =3D get_sched_res(cpu)->cpus; + master_cpu =3D sched_get_resource_cpu(cpu); + if ( cpumask_intersects(cpus, &cpupool_locked_cpus) ) ret =3D -EBUSY; else cpumask_set_cpu(cpu, &cpupool_locked_cpus); + rcu_read_unlock(&sched_res_rculock); =20 spin_unlock(&cpupool_lock); =20 if ( ret ) return ret; =20 - if ( cpumask_test_cpu(cpu, cpupool0->cpu_valid) ) + if ( cpumask_test_cpu(master_cpu, cpupool0->cpu_valid) ) { /* Cpupool0 is populated only after all cpus are up. */ ASSERT(system_state =3D=3D SYS_STATE_active); =20 - ret =3D cpupool_unassign_cpu_prologue(cpupool0, cpu); + ret =3D cpupool_unassign_cpu_prologue(cpupool0, master_cpu); } - else if ( !cpumask_test_cpu(cpu, &cpupool_free_cpus) ) + else if ( !cpumask_test_cpu(master_cpu, &cpupool_free_cpus) ) ret =3D -ENODEV; =20 return ret; @@ -584,12 +615,13 @@ static void cpupool_cpu_remove_forced(unsigned int cp= u) { struct cpupool **c; int ret; + unsigned int master_cpu =3D sched_get_resource_cpu(cpu); =20 for_each_cpupool ( c ) { - if ( cpumask_test_cpu(cpu, (*c)->cpu_valid) ) + if ( cpumask_test_cpu(master_cpu, (*c)->cpu_valid) ) { - ret =3D cpupool_unassign_cpu_prologue(*c, cpu); + ret =3D cpupool_unassign_cpu_prologue(*c, master_cpu); BUG_ON(ret); ret =3D cpupool_unassign_cpu_epilogue(*c); BUG_ON(ret); @@ -657,27 +689,43 @@ int cpupool_do_sysctl(struct xen_sysctl_cpupool_op *o= p) case XEN_SYSCTL_CPUPOOL_OP_ADDCPU: { unsigned cpu; + const cpumask_t *cpus; =20 cpu =3D op->cpu; cpupool_dprintk("cpupool_assign_cpu(pool=3D%d,cpu=3D%d)\n", op->cpupool_id, cpu); + spin_lock(&cpupool_lock); + + c =3D cpupool_find_by_id(op->cpupool_id); + ret =3D -ENOENT; + if ( c =3D=3D NULL ) + goto addcpu_out; if ( cpu =3D=3D XEN_SYSCTL_CPUPOOL_PAR_ANY ) - cpu =3D cpumask_first(&cpupool_free_cpus); + { + for_each_cpu ( cpu, &cpupool_free_cpus ) + { + cpus =3D sched_get_opt_cpumask(c->opt_granularity, cpu); + if ( cpumask_subset(cpus, &cpupool_free_cpus) ) + break; + } + ret =3D -ENODEV; + if ( cpu >=3D nr_cpu_ids ) + goto addcpu_out; + } ret =3D -EINVAL; if ( cpu >=3D nr_cpu_ids ) goto addcpu_out; ret =3D -ENODEV; - if ( !cpumask_test_cpu(cpu, &cpupool_free_cpus) || - cpumask_test_cpu(cpu, &cpupool_locked_cpus) ) - goto addcpu_out; - c =3D cpupool_find_by_id(op->cpupool_id); - ret =3D -ENOENT; - if ( c =3D=3D NULL ) + cpus =3D sched_get_opt_cpumask(c->opt_granularity, cpu); + if ( !cpumask_subset(cpus, &cpupool_free_cpus) || + cpumask_intersects(cpus, &cpupool_locked_cpus) ) goto addcpu_out; ret =3D cpupool_assign_cpu_locked(c, cpu); + addcpu_out: spin_unlock(&cpupool_lock); + cpupool_dprintk("cpupool_assign_cpu(pool=3D%d,cpu=3D%d) ret %d\n", op->cpupool_id, cpu, ret); } diff --git a/xen/common/schedule.c b/xen/common/schedule.c index a4555fd0fa..e0521de8ce 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -2555,8 +2555,7 @@ static struct notifier_block cpu_schedule_nfb =3D { .notifier_call =3D cpu_schedule_callback }; =20 -static const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, - unsigned int cpu) +const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, unsigned int c= pu) { const cpumask_t *mask; =20 diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index 5a93ba3686..c152547a94 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -624,5 +624,6 @@ affinity_balance_cpumask(const struct sched_unit *unit,= int step, } =20 void sched_rm_cpu(unsigned int cpu); +const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, unsigned int c= pu); =20 #endif /* __XEN_SCHED_IF_H__ */ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362810; cv=none; d=zoho.com; s=zohoarc; b=GiL7LdvEpBuk2hvrxDX6Si8zwESWoZwkmeyHR5w+6uW3MfFi9KpkBG1+mi3sIsHwgZQw4ZFJkBMnloJ3BMxZYLCHIIXAI0uVHGnQP1Qh8OTrBIwLeUz/w8Ifdu/EUIMlG7a652mikjN1u5wfwehB2ILQ8Oh+1fox8VMr6zDJymg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362810; 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=7sM0ZV5J6pxguGjwQ2vVM6KKYyE5WrhkfrOIxg7Bp5o=; b=OHmId5HWFAwxNu0pBiG/8+1kccJnlJ3Tbjkmqdcb1wj7UHzJ0xSvDjsapo8/4P/zyCRywNGPOhE9EX2RPpUev588z3/lwlGeRwS6aSTVaJUOkIZ+SaTELkMW94g3VIGY1BKJE+dxfvxfK9Fy8nNMO9nldawMsBHbfrkoa6ycAqI= 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 1565362810698601.6518433205863; Fri, 9 Aug 2019 08:00:10 -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 1hw6Mb-0007t1-LA; Fri, 09 Aug 2019 14:59:29 +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 1hw6M7-0006l0-4x for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:58:59 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 353b9e9e-bab6-11e9-aee5-2716450258bd; Fri, 09 Aug 2019 14:58:55 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D9081AFCE; Fri, 9 Aug 2019 14:58:54 +0000 (UTC) X-Inumbo-ID: 353b9e9e-bab6-11e9-aee5-2716450258bd X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:32 +0200 Message-Id: <20190809145833.1020-48-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 47/48] xen/sched: disable scheduling when entering ACPI deep sleep states 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= 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" When entering deep sleep states all domains are paused resulting in all cpus only running idle vcpus. This enables us to stop scheduling completely in order to avoid synchronization problems with core scheduling when individual cpus are offlined. Disabling the scheduler is done by replacing the softirq handler with a dummy scheduling routine only enabling tasklets to run. Signed-off-by: Juergen Gross --- V2: new patch --- xen/arch/x86/acpi/power.c | 4 ++++ xen/common/schedule.c | 31 +++++++++++++++++++++++++++++-- xen/include/xen/sched.h | 2 ++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/acpi/power.c b/xen/arch/x86/acpi/power.c index aecc754fdb..431db8dca8 100644 --- a/xen/arch/x86/acpi/power.c +++ b/xen/arch/x86/acpi/power.c @@ -122,12 +122,16 @@ static void freeze_domains(void) for_each_domain ( d ) domain_pause(d); rcu_read_unlock(&domlist_read_lock); + + scheduler_disable(); } =20 static void thaw_domains(void) { struct domain *d; =20 + scheduler_enable(); + rcu_read_lock(&domlist_read_lock); for_each_domain ( d ) { diff --git a/xen/common/schedule.c b/xen/common/schedule.c index e0521de8ce..181adb00b2 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -84,6 +84,8 @@ extern const struct scheduler *__start_schedulers_array[]= , *__end_schedulers_arr =20 static struct scheduler __read_mostly ops; =20 +static bool scheduler_active; + static struct sched_resource * sched_idle_res_pick(const struct scheduler *ops, struct sched_unit *unit) { @@ -2230,6 +2232,13 @@ static struct sched_unit *sched_wait_rendezvous_in(s= truct sched_unit *prev, cpu_relax(); =20 *lock =3D pcpu_schedule_lock_irq(cpu); + + if ( unlikely(!scheduler_active) ) + { + ASSERT(is_idle_unit(prev)); + atomic_set(&prev->next_task->rendezvous_out_cnt, 0); + prev->rendezvous_in_cnt =3D 0; + } } =20 return prev->next_task; @@ -2578,14 +2587,32 @@ const cpumask_t *sched_get_opt_cpumask(enum sched_g= ran opt, unsigned int cpu) return mask; } =20 +static void schedule_dummy(void) +{ + sched_tasklet_check_cpu(smp_processor_id()); +} + +void scheduler_disable(void) +{ + scheduler_active =3D false; + open_softirq(SCHEDULE_SOFTIRQ, schedule_dummy); + open_softirq(SCHED_SLAVE_SOFTIRQ, schedule_dummy); +} + +void scheduler_enable(void) +{ + open_softirq(SCHEDULE_SOFTIRQ, schedule); + open_softirq(SCHED_SLAVE_SOFTIRQ, sched_slave); + scheduler_active =3D true; +} + /* Initialise the data structures. */ void __init scheduler_init(void) { struct domain *idle_domain; int i; =20 - open_softirq(SCHEDULE_SOFTIRQ, schedule); - open_softirq(SCHED_SLAVE_SOFTIRQ, sched_slave); + scheduler_enable(); =20 for ( i =3D 0; i < NUM_SCHEDULERS; i++) { diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 346e564e05..6d0ea1f60b 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -926,6 +926,8 @@ void vcpu_runstate_get(struct vcpu *v, struct vcpu_runs= tate_info *runstate); uint64_t get_cpu_idle_time(unsigned int cpu); bool sched_has_urgent_vcpu(void); void sched_guest_idle(void (*idle) (void), unsigned int cpu); +void scheduler_enable(void); +void scheduler_disable(void); =20 /* * Used by idle loop to decide whether there is work to do: --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue Apr 23 21:45:40 2024 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=1565362813; cv=none; d=zoho.com; s=zohoarc; b=aPW4TCgDbB4LKwSJIx4lCU1euwle2Rszjv1eSluX9WNInHLC2juTf+wGHHPUS0Dodo9e9cnql8NzIzxU0VVlArNHXA+vzeImEZoS0yV7VUHQtDpHT7K0WudEHEyACllPFDxss5ho0GL1pL9dMiouX+tTGr8qdUIujs8EtHtShfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565362813; 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=q1YIdUR6Wqd3sy1CNq1s2ZVmEpwCaf0HZ1KTaF65FzE=; b=L2efZ+XF4sqd7De7cuq8k3g2UMZhtNj3KCqbmxa37T2odHpwQkaGyNhUCUEWK6YnGjExD/f5JaD8/DgWtxNcux4UAfic6o/zPIl0icVaOTo/6+ZBPflSd/ltjB/avKpIJ208EgL0QnU0qUSg3jTb0A3EtaypamJQKNE53IV1naQ= 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 1565362813082165.68327447985007; Fri, 9 Aug 2019 08:00:13 -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 1hw6Mj-0008Bs-2J; Fri, 09 Aug 2019 14:59:37 +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 1hw6M9-0006pR-8A for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 14:59:01 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3580a106-bab6-11e9-8bf6-4fc566d6eecf; Fri, 09 Aug 2019 14:58:56 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 51444B016; Fri, 9 Aug 2019 14:58:55 +0000 (UTC) X-Inumbo-ID: 3580a106-bab6-11e9-8bf6-4fc566d6eecf X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 16:58:33 +0200 Message-Id: <20190809145833.1020-49-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 48/48] xen/sched: add scheduling granularity enum 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 , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= 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" Add a scheduling granularity enum ("cpu", "core", "socket") for specification of the scheduling granularity. Initially it is set to "cpu", this can be modified by the new boot parameter (x86 only) "sched-gran". According to the selected granularity sched_granularity is set after all cpus are online. A test is added for all sched resources holding the same number of cpus. Fall back to core- or cpu-scheduling in that case. Signed-off-by: Juergen Gross --- RFC V2: - fixed freeing of sched_res when merging cpus - rename parameter to "sched-gran" (Jan Beulich) - rename parameter option from "thread" to "cpu" (Jan Beulich) V1: - rename scheduler_smp_init() to scheduler_gran_init(), let it be called by cpupool_init() - avoid using literal cpu number 0 in scheduler_percpu_init() (Jan Beulich) - style correction (Jan Beulich) - fallback to smaller granularity instead of panic in case of unbalanced cpu configuration V2: - style changes (Jan Beulich) - introduce CONFIG_HAS_SCHED_GRANULARITY (Jan Beulich) --- xen/arch/x86/Kconfig | 1 + xen/common/Kconfig | 3 ++ xen/common/cpupool.c | 2 ++ xen/common/schedule.c | 78 ++++++++++++++++++++++++++++++++++++++++++= ++++ xen/include/xen/sched-if.h | 1 + 5 files changed, 85 insertions(+) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 288dc6c042..3f88adae97 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -22,6 +22,7 @@ config X86 select HAS_PASSTHROUGH select HAS_PCI select HAS_PDX + select HAS_SCHED_GRANULARITY select HAS_UBSAN select HAS_VPCI if !PV_SHIM_EXCLUSIVE && HVM select NEEDS_LIBELF diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 16829f6274..e9247871a8 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -63,6 +63,9 @@ config HAS_GDBSX config HAS_IOPORTS bool =20 +config HAS_SCHED_GRANULARITY + bool + config NEEDS_LIBELF bool =20 diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c index 6917488210..d12269d5a3 100644 --- a/xen/common/cpupool.c +++ b/xen/common/cpupool.c @@ -870,6 +870,8 @@ static int __init cpupool_init(void) unsigned int cpu; int err; =20 + scheduler_gran_init(); + cpupool0 =3D cpupool_create(0, 0, &err); BUG_ON(cpupool0 =3D=3D NULL); cpupool_put(cpupool0); diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 181adb00b2..bd596ba1dc 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,23 @@ unsigned int __read_mostly sched_granularity =3D 1; bool __read_mostly sched_disable_smt_switching; cpumask_var_t sched_res_mask; =20 +#ifdef CONFIG_HAS_SCHED_GRANULARITY +static int __init sched_select_granularity(const char *str) +{ + if ( strcmp("cpu", str) =3D=3D 0 ) + opt_sched_granularity =3D SCHED_GRAN_cpu; + else if ( strcmp("core", str) =3D=3D 0 ) + opt_sched_granularity =3D SCHED_GRAN_core; + else if ( strcmp("socket", str) =3D=3D 0 ) + opt_sched_granularity =3D SCHED_GRAN_socket; + else + return -EINVAL; + + return 0; +} +custom_param("sched-gran", sched_select_granularity); +#endif + /* Common lock for free cpus. */ static DEFINE_SPINLOCK(sched_free_cpu_lock); =20 @@ -2606,6 +2624,66 @@ void scheduler_enable(void) scheduler_active =3D true; } =20 +static unsigned int __init sched_check_granularity(void) +{ + unsigned int cpu; + unsigned int siblings, gran =3D 0; + + if ( opt_sched_granularity =3D=3D SCHED_GRAN_cpu ) + return 1; + + for_each_online_cpu ( cpu ) + { + siblings =3D cpumask_weight(sched_get_opt_cpumask(opt_sched_granul= arity, + cpu)); + if ( gran =3D=3D 0 ) + gran =3D siblings; + else if ( gran !=3D siblings ) + return 0; + } + + sched_disable_smt_switching =3D true; + + return gran; +} + +/* Setup data for selected scheduler granularity. */ +void __init scheduler_gran_init(void) +{ + unsigned int gran =3D 0; + const char *fallback =3D NULL; + + while ( gran =3D=3D 0 ) + { + gran =3D sched_check_granularity(); + + if ( gran =3D=3D 0 ) + { + switch ( opt_sched_granularity ) + { + case SCHED_GRAN_core: + opt_sched_granularity =3D SCHED_GRAN_cpu; + fallback =3D "Asymmetric cpu configuration.\n" + "Falling back to sched-gran=3Dcpu.\n"; + break; + case SCHED_GRAN_socket: + opt_sched_granularity =3D SCHED_GRAN_core; + fallback =3D "Asymmetric cpu configuration.\n" + "Falling back to sched-gran=3Dcore.\n"; + break; + default: + ASSERT_UNREACHABLE(); + break; + } + } + } + + if ( fallback ) + warning_add(fallback); + + sched_granularity =3D gran; +} + /* Initialise the data structures. */ void __init scheduler_init(void) { diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index c152547a94..ace08d609c 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -625,5 +625,6 @@ affinity_balance_cpumask(const struct sched_unit *unit,= int step, =20 void sched_rm_cpu(unsigned int cpu); const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, unsigned int c= pu); +void scheduler_gran_init(void); =20 #endif /* __XEN_SCHED_IF_H__ */ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel