Skip to content

Commit b43a7ff

Browse files
vireshkrafaeljw
authored andcommitted
cpufreq: Notify all policy->cpus in cpufreq_notify_transition()
policy->cpus contains all online cpus that have single shared clock line. And their frequencies are always updated together. Many SMP system's cpufreq drivers take care of this in individual drivers but the best place for this code is in cpufreq core. This patch modifies cpufreq_notify_transition() to notify frequency change for all cpus in policy->cpus and hence updates all users of this API. Signed-off-by: Viresh Kumar <[email protected]> Acked-by: Stephen Warren <[email protected]> Tested-by: Stephen Warren <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent fd143b4 commit b43a7ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+238
-340
lines changed

arch/arm/mach-davinci/cpufreq.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ static int davinci_target(struct cpufreq_policy *policy,
9090

9191
freqs.old = davinci_getspeed(0);
9292
freqs.new = clk_round_rate(armclk, target_freq * 1000) / 1000;
93-
freqs.cpu = 0;
9493

9594
if (freqs.old == freqs.new)
9695
return ret;
@@ -102,7 +101,7 @@ static int davinci_target(struct cpufreq_policy *policy,
102101
if (ret)
103102
return -EINVAL;
104103

105-
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
104+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
106105

107106
/* if moving to higher frequency, up the voltage beforehand */
108107
if (pdata->set_voltage && freqs.new > freqs.old) {
@@ -126,7 +125,7 @@ static int davinci_target(struct cpufreq_policy *policy,
126125
pdata->set_voltage(idx);
127126

128127
out:
129-
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
128+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
130129

131130
return ret;
132131
}

arch/arm/mach-imx/cpufreq.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ static int mxc_set_target(struct cpufreq_policy *policy,
8787

8888
freqs.old = clk_get_rate(cpu_clk) / 1000;
8989
freqs.new = freq_Hz / 1000;
90-
freqs.cpu = 0;
9190
freqs.flags = 0;
92-
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
91+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
9392

9493
ret = set_cpu_freq(freq_Hz);
9594

96-
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
95+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
9796

9897
return ret;
9998
}

arch/arm/mach-integrator/cpu.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,12 @@ static int integrator_set_target(struct cpufreq_policy *policy,
123123
vco = icst_hz_to_vco(&cclk_params, target_freq * 1000);
124124
freqs.new = icst_hz(&cclk_params, vco) / 1000;
125125

126-
freqs.cpu = policy->cpu;
127-
128126
if (freqs.old == freqs.new) {
129127
set_cpus_allowed(current, cpus_allowed);
130128
return 0;
131129
}
132130

133-
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
131+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
134132

135133
cm_osc = __raw_readl(CM_OSC);
136134

@@ -151,7 +149,7 @@ static int integrator_set_target(struct cpufreq_policy *policy,
151149
*/
152150
set_cpus_allowed(current, cpus_allowed);
153151

154-
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
152+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
155153

156154
return 0;
157155
}

arch/arm/mach-pxa/cpufreq-pxa2xx.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ static int pxa_set_target(struct cpufreq_policy *policy,
311311
new_freq_mem = pxa_freq_settings[idx].membus;
312312
freqs.old = policy->cur;
313313
freqs.new = new_freq_cpu;
314-
freqs.cpu = policy->cpu;
315314

316315
if (freq_debug)
317316
pr_debug("Changing CPU frequency to %d Mhz, (SDRAM %d Mhz)\n",
@@ -327,7 +326,7 @@ static int pxa_set_target(struct cpufreq_policy *policy,
327326
* you should add a notify client with any platform specific
328327
* Vcc changing capability
329328
*/
330-
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
329+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
331330

332331
/* Calculate the next MDREFR. If we're slowing down the SDRAM clock
333332
* we need to preset the smaller DRI before the change. If we're
@@ -382,7 +381,7 @@ static int pxa_set_target(struct cpufreq_policy *policy,
382381
* you should add a notify client with any platform specific
383382
* SDRAM refresh timer adjustments
384383
*/
385-
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
384+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
386385

387386
/*
388387
* Even if voltage setting fails, we don't report it, as the frequency

arch/arm/mach-pxa/cpufreq-pxa3xx.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ static int pxa3xx_cpufreq_set(struct cpufreq_policy *policy,
184184

185185
freqs.old = policy->cur;
186186
freqs.new = next->cpufreq_mhz * 1000;
187-
freqs.cpu = policy->cpu;
188187

189188
pr_debug("CPU frequency from %d MHz to %d MHz%s\n",
190189
freqs.old / 1000, freqs.new / 1000,
@@ -193,14 +192,14 @@ static int pxa3xx_cpufreq_set(struct cpufreq_policy *policy,
193192
if (freqs.old == target_freq)
194193
return 0;
195194

196-
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
195+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
197196

198197
local_irq_save(flags);
199198
__update_core_freq(next);
200199
__update_bus_freq(next);
201200
local_irq_restore(flags);
202201

203-
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
202+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
204203

205204
return 0;
206205
}

arch/arm/mach-s3c24xx/cpufreq.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ static int s3c_cpufreq_settarget(struct cpufreq_policy *policy,
204204
freqs.old = cpu_cur.freq;
205205
freqs.new = cpu_new.freq;
206206

207-
freqs.freqs.cpu = 0;
208207
freqs.freqs.old = cpu_cur.freq.armclk / 1000;
209208
freqs.freqs.new = cpu_new.freq.armclk / 1000;
210209

@@ -218,9 +217,7 @@ static int s3c_cpufreq_settarget(struct cpufreq_policy *policy,
218217
s3c_cpufreq_updateclk(clk_pclk, cpu_new.freq.pclk);
219218

220219
/* start the frequency change */
221-
222-
if (policy)
223-
cpufreq_notify_transition(&freqs.freqs, CPUFREQ_PRECHANGE);
220+
cpufreq_notify_transition(policy, &freqs.freqs, CPUFREQ_PRECHANGE);
224221

225222
/* If hclk is staying the same, then we do not need to
226223
* re-write the IO or the refresh timings whilst we are changing
@@ -264,8 +261,7 @@ static int s3c_cpufreq_settarget(struct cpufreq_policy *policy,
264261
local_irq_restore(flags);
265262

266263
/* notify everyone we've done this */
267-
if (policy)
268-
cpufreq_notify_transition(&freqs.freqs, CPUFREQ_POSTCHANGE);
264+
cpufreq_notify_transition(policy, &freqs.freqs, CPUFREQ_POSTCHANGE);
269265

270266
s3c_freq_dbg("%s: finished\n", __func__);
271267
return 0;

arch/arm/mach-sa1100/cpu-sa1100.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,8 @@ static int sa1100_target(struct cpufreq_policy *policy,
201201

202202
freqs.old = cur;
203203
freqs.new = sa11x0_ppcr_to_freq(new_ppcr);
204-
freqs.cpu = 0;
205204

206-
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
205+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
207206

208207
if (freqs.new > cur)
209208
sa1100_update_dram_timings(cur, freqs.new);
@@ -213,7 +212,7 @@ static int sa1100_target(struct cpufreq_policy *policy,
213212
if (freqs.new < cur)
214213
sa1100_update_dram_timings(cur, freqs.new);
215214

216-
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
215+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
217216

218217
return 0;
219218
}

arch/arm/mach-sa1100/cpu-sa1110.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ static int sa1110_target(struct cpufreq_policy *policy,
258258

259259
freqs.old = sa11x0_getspeed(0);
260260
freqs.new = sa11x0_ppcr_to_freq(ppcr);
261-
freqs.cpu = 0;
262261

263262
sdram_calculate_timing(&sd, freqs.new, sdram);
264263

@@ -279,7 +278,7 @@ static int sa1110_target(struct cpufreq_policy *policy,
279278
sd.mdcas[2] = 0xaaaaaaaa;
280279
#endif
281280

282-
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
281+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
283282

284283
/*
285284
* The clock could be going away for some time. Set the SDRAMs
@@ -327,7 +326,7 @@ static int sa1110_target(struct cpufreq_policy *policy,
327326
*/
328327
sdram_update_refresh(freqs.new, sdram);
329328

330-
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
329+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
331330

332331
return 0;
333332
}

arch/arm/mach-tegra/cpu-tegra.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ static int tegra_cpu_clk_set_rate(unsigned long rate)
106106
return ret;
107107
}
108108

109-
static int tegra_update_cpu_speed(unsigned long rate)
109+
static int tegra_update_cpu_speed(struct cpufreq_policy *policy,
110+
unsigned long rate)
110111
{
111112
int ret = 0;
112113
struct cpufreq_freqs freqs;
@@ -128,8 +129,7 @@ static int tegra_update_cpu_speed(unsigned long rate)
128129
else
129130
clk_set_rate(emc_clk, 100000000); /* emc 50Mhz */
130131

131-
for_each_online_cpu(freqs.cpu)
132-
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
132+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
133133

134134
#ifdef CONFIG_CPU_FREQ_DEBUG
135135
printk(KERN_DEBUG "cpufreq-tegra: transition: %u --> %u\n",
@@ -143,8 +143,7 @@ static int tegra_update_cpu_speed(unsigned long rate)
143143
return ret;
144144
}
145145

146-
for_each_online_cpu(freqs.cpu)
147-
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
146+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
148147

149148
return 0;
150149
}
@@ -181,7 +180,7 @@ static int tegra_target(struct cpufreq_policy *policy,
181180

182181
target_cpu_speed[policy->cpu] = freq;
183182

184-
ret = tegra_update_cpu_speed(tegra_cpu_highest_speed());
183+
ret = tegra_update_cpu_speed(policy, tegra_cpu_highest_speed());
185184

186185
out:
187186
mutex_unlock(&tegra_cpu_lock);
@@ -193,10 +192,12 @@ static int tegra_pm_notify(struct notifier_block *nb, unsigned long event,
193192
{
194193
mutex_lock(&tegra_cpu_lock);
195194
if (event == PM_SUSPEND_PREPARE) {
195+
struct cpufreq_policy *policy = cpufreq_cpu_get(0);
196196
is_suspended = true;
197197
pr_info("Tegra cpufreq suspend: setting frequency to %d kHz\n",
198198
freq_table[0].frequency);
199-
tegra_update_cpu_speed(freq_table[0].frequency);
199+
tegra_update_cpu_speed(policy, freq_table[0].frequency);
200+
cpufreq_cpu_put(policy);
200201
} else if (event == PM_POST_SUSPEND) {
201202
is_suspended = false;
202203
}

arch/avr32/mach-at32ap/cpufreq.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,22 @@ static int at32_set_target(struct cpufreq_policy *policy,
6161

6262
freqs.old = at32_get_speed(0);
6363
freqs.new = (freq + 500) / 1000;
64-
freqs.cpu = 0;
6564
freqs.flags = 0;
6665

6766
if (!ref_freq) {
6867
ref_freq = freqs.old;
6968
loops_per_jiffy_ref = boot_cpu_data.loops_per_jiffy;
7069
}
7170

72-
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
71+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
7372
if (freqs.old < freqs.new)
7473
boot_cpu_data.loops_per_jiffy = cpufreq_scale(
7574
loops_per_jiffy_ref, ref_freq, freqs.new);
7675
clk_set_rate(cpuclk, freq);
7776
if (freqs.new < freqs.old)
7877
boot_cpu_data.loops_per_jiffy = cpufreq_scale(
7978
loops_per_jiffy_ref, ref_freq, freqs.new);
80-
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
79+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
8180

8281
pr_debug("cpufreq: set frequency %lu Hz\n", freq);
8382

arch/blackfin/mach-common/cpufreq.c

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ unsigned long cpu_set_cclk(int cpu, unsigned long new)
127127
}
128128
#endif
129129

130-
static int bfin_target(struct cpufreq_policy *poli,
130+
static int bfin_target(struct cpufreq_policy *policy,
131131
unsigned int target_freq, unsigned int relation)
132132
{
133133
#ifndef CONFIG_BF60x
134134
unsigned int plldiv;
135135
#endif
136-
unsigned int index, cpu;
136+
unsigned int index;
137137
unsigned long cclk_hz;
138138
struct cpufreq_freqs freqs;
139139
static unsigned long lpj_ref;
@@ -144,59 +144,48 @@ static int bfin_target(struct cpufreq_policy *poli,
144144
cycles_t cycles;
145145
#endif
146146

147-
for_each_online_cpu(cpu) {
148-
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
147+
if (cpufreq_frequency_table_target(policy, bfin_freq_table, target_freq,
148+
relation, &index))
149+
return -EINVAL;
149150

150-
if (!policy)
151-
continue;
151+
cclk_hz = bfin_freq_table[index].frequency;
152152

153-
if (cpufreq_frequency_table_target(policy, bfin_freq_table,
154-
target_freq, relation, &index))
155-
return -EINVAL;
153+
freqs.old = bfin_getfreq_khz(0);
154+
freqs.new = cclk_hz;
156155

157-
cclk_hz = bfin_freq_table[index].frequency;
156+
pr_debug("cpufreq: changing cclk to %lu; target = %u, oldfreq = %u\n",
157+
cclk_hz, target_freq, freqs.old);
158158

159-
freqs.old = bfin_getfreq_khz(0);
160-
freqs.new = cclk_hz;
161-
freqs.cpu = cpu;
162-
163-
pr_debug("cpufreq: changing cclk to %lu; target = %u, oldfreq = %u\n",
164-
cclk_hz, target_freq, freqs.old);
165-
166-
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
167-
if (cpu == CPUFREQ_CPU) {
159+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
168160
#ifndef CONFIG_BF60x
169-
plldiv = (bfin_read_PLL_DIV() & SSEL) |
170-
dpm_state_table[index].csel;
171-
bfin_write_PLL_DIV(plldiv);
161+
plldiv = (bfin_read_PLL_DIV() & SSEL) | dpm_state_table[index].csel;
162+
bfin_write_PLL_DIV(plldiv);
172163
#else
173-
ret = cpu_set_cclk(cpu, freqs.new * 1000);
174-
if (ret != 0) {
175-
WARN_ONCE(ret, "cpufreq set freq failed %d\n", ret);
176-
break;
177-
}
164+
ret = cpu_set_cclk(policy->cpu, freqs.new * 1000);
165+
if (ret != 0) {
166+
WARN_ONCE(ret, "cpufreq set freq failed %d\n", ret);
167+
return ret;
168+
}
178169
#endif
179-
on_each_cpu(bfin_adjust_core_timer, &index, 1);
170+
on_each_cpu(bfin_adjust_core_timer, &index, 1);
180171
#if defined(CONFIG_CYCLES_CLOCKSOURCE)
181-
cycles = get_cycles();
182-
SSYNC();
183-
cycles += 10; /* ~10 cycles we lose after get_cycles() */
184-
__bfin_cycles_off +=
185-
(cycles << __bfin_cycles_mod) - (cycles << index);
186-
__bfin_cycles_mod = index;
172+
cycles = get_cycles();
173+
SSYNC();
174+
cycles += 10; /* ~10 cycles we lose after get_cycles() */
175+
__bfin_cycles_off += (cycles << __bfin_cycles_mod) - (cycles << index);
176+
__bfin_cycles_mod = index;
187177
#endif
188-
if (!lpj_ref_freq) {
189-
lpj_ref = loops_per_jiffy;
190-
lpj_ref_freq = freqs.old;
191-
}
192-
if (freqs.new != freqs.old) {
193-
loops_per_jiffy = cpufreq_scale(lpj_ref,
194-
lpj_ref_freq, freqs.new);
195-
}
196-
}
197-
/* TODO: just test case for cycles clock source, remove later */
198-
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
178+
if (!lpj_ref_freq) {
179+
lpj_ref = loops_per_jiffy;
180+
lpj_ref_freq = freqs.old;
199181
}
182+
if (freqs.new != freqs.old) {
183+
loops_per_jiffy = cpufreq_scale(lpj_ref,
184+
lpj_ref_freq, freqs.new);
185+
}
186+
187+
/* TODO: just test case for cycles clock source, remove later */
188+
cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
200189

201190
pr_debug("cpufreq: done\n");
202191
return ret;

0 commit comments

Comments
 (0)