Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp335275rdb; Sat, 27 Jan 2024 08:23:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNSlcS+oCPzVnk//0fkK+Q4G55kCvqkGfF8jF653LWDAIi7XK/iQc4TgztV8Q1J+6M6FDp X-Received: by 2002:a17:906:54d:b0:a30:cf8d:8c27 with SMTP id k13-20020a170906054d00b00a30cf8d8c27mr1287155eja.68.1706372617883; Sat, 27 Jan 2024 08:23:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706372617; cv=pass; d=google.com; s=arc-20160816; b=wa9hKui4e2qR7nA4bApYDrjmGn0NI57+z/+c1eQWid3ja6ZMzBayhod4H7t683enja t174bx5xQneiqEw0wBHx2Tl+TsBJA8i9y5MyCPzuyvS/XcynZPvB3aSvdmmsktjRdd8a s4K8BbVEimwNg9HP/Ukh8KgWlSDHo6iStWsapuPv4/SEthsXp2PDpbVI9sslqPngOZgX YsPEihLwZq7+vVSB/ci51Wg6d15+aSY5H8/g6+YWd97jlWUfxoPPzBvz/GAkCQxo9JPx eswIwQCDtL6jCEXTPyD3z0KzkRKaxh08J6kd4f6UrYtfb3kDeFBynY7EZBMm8kiCg2iG fQSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=104PBPP87dGRJ1dWRj3TJVt38h0tClUYGYzJ0Qy5+KM=; fh=VZMBJy1ItAStxvnABCC9aX2CbehCcfUrTxCPs4KgTF4=; b=O97KamU6HJbEXaLDEJSBgfomtvNt2E0c6SlEHJ9Tlb9TzThkKayoCREJ0Ebs9Mh2DW tc2RALPKcAiyDTqEx6v4MbRuf9Qz8Q3dF6swrC5xR3bYQrhdHlvG15lXrYTh5sqPdjFH nNltnArLZxmoNNaIHA1G3KwXcn+is7fovzDezJdCD2DlCj5+rJ+qT4kIRjOcj491Ws7i AKHaolSfrnpv79zHgQfpX0QrU0fhq+1wt4Rjdb8CBa4hVEGk2Kf1yFdjzFSwSQv1083L G5aGKztEnjZGVYtW3L47KyBI8vigDWvhwgxcrXihQr+wWkXp7xsasA1wy0xWBPmdnegK buVA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=jN2ttUfJ; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-41291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41291-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id hj12-20020a170906874c00b00a2eb027b083si1727835ejb.798.2024.01.27.08.23.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 08:23:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=jN2ttUfJ; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-41291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41291-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 77CE61F2329B for ; Sat, 27 Jan 2024 16:23:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 831575C8F4; Sat, 27 Jan 2024 16:19:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="jN2ttUfJ" Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 576EC5D747 for ; Sat, 27 Jan 2024 16:19:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706372397; cv=none; b=LPjPuVBTFSEOk2yPpUkjH4XtEh0hJVwQvZgGunbfWRgFx3ykjITfW00/lyd+79zVXEgS0Qa+EfDbehonloc2jROZyK+U8XM7em6A0Sgbe+qMLZ17B+/LNub/mFsozFVq0s7nA7Dn9QHoJHL2ec5GNqlbg2zbxllNl/mkvu0anJ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706372397; c=relaxed/simple; bh=v7MGRVtZtPXfGkmyqYWN6Y63LLsHhhJ5iWWU9xTfhDY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=m1DamaYde4/2QKWPatVyWkO29PHciU3mS3cgMduuJ1+hvyAipCbbfJmdcaIBFM8vNmsfcusZxKS0MsK8HVYqQgghZ2rkkcP4/7UfGC8k2QdrFpXd6aTEmG2ZCaq/kL5P3lwc1cSEvj8f8e4uuYotkC+02vLw58tIWJ65ngbm3BI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=jN2ttUfJ; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2906fd62cb2so689611a91.2 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=vger.kernel.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=jN2ttUfJUBzfZjgVodEnThF8xCifBFgPOKFgoV56WDBsmTNIWW2J5c/X/RfW4tYi7q r2Qbdjt3DzeIBdI/6qO3Dgg++Xyry7e9b/7Uz9+vQncEuRVI/+v3uGqV4Ix6RjU3GD1O oAIMfPra2kBp6yPgIo+/+pV94KTdp28xFhiCE4X6EbbFOvyg0Rj+54gVht3X8c1nHe3G BXQ5JbYNcs/u6bE5mMrcZbXTXoxWBDKAno9uAn+oRREFYcTW1WgKSxZfP2RI+hvUPEN5 oTDzGG+HL9LzbauBuHQ8Quyr8oEwj5VHvOSMSI5KhcxI0Yf71DuvUlGKDeHzsl+IMOuB yf8Q== 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=on2JZOI5qzJKI1jUgC2KihymPgbpiZsJRQl4bIC68Glr/BY96qNVO+z0EbVwseazfk kVl14HWBFbEc4wTEGuc+gXu3x2IT3LX0LXkDbCVZsuTVFHBl9qjgM98TuUyMfHQe5tT6 PsKbv6NhULq94ymJmBoqcXjADJlDATNSEg8uZd7LV8HDnzHVk+asspw7uFMz5RhWCqpl NqwLHV+piVWNWZW/ZTeYL2B1C3bXvVwv8zO29cFi6/o2XkrR67AsQJkDEpXv9HuJLGSu iwOL0sYl+4gcOeEogTipRmtN+8CyjcWggWyAHRf/JzIEaM8Z4xHfMow5GFqZo9AuU5YK 3+8Q== X-Gm-Message-State: AOJu0Yz6uIcXTEjnPpTwCoVQEURLilMoCGBymmlEopdEm2Vuqh9lzy8L YLDbeLsVxc88p8alvprYHQUZhP//08pRBJRkSebZdW4hxNRoOm/dMVsQPcbmfuw= 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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; } -- 2.34.1