From nobody Mon Apr 29 07:01:54 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1564397430; cv=none; d=zoho.com; s=zohoarc; b=Y0MSpKiQBKOFnIRV3psN3gw3M1o96qatX/rK2W5y00qjwbuBEyNZOobEroaEilF4yAjlAR5CcuYIKFiFbnmoJvRLxf1AM3u0LzFwfuwx/xRFGUIsZou5eJgdkWFDrkXlUWbINy2LrHNLH1PmpOaFVVdiS2bNWBtJ6wpjtX4dRbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564397430; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=Q2KWEfUlUGGIkgP3OE5hqyfqtxVTwdZk6vPkT965Gz8=; b=W/evhT9vlNwhU/YsTZFz37JDyyZUNjhzgriHMn11GpQJJ3H+nNWCpNsAQH5b7DhqjVUBKln7dU7MR8/Xgl2YW7Z/ohNCp/ilflqW/+iIO0aXdwwsKRrhR2qpyYiDgBokhji6a+PNic4B2sx39X9Mc925INjydJe8mgaj+a0rG5M= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1564397430036807.0508538297508; Mon, 29 Jul 2019 03:50:30 -0700 (PDT) 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 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) 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) X-Inumbo-ID: 7f6388a4-b1ee-11e9-b5e3-cbf56ce58823 X-Virus-Scanned: by amavisd-new at test-mx.suse.de 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 = */ =20 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) = */ =20 int load; /* Instantaneous load (num of non-idle vcpu= s) */ @@ -2613,8 +2614,8 @@ retry: if ( st.orqd->b_avgload > load_max ) load_max =3D st.orqd->b_avgload; =20 - cpus_max =3D cpumask_weight(&st.lrqd->active); - i =3D cpumask_weight(&st.orqd->active); + cpus_max =3D st.lrqd->nr_cpus; + i =3D st.orqd->nr_cpus; if ( i > cpus_max ) cpus_max =3D i; =20 @@ -3697,7 +3698,7 @@ csched2_dump(const struct scheduler *ops) "\tinstload =3D %d\n" "\taveload =3D %"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 csched= 2_pcpu *spc, =20 __cpumask_set_cpu(cpu, &spc->sibling_mask); =20 - 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 csche= d2_pcpu *spc, __cpumask_set_cpu(cpu, &prv->initialized); __cpumask_set_cpu(cpu, &rqd->smt_idle); =20 - if ( cpumask_weight(&rqd->active) =3D=3D 1 ) + rqd->nr_cpus++; + ASSERT(cpumask_weight(&rqd->active) =3D=3D rqd->nr_cpus); + + if ( rqd->nr_cpus =3D=3D 1 ) rqd->pick_bias =3D cpu; =20 return spc->runq_id; @@ -3934,7 +3938,10 @@ csched2_deinit_pdata(const struct scheduler *ops, vo= id *pcpu, int cpu) for_each_cpu ( rcpu, &rqd->active ) __cpumask_clear_cpu(cpu, &csched2_pcpu(rcpu)->sibling_mask); =20 - if ( cpumask_empty(&rqd->active) ) + rqd->nr_cpus--; + ASSERT(cpumask_weight(&rqd->active) =3D=3D rqd->nr_cpus); + + if ( rqd->nr_cpus =3D=3D 0 ) { printk(XENLOG_INFO " No cpus left on runqueue, disabling\n"); deactivate_runqueue(prv, spc->runq_id); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel