From patchwork Sat Jan 27 16:17:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13534167 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 1C843C46CD2 for ; Sat, 27 Jan 2024 16:24:45 +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:References:In-Reply-To: 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: List-Owner; bh=N+DK40egpEQgjuj3UyZaeFXSXgxOVWiuMWESPJA6+Vs=; b=l6GIJ6P0/rsOsP aTnfOSyVteVhSF7Q9fzcUHScZwOe+9mnZbHCRee0TysV6BnSv81UjXZ61PdPN+Iv4jjbhvOpDk4sJ 4qSHi6cr5YX6UZN9REmpJIZjwezC+0ikn0jMyI+dvRRjKGn1itptVwLkfiRyIzHjStW+zOHsQ83sV WVUGMU4VaPUPfhvjoYCD/RSaSkyIby7DTunIwpwQpjwD+DmsV1uc9plyqn5OFnJz3jKzV1RnsK+lw xgKEnaog+E5kHRU4p0cP97Qv22H9npPBScmk+ZMztjy0UsDnjc+j8sCwUMaXOd42Juv8Xqc4215mr nLTHv46nqs1Z7bPVGMRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTlTs-00000007nyQ-1LnX; Sat, 27 Jan 2024 16:24:32 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTlPQ-00000007l2L-3dab for linux-arm-kernel@lists.infradead.org; Sat, 27 Jan 2024 16:19:59 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2902b0e9524so718042a91.1 for ; Sat, 27 Jan 2024 08:19:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1706372395; x=1706977195; 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=iixTCfUU5lFcxM6PT+INVWxrx22IHRjVu2GHbaK+4QrzNLq3JoTgF2Df78ysrWOR5T aSLRFsOVqhZQTtrbq4cR2n7c5aHjZEB/2K+5YcCMro+Y4LSXyDNN8pQQxNwADpiQdES5 xZN5iNLmNfWN25zodSc7lAN2gunw7x2t+9Y/+4GZpeBujQE8vq/Ta3LozoTfL/TCnKHn HGrZOClzd8BQVCwvkZN00JRNRD9jJnzRGUg+xENkpmTEea+QX114tSs1+/ZrfZ9yFnRM zt8bSlbWWprMqFZwDZTOSQ9mXAs0p4m6wHs/OKVvfuPis9IkncIkC4dX10aIAYfJZCo+ PKAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706372395; x=1706977195; 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=aK3gKmLeJ2mJwCmKJJ1Wm6dkQ04sqsnjeoQoDgyXqgczaaD99L2jSrXm6lY+cVMDcl lH//x1rbhi1sdJgw59PtBxQ4IGb7XJPE2x3f3OIzVMJI6F2mIY/buHaO9uFYplOkEa6H qrct4YoyF+voAQy07PFWQ9l1lWaW56aUDThaJo/8RAhw63XpWpHM7KpS/gjrdQwCgg8h Mp7CKAbAYIDG+xP/7TeVV0zhB22wshCPl62Zu3EG7xN8XZscGOsPMfhEylxNIuSgOIpz TV47t/XE1Ns69Bso1/6uy06utnLFsUc4rGYOZ1yhi3Mne/NY1aFkhRQGAFJMaAB3QuUv TzSg== X-Gm-Message-State: AOJu0YznfQ/pCtjBdGgE+1UDxa64rOaKcbxli1jPl9umk0QF3lWlsXdd itVsZWoIPNnfSE1SpCnb/T09SJRGfAnCl3rnN7HPdHSXwIad7JRSvE8AZKeUn94= X-Google-Smtp-Source: AGHT+IFw60sBjhZzP3OtGpGnPIYlvLc3K10/d07qGX8jMkSQJpYxEHRTdlY+1NIY9ZTwX2uWP8xCuw== X-Received: by 2002:a17:90b:a01:b0:28e:86a3:11f9 with SMTP id gg1-20020a17090b0a0100b0028e86a311f9mr815362pjb.34.1706372395429; Sat, 27 Jan 2024 08:19:55 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([171.76.86.17]) by smtp.gmail.com with ESMTPSA id d11-20020a17090ac24b00b00290f8c708d0sm5091620pjx.57.2024.01.27.08.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 08:19:55 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Conor Dooley Cc: Marc Zyngier , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Atish Patra , Andrew Jones , Sunil V L , Saravana Kannan , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Anup Patel Subject: [PATCH v12 17/25] genirq/matrix: Dynamic bitmap allocation Date: Sat, 27 Jan 2024 21:47:45 +0530 Message-Id: <20240127161753.114685-18-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240127161753.114685-1-apatel@ventanamicro.com> References: <20240127161753.114685-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240127_081957_194903_4FD5E235 X-CRM114-Status: GOOD ( 14.90 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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; }