Skip to contentSkip to conversation

amd76x_pm port to 2.5.70

PATCH In review Pasi Savolainen 6 participants 6 messages May 31, 2003 – Jun 1, 2003 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 amd76x_pm port to 2.5.70

Attached is a simplistic port of amd76x_pm to 2.5.70. There is a mention about being non-preempt safe, and I can't tell spinlock from semaphore, so can do nada about it.
zwane told me on #kernelnewbies that

  pm_idle = old_pm_idle; wmb();

should take care about the processor syncing, but I do get total hangs on rmmod.

There's also the thing that in 2.5.70-mm2 pm_idle doesn't get called at all unless there's some load. eg. if I load this on boot, before starting X, /proc/drivers/amd76x_pm stays at 0.

drivers/char/Kconfig +15 -0
diff -Nru linux-2.5.70/drivers/char/Kconfig linux-2.5.70-mod/drivers/char/Kconfig
@@ -737,6 +737,21 @@
 
 	  If unsure, say N.
 
+config AMD76X_PM
+        tristate "AMD76x Native Power Management support"
+        depends on X86 && PCI
+        ---help---
+         This driver enables Power Management on AMD760MP & AMD760MPX chipsets.
+	  This is about same as ACPI C2, except that ACPI folks don't do SMP ATM.
+	  A /proc/drivers/amd76x_pm -statistics file will be created at runtime.
+
+	  To compile this driver as a module ( = code which can be inserted in
+	  and removed from the running kernel whenever you want), say M here
+	  and read <file:Documentation/modules.txt>. The module will be called
+	  amd76x_pm, it cannot be unloaded.	 
+
+	  If unsure, say N.
+
 config NVRAM
 	tristate "/dev/nvram support"
 	---help---
drivers/char/Makefile +1 -0
diff -Nru linux-2.5.70/drivers/char/Makefile linux-2.5.70-mod/drivers/char/Makefile
@@ -61,6 +61,7 @@
 obj-$(CONFIG_I8K) += i8k.o
 obj-$(CONFIG_DS1620) += ds1620.o
 obj-$(CONFIG_HW_RANDOM) += hw_random.o
+obj-$(CONFIG_AMD76X_PM) += amd76x_pm.o
 obj-$(CONFIG_QIC02_TAPE) += tpqic02.o
 obj-$(CONFIG_FTAPE) += ftape/
 obj-$(CONFIG_H8) += h8.o
drivers/char/amd76x_pm.c +711 -0

711 lines not on this page · raw message

include/linux/amd76x_pm.h +59 -0

59 lines not on this page · raw message

Signature · 1 line
Psi -- <http://iki.fi/psavo>
#1 lore raw
Quoted 9 lines · Pasi Savolainen

Attached is a simplistic port of amd76x_pm to 2.5.70. There is a mention about being non-preempt safe, and I can't tell spinlock from semaphore, so can do nada about it.
zwane told me on #kernelnewbies that

  pm_idle = old_pm_idle; wmb();

should take care about the processor syncing, but I do get total hangs on rmmod.

pm_idle = NULL_or_previous_handler;
synchronize_kernel();
unload_module;

drivers/char/amd76x_pm.c line 496

Quoted 5 lines
drivers/char/amd76x_pm.c +5 -0
+amd76x_up_idle(void)
+{
+	// FIXME: Optionally add non-smp idle loop here
+}
+#endif

This is going to really suck power wise, at least do a rep_nop or some such otherwise you spin in a tight polling loop around need_resched.

drivers/char/amd76x_pm.c line 516

