From patchwork Sat May 27 05:46:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huacai Chen X-Patchwork-Id: 99761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp163168vqr; Fri, 26 May 2023 23:26:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42h93QGDwco76uCefu4zKtEi+g6V6I0uTwv6L4wkX3cV01BOCEcbxrHZb3mDm9GRB3th8l X-Received: by 2002:a17:90a:bf04:b0:256:4b15:395b with SMTP id c4-20020a17090abf0400b002564b15395bmr1169003pjs.47.1685168813052; Fri, 26 May 2023 23:26:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685168813; cv=none; d=google.com; s=arc-20160816; b=FaLub89GDmXNh8lfkCDvD/MF+cSOU1Rzb0cUUIctDe9Bb+xyQY1/W8yoJ6eocxGCfP /oH9j7zjByXsdg8FyUBCS2Kd5Hjhg0yRIvHPz/2zTYR5dSBRd/Q/lwPAmHYnRgOuX5Xj 4LcW9g2MsNqXyUd0+mOg4gca1IVMalRSeCy3xAVKfGcqNd8DJQdrNagkzjQtyuuMCdq5 j8wRdxxuRp5HOfgAKWgl1qqiOrtkJ84Rcv3cNLg6QCaHvWDEbVJK0ub/zXIyP6YlLCz2 50vhLzgvplVrl6jWZbvSv3BGLl58fkdDpUIOoxsCPFvTw46phZlu8eWwEanna0WUKHsT 8/YQ== ARC-Message-Signature: i=1; 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; bh=0GfSgxGbayJ7k7drxjfxTiw0vf/ejfsUPu/0wdED5PI=; b=FFAXsLgSaMif7eocKQUB4r0qYGT9cWqYiZaxbbknEAG4BJtzvYMTSZ4A6m3mJSQTft JCoLH7fJoL9I9PUc6oqbin5JcNnc2ggAg6jmtNl5+edVFyQlq/omlS5tRzsXTkKo11zA KE31tXcuFcOAVt3jhtlY6Gk244MgEcRg9yjDxCiDe6UZO9VFX9SR7Z6bXcRZu3fSqlHJ V212ttiCYrNZx/LhrlVo9PmKNfLAEruaUSHSDb0PfnidyfeziZdbDFuPt04qGgSLKAbx XrMtPXw6F/vaIHqOFyxIvBbr6VDVzqTzbXbUoxo7ozAhUYKz82IaEZMSbd+XifA3Hdn2 bn+w== ARC-Authentication-Results: i=1; mx.google.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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a17090a4e4800b00246a75f49desi6056814pjl.112.2023.05.26.23.26.36; Fri, 26 May 2023 23:26:52 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231261AbjE0Fr5 (ORCPT + 99 others); Sat, 27 May 2023 01:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbjE0Fr4 (ORCPT ); Sat, 27 May 2023 01:47:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15AB2114 for ; Fri, 26 May 2023 22:47:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9E0D560F27 for ; Sat, 27 May 2023 05:47:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57772C433D2; Sat, 27 May 2023 05:47:51 +0000 (UTC) From: Huacai Chen To: Thomas Gleixner , Marc Zyngier , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn, Xuefeng Li , Huacai Chen , Jiaxun Yang , Huacai Chen , Juxin Gao Subject: [PATCH 2/2] irqchip/loongson-pch-msi: Add machanism to limit msi allocation Date: Sat, 27 May 2023 13:46:33 +0800 Message-Id: <20230527054633.704916-3-chenhuacai@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230527054633.704916-1-chenhuacai@loongson.cn> References: <20230527054633.704916-1-chenhuacai@loongson.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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?1767027572852917867?= X-GMAIL-MSGID: =?utf-8?q?1767027572852917867?= Loongson machines can have as many as 256 logical cpus, but the maximum of msi vectors in one irqchip is also 256 (practically that is less than 256, because pch-pic consumes some of them). Even on a 64-core machine, 256 irqs can be easily exhausted if there are several NICs (NICs usually allocate msi irqs depending on the number of online cpus). So we want to limit the msi allocation. In this patch we add a machanism to limit msi allocation: 1, Modify input "nvec" by overriding the msi_domain_ops::msi_prepare(); 2, The default limit is 256, which is compatible with the old behavior; 3, Add a cmdline parameter "loongson_msi_limit=xxx" to control the limit. Signed-off-by: Juxin Gao Signed-off-by: Huacai Chen --- drivers/irqchip/irq-loongson-pch-msi.c | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/irqchip/irq-loongson-pch-msi.c b/drivers/irqchip/irq-loongson-pch-msi.c index 6e1e1f011bb2..85e2e3468b8c 100644 --- a/drivers/irqchip/irq-loongson-pch-msi.c +++ b/drivers/irqchip/irq-loongson-pch-msi.c @@ -85,9 +85,36 @@ static void pch_msi_compose_msi_msg(struct irq_data *data, msg->data = data->hwirq; } +#define DEFAULT_MSI_LIMITS 256 + +static int pch_msi_limits = DEFAULT_MSI_LIMITS; + +static int __init pch_msi_limit(char *str) +{ + get_option(&str, &pch_msi_limits); + + if (pch_msi_limits <= 0) + pch_msi_limits = DEFAULT_MSI_LIMITS; + + return 0; +} + +early_param("loongson_msi_limit", pch_msi_limit); + +static int pch_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec, msi_alloc_info_t *arg) +{ + memset(arg, 0, sizeof(*arg)); + return clamp_val(nvec, 0, pch_msi_limits); +} + +static struct msi_domain_ops pch_msi_ops = { + .msi_prepare = pch_msi_prepare, +}; + static struct msi_domain_info pch_msi_domain_info = { .flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX, + .ops = &pch_msi_ops, .chip = &pch_msi_irq_chip, };