Sunday, December 22, 2013

Shhh... Go ahead. You throttle that CPU.

Lately I got sucked into looking at methods to throttle CPUs on PowerPC. It started out as a good idea, but my compulsion for completeness made it take on a life of its own and I probably spent way more time reading about it than necessary. But I've come out the other side, and now I'm reading a 580 page book about the Crimean War! Totally useful knowledge. I know how to pick 'em. Anyway, the point of all this is I am now here to share the fruits of my labor and tell you exactly why Orthodox religion and rampant Russophobia in Western Europe led to... I mean, tell you all the ways you can throttle your Mac's CPU.

Throttling CPUs often gets confused with the nice/renice commands, but they aren't quite the same. Nice/renice only prioritizes processes eating your CPU, but all your idle CPU will still be used. CPU throttling actually limits the amount of CPU a process can use. For example, if you throttle Handbrake to 50% CPU, Handbrake won't rise above 50% usage even if there are no other processes running. The practical use for this is mostly for laptops. Let's say you're doing some compiling or video encoding, something CPU intensive that takes a long time, but your laptop easily overheats or you just don't want to hear the fan going. You can limit the heat by throttling the CPU. Sure, it'll take longer, but your laptop won't give you Toasted Skin Syndrome.

For our PowerPC Macs I found a few ways of doing this, all from the command line. First, on Linux there's a program called cpulimit which has you enter a process name or PID number and the percentage of maximum CPU you want to set it to. A typical command would look like this:

cpulimit -e iceweasel -l 50

The "-e" is used when you enter the name of the program (iceweasel). You use "-p" when entering the PID instead, and you can also use -P to enter the absolute path (/usr/bin/iceweasel). The "-l" is for limit, and the 50 is the max percentage of CPU allowed. To exit, just use the standard ctrl-C.

For OS X, I found a couple of ways that work in Tiger. First, there's cpulimitrob. This is a script that someone left on Mac OS X Hints and does essentially what cpulimit does. It uses SIGSTOP and SIGCONT to pause and restart, thereby limiting total CPU time. After you download it and give it the customary chmod kiss (755), you change directories to its current location with the cd command and fire it up as root:

~ dan$ cd Development

~/Development dan$ sudo ./
Which process ID (PID)?
Sleep time in seconds?
Run time in seconds (e.g 0.5 or 1 ?)?

and the dots continue on and on until you exit with ctrl-C. It mostly works well. The only hitch I found was when testing with TenFourFox, where the browser froze whenever I exited cpulimitrob in the middle of a page loading.

The other tool I found for Tiger didn't have any such problems and appears to exit more gracefully. It's called cputhrottle. However, the binary available for download isn't compiled for PowerPC, and to compile requires Boost 1.33.1. So being the completist that I am, I installed Boost with Tigerbrew (about 3-4 hours to configure and make) and then compiled cputhrottle from source. Using cputhrottle is almost the same as cpulimit, though like cpulimitrob, you need to run it with the sudo command:

~ dan$ cd Development/cputhrottle

~/Development/cputhrottle dan$ sudo ./cputhrottle 1309 50

The 1309 is the PID which you can get from top or Activity Monitor, and the 50 is the max CPU percentage. And again, killing the limit is as simple as ctrl-C.

In case you don't want to compile Boost and cputhrottle, I uploaded the binary I made to my Mediafire folder. It should work on Tiger, though I'm not enough of a compiling expert to say definitively whether it'll work on Leopard. You may also need to run "chmod +x cputhrottle" to make it executable.

Finally, if you just want to prioritize your processes so web browsing or somesuch isn't super slow while something else hogs the CPU, you don't have to use nice/renice from the command line. There's a very old GUI application for OS X called ProcessWizard that still works. In Linux, you can do the same with Gnome System Monitor.


  1. Hmmm.

    That encyclopedic approach aside, you haven't mentioned why I'd want to slow down my 10 year-old, 1.25 MHz, G4 PPC iMac in the first place. I figure I'd have already learned if 1.25 MHz was fast enough to cause overheating by now?

    On the other hand, if you were telling me it was okay to rev it up beyond 1.25 MHz, I'd be all ears...

  2. thank you so much!!! ::::shakes hand with both hands, vigorously::::: you uploaded it!!!

    merry & happy to you sir

  3. Hello!
    Thanks. It works fine. But, is there a program to stop or slow down the Hard Disk? My HD gets hot every time I use my Ibook G4. Sometimes I want to disable HD. I could do this when I'm webbrowsing, for example.


    1. There's the preference in Energy Saver where it says "Put the hard disk(s) to sleep when possible." This spins down the hard drive after 10 minutes of inactivity. You can fine tune this with the pmset command. Enter something like this in a terminal:

      sudo pmset -a disksleep 4

      where the 4 is the minutes till the hard drive spins down. You can do "man pmset" to find out more. "pmset -g" gives you your current settings.