From patchwork Mon Apr 10 15:57:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 81553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2001977vqo; Mon, 10 Apr 2023 09:17:49 -0700 (PDT) X-Google-Smtp-Source: AKy350aV1zIhEm1qozGvy1TrvzWWw4uSDJ0hGx0pg3S/NgUmbtkHRwVQYJ/nPGsbujIuXg5wHxOf X-Received: by 2002:a17:903:1111:b0:1a4:f295:32fa with SMTP id n17-20020a170903111100b001a4f29532famr14790371plh.15.1681143468802; Mon, 10 Apr 2023 09:17:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681143468; cv=pass; d=google.com; s=arc-20160816; b=rsf8x7QstYpXRpMcbUj2d34G7aTl7K008cSzDo5j6/+TgqTAMvnaXyhowSQXVnMwKH sITyto8F4Wfm5fg0xpVo+9DS/GN8tYm/s2Kb0lzeajtM0UbT2kvXWldGxtg7I76hEYPk vrEPR2bfBwadmsLFe+kbLAosM1gH//RLIRYI00MWx5fXU/mHwccMlQyT1UPPvpyeV+xg oixs5Gy97BXRGgmTD42t3L0vMgjyyVRAwUA8VjXXXukGjfGRucdyOxKXY7LqszyQvXKc OcLMWJ/V0ckHcrH2Iljko/yRZYLVwktDNtqt3h5c+n5oyseHvLkKZJE0npRG09+0+AYh B6dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PH2FJ3ygWRVmXHPyWjnyKBW3RGtReAKw2JojLX8VxJo=; b=GFMPNDpKCRVx5VktohZNn1phXzI8xDQo6WaSdg0arqqnV8KS8h6jDixE73xIvatcPx OxHelsSq3XGXMk+JOjcHMcVL1ShBxKCIFMmjfnGH7IfNyMIrLi9a63lDG7+ELaJJ8fnl I4lurweJZfbktqf0kE9yfxGnvWQ8zvxm7dxtYFywsfO2RvhvfyCSBg/ivFwtwqzYwd+l Atcr0X2ZzhZXGsaWqL4VRiPcsVYvlE8zMfx75Y6pU0p+4T+LKA5uoDKfY5dIhLHDKM2T 4ScHmJaKXp2F6G1mIBz8l9RQBeCnFtXw6tgAiU2LZcaXRg9noXe9nbuHUxSQohkSP0f5 stlw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=KYzheKwC; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y15-20020a63494f000000b005138c1f1fccsi10597687pgk.31.2023.04.10.09.17.35; Mon, 10 Apr 2023 09:17:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=KYzheKwC; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230053AbjDJP5h (ORCPT + 99 others); Mon, 10 Apr 2023 11:57:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbjDJP5d (ORCPT ); Mon, 10 Apr 2023 11:57:33 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2063.outbound.protection.outlook.com [40.107.100.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F32F171C for ; Mon, 10 Apr 2023 08:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lNL590l8fj9U20A+OUSMPvoGuBicY9cOdyjr3mBO8TIxfKbYJ6ddTmBvxLtIYaQihPynNl6ZnJr4ZWh/VIQmso01rZFKLo2M9fQr/VpB2ItyArIbtBrUCuVmSZineaFwy47IOVJarJ/5WcUUhu/9bRjZFGys88AsSHIitSBb+YntoIC01NQ67lpIHAqmnd3qd053rhogJ264xkIXj+FPCI4d7VCnPNUAfEazqyl4TfXYZjPD7RFsS3ZuHJc6CAX+mrNSulUF+w9v0/EEDcKfXkgFssnIvUgpYSbt76wHyQpX3UgE6eS1JKRGJIMCsw5wvCgD/r6A22SWcPeoTR6QXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PH2FJ3ygWRVmXHPyWjnyKBW3RGtReAKw2JojLX8VxJo=; b=OXHo1b3f9YfAaj0jxzk15e48Keky5q6lJ1va+tPEGtT/A15kYprRruAy+EIIgXKUpVu0nWZlxqHLmbdLuueutIIlC1vwDgBbWyIQ9arGAhEdgFcPDJnHnf5g5i5FnLXYREzsJymJY7VXnM9WVNQP6HqE3PIV27xB59EwBpdpKuoCW8krbmKClhlhDvwpS+HtWwKHRZCMJXTJq3XE/ZaCMy9jRsypSxFTHzzzM0xTxG1bjBJ9TRhpEs6Ov8WWmF1QqbFKsbMyeXu3cAO2rdzszvd0gcby5f7kwYbD/OGfKEBnAAp0pwnIB+BKggc7fjiQLLTAGDpqUjWsOOXThGJY7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=linutronix.de smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PH2FJ3ygWRVmXHPyWjnyKBW3RGtReAKw2JojLX8VxJo=; b=KYzheKwCyUv9nx/8DReoXlin2yxC88fVOVwh1RUT2a83MeHwdAj2YIM9paGDsAoLAh/3mbw8zI6W+1G+yluGta+rhGt/C0ysvpOzEvbZXPPXlrQOEotzLlnJfp2raQDqdd4QLaL3YEfwAdtFs8JZLJCvVx6OSJ4EB/2v1OkYbf1NA4VVqq0NU/FNvoSXYLwhOP8SSV1C0mG+6bHr6Y/YjMxsXCfadyNPgn45ny2RuAjrlP8vxfxDEO4Tut2tfL8MuMEFKzm+4DdC7/taVJAbNOSbA15U6UEeqYFeHkXoSIUlZtTTtqXS4tshjGxZrID81uiNfHvrm7hA9lA3XKUFtA== Received: from DS7P222CA0008.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::29) by PH7PR12MB8039.namprd12.prod.outlook.com (2603:10b6:510:26a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Mon, 10 Apr 2023 15:57:28 +0000 Received: from DM6NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::b2) by DS7P222CA0008.outlook.office365.com (2603:10b6:8:2e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.39 via Frontend Transport; Mon, 10 Apr 2023 15:57:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DM6NAM11FT056.mail.protection.outlook.com (10.13.173.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.27 via Frontend Transport; Mon, 10 Apr 2023 15:57:27 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Mon, 10 Apr 2023 08:57:24 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 10 Apr 2023 08:57:24 -0700 Received: from SDONTHINENI-DESKTOP.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 10 Apr 2023 08:57:24 -0700 From: Shanker Donthineni To: Thomas Gleixner , Marc Zyngier CC: Sebastian Andrzej Siewior , Michael Walle , Shanker Donthineni , , Vikram Sethi Subject: [PATCH v3 1/3] genirq: Use hlist for managing resend handlers Date: Mon, 10 Apr 2023 10:57:19 -0500 Message-ID: <20230410155721.3720991-2-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230410155721.3720991-1-sdonthineni@nvidia.com> References: <20230410155721.3720991-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT056:EE_|PH7PR12MB8039:EE_ X-MS-Office365-Filtering-Correlation-Id: c04ef78d-6e44-4aa1-f46e-08db39dc48d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QRlHh+bKWj+gmQkOQOX8u9Dd9GRAB35qhNb6cRAafB7sYMe3D7b2NYWhkYQly3bC42THQ0q3EHbBjVPYdpF2MqdRyMK0GaYqXLmlZu7N4mLh8ZzwfuUmuPSSnCKat/nfJ7qw6io6rlltnmr7Y1SJGeNczxp2HKjU6JeVeCLkVv304AM8KX4mojcidpzx+h74LizAKBFO6tCvCJYdxxFcukBlzMAqm6O3+3AdNF9XtnKiUB2la2N+FZBS+STCHEgc/Y0eSgMW6ZO+PFtAdSIiYNzvHZVoqcHE1/XiMjWZLjgJlQFzCzhC7g6HVPOHdVkweN5ZC4VD56mzhmoWfpF2cf9Jnn3hSDZvmvebks/kvsFTiJT1tn3adxsmJ3TVXuy3tKDkQBjXfCGxzl7rIWJys3s90vifAiDM8TVkenEHz51lLx8f6m1uUuQaXblVcTROGtn15HrhwvVROt590GIUsmflHfvNdbN3Ur1pef78wQOQrjURlla4ebV2BUlPdgZP8NhhMF4zT/JwiCYx7dp0eTBlAEjkTTQ/gw4Y3n6L4zJuzaWuxSj/RJFRaP8RVT7ifZWsgvpzfEr4V+Tl7V/Xa+T7WkGr5ZzyoNCxg2xNrRb+AYKPJ7BZw3Vd+SVO6CXmHDxMR8yjCcoxTNEM4YrMJDnOwYGOZOHsYeBDtC7YLvOJX9hWAbkCSww4hDu3QIp8JPj1oCtuEFg6Z42un8TxPYFtWu0k4fkC2IjfX9Lf25+TSW08A77Yy4HjPzHvlbEw X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(346002)(396003)(376002)(136003)(451199021)(40470700004)(46966006)(36840700001)(316002)(110136005)(82310400005)(54906003)(356005)(7636003)(36860700001)(82740400003)(70586007)(8676002)(70206006)(86362001)(478600001)(4326008)(83380400001)(336012)(426003)(47076005)(2616005)(186003)(41300700001)(36756003)(2906002)(1076003)(26005)(7696005)(66899021)(40460700003)(40480700001)(8936002)(6666004)(107886003)(5660300002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2023 15:57:27.9482 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c04ef78d-6e44-4aa1-f46e-08db39dc48d9 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8039 X-Spam-Status: No, score=0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762806693858291939?= X-GMAIL-MSGID: =?utf-8?q?1762806693858291939?= The current implementation utilizes a bitmap for managing IRQ resend handlers, which is allocated based on the SPARSE_IRQ/NR_IRQS macros. However, this method may not efficiently utilize memory during runtime, particularly when IRQ_BITMAP_BITS is large. Address this issue by using the hlist to manage IRQ resend handlers instead of relying on a static bitmap memory allocation. Additionally, a new function, clear_irq_resend(), is introduced and called from irq_shutdown to ensure a graceful teardown of the interrupt. Signed-off-by: Shanker Donthineni --- include/linux/irqdesc.h | 3 +++ kernel/irq/chip.c | 1 + kernel/irq/internals.h | 2 ++ kernel/irq/irqdesc.c | 2 ++ kernel/irq/resend.c | 47 ++++++++++++++++++++++++++--------------- 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h index 844a8e30e6de..d9451d456a73 100644 --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h @@ -102,6 +102,9 @@ struct irq_desc { int parent_irq; struct module *owner; const char *name; +#ifdef CONFIG_HARDIRQS_SW_RESEND + struct hlist_node resend_node; +#endif } ____cacheline_internodealigned_in_smp; #ifdef CONFIG_SPARSE_IRQ diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index 49e7bc871fec..2eac5532c3c8 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -306,6 +306,7 @@ static void __irq_disable(struct irq_desc *desc, bool mask); void irq_shutdown(struct irq_desc *desc) { if (irqd_is_started(&desc->irq_data)) { + clear_irq_resend(desc); desc->depth = 1; if (desc->irq_data.chip->irq_shutdown) { desc->irq_data.chip->irq_shutdown(&desc->irq_data); diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index 5fdc0b557579..51fc8c497c22 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -113,6 +113,8 @@ irqreturn_t handle_irq_event(struct irq_desc *desc); /* Resending of interrupts :*/ int check_irq_resend(struct irq_desc *desc, bool inject); +void clear_irq_resend(struct irq_desc *desc); +void irq_resend_init(struct irq_desc *desc); bool irq_wait_for_poll(struct irq_desc *desc); void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action); diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 240e145e969f..b401b89b226a 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -415,6 +415,7 @@ static struct irq_desc *alloc_desc(int irq, int node, unsigned int flags, desc_set_defaults(irq, desc, node, affinity, owner); irqd_set(&desc->irq_data, flags); kobject_init(&desc->kobj, &irq_kobj_type); + irq_resend_init(desc); return desc; @@ -581,6 +582,7 @@ int __init early_irq_init(void) mutex_init(&desc[i].request_mutex); init_waitqueue_head(&desc[i].wait_for_threads); desc_set_defaults(i, &desc[i], node, NULL, NULL); + irq_resend_init(desc); } return arch_early_irq_init(); } diff --git a/kernel/irq/resend.c b/kernel/irq/resend.c index 0c46e9fe3a89..edec335c0a7a 100644 --- a/kernel/irq/resend.c +++ b/kernel/irq/resend.c @@ -21,8 +21,9 @@ #ifdef CONFIG_HARDIRQS_SW_RESEND -/* Bitmap to handle software resend of interrupts: */ -static DECLARE_BITMAP(irqs_resend, IRQ_BITMAP_BITS); +/* hlist_head to handle software resend of interrupts: */ +static HLIST_HEAD(irq_resend_list); +static DEFINE_RAW_SPINLOCK(irq_resend_lock); /* * Run software resends of IRQ's @@ -30,18 +31,17 @@ static DECLARE_BITMAP(irqs_resend, IRQ_BITMAP_BITS); static void resend_irqs(struct tasklet_struct *unused) { struct irq_desc *desc; - int irq; - - while (!bitmap_empty(irqs_resend, nr_irqs)) { - irq = find_first_bit(irqs_resend, nr_irqs); - clear_bit(irq, irqs_resend); - desc = irq_to_desc(irq); - if (!desc) - continue; - local_irq_disable(); + + raw_spin_lock_irq(&irq_resend_lock); + while (!hlist_empty(&irq_resend_list)) { + desc = hlist_entry(irq_resend_list.first, struct irq_desc, + resend_node); + hlist_del_init(&desc->resend_node); + raw_spin_unlock(&irq_resend_lock); desc->handle_irq(desc); - local_irq_enable(); + raw_spin_lock(&irq_resend_lock); } + raw_spin_unlock_irq(&irq_resend_lock); } /* Tasklet to handle resend: */ @@ -49,8 +49,6 @@ static DECLARE_TASKLET(resend_tasklet, resend_irqs); static int irq_sw_resend(struct irq_desc *desc) { - unsigned int irq = irq_desc_get_irq(desc); - /* * Validate whether this interrupt can be safely injected from * non interrupt context @@ -70,16 +68,31 @@ static int irq_sw_resend(struct irq_desc *desc) */ if (!desc->parent_irq) return -EINVAL; - irq = desc->parent_irq; } - /* Set it pending and activate the softirq: */ - set_bit(irq, irqs_resend); + /* Add to resend_list and activate the softirq: */ + raw_spin_lock(&irq_resend_lock); + hlist_add_head(&desc->resend_node, &irq_resend_list); + raw_spin_unlock(&irq_resend_lock); tasklet_schedule(&resend_tasklet); return 0; } +void clear_irq_resend(struct irq_desc *desc) +{ + raw_spin_lock(&irq_resend_lock); + hlist_del_init(&desc->resend_node); + raw_spin_unlock(&irq_resend_lock); +} + +void irq_resend_init(struct irq_desc *desc) +{ + INIT_HLIST_NODE(&desc->resend_node); +} #else +void clear_irq_resend(struct irq_desc *desc) {} +void irq_resend_init(struct irq_desc *desc) {} + static int irq_sw_resend(struct irq_desc *desc) { return -EINVAL; From patchwork Mon Apr 10 15:57:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 81552 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1999156vqo; Mon, 10 Apr 2023 09:13:03 -0700 (PDT) X-Google-Smtp-Source: AKy350YS2hKv6B2IfBZpDqHhaF42Hy9zc55bDQer8l37el8h8G+3U+//t7du0NBtdSOdZmakidVJ X-Received: by 2002:aa7:d516:0:b0:504:b28d:88cc with SMTP id y22-20020aa7d516000000b00504b28d88ccmr1541823edq.8.1681143182997; Mon, 10 Apr 2023 09:13:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681143182; cv=pass; d=google.com; s=arc-20160816; b=DQMxINZk1iR2EtERHDmt0UM5h863fPTSIE2e1YkaUE7hcjiBo2X6leEtARA+RXmua9 LsTl292rc11h8CzWOJmvskxHNbuedbWBJmzpAoo/XMMDDF1rwP3oo5UnYHHTqr+nn7q6 WiOST1ZwO/7+pwII9ccku+N9mtMlybCYTeRLH3fFt5U06O+zP4Xh4TClUxdDdQz/jRi9 9tdmOexCZGcathtkFGq/osWowU8KxGoRSeShCA9BnF8AQU9z+dY7RrsSSgKnTQi0K9KD 38W6K7Rn1fvi9I5ow88AJXmA8FerXqROTVX0582ov4ATei0RRUgBgZHUSJpFZ/OQ7U0g My+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/aF/H+uiUkhuf5m7x27G909EICjt6oClo09RST+Zy+Q=; b=N8PG9YXAlH3LzEsgVjPwm3I9DEpk7yn5k8kxRzMMfdIpdq2WdVozZpXHoDpmYHSvdg svC27aDe3OjksHyNihmLkG7MXXIJRs419TRjex883BqmH04lta97TsxdJVhpFR4kjSUP XzK3ZAdgXxT+1XyVvzZz9gr7K62K/ZH0Dna4NCBL9eE4p2o4faFDQoZWnCGDl9HWwlsP a4kigk/ozndtcTSEYv4TVCOGtgkvgAGNhWtfFKvZWiPE2QShWHaa/gOHNFVpuv7mAm3e 6RVM1ViAMTcXXT2flfL6k6T97OwkGF7xeeiiBzwjR6yq5MB4npZNYpTWtq6TNFqagQM0 ufgg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Q4kAoIwI; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c10-20020aa7d60a000000b005048cf4f5b7si5217945edr.489.2023.04.10.09.12.29; Mon, 10 Apr 2023 09:13:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Q4kAoIwI; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230146AbjDJP5y (ORCPT + 99 others); Mon, 10 Apr 2023 11:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230092AbjDJP5t (ORCPT ); Mon, 10 Apr 2023 11:57:49 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2049.outbound.protection.outlook.com [40.107.93.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D677D4EC6 for ; Mon, 10 Apr 2023 08:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PVuR0BuOqVpR3KJm+Lg+D4rykBA3rnlhWjcnPQskwPUDhrZmFEeD3+QFqQqKAWTe8O3qs2Xm13dElPrnlqxSgZ5Ct9wSaFCkO7sBJebmIebyOFDx0IJkWJLQuYThlPHL/emAyWCwoNO9Ym/bNeB1UNSb4oYvPo6oeLwCZCAGkaU9KcgJWk3GJj1mZW/rvUnjpnO5+jB7pz/Tfzf4P/aCApugmcamlnKNM2OWS4Ss83vdTXZO+PIoXTPFCTL1GzWZKNuvWyby10DiqGfDB2Ga8ep412Q9o918Owk8n8NhtaNpEt5T1OBg35DlVdOotf0caGhJvBjIHxNx2SlvqWj7Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/aF/H+uiUkhuf5m7x27G909EICjt6oClo09RST+Zy+Q=; b=nyw6bhIOiTjSES7AzcINBsgy0kZjBTpW0LcO46EzUaCPIQu1Tvqi7mk7+xgAw57qtMkCezgWYUVQUl4q6NJRp07jr31Hsk0Sx5fjAcp/wXPyrSEh/SBgegNOrkBvEn4lgSGWKt3mlKAgYLY2fdvuhEeXPqgNLEU9LNs0wOAzcXsobCXt8G5I8/pgiPzmAj3yViKACURUhw41+fiYy0T9JQiSRTJDA5N847NEySe+9mRIqL+cTWLJstp+80lJrVrPgoMewVrvRBfpjq9XmqDoh4MNSGW5e9dqAVYBqSA/L2NDHFBC9n9s1bPDXc21HgYDlQhPVWH9a55UOzb4WTTmWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=linutronix.de smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/aF/H+uiUkhuf5m7x27G909EICjt6oClo09RST+Zy+Q=; b=Q4kAoIwIR4akZL7RSsDztNIZ4aXL0uQEZ03Eq4+qj/akMqbNDzSxA0a1t9ENOw4yQyHmmI88VMKDlIIAokY/7wtaDAUxyVIWI3AfOLlMMuKdg06CfFB+UKliI2Umbzv67VBw+3Wy5tZAlJY3nG81IxgagfT4YZu0vXjsFnHtVkqYlkwqGGcH8Js2L3Z89W70R7SGdWxJ9LbEvcez2QbpH+eysYRUwn6h8psdJ6y/mYg1fQFfhmwZYqU+Wa9EiwPk3h/SxIctN73zeAq5QvHUwV0q34ZibbtW61tOmiioOwlbtkKncszMNdS995C4tXZmac0r6DEgPx8R3w+jgYOFNA== Received: from DS7PR06CA0017.namprd06.prod.outlook.com (2603:10b6:8:2a::24) by CH2PR12MB5018.namprd12.prod.outlook.com (2603:10b6:610:6e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.35; Mon, 10 Apr 2023 15:57:36 +0000 Received: from DM6NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2a:cafe::f9) by DS7PR06CA0017.outlook.office365.com (2603:10b6:8:2a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.39 via Frontend Transport; Mon, 10 Apr 2023 15:57:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DM6NAM11FT015.mail.protection.outlook.com (10.13.172.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.25 via Frontend Transport; Mon, 10 Apr 2023 15:57:35 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Mon, 10 Apr 2023 08:57:25 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 10 Apr 2023 08:57:25 -0700 Received: from SDONTHINENI-DESKTOP.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 10 Apr 2023 08:57:24 -0700 From: Shanker Donthineni To: Thomas Gleixner , Marc Zyngier CC: Sebastian Andrzej Siewior , Michael Walle , Shanker Donthineni , , Vikram Sethi Subject: [PATCH v3 2/3] genirq: Encapsulate sparse bitmap handling Date: Mon, 10 Apr 2023 10:57:20 -0500 Message-ID: <20230410155721.3720991-3-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230410155721.3720991-1-sdonthineni@nvidia.com> References: <20230410155721.3720991-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT015:EE_|CH2PR12MB5018:EE_ X-MS-Office365-Filtering-Correlation-Id: c50330b2-01cb-477b-f9a3-08db39dc4d9c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: njLwA6lQ2RbKIxyrMX3lVOEhhXy4KCcX5KSHAXGPpmC4Q+ctd/ywQv6JHnmR5r9AXh4pciiFKGMY0eNtW6ti6YuQJzU6DDpOzsbipLB1PK+qFbcdfLXXWtgsj/32O2S5P9YQcq56tYiedFYr0YHYlVseJJeqEGTjrMf7tqvqJ29g0yToy+WO8gylG6+AxXv5Mj6731Lc6bZpxXCA7lB8C7CsQhWbcvA2HVS00lZmBbYw/nC6/6T12yO+HhlRaRrxmWNuMtwchqFiS/znUxegkbJ2t8ul4o3aeJGC4tEap+aoKOTxAMCUNbgvzjAo4+xSMHjBaftXT8FdyL5X3Kyvujdl/04WHj4z5LYFhNCRGzkJMob0bQjejxJj6hyXJU7o93BhXz3VhabGJ2cKSstOWIR8IppH1Xx7fQ/OnQkeX4FuKgI2oaVCnjDvVhwoDktuWsUeS94EGq3fsaUCAjyQ6QDc1oilyFM2WZVgfewraJz7kqn8ovWSA6obGECi7PyZbv9A9ss1kcwx3R85qMMTw9qxpzMSLYKdXrcQRayE1jfjaFva4s0v8ErXiFl/dqilLGGuvH5nS7nfN6CHVZRGmg1SAlhVRyW7tGe910INWvPhHlCo9XSjRyQkD7YAjxb1kUuSuQIxc9bWKSSy8W2jw5O/sfWwOgs6U2Z6iiHM0+Ax4zr6WT5gJ4aIsvNUaTXlo+hTfmRK0mmMKvvIVtdZEMNk+Vff091HKeSLhhFIsfFdJdJAoPZsaLTBmbXAystu X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(136003)(396003)(346002)(376002)(451199021)(36840700001)(46966006)(40470700004)(40460700003)(70206006)(4326008)(478600001)(54906003)(7696005)(70586007)(8676002)(41300700001)(316002)(110136005)(86362001)(36756003)(83380400001)(426003)(2616005)(336012)(107886003)(1076003)(26005)(6666004)(8936002)(5660300002)(2906002)(82310400005)(40480700001)(36860700001)(82740400003)(356005)(7636003)(186003)(47076005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2023 15:57:35.9060 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c50330b2-01cb-477b-f9a3-08db39dc4d9c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5018 X-Spam-Status: No, score=0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762806394532353690?= X-GMAIL-MSGID: =?utf-8?q?1762806394532353690?= Move the open coded sparse bitmap handling into helper functions as a preparatory step for converting the sparse interrupt management to a maple tree. No functional change. Signed-off-by: Shanker Donthineni --- kernel/irq/internals.h | 4 ++-- kernel/irq/irqdesc.c | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index 51fc8c497c22..f3f2090dd2de 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -12,9 +12,9 @@ #include #ifdef CONFIG_SPARSE_IRQ -# define IRQ_BITMAP_BITS (NR_IRQS + 8196) +# define MAX_SPARSE_IRQS (NR_IRQS + 8196) #else -# define IRQ_BITMAP_BITS NR_IRQS +# define MAX_SPARSE_IRQS NR_IRQS #endif #define istate core_internal_state__do_not_mess_with_it diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index b401b89b226a..9a71fc6f2c5f 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -131,7 +131,18 @@ int nr_irqs = NR_IRQS; EXPORT_SYMBOL_GPL(nr_irqs); static DEFINE_MUTEX(sparse_irq_lock); -static DECLARE_BITMAP(allocated_irqs, IRQ_BITMAP_BITS); +static DECLARE_BITMAP(allocated_irqs, MAX_SPARSE_IRQS); + +static int irq_find_free_area(unsigned int from, unsigned int cnt) +{ + return bitmap_find_next_zero_area(allocated_irqs, MAX_SPARSE_IRQS, + from, cnt, 0); +} + +static unsigned int irq_find_next_irq(unsigned int offset) +{ + return find_next_bit(allocated_irqs, nr_irqs, offset); +} #ifdef CONFIG_SPARSE_IRQ @@ -517,7 +528,7 @@ static int alloc_descs(unsigned int start, unsigned int cnt, int node, static int irq_expand_nr_irqs(unsigned int nr) { - if (nr > IRQ_BITMAP_BITS) + if (nr > MAX_SPARSE_IRQS) return -ENOMEM; nr_irqs = nr; return 0; @@ -535,11 +546,11 @@ int __init early_irq_init(void) printk(KERN_INFO "NR_IRQS: %d, nr_irqs: %d, preallocated irqs: %d\n", NR_IRQS, nr_irqs, initcnt); - if (WARN_ON(nr_irqs > IRQ_BITMAP_BITS)) - nr_irqs = IRQ_BITMAP_BITS; + if (WARN_ON(nr_irqs > MAX_SPARSE_IRQS)) + nr_irqs = MAX_SPARSE_IRQS; - if (WARN_ON(initcnt > IRQ_BITMAP_BITS)) - initcnt = IRQ_BITMAP_BITS; + if (WARN_ON(initcnt > MAX_SPARSE_IRQS)) + initcnt = MAX_SPARSE_IRQS; if (initcnt > nr_irqs) nr_irqs = initcnt; @@ -812,8 +823,7 @@ __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node, mutex_lock(&sparse_irq_lock); - start = bitmap_find_next_zero_area(allocated_irqs, IRQ_BITMAP_BITS, - from, cnt, 0); + start = irq_find_free_area(from, cnt); ret = -EEXIST; if (irq >=0 && start != irq) goto unlock; @@ -838,7 +848,7 @@ EXPORT_SYMBOL_GPL(__irq_alloc_descs); */ unsigned int irq_get_next_irq(unsigned int offset) { - return find_next_bit(allocated_irqs, nr_irqs, offset); + return irq_find_next_irq(offset); } struct irq_desc * From patchwork Mon Apr 10 15:57:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 81548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1996571vqo; Mon, 10 Apr 2023 09:09:13 -0700 (PDT) X-Google-Smtp-Source: AKy350b6ZZFOXKjY5TzAtZgdnlSJkxiiU2pCI74qjloLVz2TYATcTHnveaXClj9Ob6+k/jZRYqtv X-Received: by 2002:a17:906:3155:b0:882:cdd4:14d9 with SMTP id e21-20020a170906315500b00882cdd414d9mr7035329eje.46.1681142953582; Mon, 10 Apr 2023 09:09:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681142953; cv=pass; d=google.com; s=arc-20160816; b=R6EX1mhBqYmFZWInoIJFyAD4MmTxq4OywbcCkYOIHvEjtd3B6ivNZTw8H5DmvuUe3L MfIkub7xoNeDJkzs4gqJes9EPMDUsvUWwaPMvrNYHywQQNMetrkeXc8hSBCm00Qh0+It rNFFtbBFAMHgIp8d1cNPs5R2IwO8TjDQlZiq8SO0d/4C8JpYMDMl96aZnWMPfqf5MBlL KxTR/jIUSTg1LiUZtW8Gm4xmHFKbsAEXutG4cl2skCxtXhvXe8w3KJ43cUdR0gfqrp4Y GpSH/fZZC/9VH6jmA4JpFe3S9N5FT+G3X6pzwlNbg438ChMJM0KzAjGQzUJ2jv6Mw6XW YmEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mh6LTT8t0l62e81wt2yeOzxB5C0UdB0/j4+hBnbFyy0=; b=RsPTm5RxkXl6VWxghVOLRYugCheKwkpO/RwCDfFkQLVQDwa48i3HjXHaZA2rQrVMty WXbV/m9Xs/Z+hQuVUINzwSD7P7ZZkieppEXbW+I8feNcRiIHZAdgsTif2wThsxqCHKeF 97UF2PbWAhijCvuWOUeXVkzg5xM24EP1RQt3XuAZ1P4ryb19RGZeVulsor9MGL24GxMF v9rz86By0FgYh72iV6+3Gga1Vho2jeDPeNCHuo3SeGoxj+0vHLj7n3p94pMq45GAeFJm I1i1J2uwrjjyySKG8NDjZP9A0sX1WwLr7mhxSLnAIILi1I3JDk8vlHs4jYgbcImIBWp3 pyzA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=kYpQcgo1; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m27-20020a170906259b00b00947d7191944si8885531ejb.639.2023.04.10.09.08.49; Mon, 10 Apr 2023 09:09:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=kYpQcgo1; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbjDJP5k (ORCPT + 99 others); Mon, 10 Apr 2023 11:57:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230007AbjDJP5e (ORCPT ); Mon, 10 Apr 2023 11:57:34 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2078.outbound.protection.outlook.com [40.107.223.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED3D826B6 for ; Mon, 10 Apr 2023 08:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aKd2EQJsB0NccYsPZ23ru2RXr28IDSJ5FTxMHcBheeZNknDPIWNtg/BQgyqNJFC1M2cKlz7CTtZF4HfJIe5f/OrxZkLk6gPB000pixpxbD9+9f29N1rQLIRBYZ6+4CIpZpKySRb9W9+oBZ1gr9gRok5OpIaTQ0epm+jaJoQmdpcyRZUmL1aUPtCmspCO/blcvc1HjcLIBARcOP8ShSlPPAk4otQRYbpAkj/As+7mXRsLFRzaAqwUGVX8V7o0CbNXvowYhyWTtmKALvkw0ANvNNGwqfXwaoN67Ka3RK2eWSx4P1fCw6XvvXn8MUq2gHIyAA40BEqSUIGvw3MmwzWODg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mh6LTT8t0l62e81wt2yeOzxB5C0UdB0/j4+hBnbFyy0=; b=O3WQ74f2qWomDzYGYwiSdjbvYMciJRVY0Jx0+pI1WPtVQaIzMJt+/DQXidQkalrSsJhBTaItk/hsP6G9DL36RPMiOmlHJwh/q2jr/Tf1Z9fSWViQFwTB3XDOmdbgLIEb+h0lOl2MF0pgWvY6hxJRndE7yZbIHSc6dEBotxS4r+f4CuuhupbaZfVjywwPhjQER1DTUr9o/P1ftXTwaywrWurjZGt+DI2wFwYBMMzQE+8VTJd18vIyKyvQTwGv/COvCKB6vwVKAXJYaa4u1/pZ9Sm3AT04O7/qY8DzWMip12ORG4kEIsnRb63MSwxrwAmU+39/2QqxeFa3X9bGNCr/XA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=linutronix.de smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mh6LTT8t0l62e81wt2yeOzxB5C0UdB0/j4+hBnbFyy0=; b=kYpQcgo1JlWmimJYNmmqjO35w2XLvNUzO8F0rJDiLTvhpc+yHe6YEvR3k9zKaWxv+x3bdIQZHIIDGDcZG60SfynhGF4sTIbedwBMx+y+p8ODWLm492zdoxaLoWd41Cmae6cYduz5NNdpx2IINvEtfPuPi6aFMmeSDstVrCmnnKydkY3y+pq/6+CZCwcuulvyg9V23Qm+BEO1H7tdlMKd4lvdqHwe+47uYM+UsUqjdvsQbyyASa/e9I3uiwdxGjAru8wfRzkl+B4ORKSaMwqcPYLgsWzj+l7eFxwUyjg6/IszBI37n1VhnXuvD0jC+XI1fFSON9Y7Ai7rLBqNTo/DqQ== Received: from DS7P222CA0003.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::19) by DS7PR12MB6141.namprd12.prod.outlook.com (2603:10b6:8:9b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.34; Mon, 10 Apr 2023 15:57:30 +0000 Received: from DM6NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::6a) by DS7P222CA0003.outlook.office365.com (2603:10b6:8:2e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.39 via Frontend Transport; Mon, 10 Apr 2023 15:57:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DM6NAM11FT056.mail.protection.outlook.com (10.13.173.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.27 via Frontend Transport; Mon, 10 Apr 2023 15:57:30 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Mon, 10 Apr 2023 08:57:26 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 10 Apr 2023 08:57:26 -0700 Received: from SDONTHINENI-DESKTOP.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 10 Apr 2023 08:57:25 -0700 From: Shanker Donthineni To: Thomas Gleixner , Marc Zyngier CC: Sebastian Andrzej Siewior , Michael Walle , Shanker Donthineni , , Vikram Sethi Subject: [PATCH v3 3/3] genirq: Use the maple tree for IRQ descriptors management Date: Mon, 10 Apr 2023 10:57:21 -0500 Message-ID: <20230410155721.3720991-4-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230410155721.3720991-1-sdonthineni@nvidia.com> References: <20230410155721.3720991-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT056:EE_|DS7PR12MB6141:EE_ X-MS-Office365-Filtering-Correlation-Id: 722891f6-bc38-4e20-4e46-08db39dc4a82 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3EMqBGKM1l041qQ1mdAZzYD4vGJQ5jA+nJzZVky5s7RWdBfMGJDAutkd/w3TVvLAJGayK0t5TZbsP5dEQqeabmTtLfWv/HccK0dDFx2+TxhDh/JCmxAmY3C8hsxf3jymnXbx8mWwa5u7Eehjt9fOYknmFSj7ojmYcnzlUtrkItDC/UCNT9ykLKG8YYBhSLwD/g90hBHq7F5FNVn4DjKCZ4beL4eK9yZM8F/YOXkc4+6wTRvB6VFVoXNK123EU7pP4hqrpb+rgWaF69AcSaK6WnRk5d0WUxTKbskPC2ZHeUb82G2kYq/7hD7U1IWmEnIAOPW6zqh9I/FmW2vBl7eBz9dtyLYFBJktCyhKKEo0s0EBStVsQb4XnqjFPgCUBWMjtDDa4wYUqNxlZqkpiuuMyJKrPQPCyWVp41TdeGRM4Vs6+LL/BclxnHKtHS1JDrGJjNBe4vXsitx36O2MMUfiDKp4N5fFwCXjF11bSxOQ03WxZROyv7i84SENODVtLfDorB6Ua4H40tCIeHas4vuRA0gnPwItVSf6O+K7W0sSJDovQ6xB378ihURCM+8d2f2ZSbJS/cPwpmEKoKIRH8Y8V+COmzTCUiDrZkzmYeVIeMN7fvviyOoTsVwL4WCjg+cs8OdstyiMMU9cEBVUZnx/gnN/6GzYkMCnKLSdzPTOmiV6Lc7B25hSOaBjUnB/3xMaLMsCMUV41f1unPHo9pzr6AFqiM9vevtvXBN1shXfJg10/2C4IFknB8x+j7O1rPmz X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(136003)(346002)(396003)(376002)(451199021)(36840700001)(40470700004)(46966006)(66899021)(7696005)(478600001)(86362001)(40480700001)(47076005)(83380400001)(40460700003)(36756003)(82740400003)(7636003)(356005)(2616005)(36860700001)(336012)(426003)(6666004)(107886003)(2906002)(54906003)(110136005)(316002)(186003)(26005)(1076003)(5660300002)(41300700001)(8936002)(82310400005)(8676002)(70586007)(70206006)(4326008);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2023 15:57:30.7293 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 722891f6-bc38-4e20-4e46-08db39dc4a82 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6141 X-Spam-Status: No, score=0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762806153761950592?= X-GMAIL-MSGID: =?utf-8?q?1762806153761950592?= The current implementation uses a static bitmap and a radix tree to manage IRQ allocation and irq_desc pointer store respectively. However, the size of the bitmap is constrained by the build time macro MAX_SPARSE_IRQS, which may not be sufficient to support the high-end servers, particularly those with GICv4.1 hardware, which require a large interrupt space to cover LPIs and vSGIs. The maple tree is a highly efficient data structure for storing non-overlapping ranges and can handle a large number of entries, up to ULONG_MAX. It can be utilized for both storing interrupt descriptors and identifying available free spaces. The interrupt descriptors management can be simplified by switching to a maple tree data structure, which offers greater flexibility and scalability. To support modern servers, the maximum number of IRQs has been increased to INT_MAX, which provides a more adequate value than the previous limit of NR_IRQS+8192. Signed-off-by: Shanker Donthineni --- kernel/irq/internals.h | 2 +- kernel/irq/irqdesc.c | 54 +++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index f3f2090dd2de..7bdb7507efb0 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -12,7 +12,7 @@ #include #ifdef CONFIG_SPARSE_IRQ -# define MAX_SPARSE_IRQS (NR_IRQS + 8196) +# define MAX_SPARSE_IRQS INT_MAX #else # define MAX_SPARSE_IRQS NR_IRQS #endif diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 9a71fc6f2c5f..d6d8120ffd56 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -12,8 +12,7 @@ #include #include #include -#include -#include +#include #include #include @@ -131,17 +130,38 @@ int nr_irqs = NR_IRQS; EXPORT_SYMBOL_GPL(nr_irqs); static DEFINE_MUTEX(sparse_irq_lock); -static DECLARE_BITMAP(allocated_irqs, MAX_SPARSE_IRQS); +static struct maple_tree sparse_irqs = MTREE_INIT_EXT(sparse_irqs, + MT_FLAGS_ALLOC_RANGE | + MT_FLAGS_LOCK_EXTERN | + MT_FLAGS_USE_RCU, + sparse_irq_lock); static int irq_find_free_area(unsigned int from, unsigned int cnt) { - return bitmap_find_next_zero_area(allocated_irqs, MAX_SPARSE_IRQS, - from, cnt, 0); + MA_STATE(mas, &sparse_irqs, 0, 0); + + if (mas_empty_area(&mas, from, MAX_SPARSE_IRQS, cnt)) + return -ENOSPC; + return mas.index; } static unsigned int irq_find_next_irq(unsigned int offset) { - return find_next_bit(allocated_irqs, nr_irqs, offset); + struct irq_desc *desc = mt_next(&sparse_irqs, offset, nr_irqs); + + return desc ? irq_desc_get_irq(desc) : nr_irqs; +} + +static void irq_insert_desc(unsigned int irq, struct irq_desc *desc) +{ + MA_STATE(mas, &sparse_irqs, irq, irq); + WARN_ON(mas_store_gfp(&mas, desc, GFP_KERNEL) != 0); +} + +static void delete_irq_desc(unsigned int irq) +{ + MA_STATE(mas, &sparse_irqs, irq, irq); + mas_erase(&mas); } #ifdef CONFIG_SPARSE_IRQ @@ -355,26 +375,14 @@ static void irq_sysfs_del(struct irq_desc *desc) {} #endif /* CONFIG_SYSFS */ -static RADIX_TREE(irq_desc_tree, GFP_KERNEL); - -static void irq_insert_desc(unsigned int irq, struct irq_desc *desc) -{ - radix_tree_insert(&irq_desc_tree, irq, desc); -} - struct irq_desc *irq_to_desc(unsigned int irq) { - return radix_tree_lookup(&irq_desc_tree, irq); + return mtree_load(&sparse_irqs, irq); } #ifdef CONFIG_KVM_BOOK3S_64_HV_MODULE EXPORT_SYMBOL_GPL(irq_to_desc); #endif -static void delete_irq_desc(unsigned int irq) -{ - radix_tree_delete(&irq_desc_tree, irq); -} - #ifdef CONFIG_SMP static void free_masks(struct irq_desc *desc) { @@ -517,7 +525,6 @@ static int alloc_descs(unsigned int start, unsigned int cnt, int node, irq_sysfs_add(start + i, desc); irq_add_debugfs_entry(start + i, desc); } - bitmap_set(allocated_irqs, start, cnt); return start; err: @@ -557,7 +564,6 @@ int __init early_irq_init(void) for (i = 0; i < initcnt; i++) { desc = alloc_desc(i, node, 0, NULL, NULL); - set_bit(i, allocated_irqs); irq_insert_desc(i, desc); } return arch_early_irq_init(); @@ -612,6 +618,7 @@ static void free_desc(unsigned int irq) raw_spin_lock_irqsave(&desc->lock, flags); desc_set_defaults(irq, desc, irq_desc_get_node(desc), NULL, NULL); raw_spin_unlock_irqrestore(&desc->lock, flags); + delete_irq_desc(irq); } static inline int alloc_descs(unsigned int start, unsigned int cnt, int node, @@ -624,8 +631,8 @@ static inline int alloc_descs(unsigned int start, unsigned int cnt, int node, struct irq_desc *desc = irq_to_desc(start + i); desc->owner = owner; + irq_insert_desc(start + i, desc); } - bitmap_set(allocated_irqs, start, cnt); return start; } @@ -637,7 +644,7 @@ static int irq_expand_nr_irqs(unsigned int nr) void irq_mark_irq(unsigned int irq) { mutex_lock(&sparse_irq_lock); - bitmap_set(allocated_irqs, irq, 1); + irq_insert_desc(irq, irq_desc + irq); mutex_unlock(&sparse_irq_lock); } @@ -781,7 +788,6 @@ void irq_free_descs(unsigned int from, unsigned int cnt) for (i = 0; i < cnt; i++) free_desc(from + i); - bitmap_clear(allocated_irqs, from, cnt); mutex_unlock(&sparse_irq_lock); } EXPORT_SYMBOL_GPL(irq_free_descs);