From nobody Mon Feb 9 11:51:39 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568451325; cv=none; d=zoho.com; s=zohoarc; b=BONdRA66VAwQR58736oA1lSi7A1BRfRYzEQF5AhtLIa3ionD+/BZRTBhvJ+wzvU9slvbcdV4QsWPtDkLXw3M3f4WNJabCE9AVCu7W1bHG5BWNH2Ay4KHYNFVuTLszSZBrHdfH+HeQs8O3gIWv6Uoyybqb5o14AASDMdzBXMNuRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568451325; 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=llTU2+sba+yqv6TgP0psLjzibRyyF17vId0jg/ndgvA=; b=keU+cMEuxMQguhlTEh9Zw6H8oS+dWJBhtvfdoLnqlIFoBbozXiXiCdx9MeJbubzwR8mANeLTO2r3EpqsaTAPXXVgAGlzBL31xJzGsbUfbChD3Bck5Di2iLQEyNBmq/mxRHfIh95ZyDrHT1yOPiynhOhix3NPxc7yz83hJwyEJxo= 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 1568451325068361.4475457967926; Sat, 14 Sep 2019 01:55: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 1i93p3-00014D-Qf; Sat, 14 Sep 2019 08:54:25 +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 1i93p1-00010I-Ou for xen-devel@lists.xenproject.org; Sat, 14 Sep 2019 08:54:23 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1140439b-d6cd-11e9-95c1-12813bfff9fa; Sat, 14 Sep 2019 08:53:06 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E7EF5B671; Sat, 14 Sep 2019 08:53:03 +0000 (UTC) X-Inumbo-ID: 1140439b-d6cd-11e9-95c1-12813bfff9fa X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Sat, 14 Sep 2019 10:52:33 +0200 Message-Id: <20190914085251.18816-30-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190914085251.18816-1-jgross@suse.com> References: <20190914085251.18816-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v3 29/47] 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 V3: - add vcpu loop to unit_runnable_state() right now instead of doing so in next patch (Jan Beulich, Dario Faggioli) - make new_state unsigned int (Jan Beulich) --- 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 | 23 +++++++++++++++++++++ xen/include/xen/sched.h | 1 + 9 files changed, 66 insertions(+), 30 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 7a1be85be9..fa4023936b 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 96f3e844d2..1e88da40b1 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 5802a67784..b25a7d2270 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 414ac8f5b6..708643be7e 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 d7deef07b8..34ac018cca 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(sched_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 91bc3d56fb..9f4e397334 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 78b47acedf..03bcf796ae 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -269,7 +269,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 4872570612..25ba6f25c9 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -76,6 +76,29 @@ 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, 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; + + if ( runnable ) + ret =3D true; + } + + return ret; +} + 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 c0e4dc2dc3..5b805eac58 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 + unsigned 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