Quoted 13 lines
drivers/char/amd76x_pm.c +13 -0
+static void
+amd76x_smp_idle(void)
+{
+	/*
+	 * Exit idle mode immediately if the CPU does not change.
+	 * Usually that means that we have some load on another CPU.
+	 */
+
+	if (prs[0].idle && prs[1].idle && amd76x_pm_cfg.last_pr == smp_processor_id()) {
+		prs[0].idle = 0;
+		prs[1].idle = 0;
+		/* This looks redundent as it was just checked in the if() */
+		/* amd76x_pm_cfg.last_pr = smp_processor_id(); */

One is a comparison the other an assignment, what's going on here?

drivers/char/amd76x_pm.c line 677

Quoted 7 lines
drivers/char/amd76x_pm.c +7 -0
+static void __exit
+amd76x_pm_cleanup(void)
+{
+#ifndef AMD76X_NTH
+	pm_idle = amd76x_pm_cfg.orig_idle;
+	wmb();
+	//__asm__ __volatile__ ("wbinvd;"); // propagate through SMP

synchronize_kernel() here, then you should be safe to unload.

Signature · 1 line
function.linuxpower.ca
#2 lore raw
In reply to Pasi Savolainen

drivers/char/amd76x_pm.c line 233

Quoted 6 lines · Pasi Savolainen
drivers/char/amd76x_pm.c +6 -0
+	/* Clear W4SG, and set PMIOEN, if using a 765/766 set STPGNT as well.
+	 * AMD-766: C3A41; page 59 in AMD-766 doc
+	 * AMD-768: DevB:3x41C; page 94 in AMD-768 doc */
+	pci_read_config_byte(pdev_sb, 0x41, &regbyte);
+	if(enable) {
+		regbyte |= ((0 << 0) | (is_766?1:0 << 1) | (1 << 7));
                         ^^^^^^

This looks totally bogus. If you want that bit clearing, you need to AND its inverse, not OR it. The second statement also looks a bit funny to the eye.

drivers/char/amd76x_pm.c line 236

Quoted 3 lines
drivers/char/amd76x_pm.c +3 -0
+	}
+	else {
+		regbyte |= (0 << 7);

Ditto.

Quoted 4 lines

+/*
+ * Idle loop for SMP systems, supports currently only 2 processors.
+ *
+ * Note; for 2.5 folks - not pre-empt safe

Indeed.

drivers/char/amd76x_pm.c line 516

Quoted 13 lines
drivers/char/amd76x_pm.c +13 -0
+static void
+amd76x_smp_idle(void)
+{
+	/*
+	 * Exit idle mode immediately if the CPU does not change.
+	 * Usually that means that we have some load on another CPU.
+	 */
+
+	if (prs[0].idle && prs[1].idle && amd76x_pm_cfg.last_pr == smp_processor_id()) {
+		prs[0].idle = 0;
+		prs[1].idle = 0;
+		/* This looks redundent as it was just checked in the if() */
+		/* amd76x_pm_cfg.last_pr = smp_processor_id(); */

except with preemption, it may have changed. This needs to be fixed, as noted in the function header. Either get_cpu(),put_cpu() or explicit preempt_enable/disable()

drivers/char/amd76x_pm.c line 555

Quoted 3 lines
drivers/char/amd76x_pm.c +3 -0
+
+/*
+ *    Info exported through "/proc/driver/amd76x_pm"

This should really be using sysfs. Adding extra junk to /proc is somewhat frowned upon, and with the other PM stuff now living in sysfs, that seems to be the way forward.

drivers/char/amd76x_pm.c line 677

Quoted 7 lines
drivers/char/amd76x_pm.c +7 -0
+static void __exit
+amd76x_pm_cleanup(void)
+{
+#ifndef AMD76X_NTH
+	pm_idle = amd76x_pm_cfg.orig_idle;
+	wmb();
+	//__asm__ __volatile__ ("wbinvd;"); // propagate through SMP

Not sure why this was there, is it noted in the 766 spec to flush the cache ? if so, it needs to be reenabled, and used with on_each_cpu()

drivers/char/amd76x_pm.c line 697

Quoted 10 lines
drivers/char/amd76x_pm.c +10 -0
+	/* 
+	 * FIXME: We want to wait until all CPUs have set the new
+	 * idle function, otherwise we will oops. This may not be
+	 * the right way to do it, but seems to work.
+	 *
+	 * - Best answer is going to be to ban unload, but when its debugged
+	 *   --- Alan
+	 */
+	schedule();
+	mdelay(1000);

Ummmm, oh-kay. That's a little funky. Look at how the MTRR driver does its synchronisation, it maybe sucky, but it looks a little cleaner than this IMO.

Quoted 1 line

+#define LAZY_IDLE_DELAY 800 /* 0: Best savings, 3000: More responsive */

Sounds like possible candidate for something that should be exposed via sysfs.

Dave

#3 lore raw

* Dave Jones <[email protected]>:

Quoted 9 lines · Pasi Savolainen

drivers/char/amd76x_pm.c line 233

Quoted 6 lines
drivers/char/amd76x_pm.c +6 -0
+	/* Clear W4SG, and set PMIOEN, if using a 765/766 set STPGNT as well.
+	 * AMD-766: C3A41; page 59 in AMD-766 doc
+	 * AMD-768: DevB:3x41C; page 94 in AMD-768 doc */
+	pci_read_config_byte(pdev_sb, 0x41, &regbyte);
+	if(enable) {
+		regbyte |= ((0 << 0) | (is_766?1:0 << 1) | (1 << 7));
                         ^^^^^^
Quoted 3 lines

This looks totally bogus. If you want that bit clearing, you need to AND its inverse, not OR it. The second statement also looks a bit funny to the eye.

AFAICT, it's 'for future expansion', NMC. I'll trim it down. Either way, that enable seems to work, at least on my machine. As I don't know much about it, I can't say what's right/wrong.
(I don't have the spec. Only code that does desired thing)

Quoted 9 lines
Quoted 9 lines
drivers/char/amd76x_pm.c +9 -0
+static void
+amd76x_smp_idle(void)
+{
+	/*
+	 * Exit idle mode immediately if the CPU does not change.
+	 * Usually that means that we have some load on another CPU.
+	 */
+
+	if (prs[0].idle && prs[1].idle && amd76x_pm_cfg.last_pr == smp_processor_id()) {
Quoted 8 lines

drivers/char/amd76x_pm.c line 516

Quoted 4 lines
drivers/char/amd76x_pm.c +4 -0
+		prs[0].idle = 0;
+		prs[1].idle = 0;
+		/* This looks redundent as it was just checked in the if() */
+		/* amd76x_pm_cfg.last_pr = smp_processor_id(); */

except with preemption, it may have changed. This needs to be fixed, as noted in the function header. Either get_cpu(),put_cpu() or explicit preempt_enable/disable()

This is idle loop, like we're not doing anything, and if somebody is to preempt us, then it sure means we're not supposed to idle.

Second point is (I'm _really_ on thin ground here..) that if we get_cpu() here, and other CPU is sleeping, then it'd be woken up sooner, for cache will need syncing.

Quoted 6 lines
Quoted 2 lines

+/*
+ * Info exported through "/proc/driver/amd76x_pm"

This should really be using sysfs. Adding extra junk to /proc is somewhat frowned upon, and with the other PM stuff now living in sysfs, that seems to be the way forward.

done.

Quoted 11 lines

drivers/char/amd76x_pm.c line 677

Quoted 8 lines
drivers/char/amd76x_pm.c +7 -0
+static void __exit
+amd76x_pm_cleanup(void)
+{
+#ifndef AMD76X_NTH
+	pm_idle = amd76x_pm_cfg.orig_idle;
+	wmb();
+	//__asm__ __volatile__ ("wbinvd;"); // propagate through SMP

Not sure why this was there, is it noted in the 766 spec to flush the cache ? if so, it needs to be reenabled, and used with on_each_cpu()

Zwane told me to use synchronize_kernel(); it cured my crashes on rmmod amd76x_pm. -> hack removed.

Quoted 2 lines

Sounds like possible candidate for something that should be exposed via sysfs.

done.

Iteration n at
<http://varg.dyndns.org/psi/files/misc/amd76x_pm-2.5.70.patch.bz2>

/sys/devices/pci0/00:00.0/C2_cnt (ro) number of C2 calls made. /sys/devices/pci0/00:00.0/lazy_idle (rw) number of successfull idle
calls to be made before entering C2.

Signature · 1 line
   Psi -- <http://www.iki.fi/pasi.savolainen>
#4 lore raw
In reply to Pasi Savolainen
Quoted 1 line · [email protected] said:

+++ linux-2.5.70-mod/drivers/char/amd76x_pm.c 2003-05-31 20:55:37.000000000 +0300

What is this thing doing in drivers/char? It has nothing whatsoever to do with char devices. Couldn't this be handled by the ACPI idle loop?

Jason

#5 lore raw
Quoted 5 lines · Jason Lunz
Quoted 1 line · [email protected] said:

+++ linux-2.5.70-mod/drivers/char/amd76x_pm.c 2003-05-31 20:55:37.000000000 +0300

What is this thing doing in drivers/char? It has nothing whatsoever to do with char devices. Couldn't this be handled by the ACPI idle loop?

RTFS 8)

Its an alternative driver to the ACPI driver. I'm not sure where it should go but in 2.4 its in drivers/char. 2.5.x puts the other PM drivers in arch/i386 so maybe that is where it belongs