Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp244942lqg; Thu, 11 Apr 2024 01:06:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1A9a5rGL0BXRcXkoqdKAZ8DbxK0/RcCssEdXfb93KYw07ZSMznU3q6AkfgtGflIQYTD/O0GBKx50bsmFqztTdkjr+DoG26mrksxZUtQ== X-Google-Smtp-Source: AGHT+IF6ml3ZpIzZ7J5/W39+SGNSYcUL0HSTzCIGf+yEtO7u4NOa/7XHdZowsUYgSGqqec/g6S9y X-Received: by 2002:a17:90a:5ac2:b0:29c:761e:3955 with SMTP id n60-20020a17090a5ac200b0029c761e3955mr4782093pji.17.1712822785181; Thu, 11 Apr 2024 01:06:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712822785; cv=pass; d=google.com; s=arc-20160816; b=MHcGUOFxELy0mVKpUkqRus2mVXIbz2WJUrPmx4H8xzlMaSdnGxRkC+my1DVMQ4oqvp ofsQ8hrc5V4M3Eio0VYA8R6ZnyD1XhPXQ3kthFXP0cqIwTKVgFphU52NZ9olw7xbRAfA N3ngFm820eSZ0IkzZ4csdI1MZtdvesxgq/CCtQ3KizGuiikrAbJ+5srRGG4XKY4WTiDL CKwGybKNQ5ezp7wid5l/aWhAFtFjxLqjGy0VQ3DnijpHWgJHM9zhp5w1ESCS2PfrAyHd bHP/JTqfxYVliN2iX7ncm4igr4SLSVbY08NJZ6qU2TVKHLeFgeIKCfNWAsoF6+oGLomK J5OA== 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=gF7qIKS2+QnTwBDX4CgdxCnFsGoEC/Sga8w5/JAmLtI=; fh=h1xXNY8doO7YpZZxFq7Tt2h1zNi8L7URk9NotQAeleE=; b=ia5TYjA2/wmlU2ajnOWeOS6qS71oCAzuAVT3inOlOL/ekUJtcddPP5RJjRZIqaQnTB tT11a80Y2u7j43AkQQcmZYHPABgCwG7rx5blRlsXnj45FA/3Xw5QB95wsRg/3AsvE8ZK SOVmoLhQAgiuaYDx6Dtm78rP9jbW+uzLgUEbqXsun0Ok0+R3Mi6lgy1lIGVh7axCUbfq paAU9ROVaclbY78hsKWcY8AlAUEMCib++YbW+MAExs4sw7Dcg27tFl2PBg9PQ6koLL8z pAAwWfqbUMopc2nI4h+V+AeHdzg+ORygY1CGVHZQBVY8Lpf/deT77HzAM/xXEZMxaPzP 1Jaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b="Dr/I0tWU"; 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-140008-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140008-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 sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p9-20020a17090a348900b002a484c67ad6si4919396pjb.1.2024.04.11.01.06.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 01:06:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140008-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b="Dr/I0tWU"; 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-140008-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140008-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B3667B2A93A for ; Thu, 11 Apr 2024 07:42:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7D6213FD7D; Thu, 11 Apr 2024 07:41:51 +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="Dr/I0tWU" Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 64CD913E8AB; Thu, 11 Apr 2024 07:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712821311; cv=none; b=m52GUuatzdXaGCQF+PjG5uWLKEeJtzO2v2sl3YXiiWieXf9ukc41oD1gkYCy386XH6kFO394Mpusa5c6T+UWLRl9Fs6bkNeTEnrsWEmt4tWla9WGvidlBws2P1k3TEUIJtM2s5DwFQy9sWJo48f45J/y/QSIA9uXpZtp8u5t7DE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712821311; c=relaxed/simple; bh=wSmtT/QGZvyDyFmReyInpkD4Pd8xYPNmrS6RmhpsL/Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EQwAR9Wtm3UXl43K7JHLYHLMgDLXP2QHL795T9huMi7M87WN8QDeAQJx/I/CN/4Nxa8qdxkDroPaORtnV7GLCVFu4mRJCMgpPYCULxL1JVf30dCg6pgN83Dz/B2hbBM/O3zWrh5nLaSQH87OphSJCG87wtV4aWtsHGL5GFZLiiQ= 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=Dr/I0tWU; arc=none smtp.client-ip=115.124.30.97 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=1712821306; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=gF7qIKS2+QnTwBDX4CgdxCnFsGoEC/Sga8w5/JAmLtI=; b=Dr/I0tWU+XAeSdKP9g2oT/P1UU0nCOamOaYg2E8XkfVOmf59fGZztWBi/16aSkWZW0y5/2t4DcvOfo3NNCajIhO3+tWDuN97jp9VbWD7FpPZZK70Wk80XklrpO/qp5YZ5SaEMViqVECyZ6Tta8S8Gbm9+WLHu4C1YYkPdunng34= 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=ay29a033018046051;MF=yaoma@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0W4KbQ9Q_1712821302; Received: from localhost.localdomain(mailfrom:yaoma@linux.alibaba.com fp:SMTPD_---0W4KbQ9Q_1712821302) by smtp.aliyun-inc.com; Thu, 11 Apr 2024 15:41:44 +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 2/5] genirq: Provide a snapshot mechanism for interrupt statistics Date: Thu, 11 Apr 2024 15:41:31 +0800 Message-Id: <20240411074134.30922-3-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 The soft lockup detector lacks a mechanism to identify interrupt storms as root cause of a lockup. To enable this the detector needs a mechanism to snapshot the interrupt count statistics on a CPU when the detector observes a potential lockup scenario and compare that against the interrupt count when it warns about the lockup later on. The number of interrupts in that period give a hint whether the lockup might be caused by an interrupt storm. Instead of having extra storage in the lockup detector and accessing the internals of the interrupt descriptor directly, add a snapshot member to the per CPU irq_desc::kstat_irq structure and provide interfaces to take a snapshot of all interrupts on the current CPU and to retrieve the delta of a specific interrupt later on. Originally-by: Thomas Gleixner Signed-off-by: Bitao Hu --- include/linux/irqdesc.h | 4 ++++ include/linux/kernel_stat.h | 8 ++++++++ kernel/irq/Kconfig | 4 ++++ kernel/irq/irqdesc.c | 25 +++++++++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h index c28612674acb..fd091c35d572 100644 --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h @@ -20,9 +20,13 @@ struct pt_regs; /** * struct irqstat - interrupt statistics * @cnt: real-time interrupt count + * @ref: snapshot of interrupt count */ struct irqstat { unsigned int cnt; +#ifdef CONFIG_GENERIC_IRQ_STAT_SNAPSHOT + unsigned int ref; +#endif }; /** diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 9935f7ecbfb9..9c042c6384bb 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -79,6 +79,14 @@ static inline unsigned int kstat_cpu_softirqs_sum(int cpu) return sum; } +#ifdef CONFIG_GENERIC_IRQ_STAT_SNAPSHOT +extern void kstat_snapshot_irqs(void); +extern unsigned int kstat_get_irq_since_snapshot(unsigned int irq); +#else +static inline void kstat_snapshot_irqs(void) { } +static inline unsigned int kstat_get_irq_since_snapshot(unsigned int irq) { return 0; } +#endif + /* * Number of interrupts per specific IRQ source, since bootup */ diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig index 2531f3496ab6..529adb1f5859 100644 --- a/kernel/irq/Kconfig +++ b/kernel/irq/Kconfig @@ -108,6 +108,10 @@ config GENERIC_IRQ_MATRIX_ALLOCATOR config GENERIC_IRQ_RESERVATION_MODE bool +# Snapshot for interrupt statistics +config GENERIC_IRQ_STAT_SNAPSHOT + bool + # Support forced irq threading config IRQ_FORCED_THREADING bool diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index b59b79200ad7..f348faffa7b4 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -994,6 +994,31 @@ static unsigned int kstat_irqs(unsigned int irq) return sum; } +#ifdef CONFIG_GENERIC_IRQ_STAT_SNAPSHOT + +void kstat_snapshot_irqs(void) +{ + struct irq_desc *desc; + unsigned int irq; + + for_each_irq_desc(irq, desc) { + if (!desc->kstat_irqs) + continue; + this_cpu_write(desc->kstat_irqs->ref, this_cpu_read(desc->kstat_irqs->cnt)); + } +} + +unsigned int kstat_get_irq_since_snapshot(unsigned int irq) +{ + struct irq_desc *desc = irq_to_desc(irq); + + if (!desc || !desc->kstat_irqs) + return 0; + return this_cpu_read(desc->kstat_irqs->cnt) - this_cpu_read(desc->kstat_irqs->ref); +} + +#endif + /** * kstat_irqs_usr - Get the statistics for an interrupt from thread context * @irq: The interrupt number -- 2.37.1 (Apple Git-137.1)