Perfmon for MacOS X
Modifications to the Darwin kernel (extensions to the existing Mach API) to allow userland access to the PowerPC Performance Counter registers, including SMP systems. Also made use of the Performance Monitor interrupt to maintain a set of per-cpu 64-bit counters, so samples over larger timescales would make sense (no wrapping). Completed as part of my Honours Computer Science degree at the University of Wollongong, Australia. Originally written against Mac OS X 10.0.?, still merges in, compiles and runs fine on 10.2.3. If you are planning on downloading these, I strongly recommend downloading documentation for your particular PowerPC processor from Freescale's web site.
Why a kernel modification you may ask? Why not IOKit? The osfmk portion of the kernel seems to be the only place where you can really control on which CPU you're doing what. So for SMP, that's the choice made.
Since releasing the code, I've been made aware of Apple's own work in this area (thanks, Dave). Check out CHUD Tools. Theirs is broader than my version, and ships as a kext (wish I knew how they did that).
- xnu-Apple-201-42-3.patch.gz 6 848 bytes gzipped patch file
- xnu-Apple-344-2.patch.gz 6 833 bytes gzipped patch file
- CVS diffs taken against xnu tagged Apple-201-42-3 and Apple-344-2 (Mac OS X 10.1.5 and 10.2.1, repectively). Not for the faint-hearted to apply and build! I must admit I had a great deal of fun the first time I tried, a year before instructions started showing up at places like Darwinfo, now OpenDarwin and Apple's Darwin site. The diff applies fine to Jaguar 10.2.1, and probably all the way back to the Public Betas (it's a very stable part of the kernel).
- PerfMon-src.tgz 58 764 bytes gzipped tar archive
- Project Builder source code containing 4 plain Darwin command-line tools to get/set Performance Monitor registers via the Mach API (getpmc, getqpmc, setmmcr, clrpmc), and a Cocoa GUI Application which allows the real-time (hic) graphing of the various counters. Command line tools may break on Jaguar, due to the C99 conformance changing long long (64-bit quad-int) stdio behaviour. Update: Still works fine on Jaguar - although %llu (or the PRId64 macro) is more correct, %qu still works fine. setmmcr and clrpmc require root privileges to run, the Cocoa app uses the authentication framework to run setmmcr and clrpmc as required. To build these, you'll need to install the two changed headers (<mach/processor_info.h> and <mach/ppc/processor_info.h>) and run fixPrecomps. Not included is a sysctl interface I had begun work on, however, I never finished it. Maybe one day...
- PDF and PostScript versions of the report written for my honours thesis. Reading it back now, I'm sure I could improve on it greatly... From memory, it was written in a sleep-deprived daze... Most of it still makes some kind of sense.