Skip to contentSkip to conversation

correcting SGTC. Timer is based upon FSB.

PATCH In review Bruno Ducrot 3 participants 14 messages Apr 14, 2004 – Apr 15, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 correcting SGTC. Timer is based upon FSB.

Hi Dave,

I think this patch is needed especially if the FSB is around 166MHz or 200MHz, or else I believe we get instabilities on some K7's motherboard powernow capable (it's called Cool'n Quiet IIRC).

* Deduce fsb from cpu_khz and the max multiplier. It will be given as kHz now, so that frequency associated to a multiplier will be computate more accurately. Also, we need it for SGTC (see below).
* Fix how cpuid is computed in powernow_decode_bios().
* Be more restrictive for PST. It may be possible (on desktop shipped with low power Athlon models) that FSB can be changed by dip switchs on motherboard for example.
* Fix computation for SGTC. It use the bus timer (and then the bus frequency given by fsb).

 arch/i386/kernel/cpu/cpufreq/powernow-k7.c |  152 ++++++++++++++++++++++-------
 1 files changed, 119 insertions(+), 33 deletions(-)
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +59 -16
@@ -85,6 +85,14 @@
 static unsigned int latency;
 static char have_a0;
 
+static int check_fsb(unsigned int fsbspeed)
+{
+	int delta;
+	unsigned int f = fsb / 1000;
+
+	delta = (fsbspeed > f) ? fsbspeed - f : f - fsbspeed;
+	return (delta < 5);
+}
 
 static int check_powernow(void)
 {
@@ -140,7 +148,8 @@
 
 static int get_ranges (unsigned char *pst)
 {
-	unsigned int j, speed;
+	unsigned int j;
+	unsigned int speed;
 	u8 fid, vid;
 
 	powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) * (number_scales + 1)), GFP_KERNEL);
@@ -151,12 +160,12 @@
 	for (j=0 ; j < number_scales; j++) {
 		fid = *pst++;
 
-		powernow_table[j].frequency = fsb * fid_codes[fid] * 100;
+		powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10;
 		powernow_table[j].index = fid; /* lower 8 bits */
 
-		speed = fsb * (fid_codes[fid]/10);
+		speed = powernow_table[j].frequency;
+
 		if ((fid_codes[fid] % 10)==5) {
-			speed += fsb/2;
 #if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
 			if (have_a0 == 1)
 				powernow_table[j].frequency = CPUFREQ_ENTRY_INVALID;
@@ -164,7 +173,7 @@
 		}
 
 		dprintk (KERN_INFO PFX "   FID: 0x%x (%d.%dx [%dMHz])\t", fid,
-			fid_codes[fid] / 10, fid_codes[fid] % 10, speed);
+			fid_codes[fid] / 10, fid_codes[fid] % 10, speed/1000);
 
 		if (speed < minimum_speed)
 			minimum_speed = speed;
@@ -234,7 +243,8 @@
 
 	rdmsrl (MSR_K7_FID_VID_STATUS, fidvidstatus.val);
 	cfid = fidvidstatus.bits.CFID;
-	freqs.old = fsb * fid_codes[cfid] * 100;
+	freqs.old = fsb * fid_codes[cfid] / 10;
+
 	freqs.new = powernow_table[index].frequency;
 
 	cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
@@ -266,15 +276,12 @@
 {
 	struct psb_s *psb;
 	struct pst_s *pst;
-	struct cpuinfo_x86 *c = cpu_data;
 	unsigned int i, j;
 	unsigned char *p;
 	unsigned int etuple;
 	unsigned int ret;
 
 	etuple = cpuid_eax(0x80000001);
-	etuple &= 0xf00;
-	etuple |= (c->x86_model<<4)|(c->x86_mask);
 
 	for (i=0xC0000; i < 0xffff0 ; i+=16) {
 
@@ -305,7 +312,6 @@
 			}
 			dprintk (KERN_INFO PFX "Settling Time: %d microseconds.\n", psb->settlingtime);
 			dprintk (KERN_INFO PFX "Has %d PST tables. (Only dumping ones relevant to this CPU).\n", psb->numpst);
-			latency *= 100;	/* SGTC needs to be in units of 10ns */
 
 			p += sizeof (struct psb_s);
 
@@ -315,7 +321,8 @@
 				pst = (struct pst_s *) p;
 				number_scales = pst->numpstates;
 
-				if ((etuple == pst->cpuid) && (maxfid==pst->maxfid) && (startvid==pst->startvid))
+				if ((etuple == pst->cpuid) && check_fsb(pst->fsbspeed) &&
+				    (maxfid==pst->maxfid) && (startvid==pst->startvid))
 				{
 					dprintk (KERN_INFO PFX "PST:%d (@%p)\n", i, pst);
 					dprintk (KERN_INFO PFX " cpuid: 0x%x\t", pst->cpuid);
@@ -323,7 +330,6 @@
 					dprintk ("maxFID: 0x%x\t", pst->maxfid);
 					dprintk ("startvid: 0x%x\n", pst->startvid);
 
-					fsb = pst->fsbspeed;
 					ret = get_ranges ((char *) pst + sizeof (struct pst_s));
 					return ret;
 
@@ -365,6 +371,33 @@
 	return cpufreq_frequency_table_verify(policy, powernow_table);
 }
 
+/*
+ * We use the fact that the bus frequency is somehow
+ * a multiple of 100000/3 khz, then we compute sgtc according
+ * to this multiple.
+ * That way, we match more how AMD thinks all of that work.
+ * We will then get the same kind of behaviour already tested under
+ * the "well-known" other OS.
+ */
+static int __init fixup_sgtc(void)
+{
+	unsigned int sgtc;
+	unsigned int m;
+
+	m = fsb / 3333;
+	if ((m % 10) >= 5)
+		m += 5;
+
+	m /= 10;
+
+	sgtc = 100 * m * latency;
+	sgtc = sgtc / 3;
+	if (sgtc > 0xfffff) {
+		printk(KERN_WARNING PFX "SGTC too large %d\n", sgtc);
+		sgtc = 0xfffff;
+	}
+	return sgtc;
+}
 
 static int __init powernow_cpu_init (struct cpufreq_policy *policy)
 {
@@ -376,18 +409,28 @@
 
 	rdmsrl (MSR_K7_FID_VID_STATUS, fidvidstatus.val);
 
+	/* A K7 with powernow technology is set to max frequency by BIOS */
+	fsb = (10 * cpu_khz) / fid_codes[fidvidstatus.bits.MFID];
+	if (!fsb) {
+		printk(KERN_WARNING PFX "can not determine bus frequency\n");
+		return -EINVAL;
+	}
+	dprintk(KERN_INFO PFX "FSB: %3d.%03d MHz\n", fsb/1000, fsb%1000);
+
 	result = powernow_decode_bios(fidvidstatus.bits.MFID, fidvidstatus.bits.SVID);
 	if (result)
 		return result;
 
 	printk (KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n",
-				minimum_speed, maximum_speed);
+				minimum_speed/1000, maximum_speed/1000);
 
 	policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
 
-	/* latency is in 10 ns (look for SGTC above) for each VID
-	 * and FID transition, so multiply that value with 20 */
-	policy->cpuinfo.transition_latency = latency * 20;
+	policy->cpuinfo.transition_latency = latency * 2;
+
+	/* SGTC use the bus clock as timer */
+	latency = fixup_sgtc();
+	printk(KERN_INFO PFX "SGTC: %d\n", latency);
 
 	policy->cur = maximum_speed;
 

Cheers,

Signature · 4 lines
Bruno Ducrot

--  Which is worse:  ignorance or apathy?
--  Don't know.  Don't care.
#1 lore raw
Quoted 5 lines · Bruno Ducrot

Hi Dave,

I think this patch is needed especially if the FSB is around 166MHz or 200MHz, or else I believe we get instabilities on some K7's motherboard powernow capable (it's called Cool'n Quiet IIRC).

Looks good, applied. It'll turn up in the next -mm.

thanks,

Dave

#2 lore raw
Quoted 9 lines · Dave Jones
Quoted 5 lines · Bruno Ducrot

Hi Dave,

I think this patch is needed especially if the FSB is around 166MHz or 200MHz, or else I believe we get instabilities on some K7's motherboard powernow capable (it's called Cool'n Quiet IIRC).

Looks good, applied. It'll turn up in the next -mm.

Already? Thanks!
I actually wanted to submit also the ACPI integration...

Warning: it will only half work on the ACER Aspire, though: there is no pstate in the DSDT corresponding to the max frequency... I'm looking how to handle that correctly, probably at the init stage, if the max frequency is not given, then add it to powernow_table. It's really ugly, but I don't know how to make that OK. Suggestion is of course welcome..

* Integrate acpi perflib from Dominik.
* Use acpi if the PST tables are known to be broken (ASUS Aspire match one PST, but give brain damaged values), or use ACPI if no PST found.

 arch/i386/kernel/cpu/cpufreq/powernow-k7.c |  180 +++++++++++++++++++++++++++--
 1 files changed, 168 insertions(+), 12 deletions(-)
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +168 -12
@@ -27,6 +27,11 @@
 #include <asm/io.h>
 #include <asm/system.h>
 
+#ifdef CONFIG_ACPI_PROCESSOR
+#include <linux/acpi.h>
+#include <acpi/processor.h>
+#endif
+
 #include "powernow-k7.h"
 
 #define DEBUG
@@ -57,6 +62,17 @@ struct pst_s {
 	u8 numpstates;
 };
 
+#ifdef CONFIG_ACPI_PROCESSOR
+union powernow_acpi_control_t {
+	struct {
+		unsigned long fid:5,
+		vid:5,
+		sgtc:20,
+		res1:2;
+	} bits;
+	unsigned long val;
+};
+#endif
 
 /* divide by 1000 to get VID. */
 static int mobile_vid_table[32] = {
@@ -272,6 +288,129 @@ static void change_speed (unsigned int i
 }
 
 
+#ifdef CONFIG_ACPI_PROCESSOR
+
+struct acpi_processor_performance *acpi_processor_perf;
+
+static int powernow_acpi_init(void)
+{
+	int i;
+	int retval = 0;
+	union powernow_acpi_control_t pc;
+
+	if (acpi_processor_perf != NULL && powernow_table != NULL) {
+		retval = -EINVAL;
+		goto err0;
+	}
+
+	acpi_processor_perf = kmalloc(sizeof(struct acpi_processor_performance),
+				      GFP_KERNEL);
+
+	if (!acpi_processor_perf) {
+		retval = -ENOMEM;
+		goto err0;
+	}
+
+	memset(acpi_processor_perf, 0, sizeof(struct acpi_processor_performance));
+
+	if (acpi_processor_register_performance(acpi_processor_perf, 0)) {
+		retval = -EIO;
+		goto err1;
+	}
+
+	if (acpi_processor_perf->control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) {
+		retval = -ENODEV;
+		goto err2;
+	}
+
+	if (acpi_processor_perf->status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) {
+		retval = -ENODEV;
+		goto err2;
+	}
+
+	number_scales = acpi_processor_perf->state_count;
+
+	if (number_scales < 2) {
+		retval = -ENODEV;
+		goto err2;
+	}
+
+	powernow_table = kmalloc((number_scales + 1) * (sizeof(struct cpufreq_frequency_table)), GFP_KERNEL);
+	if (!powernow_table) {
+		retval = -ENOMEM;
+		goto err2;
+	}
+
+	memset(powernow_table, 0, ((number_scales + 1) * sizeof(struct cpufreq_frequency_table)));
+
+	pc.val = (unsigned long) acpi_processor_perf->states[0].control;
+	for (i = 0; i < number_scales; i++) {
+		u8 fid, vid;
+		unsigned int speed;
+
+		pc.val = (unsigned long) acpi_processor_perf->states[i].control;
+		dprintk (KERN_INFO PFX "acpi:  P%d: %d MHz, %d mW, %d uS, control %08x, status %08x, vid: %02x fid: %02x SGTC: %d\n",
+			 i,
+			 (u32) acpi_processor_perf->states[i].core_frequency,
+			 (u32) acpi_processor_perf->states[i].power,
+			 (u32) acpi_processor_perf->states[i].transition_latency,
+			 (u32) acpi_processor_perf->states[i].control,
+			 (u32) acpi_processor_perf->states[i].status,
+			 pc.bits.vid,
+			 pc.bits.fid,
+			 pc.bits.sgtc);
+
+		vid = pc.bits.vid;
+		fid = pc.bits.fid;
+
+		powernow_table[i].frequency = (fsb * fid_codes[fid]);
+		powernow_table[i].index = fid; /* lower 8 bits */
+		powernow_table[i].index |= (vid << 8); /* upper 8 bits */
+
+		speed = powernow_table[i].frequency;
+
+		if ((fid_codes[fid] % 10)==5) {
+			if (have_a0 == 1)
+				powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID;
+		}
+
+		dprintk (KERN_INFO PFX "   FID: 0x%x (%d.%dx [%dMHz])\t", fid,
+			fid_codes[fid] / 10, fid_codes[fid] % 10, speed/1000);
+		dprintk ("VID: 0x%x (%d.%03dV)\n", vid,	mobile_vid_table[vid]/1000,
+			mobile_vid_table[vid]%1000);
+
+		if (latency < pc.bits.sgtc)
+			latency = pc.bits.sgtc;
+
+		if (speed < minimum_speed)
+			minimum_speed = speed;
+		if (speed > maximum_speed)
+			maximum_speed = speed;
+	}
+
+	powernow_table[i].frequency = CPUFREQ_TABLE_END;
+	powernow_table[i].index = 0;
+
+	return 0;
+
+err2:
+	acpi_processor_unregister_performance(acpi_processor_perf, 0);
+err1:
+	kfree(acpi_processor_perf);
+err0:
+	printk(KERN_WARNING PFX "ACPI perflib can not be used in this platform\n");
+	acpi_processor_perf = NULL;
+	return retval;
+}
+#else
+static int powernow_acpi_init(void)
+{
+	printk(KERN_INFO PFX "no support for ACPI processor found."
+	       "  Please recompile your kernel with ACPI processor\n");
+	return -EINVAL;
+}
+#endif
+
 static int powernow_decode_bios (int maxfid, int startvid)
 {
 	struct psb_s *psb;
@@ -341,8 +480,14 @@ static int powernow_decode_bios (int max
 			}
 			printk (KERN_INFO PFX "No PST tables match this cpuid (0x%x)\n", etuple);
 			printk (KERN_INFO PFX "This is indicative of a broken BIOS.\n");
-			printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.shtml\n");
-			return -EINVAL;
+
+			printk (KERN_INFO PFX "Trying ACPI perflib\n");
+			ret = powernow_acpi_init();
+			if (ret) {
+				printk (KERN_INFO PFX "ACPI and legacy methods failed\n");
+				printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.shtml\n");
+			}
+			return ret;
 		}
 		p++;
 	}
@@ -417,7 +562,20 @@ static int __init powernow_cpu_init (str
 	}
 	dprintk(KERN_INFO PFX "FSB: %3d.%03d MHz\n", fsb/1000, fsb%1000);
 
-	result = powernow_decode_bios(fidvidstatus.bits.MFID, fidvidstatus.bits.SVID);
+	if (dmi_broken & BROKEN_CPUFREQ) {
+		printk (KERN_INFO PFX "PSB/PST known to be broken.  Trying ACPI instead\n");
+		result = powernow_acpi_init();
+	} else {
+		result = powernow_decode_bios(fidvidstatus.bits.MFID, fidvidstatus.bits.SVID);
+		if (result) {
+			result = powernow_acpi_init();
+		} else {
+			/* SGTC use the bus clock as timer */
+			latency = fixup_sgtc();
+			printk(KERN_INFO PFX "SGTC: %d\n", latency);
+		}
+	}
+
 	if (result)
 		return result;
 
@@ -426,11 +584,7 @@ static int __init powernow_cpu_init (str
 
 	policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
 
-	policy->cpuinfo.transition_latency = latency * 2;
-
-	/* SGTC use the bus clock as timer */
-	latency = fixup_sgtc();
-	printk(KERN_INFO PFX "SGTC: %d\n", latency);
+	policy->cpuinfo.transition_latency = 20 * latency / fsb;
 
 	policy->cur = maximum_speed;
 
@@ -461,10 +615,6 @@ static struct cpufreq_driver powernow_dr
 
 static int __init powernow_init (void)
 {
-	if (dmi_broken & BROKEN_CPUFREQ) {
-		printk (KERN_INFO PFX "Disabled at boot time by DMI,\n");
-		return -ENODEV;
-	}
 	if (check_powernow()==0)
 		return -ENODEV;
 	return cpufreq_register_driver(&powernow_driver);
@@ -473,6 +623,12 @@ static int __init powernow_init (void)
 
 static void __exit powernow_exit (void)
 {
+#ifdef CONFIG_ACPI_PROCESSOR
+	if (acpi_processor_perf) {
+		acpi_processor_unregister_performance(acpi_processor_perf, 0);
+		kfree(acpi_processor_perf);
+	}
+#endif
 	cpufreq_unregister_driver(&powernow_driver);
 	if (powernow_table)
 		kfree(powernow_table);
Signature · 4 lines
Bruno Ducrot

--  Which is worse:  ignorance or apathy?
--  Don't know.  Don't care.
#3 lore raw
Quoted 2 lines · Bruno Ducrot

Already? Thanks!
I actually wanted to submit also the ACPI integration...

Ok, I'll look at folding that in too after lunch.

Quoted 6 lines

Warning: it will only half work on the ACER Aspire, though: there is no pstate in the DSDT corresponding to the max frequency... I'm looking how to handle that correctly, probably at the init stage, if the max frequency is not given, then add it to powernow_table. It's really ugly, but I don't know how to make that OK. Suggestion is of course welcome..

Blacklist its BIOS with DMI tables, and adjust accordingly? Is it fixed maybe in a BIOS update ?

Quoted 3 lines

* Integrate acpi perflib from Dominik.
* Use acpi if the PST tables are known to be broken (ASUS Aspire match one PST, but give brain damaged values), or use ACPI if no PST found.

Was that the one that had every entry exactly the same ?

Dave

#4 lore raw
Quoted 6 lines · Dave Jones
Quoted 2 lines · Bruno Ducrot

Already? Thanks!
I actually wanted to submit also the ACPI integration...

Ok, I'll look at folding that in too after lunch.

Quoted 8 lines
Quoted 6 lines

Warning: it will only half work on the ACER Aspire, though: there is no pstate in the DSDT corresponding to the max frequency... I'm looking how to handle that correctly, probably at the init stage, if the max frequency is not given, then add it to powernow_table. It's really ugly, but I don't know how to make that OK. Suggestion is of course welcome..

Blacklist its BIOS with DMI tables, and adjust accordingly?

Yep. Patch below (or I can send you the dmi output privately if you prefer).

The machine is an ACER Aspire, look at:
http://bugzilla.kernel.org/show_bug.cgi?id=2025

Quoted 1 line

Is it fixed maybe in a BIOS update ?

I don't think so. Advice already done, don't know if the owner have done that though.

Quoted 6 lines
Quoted 4 lines

* Integrate acpi perflib from Dominik.
* Use acpi if the PST tables are known to be broken (ASUS Aspire match one PST, but give brain damaged values), or use ACPI if no PST found.

Was that the one that had every entry exactly the same ?

It give:

powernow:  cpuid: 0x781 fsb: 133        maxFID: 0x1     startvid: 0xb
powernow:    FID: 0x4 (5.0x [665MHz])   VID: 0xc (1.400V)
powernow:    FID: 0x6 (6.0x [798MHz])   VID: 0xc (1.400V)
powernow:    FID: 0x8 (7.0x [931MHz])   VID: 0xc (1.400V)
powernow:    FID: 0x9 (7.5x [997MHz])   VID: 0xc (1.400V)
powernow:    FID: 0x9 (7.5x [997MHz])   VID: 0xc (1.400V)

Whereas actually it's a mobile (startvid is 0xb. So, voltage can be scaled).
And there is 'only' two entries with same values.

With ACPI, (not tested yet) it should give that:

FID: 0xd (9.5x [1263.500MHz] VID: 0xc (1.400mV)
FID: 0xa (8.0x [1064.000MHz] VID: 0xd (1.350mV)
FID: 0x8 (7.0x [931.000MHz] VID: 0xe (1.300mV)
FID: 0x6 (6.0x [798.000MHz] VID: 0x11 (1.250mV)
FID: 0x4 (5.0x [665.000MHz] VID: 0x13 (1.200mV)

It's better, but max still not here.

arch/i386/kernel/dmi_scan.c +6 -0
@@ -921,6 +921,12 @@ static __initdata struct dmi_blacklist d
 			NO_MATCH, NO_MATCH,
 			} },
 
+	{ acer_cpufreq_pst, "Acer Aspire", {
+			MATCH(DMI_SYS_VENDOR, "Insyde Software"),
+			MATCH(DMI_BIOS_VERSION, "3A23"),
+			NO_MATCH, NO_MATCH,
+			} },
+
 #ifdef	CONFIG_ACPI_BOOT
 	/*
 	 * If your system is blacklisted here, but you find that acpi=force
Signature · 4 lines
Bruno Ducrot

--  Which is worse:  ignorance or apathy?
--  Don't know.  Don't care.
#5 lore raw
In reply to Bruno Ducrot
Quoted 9 lines · Bruno Ducrot

* Integrate acpi perflib from Dominik.
* Use acpi if the PST tables are known to be broken (ASUS Aspire match one PST, but give brain damaged values), or use ACPI if no PST found.

 arch/i386/kernel/cpu/cpufreq/powernow-k7.c |  180 +++++++++++++++++++++++++++--
 1 files changed, 168 insertions(+), 12 deletions(-)
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +0 -0

....

Quoted 7 lines
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +1 -2
@@ -341,8 +480,14 @@ static int powernow_decode_bios (int max
 			}
 			printk (KERN_INFO PFX "No PST tables match this cpuid (0x%x)\n", etuple);
 			printk (KERN_INFO PFX "This is indicative of a broken BIOS.\n");
-			printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.shtml\n");
-			return -EINVAL;
+

arch/i386/kernel/cpu/cpufreq/powernow-k7.c static int powernow_decode_bios (int max · line 493

Quoted 10 lines
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +7 -0
+			printk (KERN_INFO PFX "Trying ACPI perflib\n");
+			ret = powernow_acpi_init();
+			if (ret) {
+				printk (KERN_INFO PFX "ACPI and legacy methods failed\n");
+				printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.shtml\n");
+			}
+			return ret;
 		}
 		p++;
 	}

This chunk is wrong, because I handle that at powernow_cpu_init() now. Just removing that one should be OK. Do you want I resend the whole patch, or only that part ?

Sorry.

Signature · 4 lines
Bruno Ducrot

--  Which is worse:  ignorance or apathy?
--  Don't know.  Don't care.
#6 lore raw
Quoted 26 lines · Bruno Ducrot
Quoted 9 lines · Bruno Ducrot

* Integrate acpi perflib from Dominik.
* Use acpi if the PST tables are known to be broken (ASUS Aspire match one PST, but give brain damaged values), or use ACPI if no PST found.

 arch/i386/kernel/cpu/cpufreq/powernow-k7.c |  180 +++++++++++++++++++++++++++--
 1 files changed, 168 insertions(+), 12 deletions(-)
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +0 -0

....

Quoted 14 lines
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +8 -2
@@ -341,8 +480,14 @@ static int powernow_decode_bios (int max
 			}
 			printk (KERN_INFO PFX "No PST tables match this cpuid (0x%x)\n", etuple);
 			printk (KERN_INFO PFX "This is indicative of a broken BIOS.\n");
-			printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.shtml\n");
-			return -EINVAL;
+
+			printk (KERN_INFO PFX "Trying ACPI perflib\n");
+			ret = powernow_acpi_init();
+			if (ret) {
+				printk (KERN_INFO PFX "ACPI and legacy methods failed\n");
+				printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.shtml\n");
+			}
+			return ret;
Quoted 8 lines

arch/i386/kernel/cpu/cpufreq/powernow-k7.c static int powernow_decode_bios (int max · line 493

Quoted 3 lines
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +0 -0
 		}
 		p++;
 	}

This chunk is wrong, because I handle that at powernow_cpu_init() now. Just removing that one should be OK. Do you want I resend the whole patch, or only that part ?

oops. just send me a patch backing out that bit..

Dave

#7 lore raw
Quoted 3 lines · Dave Jones

oops. just send me a patch backing out that bit..

I'm very sorry. I include the late_initcall btw. I think it's needed for ACPI perflib.

arch/i386/kernel/cpu/cpufreq/powernow-k7.c +7 -8
@@ -481,13 +481,7 @@ static int powernow_decode_bios (int max
 			printk (KERN_INFO PFX "No PST tables match this cpuid (0x%x)\n", etuple);
 			printk (KERN_INFO PFX "This is indicative of a broken BIOS.\n");
 
-			printk (KERN_INFO PFX "Trying ACPI perflib\n");
-			ret = powernow_acpi_init();
-			if (ret) {
-				printk (KERN_INFO PFX "ACPI and legacy methods failed\n");
-				printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.shtml\n");
-			}
-			return ret;
+			return -EINVAL;
 		}
 		p++;
 	}
@@ -568,7 +562,12 @@ static int __init powernow_cpu_init (str
 	} else {
 		result = powernow_decode_bios(fidvidstatus.bits.MFID, fidvidstatus.bits.SVID);
 		if (result) {
+			printk (KERN_INFO PFX "Trying ACPI perflib\n");
 			result = powernow_acpi_init();
+			if (result) {
+				printk (KERN_INFO PFX "ACPI and legacy methods failed\n");
+				printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.shtml\n");
+			}
 		} else {
 			/* SGTC use the bus clock as timer */
 			latency = fixup_sgtc();
@@ -638,6 +637,6 @@ MODULE_AUTHOR ("Dave Jones <davej@codemo
 MODULE_DESCRIPTION ("Powernow driver for AMD K7 processors.");
 MODULE_LICENSE ("GPL");
 
-module_init(powernow_init);
+late_initcall(powernow_init);
 module_exit(powernow_exit);
 
Signature · 4 lines
Bruno Ducrot

--  Which is worse:  ignorance or apathy?
--  Don't know.  Don't care.
#8 lore raw
In reply to Bruno Ducrot
Quoted 1 line · Bruno Ducrot

I actually wanted to submit also the ACPI integration...

I just tried this out on my Compaq Evo 1015. It has working PST, so just uses that. I got curious though, and hardwired it to fall back to the ACPI method. This is what it comes out with on PST..

powernow: PowerNOW! Technology present. Can scale: frequency and voltage.
powernow: FSB: 132.525 MHz
powernow: Found PSB header at 020f0800
powernow: Table version: 0x12
powernow: Flags: 0x0 (Mobile voltage regulator)
powernow: Settling Time: 100 microseconds.
powernow: Has 31 PST tables. (Only dumping ones relevant to this CPU).
powernow: PST:26 (@020f09c2)
powernow:  cpuid: 0x780 fsb: 133        maxFID: 0xf     startvid: 0x9
powernow:    FID: 0x12 (4.0x [530MHz])  VID: 0x13 (1.200V)
powernow:    FID: 0x4 (5.0x [662MHz])   VID: 0x13 (1.200V)
powernow:    FID: 0x6 (6.0x [795MHz])   VID: 0x13 (1.200V)
powernow:    FID: 0xa (8.0x [1060MHz])  VID: 0xd (1.350V)
powernow:    FID: 0xf (10.5x [1391MHz]) VID: 0x9 (1.550V)
powernow: SGTC: 13333
powernow: Minimum speed 530 MHz. Maximum speed 1391 MHz.

And with the hardwired acpi fallback..

powernow: Trying ACPI perflib
powernow: acpi:  P0: 1400 MHz, 35000 mW, 125 uS, control 009c412f, status 0000012f, vid: 09 fid: 0f SGTC: 10000
powernow:    FID: 0xf (10.5x [13913MHz])        VID: 0x9 (1.550V)
powernow: acpi:  P1: 1100 MHz, 15487 mW, 125 uS, control 009c41aa, status 000001aa, vid: 0d fid: 0a SGTC: 10000
powernow:    FID: 0xa (8.0x [10600MHz]) VID: 0xd (1.350V)
powernow: acpi:  P2: 800 MHz, 12310 mW, 125 uS, control 009c4266, status 00000266, vid: 13 fid: 06 SGTC: 10000
powernow:    FID: 0x6 (6.0x [7950MHz])  VID: 0x13 (1.200V)
powernow: acpi:  P3: 660 MHz, 12310 mW, 125 uS, control 009c4264, status 00000264, vid: 13 fid: 04 SGTC: 10000
powernow:    FID: 0x4 (5.0x [6625MHz])  VID: 0x13 (1.200V)
powernow: acpi:  P4: 530 MHz, 10258 mW, 125 uS, control 009c4272, status 00000272, vid: 13 fid: 12 SGTC: 10000
powernow:    FID: 0x12 (4.0x [5300MHz]) VID: 0x13 (1.200V)
powernow: Minimum speed 530 MHz. Maximum speed 13913 MHz.

Maximum speed seems off by a factor of 10.
Formatting of that debug info could also probably be cleaned up a little, as its very wide. How do you feel about adding a module_param to force fallback, so we can get a few more people testing it too ?

Dave

#9 lore raw
Quoted 8 lines · Dave Jones
Quoted 1 line · Bruno Ducrot

I actually wanted to submit also the ACPI integration...

I just tried this out on my Compaq Evo 1015. It has working PST, so just uses that. I got curious though, and hardwired it to fall back to the ACPI method. This is what it comes out with on PST..

Will take a look at cpufreq-2004-04-14 in a moment.

Quoted 4 lines

Maximum speed seems off by a factor of 10.
Formatting of that debug info could also probably be cleaned up a little, as its very wide. How do you feel about adding a module_param to force fallback, so we can get a few more people testing it too ?

I consider this to be a _very_ good idea.

Dominik

_______________________________________________
Cpufreq mailing list
[email protected]
http://www.linux.org.uk/mailman/listinfo/cpufreq

#10 lore raw
In reply to Dave Jones
Quoted 41 lines · Dave Jones
Quoted 1 line · Bruno Ducrot

I actually wanted to submit also the ACPI integration...

I just tried this out on my Compaq Evo 1015. It has working PST, so just uses that. I got curious though, and hardwired it to fall back to the ACPI method. This is what it comes out with on PST..

powernow: PowerNOW! Technology present. Can scale: frequency and voltage.
powernow: FSB: 132.525 MHz
powernow: Found PSB header at 020f0800
powernow: Table version: 0x12
powernow: Flags: 0x0 (Mobile voltage regulator)
powernow: Settling Time: 100 microseconds.
powernow: Has 31 PST tables. (Only dumping ones relevant to this CPU).
powernow: PST:26 (@020f09c2)
powernow:  cpuid: 0x780 fsb: 133        maxFID: 0xf     startvid: 0x9
powernow:    FID: 0x12 (4.0x [530MHz])  VID: 0x13 (1.200V)
powernow:    FID: 0x4 (5.0x [662MHz])   VID: 0x13 (1.200V)
powernow:    FID: 0x6 (6.0x [795MHz])   VID: 0x13 (1.200V)
powernow:    FID: 0xa (8.0x [1060MHz])  VID: 0xd (1.350V)
powernow:    FID: 0xf (10.5x [1391MHz]) VID: 0x9 (1.550V)
powernow: SGTC: 13333
powernow: Minimum speed 530 MHz. Maximum speed 1391 MHz.

And with the hardwired acpi fallback..

powernow: Trying ACPI perflib
powernow: acpi:  P0: 1400 MHz, 35000 mW, 125 uS, control 009c412f, status 0000012f, vid: 09 fid: 0f SGTC: 10000
powernow:    FID: 0xf (10.5x [13913MHz])        VID: 0x9 (1.550V)
powernow: acpi:  P1: 1100 MHz, 15487 mW, 125 uS, control 009c41aa, status 000001aa, vid: 0d fid: 0a SGTC: 10000
powernow:    FID: 0xa (8.0x [10600MHz]) VID: 0xd (1.350V)
powernow: acpi:  P2: 800 MHz, 12310 mW, 125 uS, control 009c4266, status 00000266, vid: 13 fid: 06 SGTC: 10000
powernow:    FID: 0x6 (6.0x [7950MHz])  VID: 0x13 (1.200V)
powernow: acpi:  P3: 660 MHz, 12310 mW, 125 uS, control 009c4264, status 00000264, vid: 13 fid: 04 SGTC: 10000
powernow:    FID: 0x4 (5.0x [6625MHz])  VID: 0x13 (1.200V)
powernow: acpi:  P4: 530 MHz, 10258 mW, 125 uS, control 009c4272, status 00000272, vid: 13 fid: 12 SGTC: 10000
powernow:    FID: 0x12 (4.0x [5300MHz]) VID: 0x13 (1.200V)
powernow: Minimum speed 530 MHz. Maximum speed 13913 MHz.
Quoted 1 line

Maximum speed seems off by a factor of 10.

Oh my... I've tested that and for some strange reason, I have noticed nothing..

Quoted 2 lines

Formatting of that debug info could also probably be cleaned up a little, as its very wide.

Ok, I will remove some debug info. Status is not needed, it's more to make ACPI spec happy actually. I need SGTC. I keep it. It's stupid to get fid and vid on the acpi line: I's redundant with the second debug line.

That give that for me now:

powernow: PowerNOW! Technology present. Can scale: frequency and voltage.
powernow: FSB: 132.720 MHz
powernow: PSB/PST known to be broken. Trying ACPI instead
powernow: acpi: P0: 1800 MHz 45000 mW 125 uS control 00d05975 SGTC 13334
powernow: FID: 0x15 (13.5x [1791MHz]) VID: 0xb (1.450V)
powernow: acpi: P1: 1200 MHz 22295 mW 125 uS control 00d05a2c SGTC 13334

powernow:    FID: 0xc (9.0x [1194MHz])  VID: 0x11 (1.250V)
powernow: acpi:  P2: 933 MHz 14671 mW 125 uS control 00d05aa8 SGTC 13334
powernow:    FID: 0x8 (7.0x [929MHz])   VID: 0x15 (1.150V)
powernow: acpi:  P3: 800 MHz 10487 mW 125 uS control 00d05b26 SGTC 13334
powernow:    FID: 0x6 (6.0x [796MHz])   VID: 0x19 (1.050V)
powernow: acpi:  P4: 667 MHz 8744 mW 125 uS control 00d05b24 SGTC 13334
powernow:    FID: 0x4 (5.0x [663MHz])   VID: 0x19 (1.050V)
powernow: Minimum speed 663 MHz. Maximum speed 1791 MHz.
Quoted 2 lines

How do you feel about adding a module_param to force fallback, so we can get a few more people testing it too ?

Agreed. Though I don't understand if you want ACPI enabled by default, or legacy?

arch/i386/kernel/cpu/cpufreq/powernow-k7.c +14 -6
@@ -17,6 +17,7 @@
 #include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/module.h> 
+#include <linux/moduleparam.h> 
 #include <linux/init.h>
 #include <linux/cpufreq.h>
 #include <linux/slab.h>
@@ -90,6 +91,12 @@ static int fid_codes[32] = {
     150, 225, 160, 165, 170, 180, -1, -1,
 };
 
+/* This parameter is used in order to force ACPI instead of legacy method for
+ * configuration purpose.
+ */
+
+static int powernow_acpi_force;
+
 static struct cpufreq_frequency_table *powernow_table;
 
 static unsigned int can_scale_bus;
@@ -349,21 +356,18 @@ static int powernow_acpi_init(void)
 		unsigned int speed;
 
 		pc.val = (unsigned long) acpi_processor_perf->states[i].control;
-		dprintk (KERN_INFO PFX "acpi:  P%d: %d MHz, %d mW, %d uS, control %08x, status %08x, vid: %02x fid: %02x SGTC: %d\n",
+		dprintk (KERN_INFO PFX "acpi:  P%d: %d MHz %d mW %d uS control %08x SGTC %d\n",
 			 i,
 			 (u32) acpi_processor_perf->states[i].core_frequency,
 			 (u32) acpi_processor_perf->states[i].power,
 			 (u32) acpi_processor_perf->states[i].transition_latency,
 			 (u32) acpi_processor_perf->states[i].control,
-			 (u32) acpi_processor_perf->states[i].status,
-			 pc.bits.vid,
-			 pc.bits.fid,
 			 pc.bits.sgtc);
 
 		vid = pc.bits.vid;
 		fid = pc.bits.fid;
 
-		powernow_table[i].frequency = (fsb * fid_codes[fid]);
+		powernow_table[i].frequency = fsb * fid_codes[fid] / 10;
 		powernow_table[i].index = fid; /* lower 8 bits */
 		powernow_table[i].index |= (vid << 8); /* upper 8 bits */
 
@@ -556,7 +560,7 @@ static int __init powernow_cpu_init (str
 	}
 	dprintk(KERN_INFO PFX "FSB: %3d.%03d MHz\n", fsb/1000, fsb%1000);
 
-	if (dmi_broken & BROKEN_CPUFREQ) {
+	if ((dmi_broken & BROKEN_CPUFREQ) || powernow_acpi_force) {
 		printk (KERN_INFO PFX "PSB/PST known to be broken.  Trying ACPI instead\n");
 		result = powernow_acpi_init();
 	} else {
@@ -633,6 +637,10 @@ static void __exit powernow_exit (void)
 		kfree(powernow_table);
 }
 
+module_param(powernow_acpi_force,  int, 0444);
+
+MODULE_PARM_DESC(powernow_acpi_force, "Force ACPI to be used");
+
 MODULE_AUTHOR ("Dave Jones <[email protected]>");
 MODULE_DESCRIPTION ("Powernow driver for AMD K7 processors.");
 MODULE_LICENSE ("GPL");
Signature · 4 lines
Bruno Ducrot

--  Which is worse:  ignorance or apathy?
--  Don't know.  Don't care.
#11 lore raw

arch/i386/kernel/cpu/cpufreq/powernow-k7.c static int powernow_acpi_init(void) · line 370

Quoted 2 lines · Bruno Ducrot
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +1 -1
-		powernow_table[i].frequency = (fsb * fid_codes[fid]);
+		powernow_table[i].frequency = fsb * fid_codes[fid] / 10;

OK, you were faster :-)

arch/i386/kernel/cpu/cpufreq/powernow-k7.c static void __exit powernow_exit (void) · line 643

Quoted 4 lines
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +4 -0
+module_param(powernow_acpi_force,  int, 0444);
+
+MODULE_PARM_DESC(powernow_acpi_force, "Force ACPI to be used");
+

FYI, currently

powernow-k8 has primary mode ACPI fallback: PST
powernow-k7 PST ACPI
speedstep-centrino ACPI builtin-table

and
acpi-io only uses ACPI, of course. n/a

Dominik

_______________________________________________
Cpufreq mailing list
[email protected]
http://www.linux.org.uk/mailman/listinfo/cpufreq

#12 lore raw
Quoted 9 lines · Dominik Brodowski

FYI, currently

powernow-k8 has primary mode ACPI fallback: PST
powernow-k7 PST ACPI
speedstep-centrino ACPI builtin-table

and
acpi-io only uses ACPI, of course. n/a

Sound ok for me.

Signature · 4 lines
Bruno Ducrot

--  Which is worse:  ignorance or apathy?
--  Don't know.  Don't care.
#13 lore raw
In reply to Dave Jones
Quoted 28 lines · Dave Jones
Quoted 1 line · Bruno Ducrot

I actually wanted to submit also the ACPI integration...

I just tried this out on my Compaq Evo 1015. It has working PST, so just uses that. I got curious though, and hardwired it to fall back to the ACPI method. This is what it comes out with on PST..

powernow: PowerNOW! Technology present. Can scale: frequency and voltage.
powernow: FSB: 132.525 MHz
powernow: Found PSB header at 020f0800
powernow: Table version: 0x12
powernow: Flags: 0x0 (Mobile voltage regulator)
powernow: Settling Time: 100 microseconds.
powernow: Has 31 PST tables. (Only dumping ones relevant to this CPU).
powernow: PST:26 (@020f09c2)
powernow:  cpuid: 0x780 fsb: 133        maxFID: 0xf     startvid: 0x9
powernow:    FID: 0x12 (4.0x [530MHz])  VID: 0x13 (1.200V)
powernow:    FID: 0x4 (5.0x [662MHz])   VID: 0x13 (1.200V)
powernow:    FID: 0x6 (6.0x [795MHz])   VID: 0x13 (1.200V)
powernow:    FID: 0xa (8.0x [1060MHz])  VID: 0xd (1.350V)
powernow:    FID: 0xf (10.5x [1391MHz]) VID: 0x9 (1.550V)
powernow: SGTC: 13333
powernow: Minimum speed 530 MHz. Maximum speed 1391 MHz.

And with the hardwired acpi fallback..

Quoted 12 lines
powernow: Trying ACPI perflib
powernow: acpi:  P0: 1400 MHz, 35000 mW, 125 uS, control 009c412f, status 0000012f, vid: 09 fid: 0f SGTC: 10000
powernow:    FID: 0xf (10.5x [13913MHz])        VID: 0x9 (1.550V)
powernow: acpi:  P1: 1100 MHz, 15487 mW, 125 uS, control 009c41aa, status 000001aa, vid: 0d fid: 0a SGTC: 10000
powernow:    FID: 0xa (8.0x [10600MHz]) VID: 0xd (1.350V)
powernow: acpi:  P2: 800 MHz, 12310 mW, 125 uS, control 009c4266, status 00000266, vid: 13 fid: 06 SGTC: 10000
powernow:    FID: 0x6 (6.0x [7950MHz])  VID: 0x13 (1.200V)
powernow: acpi:  P3: 660 MHz, 12310 mW, 125 uS, control 009c4264, status 00000264, vid: 13 fid: 04 SGTC: 10000
powernow:    FID: 0x4 (5.0x [6625MHz])  VID: 0x13 (1.200V)
powernow: acpi:  P4: 530 MHz, 10258 mW, 125 uS, control 009c4272, status 00000272, vid: 13 fid: 12 SGTC: 10000
powernow:    FID: 0x12 (4.0x [5300MHz]) VID: 0x13 (1.200V)
powernow: Minimum speed 530 MHz. Maximum speed 13913 MHz.

1.) get_ranges() has

		powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10;
  powernow_acpi_init() has
		powernow_table[i].frequency = (fsb * fid_codes[fid]);

2.) minimum_speed, maximum_speed, latency should be cleared before powernow_acpi_init() is called.

arch/i386/kernel/cpu/cpufreq/powernow-k7.c renamed from arch/i386/kernel/cpu/cpufreq/powernow-k7.c.original +4 -1
@@ -363,7 +363,7 @@
 		vid = pc.bits.vid;
 		fid = pc.bits.fid;
 
-		powernow_table[i].frequency = (fsb * fid_codes[fid]);
+		powernow_table[i].frequency = (fsb * fid_codes[fid]) / 10;
 		powernow_table[i].index = fid; /* lower 8 bits */
 		powernow_table[i].index |= (vid << 8); /* upper 8 bits */
 
@@ -563,6 +563,9 @@
 		result = powernow_decode_bios(fidvidstatus.bits.MFID, fidvidstatus.bits.SVID);
 		if (result) {
 			printk (KERN_INFO PFX "Trying ACPI perflib\n");
+			maximum_speed = 0;
+			minimum_speed = -1;
+			latency = 0;
 			result = powernow_acpi_init();
 			if (result) {
 				printk (KERN_INFO PFX "ACPI and legacy methods failed\n");