From patchwork Thu Apr 6 08:17:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9666341 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 030FD60364 for ; Thu, 6 Apr 2017 08:19:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3AFE28485 for ; Thu, 6 Apr 2017 08:19:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D871C284BC; Thu, 6 Apr 2017 08:19:14 +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 46B5128485 for ; Thu, 6 Apr 2017 08:19:14 +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 1cw2bO-0000rf-SW; Thu, 06 Apr 2017 08:17:10 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cw2bN-0000qm-Fr for xen-devel@lists.xenproject.org; Thu, 06 Apr 2017 08:17:09 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id 3C/76-16497-389F5E85; Thu, 06 Apr 2017 08:17:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpileJIrShJLcpLzFFi42K5GNpwRLfh59M Ig555HBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aidVsZCw4qVbScu8LWwNgu2cXIxSEkMINR 4m7Xc1YQh0VgDavE+y2r2UAcCYFLrBLXls5i6WLkBHLiJF5d3McOYVdLTOnZzQRiCwmoSNzcv ooJYtQvRol7k5aDNQgL6EkcOfqDHcL2kJj2YSMziM0mYCDxZsdeVhBbREBJ4t6qyUDNHBzMAu ESqzu5QcIsAqoSlyefBZvPK+At0fmvjx2khFPAR2JFsziIKQQUnvu6AKRCVEBOYuXlFlaIakG JkzOfsEAM1JRYv0sfJMwsIC+x/e0c5gmMIrOQVM1CqJqFpGoBI/MqRo3i1KKy1CJdQ0u9pKLM 9IyS3MTMHF1DA1O93NTi4sT01JzEpGK95PzcTYzA0K9nYGDcwfio3+8QoyQHk5Ior4LPkwghv qT8lMqMxOKM+KLSnNTiQ4waHBwCE87Onc4kxZKXn5eqJMEb9ONphJBgUWp6akVaZg4wOmFKJT h4lER4fUHSvMUFibnFmekQqVOMxhwvLr9/z8TxZOWP90xCYJOkxHm/fAcqFQApzSjNgxsESxq XGGWlhHkZGRgYhHgKUotyM0tQ5V8xinMwKgnzSoEs5MnMK4Hb9wroFCagU3xugZ1SkoiQkmpg 1Ou06tu+NebT3I0m3BMU768J2rrlzcyfeSXB7jHTs//Zt4tzcbBNjSsOC2SpNPKIl917RGvB4 pLkQ983qmXxRktsZ+Cd8jZG4uL0ab5b8wrKnRPvVav+ZFGc4dF+ynSSYtbpqa7NsYfPRD+eoV q0Ln3G3n85xmw3Lv7KflP080m1TyX3qnv1SizFGYmGWsxFxYkAdLF4DhUDAAA= X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1491466623!91959763!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.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14467 invoked from network); 6 Apr 2017 08:17:04 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-6.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 6 Apr 2017 08:17:04 -0000 Received: by mail-wr0-f196.google.com with SMTP id g19so9014376wrb.0 for ; Thu, 06 Apr 2017 01:17:04 -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=Omr5o0y9crm+Y4fNYGb00B2+Mac0PGI0fzJCw6vOyp4=; b=Cjo5r9j1XHin2MkhisQaBeS5upHa1p9Rv3sqcphvIDOxcaknGWlSSLQMda/2jeibok QqeuBD18c+yBG2PC/F7XQaP941wV5TSTUYQbufIPSykctrJaBz5v2LdErhQvrLSxFNjB E9hCrLTukNS5JEv6X1WtMqZggaUyqwO9Os/vapJyGUXDb1tLyJeBN/ekAvDCUMYHRM3t S/iLR3/UXQ5PAK6L7HrTGPlNslnZuIkxNILL/LwBQw2omVq8XHsC8Pc14SGNayq0wbFv RXGLxt1AJ5B1iJpIbfKIa++PPhIN3beQGgJ8YfHm++FBCVfJmzkYW6Ai44NckZqGhECA Uhog== 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=Omr5o0y9crm+Y4fNYGb00B2+Mac0PGI0fzJCw6vOyp4=; b=mp+Y3bJNE3F4g/cKBt9EiWiZOHxN14iqgineGs6lTHhldxSxyNb9dFRvoEFweofzjE djoeYg0G5A7vDTJuNc5Hiv2cccIG45zlAmLtnbg+sDxALE51jWGWa4y5KlSK8FTe3uA2 Xkh1lvC3VIlEzGQg2qky2RZVu3cWY+or8cJFftq0Bwm7vbO6e6CPyLu1VIIx70bvxl4O LMEuo2qlwygkVcq7ZbP527PbsH7KJu3wvyKkWnsa77LXrhLLgWtq3XXqump+1sJU0Frf wuuQEY6jvB3m/KZebtgxi87jkx9ZYaDzA2ji+QgK4+uraW1ZsHPx/UcR+xul+lIyZvN8 D3Mw== X-Gm-Message-State: AN3rC/6ltNjZJkASCFRIsf0FoLjoJd4w8t6UCQjEfl0c3TMi9XLPEIR5 sU3akZYDhLMxPSF8 X-Received: by 10.28.153.140 with SMTP id b134mr3841034wme.124.1491466623436; Thu, 06 Apr 2017 01:17:03 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.217]) by smtp.gmail.com with ESMTPSA id y11sm1147798wrd.22.2017.04.06.01.17.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Apr 2017 01:17:02 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Thu, 06 Apr 2017 10:17:01 +0200 Message-ID: <149146662128.21348.5762709430939664791.stgit@Solace.fritz.box> In-Reply-To: <149146456487.21348.8554211499146017782.stgit@Solace.fritz.box> References: <149146456487.21348.8554211499146017782.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Anshul Makkar , George Dunlap Subject: [Xen-devel] [PATCH v2 7/7] 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 Acked-by: George Dunlap --- 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 bb1c657..a76bedb 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); @@ -2819,13 +2826,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); @@ -2928,6 +2937,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; } @@ -3040,6 +3052,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);