[PATCH: apm fixes] Re: Linux 2.3.99pre9-2 JOB list

From: Pavel Machek (pavel@suse.cz)
Date: Thu May 18 2000 - 15:09:21 EST


Hi!

> > > USB hangs on APM suspend on some machines
> > Fix exist, and is in apm code. Do you want a copy?
>
> Doesnt work on my palmax because of the IRQ flood problem the USB folks havent
> sorted yet

Okay, but this should make apm critical suspend work at least for
me. It also fixes kapmd not being able to slow down more than 50% of
time (thus not saving enough battery power; that's showstopper, too)

--- clean/arch/i386/kernel/apm.c Fri Mar 10 02:15:02 2000
+++ linux/arch/i386/kernel/apm.c Fri May 5 23:58:31 2000
@@ -921,6 +921,10 @@
         case APM_USER_SUSPEND:
                 /* map all suspends to ACPI D3 */
                 if (pm_send_all(PM_SUSPEND, (void *)3)) {
+ if (event == APM_CRITICAL_SUSPEND) {
+ printk( "apm: Critical suspend was vetoed, expect armagedon\n" );
+ return 0;
+ }
                         if (apm_bios_info.version > 0x100)
                                 apm_set_power_state(APM_STATE_REJECT);
                         return 0;
@@ -933,7 +937,6 @@
                 break;
         }
 
- queue_event(event, sender);
         return 1;
 }
 
@@ -967,6 +970,7 @@
                                 break;
 #endif
                         if (send_event(event, NULL)) {
+ queue_event(event, NULL);
 #ifdef CONFIG_APM_IGNORE_MULTIPLE_SUSPEND
                                 waiting_for_resume = 1;
 #endif
@@ -991,6 +995,7 @@
                                 break;
 #endif
                         if (send_event(event, NULL)) {
+ queue_event(event, NULL);
 #ifdef CONFIG_APM_IGNORE_MULTIPLE_SUSPEND
                                 waiting_for_resume = 1;
 #endif
@@ -1011,6 +1016,7 @@
 #endif
                         set_time();
                         send_event(event, NULL);
+ queue_event(event, NULL);
                         break;
 
                 case APM_CAPABILITY_CHANGE:
@@ -1024,6 +1030,7 @@
                         break;
 
                 case APM_CRITICAL_SUSPEND:
+ send_event(event, NULL); /* We can only hope it worked; critical suspend may not fail */
                         (void) suspend();
                         break;
                 }
@@ -1058,6 +1065,7 @@
 
 static void apm_mainloop(void)
 {
+ int timeout = HZ;
         DECLARE_WAITQUEUE(wait, current);
 
         if (smp_num_cpus > 1)
@@ -1067,7 +1075,10 @@
         current->state = TASK_INTERRUPTIBLE;
         for (;;) {
                 /* Nothing to do, just sleep for the timeout */
- schedule_timeout(APM_CHECK_TIMEOUT);
+ timeout = 2*timeout;
+ if (timeout > APM_CHECK_TIMEOUT)
+ timeout = APM_CHECK_TIMEOUT;
+ schedule_timeout(timeout);
                 if (exit_kapmd)
                         break;
 
@@ -1082,13 +1093,16 @@
                         continue;
                 if (apm_do_idle()) {
                         unsigned long start = jiffies;
- while (system_idle()) {
+ while ((!exit_kapmd) && system_idle()) {
                                 apm_do_idle();
- if (jiffies - start > APM_CHECK_TIMEOUT)
- break;
+ if (jiffies - start > (5*APM_CHECK_TIMEOUT)) {
+ apm_event_handler();
+ start = jiffies;
+ }
                         }
                         apm_do_busy();
                         apm_event_handler();
+ timeout = 1;
                 }
 #endif
         }

Part after apm_mainloop is something I'm not 100% sure has no side
effects; but what is currently there is DEFINITELY broken. Part before
apm_mainloop is safe.
                                                                Pavel

-- 
I'm pavel@ucw.cz. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents me at discuss@linmodems.org

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue May 23 2000 - 21:00:18 EST