Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp215391lql; Fri, 12 Apr 2024 08:18:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGTFU9dLUNsokGYqqHW6uEvbulVL9YX+56V2krLUZmNZZajWs/ahsxkjKtEeIJKmjQdX6yfN4CAWq3sNEFrvsfkE09Yx7de47QYSlmfg== X-Google-Smtp-Source: AGHT+IEGHXYB5c0uZaC4Y7hWVJwOpirV5n2OvR3qnbO7GaYo3XsiNCqWslKcW2fy4y9Hk2P5Qhpr X-Received: by 2002:a05:6a00:1401:b0:6ea:c42a:d705 with SMTP id l1-20020a056a00140100b006eac42ad705mr3843293pfu.10.1712935113895; Fri, 12 Apr 2024 08:18:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712935113; cv=pass; d=google.com; s=arc-20160816; b=0u+HQdKPGNpERaYURgCTVtx2cMeoJSOE7QxN9t2uZPu2MkDGNRizuEu9oUxq4lG+KP H6ED3cgEBEykwEHuOlqwkkERbi9ocTEQooiopGb6e7IyxlaliQvXf19Q3Wc3IUdRsI/F npWDCEC+QOxKfZKH/Rc4y9w8Lv4YBX/nObleLWLft4yzGSA51ZalPqKvbkvOiE75GfFr UjuGLrustry6Q84V1ROu4j5LQ25QUOeGbLqTIfRDXh7k1nsMXHZ0+HLtku2S1xcRXfZS x8QthKTIbHvajCy6vxV8lqWHtEwxsl+w4bylk4rthS7tmpaJqZugXUqFeYqeh8VdKTU2 /tOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=DYsxybRbHJADoeHwWoUIoA4oypUcOZiJa2jWyx5aNtM=; fh=9HjHzKVoqtBlKTsOF6dcUJwWXolizPbxFr7M5tgVZiE=; b=D39uNcvFAdlrDa1KjANigwrmzFm+u2PwyVZPxD8ZgHulVtR5OrZnX3K1wVDKoqkUIQ TKhldged0yhN7iInwpXDJsEp5gA9MYc+LRaPQoUGQ8VnmiMwWl3v7O6LxnJbrd6qBz9H uu/10VUpR8nAh5Zw//u9GIl3ti1HM4ws0fxTzK4YNy42c8h7G+9mqTFUiciErVdXRVRr n5lmNzSjHEFBapDfV5sRWEOCq24XcxT+97/T2XqCdyEH7mJPE9RnLU6VjimKeDjwTcbi m/FG+o3JAoR5flqlvliECuhMAT4nPqBQZD+q6VkD75Wyxv+koGB9EPv/vIfayJ5geyho T3uw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wn6ZL6Nb; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-142924-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142924-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o3-20020a637303000000b005d3a532f031si3468454pgc.257.2024.04.12.08.18.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 08:18:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142924-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wn6ZL6Nb; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-142924-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142924-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 893F1283746 for ; Fri, 12 Apr 2024 15:18:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13DCD149003; Fri, 12 Apr 2024 15:14:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wn6ZL6Nb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="t3HktWwF" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 736FF1487F2; Fri, 12 Apr 2024 15:14:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934875; cv=none; b=j0i6uiq8Kjqw4hCdakSC8cX+i2I155XA4IGwwn8Qa/j9eqN9uH7r3Jj0e1KBYiWRb/fapSGu9VPc7QCGTbOglok+VRLPoZer+JlgLylOg89Wm4jVTaVJrwq42qsfGyElvm+6ov6cyyY3dEZ8DLsROHhUTZn/XPmxwZF90x+tpCQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934875; c=relaxed/simple; bh=qcS3kbQCgIaXt9loTOK2wXSVFBTDBe9ONKy5I193WZ4=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=F+7SIeDb9ODU06v5jdajfdxmiaxd+HUAYDD2ObtViL+WSU6HjehnutrpLRmmus+LtbDRSdmAsYv9bd2BIH5QLX7ECQTiTinRxUNYy6jSa73aX4geHdgT74alnxWJVIbEIDRjqAgq831x3naV3cNabBj/HlnqFyMcPbhbO/qQnFE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wn6ZL6Nb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=t3HktWwF; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Fri, 12 Apr 2024 15:14:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712934871; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DYsxybRbHJADoeHwWoUIoA4oypUcOZiJa2jWyx5aNtM=; b=wn6ZL6NbSWmPrb4Kmhg2Fj9HhYRLqPHQBYjY4tT/+oux7WOpB2RTngBNq7bDWoE3nvNEUX DK1t4oIMxvNtr9FAt8MTiwlCCmU6ZGyYoSTf5FjregzzwIOXFHRlpMLs9EEyNRnk0HotEK xsWHQakMdUqIjWGbM1HSGxfSnMnEUVNtNXHk8WXJ0EJICH2VBKLYC2Xjm3hjXUVV36LmY4 K7M0rkLVATeqhl0l9EGnPyjbeswHT2edDEFNOphNJLKyYTOV+7YGUMm+zG5GHIGJZUHkyO sYCQm+GXSOM2ARYWADdu8/AyrJOJnmZv6N47YohDQKf+XZM/FbaVoxdgQmkzog== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712934871; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DYsxybRbHJADoeHwWoUIoA4oypUcOZiJa2jWyx5aNtM=; b=t3HktWwFRDL+sFBEu2UosgVZmNIgkpxnQRUCyNpFjyFo+zZ/2DdZOVR3UCRgsnPYGc1fEK NgE1BwVYOnV4uLAg== From: "tip-bot2 for Bitao Hu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/core] genirq: Avoid summation loops for /proc/interrupts Cc: Thomas Gleixner , Bitao Hu , Liu Song , Douglas Anderson , x86@kernel.org, linux-kernel@vger.kernel.org, maz@kernel.org In-Reply-To: <20240411074134.30922-4-yaoma@linux.alibaba.com> References: <20240411074134.30922-4-yaoma@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171293487060.10875.15677909235587319984.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the irq/core branch of tip: Commit-ID: 25a4a015118037809c97d089d69e927737e589e1 Gitweb: https://git.kernel.org/tip/25a4a015118037809c97d089d69e927737e589e1 Author: Bitao Hu AuthorDate: Thu, 11 Apr 2024 15:41:32 +08:00 Committer: Thomas Gleixner CommitterDate: Fri, 12 Apr 2024 17:08:05 +02:00 genirq: Avoid summation loops for /proc/interrupts 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 Signed-off-by: Thomas Gleixner Reviewed-by: Liu Song Reviewed-by: Douglas Anderson Link: https://lore.kernel.org/r/20240411074134.30922-4-yaoma@linux.alibaba.com --- 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 1d92532..6c43ef3 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 f348faf..3820931 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 6954e0a..5c320c3 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;