How to use the PentiumPro Performance Monitoring Counters

(If you're in a hurry, try the recapitulation of the essential steps at the end of this page.) I have written (or adapted) a little driver and a library to use the PentiumPro performance monitoring counters. It's very basic, but can be valuable if you have to measure some performance related events on the processor.

Adapting your program

All the relevant file can be found in /home/rauch/src/pentium-perf-driver/. You have to #include <libpentiumpro.h> in your C-program and link your final executable with the file libpentiumpro.o.

The library offers six functions. The first three handle the performance monitoring events which can be selected on the PentiumPro:

The next three handle the cycle counter. This registers starts every processor cycle starting when the processor is booted. You can measure very small time-periods with this counter. Please note that you have to know the MHz of your machine.

Checking your machine

As the PentiumPro Performance Monitoring Counters are only accessible from within kernel mode, we have to use a driver which is added to the kernel (Note that this is not true for the cycle counter). This driver is written as a module and can be added to the kernel at run time. However, you must make sure that the file /dev/pentium exists. If it doesn't, then contact your local system administrator (in this case, Felix or Christian). (Well, if you are root, you can also create that file yourself by calling /home/rauch/src/pentium-perf-driver/create_device with the proper major device number as argument. But please make sure that the major device number is unused on your machine! We usually take 61, but it's not always guaranteed to be free).

Now, you must make sure that the driver is loaded. As root, execute lsmod (it's in /sbin). You then probably see a module named "pentiumpro", probably followed by some numbers. E.g. "pentiumpro.2.0.33" (the numbers indicate the kernel for which the module was compiled). If you don't, then you will have to load the driver yourself. Find out which kernel your machine is running (type cat /proc/version to find out), find the appripriate module in /home/rauch/src/pentium-perf-driver/ and load it by executing insmod the_module (e.g. insmod pentiumpro.2.0.33.o if your machine runs a 2.0.33 kernel). Check if it worked by typing lsmod as described above.

Now you are ready to make your measurements.

Essential steps (recap.)

  1. Adapt your program as described above and link it with libpentiumpro.o (which can be found in /home/rauch/src/pentium-perf-driver/.
  2. If you plan to use the performance monitoring counters, load the appropriate driver from /home/rauch/src/pentium-perf-driver/ with the insmod command (you don't need the driver for the cycle counter). E.g.: insmod pentiumpro.2.0.33.o. Check if it worked with the lsmod command.
  3. Start your program and measure...

CS-Department | Institut for Computer Systems | Research Group | Up ]
Last change: 20 July 1998