]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
cpufreq: ondemand: Simplify idle cputime granularity test
authorFrederic Weisbecker <frederic@kernel.org>
Wed, 28 Jan 2026 16:05:27 +0000 (17:05 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 28 Jan 2026 21:24:58 +0000 (22:24 +0100)
cpufreq calls get_cpu_idle_time_us() just to know if idle cputime
accounting has a nanoseconds granularity.

Use the appropriate indicator instead to make that deduction.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://patch.msgid.link/aXozx0PXutnm8ECX@localhost.localdomain
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq_ondemand.c
include/linux/tick.h
kernel/time/hrtimer.c
kernel/time/tick-internal.h
kernel/time/tick-sched.c
kernel/time/timer.c

index a6ecc203f7b7f37d32f4e44fb6eaa81ec7e481b5..bb7db82930e4cad43c4cd1432ed2d4769eb24aa2 100644 (file)
@@ -334,17 +334,12 @@ static void od_free(struct policy_dbs_info *policy_dbs)
 static int od_init(struct dbs_data *dbs_data)
 {
        struct od_dbs_tuners *tuners;
-       u64 idle_time;
-       int cpu;
 
        tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
        if (!tuners)
                return -ENOMEM;
 
-       cpu = get_cpu();
-       idle_time = get_cpu_idle_time_us(cpu, NULL);
-       put_cpu();
-       if (idle_time != -1ULL) {
+       if (tick_nohz_is_active()) {
                /* Idle micro accounting is supported. Use finer thresholds */
                dbs_data->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
        } else {
index ac76ae9fa36df9c0c3a1a76d4ecadd00bcb6a1a8..738007d6f577ffca799bdb541dc7016e971956d4 100644 (file)
@@ -126,6 +126,7 @@ enum tick_dep_bits {
 
 #ifdef CONFIG_NO_HZ_COMMON
 extern bool tick_nohz_enabled;
+extern bool tick_nohz_is_active(void);
 extern bool tick_nohz_tick_stopped(void);
 extern bool tick_nohz_tick_stopped_cpu(int cpu);
 extern void tick_nohz_idle_stop_tick(void);
@@ -142,6 +143,7 @@ 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; }
 static inline int tick_nohz_tick_stopped(void) { return 0; }
 static inline int tick_nohz_tick_stopped_cpu(int cpu) { return 0; }
 static inline void tick_nohz_idle_stop_tick(void) { }
index 0e4bc1ca15ff10949ef891a20f46ba46d306dec8..1caf02a72ba8e587ee1404b9ca57f2c9c3822f91 100644 (file)
@@ -943,7 +943,7 @@ void clock_was_set(unsigned int bases)
        cpumask_var_t mask;
        int cpu;
 
-       if (!hrtimer_hres_active(cpu_base) && !tick_nohz_active)
+       if (!hrtimer_hres_active(cpu_base) && !tick_nohz_is_active())
                goto out_timerfd;
 
        if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) {
index 4e4f7bbe2a64bc9f49bef1056f16a8efe9032bda..597d816d22e8837420e2718bf3e3d3b4b8567e78 100644 (file)
@@ -156,7 +156,6 @@ static inline void tick_nohz_init(void) { }
 #endif
 
 #ifdef CONFIG_NO_HZ_COMMON
-extern unsigned long tick_nohz_active;
 extern void timers_update_nohz(void);
 extern u64 get_jiffies_update(unsigned long *basej);
 # ifdef CONFIG_SMP
@@ -171,7 +170,6 @@ extern void timer_expire_remote(unsigned int cpu);
 # endif
 #else /* CONFIG_NO_HZ_COMMON */
 static inline void timers_update_nohz(void) { }
-#define tick_nohz_active (0)
 #endif
 
 DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
index 2f8a7923fa279409ffe950f770ff2eac868f6ece..72e39c793117e2a903890d0bbe64df56e51dfbd1 100644 (file)
@@ -693,7 +693,7 @@ void __init tick_nohz_init(void)
  * NO HZ enabled ?
  */
 bool tick_nohz_enabled __read_mostly  = true;
-unsigned long tick_nohz_active  __read_mostly;
+static unsigned long tick_nohz_active  __read_mostly;
 /*
  * Enable / Disable tickless mode
  */
@@ -704,6 +704,12 @@ static int __init setup_tick_nohz(char *str)
 
 __setup("nohz=", setup_tick_nohz);
 
+bool tick_nohz_is_active(void)
+{
+       return tick_nohz_active;
+}
+EXPORT_SYMBOL_GPL(tick_nohz_is_active);
+
 bool tick_nohz_tick_stopped(void)
 {
        struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);
index 1f236412689473d9d1139226b4aa0b8188ee1d60..7e1e3bde6b8b72f82fdd81103822896f5124e7f1 100644 (file)
@@ -281,7 +281,7 @@ DEFINE_STATIC_KEY_FALSE(timers_migration_enabled);
 
 static void timers_update_migration(void)
 {
-       if (sysctl_timer_migration && tick_nohz_active)
+       if (sysctl_timer_migration && tick_nohz_is_active())
                static_branch_enable(&timers_migration_enabled);
        else
                static_branch_disable(&timers_migration_enabled);