PATCH: apm.c - runtime parameter for APM Idle call
After investigating kapm_idled problem here it turned out quite simple - BIOS neither slows down CPU nor halts it so kapm_idled enters busy loop doing basically
while !system_busy
do nothing
eating away CPU. This applies to patch of Andreas as well.
I do not like an option of recompiling without CONFIG_APM_CPU_IDLE because I think about distribution kernel in the first place. I have ASUS CUSL2 motherboard - it is not unusual brand and obviously many people have the same problem and you cannot expect all of them to recompile kernel. So this patch adds runtime parameter (no-)apm-idle that has the same effect - enabling/disabling usage of APM Idle BIOS calls. It is initialised according to CONFIG_APM_CPU_IDLE and should be 100% compatible.
If Andreas patch is accepted it needs the same treatment.
I thought once about run-time detection - if BIOS reports that Idle does not slow down CPU try Idle call once and compare jiffies (probably repeat several times to be sure). Is it sensible?
Patch is agains 2.4.16-9.dk but should apply to any version I guess.
-andrej
i386/kernel/apm.c renamed from i386/kernel/apm.c.org +9 -2
@@ -383,6 +383,11 @@static int allow_ints;#endif static int broken_psr; +#ifdef CONFIG_APM_CPU_IDLE +static int apm_idle_enabled =1 ; +#else +static int apm_idle_enabled; +#endif static DECLARE_WAIT_QUEUE_HEAD (apm_waitqueue);static DECLARE_WAIT_QUEUE_HEAD (apm_suspend_waitqueue);
@@ -1366,7 +1371,8 @@*/ set_current_state (TASK_INTERRUPTIBLE );apm_event_handler (); -#ifdef CONFIG_APM_CPU_IDLE +if (!apm_idle_enabled) +continue ;if (!system_idle ())continue ;
@@ -1393,7 +1399,6 @@apm_event_handler (); timeout =1 ; } -#endif }remove_wait_queue (&apm_waitqueue, &wait); }
@@ -1814,6 +1819,8 @@if ((strncmp (str,"realmode-power-off" ,18 ) ==0 ) || (strncmp (str,"realmode_power_off" ,18 ) ==0 )) apm_info.realmode_power_off = !invert; +if (strncmp (str,"apm-idle" ,8 ) ==0 ) + apm_idle_enabled = !invert; str =strchr (str,',' );if (str !=NULL ) str +=strspn (str,", \t" );
Quoted 3 lines · Borsenkow Andrej
I thought once about run-time detection - if BIOS reports that Idle does not slow down CPU try Idle call once and compare jiffies (probably repeat several times to be sure). Is it sensible?
A far simpler way would be to add DMI blacklist entries for the BIOSes that don't do this, although this assumes the problem machine has a DMI compliant BIOS.
Dave.
Signature · 2 lines
| Dave Jones. http://www.codemonkey.org.uk | SuSE Labs
PATCH: apm.c - detection of brokern APM Idle call implementation
Quoted 10 lines · Dave Jones
Quoted 3 lines · Borsenkow Andrej
I thought once about run-time detection - if BIOS reports that Idle does not slow down CPU try Idle call once and compare jiffies (probably repeat several times to be sure). Is it sensible?
A far simpler way would be to add DMI blacklist entries for the BIOSes that don't do this, although this assumes the problem machine has a DMI compliant BIOS.
Well, the following three-liners (+ comments) seems to do it. It checks if clock was advanced after return from APM Idle - if not we assume BIOS did not halt CPU and do it ourselves. The addidional condition && !current->need_resched is for the case when BIOS did halt CPU and non-clock interrupt happened that waked up somebody else. But may be I am just plain paranoid. The code has no impact for "BIOS slows CPU" case.
It works here for broken BIOS. I appreciate if people with good BIOS test it.
-andrej
apm.c renamed from apm.c.bor +7 -2
@@ -1381,13 +1381,18 @@*/ if (apm_do_idle () !=-1 ) {unsigned long start = jiffies; +unsigned long before;while ((!exit_kapmd) &&system_idle ()) { -if (apm_do_idle ()) { + before = jiffies; +if (apm_do_idle () || (jiffies == before && !current->need_resched)) {set_current_state (TASK_INTERRUPTIBLE );/* APM needs us to snooze .. either the BIOS call failed (-1) or it slowed the clock (1). We sleep -until it talks to us again */ +until it talks to us again. +If clock did not advance CPU was +not halted by BIOS so we do it +now*/ schedule_timeout (1 ); }if ((jiffies - start) >APM_CHECK_TIMEOUT ) {