Skip to content

Commit a554a25

Browse files
Frederic Weisbeckerrafaeljw
authored andcommitted
cpufreq: ondemand: Simplify idle cputime granularity test
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>
1 parent cc764d3 commit a554a25

6 files changed

Lines changed: 12 additions & 11 deletions

File tree

drivers/cpufreq/cpufreq_ondemand.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,12 @@ static void od_free(struct policy_dbs_info *policy_dbs)
334334
static int od_init(struct dbs_data *dbs_data)
335335
{
336336
struct od_dbs_tuners *tuners;
337-
u64 idle_time;
338-
int cpu;
339337

340338
tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
341339
if (!tuners)
342340
return -ENOMEM;
343341

344-
cpu = get_cpu();
345-
idle_time = get_cpu_idle_time_us(cpu, NULL);
346-
put_cpu();
347-
if (idle_time != -1ULL) {
342+
if (tick_nohz_is_active()) {
348343
/* Idle micro accounting is supported. Use finer thresholds */
349344
dbs_data->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
350345
} else {

include/linux/tick.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ enum tick_dep_bits {
126126

127127
#ifdef CONFIG_NO_HZ_COMMON
128128
extern bool tick_nohz_enabled;
129+
extern bool tick_nohz_is_active(void);
129130
extern bool tick_nohz_tick_stopped(void);
130131
extern bool tick_nohz_tick_stopped_cpu(int cpu);
131132
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);
142143
extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
143144
#else /* !CONFIG_NO_HZ_COMMON */
144145
#define tick_nohz_enabled (0)
146+
static inline bool tick_nohz_is_active(void) { return false; }
145147
static inline int tick_nohz_tick_stopped(void) { return 0; }
146148
static inline int tick_nohz_tick_stopped_cpu(int cpu) { return 0; }
147149
static inline void tick_nohz_idle_stop_tick(void) { }

kernel/time/hrtimer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ void clock_was_set(unsigned int bases)
943943
cpumask_var_t mask;
944944
int cpu;
945945

946-
if (!hrtimer_hres_active(cpu_base) && !tick_nohz_active)
946+
if (!hrtimer_hres_active(cpu_base) && !tick_nohz_is_active())
947947
goto out_timerfd;
948948

949949
if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) {

kernel/time/tick-internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ static inline void tick_nohz_init(void) { }
156156
#endif
157157

158158
#ifdef CONFIG_NO_HZ_COMMON
159-
extern unsigned long tick_nohz_active;
160159
extern void timers_update_nohz(void);
161160
extern u64 get_jiffies_update(unsigned long *basej);
162161
# ifdef CONFIG_SMP
@@ -171,7 +170,6 @@ extern void timer_expire_remote(unsigned int cpu);
171170
# endif
172171
#else /* CONFIG_NO_HZ_COMMON */
173172
static inline void timers_update_nohz(void) { }
174-
#define tick_nohz_active (0)
175173
#endif
176174

177175
DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);

kernel/time/tick-sched.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ void __init tick_nohz_init(void)
693693
* NO HZ enabled ?
694694
*/
695695
bool tick_nohz_enabled __read_mostly = true;
696-
unsigned long tick_nohz_active __read_mostly;
696+
static unsigned long tick_nohz_active __read_mostly;
697697
/*
698698
* Enable / Disable tickless mode
699699
*/
@@ -704,6 +704,12 @@ static int __init setup_tick_nohz(char *str)
704704

705705
__setup("nohz=", setup_tick_nohz);
706706

707+
bool tick_nohz_is_active(void)
708+
{
709+
return tick_nohz_active;
710+
}
711+
EXPORT_SYMBOL_GPL(tick_nohz_is_active);
712+
707713
bool tick_nohz_tick_stopped(void)
708714
{
709715
struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);

kernel/time/timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ DEFINE_STATIC_KEY_FALSE(timers_migration_enabled);
281281

282282
static void timers_update_migration(void)
283283
{
284-
if (sysctl_timer_migration && tick_nohz_active)
284+
if (sysctl_timer_migration && tick_nohz_is_active())
285285
static_branch_enable(&timers_migration_enabled);
286286
else
287287
static_branch_disable(&timers_migration_enabled);

0 commit comments

Comments
 (0)