From patchwork Mon Jul 29 10:49:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 11063607 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9799A13A4 for ; Mon, 29 Jul 2019 10:50:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B16A27BA5 for ; Mon, 29 Jul 2019 10:50:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CC9428414; Mon, 29 Jul 2019 10:50:47 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EAD7F27BA5 for ; Mon, 29 Jul 2019 10:50:46 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hs3DR-00083J-T0; Mon, 29 Jul 2019 10:49:17 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hs3DQ-00083E-0G for xen-devel@lists.xenproject.org; Mon, 29 Jul 2019 10:49:16 +0000 X-Inumbo-ID: 7f6388a4-b1ee-11e9-b5e3-cbf56ce58823 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7f6388a4-b1ee-11e9-b5e3-cbf56ce58823; Mon, 29 Jul 2019 10:49:11 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 88E91B616; Mon, 29 Jul 2019 10:49:10 +0000 (UTC) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Mon, 29 Jul 2019 12:49:09 +0200 Message-ID: <156439734950.9656.3257482583234913248.stgit@Palanthas> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] xen: credit2: avoid using cpumask_weight() in hot-paths X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: George Dunlap , Andrew Cooper , Andrii Anisov Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP cpumask_weight() is known to be expensive. In Credit2, we use it in load-balancing, but only for knowing how many CPUs are active in a runqueue. Keeping such count in an integer field of the per-runqueue data structure we have, completely avoids the need for cpumask_weight(). While there, remove as much other uses of it as we can, even if not in hot-paths. Signed-off-by: Dario Faggioli Reviewed-by: Andrii Anisov Reviewed-by: George Dunlap --- Cc: George Dunlap Cc: Andrew Cooper Cc: Andrii Anisov --- I just realized this patch fell through the cracks! :-O I sent it quite a while ago, I got some comments from Andrew and Andrii, but then never really followed up. So here we hare! Changes from v1: * nr_cpus is now unsigned * coding style (no hard tabs) * killed a couple of redundant ASSERT()s --- xen/common/sched_credit2.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 8e4381d8a7..fbdc4618cb 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -466,6 +466,7 @@ struct csched2_runqueue_data { spinlock_t lock; /* Lock for this runqueue */ struct list_head runq; /* Ordered list of runnable vms */ + unsigned int nr_cpus; /* How many CPUs are sharing this runqueue */ int id; /* ID of this runqueue (-1 if invalid) */ int load; /* Instantaneous load (num of non-idle vcpus) */ @@ -2613,8 +2614,8 @@ retry: if ( st.orqd->b_avgload > load_max ) load_max = st.orqd->b_avgload; - cpus_max = cpumask_weight(&st.lrqd->active); - i = cpumask_weight(&st.orqd->active); + cpus_max = st.lrqd->nr_cpus; + i = st.orqd->nr_cpus; if ( i > cpus_max ) cpus_max = i; @@ -3697,7 +3698,7 @@ csched2_dump(const struct scheduler *ops) "\tinstload = %d\n" "\taveload = %"PRI_stime" (~%"PRI_stime"%%)\n", i, - cpumask_weight(&prv->rqd[i].active), + prv->rqd[i].nr_cpus, nr_cpu_ids, cpumask_bits(&prv->rqd[i].active), prv->rqd[i].max_weight, prv->rqd[i].pick_bias, @@ -3815,7 +3816,7 @@ init_pdata(struct csched2_private *prv, struct csched2_pcpu *spc, __cpumask_set_cpu(cpu, &spc->sibling_mask); - if ( cpumask_weight(&rqd->active) > 0 ) + if ( rqd->nr_cpus > 0 ) for_each_cpu ( rcpu, per_cpu(cpu_sibling_mask, cpu) ) if ( cpumask_test_cpu(rcpu, &rqd->active) ) { @@ -3828,7 +3829,10 @@ init_pdata(struct csched2_private *prv, struct csched2_pcpu *spc, __cpumask_set_cpu(cpu, &prv->initialized); __cpumask_set_cpu(cpu, &rqd->smt_idle); - if ( cpumask_weight(&rqd->active) == 1 ) + rqd->nr_cpus++; + ASSERT(cpumask_weight(&rqd->active) == rqd->nr_cpus); + + if ( rqd->nr_cpus == 1 ) rqd->pick_bias = cpu; return spc->runq_id; @@ -3934,7 +3938,10 @@ csched2_deinit_pdata(const struct scheduler *ops, void *pcpu, int cpu) for_each_cpu ( rcpu, &rqd->active ) __cpumask_clear_cpu(cpu, &csched2_pcpu(rcpu)->sibling_mask); - if ( cpumask_empty(&rqd->active) ) + rqd->nr_cpus--; + ASSERT(cpumask_weight(&rqd->active) == rqd->nr_cpus); + + if ( rqd->nr_cpus == 0 ) { printk(XENLOG_INFO " No cpus left on runqueue, disabling\n"); deactivate_runqueue(prv, spc->runq_id);