Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Power Management (sleep) questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Power Management (sleep) questions



Hi Jim-

I'm adding Power Management support to my driver, specifically for ExpressCard support.  When the device was just PCIe, we didn't support sleep, because the device doesn't support any intermediate states, and the code wasn't really written in a way that's conducive to saving/restoring device state.  This is more of an issue now with the ExpressCard device.

At this point, we can't support sleep at any arbitrary time, but we can support it at well-defined times (i.e. requiring the user to select a menu item in our control app "Prepare for sleep" first for example).  I know this isn't ideal but I'm hoping we can make it work this way as a first pass.  I'm wondering if there is a way to tell the PM that the we *cannot* go into deep sleep until further notice? The idea is we'd indicate this to the PM when the device is in use, then when the user tells us manually to prepare for sleep, we'd clean things up in the driver and then tell the PM that we can go to sleep.


Why can't you support sleep at any arbitrary time?

Why can't you take whatever action you would be taking at "user selects 'prepare for sleep' time" at actual ystem go to sleep time?

What is it you need to do in the 'prepare for sleep' menu item? I'd suggest that you bite the bullet and go ahead and implement a full sleep/wake handler, because disabling sleep isn't an option.
• Your driver can stall the going to sleep process for an arbitrary amount of time to finish whatever it needs to do, like complete outstanding I/Os 
• And there are a number of ways to block incoming I/O requests while your device is going to sleep, and any time the hardware is unavailable. I'd be happy to talk about some IOWorkLoop techniques you can use to synchronize access to your hw if this is the problem.

I played around with this a bit, but couldn't figure out how to do it.  On desktop machines, if I don't register with the PM, then the machine never goes into deep sleep; it seems to assume that any device that isn't specifically power-managed should never go into deep sleep.  If I do register with PM, the machine does go into deep sleep, and I can't seem to make it NOT do this.  I found that if I just call PMstop() when I don't want to allow sleep, then it does behave as I would like and doesn't go into deep sleep.


You cannot disable sleep on a portable.

Desktop machines will not fully sleep if there's a non-power managed PCI card attached. We intentionally don't grant portables this luxury. If you're writing a driver for a ExpressCard, it needs to be power managed.

However, this is not the case on the MacBook Pro.  It seems to always put the machine into deep sleep regardless whether there's a power-managed driver installed for the ExpressCard device or not.

In user-land, there's the IOAllow/CancelPowerChange calls, which look like the app can call in response to the kIOMessageCanSystemSleep/kIOMessageSystemWillSleep messages.  Is there something similar in kernel space?


Even in userland, a menu item sleep or a closed-clamshell sleep does not generate a kIOMessageCanSystemSleep message. Only idle sleep is cancellable; any kind of "forced" sleep is non-cancellable.

One final thing.  Currently, if no device driver is installed for our ExpressCard device, but the card itself is installed, then if the laptop is put to sleep, the system will hang.  This seems very odd as there is no software involved other than the OS.  Any ideas what could be causing this, or where to look to debug it?


Bummer. Are you familiar with FireWire kprintf debugging? As long as your device isn't a FireWire device of some sort, this will be super handy for you. FireWire kprintf's let you get printf-style logs out of a computer via the FireWire port throughout the sleep/wake process, past the point where ethernet and disks power off.

So I'd recommend you get some FireWire kprintf logs of this sleep problem and send it to me, or preferably file a bug to Apple through ADC. Here's FW kprintf debugging instructions:

1. Download and install FireWire SDK 23:

2. Navigate to /Developer/FireWireSDK23/Tools/FireWireKPrintf 1.1.5

3. Open ReadMe.rtf

4. Per instructions in ReadMe.rtf:
• Install AppleFireWireKPrintf.kext on PowerBook with wake issue
• Run: sudo nvram boot-args = "debug=0x14e io=0x80"
• Reboot
• Connect to a 2nd mac and run FireWireKPrintfViewer to collect logs

Please collect logs from one successful sleep/wake, and at least one or two failed wakes from sleep. And thank you!!



-Ethan Bold
I/O Kit Power Management
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-drivers mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Power Management (sleep) questions (From: Jim Wintermyre <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.