From nobody Wed Dec 17 09:50:02 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 917B0C25B6B for ; Thu, 26 Oct 2023 10:20:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235061AbjJZKUe (ORCPT ); Thu, 26 Oct 2023 06:20:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235029AbjJZKUU (ORCPT ); Thu, 26 Oct 2023 06:20:20 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E233D6F for ; Thu, 26 Oct 2023 03:20:11 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4116C433C8; Thu, 26 Oct 2023 10:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698315611; bh=HTgDnY6nOK0UE+C53lOyr46cNkU6RAJxBArDMZcQUKU=; h=From:To:Cc:Subject:Date:From; b=qEKGSub5Z8oLBiMI2J2SXGHlKosMfJIrdE7oOGvTW868BjkOGFtbdWjJL86QAidw5 mhTFMJTTrBo8LxwDa5KjbPWRd78e3xrmv9+DMSIC82qXgtq8qjeA84mkoOlbKyCoMW Fx+WWkmhglTC3EsALOLaBZy5vAEviAgKF6yIXf7Xjr3NuMJdRgKWKghkpqJNbS3FBd XRSxLTYa+qznnJyM0fSt+bUalLwCloCTdAhF7dJxtDDOguVTcqwMrJUlVZFOoKT3Hp 273IYM2XKujF1fLy/lNsTa0THgh7H6OpcF18Y25wgQE6jSUTU8saXaWUaacaJn3CYL FYxJcHFl7bLPw== From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= To: Anup Patel Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org Subject: [RFC PATCH] genirq/matrix: Dynamic bitmap allocation Date: Thu, 26 Oct 2023 12:19:57 +0200 Message-Id: <20231026101957.320572-1-bjorn@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bj=C3=B6rn T=C3=B6pel Some (future) users of the irq matrix allocator, do not know the size of the matrix bitmaps at compile time. To avoid wasting memory on unnecessary large bitmaps, size the bitmap at matrix allocation time. Signed-off-by: Bj=C3=B6rn T=C3=B6pel --- Here's a cleaned up, boot tested, proper patch. Thomas, this is just FYI/RFC. This change would only make sense, if the RISC-V AIA series starts using the IRQ matrix allocator. Bj=C3=B6rn --- arch/x86/include/asm/hw_irq.h | 2 -- kernel/irq/matrix.c | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h index 551829884734..dcfaa3812306 100644 --- a/arch/x86/include/asm/hw_irq.h +++ b/arch/x86/include/asm/hw_irq.h @@ -16,8 +16,6 @@ =20 #include =20 -#define IRQ_MATRIX_BITS NR_VECTORS - #ifndef __ASSEMBLY__ =20 #include diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c index 1698e77645ac..996cbb46d654 100644 --- a/kernel/irq/matrix.c +++ b/kernel/irq/matrix.c @@ -8,8 +8,6 @@ #include #include =20 -#define IRQ_MATRIX_SIZE (BITS_TO_LONGS(IRQ_MATRIX_BITS)) - struct cpumap { unsigned int available; unsigned int allocated; @@ -17,8 +15,8 @@ struct cpumap { unsigned int managed_allocated; bool initialized; bool online; - unsigned long alloc_map[IRQ_MATRIX_SIZE]; - unsigned long managed_map[IRQ_MATRIX_SIZE]; + unsigned long *managed_map; + unsigned long alloc_map[]; }; =20 struct irq_matrix { @@ -32,8 +30,8 @@ struct irq_matrix { unsigned int total_allocated; unsigned int online_maps; struct cpumap __percpu *maps; - unsigned long scratch_map[IRQ_MATRIX_SIZE]; - unsigned long system_map[IRQ_MATRIX_SIZE]; + unsigned long *system_map; + unsigned long scratch_map[]; }; =20 #define CREATE_TRACE_POINTS @@ -50,24 +48,32 @@ __init struct irq_matrix *irq_alloc_matrix(unsigned int= matrix_bits, unsigned int alloc_start, unsigned int alloc_end) { + unsigned int cpu, matrix_size =3D BITS_TO_LONGS(matrix_bits); struct irq_matrix *m; =20 - if (matrix_bits > IRQ_MATRIX_BITS) - return NULL; - - m =3D kzalloc(sizeof(*m), GFP_KERNEL); + m =3D kzalloc(struct_size(m, scratch_map, matrix_size * 2), GFP_KERNEL); if (!m) return NULL; =20 + m->system_map =3D &m->scratch_map[matrix_size]; + m->matrix_bits =3D matrix_bits; m->alloc_start =3D alloc_start; m->alloc_end =3D alloc_end; m->alloc_size =3D alloc_end - alloc_start; - m->maps =3D alloc_percpu(*m->maps); + m->maps =3D __alloc_percpu(struct_size(m->maps, alloc_map, matrix_size * = 2), + __alignof__(*m->maps)); if (!m->maps) { kfree(m); return NULL; } + + for_each_possible_cpu(cpu) { + struct cpumap *cm =3D per_cpu_ptr(m->maps, cpu); + + cm->managed_map =3D &cm->alloc_map[matrix_size]; + } + return m; } =20 base-commit: 611da07b89fdd53f140d7b33013f255bf0ed8f34 --=20 2.40.1