Skip to content

Commit

Permalink
cpufreq: longhaul: Fix double invocation of cpufreq_freq_transition_b…
Browse files Browse the repository at this point in the history
…egin/end

During frequency transitions, the cpufreq core takes the responsibility of
invoking cpufreq_freq_transition_begin() and cpufreq_freq_transition_end()
for those cpufreq drivers that define the ->target_index callback but don't
set the ASYNC_NOTIFICATION flag.

The longhaul cpufreq driver falls under this category, but this driver was
invoking the _begin() and _end() APIs itself around frequency transitions,
which led to double invocation of the _begin() API. The _begin API makes
contending callers wait until the previous invocation is complete. Hence,
the longhaul driver ended up waiting on itself, leading to system hangs
during boot.

Fix this by removing the calls to the _begin() and _end() APIs from the
longhaul driver, since they rightly belong to the cpufreq core.

(Note that during module_exit(), the longhaul driver sets the frequency
 without any help from the cpufreq core. So add explicit calls to the
 _begin() and _end() APIs around that frequency transition alone, to take
 care of that special case.)

Fixes: 12478cf (cpufreq: Make sure frequency transitions are serialized)
Reported-and-tested-by: Meelis Roos <mroos@linux.ee>
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Srivatsa S. Bhat authored and Rafael J. Wysocki committed Apr 28, 2014
1 parent d1db0ee commit 7aa0557
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions drivers/cpufreq/longhaul.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static void do_powersaver(int cx_address, unsigned int mults_index,
* Sets a new clock ratio.
*/

static void longhaul_setstate(struct cpufreq_policy *policy,
static int longhaul_setstate(struct cpufreq_policy *policy,
unsigned int table_index)
{
unsigned int mults_index;
Expand All @@ -258,19 +258,19 @@ static void longhaul_setstate(struct cpufreq_policy *policy,
/* Safety precautions */
mult = mults[mults_index & 0x1f];
if (mult == -1)
return;
return -EINVAL;

speed = calc_speed(mult);
if ((speed > highest_speed) || (speed < lowest_speed))
return;
return -EINVAL;

/* Voltage transition before frequency transition? */
if (can_scale_voltage && longhaul_index < table_index)
dir = 1;

freqs.old = calc_speed(longhaul_get_cpu_mult());
freqs.new = speed;

cpufreq_freq_transition_begin(policy, &freqs);

pr_debug("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n",
fsb, mult/10, mult%10, print_speed(speed/1000));
retry_loop:
Expand Down Expand Up @@ -385,12 +385,14 @@ static void longhaul_setstate(struct cpufreq_policy *policy,
goto retry_loop;
}
}
/* Report true CPU frequency */
cpufreq_freq_transition_end(policy, &freqs, 0);

if (!bm_timeout)
if (!bm_timeout) {
printk(KERN_INFO PFX "Warning: Timeout while waiting for "
"idle PCI bus.\n");
return -EBUSY;
}

return 0;
}

/*
Expand Down Expand Up @@ -631,9 +633,10 @@ static int longhaul_target(struct cpufreq_policy *policy,
unsigned int i;
unsigned int dir = 0;
u8 vid, current_vid;
int retval = 0;

if (!can_scale_voltage)
longhaul_setstate(policy, table_index);
retval = longhaul_setstate(policy, table_index);
else {
/* On test system voltage transitions exceeding single
* step up or down were turning motherboard off. Both
Expand All @@ -648,7 +651,7 @@ static int longhaul_target(struct cpufreq_policy *policy,
while (i != table_index) {
vid = (longhaul_table[i].driver_data >> 8) & 0x1f;
if (vid != current_vid) {
longhaul_setstate(policy, i);
retval = longhaul_setstate(policy, i);
current_vid = vid;
msleep(200);
}
Expand All @@ -657,10 +660,11 @@ static int longhaul_target(struct cpufreq_policy *policy,
else
i--;
}
longhaul_setstate(policy, table_index);
retval = longhaul_setstate(policy, table_index);
}

longhaul_index = table_index;
return 0;
return retval;
}


Expand Down Expand Up @@ -968,7 +972,15 @@ static void __exit longhaul_exit(void)

for (i = 0; i < numscales; i++) {
if (mults[i] == maxmult) {
struct cpufreq_freqs freqs;

freqs.old = policy->cur;
freqs.new = longhaul_table[i].frequency;
freqs.flags = 0;

cpufreq_freq_transition_begin(policy, &freqs);
longhaul_setstate(policy, i);
cpufreq_freq_transition_end(policy, &freqs, 0);
break;
}
}
Expand Down

0 comments on commit 7aa0557

Please sign in to comment.