From nobody Mon Jun 8 05:26:23 2026 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 1C0B433E37C; Tue, 2 Jun 2026 19:30:08 +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=1780428610; cv=none; b=GoivXr5UTPk8CuEpoQFDlv/C5pmFAIxBgbmxvmnJeIsCJd3eMyx221IRJThalXqMPTe6aV+Zts+9n8OcEk+XYgbrG2LwG7RbJ9TNojcGL2LdBJbSv+6XbpB+RIIck8vvYsFnIbkUkd+aWRoxvhPz6qb+LvozDD5cyMMaRTftFIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780428610; c=relaxed/simple; bh=wyqDrVyDaiKb/Dd50HeuOcBIXURScVg8vMo2y3rhRnA=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=rITeooID2WXYWld6xteRK0vgv2+v7Mw7xrp9nXiTsQFJaAP+ez3yfcwsDWR+VlUkv2AFqTFdgs0i7hUAkP0FW5HcyGjcQuPuGiyiRrG5hwjMMRYfrZIFfkvsdNaFi6GidsuTxoNzi67X/eBxy4ZwVSW8Fn1RSrUJuSAwfWNxqC4= 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=mqNzv+Xw; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tbZ41ewG; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mqNzv+Xw"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tbZ41ewG" Date: Tue, 02 Jun 2026 19:30:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1780428607; 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=zonIOF5KOYHqNKZghCzv+T7O/UPos7sZT9yPBS9KNo4=; b=mqNzv+Xw27Fhyuc9kyV8di8SqK+WdvPnK1msZDKS0dRgP+vrqTZA9YotojO5BTNfkTTr9t LFPXu7/ByW0g/gD8vvN3Gf4ZwS6Agzf2F5rxn7GLB6n+tGfJHd4btX361EmZXeaqJpqT9l xjnugSGOghm9mgG5wxGP1iGWTa4VT1kOXXnM1+gxpstirVIWZHDDIF+fSIOLep1685cqd5 MRjliYSXGyzrN8rVgOZy0uyBuIcDBGqPLMNxJdi5ShwtCxqYLMb6hzxmow5ppgfEDG4Zvn rDAbUydnjnMhubeSck070GDPYdJmsqgIgSN5TJVYa8fBkvJRJzTVTJa+JjejvA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1780428607; 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=zonIOF5KOYHqNKZghCzv+T7O/UPos7sZT9yPBS9KNo4=; b=tbZ41ewG+2WJuD2fQJLHKcWltUhv0hGoHP/wGKueAvO5kMb705OGQ5KByIlXS//VP6VCjQ FUpimP+rAM30hLBw== From: "tip-bot2 for Frederic Weisbecker" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/nohz] sched/cputime: Provide get_cpu_[idle|iowait]_time_us() off-case Cc: Frederic Weisbecker , Thomas Gleixner , Shrikanth Hegde , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260508131647.43868-14-frederic@kernel.org> References: <20260508131647.43868-14-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178042860613.710.15942255853809969601.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: quoted-printable The following commit has been merged into the timers/nohz branch of tip: Commit-ID: 3b45b4f188f3a0ebd16ab71efd2ffcc7a16ad861 Gitweb: https://git.kernel.org/tip/3b45b4f188f3a0ebd16ab71efd2ffcc7a= 16ad861 Author: Frederic Weisbecker AuthorDate: Fri, 08 May 2026 15:16:45 +02:00 Committer: Thomas Gleixner CommitterDate: Tue, 02 Jun 2026 21:27:26 +02:00 sched/cputime: Provide get_cpu_[idle|iowait]_time_us() off-case The last reason why get_cpu_idle/iowait_time_us() may return -1 now is if the config doesn't support nohz. The ad-hoc replacement solution by cpufreq is to compute jiffies minus the whole busy cputime. Although the intention should provide a coherent low resolution estimation of the idle and iowait time, the implementation is buggy because jiffies don't start at 0. Just provide instead a real get_cpu_[idle|iowait]_time_us() offcase. Signed-off-by: Frederic Weisbecker Signed-off-by: Thomas Gleixner Tested-by: Shrikanth Hegde Link: https://patch.msgid.link/20260508131647.43868-14-frederic@kernel.org --- drivers/cpufreq/cpufreq.c | 29 +---------------------------- include/linux/kernel_stat.h | 3 +++ include/linux/tick.h | 4 ---- kernel/sched/cputime.c | 12 +++++++++--- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 44eb1b7..dda0d34 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -130,38 +130,11 @@ struct kobject *get_governor_parent_kobj(struct cpufr= eq_policy *policy) } EXPORT_SYMBOL_GPL(get_governor_parent_kobj); =20 -static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall) -{ - struct kernel_cpustat kcpustat; - u64 cur_wall_time; - u64 idle_time; - u64 busy_time; - - cur_wall_time =3D jiffies64_to_nsecs(get_jiffies_64()); - - kcpustat_cpu_fetch(&kcpustat, cpu); - - busy_time =3D kcpustat.cpustat[CPUTIME_USER]; - busy_time +=3D kcpustat.cpustat[CPUTIME_SYSTEM]; - busy_time +=3D kcpustat.cpustat[CPUTIME_IRQ]; - busy_time +=3D kcpustat.cpustat[CPUTIME_SOFTIRQ]; - busy_time +=3D kcpustat.cpustat[CPUTIME_STEAL]; - busy_time +=3D kcpustat.cpustat[CPUTIME_NICE]; - - idle_time =3D cur_wall_time - busy_time; - if (wall) - *wall =3D div_u64(cur_wall_time, NSEC_PER_USEC); - - return div_u64(idle_time, NSEC_PER_USEC); -} - u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy) { u64 idle_time =3D get_cpu_idle_time_us(cpu, io_busy ? wall : NULL); =20 - if (idle_time =3D=3D -1ULL) - return get_cpu_idle_time_jiffy(cpu, wall); - else if (!io_busy) + if (!io_busy) idle_time +=3D get_cpu_iowait_time_us(cpu, wall); =20 return idle_time; diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 3680519..512104b 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -133,6 +133,9 @@ static inline bool kcpustat_idle_dyntick(void) } #endif /* CONFIG_NO_HZ_COMMON */ =20 +extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); +extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); + /* Fetch cputime values when vtime is disabled on a CPU */ static inline u64 kcpustat_field_default(enum cpu_usage_stat usage, int cp= u) { diff --git a/include/linux/tick.h b/include/linux/tick.h index 738007d..1cf4651 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -139,8 +139,6 @@ extern bool tick_nohz_idle_got_tick(void); extern ktime_t tick_nohz_get_next_hrtimer(void); extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next); extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu); -extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); -extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); #else /* !CONFIG_NO_HZ_COMMON */ #define tick_nohz_enabled (0) static inline bool tick_nohz_is_active(void) { return false; } @@ -162,8 +160,6 @@ static inline ktime_t tick_nohz_get_sleep_length(ktime_= t *delta_next) *delta_next =3D TICK_NSEC; return *delta_next; } -static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; } -static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1= ; } #endif /* !CONFIG_NO_HZ_COMMON */ =20 /* diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index c91fd67..335d2c1 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -522,6 +522,13 @@ u64 kcpustat_field_iowait(int cpu) nr_iowait_cpu(cpu), ktime_get()); } EXPORT_SYMBOL_GPL(kcpustat_field_iowait); +#else +static u64 kcpustat_field_dyntick(int cpu, enum cpu_usage_stat idx, + bool compute_delta, ktime_t now) +{ + return kcpustat_cpu(cpu).cpustat[idx]; +} +#endif /* CONFIG_NO_HZ_COMMON */ =20 static u64 get_cpu_sleep_time_us(int cpu, enum cpu_usage_stat idx, bool compute_delta, u64 *last_update_time) @@ -557,7 +564,7 @@ static u64 get_cpu_sleep_time_us(int cpu, enum cpu_usag= e_stat idx, * This time is measured via accounting rather than sampling, * and is as accurate as ktime_get() is. * - * Return: -1 if generic vtime is enabled, else total idle time of the @cpu + * Return: total idle time of the @cpu */ u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time) { @@ -581,7 +588,7 @@ EXPORT_SYMBOL_GPL(get_cpu_idle_time_us); * This time is measured via accounting rather than sampling, * and is as accurate as ktime_get() is. * - * Return: -1 if generic vtime is enabled, else total iowait time of @cpu + * Return: total iowait time of @cpu */ u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time) { @@ -589,7 +596,6 @@ u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_ti= me) nr_iowait_cpu(cpu), last_update_time); } EXPORT_SYMBOL_GPL(get_cpu_iowait_time_us); -#endif /* CONFIG_NO_HZ_COMMON */ =20 /* * Use precise platform statistics if available: