Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2275523imb; Mon, 4 Mar 2019 00:29:15 -0800 (PST) X-Google-Smtp-Source: APXvYqwZ5j0dPu5O1x5khPTMc7W6ZpWEerDT5ZMf782izNkRzitEBy3z4MSPSrr0K1zwHozVM7cg X-Received: by 2002:aa7:81c5:: with SMTP id c5mr19294683pfn.217.1551688155445; Mon, 04 Mar 2019 00:29:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551688155; cv=none; d=google.com; s=arc-20160816; b=LLcDhx+sr1ecL2fVccFc2s6TlzeobQV9h06Bs5q2RkCFHCgVTiLcfGGgrUzvLunY36 Tj+EQEQlKpn4nOy+oHzrGDF5R9r+XqYSSczZrgEWMgZiNWh8cRqOdMtf/wYzqgJWEEwV y0FEr0lvpMDn6aN5cSS7cj6F5oj+EEj8yOM8Wa8Sxe2MW1p1WMLbQuvjs+ARWIV/uk0c G6fVM8v0DPEfsqjDHomKReQoYLh2bk+eWryjyzVS27AB92/BBtuf0oiKVxvsuKkdUBaw MuofHHMMCbe9Ch0lEw9N5l9CB2WTLp61uB44TwjEEZyohGZrulDoI/FYnRPUEd7eg1ZI x42w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jJbWlPg25wra0Ycn2h8R+QlMs5Qw/tOEoizvW4zoUnk=; b=uV5VGK8KlYUMKS6elaYpeNk8YUg+NUvZrtExlYICvbFqncox9QagahTF8HRTvC6W9S eOjBp43MWiXUgskhRrYcoQksfZ0j76El3qc15xcJ/7kwYDn3uB53NDGCqiYHnUiEzWg3 HePSiUNhNy9gWs8+/mHGyolHnUePurnJhh05PadktJO1VL29T0W8BXAmN58eBv+h7Lz/ og3SvpRXp5Jd1gSFwG6gwh4NdrIgw1mnQyS/03MqnhG1KBquubsDa0iWxu3uQt/pwi9D pTK80Em5qVJDYgLoVqe39n7xStHNWgqtFCj4aYxOG8tHS2nuWKU/FdHqYfVm5NiNZwp1 VzYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bYRm7lJm; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w189si4749774pgd.486.2019.03.04.00.29.00; Mon, 04 Mar 2019 00:29:15 -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; dkim=pass header.i=@kernel.org header.s=default header.b=bYRm7lJm; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727333AbfCDI15 (ORCPT + 99 others); Mon, 4 Mar 2019 03:27:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:52420 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727325AbfCDI1y (ORCPT ); Mon, 4 Mar 2019 03:27:54 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 070FC20823; Mon, 4 Mar 2019 08:27:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551688073; bh=RNe4baonLWuMO5KYV8SbSF73kRxzIolx7gsTF4nxbv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bYRm7lJm9Gkv6LVdfAW8srSB1lG0xWZdqhOff//0Rs+Qjq85+ALKliuVgSZ5u7YGr 6OYndnD9m21n99aeK4Eqlvv1fOZXiGCL+qGE9Z/2u5KmdX5nwhl5jTELinNC/QUJM6 boMYrzFuouohQJvkQCJawBhV6Yz4c7S8wPWtxxSU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dou Liyang , Thomas Gleixner , hpa@zytor.com, Sasha Levin Subject: [PATCH 4.19 01/78] irq/matrix: Split out the CPU selection code into a helper Date: Mon, 4 Mar 2019 09:21:44 +0100 Message-Id: <20190304081625.570790978@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190304081625.508788074@linuxfoundation.org> References: <20190304081625.508788074@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 8ffe4e61c06a48324cfd97f1199bb9838acce2f2 ] Linux finds the CPU which has the lowest vector allocation count to spread out the non managed interrupts across the possible target CPUs, but does not do so for managed interrupts. Split out the CPU selection code into a helper function for reuse. No functional change. Signed-off-by: Dou Liyang Signed-off-by: Thomas Gleixner Cc: hpa@zytor.com Link: https://lkml.kernel.org/r/20180908175838.14450-1-dou_liyang@163.com Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/irq/matrix.c | 65 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 27 deletions(-) --- a/kernel/irq/matrix.c +++ b/kernel/irq/matrix.c @@ -124,6 +124,27 @@ static unsigned int matrix_alloc_area(st return area; } +/* Find the best CPU which has the lowest vector allocation count */ +static unsigned int matrix_find_best_cpu(struct irq_matrix *m, + const struct cpumask *msk) +{ + unsigned int cpu, best_cpu, maxavl = 0; + struct cpumap *cm; + + best_cpu = UINT_MAX; + + for_each_cpu(cpu, msk) { + cm = per_cpu_ptr(m->maps, cpu); + + if (!cm->online || cm->available <= maxavl) + continue; + + best_cpu = cpu; + maxavl = cm->available; + } + return best_cpu; +} + /** * irq_matrix_assign_system - Assign system wide entry in the matrix * @m: Matrix pointer @@ -322,37 +343,27 @@ void irq_matrix_remove_reserved(struct i int irq_matrix_alloc(struct irq_matrix *m, const struct cpumask *msk, bool reserved, unsigned int *mapped_cpu) { - unsigned int cpu, best_cpu, maxavl = 0; + unsigned int cpu, bit; struct cpumap *cm; - unsigned int bit; - best_cpu = UINT_MAX; - for_each_cpu(cpu, msk) { - cm = per_cpu_ptr(m->maps, cpu); - - if (!cm->online || cm->available <= maxavl) - continue; + cpu = matrix_find_best_cpu(m, msk); + if (cpu == UINT_MAX) + return -ENOSPC; - best_cpu = cpu; - maxavl = cm->available; - } + cm = per_cpu_ptr(m->maps, cpu); + bit = matrix_alloc_area(m, cm, 1, false); + if (bit >= m->alloc_end) + return -ENOSPC; + cm->allocated++; + cm->available--; + m->total_allocated++; + m->global_available--; + if (reserved) + m->global_reserved--; + *mapped_cpu = cpu; + trace_irq_matrix_alloc(bit, cpu, m, cm); + return bit; - if (maxavl) { - cm = per_cpu_ptr(m->maps, best_cpu); - bit = matrix_alloc_area(m, cm, 1, false); - if (bit < m->alloc_end) { - cm->allocated++; - cm->available--; - m->total_allocated++; - m->global_available--; - if (reserved) - m->global_reserved--; - *mapped_cpu = best_cpu; - trace_irq_matrix_alloc(bit, best_cpu, m, cm); - return bit; - } - } - return -ENOSPC; } /**