Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4637357pxb; Tue, 5 Oct 2021 07:19:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrYA7dJcQxQp1zl2msqaL03o36dQFXyppnewSC8Bnp4Fx/agIftvWNxMFanogM1jzhQY2i X-Received: by 2002:adf:a114:: with SMTP id o20mr20864897wro.95.1633443548323; Tue, 05 Oct 2021 07:19:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633443548; cv=none; d=google.com; s=arc-20160816; b=rSJNSx0xvOvmkgoPbQLtiuQU+aIxxhA+mVAx5x+a90hrYw+AX5m17eoaBH59wzgy40 H4rafbZMGifL4GqoHAaYPvP84evgPp1jfamEy+9K3ZatPl/v3wnE4ehWNtYxcTvNBTKB mB3LljbHWDmHF54/7CTQcGW+VtOXPqg9egFrE3HQw/TkY9RRbO5xPDgr+MBFiu8Ec0is B7VgGuMJ3HOleTqNfk3hHMQuYMgnOu/KwxzDaJbsNkaXjkL330bmRQFUwD0kaW9wgEJb r+FlTokzOxox+oydnPMRG0zBH01jcXopIPscvSLXvMVbaqbye230jxXWsC09LUinQ5Vi YVaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=l6TpAgVxtA6nWkg/ai1HTTudbJAeoQ2gCTt+dNkTQbc=; b=wPkqdIm0giWoYcM5rVLpJOsneQ/u1aEOakIp2wT4YMMhUgqWfB7C0NTYvjpip/TKbj fuEqImE6MjaDrVGX4zF9iDYdBvDom/yGiGdI3pjOoojbpEWDV1YYCC0yuxpO5W/LTg1z kvYF1uHVd6xM2aSOrr1EodCtrw9PYAn1HFAgz5/XuBZwDv7PGCuq2BwODvdagtI9+ZPt SWkhlM9KmoOIbkgrqY9mft4oU9yqHdMDDi3QsoLYGX1kxQgaUslGHEqrOw1giOL6EKjh M4686xREDeLS4wn8tR+jnPRZk9Oc3rGgKmIR93jui/XAWgy6Gn0T2W9C134UheVwZoSl hJ4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2ot32Q7n; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k11si21414121ejk.702.2021.10.05.07.18.39; Tue, 05 Oct 2021 07:19:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2ot32Q7n; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236390AbhJEOPl (ORCPT + 99 others); Tue, 5 Oct 2021 10:15:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236238AbhJEOO3 (ORCPT ); Tue, 5 Oct 2021 10:14:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 085A4C0617A7; Tue, 5 Oct 2021 07:12:17 -0700 (PDT) Date: Tue, 05 Oct 2021 14:12:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1633443135; 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=l6TpAgVxtA6nWkg/ai1HTTudbJAeoQ2gCTt+dNkTQbc=; b=2ot32Q7nD+4Ra9lQEjetmP/xKOfaUomA8EWN3zTKLtYh3sz8dJPsMtg7lwpW9CN6VVWAWe HsumMCLiHLKC8zU/nQrSpSH0erjkhLHO8gRvgSPb7bt2AsG6fOA+xbdnTX8aasYtASskyf +EWj0Rl703cDnUEodeIgQOIB13uuaP3tCWZwp8AyVdARHtTN+1Pp5JI/z/f2bH7+L1R/s5 vWcvpu4mrrtMSDy4v+xLNWZnSOfIcUj3X58iLq5cbBkDmNQ+Z+7sf1KwxZhp8Sd2QcduxN ccvQbqDGr5KzsJeotnYDmyStHX+lax3YkuICtz+30/Hx2f8QwBJ7Xgh1KToIdg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1633443135; 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=l6TpAgVxtA6nWkg/ai1HTTudbJAeoQ2gCTt+dNkTQbc=; b=FRb26HITfjE9PB2TPoKwOtEsRhrSsfJfelQf7pAWUqOpzkajjIE53ft/Ab6pcdPr/HmWRk nfVvjgKHcOmPbABQ== From: "tip-bot2 for Josh Don" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] fs/proc/uptime.c: Fix idle time reporting in /proc/uptime Cc: Luigi Rizzo , Josh Don , "Peter Zijlstra (Intel)" , Eric Dumazet , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210827165438.3280779-1-joshdon@google.com> References: <20210827165438.3280779-1-joshdon@google.com> MIME-Version: 1.0 Message-ID: <163344313490.25758.8126200201306491784.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: a130e8fbc7de796eb6e680724d87f4737a26d0ac Gitweb: https://git.kernel.org/tip/a130e8fbc7de796eb6e680724d87f4737a26d0ac Author: Josh Don AuthorDate: Fri, 27 Aug 2021 09:54:38 -07:00 Committer: Peter Zijlstra CommitterDate: Tue, 05 Oct 2021 15:51:35 +02:00 fs/proc/uptime.c: Fix idle time reporting in /proc/uptime /proc/uptime reports idle time by reading the CPUTIME_IDLE field from the per-cpu kcpustats. However, on NO_HZ systems, idle time is not continually updated on idle cpus, leading this value to appear incorrectly small. /proc/stat performs an accounting update when reading idle time; we can use the same approach for uptime. With this patch, /proc/stat and /proc/uptime now agree on idle time. Additionally, the following shows idle time tick up consistently on an idle machine: (while true; do cat /proc/uptime; sleep 1; done) | awk '{print $2-prev; prev=$2}' Reported-by: Luigi Rizzo Signed-off-by: Josh Don Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Eric Dumazet Link: https://lkml.kernel.org/r/20210827165438.3280779-1-joshdon@google.com --- fs/proc/stat.c | 4 ++-- fs/proc/uptime.c | 14 +++++++++----- include/linux/kernel_stat.h | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/proc/stat.c b/fs/proc/stat.c index 6561a06..4fb8729 100644 --- a/fs/proc/stat.c +++ b/fs/proc/stat.c @@ -24,7 +24,7 @@ #ifdef arch_idle_time -static u64 get_idle_time(struct kernel_cpustat *kcs, int cpu) +u64 get_idle_time(struct kernel_cpustat *kcs, int cpu) { u64 idle; @@ -46,7 +46,7 @@ static u64 get_iowait_time(struct kernel_cpustat *kcs, int cpu) #else -static u64 get_idle_time(struct kernel_cpustat *kcs, int cpu) +u64 get_idle_time(struct kernel_cpustat *kcs, int cpu) { u64 idle, idle_usecs = -1ULL; diff --git a/fs/proc/uptime.c b/fs/proc/uptime.c index 5a1b228..deb99bc 100644 --- a/fs/proc/uptime.c +++ b/fs/proc/uptime.c @@ -12,18 +12,22 @@ static int uptime_proc_show(struct seq_file *m, void *v) { struct timespec64 uptime; struct timespec64 idle; - u64 nsec; + u64 idle_nsec; u32 rem; int i; - nsec = 0; - for_each_possible_cpu(i) - nsec += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE]; + idle_nsec = 0; + for_each_possible_cpu(i) { + struct kernel_cpustat kcs; + + kcpustat_cpu_fetch(&kcs, i); + idle_nsec += get_idle_time(&kcs, i); + } ktime_get_boottime_ts64(&uptime); timens_add_boottime(&uptime); - idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem); + idle.tv_sec = div_u64_rem(idle_nsec, NSEC_PER_SEC, &rem); idle.tv_nsec = rem; seq_printf(m, "%lu.%02lu %lu.%02lu\n", (unsigned long) uptime.tv_sec, diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 44ae1a7..69ae6b2 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -102,6 +102,7 @@ extern void account_system_index_time(struct task_struct *, u64, enum cpu_usage_stat); extern void account_steal_time(u64); extern void account_idle_time(u64); +extern u64 get_idle_time(struct kernel_cpustat *kcs, int cpu); #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE static inline void account_process_tick(struct task_struct *tsk, int user)