perfctr-2.7.2 for 2.6.6-mm2: x86_64
A message that is not in the archive (sent off-list or not yet received): [email protected]
Mikael Pettersson <[email protected]> writes:
Before merging all that I would definitely recommend some generic module to allocate performance counters. IBM had a patch for this long ago, and it is even more needed now.
drivers/perfctr/x86_64.c line 2
Quoted 6 lines
diff -ruN
linux-2.6.6-mm2/drivers/perfctr/x86_64.clinux-2.6.6-mm2.perfctr-2.7.2.x86_64/drivers/perfctr/x86_64.cdrivers/perfctr/x86_64.c +2
-0@@ -0,0 +1,660 @@ +/* $Id: x86_64.c,v 1.27 2004/05/13 23:32:50 mikpe Exp $ +* x86_64 performance-monitoring counters driver.
[...]
Can't you share most/all of that file with i386 ? You'll want that definitely once you support Intel CPUs too, and you have to do that eventually.
Same for include/asm-x86_64/perfctr.h
+struct per_cpu_cache { /* roughly a subset of perfctr_cpu_state */
+ union {
+ unsigned int id; /* cache owner id */
+ } k1;
+ struct {
+ /* NOTE: these caches have physical indices, not virtual */
+ unsigned int evntsel[4];
+ } control;
+} ____cacheline_aligned;
+static struct per_cpu_cache per_cpu_cache[NR_CPUS] __cacheline_aligned;
This should use per_cpu_data
+static unsigned int new_id(void)
[...]
Why can't that wrap? Maybe it should use the functions in lib/idr.c ?
+ if( perfctr_cstatus_has_tsc(cstatus) )
+ rdtscl(ctrs->tsc);
+ nrctrs = perfctr_cstatus_nractrs(cstatus);
+ for(i = 0; i < nrctrs; ++i) {
+ unsigned int pmc = state->pmc[i].map;
+ rdpmc_low(pmc, ctrs->pmc[i]);
+ }
K8 has speculative rdtsc. Most likely you want a sync_core() somewhere in there.
The way you set your brackets is weird.
Why do you check for K8 C stepping? I don't see any code that does anything special with that.
-Andi
Quoted 3 lines · Andi Kleen
Before merging all that I would definitely recommend some generic module to allocate performance counters. IBM had a patch for this long ago, and it is even more needed now.
That's currently handled in user space, by PAPI (which sits on top of perfctr). One reason *not* to do it in the kernel is the bloat it would entail; just look at the horrendous mess that is the P4 performance counter event selector.
Quoted 2 lines
Why do you check for K8 C stepping? I don't see any code that does anything special with that.
The reason it's interesting at all is that it's the first K8 stepping that introduces new performance counter unit masks. The kernel driver already passes its notion of what the CPU type is up to userspace. (Clearly, userspace could figure this out, since it's just parsing the cpuid instruction.)
It also checks the CPU type in a few places internally; it just doesn't happen to care internally about K8 stepping C. Thoroughness?
<b
Quoted 8 lines · Bryan O'Sullivan
Quoted 3 lines · Andi Kleen
Before merging all that I would definitely recommend some generic module to allocate performance counters. IBM had a patch for this long ago, and it is even more needed now.
That's currently handled in user space, by PAPI (which sits on top of perfctr). One reason *not* to do it in the kernel is the bloat it would
That's clearly the wrong place to do it.
Quoted 2 lines
entail; just look at the horrendous mess that is the P4 performance counter event selector.
There is no way around that - there are kernel users (like the nmi watchdog or oprofile) and kernel users cannot be made dependent on user space modules. Also I think managing of hardware resources is the primary task of a kernel, nothing that should be delegated to user space.
The netburst mess can be probably abstracted just into more counters. The kernel doesn't need to know everything about them, just roughly how many independent counters there are.
Quoted 4 lines
Quoted 3 lines
Why do you check for K8 C stepping? I don't see any code that does anything special with that.
Quoted 8 lines
The reason it's interesting at all is that it's the first K8 stepping that introduces new performance counter unit masks. The kernel driver already passes its notion of what the CPU type is up to userspace. (Clearly, userspace could figure this out, since it's just parsing the cpuid instruction.)
It also checks the CPU type in a few places internally; it just doesn't happen to care internally about K8 stepping C. Thoroughness?
Why does the library caring about that not just read /proc/cpuinfo to find out?
I sense pointless duplication of mechanism.
-Andi
Quoted 4 lines · Andi Kleen
Quoted 2 lines
That's currently handled in user space, by PAPI (which sits on top of perfctr). One reason *not* to do it in the kernel is the bloat it would
That's clearly the wrong place to do it.
I can see both sides. The perfctr driver already sanity-checks the event selectors to make sure they're not set to anything malicious; this is the very least it must do.
The next step up from that is allocating real performance counters properly, but this requires quite a bit of work. For example, you need to know what the asymmetries in a particular CPU's counters are, so you can tell which counter can handle the events being requested - this varies from perfectly symmetrical (K7 and K8) through slightly odd (P3 and PM) to completely insane (P4).
After that, perhaps you start thinking about abstracting the notions of what you're counting. Different CPUs provide radically different ways of counting roughly the same thing. The event selectors for counting instructions retired differ between AMD and P3, and between P3 and P4, but they can all count this kind of event. More primitive CPUs can't.
Beyond that, it is possible - and in some cases desirable - to, for example, time-slice the real performance counters so that you could get a somewhat representative sample of everything you wanted, assuming the CPU could count it in the first place. The Irix kernel does this.
Where would you draw the line?
Oh, I forgot to mention IA64 and SPARC64's incompatible performance counter APIs :-)
Quoted 3 lines
There is no way around that - there are kernel users (like the nmi watchdog or oprofile) and kernel users cannot be made dependent on user space modules.
There's no kernel-to-user dependency.
<b