From patchwork Thu Feb 22 09:39:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13566975 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 B476CC48BEB for ; Thu, 22 Feb 2024 09:42:49 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DRVKmNXQtuttePU/d6O8DS+1ywrf2lndXa2QIQd5Roc=; b=X6UdVPEz4jLFLR h0fj7p96LJ8+ItYtvSXoybOm6HaYTW/CWQEemDze5CtFaga5rlOEVl5g2A3jQr2s5+UtThuPbMuGP ELfENBkkOfAjECIYEj8aS6/QlMsQ1eut7QI/ZrDP8HxjvslxdxRVBh83oDcOxIsrTVglZeqczVLQo BXi5jqxxBxWbRWJpX+DOkufhgr8RhVZbiYSy3tlmg7eeXC6qOlJo1NHzw7LgbKANKHoyb1Zr16YxA zNPVoVSvy7d52gXlsaZLj2sc5n/MBAWfOLREbaNBNwnwCfoxuUT9oWLgKeGFVBCSHK4e9xDdVHhXD rQ2uZC2NyR+rI9KvXfbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd5bH-00000004JXt-4A4W; Thu, 22 Feb 2024 09:42:44 +0000 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd5aF-00000004Iey-0laE for linux-riscv@lists.infradead.org; Thu, 22 Feb 2024 09:41:44 +0000 Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3c0d59a219dso4682870b6e.0 for ; Thu, 22 Feb 2024 01:41:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708594897; x=1709199697; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=104PBPP87dGRJ1dWRj3TJVt38h0tClUYGYzJ0Qy5+KM=; b=GiGSpJB4LK4bxGlRzFmiftaK2M+X20BNnqOcouWh233Dj/HJ5EirCOkJDV5uPB0kr2 6khKuDwqwUP2z+jYJDOwQ8uuPUdP/CxAfZbnNp0+ucwfmWbCbyFJHdCIUGEQzgiMOPgy F+CqVWilu9fbwK34E8DYwUGhvTBkRNihGMAT6aVDRpWnCB3FCIHsxqCMX2N3WJl3wz6O QidilEspMKAjz/QBOQC8iMNuIMyaRoaIADVkT7TN/jtbGO9leNL25FagqeWTpw277AD5 nZDesVzYjVst1V/X7JmDnqimx4iUjwYtqX7Cf0fuJfqT6SsEW7Z8CaT3QbHcDInHsQBY G7MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708594897; x=1709199697; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=104PBPP87dGRJ1dWRj3TJVt38h0tClUYGYzJ0Qy5+KM=; b=eAEkCmPx1Hfe2ZvG/64BaSqgN9QZITcSGh3UX5p6Skut+nJiCCwCas5YmG+28ZAYxE tGnPlLyFpbFL40qv3VTKYBbxyoF6uyD42IGR4DBvVZDWc/oN4J+plNpsezTtJYsNNXXD yrCqN8Y39t1nLGYWdQ8ZsfIsCERiyx6t4eX2DwgXZyuuzu0SPWfIQj4S1MHNDy4hfsgu t9lmBZSxiFmF1RRB83rjwIZMtZs6pb8irrDL9vxUQO9Bav3B8zlcclbpCITJwBuGz7l1 N25YV8IqoCkhGXKtuGwlrojN0gT/2QF6n6sdnE0KdCaGpLYp40vfWp/5heSE7uCI0EtX FbqQ== X-Forwarded-Encrypted: i=1; AJvYcCVRymVtaUlkjfefHzWFWPjaQy1AzdxqnO5rdLZkr6yNi2ly5CnlB/vRbg+EixsrtzNY/N/np7f6WJntsOuu3Ed8PCKU5UCVhoQc+Jkp/yPW X-Gm-Message-State: AOJu0YzmPjFFpV3+18ULakmyDDPYY1fRH/Kh3jzRtIa7OlKqUxB+cfM5 qQWHrnaAK1bK5jlns/2YxeRa6cWAqvyzDcQ+MbbY0uVTW9RS5dzrIU92bZFQG3XtmSHffQasP6c D+OU= X-Google-Smtp-Source: AGHT+IG88khSq1/PCKAmx/cLM4tzht00nwLDSagx3gre/CG1DcDTTQJYSGtnn3JbDviLDEoBKv0D4Q== X-Received: by 2002:a05:6808:118b:b0:3c1:59ea:1b9b with SMTP id j11-20020a056808118b00b003c159ea1b9bmr11802239oil.50.1708594897585; Thu, 22 Feb 2024 01:41:37 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n15-20020a05680803af00b003c17c2b8d09sm130699oie.31.2024.02.22.01.41.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 01:41:37 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Conor Dooley Subject: [PATCH v14 10/18] genirq/matrix: Dynamic bitmap allocation Date: Thu, 22 Feb 2024 15:09:58 +0530 Message-Id: <20240222094006.1030709-11-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222094006.1030709-1-apatel@ventanamicro.com> References: <20240222094006.1030709-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240222_014139_530616_7BB1A56B X-CRM114-Status: GOOD ( 13.78 ) 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: , Cc: Anup Patel , devicetree@vger.kernel.org, Saravana Kannan , Marc Zyngier , Anup Patel , linux-kernel@vger.kernel.org, =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?QmrDtnJu?= =?utf-8?b?IFTDtnBlbA==?= , Atish Patra , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Andrew Jones 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 Signed-off-by: Anup Patel --- 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 b02c3cd3c0f6..edebf1020e04 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 75d0ae490e29..8f222d1cccec 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; }