Keep that Laptop from Racing thru Battery

Linux and Laptops: a long, old story. However, one that with a bit homework, helps get the most out of your battery. Using powertop, you can see your energy usage profile and your device power settings. The downside to powertop is that you cannot "export as shell script." (Seriously, y u no export?) To get these power savings on boot, I wrote my own script.

  1 #!/bin/bash
  2 /usr/sbin/rfkill block 0 #bt
  3 /usr/sbin/rfkill block 1 #wifi
  4 /usr/sbin/rfkill block 2 #bt
  5 for i in /sys/class/scsi_host/host*/link_power_management_policy
  6 do
  7     echo "min_power" > $i
  8 done
  9 echo 0 > /proc/sys/kernel/nmi_watchdog
 10 echo 1 > /sys/module/snd_hda_intel/parameters/power_save
 11 echo 60000 > /proc/sys/vm/dirty_writeback_centisecs
 12 
 13 find /sys/devices/ \
 14 | grep 'power/control' \
 15 | while read i
 16 do
 17     echo -n "$i@"
 18     cat $i 2>/dev/nulll
 19 done \
 20 | grep -v auto \
 21 | awk -F@ '{print $1}' > /tmp/sleepy.tmp
 22 
 23 for i in `cat /tmp/sleepy.tmp`
 24 do
 25     echo "auto" > $i
 26 done
 27 
 28 for i in `find /sys -name autosuspend -exec echo {} \;`
 29 do
 30     echo "1" > $i
 31 done
 32 
 33 find /sys/devices/pci0000:00 -type f -iname autosuspend_delay_ms \
 34    -exec echo "1000" > {} \;
 35 
 36 for i in /sys/bus/usb/devices/usb*/power/autosuspend_delay_ms
 37 do
 38     echo "1000" > $i
 39 done
 40 
 41 for i in /sys/bus/usb/devices/usb*/power/autosuspend
 42 do
 43     echo "1" > $i
 44 done
 45 
 46 for i in /sys/bus/usb/devices/*/power/autosuspend
 47 do
 48     echo "1" > $i
 49 done
 50 
 51 webcamDev=$( lsusb | grep -i webcam | awk '{print $2 "-" $4 }' | tr -d ':0' )
 52 if [ ! -z "$webcamDev" ]
 53 then
 54     echo 1 > /sys/bus/usb/devices/$webcamDev/power/autosuspend
 55     echo auto > /sys/bus/usb/devices/$webcamDev/power/level
 56     echo 1000 > /sys/bus/usb/devices/$webcamDev/power/autosuspend_delay_ms
 57 fi
 58 
 59 # eof

The best way to run this script is to open two windows, one running powertop, the other for this script. After adjusting this script, type r in the powertop window to refresh the device stats. I was able to take my T60 from 30.1W down to somewhere between 19.8 – 16.1W. Unfortunately, I haven’t seen that 16.1W reading since.

I hope this serves as a good starting point for your own laptop power savings! And not just laptops, but this script can also be used for home NAS or media center or other small servers where you need thermal management, too.

Thoughts on my GSII

Having a mobile phone is kind of like holding an open beer and not sipping. However, if I wanted to take a sip out of this phone, it would repeatedly place the pull tab over the mouth of the can, the brew would slosh up when the can was not being held, the beer would mysteriously pause after the first tip, then it would run backwards back up into the can and fall forward again. Repeatedly.

The screen on this phone seems always to think some of the lower buttons are getting tapped. This might be due to the case I put on the phone, but I did my best to carve a bunch off. Google voice jumps up most annoyingly as soon as I start to do something.

And battery life is atrocious. I it seems like the actual phone life is closer to 100 minutes judging from how quickly I see the battery tick down from 100% even if I have wifi and mobile data off. Checking email on it is frustrating and it brings to mind how much I have to refine my gmail filters because I do not want to see donation requests on my phone, that seems like a complete waste of my battery, data and attention.

Having a flip-phone was actually more relaxing.

Backups: one quick file backup alias

When you have a file you need to edit and you have the foresight to think, “whoa, make a copy before I destroy…” you often copy hulk.txt to hulk.txt.old (that’s using the minimum of keystrokes:

 cp hul[tab][tab] hul[tab][tab].old[enter].
Linux Backups logo

Linux Backups

Well, a week later, what do you rename your next .old file? .old2? No time to put this folder into revision control? Thought so. You can inspect that last modified time on your file with stat. Experiment with this first:

echo `stat hulk.txt | awk '/Modify:/ {print $2}'`

(*snrk* did I just get you use use Awk? OMG!)

So how does that help…more precisely, you’re asking how do I add that to a backup file name? One of many ways, and I will show you the method with least typing: use an in-place shell exansion.

cp hulk.txt .hulk.txt.`stat hulk.txt | awk '/Modify:/ {print $2}'`

STOP. What wee character did I just sneek into that filename? Hold on, first write it up in an alias so you can reuse it:

alias bu="cp hulk.txt .hulk.txt.\`stat hulk.txt | awk '/Modify:/ {print $2}'\`"

Right, the backslashes (or ‘hacks’ as I nic them) keep your statement from actually evaluating the command as soon as it’s defined. The backtick is the same as saying “bash -e …stuff...”. Anyhow, now type bu and you can backup hulk.txt again. Now type ‘ls’ and see where your backup is.

No file? And no error? Oh, right the period before name hides it (sneeky). This means the next time we accidentally do a “rm *” (which often appears when you say “rm * .old” — Computer, stop, replay with magnification: rm__*__.old ). You need a good-old-fasioned:

ls -a

It’s hiding. Let’s finish up here with your alias, properly written:

alias bu="\`cp $1 .$1.\`stat $1 | awk '/Modify:/ {print $2}'\`"

Can we do it without that crazy awk? Sure:

alias bu="\`cp $1 .$1.\`stat $1 --printf %Y '\`"

Now go make a backup…right now!

Modern Picture Management?

I like to run a thumbnailer across most of my photos so I have little copies to send around, and I mod them so that they look distinctly different from the full resolution source files. I like to use gwenview to flip and rotate them. Gwenview can export to FB and email so that makes things easier.

I copied a bunch of these thumbs to a project folder. However, I still need to use scripting to sets of pictures from different directories, because they match by name. Buckle up:

ls \
| grep small-imgp \
| perl -pe 's/small-(imgp[0-9]+\.jpg)$/$1/' \
| while read F 
do 
   find /home/jreynolds/9/2012/ -iname "$F" -exec cp {} ~/For-Mary \; 
done

Wow, now I can really get to work.

Upcoming: New Standing Workstation

I’ve posted about how my previous endeavors to work at a standing workspace, at work, and at home. It has not gone sour on me yet. Presently at
Candelatech I’ve been sitting on an exercise ball with three landscape monitors. It’s a lot of screen realestate! I love not needing to maximize and minimize windows and the ability to glance at my debug window and at log output at the same time. 

I feel like I slouch a lot more when I’m on the exercise ball–I’m eager to bounce up to the standing work space again. And soon I shall. I have built a wooden monitor rack from lumber reclaimed from a few projects around the house. I have hauled the pieces to work on my bike. It looks like nothing you’ve ever seen before. Expect photos soon.st

Cars Passing Bikes: Do Gutter Bunnies Dress in Wigs?

Interesting news about how drivers act around bicyclists…there seems to be a space about 3 feet away from the curb. Too close to the gutter, and they assume they can pass closer. Also, lack of helmet and having long hair apparently promote further passing distance. Read more at cyclious and streetsblog. Remember — be conspicuous and predictable. Don’t duck between parked cars, cycle in a straight line as if you had a bike lane besides parked cars…otherwise you’re constantly mergine back into a lane of traffic.

Bike Shed Ideas?

My office is exploring the possibility of a free standing structure in the parking lot for bike parking. If you’ve been part of such a project, I’d love to hear from you (comment, email or facebook).

This structure would want to hold six bikes, have cable locks, and a structure. Probably both the options for upright and horizontal locking. The structure should not penetrate the tarmac (no concrete bolts or staples), and it will not be touching the existing office structure. It would want to be tall enough to hang upright a cargo bike or a long wheel base recumbent, so that puts a hook as high as 72-74 inches, iirc.

The approval process involves presenting plans to building management and HR, et al. Ideas welcome!

Clear Thoughts on Share the Lane Signs

This concept, and flaws, need to be distinguished in drivers ed, and commonly reminded: A “Share The Road” sign may give the motorist behind the cyclist the wrong message that the motorist can choose to share, or not, since the implication is that the bigger car has bigger rights that supercedes the right of the cyclist.  It may also give the motorist the wrong impression that the LANE can be “Shared” with the bicycle – i.e., that they can co-exist side by side in the same lane.