diff options
author | Paul Mackerras <paulus@samba.org> | 2009-04-29 08:38:51 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-04-29 08:58:35 -0400 |
commit | ab7ef2e50a557af92f4f90689f51fadadafc16b2 (patch) | |
tree | 71ef1cbc279e5d2ad96b6c701617ac60ff36c363 /arch/powerpc/include | |
parent | 98144511427c192e4249ff66a3f9debc55c59411 (diff) |
perf_counter: powerpc: allow use of limited-function counters
POWER5+ and POWER6 have two hardware counters with limited functionality:
PMC5 counts instructions completed in run state and PMC6 counts cycles
in run state. (Run state is the state when a hardware RUN bit is 1;
the idle task clears RUN while waiting for work to do and sets it when
there is work to do.)
These counters can't be written to by the kernel, can't generate
interrupts, and don't obey the freeze conditions. That means we can
only use them for per-task counters (where we know we'll always be in
run state; we can't put a per-task counter on an idle task), and only
if we don't want interrupts and we do want to count in all processor
modes.
Obviously some counters can't go on a limited hardware counter, but there
are also situations where we can only put a counter on a limited hardware
counter - if there are already counters on that exclude some processor
modes and we want to put on a per-task cycle or instruction counter that
doesn't exclude any processor mode, it could go on if it can use a
limited hardware counter.
To keep track of these constraints, this adds a flags argument to the
processor-specific get_alternatives() functions, with three bits defined:
one to say that we can accept alternative event codes that go on limited
counters, one to say we only want alternatives on limited counters, and
one to say that this is a per-task counter and therefore events that are
gated by run state are equivalent to those that aren't (e.g. a "cycles"
event is equivalent to a "cycles in run state" event). These flags
are computed for each counter and stored in the counter->hw.counter_base
field (slightly wonky name for what it does, but it was an existing
unused field).
Since the limited counters don't freeze when we freeze the other counters,
we need some special handling to avoid getting skew between things counted
on the limited counters and those counted on normal counters. To minimize
this skew, if we are using any limited counters, we read PMC5 and PMC6
immediately after setting and clearing the freeze bit. This is done in
a single asm in the new write_mmcr0() function.
The code here is specific to PMC5 and PMC6 being the limited hardware
counters. Being more general (e.g. having a bitmap of limited hardware
counter numbers) would have meant more complex code to read the limited
counters when freezing and unfreezing the normal counters, with
conditional branches, which would have increased the skew. Since it
isn't necessary for the code to be more general at this stage, it isn't.
This also extends the back-ends for POWER5+ and POWER6 to be able to
handle up to 6 counters rather than the 4 they previously handled.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
LKML-Reference: <18936.19035.163066.892208@cargo.ozlabs.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/powerpc/include')
-rw-r--r-- | arch/powerpc/include/asm/perf_counter.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/arch/powerpc/include/asm/perf_counter.h b/arch/powerpc/include/asm/perf_counter.h index 9d7ff6d7fb56..56d66c38143b 100644 --- a/arch/powerpc/include/asm/perf_counter.h +++ b/arch/powerpc/include/asm/perf_counter.h | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #define MAX_HWCOUNTERS 8 | 13 | #define MAX_HWCOUNTERS 8 |
14 | #define MAX_EVENT_ALTERNATIVES 8 | 14 | #define MAX_EVENT_ALTERNATIVES 8 |
15 | #define MAX_LIMITED_HWCOUNTERS 2 | ||
15 | 16 | ||
16 | /* | 17 | /* |
17 | * This struct provides the constants and functions needed to | 18 | * This struct provides the constants and functions needed to |
@@ -25,8 +26,11 @@ struct power_pmu { | |||
25 | int (*compute_mmcr)(unsigned int events[], int n_ev, | 26 | int (*compute_mmcr)(unsigned int events[], int n_ev, |
26 | unsigned int hwc[], u64 mmcr[]); | 27 | unsigned int hwc[], u64 mmcr[]); |
27 | int (*get_constraint)(unsigned int event, u64 *mskp, u64 *valp); | 28 | int (*get_constraint)(unsigned int event, u64 *mskp, u64 *valp); |
28 | int (*get_alternatives)(unsigned int event, unsigned int alt[]); | 29 | int (*get_alternatives)(unsigned int event, unsigned int flags, |
30 | unsigned int alt[]); | ||
29 | void (*disable_pmc)(unsigned int pmc, u64 mmcr[]); | 31 | void (*disable_pmc)(unsigned int pmc, u64 mmcr[]); |
32 | int (*limited_pmc_event)(unsigned int event); | ||
33 | int limited_pmc5_6; /* PMC5 and PMC6 have limited function */ | ||
30 | int n_generic; | 34 | int n_generic; |
31 | int *generic_events; | 35 | int *generic_events; |
32 | }; | 36 | }; |
@@ -34,6 +38,13 @@ struct power_pmu { | |||
34 | extern struct power_pmu *ppmu; | 38 | extern struct power_pmu *ppmu; |
35 | 39 | ||
36 | /* | 40 | /* |
41 | * Values for flags to get_alternatives() | ||
42 | */ | ||
43 | #define PPMU_LIMITED_PMC_OK 1 /* can put this on a limited PMC */ | ||
44 | #define PPMU_LIMITED_PMC_REQD 2 /* have to put this on a limited PMC */ | ||
45 | #define PPMU_ONLY_COUNT_RUN 4 /* only counting in run state */ | ||
46 | |||
47 | /* | ||
37 | * The power_pmu.get_constraint function returns a 64-bit value and | 48 | * The power_pmu.get_constraint function returns a 64-bit value and |
38 | * a 64-bit mask that express the constraints between this event and | 49 | * a 64-bit mask that express the constraints between this event and |
39 | * other events. | 50 | * other events. |