Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp236257lqg; Thu, 11 Apr 2024 00:43:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV3gu1V6YsaEMgELV+WR6GUlkzvyFAuAfopFXR56yHXG27G55FVPW4dpTkpjk7/soCc1jj6VRzvAruYRJL1kYSzcekaIc2pBsHAQZNMEQ== X-Google-Smtp-Source: AGHT+IHCkmMmUNHqmC7UQ4TThAmYHmywXygZjhv2/6HezS4p9uz6ShMCh4LtNT72atl/VUSq8+gd X-Received: by 2002:a17:907:369:b0:a51:dd18:bd20 with SMTP id rs9-20020a170907036900b00a51dd18bd20mr2579798ejb.14.1712821394489; Thu, 11 Apr 2024 00:43:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712821394; cv=pass; d=google.com; s=arc-20160816; b=Jg8XK9TXObVDZf/CwtS2DAYDsb0ym1kAEORRKnbxPFIBrj4wSNSf1b9x3gpEjzjJO4 lYVombptSRFnY7J9+cGDZGPHJ8qJekxrYMmo2T6y8KV5d6oHjHIByR7P+6l1iKHDzTz5 nHoBVdFUGabobH/zQx8k1OEXoYTJXqeY8on19Wgx6JlBfkYHIhYTxN8+bDRPgJlEUj0g wYSgIXLwVJU34PeyxxlDWvAoBdhLOXfJgw8x5f659cLGReNOyujhbAfjzIhxtVjH/I3l jxSX+XMeZ/r2BU5VzHFvje7VkgZ1YoGl7a07oOV0AWS0aV3XFvwhf2Xj1HTqklwbg3bs 5FcA== 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=tUtCoF0eyO9gScpPeW9H9/9ARpqG/SH0m0PV7EcoO1o=; fh=h1xXNY8doO7YpZZxFq7Tt2h1zNi8L7URk9NotQAeleE=; b=ylLULHYCwUn65wX99hURreq+RdZ8t9bNsE/lGannGj0g6LhphVhjV+onC/KkXnr7Cc AtOsApHcLuUtPHOGJQpVb8Adu2b+n6cMYEjn8Ock0al0LITw+ZJ08OMGu367km1Hi7/g l+ZOac+q/xXR5hu6cdHyKsg+zoQzeb7JoVne4bL8Ere+wC90Bmp7iO7MUsmf4Sx06b2b jWDctq2kfZC53kK+5OISx6NwIl42+cgJGlllpkPCWyejKr7A7Tr9UHgo3fn05mPMOjhf IkXWleK3Wej4hrngp9Wt8qXyRYs4SLylMM2yly8ji+/f4t7moeurHYcZ8/zbJNmrkoEe QTtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=UeqnWu2q; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-140009-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140009-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id hw9-20020a170907a0c900b00a5224111a07si296434ejc.369.2024.04.11.00.43.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 00:43:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140009-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=@linux.alibaba.com header.s=default header.b=UeqnWu2q; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-140009-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140009-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com 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 7A1061F21ADD for ; Thu, 11 Apr 2024 07:43:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85AC013E8AB; Thu, 11 Apr 2024 07:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="UeqnWu2q" Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B7B813FD71; Thu, 11 Apr 2024 07:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712821313; cv=none; b=YzxayG19z+zBmSZIN9w4KUp8nxbZ1VI5CN0OjmHlXCipQdYFkF3R3bziUgfYWKAziyIL1NKL030dJ+osKYjMZVMrKcT9xjgca7AYl65Bc7csUd04C2AgTxlWDXOkYGohaClAaUMVHNUlMQDF9tB3jUflx6g7dbCTG2RKFsAsD2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712821313; c=relaxed/simple; bh=26AX6FbxiCSYyPBzCKKI+HNN6hEkh52RFtYiSfHMdx4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PbzQP/fhgXt7Nfjbls2paPL+LTbjIp3e5MDEBTeK25R/7ZEHzKiKHfGnq4rRsWRhaSasZl+p/pbRIvn7/dgH2ox8HsmYRpVrQhD7yMcyr5yR+GOz1fxFPHR4+sF+KZU06hMhnz8XFvyZc6qbfON4zua0oEqlYOr2SxZtuS/0NZA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=UeqnWu2q; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1712821309; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=tUtCoF0eyO9gScpPeW9H9/9ARpqG/SH0m0PV7EcoO1o=; b=UeqnWu2qr0eOPJOK4TYrHlc2VCpibp+vNx4pPoLnuxSuiTQy5ARfk89cbeq/kjFJLM8t7+9R6r3sJcQhWB7FvdD7z3EeAJv3UFYwrNvesYpC8BxtHi/GEYD49jtfCHpu667hwXAj9f+EuTdGYGp6A2s8U9fMvE35WMahvyI4NT8= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=yaoma@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0W4KbQAN_1712821305; Received: from localhost.localdomain(mailfrom:yaoma@linux.alibaba.com fp:SMTPD_---0W4KbQAN_1712821305) by smtp.aliyun-inc.com; Thu, 11 Apr 2024 15:41:47 +0800 From: Bitao Hu To: dianders@chromium.org, tglx@linutronix.de, liusong@linux.alibaba.com, akpm@linux-foundation.org, pmladek@suse.com, kernelfans@gmail.com, deller@gmx.de, npiggin@gmail.com, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, jan.kiszka@siemens.com Cc: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, yaoma@linux.alibaba.com Subject: [PATCHv13 3/5] genirq: Avoid summation loops for /proc/interrupts Date: Thu, 11 Apr 2024 15:41:32 +0800 Message-Id: <20240411074134.30922-4-yaoma@linux.alibaba.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20240411074134.30922-1-yaoma@linux.alibaba.com> References: <20240411074134.30922-1-yaoma@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit show_interrupts() unconditionally accumulates the per CPU interrupt statistics to determine whether an interrupt was ever raised. This can be avoided for all interrupts which are not strictly per CPU and not of type NMI because those interrupts provide already an accumulated counter. The required logic is already implemented in kstat_irqs(). Split the inner access logic out of kstat_irqs() and use it for kstat_irqs() and show_interrupts() to avoid the accumulation loop when possible. Originally-by: Thomas Gleixner Signed-off-by: Bitao Hu Reviewed-by: Liu Song Reviewed-by: Douglas Anderson --- kernel/irq/internals.h | 2 ++ kernel/irq/irqdesc.c | 16 +++++++++++----- kernel/irq/proc.c | 6 ++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index 1d92532c2aae..6c43ef3e7308 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -98,6 +98,8 @@ extern void mask_irq(struct irq_desc *desc); extern void unmask_irq(struct irq_desc *desc); extern void unmask_threaded_irq(struct irq_desc *desc); +extern unsigned int kstat_irqs_desc(struct irq_desc *desc, const struct cpumask *cpumask); + #ifdef CONFIG_SPARSE_IRQ static inline void irq_mark_irq(unsigned int irq) { } #else diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index f348faffa7b4..382093196210 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -976,24 +976,30 @@ static bool irq_is_nmi(struct irq_desc *desc) return desc->istate & IRQS_NMI; } -static unsigned int kstat_irqs(unsigned int irq) +unsigned int kstat_irqs_desc(struct irq_desc *desc, const struct cpumask *cpumask) { - struct irq_desc *desc = irq_to_desc(irq); unsigned int sum = 0; int cpu; - if (!desc || !desc->kstat_irqs) - return 0; if (!irq_settings_is_per_cpu_devid(desc) && !irq_settings_is_per_cpu(desc) && !irq_is_nmi(desc)) return data_race(desc->tot_count); - for_each_possible_cpu(cpu) + for_each_cpu(cpu, cpumask) sum += data_race(per_cpu(desc->kstat_irqs->cnt, cpu)); return sum; } +static unsigned int kstat_irqs(unsigned int irq) +{ + struct irq_desc *desc = irq_to_desc(irq); + + if (!desc || !desc->kstat_irqs) + return 0; + return kstat_irqs_desc(desc, cpu_possible_mask); +} + #ifdef CONFIG_GENERIC_IRQ_STAT_SNAPSHOT void kstat_snapshot_irqs(void) diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c index 6954e0a02047..5c320c3f10a7 100644 --- a/kernel/irq/proc.c +++ b/kernel/irq/proc.c @@ -488,10 +488,8 @@ int show_interrupts(struct seq_file *p, void *v) if (!desc || irq_settings_is_hidden(desc)) goto outsparse; - if (desc->kstat_irqs) { - for_each_online_cpu(j) - any_count |= data_race(per_cpu(desc->kstat_irqs->cnt, j)); - } + if (desc->kstat_irqs) + any_count = kstat_irqs_desc(desc, cpu_online_mask); if ((!desc->action || irq_desc_is_chained(desc)) && !any_count) goto outsparse; -- 2.37.1 (Apple Git-137.1)