Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1802029rbb; Tue, 27 Feb 2024 01:18:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXxT3RX9v8UAtlUtC7hxUhLMhhgLKE+TFRkTUUJC+7GNm/o1I7YQrALlm4ZnXpmfzr/zxvV1PlfzH6eLVW2jrsGE2EDU5lo4pSsqtaRqQ== X-Google-Smtp-Source: AGHT+IG1LTBwf4lhx2wBLZ6LI8RiuTuUuLa6EiTAHhao4HPlVHeFGZTe/AhGd3RfeF2jDvExbAE1 X-Received: by 2002:a05:6a00:3217:b0:6e4:4320:27cf with SMTP id bm23-20020a056a00321700b006e4432027cfmr8260476pfb.32.1709025499979; Tue, 27 Feb 2024 01:18:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709025499; cv=pass; d=google.com; s=arc-20160816; b=UTBAq0DR8EfoHAGmnMF4Nf2ZnjtVeNMHD0+gz/VEAN70+gLu6D2xMclHX5DUyE24IY SkOGXkXK32+dvLZW+zD9TWyI11Z3KQODJuZNfm1sXcCzC77UPfgqw6TO3aD7DkHhc1Zs DgXZMqmIQnNGs6iw3IyLao1oeAE8lLmNERbMEmVBObJM4109PGVyM0ny2ez/cP/HkaD/ B8BgZ/5VzoDKmQ6HOFwu2/lIQf3AlsVATTPJBNFBvEfPn9NUGycKU68VqfnZlk2jHuub 0jqk8xANAABvZ8Fd/ozkW4i+xXjgwfFi91wOcm7FFztHQeGnzDYkTQ2+SvcpxEmmOpIS 7khw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=bKyExLaJsMJFtDGzvQca2erL9AyFIbFelzMrpVgTicU=; fh=GBeKqO3WLH1djTmf+MOX613dtVoTWKZiA2KHM7GjkXE=; b=tp5Q6odTBNPzrxZpbEDI50htokCvMcZ8WByHdr0tJZ3DxarFgASN53q6Pv7WPPP32f Z44c4iqCNIcaCnIcbwHRb8fz8LoEf361xXDHXJ77e4wdHnOmVFtUOjasimBzJswS44ht HckBmRs4rtg3BuheGvH2l0m4VsOOIg9ZX3yLX/6X/4vveq+BgZVM0U+va0+qWhb4lWIX rvYWjWDNrV7lbhSRdO9RJPte5Zd4M+I+N0uNjcYFYYSiLrRmerVmaIL/SFBUKK0OJCC5 BgGQvrpGXsxLeZomd5b9EcIEbQ31DccM0UzeA6N0jheXIrPva7/Zzjw15Kdp3GRiBpLo P//Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=rzlV55dA; 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-82901-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82901-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 ln6-20020a056a003cc600b006e4bb525845si5191458pfb.274.2024.02.27.01.18.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 01:18:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82901-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=rzlV55dA; 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-82901-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82901-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 B831BB273DE for ; Tue, 27 Feb 2024 09:03:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E1DB13698B; Tue, 27 Feb 2024 09:02:58 +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="rzlV55dA" Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (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 EAAA9135A65; Tue, 27 Feb 2024 09:02:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709024576; cv=none; b=U2X2dNc36yEKBaUNMZqz0Tylq7fdqsb1b5kNaVF2e9ayc3i9kE8p8gqrkcf3DxnAASR/tsC7yaaJSec2KnQ0BqGonPMQ+a5QkIw2QnLZ4RNF6yyiC6q3yQ1Ku8TcvIwqQ4lEngf227+Ocs48SkszAIBQZ3lZLna1Em1NMoWWOZk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709024576; c=relaxed/simple; bh=Um1XAVigevnv14Yo2UsDOc+ic7fQArkcwp7Zqnjv6sk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FArA0TrYoVFNMTc5yVdv8yrDPm4lF60CA8q3bSXvBa8wRa/x2KTQu1Xid2yYyzIKXP+yJCKW3Nvwht3LXQWjGgzg1jWELIuQgUBJOkVG8vvE9Z2ZAiQ3RyH4NsdxGRqtWhmuk9NeipL0LDCH1lv0dSZM+pS8LU89OHwAOLbpZQw= 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=rzlV55dA; arc=none smtp.client-ip=115.124.30.99 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=1709024565; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=bKyExLaJsMJFtDGzvQca2erL9AyFIbFelzMrpVgTicU=; b=rzlV55dA/EulHOyzrz+tKIVP/GSIUV5b5wsi3x62+7/vlLRTp0R5+AOujcj0MTbXU/IbbX+RAnUNwYfLbzCYihy9bffR23tuPwGJ6b5Odfkf7R7sGNbEeN4D2Jt/RBhvF9S6UqzOiePdPz4MYefYcMxOPvDrviPaL4aGJG+33OA= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R311e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=liusong@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0W1M9Gjj_1709024562; Received: from 30.178.80.107(mailfrom:liusong@linux.alibaba.com fp:SMTPD_---0W1M9Gjj_1709024562) by smtp.aliyun-inc.com; Tue, 27 Feb 2024 17:02:44 +0800 Message-ID: <49144bb6-dd90-44ef-965a-aa5af8d568b1@linux.alibaba.com> Date: Tue, 27 Feb 2024 17:02:41 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCHv10 4/4] watchdog/softlockup: report the most frequent interrupts To: Bitao Hu , dianders@chromium.org, tglx@linutronix.de, 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 References: <20240226020939.45264-1-yaoma@linux.alibaba.com> <20240226020939.45264-5-yaoma@linux.alibaba.com> From: Liu Song In-Reply-To: <20240226020939.45264-5-yaoma@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2024/2/26 10:09, Bitao Hu 写道: > When the watchdog determines that the current soft lockup is due > to an interrupt storm based on CPU utilization, reporting the > most frequent interrupts could be good enough for further > troubleshooting. > > Below is an example of interrupt storm. The call tree does not > provide useful information, but we can analyze which interrupt > caused the soft lockup by comparing the counts of interrupts. > > [ 638.870231] watchdog: BUG: soft lockup - CPU#9 stuck for 26s! [swapper/9:0] > [ 638.870825] CPU#9 Utilization every 4s during lockup: > [ 638.871194] #1: 0% system, 0% softirq, 100% hardirq, 0% idle > [ 638.871652] #2: 0% system, 0% softirq, 100% hardirq, 0% idle > [ 638.872107] #3: 0% system, 0% softirq, 100% hardirq, 0% idle > [ 638.872563] #4: 0% system, 0% softirq, 100% hardirq, 0% idle > [ 638.873018] #5: 0% system, 0% softirq, 100% hardirq, 0% idle > [ 638.873494] CPU#9 Detect HardIRQ Time exceeds 50%. Most frequent HardIRQs: > [ 638.873994] #1: 330945 irq#7 > [ 638.874236] #2: 31 irq#82 > [ 638.874493] #3: 10 irq#10 > [ 638.874744] #4: 2 irq#89 > [ 638.874992] #5: 1 irq#102 > ... > [ 638.875313] Call trace: > [ 638.875315] __do_softirq+0xa8/0x364 > > Signed-off-by: Bitao Hu > --- > kernel/watchdog.c | 115 ++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 111 insertions(+), 4 deletions(-) > > diff --git a/kernel/watchdog.c b/kernel/watchdog.c > index 69e72d7e461d..c9d49ae8d045 100644 > --- a/kernel/watchdog.c > +++ b/kernel/watchdog.c > @@ -12,22 +12,25 @@ > > #define pr_fmt(fmt) "watchdog: " fmt > > -#include > #include > -#include > #include > +#include > +#include > #include > +#include > #include > +#include > #include > +#include > +#include > #include > #include > + > #include > #include > #include > -#include > > #include > -#include > > static DEFINE_MUTEX(watchdog_mutex); > > @@ -417,13 +420,104 @@ static void print_cpustat(void) > } > } > > +#define HARDIRQ_PERCENT_THRESH 50 > +#define NUM_HARDIRQ_REPORT 5 > +struct irq_counts { > + int irq; > + u32 counts; > +}; > + > +static DEFINE_PER_CPU(bool, snapshot_taken); > + > +/* Tabulate the most frequent interrupts. */ > +static void tabulate_irq_count(struct irq_counts *irq_counts, int irq, u32 counts, int rank) > +{ > + int i; > + struct irq_counts new_count = {irq, counts}; > + > + for (i = 0; i < rank; i++) { > + if (counts > irq_counts[i].counts) > + swap(new_count, irq_counts[i]); > + } > +} > + > +/* > + * If the hardirq time exceeds HARDIRQ_PERCENT_THRESH% of the sample_period, > + * then the cause of softlockup might be interrupt storm. In this case, it > + * would be useful to start interrupt counting. > + */ > +static bool need_counting_irqs(void) > +{ > + u8 util; > + int tail = __this_cpu_read(cpustat_tail); > + > + tail = (tail + NUM_HARDIRQ_REPORT - 1) % NUM_HARDIRQ_REPORT; > + util = __this_cpu_read(cpustat_util[tail][STATS_HARDIRQ]); > + return util > HARDIRQ_PERCENT_THRESH; > +} > + > +static void start_counting_irqs(void) > +{ > + if (!__this_cpu_read(snapshot_taken)) { > + kstat_snapshot_irqs(); > + __this_cpu_write(snapshot_taken, true); > + } > +} > + > +static void stop_counting_irqs(void) > +{ > + __this_cpu_write(snapshot_taken, false); > +} > + > +static void print_irq_counts(void) > +{ > + unsigned int i, count; > + struct irq_counts irq_counts_sorted[NUM_HARDIRQ_REPORT] = { > + {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0} > + }; > + > + if (__this_cpu_read(snapshot_taken)) { > + for_each_active_irq(i) { > + count = kstat_get_irq_since_snapshot(i); > + tabulate_irq_count(irq_counts_sorted, i, count, NUM_HARDIRQ_REPORT); > + } > + > + /* > + * We do not want the "watchdog: " prefix on every line, > + * hence we use "printk" instead of "pr_crit". > + */ > + printk(KERN_CRIT "CPU#%d Detect HardIRQ Time exceeds %d%%. Most frequent HardIRQs:\n", > + smp_processor_id(), HARDIRQ_PERCENT_THRESH); > + > + for (i = 0; i < NUM_HARDIRQ_REPORT; i++) { > + if (irq_counts_sorted[i].irq == -1) > + break; > + > + printk(KERN_CRIT "\t#%u: %-10u\tirq#%d\n", > + i + 1, irq_counts_sorted[i].counts, > + irq_counts_sorted[i].irq); > + } > + > + /* > + * If the hardirq time is less than HARDIRQ_PERCENT_THRESH% in the last > + * sample_period, then we suspect the interrupt storm might be subsiding. > + */ > + if (!need_counting_irqs()) > + stop_counting_irqs(); > + } > +} > + > static void report_cpu_status(void) > { > print_cpustat(); > + print_irq_counts(); > } > #else > static inline void update_cpustat(void) { } > static inline void report_cpu_status(void) { } > +static inline bool need_counting_irqs(void) { return false; } > +static inline void start_counting_irqs(void) { } > +static inline void stop_counting_irqs(void) { } > #endif > > /* > @@ -527,6 +621,18 @@ static int is_softlockup(unsigned long touch_ts, > unsigned long now) > { > if ((watchdog_enabled & WATCHDOG_SOFTOCKUP_ENABLED) && watchdog_thresh) { > + /* > + * If period_ts has not been updated during a sample_period, then > + * in the subsequent few sample_periods, period_ts might also not > + * be updated, which could indicate a potential softlockup. In > + * this case, if we suspect the cause of the potential softlockup > + * might be interrupt storm, then we need to count the interrupts > + * to find which interrupt is storming. > + */ > + if (time_after_eq(now, period_ts + get_softlockup_thresh() / NUM_SAMPLE_PERIODS) && > + need_counting_irqs()) > + start_counting_irqs(); > + > /* Warn about unreasonable delays. */ > if (time_after(now, period_ts + get_softlockup_thresh())) > return now - touch_ts; > @@ -549,6 +655,7 @@ static DEFINE_PER_CPU(struct cpu_stop_work, softlockup_stop_work); > static int softlockup_fn(void *data) > { > update_touch_ts(); > + stop_counting_irqs(); > complete(this_cpu_ptr(&softlockup_completion)); > > return 0; Looks good. Reviewed-by: Liu Song