From patchwork Fri Jun 16 14:13:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9791813 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 D04D76038E for ; Fri, 16 Jun 2017 14:16:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C4F7C285C2 for ; Fri, 16 Jun 2017 14:16:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B831C28649; Fri, 16 Jun 2017 14:16:09 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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 31534285C2 for ; Fri, 16 Jun 2017 14:16:09 +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 1dLs0f-0001ti-PR; Fri, 16 Jun 2017 14:14:01 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLs0f-0001tH-5o for xen-devel@lists.xenproject.org; Fri, 16 Jun 2017 14:14:01 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id 6A/FE-01709-8A7E3495; Fri, 16 Jun 2017 14:14:00 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmleJIrShJLcpLzFFi42K5GNpwWHf5c+d Ig+NvtC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1owDrWeZCu5rVLxd2cLUwNgq38XIxSEkMINR Yu2EC0wgDovAGlaJJZf+s4A4EgKXWCU+rHzK1sXICeTESczvmsQIYVdLfHr7ECwuJKAicXP7K iaIUT8ZJd7e2M8EkhAW0JM4cvQHO4TtI/HpxFywOJuAgcSbHXtZQWwRASWJe6smgzUzC7QySr xcfh2sgUVAVWLL34lACQ4OXqDmZf91QcKcQOb150dYIRZ7S/x7dBnsCFEBOYmVl1vA4rwCghI nZz5hAWllFtCUWL9LHyTMLCAvsf3tHOYJjCKzkFTNQqiahaRqASPzKkaN4tSistQiXUNzvaSi zPSMktzEzBxdQwNTvdzU4uLE9NScxKRiveT83E2MwAhgAIIdjBdPex5ilORgUhLlff/EOVKIL yk/pTIjsTgjvqg0J7X4EKMGB4fAhLNzpzNJseTl56UqSfBuewZUJ1iUmp5akZaZA4xRmFIJDh 4lEd5TIGN4iwsSc4sz0yFSpxgtOa5cWfeFiWPD6vVAcsqB7V+YhMDmSYnz9oHMEwBpyCjNgxs HSyOXGGWlhHkZgY4V4ilILcrNLEGVf8UozsGoJMzLCzKFJzOvBG7rK6CDmIAOCrrgAHJQSSJC SqqBkSHPK2dHldezdb2i+sbvtvW+i/2mUuV1WNNzYRLbzZ9eH1aH6XQ4PmZ6W/Liq/nsNzJ5v oUzX7zbsjd8zcNz8hWlvBW3LnG9+PNyosrclgdcC66HSvK1/Vz4N1hw/9fW5AUXjyYc3mS6aZ t33eO9DF2eF9ysC28dnmx89/0FBk22SX4KgSEHe5RYijMSDbWYi4oTAf2sysEeAwAA X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1497622439!87895865!1 X-Originating-IP: [209.85.128.195] 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 20932 invoked from network); 16 Jun 2017 14:13:59 -0000 Received: from mail-wr0-f195.google.com (HELO mail-wr0-f195.google.com) (209.85.128.195) by server-16.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 16 Jun 2017 14:13:59 -0000 Received: by mail-wr0-f195.google.com with SMTP id x23so6731892wrb.0 for ; Fri, 16 Jun 2017 07:13:59 -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=Ot67Ajjehpj0vhWv2whpA+rBSx0DFqGswrpiYARMY2s=; b=hsx1VWA0YplSpJLj2k5rhHrI2+YThL8oqUs9o0rWYHl24L1+oy5xyaLxNQl6KJzFdK TCZarXMI05d3gkldAtpc1zyI+MS5vossFxnNNs6ArUm1Y7iwuv7NsE/uP8IOkdOQUlUa 0bf5W3tT4rmM6Jdi5zqfZItw+K4vE8p5a1YlfaUN12NIzbSY4Ho9kd0EcV11D8+Mbqw2 2MRXgQKGRCCWUY1+QQuSHQv5NeuPSIEI5qlN7KNjxX9yOWqJsJn0J5Sq9E2ArTd8uhDY YaqsFghM2tgQYgpSmPlwSQzz5ciHc53z3OSPmwni715OiggrNsuKO5mY0g6RAed2Ca3C Gl3A== 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=Ot67Ajjehpj0vhWv2whpA+rBSx0DFqGswrpiYARMY2s=; b=lvI0mo/sRRY3XobcS6m8sEYtiMDNuyiCZYeghDkyQ6treyyid5jblTWDCrBvNunQCK +muKte6Pc4DzNUGtuNhYrPvqaCTtPXYuVZqCJ/D28t30W+H6EtfokiYQRdmg+Q+pnn3N +fpesNyNmZywRBFlGdUdu0cHNrJAjHLFcvEy8dz5t+lUFt9iCGtcbNd8P0C/SP1t0tob 42jpnUFAfIq7LbX5yATcM+gp0LHWJ3ihDk5/xREpg4nkErCOY9hsCudgHJgQBKFw0of5 yflHaQVcjvgyyyS3oPINJ+AjOzN2kyLTob13iPClGWVo5wNuWDGiJabzBw3mH1Wjv50O WVYw== X-Gm-Message-State: AKS2vOyg0Lmdsf3/VCsyAZw334Pl5Xug9szZjpkHNntegqk4WgYJeDGL uiW+5fTpfEO5FJDW X-Received: by 10.223.166.248 with SMTP id t111mr8107041wrc.39.1497622439294; Fri, 16 Jun 2017 07:13:59 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.68]) by smtp.gmail.com with ESMTPSA id 135sm3515834wmy.11.2017.06.16.07.13.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jun 2017 07:13:58 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 16 Jun 2017 16:13:57 +0200 Message-ID: <149762243723.11899.13163340131516329714.stgit@Solace.fritz.box> In-Reply-To: <149762114626.11899.6393770850121347748.stgit@Solace.fritz.box> References: <149762114626.11899.6393770850121347748.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap , Anshul Makkar , "Justin T. Weaver" Subject: [Xen-devel] [PATCH 3/7] xen: credit2: soft-affinity awareness in fallback_cpu() 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 By, basically, moving all the logic of the function inside the usual two steps (soft-affinity step and hard-affinity step) loop. Signed-off-by: Dario Faggioli Signed-off-by: Justin T. Weaver --- Cc: Anshul Makkar Cc: George Dunlap --- George, you gave your Reviewed-by to: https://lists.xenproject.org/archives/html/xen-devel/2016-08/msg02201.html which was adding soft-affinity awareness to both fallback_cpu and cpu_pick(). See here: https://lists.xenproject.org/archives/html/xen-devel/2016-09/msg03259.html I changed the cpu_pick() part a lot, and that's why I decided to split the patch in two. As far as fallback_cpu(), though, what's done in this patch is exactly the same that was being done in the original one. So, of course I'm dropping the Rev-by, but I thought it could have been useful to mention this. :-) --- xen/common/sched_credit2.c | 77 ++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index c749d4e..54f6e21 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -537,36 +537,71 @@ void smt_idle_mask_clear(unsigned int cpu, cpumask_t *mask) } /* - * When a hard affinity change occurs, we may not be able to check some - * (any!) of the other runqueues, when looking for the best new processor - * for svc (as trylock-s in csched2_cpu_pick() can fail). If that happens, we - * pick, in order of decreasing preference: - * - svc's current pcpu; - * - another pcpu from svc's current runq; - * - any cpu. + * In csched2_cpu_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; + * 2) a pcpu in svc's current runqueue that is also in svc's soft affinity; + * 3) just one valid pcpu from svc's soft affinity; + * 4) svc's current pcpu, if it is part of svc's hard affinity; + * 5) a pcpu in svc's current runqueue that is also in svc's hard affinity; + * 6) just one valid pcpu from svc's hard affinity + * + * Of course, 1, 2 and 3 makes sense only if svc has a soft affinity. Also + * note that at least 6 is guaranteed to _always_ return at least one pcpu. */ static int get_fallback_cpu(struct csched2_vcpu *svc) { struct vcpu *v = svc->vcpu; - int cpu = v->processor; + unsigned int bs; - cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity, - cpupool_domain_cpumask(v->domain)); + for_each_affinity_balance_step( bs ) + { + int cpu = v->processor; + + if ( bs == BALANCE_SOFT_AFFINITY && + !has_soft_affinity(v, v->cpu_hard_affinity) ) + continue; - if ( likely(cpumask_test_cpu(cpu, cpumask_scratch_cpu(cpu))) ) - return cpu; + affinity_balance_cpumask(v, bs, cpumask_scratch_cpu(cpu)); + cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), + cpupool_domain_cpumask(v->domain)); - if ( likely(cpumask_intersects(cpumask_scratch_cpu(cpu), - &svc->rqd->active)) ) - { - cpumask_and(cpumask_scratch_cpu(cpu), &svc->rqd->active, - cpumask_scratch_cpu(cpu)); - return cpumask_first(cpumask_scratch_cpu(cpu)); - } + /* + * This is cases 1 or 4 (depending on bs): if v->processor is (still) + * in our affinity, go for it, for cache betterness. + */ + if ( likely(cpumask_test_cpu(cpu, cpumask_scratch_cpu(cpu))) ) + return cpu; - ASSERT(!cpumask_empty(cpumask_scratch_cpu(cpu))); + /* + * This is cases 2 or 5 (depending on bs): v->processor isn't there + * any longer, check if we at least can stay in our current runq. + */ + if ( likely(cpumask_intersects(cpumask_scratch_cpu(cpu), + &svc->rqd->active)) ) + { + cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), + &svc->rqd->active); + return cpumask_first(cpumask_scratch_cpu(cpu)); + } - return cpumask_first(cpumask_scratch_cpu(cpu)); + /* + * This is cases 3 or 6 (depending on bs): last stand, just one valid + * pcpu from our soft affinity, if we have one and if there's any. In + * fact, if we are doing soft-affinity, it is possible that we fail, + * which means we stay in the loop and look for hard affinity. OTOH, + * if we are at the hard-affinity balancing step, it's guaranteed that + * there is at least one valid cpu, and therefore we are sure that we + * return it, and never really exit the loop. + */ + ASSERT(!cpumask_empty(cpumask_scratch_cpu(cpu)) || + bs == BALANCE_SOFT_AFFINITY); + cpu = cpumask_first(cpumask_scratch_cpu(cpu)); + if ( likely(cpu < nr_cpu_ids) ) + return cpu; + } + BUG_ON(1); } /*