From patchwork Thu Mar 2 10:38:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9599903 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 A4AD760414 for ; Thu, 2 Mar 2017 10:40:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82AA827F7F for ; Thu, 2 Mar 2017 10:40:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 777092858C; Thu, 2 Mar 2017 10:40:36 +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 CE0BD27F7F for ; Thu, 2 Mar 2017 10:40:34 +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 1cjO7e-00048a-V6; Thu, 02 Mar 2017 10:38:10 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjO7d-00048S-Tu for xen-devel@lists.xenproject.org; Thu, 02 Mar 2017 10:38:10 +0000 Received: from [85.158.137.68] by server-17.bemta-3.messagelabs.com id 58/43-04270-016F7B85; Thu, 02 Mar 2017 10:38:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpileJIrShJLcpLzFFi42K5GNpwWJf/2/Y Ig53NZhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aDab+ZC7o1Ko5//MbWwLhDuouRi0NIYAaj ROvD6exdjJwcLAJrWCVWrKoESUgIXGKV+NPykwUkISEQI7F2eScrhF0t0XLjEZgtJKAicXP7K iaIST8ZJeaeOQ02SVhAT+LI0R9Qtq/Epp2vwRrYBAwk3uzYC2aLCChJ3Fs1GaiZg4NZQF9i9V ceiCNUJfZs28EEYvMK+Ehsat/FBmJzAo3p/HsBaq+PxI+Z/WC2qICcxMrLLawQ9YISJ2c+YYE YqSmxfpc+SJhZQF5i+9s5zBMYRWYhqZqFUDULSdUCRuZVjOrFqUVlqUW6xnpJRZnpGSW5iZk5 uoYGxnq5qcXFiempOYlJxXrJ+bmbGIGhzwAEOxibvzgdYpTkYFIS5eV9tj1CiC8pP6UyI7E4I 76oNCe1+BCjBgeHwISzc6czSbHk5eelKknwnv8CVCdYlJqeWpGWmQOMTphSCQ4eJRHeVpA0b3 FBYm5xZjpE6hSjMceDU7veMHF86j/8hkkIbJKUOG8DSKkASGlGaR7cIFjSuMQoKyXMywh0phB PQWpRbmYJqvwrRnEORiVhXruvQFN4MvNK4Pa9AjqFCeiUFypbQU4pSURISTUwOplv0nz1Uzf/ /JrlE20fTPqulOe4z3PboWftn9T/W87oWCTv+c1jk2rkuxWbXs4UPLa183RNzfvOfYr5HzPXf PZ7mTthtuts42S2l5GXvSezuNxp3HN+zjUp37p/cVparQt5oxUD3Ziu2m1d7+X7jYHT4ehaGZ f1z25uFIrZ/Top2uK27BQZHyWW4oxEQy3mouJEAEspOgcVAwAA X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1488451087!30103470!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.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31179 invoked from network); 2 Mar 2017 10:38:07 -0000 Received: from mail-wr0-f195.google.com (HELO mail-wr0-f195.google.com) (209.85.128.195) by server-4.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 2 Mar 2017 10:38:07 -0000 Received: by mail-wr0-f195.google.com with SMTP id u48so8928575wrc.1 for ; Thu, 02 Mar 2017 02:38:07 -0800 (PST) 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=T5rGu3wpkIs2CvVoPm+LVvpwy2ZAP767PtnmHcks7Zw=; b=hr+x5gf0/EMcK/mA3LIHYGP2ot3nnU8YhtzRMVUzo8No9KMXrdC2XFJ1N54DcyMGvQ IeaaC3nY4+z1kYlxryAywz9yZGtDUkKvIh3sMdntKkNhMLQpLRuAdqT2qD+uzxpeEIca IRfjfU6zR8WY52CTNJ/vKg4yb+NKcajXW0szeHO6Kl7zD+7T2Le4X9lhpM3Ua1s4+L1a YMhJWDWMN5s5HTHWzu4hJga6S+ToyGL2Uy/hFYlnD3+EmYjVF4c+PA9OdmqFw3zJlHMQ yuVxLlcHamkc7Wf1m383GkGJs+BoImHw16OF5lmcfsFpokVjOzX05/GAihHyfkvx17/b 9bsg== 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=T5rGu3wpkIs2CvVoPm+LVvpwy2ZAP767PtnmHcks7Zw=; b=ljYYlvzaTFDhYSmglIPSJlFgXVNOPQzet0IVqRoiOIvROFHqs9dfcC6LNADkF9x9Gu lXlYNtmapRDdS8+sTXnwKmK1X9GOA7fYbbn2gglVPvNlviOGH9gg4JLaPB0WEhg7eerD ok2bun37J5/kjsd47uuU3w0rVnqooYceqNbgJ0Xx8vcbvW2rQYhTx5lQ1fHyeWqa0XZn pxi3nX/XicD+EmiUzpPWyvt71m5Fxjkbql/gk/FSN3OFjG2J/agqUSJ4oZP2VdwJ4gKf jvTYLFsBoW9eaaR6ckWU71jEPNjat0MnoKWkdgqyM0DGeAFmh03kDFM1tM6EKl8Y0Bsf A4Cw== X-Gm-Message-State: AMke39k3ShCP7SA0U8BNiLQMCUnncnFvvCV4cUOhD6In+ng7LBM9bWSrLOYcQFU1bhx7DQ== X-Received: by 10.223.171.239 with SMTP id s102mr3614584wrc.23.1488451087370; Thu, 02 Mar 2017 02:38:07 -0800 (PST) Received: from Solace.fritz.box ([80.66.223.93]) by smtp.gmail.com with ESMTPSA id w97sm8944450wrc.20.2017.03.02.02.38.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Mar 2017 02:38:06 -0800 (PST) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Thu, 02 Mar 2017 11:38:05 +0100 Message-ID: <148845108437.23452.18282287504552403796.stgit@Solace.fritz.box> In-Reply-To: <148844531279.23452.17528540110704914171.stgit@Solace.fritz.box> References: <148844531279.23452.17528540110704914171.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap Subject: [Xen-devel] [PATCH 1/6] xen: credit1: simplify csched_runq_steal() a little bit. 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 Since we're holding the lock on the pCPU from which we are trying to steal, it can't have disappeared, so we can drop the check for that (and convert it in an ASSERT()). And since we try to steal only from busy pCPUs, it's unlikely for such pCPU to be idle, so we mark it as such (and bail early if it unfortunately is). Signed-off-by: Dario Faggioli --- Cc: George Dunlap --- xen/common/sched_credit.c | 87 +++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 4649e64..63a8675 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -1593,64 +1593,65 @@ static struct csched_vcpu * csched_runq_steal(int peer_cpu, int cpu, int pri, int balance_step) { const struct csched_pcpu * const peer_pcpu = CSCHED_PCPU(peer_cpu); - const struct vcpu * const peer_vcpu = curr_on_cpu(peer_cpu); struct csched_vcpu *speer; struct list_head *iter; struct vcpu *vc; + ASSERT(peer_pcpu != NULL); + /* * Don't steal from an idle CPU's runq because it's about to * pick up work from it itself. */ - if ( peer_pcpu != NULL && !is_idle_vcpu(peer_vcpu) ) + if ( unlikely(is_idle_vcpu(curr_on_cpu(peer_cpu))) ) + goto out; + + list_for_each( iter, &peer_pcpu->runq ) { - list_for_each( iter, &peer_pcpu->runq ) - { - speer = __runq_elem(iter); + speer = __runq_elem(iter); - /* - * If next available VCPU here is not of strictly higher - * priority than ours, this PCPU is useless to us. - */ - if ( speer->pri <= pri ) - break; + /* + * If next available VCPU here is not of strictly higher + * priority than ours, this PCPU is useless to us. + */ + if ( speer->pri <= pri ) + break; - /* Is this VCPU runnable on our PCPU? */ - vc = speer->vcpu; - BUG_ON( is_idle_vcpu(vc) ); + /* Is this VCPU runnable on our PCPU? */ + vc = speer->vcpu; + BUG_ON( is_idle_vcpu(vc) ); - /* - * If the vcpu has no useful soft affinity, skip this vcpu. - * 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 - * 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 - * or counter. - */ - if ( balance_step == CSCHED_BALANCE_SOFT_AFFINITY - && !__vcpu_has_soft_affinity(vc, vc->cpu_hard_affinity) ) - continue; + /* + * If the vcpu has no useful soft affinity, skip this vcpu. + * 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 + * 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 + * or counter. + */ + if ( balance_step == CSCHED_BALANCE_SOFT_AFFINITY + && !__vcpu_has_soft_affinity(vc, vc->cpu_hard_affinity) ) + continue; - csched_balance_cpumask(vc, balance_step, cpumask_scratch); - if ( __csched_vcpu_is_migrateable(vc, 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); - SCHED_STAT_CRANK(migrate_queued); - WARN_ON(vc->is_urgent); - __runq_remove(speer); - vc->processor = cpu; - return speer; - } + csched_balance_cpumask(vc, balance_step, cpumask_scratch); + if ( __csched_vcpu_is_migrateable(vc, 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); + SCHED_STAT_CRANK(migrate_queued); + WARN_ON(vc->is_urgent); + __runq_remove(speer); + vc->processor = cpu; + return speer; } } - + out: SCHED_STAT_CRANK(steal_peer_idle); return NULL; }