OProfile figures out what registers are available strictly from the
cpu type information. This works when OProfile is the only thing using
the performance monitoring hardware.
Recent change to the Linux 2.6.19 reserve a performance counter for
the watchdog timer via reserve_pffctr_nmi(), and there are other
possible users of the performance monitoring hardware,
e.g. perfmon2. The oprofile driver in the kernel makes the available
performance counters visible in /dev/oprofile/. On the x86-64 the
watchdog appears to take performance counter 0, leaving registers 1,
2, and 3 available.
The oprofile allocation code needs some modification to be able to
handle the case where some of the performance counters are not
available. The ophelp code calls map_event_to_counter in
libop/op_alloc_counter.c. This function in turn calls
allocate_counter. The fourth argument to allocate_counter is a bit
mask indicating that all the performance counters are available.
Would it be reasonable to allow the fourth argument be a possibly
non-zero bitmask, indicating which counters are already
unavailable. This information would be obtained by scanning the
/dev/oprofile directory for numbered directories. Mark the found
numbered directories in bit vector as zero and everything else and
The algorithm won't work if there are counters already allocated.
Shouldn't the code be the following?
RCS file: /cvsroot/oprofile/oprofile/libop/op_alloc_counter.c,v
retrieving revision 1.6
diff -u -r1.6 op_alloc_counter.c
--- libop/op_alloc_counter.c 1 Oct 2003 21:53:46 -0000 1.6
+++ libop/op_alloc_counter.c 17 Nov 2006 17:03:04 -0000
@@ -130,7 +130,7 @@
counter_arc const * arc = list_entry(pos, counter_arc, next);
if (allocated_mask & (1 << arc->counter))
- return 0;
counter_map[depth] = arc->counter;
The other issue that will need to be addressed is the sharing of the
performance counter interrupt in the kernel. The there could be
different handlers for the different counters, e.g. one handler for
the watchdog timer and different handler for the regular oprofile