* [PATCH 5/8] p4_clockmod: detect speed without relying on cpu_khz or user input
@ 2003-11-19 18:32 Dominik Brodowski
2003-11-19 19:09 ` Dave Jones
0 siblings, 1 reply; 5+ messages in thread
From: Dominik Brodowski @ 2003-11-19 18:32 UTC (permalink / raw)
To: cpufreq, davej
Other cpufreq drivers don't rely on cpu_khz, but use the "decoded"/theoretical CPU frequency
as base for all calculations.
arch/i386/kernel/cpu/cpufreq/p4-clockmod.c | 66 +++++++++++++++++++++++------
1 files changed, 53 insertions(+), 13 deletions(-)
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c linux/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c
--- linux-original/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c 2003-11-19 17:06:10.569869104 +0100
+++ linux/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c 2003-11-19 18:18:53.114661488 +0100
@@ -48,8 +48,7 @@
static int has_N44_O17_errata[NR_CPUS];
-static int stock_freq;
-
+unsigned int stock_freq;
static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate)
{
@@ -175,6 +174,54 @@
return cpufreq_frequency_table_verify(policy, &p4clockmod_table[0]);
}
+/* copied from speedstep_lib, made SMP-compatible */
+static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
+{
+ u32 msr_lo, msr_hi, mult;
+ unsigned int fsb = 0;
+
+ if (c->x86 != 0xF) {
+ printk(KERN_DEBUG PFX "Unknown P4. Please send an e-mail to <linux@brodo.de>\n");
+ return 0;
+ }
+
+ rdmsr(0x2c, msr_lo, msr_hi);
+
+ /* printk(KERN_DEBUG PFX "P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr_lo, msr_hi); */
+ /* decode the FSB: see IA-32 Intel (C) Architecture Software
+ * Developer's Manual, Volume 3: System Prgramming Guide,
+ * revision #12 in Table B-1: MSRs in the Pentium 4 and
+ * Intel Xeon Processors, on page B-4 and B-5.
+ */
+ if (c->x86_model < 2)
+ fsb = 100 * 1000;
+ else {
+ u8 fsb_code = (msr_lo >> 16) & 0x7;
+ switch (fsb_code) {
+ case 0:
+ fsb = 100 * 1000;
+ break;
+ case 1:
+ fsb = 13333 * 10;
+ break;
+ case 2:
+ fsb = 200 * 1000;
+ break;
+ }
+ }
+
+ if (!fsb) {
+ printk(KERN_DEBUG PFX "couldn't detect FSB speed. Please send an e-mail to <linux@brodo.de>\n");
+ printk(KERN_DEBUG PFX "P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr_lo, msr_hi);
+ }
+
+ /* Multiplier. */
+ mult = msr_lo >> 24;
+
+ return (fsb * mult);
+}
+
+
static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)
{
@@ -192,15 +239,10 @@
has_N44_O17_errata[policy->cpu] = 1;
}
- /* get frequency */
- if (!stock_freq) {
- if (cpu_khz)
- stock_freq = cpu_khz;
- else {
- printk(KERN_INFO PFX "unknown core frequency - please use module parameter 'stock_freq'\n");
- return -EINVAL;
- }
- }
+ /* get max frequency */
+ stock_freq = cpufreq_p4_get_frequency(c);
+ if (!stock_freq)
+ return -EINVAL;
/* table init */
for (i=1; (p4clockmod_table[i].frequency != CPUFREQ_TABLE_END); i++) {
@@ -269,8 +311,6 @@
}
-MODULE_PARM(stock_freq, "i");
-
MODULE_AUTHOR ("Zwane Mwaikambo <zwane@commfireservices.com>");
MODULE_DESCRIPTION ("cpufreq driver for Pentium(TM) 4/Xeon(TM)");
MODULE_LICENSE ("GPL");
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 5/8] p4_clockmod: detect speed without relying on cpu_khz or user input
2003-11-19 18:32 [PATCH 5/8] p4_clockmod: detect speed without relying on cpu_khz or user input Dominik Brodowski
@ 2003-11-19 19:09 ` Dave Jones
2003-11-20 18:33 ` Dominik Brodowski
0 siblings, 1 reply; 5+ messages in thread
From: Dave Jones @ 2003-11-19 19:09 UTC (permalink / raw)
To: Dominik Brodowski; +Cc: cpufreq
On Wed, Nov 19, 2003 at 07:32:28PM +0100, Dominik Brodowski wrote:
> + rdmsr(0x2c, msr_lo, msr_hi);
> +
> + /* printk(KERN_DEBUG PFX "P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr_lo, msr_hi); */
> + /* decode the FSB: see IA-32 Intel (C) Architecture Software
> + * Developer's Manual, Volume 3: System Prgramming Guide,
> + * revision #12 in Table B-1: MSRs in the Pentium 4 and
> + * Intel Xeon Processors, on page B-4 and B-5.
> + */
> + if (c->x86_model < 2)
> + fsb = 100 * 1000;
> + else {
> + u8 fsb_code = (msr_lo >> 16) & 0x7;
> + switch (fsb_code) {
> + case 0:
> + fsb = 100 * 1000;
> + break;
> + case 1:
> + fsb = 13333 * 10;
> + break;
> + case 2:
> + fsb = 200 * 1000;
> + break;
> + }
> + }
> +
> + if (!fsb) {
> + printk(KERN_DEBUG PFX "couldn't detect FSB speed. Please send an e-mail to <linux@brodo.de>\n");
> + printk(KERN_DEBUG PFX "P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr_lo, msr_hi);
> + }
patch 4/8 introduced what seems to be the exact same code in the speedstep-lib.
Perhaps it belongs in an fsb.o instead that they can both share ?
I don't mind duplicating it twice in object code, but having two copies
in the source seems a bit silly.
Dave
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 5/8] p4_clockmod: detect speed without relying on cpu_khz or user input
2003-11-19 19:09 ` Dave Jones
@ 2003-11-20 18:33 ` Dominik Brodowski
2003-11-21 2:26 ` Dave Jones
0 siblings, 1 reply; 5+ messages in thread
From: Dominik Brodowski @ 2003-11-20 18:33 UTC (permalink / raw)
To: Dave Jones; +Cc: cpufreq
On Wed, Nov 19, 2003 at 07:09:46PM +0000, Dave Jones wrote:
>
> patch 4/8 introduced what seems to be the exact same code in the speedstep-lib.
> Perhaps it belongs in an fsb.o instead that they can both share ?
> I don't mind duplicating it twice in object code, but having two copies
> in the source seems a bit silly.
Usually, I agree to this topic. However, I don't want to create just another
file for just this function, and it doesn't belong to speedstep-lib either
as a plain p4 isn't a valid processor for speedstep-lib. So I'd prefer to
have this source code duplication as an exception here.
Dominik
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 5/8] p4_clockmod: detect speed without relying on cpu_khz or user input
2003-11-20 18:33 ` Dominik Brodowski
@ 2003-11-21 2:26 ` Dave Jones
2003-11-21 9:56 ` Dominik Brodowski
0 siblings, 1 reply; 5+ messages in thread
From: Dave Jones @ 2003-11-21 2:26 UTC (permalink / raw)
To: Dominik Brodowski; +Cc: cpufreq
On Thu, Nov 20, 2003 at 07:33:35PM +0100, Dominik Brodowski wrote:
> On Wed, Nov 19, 2003 at 07:09:46PM +0000, Dave Jones wrote:
> >
> > patch 4/8 introduced what seems to be the exact same code in the speedstep-lib.
> > Perhaps it belongs in an fsb.o instead that they can both share ?
> > I don't mind duplicating it twice in object code, but having two copies
> > in the source seems a bit silly.
>
> Usually, I agree to this topic. However, I don't want to create just another
> file for just this function, and it doesn't belong to speedstep-lib either
> as a plain p4 isn't a valid processor for speedstep-lib. So I'd prefer to
> have this source code duplication as an exception here.
Your call. I'm just concerned with the maintainence effort as this
routine grows.
As a sidenote, this could be useful outside of cpufreq at some point too.
Alan tried adding 'overclocking detection' using these registers a while
back. It is very difficult to get correct however, so it never came to
anything. If we took the "perfect is the enemy of 'good enough'" approach
and just did these checks for cpus we knew we do it correctly on, this
would become feasable to pull off for 2.7.
Dave
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 5/8] p4_clockmod: detect speed without relying on cpu_khz or user input
2003-11-21 2:26 ` Dave Jones
@ 2003-11-21 9:56 ` Dominik Brodowski
0 siblings, 0 replies; 5+ messages in thread
From: Dominik Brodowski @ 2003-11-21 9:56 UTC (permalink / raw)
To: Dave Jones; +Cc: cpufreq
On Fri, Nov 21, 2003 at 02:26:13AM +0000, Dave Jones wrote:
> On Thu, Nov 20, 2003 at 07:33:35PM +0100, Dominik Brodowski wrote:
> > On Wed, Nov 19, 2003 at 07:09:46PM +0000, Dave Jones wrote:
> > >
> > > patch 4/8 introduced what seems to be the exact same code in the speedstep-lib.
> > > Perhaps it belongs in an fsb.o instead that they can both share ?
> > > I don't mind duplicating it twice in object code, but having two copies
> > > in the source seems a bit silly.
> >
> > Usually, I agree to this topic. However, I don't want to create just another
> > file for just this function, and it doesn't belong to speedstep-lib either
> > as a plain p4 isn't a valid processor for speedstep-lib. So I'd prefer to
> > have this source code duplication as an exception here.
>
> Your call. I'm just concerned with the maintainence effort as this
> routine grows.
>
> As a sidenote, this could be useful outside of cpufreq at some point too.
> Alan tried adding 'overclocking detection' using these registers a while
> back. It is very difficult to get correct however, so it never came to
> anything. If we took the "perfect is the enemy of 'good enough'" approach
> and just did these checks for cpus we knew we do it correctly on, this
> would become feasable to pull off for 2.7.
Well, for Intel P3s and P4s the MSRs are eithre documented or reverse-
engineered quite well, so it should be something good to do in 2.7.[*]
Dominik
[*] which will hopefully be soon!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-11-21 9:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-19 18:32 [PATCH 5/8] p4_clockmod: detect speed without relying on cpu_khz or user input Dominik Brodowski
2003-11-19 19:09 ` Dave Jones
2003-11-20 18:33 ` Dominik Brodowski
2003-11-21 2:26 ` Dave Jones
2003-11-21 9:56 ` Dominik Brodowski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.