Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp426635rdb; Tue, 23 Jan 2024 04:13:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtR0MNsumwoh0rU2HtKxr1V+oSHzlmErXuiiOOOvYrsoh8pu6b+oRn8Z71yjK0aK2WZLNy X-Received: by 2002:a05:622a:1711:b0:42a:7e0:35dd with SMTP id h17-20020a05622a171100b0042a07e035ddmr814074qtk.129.1706011991556; Tue, 23 Jan 2024 04:13:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706011991; cv=pass; d=google.com; s=arc-20160816; b=UcSCIsKl4xJW0+gN4ZO4pcs2JQkYoVFcoaPPUG3949It8eYZuLwm0arNNhMOYjR7Az XKSVZmy0JLnnbqXAoGv1Xn6Pa8xqrCT94zIN7KrR1rD/wwHqFrbOrclmqNQSRy0UmwS5 IUmoGatNWl0Df4/Petg6b3FRqdNqRJVBvvF/TYKbA7C2SQDKTVmfNvg88MJyDBGS6+tu +nsu0FzyslGsYfF4TGncaMucQraBucckGlXl2vzBHld5A/rpOY8qDdxpDT2i+vQgLU8S AQ+VDr7imyhTHNUwnAOHu/haqY2XFhgZw9M9M0kV3DAwA3YkoCRYoGXd5Ch9l5d8xX7S 6p/Q== 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; bh=D1+Iacim/WK875f9j1gscc+nQfeYY4auE12GXEvGDro=; fh=E8Kf3tAYQUJQiYwjk7DEi5yT6N0tsnUPOgoJKt1bx2o=; b=KV+/VrFR3s+Pi3bIwookdNlq3GFslu6OVZ5XZfTrHLVDAkeRWnnkrZziY+j4wWJ+w8 lPutpROJafxtj7P6Ahq9SkxdiTQhSAqqZ2Cj46XYnWwfsDR/B8ysZyCHnxbKSaBJxq81 fNVUMOngIpiBcQ0cX6tQgmGkxeQoHfbe1lPEPjKKatCdXzrzV1wdbv52A7iLamEZm/kt MYL489kjJ/6pPzDVF9+s3eR59T+4YmB9PZM8+RNCuoEjpjaqJiAUKEsJcj8XjCfjQ+le trk0SbHt/j//nBYxairwqbuiV6Z36AvGjcRcWeiZRD+jZRIYotyfl7DvSB7MM2+U7Zou PsDA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-35235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35235-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y9-20020a05622a164900b0042a09c94802si7639789qtj.563.2024.01.23.04.13.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 04:13:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-35235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35235-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 53A7A1C21655 for ; Tue, 23 Jan 2024 12:13:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00B675EE88; Tue, 23 Jan 2024 12:12:45 +0000 (UTC) Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (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 164F85DF30 for ; Tue, 23 Jan 2024 12:12:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706011964; cv=none; b=TqJ/euDQWThaoihwDZ8c8Vbp6tgyK6+1LyHzNUyj70p6W2TT1J12SS71DGqRDJZheEcuMUYpUyVRzzxYg1Pb2fN0eNNxa/ozTh5OG/aA/zx1TiE8+8fokuxaHR+XaT0CP/EfNhbNFQX7fqdETxvPz/ijVZg/SCBSAKoic6211sI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706011964; c=relaxed/simple; bh=bf8N058MM2i5Zf5QpJiVM/3LphTudf9h6j37YkLGJZg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=RQU5+zOppUetXGF+PmUmYjXT1hzk2Wzt4MQeV1SOecucqZr6lkF5KiyTYUSfcY0eonx2X0bBSXDaMbsHX87rYk7x3belaw3jMN8b7wGq+ulKPkGOF0G84fi5759sW0RG7kI1XfldknnWLYdfrSmoKRlW3V0DXVlk5wa0WWCAmIQ= 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; arc=none smtp.client-ip=115.124.30.131 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 X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R151e4;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=8;SR=0;TI=SMTPD_---0W.CnxF7_1706011949; Received: from localhost.localdomain(mailfrom:yaoma@linux.alibaba.com fp:SMTPD_---0W.CnxF7_1706011949) by smtp.aliyun-inc.com; Tue, 23 Jan 2024 20:12:32 +0800 From: Bitao Hu To: dianders@chromium.org, akpm@linux-foundation.org, pmladek@suse.com, tglx@linutronix.de, maz@kernel.org, liusong@linux.alibaba.com Cc: linux-kernel@vger.kernel.org, Bitao Hu Subject: [PATCH 1/3] watchdog/softlockup: low-overhead detection of interrupt storm Date: Tue, 23 Jan 2024 20:12:21 +0800 Message-Id: <20240123121223.22318-2-yaoma@linux.alibaba.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20240123121223.22318-1-yaoma@linux.alibaba.com> References: <20240123121223.22318-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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following softlockup is caused by interrupt storm, but it cannot be identified from the call tree. Because the call tree is just a snapshot and doesn't fully capture the behavior of the CPU during the soft lockup. watchdog: BUG: soft lockup - CPU#28 stuck for 23s! [fio:83921] ... Call trace: __do_softirq+0xa0/0x37c __irq_exit_rcu+0x108/0x140 irq_exit+0x14/0x20 __handle_domain_irq+0x84/0xe0 gic_handle_irq+0x80/0x108 el0_irq_naked+0x50/0x58 Therefore,I think it is necessary to report CPU utilization during the softlockup_thresh period (report once every sample_period, for a total of 5 reportings), like this: watchdog: BUG: soft lockup - CPU#28 stuck for 23s! [fio:83921] CPU#28 Utilization every 4s during lockup: #1: 0.0% system, 0.0% softirq, 100.0% hardirq, 0.0% idle #2: 0.0% system, 0.0% softirq, 100.0% hardirq, 0.0% idle #3: 0.0% system, 0.0% softirq, 100.0% hardirq, 0.0% idle #4: 0.0% system, 0.0% softirq, 100.0% hardirq, 0.0% idle #5: 0.0% system, 0.0% softirq, 100.0% hardirq, 0.0% idle ... This would be helpful in determining whether an interrupt storm has occurred or in identifying the cause of the softlockup. The criteria for determination are as follows: a. If the hardirq utilization is high, then interrupt storm should be considered and the root cause cannot be determined from the call tree. b. If the softirq utilization is high, then we could analyze the call tree but it may cannot reflect the root cause. c. If the system utilization is high, then we could analyze the root cause from the call tree. Signed-off-by: Bitao Hu --- kernel/watchdog.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/kernel/watchdog.c b/kernel/watchdog.c index 81a8862295d6..9fad10e0a147 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include @@ -441,6 +443,58 @@ static int is_softlockup(unsigned long touch_ts, return 0; } +#ifdef CONFIG_IRQ_TIME_ACCOUNTING +static DEFINE_PER_CPU(u64, cpustat_old[NR_STATS]); +static DEFINE_PER_CPU(u64, cpustat_diff[5][NR_STATS]); +static DEFINE_PER_CPU(int, cpustat_tail); + +static void update_cpustat(void) +{ + u64 *old = this_cpu_ptr(cpustat_old); + u64 (*diff)[NR_STATS] = this_cpu_ptr(cpustat_diff); + int tail = this_cpu_read(cpustat_tail), i; + struct kernel_cpustat kcpustat; + u64 *cpustat = kcpustat.cpustat; + + kcpustat_cpu_fetch(&kcpustat, smp_processor_id()); + for (i = 0; i < NR_STATS; i++) { + diff[tail][i] = cpustat[i] - old[i]; + old[i] = cpustat[i]; + } + this_cpu_write(cpustat_tail, (tail + 1) % 5); +} + +static void print_cpustat(void) +{ + int i, j, k; + u64 a[5][NR_STATS], b[5][NR_STATS]; + u64 (*diff)[NR_STATS] = this_cpu_ptr(cpustat_diff); + int tail = this_cpu_read(cpustat_tail); + u32 period_us = sample_period / 1000; + + for (i = 0; i < 5; i++) { + for (j = 0; j < NR_STATS; j++) { + a[i][j] = 100 * (diff[i][j] / 1000); + b[i][j] = 10 * do_div(a[i][j], period_us); + do_div(b[i][j], period_us); + } + } + printk(KERN_CRIT "CPU#%d Utilization every %us during lockup:\n", + smp_processor_id(), period_us/1000000); + for (k = 0, i = tail; k < 5; k++, i = (i + 1) % 5) { + printk(KERN_CRIT "\t#%d: %llu.%llu%% system,\t%llu.%llu%% softirq,\t" + "%llu.%llu%% hardirq,\t%llu.%llu%% idle\n", k+1, + a[i][CPUTIME_SYSTEM], b[i][CPUTIME_SYSTEM], + a[i][CPUTIME_SOFTIRQ], b[i][CPUTIME_SOFTIRQ], + a[i][CPUTIME_IRQ], b[i][CPUTIME_IRQ], + a[i][CPUTIME_IDLE], b[i][CPUTIME_IDLE]); + } +} +#else +static inline void update_cpustat(void) { } +static inline void print_cpustat(void) { } +#endif + /* watchdog detector functions */ static DEFINE_PER_CPU(struct completion, softlockup_completion); static DEFINE_PER_CPU(struct cpu_stop_work, softlockup_stop_work); @@ -504,6 +558,9 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) */ period_ts = READ_ONCE(*this_cpu_ptr(&watchdog_report_ts)); + /* update cpu usage stat */ + update_cpustat(); + /* Reset the interval when touched by known problematic code. */ if (period_ts == SOFTLOCKUP_DELAY_REPORT) { if (unlikely(__this_cpu_read(softlockup_touch_sync))) { @@ -539,6 +596,7 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) pr_emerg("BUG: soft lockup - CPU#%d stuck for %us! [%s:%d]\n", smp_processor_id(), duration, current->comm, task_pid_nr(current)); + print_cpustat(); print_modules(); print_irqtrace_events(current); if (regs) -- 2.37.1 (Apple Git-137.1)