From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C75A6C433FF for ; Fri, 9 Aug 2019 10:23:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A35112166E for ; Fri, 9 Aug 2019 10:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406379AbfHIKXp (ORCPT ); Fri, 9 Aug 2019 06:23:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36892 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbfHIKXp (ORCPT ); Fri, 9 Aug 2019 06:23:45 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A66927FDF0; Fri, 9 Aug 2019 10:23:44 +0000 (UTC) Received: from localhost (ovpn-8-23.pek2.redhat.com [10.72.8.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id A482319C70; Fri, 9 Aug 2019 10:23:41 +0000 (UTC) From: Ming Lei To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Ming Lei , Christoph Hellwig , Keith Busch , linux-nvme@lists.infradead.org, Jon Derrick Subject: [PATCH 1/2] genirq/affinity: improve __irq_build_affinity_masks() Date: Fri, 9 Aug 2019 18:23:09 +0800 Message-Id: <20190809102310.27246-2-ming.lei@redhat.com> In-Reply-To: <20190809102310.27246-1-ming.lei@redhat.com> References: <20190809102310.27246-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 09 Aug 2019 10:23:44 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org One invariant of __irq_build_affinity_masks() is that all CPUs in the specified masks( cpu_mask AND node_to_cpumask for each node) should be covered during the spread. Even though all requested vectors have been reached, we still need to spread vectors among left CPUs. The similar policy has been taken in case of 'numvecs <= nodes'. So remove the following check inside the loop: if (done >= numvecs) break; Meantime assign at least 1 vector for left nodes if 'numvecs' vectors have been spread. Also, if the specified cpumask for one numa node is empty, simply not spread vectors on this node. Cc: Christoph Hellwig Cc: Keith Busch Cc: linux-nvme@lists.infradead.org, Cc: Jon Derrick Signed-off-by: Ming Lei --- kernel/irq/affinity.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c index 6fef48033f96..bc3652a2c61b 100644 --- a/kernel/irq/affinity.c +++ b/kernel/irq/affinity.c @@ -129,21 +129,32 @@ static int __irq_build_affinity_masks(unsigned int startvec, for_each_node_mask(n, nodemsk) { unsigned int ncpus, v, vecs_to_assign, vecs_per_node; - /* Spread the vectors per node */ - vecs_per_node = (numvecs - (curvec - firstvec)) / nodes; - /* Get the cpus on this node which are in the mask */ cpumask_and(nmsk, cpu_mask, node_to_cpumask[n]); - - /* Calculate the number of cpus per vector */ ncpus = cpumask_weight(nmsk); + if (!ncpus) + continue; + + /* + * Calculate the number of cpus per vector + * + * Spread the vectors evenly per node. If the requested + * vector number has been reached, simply allocate one + * vector for each remaining node so that all nodes can + * be covered + */ + if (numvecs > done) + vecs_per_node = max_t(unsigned, + (numvecs - done) / nodes, 1); + else + vecs_per_node = 1; + vecs_to_assign = min(vecs_per_node, ncpus); /* Account for rounding errors */ extra_vecs = ncpus - vecs_to_assign * (ncpus / vecs_to_assign); - for (v = 0; curvec < last_affv && v < vecs_to_assign; - curvec++, v++) { + for (v = 0; v < vecs_to_assign; v++) { cpus_per_vec = ncpus / vecs_to_assign; /* Account for extra vectors to compensate rounding errors */ @@ -153,16 +164,14 @@ static int __irq_build_affinity_masks(unsigned int startvec, } irq_spread_init_one(&masks[curvec].mask, nmsk, cpus_per_vec); + if (++curvec >= last_affv) + curvec = firstvec; } done += v; - if (done >= numvecs) - break; - if (curvec >= last_affv) - curvec = firstvec; --nodes; } - return done; + return done < numvecs ? done : numvecs; } /* -- 2.20.1