Commit 72001990 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Ingo Molnar

x86, perf: P4 PMU -- use hash for p4_get_escr_idx()

Linear search over all p4 MSRs should be fine if only
we would not use it in events scheduling routine which
is pretty time critical. Lets use hashes. It should speed
scheduling up significantly.

v2: Steven proposed to use more gentle approach than issue
    BUG on error, so we use WARN_ONCE now
Signed-off-by: default avatarCyrill Gorcunov <gorcunov@openvz.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Lin Ming <ming.m.lin@intel.com>
LKML-Reference: <20100512174242.GA5190@lenovo>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 975fc2d5
...@@ -668,66 +668,80 @@ static void p4_pmu_swap_config_ts(struct hw_perf_event *hwc, int cpu) ...@@ -668,66 +668,80 @@ static void p4_pmu_swap_config_ts(struct hw_perf_event *hwc, int cpu)
} }
} }
/* ESCRs are not sequential in memory so we need a map */ /*
static const unsigned int p4_escr_map[ARCH_P4_TOTAL_ESCR] = { * ESCR address hashing is tricky, ESCRs are not sequential
MSR_P4_ALF_ESCR0, /* 0 */ * in memory but all starts from MSR_P4_BSU_ESCR0 (0x03e0) and
MSR_P4_ALF_ESCR1, /* 1 */ * the metric between any ESCRs is laid in range [0xa0,0xe1]
MSR_P4_BPU_ESCR0, /* 2 */ *
MSR_P4_BPU_ESCR1, /* 3 */ * so we make ~70% filled hashtable
MSR_P4_BSU_ESCR0, /* 4 */ */
MSR_P4_BSU_ESCR1, /* 5 */
MSR_P4_CRU_ESCR0, /* 6 */ #define P4_ESCR_MSR_BASE 0x000003a0
MSR_P4_CRU_ESCR1, /* 7 */ #define P4_ESCR_MSR_MAX 0x000003e1
MSR_P4_CRU_ESCR2, /* 8 */ #define P4_ESCR_MSR_TABLE_SIZE (P4_ESCR_MSR_MAX - P4_ESCR_MSR_BASE + 1)
MSR_P4_CRU_ESCR3, /* 9 */ #define P4_ESCR_MSR_IDX(msr) (msr - P4_ESCR_MSR_BASE)
MSR_P4_CRU_ESCR4, /* 10 */ #define P4_ESCR_MSR_TABLE_ENTRY(msr) [P4_ESCR_MSR_IDX(msr)] = msr
MSR_P4_CRU_ESCR5, /* 11 */
MSR_P4_DAC_ESCR0, /* 12 */ static const unsigned int p4_escr_table[P4_ESCR_MSR_TABLE_SIZE] = {
MSR_P4_DAC_ESCR1, /* 13 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ALF_ESCR0),
MSR_P4_FIRM_ESCR0, /* 14 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ALF_ESCR1),
MSR_P4_FIRM_ESCR1, /* 15 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BPU_ESCR0),
MSR_P4_FLAME_ESCR0, /* 16 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BPU_ESCR1),
MSR_P4_FLAME_ESCR1, /* 17 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BSU_ESCR0),
MSR_P4_FSB_ESCR0, /* 18 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BSU_ESCR1),
MSR_P4_FSB_ESCR1, /* 19 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR0),
MSR_P4_IQ_ESCR0, /* 20 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR1),
MSR_P4_IQ_ESCR1, /* 21 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR2),
MSR_P4_IS_ESCR0, /* 22 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR3),
MSR_P4_IS_ESCR1, /* 23 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR4),
MSR_P4_ITLB_ESCR0, /* 24 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR5),
MSR_P4_ITLB_ESCR1, /* 25 */ P4_ESCR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CR1, /* 41 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MOB_ESCR0),
MSR_P4_TC_ESCR0, /* 42 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MOB_ESCR1),
MSR_P4_TC_ESCR1, /* 43 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MS_ESCR0),
MSR_P4_U2L_ESCR0, /* 44 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MS_ESCR1),
MSR_P4_U2L_ESCR1, /* 45 */ P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_PMH_ESCR0),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_PMH_ESCR1),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_RAT_ESCR0),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_RAT_ESCR1),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SAAT_ESCR0),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SAAT_ESCR1),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SSU_ESCR0),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SSU_ESCR1),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TBPU_ESCR0),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TBPU_ESCR1),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TC_ESCR0),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TC_ESCR1),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_U2L_ESCR0),
P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_U2L_ESCR1),
}; };
static int p4_get_escr_idx(unsigned int addr) static int p4_get_escr_idx(unsigned int addr)
{ {
unsigned int i; unsigned int idx = P4_ESCR_MSR_IDX(addr);
for (i = 0; i < ARRAY_SIZE(p4_escr_map); i++) { if (unlikely(idx >= P4_ESCR_MSR_TABLE_SIZE ||
if (addr == p4_escr_map[i]) !p4_escr_table[idx])) {
return i; WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr);
return -1;
} }
return -1; return idx;
} }
static int p4_next_cntr(int thread, unsigned long *used_mask, static int p4_next_cntr(int thread, unsigned long *used_mask,
...@@ -747,7 +761,7 @@ static int p4_next_cntr(int thread, unsigned long *used_mask, ...@@ -747,7 +761,7 @@ static int p4_next_cntr(int thread, unsigned long *used_mask,
static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign) static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign)
{ {
unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
unsigned long escr_mask[BITS_TO_LONGS(ARCH_P4_TOTAL_ESCR)]; unsigned long escr_mask[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE)];
int cpu = raw_smp_processor_id(); int cpu = raw_smp_processor_id();
struct hw_perf_event *hwc; struct hw_perf_event *hwc;
struct p4_event_bind *bind; struct p4_event_bind *bind;
...@@ -755,7 +769,7 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign ...@@ -755,7 +769,7 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign
int cntr_idx, escr_idx; int cntr_idx, escr_idx;
bitmap_zero(used_mask, X86_PMC_IDX_MAX); bitmap_zero(used_mask, X86_PMC_IDX_MAX);
bitmap_zero(escr_mask, ARCH_P4_TOTAL_ESCR); bitmap_zero(escr_mask, P4_ESCR_MSR_TABLE_SIZE);
for (i = 0, num = n; i < n; i++, num--) { for (i = 0, num = n; i < n; i++, num--) {
...@@ -763,6 +777,8 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign ...@@ -763,6 +777,8 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign
thread = p4_ht_thread(cpu); thread = p4_ht_thread(cpu);
bind = p4_config_get_bind(hwc->config); bind = p4_config_get_bind(hwc->config);
escr_idx = p4_get_escr_idx(bind->escr_msr[thread]); escr_idx = p4_get_escr_idx(bind->escr_msr[thread]);
if (unlikely(escr_idx == -1))
goto done;
if (hwc->idx != -1 && !p4_should_swap_ts(hwc->config, cpu)) { if (hwc->idx != -1 && !p4_should_swap_ts(hwc->config, cpu)) {
cntr_idx = hwc->idx; cntr_idx = hwc->idx;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment