From patchwork Thu Jul 27 12:06:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9866703 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 7395960382 for ; Thu, 27 Jul 2017 12:08:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65B0328789 for ; Thu, 27 Jul 2017 12:08:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A64D287FE; Thu, 27 Jul 2017 12:08:13 +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 D340028789 for ; Thu, 27 Jul 2017 12:08:12 +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 1dahYT-0005eZ-D1; Thu, 27 Jul 2017 12:06:13 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dahYS-0005e9-1g for xen-devel@lists.xenproject.org; Thu, 27 Jul 2017 12:06:12 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 7A/86-02177-337D9795; Thu, 27 Jul 2017 12:06:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmleJIrShJLcpLzFFi42K5GNpwSNfoemW kwe+Xihbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bUA5dZCtZLVFxoOcvewLhDuIuRi0NIYAaj xOXVV9hBHBaBNawSHZNfsoI4EgKXWCXud+1j7GLkBHLiJE59fcvWxcgBZFdIrH/uARIWElCRu Ll9FROE/YNR4vv6SBBbWEBP4sjRH+wQto/E5AVnWEBsNgEDiTc79rKC2CICShL3Vk0G62UWCJ WY8+4MG4jNIqAqMXnjebA4r4CjxIFvL5lBbE4BJ4ntF5rYIHY5Stw++xNsvqiAnMTKyy2sEPW CEidnPmEBOZNZQFNi/S59iPHyEtvfzmGewCgyC0nVLISqWUiqFjAyr2LUKE4tKkst0jWy0Esq ykzPKMlNzMzRNTQw1stNLS5OTE/NSUwq1kvOz93ECAz+egYGxh2M7Sf8DjFKcjApifJOMq2IF OJLyk+pzEgszogvKs1JLT7EqMHBITDh7NzpTFIsefl5qUoSvDOvVUYKCRalpqdWpGXmAOMTpl SCg0dJhLf9KlCat7ggMbc4Mx0idYrRmOPKlXVfmDimHNj+hUkIbJKUOG8KyCQBkNKM0jy4QbC 0cYlRVkqYl5GBgUGIpyC1KDezBFX+FaM4B6OSMO9NkIU8mXklcPteAZ3CBHTKxCawU0oSEVJS DYz8d5gqmv89nvKk87iFl8Yu940rHbbWnPslvM1/Y3Rq5tWGSzNLHr36vaOtZBl3u4XFnsNZ2 l+CNyofjTwRKlSe0OrpVv7l76qTW99UfV9bXKIwhWmaKSOLkNevlVvOsLOsTSjP6GuMC1rvcL MrhkcxyqvWlM3D8Cxbh93NV/+nxdo5TT5at0yJpTgj0VCLuag4EQC3X3JkFgMAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1501157170!51920248!1 X-Originating-IP: [209.85.128.194] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22569 invoked from network); 27 Jul 2017 12:06:10 -0000 Received: from mail-wr0-f194.google.com (HELO mail-wr0-f194.google.com) (209.85.128.194) by server-9.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 27 Jul 2017 12:06:10 -0000 Received: by mail-wr0-f194.google.com with SMTP id 12so16211901wrb.4 for ; Thu, 27 Jul 2017 05:06:10 -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=2TA1rh4DrPBzLWGm90fQ9eMix+JIYgYjcLVSxuwuISg=; b=hBet8UUGcMpIsc/Y65MWXN3gdlIHdZ5m5Y+UoGta1suB8UjQuyQqEqKZCCwlPKAh1i T4GQdkWBdbXgDkXnZpMDXGGKnBEEDFQjFkE0JiEsq4m0AwZAnJPwrAFWbxywgOyt5Kha lHHZ3v1MiUmShS4hDl46x6wjabRFS6kSJxNUGiOQBOJzkiDKijhgQrJIfmIJj+zxgZ5E YkVdkVomIA9/lE9vpE2Z8u+nm9T4lnnevZzpfmDDW+LdjdwOzzmgMQoQvaJEyLyItey1 Sbg4sc5+dktxGrb9cvtPhHvg5VJOTSPq4qUMRQPfH2h8inTGf7XjpDhGj7KROfokYL9f Al9Q== 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=2TA1rh4DrPBzLWGm90fQ9eMix+JIYgYjcLVSxuwuISg=; b=Dg5iJhBLirsG0/1RSV5iHvZyrBwPfyV+5vThAZIcfc2cwuQtGaSb8bTidBkkMOueq9 KPxN1nIBLSM7YTPpzJxrS5tvCiS3VTwM/ea+rt8OMxYXg6bnoKeOEPjJ0FPOeJcn98uj PiC/Rp1B4jQ7FLvQcMQeiC+G0ivJC9jPvT/qp7FAAZgk6Mqr2n1V4nIbNK3iYJrOSEfY mSUfOMF+caX2x7P6OlEremUL9fv073phHMOffto/QIdyiSbOo3VYxTHuNL7hwtJxTATW zfQ7EL6fftx/9Bg5LA6cH8A7/9GV8yBFKwjs8j61x1WF3jUzxPmmaLuiPil5TMa0DKsI QRWw== X-Gm-Message-State: AIVw112vjK9XCIldU2YK9iA0OEvcEJWet0y+SsEZ9Xpgo/ScS/5a9cKE 46iH7RajduBjwRnm X-Received: by 10.223.131.130 with SMTP id 2mr3811643wre.51.1501157169838; Thu, 27 Jul 2017 05:06:09 -0700 (PDT) Received: from [192.168.0.31] ([80.66.223.212]) by smtp.gmail.com with ESMTPSA id 141sm2060391wmh.45.2017.07.27.05.06.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Jul 2017 05:06:09 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Thu, 27 Jul 2017 14:06:08 +0200 Message-ID: <150115716805.6767.12099050566492087569.stgit@Solace> In-Reply-To: <150115657192.6767.15778617807307106582.stgit@Solace> References: <150115657192.6767.15778617807307106582.stgit@Solace> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap , Anshul Makkar Subject: [Xen-devel] [PATCH v2 5/6] 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 Reviewed-by: George Dunlap --- Cc: Anshul Makkar --- Changes from v1: - for George: about what you said in , I went for the "leave unset at declaration and set explicitly on both paths" apprach, i.e., the one you said you preferred (as I also like it better in this case). After doing that, I've applied your Reviewed-by, as you said I could. --- xen/common/sched_credit2.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 3f10b4b..30d9f55 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -2674,11 +2674,18 @@ runq_candidate(struct csched2_runqueue_data *rqd, struct list_head *iter; struct csched2_vcpu *snext = NULL; 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 @@ -2688,8 +2695,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) ) { @@ -2710,8 +2716,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); @@ -2750,6 +2755,7 @@ runq_candidate(struct csched2_runqueue_data *rqd, 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);