aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2013-12-11 19:38:32 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-01-06 09:52:11 -0500
commite20e1d0ac02308e2211306fc67abcd0b2668fb8b (patch)
tree637426328736c0ec5ca644ad189c0d70f67910df /drivers/cpufreq
parentfbe299e0c8c47bf6aea5c426e8ec4b9d34529659 (diff)
powernow-k6: disable cache when changing frequency
I found out that a system with k6-3+ processor is unstable during network server load. The system locks up or the network card stops receiving. The reason for the instability is the CPU frequency scaling. During frequency transition the processor is in "EPM Stop Grant" state. The documentation says that the processor doesn't respond to inquiry requests in this state. Consequently, coherency of processor caches and bus master devices is not maintained, causing the system instability. This patch flushes the cache during frequency transition. It fixes the instability. Other minor changes: * u64 invalue changed to unsigned long because the variable is 32-bit * move the logic to set the multiplier to a separate function powernow_k6_set_cpu_multiplier * preserve lower 5 bits of the powernow port instead of 4 (the voltage field has 5 bits) * mask interrupts when reading the multiplier, so that the port is not open during other activity (running other kernel code with the port open shouldn't cause any misbehavior, but we should better be safe and keep the port closed) This patch should be backported to all stable kernels. If it doesn't apply cleanly, change it, or ask me to change it. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r--drivers/cpufreq/powernow-k6.c56
1 files changed, 39 insertions, 17 deletions
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c
index 643e7952cad3..1332b72f373a 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -44,23 +44,58 @@ static struct cpufreq_frequency_table clock_ratio[] = {
44/** 44/**
45 * powernow_k6_get_cpu_multiplier - returns the current FSB multiplier 45 * powernow_k6_get_cpu_multiplier - returns the current FSB multiplier
46 * 46 *
47 * Returns the current setting of the frequency multiplier. Core clock 47 * Returns the current setting of the frequency multiplier. Core clock
48 * speed is frequency of the Front-Side Bus multiplied with this value. 48 * speed is frequency of the Front-Side Bus multiplied with this value.
49 */ 49 */
50static int powernow_k6_get_cpu_multiplier(void) 50static int powernow_k6_get_cpu_multiplier(void)
51{ 51{
52 u64 invalue = 0; 52 unsigned long invalue = 0;
53 u32 msrval; 53 u32 msrval;
54 54
55 local_irq_disable();
56
55 msrval = POWERNOW_IOPORT + 0x1; 57 msrval = POWERNOW_IOPORT + 0x1;
56 wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */ 58 wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
57 invalue = inl(POWERNOW_IOPORT + 0x8); 59 invalue = inl(POWERNOW_IOPORT + 0x8);
58 msrval = POWERNOW_IOPORT + 0x0; 60 msrval = POWERNOW_IOPORT + 0x0;
59 wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */ 61 wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
60 62
63 local_irq_enable();
64
61 return clock_ratio[(invalue >> 5)&7].driver_data; 65 return clock_ratio[(invalue >> 5)&7].driver_data;
62} 66}
63 67
68static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
69{
70 unsigned long outvalue, invalue;
71 unsigned long msrval;
72 unsigned long cr0;
73
74 /* we now need to transform best_i to the BVC format, see AMD#23446 */
75
76 /*
77 * The processor doesn't respond to inquiry cycles while changing the
78 * frequency, so we must disable cache.
79 */
80 local_irq_disable();
81 cr0 = read_cr0();
82 write_cr0(cr0 | X86_CR0_CD);
83 wbinvd();
84
85 outvalue = (1<<12) | (1<<10) | (1<<9) | (best_i<<5);
86
87 msrval = POWERNOW_IOPORT + 0x1;
88 wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
89 invalue = inl(POWERNOW_IOPORT + 0x8);
90 invalue = invalue & 0x1f;
91 outvalue = outvalue | invalue;
92 outl(outvalue, (POWERNOW_IOPORT + 0x8));
93 msrval = POWERNOW_IOPORT + 0x0;
94 wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
95
96 write_cr0(cr0);
97 local_irq_enable();
98}
64 99
65/** 100/**
66 * powernow_k6_target - set the PowerNow! multiplier 101 * powernow_k6_target - set the PowerNow! multiplier
@@ -71,8 +106,6 @@ static int powernow_k6_get_cpu_multiplier(void)
71static int powernow_k6_target(struct cpufreq_policy *policy, 106static int powernow_k6_target(struct cpufreq_policy *policy,
72 unsigned int best_i) 107 unsigned int best_i)
73{ 108{
74 unsigned long outvalue = 0, invalue = 0;
75 unsigned long msrval;
76 struct cpufreq_freqs freqs; 109 struct cpufreq_freqs freqs;
77 110
78 if (clock_ratio[best_i].driver_data > max_multiplier) { 111 if (clock_ratio[best_i].driver_data > max_multiplier) {
@@ -85,18 +118,7 @@ static int powernow_k6_target(struct cpufreq_policy *policy,
85 118
86 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE); 119 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
87 120
88 /* we now need to transform best_i to the BVC format, see AMD#23446 */ 121 powernow_k6_set_cpu_multiplier(best_i);
89
90 outvalue = (1<<12) | (1<<10) | (1<<9) | (best_i<<5);
91
92 msrval = POWERNOW_IOPORT + 0x1;
93 wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
94 invalue = inl(POWERNOW_IOPORT + 0x8);
95 invalue = invalue & 0xf;
96 outvalue = outvalue | invalue;
97 outl(outvalue , (POWERNOW_IOPORT + 0x8));
98 msrval = POWERNOW_IOPORT + 0x0;
99 wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
100 122
101 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 123 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
102 124
@@ -125,7 +147,7 @@ static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
125 } 147 }
126 148
127 /* cpuinfo and default policy values */ 149 /* cpuinfo and default policy values */
128 policy->cpuinfo.transition_latency = 200000; 150 policy->cpuinfo.transition_latency = 500000;
129 151
130 return cpufreq_table_validate_and_show(policy, clock_ratio); 152 return cpufreq_table_validate_and_show(policy, clock_ratio);
131} 153}