From patchwork Thu Jun 29 12:56:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9816705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1DF5E603D7 for ; Thu, 29 Jun 2017 12:58:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03996285B0 for ; Thu, 29 Jun 2017 12:58:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC256286E2; Thu, 29 Jun 2017 12:58:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AEC35285B0 for ; Thu, 29 Jun 2017 12:58:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQYzd-0006eN-OY; Thu, 29 Jun 2017 12:56:21 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQYzc-0006eC-Qr for xen-devel@lists.xenproject.org; Thu, 29 Jun 2017 12:56:21 +0000 Received: from [193.109.254.147] by server-10.bemta-6.messagelabs.com id 89/07-03582-4F8F4595; Thu, 29 Jun 2017 12:56:20 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBIsWRWlGSWpSXmKPExsVyMbThiO7nHyG RBqtPiVt83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBkzz71mLDgdWtF5Vr6Bsd2xi5GLQ0hgJqPE xCU9zCAOi8AaVokvv8+zgTgSApdYJZa1d7N2MXICOXESS/beZIewqyXeHdoKFhcSUJG4uX0VE 8Sor4wSU5dPYARJCAvoSRw5+oMdwvaXmLDqLhuIzSZgIPFmx16wZhEBJYl7qyaDNTMLNDFKPN 7ZzAKSYBFQlfh0vxusgVfAQaLvUgOYzSngKLHp4RJGiM0OEncuvAKzRQXkJFZebmGFqBeUODn zCdAcDqChmhLrd+mDhJkF5CW2v53DPIFRZBaSqlkIVbOQVC1gZF7FqF6cWlSWWqRroZdUlJme UZKbmJmja2hgppebWlycmJ6ak5hUrJecn7uJERj+DECwg3H2Zf9DjJIcTEqivIbPQyKF+JLyU yozEosz4otKc1KLDzHKcHAoSfBmfQfKCRalpqdWpGXmACMRJi3BwaMkwvvwK1Cat7ggMbc4Mx 0idYrRmOPKlXVfmDimHNj+hUmIJS8/L1VKnFcOZJIASGlGaR7cIFiCuMQoKyXMywh0mhBPQWp RbmYJqvwrRnEORiVh3r8gU3gy80rg9r0COoUJ6BThGWCnlCQipKQaGIOqdgSI5G56Yfenh6u7 /czrHxaC74W0dq3Pk/v65Nib1Gs2vq1HVm3LkXpe0lz2oNjTb6NnamKPXMiXr7sl3nEmfqmcL jZxRuspyeWWXd0vFlgaMS3xUnV/z7jzcqWnujKjgN2e+akT+6ewp6v8ETndsibkRE9LaPzsRd cUXc5o8VXvC7qgqMRSnJFoqMVcVJwIAKxdSIELAwAA X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-5.tower-27.messagelabs.com!1498740979!99304593!1 X-Originating-IP: [209.85.128.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 16117 invoked from network); 29 Jun 2017 12:56:19 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-5.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 29 Jun 2017 12:56:19 -0000 Received: by mail-wr0-f196.google.com with SMTP id z45so36830441wrb.2 for ; Thu, 29 Jun 2017 05:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=3oaXxU6AVH5414BbXi3bEqmw1/RAqG6UldGz32D0UTM=; b=Kchm3S49D+i/6O8GmL++n7WlZdZDfS7ZoCbxTMhiktXlMkLg2Wku1Y56V0BPu1CfB1 JG1GUNegHb8LlXBvAEeC9XK2rGGDBIIsFNMPLfZ7FP1xhLC2VrC4gEgd7aXzJDjwJfe0 Sxd/p+hdItej7IbgyyZqbIWJZD2LSupqX7ieINumYiaOzUrkF+W+0gV5ujVOWsiyhXfV R7ER2TrIep8xyaKcOBetF56nCBrjAm3uVo3x6xzNJXNqDQZFklr4AjTk1bxDW8Sy1I/H /mS8wbSTtARAxra6FIWNf2w73NebZ857r5xy4jz1nGIKFZRdwN6fw8E3j7UaWipsfWct NE4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=3oaXxU6AVH5414BbXi3bEqmw1/RAqG6UldGz32D0UTM=; b=ZiedMDxjglcWx+324jyd9tSyyO2+chrI5s4pNlZoAukSCbou1TRsI5f0P0C9tYnd4u EZlZ8ym3bINmFc80+sqgWtj2fS+qNLM4jCMIRGzNLfm3t9PwCdImBZhtkZ59erwdYsoN +MoY+ANiG06dM8G++GyR6tumgApEsfUflhqDJZGT8jHqFP2AmDIchIoV9k08sx9R1T0H 4xk/5sDHMrqBG5jA55QPTZYH8nxDVqn0L7QRlQ3LgF5QdkLhwHiQcnUNM75a+CNUySSG 5vc3b2XgWAFtqZPzadS7Yu8OZ4uTRWRR3/3grojeW1xegU/EkykzWF9biW5A7dmgZzBg VHcA== X-Gm-Message-State: AKS2vOzvvr/nVwxU+u33EGvqhnvpLARdmFZtLEpFca0W9KcgEvmGP0HB NMN2MoTz0TyV7iPs X-Received: by 10.223.142.66 with SMTP id n60mr23854937wrb.188.1498740978514; Thu, 29 Jun 2017 05:56:18 -0700 (PDT) Received: from [192.168.0.31] ([80.66.223.37]) by smtp.gmail.com with ESMTPSA id 46sm6238063wrz.8.2017.06.29.05.56.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 05:56:17 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Thu, 29 Jun 2017 14:56:16 +0200 Message-ID: <149874097293.524.13918122801195964226.stgit@Solace> In-Reply-To: <149874017405.524.14075439009139766753.stgit@Solace> References: <149874017405.524.14075439009139766753.stgit@Solace> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Anshul Makkar , "Justin T. Weaver" , George Dunlap Subject: [Xen-devel] [PATCH 1/5] xen: sched: factor affinity helpers out of sched_credit.c X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In fact, we want to be able to use them from any scheduler. While there, make the moved code use 'v' for struct_vcpu* variable, like it should be done everywhere. No functional change intended. Signed-off-by: Dario Faggioli Signed-off-by: Justin T. Weaver Reviewed-by: George Dunlap --- Cc: Anshul Makkar --- xen/common/sched_credit.c | 97 +++++++------------------------------------- xen/include/xen/sched-if.h | 64 +++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 82 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index efdf6bf..53773df 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -136,27 +136,6 @@ #define TRC_CSCHED_RATELIMIT TRC_SCHED_CLASS_EVT(CSCHED, 10) #define TRC_CSCHED_STEAL_CHECK TRC_SCHED_CLASS_EVT(CSCHED, 11) - -/* - * Hard and soft affinity load balancing. - * - * Idea is each vcpu has some pcpus that it prefers, some that it does not - * prefer but is OK with, and some that it cannot run on at all. The first - * set of pcpus are the ones that are both in the soft affinity *and* in the - * hard affinity; the second set of pcpus are the ones that are in the hard - * affinity but *not* in the soft affinity; the third set of pcpus are the - * ones that are not in the hard affinity. - * - * We implement a two step balancing logic. Basically, every time there is - * the need to decide where to run a vcpu, we first check the soft affinity - * (well, actually, the && between soft and hard affinity), to see if we can - * send it where it prefers to (and can) run on. However, if the first step - * does not find any suitable and free pcpu, we fall back checking the hard - * affinity. - */ -#define CSCHED_BALANCE_SOFT_AFFINITY 0 -#define CSCHED_BALANCE_HARD_AFFINITY 1 - /* * Boot parameters */ @@ -331,52 +310,6 @@ runq_remove(struct csched_vcpu *svc) __runq_remove(svc); } -#define for_each_csched_balance_step(step) \ - for ( (step) = 0; (step) <= CSCHED_BALANCE_HARD_AFFINITY; (step)++ ) - - -/* - * Hard affinity balancing is always necessary and must never be skipped. - * But soft affinity need only be considered when it has a functionally - * different effect than other constraints (such as hard affinity, cpus - * online, or cpupools). - * - * Soft affinity only needs to be considered if: - * * The cpus in the cpupool are not a subset of soft affinity - * * The hard affinity is not a subset of soft affinity - * * There is an overlap between the soft affinity and the mask which is - * currently being considered. - */ -static inline int __vcpu_has_soft_affinity(const struct vcpu *vc, - const cpumask_t *mask) -{ - return !cpumask_subset(cpupool_domain_cpumask(vc->domain), - vc->cpu_soft_affinity) && - !cpumask_subset(vc->cpu_hard_affinity, vc->cpu_soft_affinity) && - cpumask_intersects(vc->cpu_soft_affinity, mask); -} - -/* - * Each csched-balance step uses its own cpumask. This function determines - * which one (given the step) and copies it in mask. For the soft affinity - * balancing step, the pcpus that are not part of vc's hard affinity are - * filtered out from the result, to avoid running a vcpu where it would - * like, but is not allowed to! - */ -static void -csched_balance_cpumask(const struct vcpu *vc, int step, cpumask_t *mask) -{ - if ( step == CSCHED_BALANCE_SOFT_AFFINITY ) - { - cpumask_and(mask, vc->cpu_soft_affinity, vc->cpu_hard_affinity); - - if ( unlikely(cpumask_empty(mask)) ) - cpumask_copy(mask, vc->cpu_hard_affinity); - } - else /* step == CSCHED_BALANCE_HARD_AFFINITY */ - cpumask_copy(mask, vc->cpu_hard_affinity); -} - static void burn_credits(struct csched_vcpu *svc, s_time_t now) { s_time_t delta; @@ -441,18 +374,18 @@ static inline void __runq_tickle(struct csched_vcpu *new) * Soft and hard affinity balancing loop. For vcpus without * a useful soft affinity, consider hard affinity only. */ - for_each_csched_balance_step( balance_step ) + for_each_affinity_balance_step( balance_step ) { int new_idlers_empty; - if ( balance_step == CSCHED_BALANCE_SOFT_AFFINITY - && !__vcpu_has_soft_affinity(new->vcpu, - new->vcpu->cpu_hard_affinity) ) + if ( balance_step == BALANCE_SOFT_AFFINITY + && !has_soft_affinity(new->vcpu, + new->vcpu->cpu_hard_affinity) ) continue; /* Are there idlers suitable for new (for this balance step)? */ - csched_balance_cpumask(new->vcpu, balance_step, - cpumask_scratch_cpu(cpu)); + affinity_balance_cpumask(new->vcpu, balance_step, + cpumask_scratch_cpu(cpu)); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), &idle_mask); new_idlers_empty = cpumask_empty(cpumask_scratch_cpu(cpu)); @@ -463,7 +396,7 @@ static inline void __runq_tickle(struct csched_vcpu *new) * hard affinity as well, before taking final decisions. */ if ( new_idlers_empty - && balance_step == CSCHED_BALANCE_SOFT_AFFINITY ) + && balance_step == BALANCE_SOFT_AFFINITY ) continue; /* @@ -789,7 +722,7 @@ _csched_cpu_pick(const struct scheduler *ops, struct vcpu *vc, bool_t commit) online = cpupool_domain_cpumask(vc->domain); cpumask_and(&cpus, vc->cpu_hard_affinity, online); - for_each_csched_balance_step( balance_step ) + for_each_affinity_balance_step( balance_step ) { /* * We want to pick up a pcpu among the ones that are online and @@ -809,12 +742,12 @@ _csched_cpu_pick(const struct scheduler *ops, struct vcpu *vc, bool_t commit) * cpus and, if the result is empty, we just skip the soft affinity * balancing step all together. */ - if ( balance_step == CSCHED_BALANCE_SOFT_AFFINITY - && !__vcpu_has_soft_affinity(vc, &cpus) ) + if ( balance_step == BALANCE_SOFT_AFFINITY + && !has_soft_affinity(vc, &cpus) ) continue; /* Pick an online CPU from the proper affinity mask */ - csched_balance_cpumask(vc, balance_step, &cpus); + affinity_balance_cpumask(vc, balance_step, &cpus); cpumask_and(&cpus, &cpus, online); /* If present, prefer vc's current processor */ @@ -1710,11 +1643,11 @@ csched_runq_steal(int peer_cpu, int cpu, int pri, int balance_step) * or counter. */ if ( vc->is_running || - (balance_step == CSCHED_BALANCE_SOFT_AFFINITY - && !__vcpu_has_soft_affinity(vc, vc->cpu_hard_affinity)) ) + (balance_step == BALANCE_SOFT_AFFINITY + && !has_soft_affinity(vc, vc->cpu_hard_affinity)) ) continue; - csched_balance_cpumask(vc, balance_step, cpumask_scratch); + affinity_balance_cpumask(vc, balance_step, cpumask_scratch); if ( __csched_vcpu_is_migrateable(vc, cpu, cpumask_scratch) ) { /* We got a candidate. Grab it! */ @@ -1774,7 +1707,7 @@ csched_load_balance(struct csched_private *prv, int cpu, * 1. any "soft-affine work" to steal first, * 2. if not finding anything, any "hard-affine work" to steal. */ - for_each_csched_balance_step( bstep ) + for_each_affinity_balance_step( bstep ) { /* * We peek at the non-idling CPUs in a node-wise fashion. In fact, diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h index c32ee7a..c4a4935 100644 --- a/xen/include/xen/sched-if.h +++ b/xen/include/xen/sched-if.h @@ -208,4 +208,68 @@ static inline cpumask_t* cpupool_domain_cpumask(struct domain *d) return d->cpupool->cpu_valid; } +/* + * Hard and soft affinity load balancing. + * + * Idea is each vcpu has some pcpus that it prefers, some that it does not + * prefer but is OK with, and some that it cannot run on at all. The first + * set of pcpus are the ones that are both in the soft affinity *and* in the + * hard affinity; the second set of pcpus are the ones that are in the hard + * affinity but *not* in the soft affinity; the third set of pcpus are the + * ones that are not in the hard affinity. + * + * We implement a two step balancing logic. Basically, every time there is + * the need to decide where to run a vcpu, we first check the soft affinity + * (well, actually, the && between soft and hard affinity), to see if we can + * send it where it prefers to (and can) run on. However, if the first step + * does not find any suitable and free pcpu, we fall back checking the hard + * affinity. + */ +#define BALANCE_SOFT_AFFINITY 0 +#define BALANCE_HARD_AFFINITY 1 + +#define for_each_affinity_balance_step(step) \ + for ( (step) = 0; (step) <= BALANCE_HARD_AFFINITY; (step)++ ) + +/* + * Hard affinity balancing is always necessary and must never be skipped. + * But soft affinity need only be considered when it has a functionally + * different effect than other constraints (such as hard affinity, cpus + * online, or cpupools). + * + * Soft affinity only needs to be considered if: + * * The cpus in the cpupool are not a subset of soft affinity + * * The hard affinity is not a subset of soft affinity + * * There is an overlap between the soft affinity and the mask which is + * currently being considered. + */ +static inline int has_soft_affinity(const struct vcpu *v, + const cpumask_t *mask) +{ + return !cpumask_subset(cpupool_domain_cpumask(v->domain), + v->cpu_soft_affinity) && + !cpumask_subset(v->cpu_hard_affinity, v->cpu_soft_affinity) && + cpumask_intersects(v->cpu_soft_affinity, mask); +} + +/* + * This function copies in mask the cpumask that should be used for a + * particular affinity balancing step. For the soft affinity one, the pcpus + * that are not part of vc's hard affinity are filtered out from the result, + * 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) +{ + if ( step == BALANCE_SOFT_AFFINITY ) + { + cpumask_and(mask, v->cpu_soft_affinity, v->cpu_hard_affinity); + + if ( unlikely(cpumask_empty(mask)) ) + cpumask_copy(mask, v->cpu_hard_affinity); + } + else /* step == BALANCE_HARD_AFFINITY */ + cpumask_copy(mask, v->cpu_hard_affinity); +} + #endif /* __XEN_SCHED_IF_H__ */