in kernel/perf_event_cpu.c [551:593]
static int nds32_pmu_get_event_idx(struct pmu_hw_events *cpuc,
struct perf_event *event)
{
int idx;
struct hw_perf_event *hwc = &event->hw;
/*
* Current implementation maps cycles, instruction count and cache-miss
* to specific counter.
* However, multiple of the 3 counters are able to count these events.
*
*
* SOFTWARE_EVENT_MASK mask for getting event num ,
* This is defined by Jia-Rung, you can change the polocies.
* However, do not exceed 8 bits. This is hardware specific.
* The last number is SPAv3_2_SEL_LAST.
*/
unsigned long evtype = hwc->config_base & SOFTWARE_EVENT_MASK;
idx = get_converted_event_idx(evtype);
/*
* Try to get the counter for correpsonding event
*/
if (evtype == SPAV3_0_SEL_TOTAL_CYCLES) {
if (!test_and_set_bit(idx, cpuc->used_mask))
return idx;
if (!test_and_set_bit(NDS32_IDX_COUNTER0, cpuc->used_mask))
return NDS32_IDX_COUNTER0;
if (!test_and_set_bit(NDS32_IDX_COUNTER1, cpuc->used_mask))
return NDS32_IDX_COUNTER1;
} else if (evtype == SPAV3_1_SEL_COMPLETED_INSTRUCTION) {
if (!test_and_set_bit(idx, cpuc->used_mask))
return idx;
else if (!test_and_set_bit(NDS32_IDX_COUNTER1, cpuc->used_mask))
return NDS32_IDX_COUNTER1;
else if (!test_and_set_bit
(NDS32_IDX_CYCLE_COUNTER, cpuc->used_mask))
return NDS32_IDX_CYCLE_COUNTER;
} else {
if (!test_and_set_bit(idx, cpuc->used_mask))
return idx;
}
return -EAGAIN;
}