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 ./cpulimitrob.sh
Password:
Which process ID (PID)?
297
Sleep time in seconds?
.5
Run time in seconds (e.g 0.5 or 1 ?)?
.5
.................


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.

Sunday, December 8, 2013

Let's Play...

...let's link to other people's PowerPC Youtube channels! These are (more or less) PowerPC centric, though I don't vouch for the quality of each and every vid.

The iBookGuy - Not just iBooks!

The PowerPC Hub - Actually a mix of MacIntel, iOS and PowerPC.

Lmull3's Geekery Emporium - Macs and Mac clones.

ItsMyNaturalColour - The dude with the white hair.

BBISHOPPCM's World - Some really old vintage stuff.

gavinstubbs09 - A few PowerPC videos here.

Tuesday, December 3, 2013

My Stupid Mac Youtube Channel

So I went and made my own Youtube channel. I intend to populate it with mostly videos of old Mac games, at least the ones I liked. I might also throw in a Linux screencast. I've been meaning to do something like that for ages, so at my current pace I'll get around to it sometime in the next calendar year (don't hold me to it). Also, it looks like Youtube implemented their new comment policy just in time, so all of you who want to call me a booger snot will have to do it from your public Google+ profile :-P

Incidentally, did you know MPEG Steamclip is still around? I needed to edit some of these videos, which were .mov files with an odd audio codec, and Avidemux wouldn't play along. So I remembered MPEG Streamclip which I used a long time ago and went over to their site and saw they had an update from last year. Still runs on Jaguar (!). It's still as easy as ever to use and did exactly what I needed.

One last tidbit, if you upload a 640x480 video to Youtube in H.264 format, it will be horribly distorted when Youtube downscales it to 360p. If you upload as MPEG-4, you won't have that problem.