From patchwork Sat Apr 20 15:24:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 10910349 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 B1554922 for ; Sat, 20 Apr 2019 15:26:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9538B28698 for ; Sat, 20 Apr 2019 15:26:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85727289A3; Sat, 20 Apr 2019 15:26:37 +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 E00CA28698 for ; Sat, 20 Apr 2019 15:26:36 +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 1hHrrC-00049L-UZ; Sat, 20 Apr 2019 15:24:46 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hHrrA-000495-O1 for xen-devel@lists.xenproject.org; Sat, 20 Apr 2019 15:24:44 +0000 X-Inumbo-ID: 6bf64945-6380-11e9-92d7-bc764e045a96 Received: from mail-wm1-f66.google.com (unknown [209.85.128.66]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 6bf64945-6380-11e9-92d7-bc764e045a96; Sat, 20 Apr 2019 15:24:43 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id z6so10876058wmi.0 for ; Sat, 20 Apr 2019 08:24:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=aN8ovK6MLgPyDT9K6fPdxnO4TPJN6/GOvyeYdsc0Fpg=; b=n+eZRJEaqq49LnhqPkbv0ul1OPQgU7pnidiCyXtD8UKVn98BDGQQ42KmcphPKm88v0 naTXEwAq0UACkRbHFIuqUQgrUotuhgS6MRTxP/PeVcilJg3DzCF9ScOhV2sqeXAtwqlX V8GoJCARmZ7d/ScnM5elFWRQo0MYzOqX6umZ+/aqzOM+F5Ty5n8UUdGjxIp4omRIi5wE WohGxqQdgyQ87HGg6k4BONpnBoCksbZw3goNrf9THaBr/MBfqY0rTAmvDXlp9vlx3bVP NEhEagaob6xkA2LumXSEXI/f99Fau72QAvIANqkHU+2DVjswVlF7s/Z5VL1SJ5iFjOoT drMA== X-Gm-Message-State: APjAAAWx0ZX+3J2N4XqQXjz3bswAaNEE2rcis8KCg2w2L+dwg9Z2HEPc hUb1IAIhYbTnLxYo6zRSErMnWkqO3ao= X-Google-Smtp-Source: APXvYqzpdll8nS2reTTJvTDKDq740iswK8KazTs0ntvlreoNntvgGZW93JelwHzh/TiOgGrSsBHc6w== X-Received: by 2002:a7b:c147:: with SMTP id z7mr6407423wmi.67.1555773882349; Sat, 20 Apr 2019 08:24:42 -0700 (PDT) Received: from [127.0.0.1] (87.78.186.89.cust.ip.kpnqwest.it. [89.186.78.87]) by smtp.gmail.com with ESMTPSA id y3sm7093626wmi.27.2019.04.20.08.24.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Apr 2019 08:24:41 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Sat, 20 Apr 2019 17:24:40 +0200 Message-ID: <155577388014.25746.13361382203794112287.stgit@wayrath> In-Reply-To: <155577364571.25746.11988517450711182732.stgit@wayrath> References: <155577364571.25746.11988517450711182732.stgit@wayrath> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/2] 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 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 --- Cc: George Dunlap --- xen/common/sched_credit2.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 6958b265fc..7034325243 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 */ + 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, @@ -3818,6 +3819,9 @@ init_pdata(struct csched2_private *prv, struct csched2_pcpu *spc, __cpumask_set_cpu(cpu, &prv->initialized); __cpumask_set_cpu(cpu, &rqd->smt_idle); + rqd->nr_cpus++; + ASSERT(cpumask_weight(&rqd->active) == rqd->nr_cpus); + /* On the boot cpu we are called before cpu_sibling_mask has been set up. */ if ( cpu == 0 && system_state < SYS_STATE_active ) __cpumask_set_cpu(cpu, &csched2_pcpu(cpu)->sibling_mask); @@ -3829,8 +3833,11 @@ init_pdata(struct csched2_private *prv, struct csched2_pcpu *spc, __cpumask_set_cpu(rcpu, &csched2_pcpu(cpu)->sibling_mask); } - if ( cpumask_weight(&rqd->active) == 1 ) + if ( rqd->nr_cpus == 1 ) + { + ASSERT(cpumask_weight(&rqd->active) == 1); rqd->pick_bias = cpu; + } return spc->runq_id; } @@ -3944,8 +3951,12 @@ csched2_deinit_pdata(const struct scheduler *ops, void *pcpu, int cpu) __cpumask_clear_cpu(cpu, &rqd->smt_idle); __cpumask_clear_cpu(cpu, &rqd->active); - if ( cpumask_empty(&rqd->active) ) + rqd->nr_cpus--; + ASSERT(cpumask_weight(&rqd->active) == rqd->nr_cpus); + + if ( rqd->nr_cpus == 0 ) { + ASSERT(cpumask_empty(&rqd->active)); printk(XENLOG_INFO " No cpus left on runqueue, disabling\n"); deactivate_runqueue(prv, spc->runq_id); }