From patchwork Thu Oct 26 10:19:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 13437462 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2BF21C25B48 for ; Thu, 26 Oct 2023 10:20:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=PAf9AvfSG4otQovdhUTvaP6qui1afHVAIeHNNMe1W+k=; b=p1SGI3XsqB7TWA gBMIh1UcCgv9dQWx85c9kQY4TT3zCa7mLoq15px3fCuDlhlTGIu9Z8qkuwfjEQTsXpmLboFNXfZnn kzL4G4vo1XMbIYHO0wm27YNrPssGf2BSXyvlhTBRkP0x5iJlH0ZjLqqJAli7DHhvvYUXPDydSGjSj 11nqYDF4XtyfZ/ZaBaNMJ4wlDFLSZfo1p2X/8sA0WtqVLqzHeG2H1Xn0No6OLWmMBuKqSGvGBr5mJ LRDaEryWmnp+6ofosUlObCxeXL2xBy0f77/qj0e9OAUS8FI+FkfSy5vslNoNmLM2KXM3avG7mxo2x YIiuN1gmaiOOJWBcMAHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qvxTM-00EA2o-29; Thu, 26 Oct 2023 10:20:16 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qvxTK-00EA1S-0b for linux-riscv@lists.infradead.org; Thu, 26 Oct 2023 10:20:15 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id DB1EEB83542; Thu, 26 Oct 2023 10:20:12 +0000 (UTC) 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?b?QmrDtnJuIFTDtnBlbA==?= To: Anup Patel Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231026_032014_501644_231EA839 X-CRM114-Status: GOOD ( 12.87 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Björn Töpel 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örn Töpel --- 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örn --- arch/x86/include/asm/hw_irq.h | 2 -- kernel/irq/matrix.c | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) base-commit: 611da07b89fdd53f140d7b33013f255bf0ed8f34 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 @@ #include -#define IRQ_MATRIX_BITS NR_VECTORS - #ifndef __ASSEMBLY__ #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 -#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[]; }; 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[]; }; #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 = BITS_TO_LONGS(matrix_bits); struct irq_matrix *m; - if (matrix_bits > IRQ_MATRIX_BITS) - return NULL; - - m = kzalloc(sizeof(*m), GFP_KERNEL); + m = kzalloc(struct_size(m, scratch_map, matrix_size * 2), GFP_KERNEL); if (!m) return NULL; + m->system_map = &m->scratch_map[matrix_size]; + m->matrix_bits = matrix_bits; m->alloc_start = alloc_start; m->alloc_end = alloc_end; m->alloc_size = alloc_end - alloc_start; - m->maps = alloc_percpu(*m->maps); + m->maps = __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 = per_cpu_ptr(m->maps, cpu); + + cm->managed_map = &cm->alloc_map[matrix_size]; + } + return m; }