Skip to content

Commit 5720821

Browse files
Frederic WeisbeckerIngo Molnar
authored andcommitted
cpufreq: Use vtime aware kcpustat accessors for user time
We can now safely read user and guest kcpustat fields on nohz_full CPUs. Use the appropriate accessors. Reported-by: Yauheni Kaliuta <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Cc: Viresh Kumar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Wanpeng Li <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 26dae14 commit 5720821

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,21 @@ EXPORT_SYMBOL_GPL(get_governor_parent_kobj);
113113

114114
static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
115115
{
116-
u64 idle_time;
116+
struct kernel_cpustat kcpustat;
117117
u64 cur_wall_time;
118+
u64 idle_time;
118119
u64 busy_time;
119120

120121
cur_wall_time = jiffies64_to_nsecs(get_jiffies_64());
121122

122-
busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER];
123-
busy_time += kcpustat_field(&kcpustat_cpu(cpu), CPUTIME_SYSTEM, cpu);
124-
busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ];
125-
busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ];
126-
busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL];
127-
busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE];
123+
kcpustat_cpu_fetch(&kcpustat, cpu);
124+
125+
busy_time = kcpustat.cpustat[CPUTIME_USER];
126+
busy_time += kcpustat.cpustat[CPUTIME_SYSTEM];
127+
busy_time += kcpustat.cpustat[CPUTIME_IRQ];
128+
busy_time += kcpustat.cpustat[CPUTIME_SOFTIRQ];
129+
busy_time += kcpustat.cpustat[CPUTIME_STEAL];
130+
busy_time += kcpustat.cpustat[CPUTIME_NICE];
128131

129132
idle_time = cur_wall_time - busy_time;
130133
if (wall)

drivers/cpufreq/cpufreq_governor.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void gov_update_cpu_data(struct dbs_data *dbs_data)
105105
j_cdbs->prev_cpu_idle = get_cpu_idle_time(j, &j_cdbs->prev_update_time,
106106
dbs_data->io_is_busy);
107107
if (dbs_data->ignore_nice_load)
108-
j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
108+
j_cdbs->prev_cpu_nice = kcpustat_field(&kcpustat_cpu(j), CPUTIME_NICE, j);
109109
}
110110
}
111111
}
@@ -149,7 +149,7 @@ unsigned int dbs_update(struct cpufreq_policy *policy)
149149
j_cdbs->prev_cpu_idle = cur_idle_time;
150150

151151
if (ignore_nice) {
152-
u64 cur_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
152+
u64 cur_nice = kcpustat_field(&kcpustat_cpu(j), CPUTIME_NICE, j);
153153

154154
idle_time += div_u64(cur_nice - j_cdbs->prev_cpu_nice, NSEC_PER_USEC);
155155
j_cdbs->prev_cpu_nice = cur_nice;
@@ -530,7 +530,7 @@ int cpufreq_dbs_governor_start(struct cpufreq_policy *policy)
530530
j_cdbs->prev_load = 0;
531531

532532
if (ignore_nice)
533-
j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
533+
j_cdbs->prev_cpu_nice = kcpustat_field(&kcpustat_cpu(j), CPUTIME_NICE, j);
534534
}
535535

536536
gov->start(policy);

0 commit comments

Comments
 (0)