From patchwork Fri Jun 16 14:14:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9791825 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 61BB46038E for ; Fri, 16 Jun 2017 14:16:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 576DE285C2 for ; Fri, 16 Jun 2017 14:16:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C5AC28649; Fri, 16 Jun 2017 14:16:34 +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 D95CF285C2 for ; Fri, 16 Jun 2017 14:16:33 +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 1dLs11-00023I-JZ; Fri, 16 Jun 2017 14:14:23 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLs10-000226-4Q for xen-devel@lists.xenproject.org; Fri, 16 Jun 2017 14:14:22 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id 2A/32-02199-DB7E3495; Fri, 16 Jun 2017 14:14:21 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmleJIrShJLcpLzFFi42K5GNpwRHfPc+d Ig2X9uhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bRc73MBVPEK3Z3TmJrYFwi1MXIxSEkMINR YsbnxewgDovAGlaJ67MfMoE4EgKXWCWmPLvM3MXICeTESWw+3QdlV0icmv+QEcQWElCRuLl9F RPEqJ+MEh13fjGBJIQF9CSOHP3BDmF7SvTcnwMWZxMwkHizYy8riC0ioCRxb9VkoDgHB7NAuM TqTm6QMIuAqsS075PA5vMK+EgcvfGTBcTmBLKvPz/CCrHXW+Lfo8tsILaogJzEysstrBD1ghI nZz5hgRipKbF+lz5ImFlAXmL72znMExhFZiGpmoVQNQtJ1QJG5lWM6sWpRWWpRbpGeklFmekZ JbmJmTm6hgbGermpxcWJ6ak5iUnFesn5uZsYgcFfz8DAuIPxVLPzIUZJDiYlUd73T5wjhfiS8 lMqMxKLM+KLSnNSiw8xanBwCEw4O3c6kxRLXn5eqpIE77ZnQHWCRanpqRVpmTnA+IQpleDgUR LhPQUyhre4IDG3ODMdInWK0ZjjypV1X5g4phzY/oVJCGySlDhvH8gkAZDSjNI8uEGwtHGJUVZ KmJeRgYFBiKcgtSg3swRV/hWjOAejkjAvL8gUnsy8Erh9r4BOYQI6JeiCA8gpJYkIKakGxtxf H85fWXByknDzkv3mzxkfNP5c92Gb10Olp3PWx320kriV1R2fZL2nzHLvm3U+9+bMkGUu8Pjzb +qEoL6rXP9Ul1hPrdfZbqqx6vD0ZRNyM8I/nq4/VFsXKajtY/+De9aKDYYvOlSkoy5vyXTc/F KKU+JEoCx/tFl3v7G5nkvc7sp1Chqb7yixFGckGmoxFxUnAgDoPct8FgMAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1497622460!98451183!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 2579 invoked from network); 16 Jun 2017 14:14:20 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-7.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 16 Jun 2017 14:14:20 -0000 Received: by mail-wr0-f196.google.com with SMTP id x23so6733026wrb.0 for ; Fri, 16 Jun 2017 07:14:20 -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=8vaEdTcWG0+iIX/MWddoeZbKTXLI2T7214uG9MvJmxQ=; b=K4UdJGRzfFpTTpLg29AJIxT6R9HB3zwotWhleB3h7Q5Sr1NOLM1GmQXCL6XHyZRKet DettZiys36JPL297e6ZoG9wROQbsSBYNq9J2pQkdRSzTK8804WKGvH0XDXTYMGYWw3J4 aM7deySj9fNmb4eQSLqrM+0xJ8SL5+BBEOHQL3S3SjKm4WxenIzjIjsb67Mn91c4eLTM 2zufy7YZFOZ7r0R4xx1teilOZgTtpC/b4E3YLA90xodGsUshKuW7uWRwS/xk7Z1vu1JZ UhZjgyHMKTf9r4DpislM1Ct7YTK3XdNKtB3ejiBKBN+y4fUoHIHnmrH7vv2wueA3tfvv WmHQ== 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=8vaEdTcWG0+iIX/MWddoeZbKTXLI2T7214uG9MvJmxQ=; b=YlddM/jONm9Ohw9btTjZEWte6LGS++36rPMumj37jIjLBYtsjZKOnwqWX/onvM7bV/ +26N5lniujC73fOfVp4vz6nVitZfWIQtDwcN6E98qkb1oM3WApsOdonItJcU2YKvScAs J+Uz/YaL5SiqWy067bSKMTkZwxRyBqZGfgb3Y8as9G2ySt11HlQSWXQwvmXVsqxQFUA3 EmErBfzo8fZ/6H1Yfrk3wXqz7YUnh4oJzD+oTOh5eZBqjnEYs9mVvp1TpW6prj+GwZFL SKSAso7o1NBvAyqsOoUf32XnfmWXxv0O2Aw9K3t8XEpDmH73SQPkcZTdKKvOEHQP8Vp7 4ooA== X-Gm-Message-State: AKS2vOy4Nlu97s5PeIw3fYgEo2tnb9DuWmJi9C4n47DSJ1aOwR+X0k3P 1HdgUXqGjleUP3xq X-Received: by 10.223.152.20 with SMTP id v20mr8054029wrb.8.1497622460082; Fri, 16 Jun 2017 07:14:20 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.68]) by smtp.gmail.com with ESMTPSA id w17sm1879938wra.34.2017.06.16.07.14.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jun 2017 07:14:19 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 16 Jun 2017 16:14:18 +0200 Message-ID: <149762245830.11899.18267597682474657110.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: Anshul Makkar , George Dunlap Subject: [Xen-devel] [PATCH 6/7] xen: credit2: optimize runq_candidate() 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 By factoring into one (at the top) all the checks to see whether current is the idle vcpu, and mark it as unlikely(). In fact, if current is idle, all the logic for dealing with yielding, context switching rate limiting and soft-affinity, is just pure overhead, and we better rush checking the runq and pick some vcpu up. Signed-off-by: Dario Faggioli --- Cc: George Dunlap Cc: Anshul Makkar --- xen/common/sched_credit2.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 5d8f25c..bbda790 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -2634,13 +2634,20 @@ runq_candidate(struct csched2_runqueue_data *rqd, unsigned int *skipped) { struct list_head *iter; - struct csched2_vcpu *snext = NULL; + struct csched2_vcpu *snext = csched2_vcpu(idle_vcpu[cpu]); struct csched2_private *prv = csched2_priv(per_cpu(scheduler, cpu)); - bool yield = __test_and_clear_bit(__CSFLAG_vcpu_yield, &scurr->flags); - bool soft_aff_preempt = false; + bool yield = false, soft_aff_preempt = false; *skipped = 0; + if ( unlikely(is_idle_vcpu(scurr->vcpu)) ) + { + snext = scurr; + goto check_runq; + } + + yield = __test_and_clear_bit(__CSFLAG_vcpu_yield, &scurr->flags); + /* * Return the current vcpu if it has executed for less than ratelimit. * Adjuststment for the selected vcpu's credit and decision @@ -2650,8 +2657,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 && !is_idle_vcpu(scurr->vcpu) && - vcpu_runnable(scurr->vcpu) && + if ( !yield && prv->ratelimit_us && vcpu_runnable(scurr->vcpu) && (now - scurr->vcpu->runstate.state_entry_time) < MICROSECS(prv->ratelimit_us) ) { @@ -2672,8 +2678,7 @@ runq_candidate(struct csched2_runqueue_data *rqd, } /* If scurr has a soft-affinity, let's check whether cpu is part of it */ - if ( !is_idle_vcpu(scurr->vcpu) && - has_soft_affinity(scurr->vcpu, scurr->vcpu->cpu_hard_affinity) ) + if ( has_soft_affinity(scurr->vcpu, scurr->vcpu->cpu_hard_affinity) ) { affinity_balance_cpumask(scurr->vcpu, BALANCE_SOFT_AFFINITY, cpumask_scratch); @@ -2709,9 +2714,8 @@ runq_candidate(struct csched2_runqueue_data *rqd, */ if ( vcpu_runnable(scurr->vcpu) && !soft_aff_preempt ) snext = scurr; - else - snext = csched2_vcpu(idle_vcpu[cpu]); + check_runq: list_for_each( iter, &rqd->runq ) { struct csched2_vcpu * svc = list_entry(iter, struct csched2_vcpu, runq_elem);