4 ms·
Great post - glad some of that code has been useful! If it's of interest, these performance events (and the whitelist for this API), are described by Apple at
by dougall 6y ago
Great post - glad some of that code has been useful!
If it's of interest, these performance events (and the whitelist for this API), are described by Apple at https://github.com/apple/darwin-xnu/blob/main/osfmk/arm64/kpc.c https://github.com/apple/darwin-xnu/blob/main/osfmk/arm64/kp...
Instruments.app is the official way to access performance counters. I believe it can use a few more (non-whitelisted) events, which are described in /usr/share/kpep/a14.plist - I couldn't figure out how to hijack the single-consumer API that I think it's using. (Edit: it seems it just shows non-whitelisted events in the GUI, but doesn't let me use them.)
(And, for my own measurements, I use a kernel module to bypass the whitelist, which is even more likely to blow up the computer, and definitely not recommended: https://github.com/dougallj/applecpu/tree/main/timer-hacks https://github.com/dougallj/applecpu/tree/main/timer-hacks )
- kragen 6y agoInteresting! Do you need Apple's permission to write a kernel module? Have you tried running this kind of instrumentation on Linux on M1?
- dougall 6y agoI don't really understand the kernel module process/policy - it was a lot of trying random things and seeing what worked. But I think you shouldn't need permission, as long as you're building it and running it on your own machine. But I do have an Apple developer account that costs money to let you develop on iOS, so that might have been a factor. You do need to disable some security features to run kernel modules. I'd rather be running this kind of instrumentation on Linux (or without a kernel, e.g. using m1n1), but I haven't set that up yet. (It'd be nice to lock the CPU to a frequency, and pin threads to cores, etc.)
- kragen 6y agoThank you!