Received: by 10.223.185.116 with SMTP id b49csp6162765wrg; Thu, 8 Mar 2018 02:56:01 -0800 (PST) X-Google-Smtp-Source: AG47ELs//R50zhSw2jWOwh9nMTjtrcxSRuWxq5K5Zu+IzL+IUDW3d+6nOaCgW3FQyjEW9WAQwfkH X-Received: by 10.101.64.194 with SMTP id u2mr20958863pgp.280.1520506561760; Thu, 08 Mar 2018 02:56:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520506561; cv=none; d=google.com; s=arc-20160816; b=ug3umAgPwsSm54g2jdWeUGqvlSVdAfiCSBW8dIcHhtAY9xWLUKyVW02a5hERfcFr/J pKsNjkOGmbS6WXkcnGVNXoFirLtpglP0jl55lQ4V86+ZP/Rtxnt7mA1xUBAkE1tpEdd+ KcBDl/UBqIqWAHqcTi8HcCEEWf15215ZTZLQR/rRsOC+D5Rxl/ucyx5Ba2eev0mdB6z1 So5ykkqXYrcT0LsC2Kl7hjlEvJKguxv7fvL0LMMgFEN+hUjdJxmpdknPPrykJ6u6qTTu oyGatEv+8CD/MqgGAsFN+zaTwbdUL1v0VjBT1936CSv4pAX+Tobe2ImyyWrS0WwdsL2k /uog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=XwEprRhqtBPZyefXKI4xFFbtCbAHsIP2XSwm/kkedj4=; b=MQ1H9HzQ+47FyblAf8IC3SqOFjFJoVkdvpRko+UiOwfQ7yZvVbti9VxHoHh+y+CVei tAQdoyfqMu9+PBCbBAT6UQsbJB/NEypDWmrnRtPEC86A88aEYgWzRbzpbTaZlznYvkLI paIwq1zsVpKByJ0QO/rf2ZDnfyiW00NLDXF6xqZxPnOkMn4vLFz2YM30ujMMg67LdfN5 rjz8aAHgYEG1Qhbip5/MEKE5lZPO68m1+cnU2zhHws5znsC40CLL42oOM3FwKW9QPL7D aKFmAEdwOJ5pSmeyiLJ1kDhdCqVeRlEi07z2pYMxf8Bn6Kmsg2NjT3WYlUGWSXF75enB qoFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si12794778pgv.738.2018.03.08.02.55.47; Thu, 08 Mar 2018 02:56:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966125AbeCHKyk (ORCPT + 99 others); Thu, 8 Mar 2018 05:54:40 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39308 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S964852AbeCHKyj (ORCPT ); Thu, 8 Mar 2018 05:54:39 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82B7D8424D; Thu, 8 Mar 2018 10:54:38 +0000 (UTC) Received: from localhost (ovpn-12-72.pek2.redhat.com [10.72.12.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81355215CDAA; Thu, 8 Mar 2018 10:54:30 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Thomas Gleixner , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Laurence Oberman , Ming Lei Subject: [PATCH V3 2/4] genirq/affinity: move actual irq vector spread into one helper Date: Thu, 8 Mar 2018 18:53:56 +0800 Message-Id: <20180308105358.1506-3-ming.lei@redhat.com> In-Reply-To: <20180308105358.1506-1-ming.lei@redhat.com> References: <20180308105358.1506-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 08 Mar 2018 10:54:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 08 Mar 2018 10:54:38 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org No functional change, just prepare for converting to 2-stage irq vector spread. Cc: Thomas Gleixner Reviewed-by: Christoph Hellwig Signed-off-by: Ming Lei --- kernel/irq/affinity.c | 97 +++++++++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c index 4b1c4763212d..e119e86bed48 100644 --- a/kernel/irq/affinity.c +++ b/kernel/irq/affinity.c @@ -94,50 +94,19 @@ static int get_nodes_in_cpumask(cpumask_var_t *node_to_cpumask, return nodes; } -/** - * irq_create_affinity_masks - Create affinity masks for multiqueue spreading - * @nvecs: The total number of vectors - * @affd: Description of the affinity requirements - * - * Returns the masks pointer or NULL if allocation failed. - */ -struct cpumask * -irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) +static int irq_build_affinity_masks(int nvecs, const struct irq_affinity *affd, + cpumask_var_t *node_to_cpumask, + const struct cpumask *cpu_mask, + struct cpumask *nmsk, + struct cpumask *masks) { - int n, nodes, cpus_per_vec, extra_vecs, curvec; int affv = nvecs - affd->pre_vectors - affd->post_vectors; int last_affv = affv + affd->pre_vectors; + int curvec = affd->pre_vectors; nodemask_t nodemsk = NODE_MASK_NONE; - struct cpumask *masks; - cpumask_var_t nmsk, *node_to_cpumask; - - /* - * If there aren't any vectors left after applying the pre/post - * vectors don't bother with assigning affinity. - */ - if (!affv) - return NULL; - - if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL)) - return NULL; - - masks = kcalloc(nvecs, sizeof(*masks), GFP_KERNEL); - if (!masks) - goto out; + int n, nodes, cpus_per_vec, extra_vecs; - node_to_cpumask = alloc_node_to_cpumask(); - if (!node_to_cpumask) - goto out; - - /* Fill out vectors at the beginning that don't need affinity */ - for (curvec = 0; curvec < affd->pre_vectors; curvec++) - cpumask_copy(masks + curvec, irq_default_affinity); - - /* Stabilize the cpumasks */ - get_online_cpus(); - build_node_to_cpumask(node_to_cpumask); - nodes = get_nodes_in_cpumask(node_to_cpumask, cpu_possible_mask, - &nodemsk); + nodes = get_nodes_in_cpumask(node_to_cpumask, cpu_mask, &nodemsk); /* * If the number of nodes in the mask is greater than or equal the @@ -150,7 +119,7 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) if (++curvec == last_affv) break; } - goto done; + goto out; } for_each_node_mask(n, nodemsk) { @@ -160,7 +129,7 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) vecs_per_node = (affv - (curvec - affd->pre_vectors)) / nodes; /* Get the cpus on this node which are in the mask */ - cpumask_and(nmsk, cpu_possible_mask, node_to_cpumask[n]); + cpumask_and(nmsk, cpu_mask, node_to_cpumask[n]); /* Calculate the number of cpus per vector */ ncpus = cpumask_weight(nmsk); @@ -186,7 +155,51 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) --nodes; } -done: +out: + return curvec - affd->pre_vectors; +} + +/** + * irq_create_affinity_masks - Create affinity masks for multiqueue spreading + * @nvecs: The total number of vectors + * @affd: Description of the affinity requirements + * + * Returns the masks pointer or NULL if allocation failed. + */ +struct cpumask * +irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) +{ + int curvec; + struct cpumask *masks; + cpumask_var_t nmsk, *node_to_cpumask; + + /* + * If there aren't any vectors left after applying the pre/post + * vectors don't bother with assigning affinity. + */ + if (nvecs == affd->pre_vectors + affd->post_vectors) + return NULL; + + if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL)) + return NULL; + + masks = kcalloc(nvecs, sizeof(*masks), GFP_KERNEL); + if (!masks) + goto out; + + node_to_cpumask = alloc_node_to_cpumask(); + if (!node_to_cpumask) + goto out; + + /* Fill out vectors at the beginning that don't need affinity */ + for (curvec = 0; curvec < affd->pre_vectors; curvec++) + cpumask_copy(masks + curvec, irq_default_affinity); + + /* Stabilize the cpumasks */ + get_online_cpus(); + build_node_to_cpumask(node_to_cpumask); + curvec += irq_build_affinity_masks(nvecs, affd, node_to_cpumask, + cpu_possible_mask, nmsk, masks); put_online_cpus(); /* Fill out vectors at the end that don't need affinity */ -- 2.9.5