Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1546394rdb; Mon, 19 Feb 2024 22:09:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWiHexuuXJBOtoPrH8aeZlByjft7jSKskR/9BbwrduWIa7N1xBLJmeOPcH1Zm5pR0yxFOXUF0oGKIeW/gjLS9LkPzte96unoEjhplrCuA== X-Google-Smtp-Source: AGHT+IGhNZ/hvOb5F43CNVqbmhLbOUBWNPgPSKnR9Yy88wSpkdH87JPLYtiL463B+BXwsxz7dS2I X-Received: by 2002:a05:6a20:4c1b:b0:19e:b196:ddb7 with SMTP id fm27-20020a056a204c1b00b0019eb196ddb7mr10569977pzb.15.1708409346024; Mon, 19 Feb 2024 22:09:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708409346; cv=pass; d=google.com; s=arc-20160816; b=VvGXtIbGjih0azndeL4vIfibvSlCGFNPt2gYa4f64y/5Jyc0p9KI+HHvkaTC94AW0+ P7L/Lb7nQ5I22gH7tjGPsCX7A5RiELuUejQBvZmO2yuHlq8VNoMQg5/Jpqrqpxup/Onl 7V2+w/aKYueLHEJK/wYx+2Tf+n4oRmT/51TrNZQFwg7GJcwNC1iVq5nUz0GCqLhouqYw m/yrycUJG7nEct5zppVvsDvGObmSBm3KA7OkHN7hMrPcO6um1x6aLYzRqRe61GAb/XTm x8CzvB3rncv4hLzbhY3TDw3T4Vin0LImE8hu4k4qo3sPfG9g54ABNEUwfBO+XdimHiPl a1ew== 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=NdhNu/tt1pg3ocOm6JquWsdD3K5/mNnKFNFnfKYX8G8=; b=aK9cFqGjHBbBD86L57CatguiGC30M84ibFa/6WGbu+cpYdYx+Bor3Ptq20Ud5CnBv6 G7ZhQ8VPxxng1ZEim6iWptorbUEKrvevivy8mnmTEbj56mCIE3f/rDho1KV8yVsuVyJe GbqjS9OUZrOaTxQwpv6zMCivzq80Pp6p9C82Cx6VOMnPeOFftPTbCRZvX7OlnYBYRFPp jpyKejzSd1Ve1OEKkU3Cor+JDcUy3PcfPaVwTaRDpGA3Oa/+KEIkHRJwxIirJrCY6Nqg AkBqugN52niCKweUoQsTHAdkDptzkAuuOfF1JeNQtEv2uAj+B7qOxUPEu9P7sJLe+Ojl wHuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=aPqJCBdc; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-72380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72380-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id c8-20020a17090ad90800b002993c623005si5663256pjv.127.2024.02.19.22.09.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 22:09:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=aPqJCBdc; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-72380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72380-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C049FB22A7A for ; Tue, 20 Feb 2024 06:09:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 752C359B43; Tue, 20 Feb 2024 06:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="aPqJCBdc" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 1820659173 for ; Tue, 20 Feb 2024 06:08:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708409298; cv=none; b=PLGmhh9n8+2eNFVAkaf/04w2PCXekTJ9mVCY5jmNDnzEIkfxe92eei5W4yp6D5imJ90d9YXHlLtKaYq1V2B+z65GI4PB2shQ9tdJdeukpCTXT6SSlb9E4yTDFqtTZuDB2NlqEE0HXOBjBl1zbtr+aRs0RF98/bDACVB8eESi9yw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708409298; c=relaxed/simple; bh=v7MGRVtZtPXfGkmyqYWN6Y63LLsHhhJ5iWWU9xTfhDY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=kjpByJhQYbZMEKlcsMnj2NVZZioKfL8TcxEMhLuNEbNEUk7uOJmMrcSnT+absKq4C83nOlyBKM6raifCosujSTlJGfaZXK9hgBowNV4bZ5LRZB/wvkkGVXqdk60YT9vqXK1Exca/Z2mQDnXZ2JnLyXAY6LRynZAmfxGO5KIl7CA= 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=aPqJCBdc; arc=none smtp.client-ip=209.85.214.171 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-pl1-f171.google.com with SMTP id d9443c01a7336-1d7232dcb3eso27198745ad.2 for ; Mon, 19 Feb 2024 22:08:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708409296; x=1709014096; 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=aPqJCBdcguj+QRV4/8xux4H71k2JcnCkg5WcnCVabn4aemZ/VLzcnb+Ows6/pAMOm9 MEFIXo/d5dOURfIn8uLgIL4dzq9AszhBy9MF0BfE8r24BZ+xaAkPZtyrP2XcMl3ducAs Q8JSiDBFf1uakZgJTUltK7JdFn23Wli7Ch66deirIqZWtNVUosiigJl9jayH0knyLDUt r/yzfJmlV7Sy7COHIl/erle9ILw7q0lb5BZ4JB5qGErxHyqII1RZqox3Y0vUSxpjIvQ0 BGeZhymC8whTvqcdYG+0jiGII/c5FoMk1zVSkkjWkqcsXSi6zihkvpuPCD3zVFG9P0Pc BThg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708409296; x=1709014096; 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=SjyrIuXDdKTBY7K08t41xDR42vUkRCD4qXMcwQScDELFqQ9OuanGn4gdt49FFvmKm8 Nj2jvtkdeFAOPMFp6f/43h6QkHCRqtvZg46a94WLBx7SBn+FrWtQ5HGbXaZuhqt2gjaS aWzj87ryBrHFfyXeKpxKfuOrhX39uy7eHXEbksc2p1cHNbfB9JQ3TKzkR/xAgKfmuMZr 9B07Xl0+L/bfF0npy3J8HNT+nGTCGeK1AHED34iwspXJjTobaRJmYXd83uRu1Jug7s8A MXwOknEms8HupndsXHFnNdHNpuBNntYP7Fv6kqFEqYEoaTRDgm98mBOECF4D9yOAx1yp QSyQ== X-Forwarded-Encrypted: i=1; AJvYcCX/Z9N1CvoJMjEp8XS+QlrN1+/ymRigpVL1LzwG+C6Mv6Rbm3FwWZLVk8AMQHCoNkajYS5Ct82uWjm6MSDeZ6c4O6x1r/FYKbzGbtxz X-Gm-Message-State: AOJu0Yw6/NbzvsIl8A7vtJ8kii3DF2LOHIduM6eDklnYnlXeT+oCWd6t Syxn5fIDAayLeVjUVH3uuaZuT3FryZhiVhKoyb9K5Y6uVthkoZnUbM1OUzRTOKw= X-Received: by 2002:a17:902:cf0e:b0:1db:a164:3e50 with SMTP id i14-20020a170902cf0e00b001dba1643e50mr13726229plg.40.1708409296360; Mon, 19 Feb 2024 22:08:16 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([171.76.80.86]) by smtp.gmail.com with ESMTPSA id j6-20020a17090276c600b001db4c89aea5sm5368114plt.158.2024.02.19.22.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 22:08:15 -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 v13 05/13] genirq/matrix: Dynamic bitmap allocation Date: Tue, 20 Feb 2024 11:37:10 +0530 Message-Id: <20240220060718.823229-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220060718.823229-1-apatel@ventanamicro.com> References: <20240220060718.823229-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