From patchwork Thu Mar 2 10:38:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9599913 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 3088260522 for ; Thu, 2 Mar 2017 10:40:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0ECC2284F4 for ; Thu, 2 Mar 2017 10:40:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0384428562; Thu, 2 Mar 2017 10:40:46 +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 8DEEF2858C for ; Thu, 2 Mar 2017 10:40:45 +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 1cjO8F-0004NN-7H; Thu, 02 Mar 2017 10:38:47 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjO8D-0004Mi-Tr for xen-devel@lists.xenproject.org; Thu, 02 Mar 2017 10:38:46 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id 8C/CE-00609-536F7B85; Thu, 02 Mar 2017 10:38:45 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrHIsWRWlGSWpSXmKPExsXiVRvkqGvybXu EwZJDYhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0ZDTwdbwUGliiMT37M1MLZLdjFycQgJzGCU mNJ2ngnEYRFYwyrRvP0bO4gjIXAJyPm/jK2LkRPIiZFY9/s+M4RdLrF7yhqwuJCAisTN7auYI Eb9YJRoOA/RICygJ3Hk6A92CNtVYnrbPrA4m4CBxJsde1lBbBEBJYl7qyYDNXNwMAuES6zu5A YJswioSiy7fw2shFfAW6L7xiowm1PAV6Lz7wVWiL0+Ej9m9oPZogJyEisvt0DVC0qcnPmEBWK kpsT6XfogYWYBeYntb+cwT2AUmYWkahZC1SwkVQsYmVcxahSnFpWlFukaGuklFWWmZ5TkJmbm 6BoaGOvlphYXJ6an5iQmFesl5+duYgSGPwMQ7GB81e18iFGSg0lJlJf32fYIIb6k/JTKjMTij Pii0pzU4kOMGhwcAhPOzp3OJMWSl5+XqiTB6/gVqE6wKDU9tSItMwcYoTClEhw8SiK85SBp3u KCxNzizHSI1ClGXY4P/YffMAmBzZAS52UDKRIAKcoozYMbAUsWlxhlpYR5GYEOFOIpSC3KzSx BlX/FKM7BqCTM+/cL0BSezLwSuE2vgI5gAjrihcpWkCNKEhFSUg2M2eu9c0qOVt2VlnScckbN rOlu+zvrbZOKWhk4zzCcDUzPzT76XG0SS91Sw7XLt+UVf8qNrX4xOWvmj893OOr1fOo4Hp/jf KGtKWh6Xue2esvEKnnfmL27LrSse6bZaaHsMYtLONykPS1OrPHtSpUar1u3Lj5yYLnHvmJ3yZ 2E3NTIM7MWxeUpsRRnJBpqMRcVJwIAWPqe/hEDAAA= X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1488451124!61837656!1 X-Originating-IP: [74.125.82.65] 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 59020 invoked from network); 2 Mar 2017 10:38:44 -0000 Received: from mail-wm0-f65.google.com (HELO mail-wm0-f65.google.com) (74.125.82.65) by server-6.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 2 Mar 2017 10:38:44 -0000 Received: by mail-wm0-f65.google.com with SMTP id u63so11697586wmu.2 for ; Thu, 02 Mar 2017 02:38:44 -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=3Vi5k34a+JW3zq5axUvgXtxAduk/vTOtz02Tb7AaHkY=; b=rBoXh2jNdoj8HXikeUd/CGGX9s9XGbsYUb34OaWBklGYPCQjgxvVcKX6U/ArM+skHy Z/qiUtIAaCBvh4nPJP70NGSPOSxyKP26ZLgoy3yc4ZHap1/nWydjZrTMzqGqxqJS+47t yhkCyNcYXqd88fYrKuTgqWPosPzbf2dAHFfL+IdKpPyDxzeWZJYe67s21jRm3Se+Fshk /WwG/fry6oUGUJLifzF1z/SJNM/UOWeHtd8ic7zVpe2fXyNDPGrrlSjgR3QGcSAphCX5 N5HMkFgYyBcOW7N6S0BsyfZL1fjzPppo7FNfBxEfMKbMqW21FggBtRpZLYG2Xx0Tl15a +TPw== 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=3Vi5k34a+JW3zq5axUvgXtxAduk/vTOtz02Tb7AaHkY=; b=QERnS6c10TGGnTOL8oYdhNYbGVV014oQbgH+8/ujFl+807gnOIiBwUsh3Uw9AtfT+i Uo3QSBCOwkoyDEiU4RhubKLwqjHgC9yRl32r4eh04AWMHmj7NtoCYBBM/WLTs7s0KpRw jRy9Tw2RlW/CnA/3c4z5mVw7ybh0zg91LL3yI9aN8xA78FtPQNXrlTE0Ip2fRllWLm4R 35TMRknvmCV9q8rE2Ecu4sXq87TqYt7dQ5lbb0uUFGzkPCrT4deK6NS/AoNX2uTBTJRf yQshgkdeJ16v2n/dpDsTIlxQsykwFcSybd6KII1btwCByQNcGfcGK8V997XVMBvpISj9 T/zg== X-Gm-Message-State: AMke39na7s8RfulhFmzhjdloUov6flk5zYMl2ip9IazdwnlepPC1xfbwtWqbXjiP/bhIJg== X-Received: by 10.28.16.70 with SMTP id 67mr7806960wmq.142.1488451123922; Thu, 02 Mar 2017 02:38:43 -0800 (PST) Received: from Solace.fritz.box ([80.66.223.93]) by smtp.gmail.com with ESMTPSA id g5sm6552802wrb.48.2017.03.02.02.38.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Mar 2017 02:38:43 -0800 (PST) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Thu, 02 Mar 2017 11:38:42 +0100 Message-ID: <148845112180.23452.8259262785857293794.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: Anshul Makkar , George Dunlap Subject: [Xen-devel] [PATCH 6/6] xen: credit2: avoid cpumask_any() in pick_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 cpumask_any() is costly (because of the randomization). And since it does not really matter which exact CPU is selected within a runqueue, as that will be overridden shortly after, in runq_tickle(), spending too much time and achieving true randomization is pretty pointless. As the picked CPU, however, would be used as an hint, within runq_tickle(), don't give up on it entirely, and let's make sure we don't always return the same CPU, or favour lower or higher ID CPUs. To achieve that, let's record and remember, for each runqueue, what CPU we picked for last, and start from that the following time. Signed-off-by: Dario Faggioli --- Cc: George Dunlap Cc: Anshul Makkar --- xen/common/sched_credit2.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index af457c1..7b9e1a1 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -363,6 +363,7 @@ struct csched2_runqueue_data { struct list_head runq; /* Ordered list of runnable vms */ struct list_head svc; /* List of all vcpus assigned to this runqueue */ unsigned int max_weight; + unsigned int pick_bias;/* Last CPU we picked. Start from it next time */ cpumask_t idle, /* Currently idle pcpus */ smt_idle, /* Fully idle-and-untickled cores (see below) */ @@ -1679,7 +1680,9 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) { cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), &svc->migrate_rqd->active); - new_cpu = cpumask_any(cpumask_scratch_cpu(cpu)); + new_cpu = cpumask_cycle(svc->migrate_rqd->pick_bias, + cpumask_scratch_cpu(cpu)); + svc->migrate_rqd->pick_bias = new_cpu; goto out_up; } /* Fall-through to normal cpu pick */ @@ -1737,7 +1740,9 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), &prv->rqd[min_rqi].active); - new_cpu = cpumask_any(cpumask_scratch_cpu(cpu)); + new_cpu = cpumask_cycle(prv->rqd[min_rqi].pick_bias, + cpumask_scratch_cpu(cpu)); + prv->rqd[min_rqi].pick_bias = new_cpu; BUG_ON(new_cpu >= nr_cpu_ids); out_up: @@ -1854,7 +1859,9 @@ static void migrate(const struct scheduler *ops, cpupool_domain_cpumask(svc->vcpu->domain)); cpumask_and(cpumask_scratch_cpu(cpu), cpumask_scratch_cpu(cpu), &trqd->active); - svc->vcpu->processor = cpumask_any(cpumask_scratch_cpu(cpu)); + svc->vcpu->processor = cpumask_cycle(trqd->pick_bias, + cpumask_scratch_cpu(cpu)); + trqd->pick_bias = svc->vcpu->processor; ASSERT(svc->vcpu->processor < nr_cpu_ids); _runq_assign(svc, trqd); @@ -2821,13 +2828,15 @@ csched2_dump(const struct scheduler *ops) printk("Runqueue %d:\n" "\tncpus = %u\n" "\tcpus = %s\n" - "\tmax_weight = %d\n" + "\tmax_weight = %u\n" + "\tpick_bias = %u\n" "\tinstload = %d\n" "\taveload = %"PRI_stime" (~%"PRI_stime"%%)\n", i, cpumask_weight(&prv->rqd[i].active), cpustr, prv->rqd[i].max_weight, + prv->rqd[i].pick_bias, prv->rqd[i].load, prv->rqd[i].avgload, fraction); @@ -2930,6 +2939,9 @@ init_pdata(struct csched2_private *prv, unsigned int cpu) __cpumask_set_cpu(cpu, &prv->initialized); __cpumask_set_cpu(cpu, &rqd->smt_idle); + if ( cpumask_weight(&rqd->active) == 1 ) + rqd->pick_bias = cpu; + return rqi; } @@ -3042,6 +3054,8 @@ csched2_deinit_pdata(const struct scheduler *ops, void *pcpu, int cpu) printk(XENLOG_INFO " No cpus left on runqueue, disabling\n"); deactivate_runqueue(prv, rqi); } + else if ( rqd->pick_bias == cpu ) + rqd->pick_bias = cpumask_first(&rqd->active); spin_unlock(&rqd->lock);