Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure L1, L2, L3 cache hits & misses in OSX

I've a C++ program and I would like to quantify it's performance by checking the number of hits and misses against the CPU cache.

What's the best way to do it?

I tried using Intel's Performance Counter Monitor but it uses an unsigned Kernel Extension which are disabled on Yosemite. I can obviously disable the check to not load unsigned kexts but I wouldn't like to go down that path.

Is there any other possible way that I'm unaware of?

like image 229
evanescent Avatar asked Oct 19 '22 20:10

evanescent


1 Answers

You can enable unsigned kernel extensions with OS X (reboot afterwards required):

sudo nvram boot-args=kext-dev-mode=1

This enables developer mode on your machine and you can run Intel Performance Counter Monitor as long at it supports Mac OS X 10.10 (Yosemite) in general.

Don't forget to disable it again after you are done with testing (security-issue otherwise):

sudo nvram boot-args=kext-dev-mode=0

As far as I know Intel's tool is far better than cache grind because it uses actual counters from the hardware instead of simulating an cpu and it's cache characteristics in software.

like image 125
Manuel Arwed Schmidt Avatar answered Oct 21 '22 16:10

Manuel Arwed Schmidt