Feb 15, 2011

Your MacBook can sleep smarter

I love my MacBook Pro, it's my primary computer actually and I used it for just about everything email, surfing, writing, and programming. I don't even think this is odd at all anymore as most of my friends and co-workers use laptop's as their primary computers; I suspect it could be the normal case at this point.

On several occasions when I've come back to my computer I've been surprised to find it powered off, weird, so I press the power button (I use the power button so seldomly that it feels a bit odd because the button is perfectly flush mounted which I apparently forget from time to time). Next, also to my surprise, it wakes from hibernation so I check ... sure enough the battery is almost dead. My wife or a family member must have unplugged it or tripped over the cord detaching the mag-safe power connector. I very much appreciate the SafeSleep functionality but it really needs to be a little smarter in my opinion. It just needs an additional hibernation timeout setting to save even more battery in instances like I've had.

I've been using iPhones for nearly 3 years and my iPad for almost a year and it's surprising to me that my unibody MBP hasn't learned the same tricks already. So, thinking I must be missing an obvious power setting somewhere I poked around apple's support forum's but wasn't able to find any useful information. It happened again recently and I dug a little deeper. I didn't find a way to setup sleep as I've described but I did find a way to use SafeSleep when connected to AC Power and switch to hibernation sleep when running on your battery. Doing so requires Terminal but the command is quick and easy.

Let's define a few terms for clarity:
Sleep
The default on supported desktops. The system will not back memory up to persistent storage. The system must wake from the contents of memory; the system will lose context on power loss. This is, historically, plain old sleep.

SafeSleep
The default on supported portables. The system will store a copy of memory to persistent storage (the disk), and will power memory during sleep. The system will wake from memory, unless a power loss forces it to restore from disk image.

Hibernation
Only settable via the 'pmset' command. The system will store a copy of memory to persistent storage (the disk), and will remove power to memory. The system will restore from disk image. If you want "hibernation" - slower sleeps, slower wakes, and better battery life, you should use this setting.

DeepSleep
Activates kernel power management to automatically hibernate a machine after it has slept for a specified time period. This saves power while asleep. This setting defaults to ON for supported hardware. DeepSleep only works if Hibernation or SafeSleep are turned on.
Yes, DeepSleep is exactly what I want, but why isn't it working then if it "defaults to ON"? Oh, "for supported hardware"...
The setting 'DeepSleep' will be visible via 'pmset -g' if the feature is supported on this machine.
OK. Let's see what's supported on my unibody MacBook Pro (MacBookPro5,4). Open Terminal and type the command 'pmset -g' and the return key. You should see something similar to:
pmset -g
Active Profiles:
Battery Power -1
AC Power -1*
Currently in use:
hibernatemode 3
halfdim 0
lidwake 1
acwake 0
womp 1
sleep 30
disksleep 10
sms 1
hibernatefile /var/vm/sleepimage
ttyskeepawake 1
displaysleep 15
Nope, not supported. I think the 2nd generation MacBook Air may be the only laptops that support DeepSleep at the time of this post... It looks like we can however enable Hibernation when we are not running on AC Power. Here are the commands I use, tweak them to your preferences:

My Hibernation setting when running on battery power
$ pmset -b hibernatemode 25 displaysleep 5 disksleep 3 sleep 30 womp 1 lidwake 1 acwake 1 lessbright 1 halfdim 1 sms 1
My SmartSleep setting when running no AC power adapter

pmset -c hibernatemode 3 displaysleep 10 disksleep 10 sleep 30 womp 1 lidwake 1 acwake 1 lessbright 1 halfdim 1 sms 1
pmset arguments (excerpt from 'man pmset'):
hibernatemode
change hibernation mode. Please use caution. (value = integer) [3, and 25 are safe. You don't want to use 0 on a portable. ]

displaysleep
display sleep timer; replaces 'dim' argument in 10.4 (value in minutes, or 0 to disable)

disksleep
disk spindown timer; replaces 'spindown' argument in 10.4 (value in minutes, or 0 to disable)

sleep
system sleep timer (value in minutes, or 0 to disable) [only effects the timeout, not the sleep mode]

womp
wake on ethernet magic packet (value = 0/1) [wired ethernet only has no effect over wifi]

powerbutton
sleep the machine when power button is pressed (value = 0/1)

lidwake
wake the machine when the laptop lid (or clamshell) is opened (value = 0/1)

acwake
wake the machine when power source (AC/battery) is changed (value = 0/1)

lessbright
slightly turn down display brightness when switching to this power source (value = 0/1)

halfdim
display sleep will use an intermediate half-brightness state between full brightness and fully off (value = 0/1)

sms
use Sudden Motion Sensor to park disk heads on sudden changes in G force (value = 0/1)

hibernatefile
change hibernation image file location. Image may only be located on the root volume. Please use caution. (value = path)

No comments: