2 * Linux performance counter support for MIPS.
4 * Copyright (C) 2010 MIPS Technologies, Inc.
5 * Author: Deng-Cheng Zhu
7 * This code is based on the implementation for ARM, which is in turn
8 * based on the sparc64 perf event code and the x86 code. Performance
9 * counter access is based on the MIPS Oprofile code. And the callchain
10 * support references the code of MIPS stacktrace.c.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
17 #include <linux/cpumask.h>
18 #include <linux/interrupt.h>
19 #include <linux/smp.h>
20 #include <linux/kernel.h>
21 #include <linux/perf_event.h>
22 #include <linux/uaccess.h>
25 #include <asm/irq_regs.h>
26 #include <asm/stacktrace.h>
27 #include <asm/time.h> /* For perf_irq */
29 /* These are for 32bit counters. For 64bit ones, define them accordingly. */
30 #define MAX_PERIOD ((1ULL << 32) - 1)
31 #define VALID_COUNT 0x7fffffff
33 #define HIGHEST_BIT 31
35 #define MIPS_MAX_HWEVENTS 4
37 struct cpu_hw_events {
38 /* Array of events on this cpu. */
39 struct perf_event *events[MIPS_MAX_HWEVENTS];
42 * Set the bit (indexed by the counter number) when the counter
43 * is used for an event.
45 unsigned long used_mask[BITS_TO_LONGS(MIPS_MAX_HWEVENTS)];
48 * The borrowed MSB for the performance counter. A MIPS performance
49 * counter uses its bit 31 (for 32bit counters) or bit 63 (for 64bit
50 * counters) as a factor of determining whether a counter overflow
51 * should be signaled. So here we use a separate MSB for each
52 * counter to make things easy.
54 unsigned long msbs[BITS_TO_LONGS(MIPS_MAX_HWEVENTS)];
57 * Software copy of the control register for each performance counter.
58 * MIPS CPUs vary in performance counters. They use this differently,
59 * and even may not use it.
61 unsigned int saved_ctrl[MIPS_MAX_HWEVENTS];
63 DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = {
67 /* The description of MIPS performance events. */
68 struct mips_perf_event {
69 unsigned int event_id;
71 * MIPS performance counters are indexed starting from 0.
72 * CNTR_EVEN indicates the indexes of the counters to be used are
75 unsigned int cntr_mask;
76 #define CNTR_EVEN 0x55555555
77 #define CNTR_ODD 0xaaaaaaaa
78 #ifdef CONFIG_MIPS_MT_SMP
91 static struct mips_perf_event raw_event;
92 static DEFINE_MUTEX(raw_event_mutex);
94 #define UNSUPPORTED_PERF_EVENT_ID 0xffffffff
95 #define C(x) PERF_COUNT_HW_CACHE_##x
100 irqreturn_t (*handle_irq)(int irq, void *dev);
101 int (*handle_shared_irq)(void);
104 int (*alloc_counter)(struct cpu_hw_events *cpuc,
105 struct hw_perf_event *hwc);
106 u64 (*read_counter)(unsigned int idx);
107 void (*write_counter)(unsigned int idx, u64 val);
108 void (*enable_event)(struct hw_perf_event *evt, int idx);
109 void (*disable_event)(int idx);
110 const struct mips_perf_event *(*map_raw_event)(u64 config);
111 const struct mips_perf_event (*general_event_map)[PERF_COUNT_HW_MAX];
112 const struct mips_perf_event (*cache_event_map)
113 [PERF_COUNT_HW_CACHE_MAX]
114 [PERF_COUNT_HW_CACHE_OP_MAX]
115 [PERF_COUNT_HW_CACHE_RESULT_MAX];
116 unsigned int num_counters;
119 static const struct mips_pmu *mipspmu;
121 static int mipspmu_event_set_period(struct perf_event *event,
122 struct hw_perf_event *hwc,
125 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
126 s64 left = local64_read(&hwc->period_left);
127 s64 period = hwc->sample_period;
132 if (unlikely(left <= -period)) {
134 local64_set(&hwc->period_left, left);
135 hwc->last_period = period;
139 if (unlikely(left <= 0)) {
141 local64_set(&hwc->period_left, left);
142 hwc->last_period = period;
146 if (left > (s64)MAX_PERIOD)
149 local64_set(&hwc->prev_count, (u64)-left);
151 local_irq_save(flags);
152 uleft = (u64)(-left) & MAX_PERIOD;
153 uleft > VALID_COUNT ?
154 set_bit(idx, cpuc->msbs) : clear_bit(idx, cpuc->msbs);
155 mipspmu->write_counter(idx, (u64)(-left) & VALID_COUNT);
156 local_irq_restore(flags);
158 perf_event_update_userpage(event);
163 static void mipspmu_event_update(struct perf_event *event,
164 struct hw_perf_event *hwc,
167 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
169 int shift = 64 - TOTAL_BITS;
170 s64 prev_raw_count, new_raw_count;
174 prev_raw_count = local64_read(&hwc->prev_count);
175 local_irq_save(flags);
176 /* Make the counter value be a "real" one. */
177 new_raw_count = mipspmu->read_counter(idx);
178 if (new_raw_count & (test_bit(idx, cpuc->msbs) << HIGHEST_BIT)) {
179 new_raw_count &= VALID_COUNT;
180 clear_bit(idx, cpuc->msbs);
182 new_raw_count |= (test_bit(idx, cpuc->msbs) << HIGHEST_BIT);
183 local_irq_restore(flags);
185 if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
186 new_raw_count) != prev_raw_count)
189 delta = (new_raw_count << shift) - (prev_raw_count << shift);
192 local64_add(delta, &event->count);
193 local64_sub(delta, &hwc->period_left);
196 static void mipspmu_start(struct perf_event *event, int flags)
198 struct hw_perf_event *hwc = &event->hw;
203 if (flags & PERF_EF_RELOAD)
204 WARN_ON_ONCE(!(hwc->state & PERF_HES_UPTODATE));
208 /* Set the period for the event. */
209 mipspmu_event_set_period(event, hwc, hwc->idx);
211 /* Enable the event. */
212 mipspmu->enable_event(hwc, hwc->idx);
215 static void mipspmu_stop(struct perf_event *event, int flags)
217 struct hw_perf_event *hwc = &event->hw;
222 if (!(hwc->state & PERF_HES_STOPPED)) {
223 /* We are working on a local event. */
224 mipspmu->disable_event(hwc->idx);
226 mipspmu_event_update(event, hwc, hwc->idx);
227 hwc->state |= PERF_HES_STOPPED | PERF_HES_UPTODATE;
231 static int mipspmu_add(struct perf_event *event, int flags)
233 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
234 struct hw_perf_event *hwc = &event->hw;
238 perf_pmu_disable(event->pmu);
240 /* To look for a free counter for this event. */
241 idx = mipspmu->alloc_counter(cpuc, hwc);
248 * If there is an event in the counter we are going to use then
249 * make sure it is disabled.
252 mipspmu->disable_event(idx);
253 cpuc->events[idx] = event;
255 hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
256 if (flags & PERF_EF_START)
257 mipspmu_start(event, PERF_EF_RELOAD);
259 /* Propagate our changes to the userspace mapping. */
260 perf_event_update_userpage(event);
263 perf_pmu_enable(event->pmu);
267 static void mipspmu_del(struct perf_event *event, int flags)
269 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
270 struct hw_perf_event *hwc = &event->hw;
273 WARN_ON(idx < 0 || idx >= mipspmu->num_counters);
275 mipspmu_stop(event, PERF_EF_UPDATE);
276 cpuc->events[idx] = NULL;
277 clear_bit(idx, cpuc->used_mask);
279 perf_event_update_userpage(event);
282 static void mipspmu_read(struct perf_event *event)
284 struct hw_perf_event *hwc = &event->hw;
286 /* Don't read disabled counters! */
290 mipspmu_event_update(event, hwc, hwc->idx);
293 static void mipspmu_enable(struct pmu *pmu)
299 static void mipspmu_disable(struct pmu *pmu)
305 static atomic_t active_events = ATOMIC_INIT(0);
306 static DEFINE_MUTEX(pmu_reserve_mutex);
307 static int (*save_perf_irq)(void);
309 static int mipspmu_get_irq(void)
313 if (mipspmu->irq >= 0) {
314 /* Request my own irq handler. */
315 err = request_irq(mipspmu->irq, mipspmu->handle_irq,
316 IRQF_DISABLED | IRQF_NOBALANCING,
317 "mips_perf_pmu", NULL);
319 pr_warning("Unable to request IRQ%d for MIPS "
320 "performance counters!\n", mipspmu->irq);
322 } else if (cp0_perfcount_irq < 0) {
324 * We are sharing the irq number with the timer interrupt.
326 save_perf_irq = perf_irq;
327 perf_irq = mipspmu->handle_shared_irq;
330 pr_warning("The platform hasn't properly defined its "
331 "interrupt controller.\n");
338 static void mipspmu_free_irq(void)
340 if (mipspmu->irq >= 0)
341 free_irq(mipspmu->irq, NULL);
342 else if (cp0_perfcount_irq < 0)
343 perf_irq = save_perf_irq;
347 * mipsxx/rm9000/loongson2 have different performance counters, they have
348 * specific low-level init routines.
350 static void reset_counters(void *arg);
351 static int __hw_perf_event_init(struct perf_event *event);
353 static void hw_perf_event_destroy(struct perf_event *event)
355 if (atomic_dec_and_mutex_lock(&active_events,
356 &pmu_reserve_mutex)) {
358 * We must not call the destroy function with interrupts
361 on_each_cpu(reset_counters,
362 (void *)(long)mipspmu->num_counters, 1);
364 mutex_unlock(&pmu_reserve_mutex);
368 static int mipspmu_event_init(struct perf_event *event)
372 switch (event->attr.type) {
374 case PERF_TYPE_HARDWARE:
375 case PERF_TYPE_HW_CACHE:
382 if (!mipspmu || event->cpu >= nr_cpumask_bits ||
383 (event->cpu >= 0 && !cpu_online(event->cpu)))
386 if (!atomic_inc_not_zero(&active_events)) {
387 if (atomic_read(&active_events) > MIPS_MAX_HWEVENTS) {
388 atomic_dec(&active_events);
392 mutex_lock(&pmu_reserve_mutex);
393 if (atomic_read(&active_events) == 0)
394 err = mipspmu_get_irq();
397 atomic_inc(&active_events);
398 mutex_unlock(&pmu_reserve_mutex);
404 err = __hw_perf_event_init(event);
406 hw_perf_event_destroy(event);
411 static struct pmu pmu = {
412 .pmu_enable = mipspmu_enable,
413 .pmu_disable = mipspmu_disable,
414 .event_init = mipspmu_event_init,
417 .start = mipspmu_start,
418 .stop = mipspmu_stop,
419 .read = mipspmu_read,
422 static unsigned int mipspmu_perf_event_encode(const struct mips_perf_event *pev)
425 * Top 8 bits for range, next 16 bits for cntr_mask, lowest 8 bits for
428 #ifdef CONFIG_MIPS_MT_SMP
429 return ((unsigned int)pev->range << 24) |
430 (pev->cntr_mask & 0xffff00) |
431 (pev->event_id & 0xff);
433 return (pev->cntr_mask & 0xffff00) |
434 (pev->event_id & 0xff);
438 static const struct mips_perf_event *mipspmu_map_general_event(int idx)
440 const struct mips_perf_event *pev;
442 pev = ((*mipspmu->general_event_map)[idx].event_id ==
443 UNSUPPORTED_PERF_EVENT_ID ? ERR_PTR(-EOPNOTSUPP) :
444 &(*mipspmu->general_event_map)[idx]);
449 static const struct mips_perf_event *mipspmu_map_cache_event(u64 config)
451 unsigned int cache_type, cache_op, cache_result;
452 const struct mips_perf_event *pev;
454 cache_type = (config >> 0) & 0xff;
455 if (cache_type >= PERF_COUNT_HW_CACHE_MAX)
456 return ERR_PTR(-EINVAL);
458 cache_op = (config >> 8) & 0xff;
459 if (cache_op >= PERF_COUNT_HW_CACHE_OP_MAX)
460 return ERR_PTR(-EINVAL);
462 cache_result = (config >> 16) & 0xff;
463 if (cache_result >= PERF_COUNT_HW_CACHE_RESULT_MAX)
464 return ERR_PTR(-EINVAL);
466 pev = &((*mipspmu->cache_event_map)
471 if (pev->event_id == UNSUPPORTED_PERF_EVENT_ID)
472 return ERR_PTR(-EOPNOTSUPP);
478 static int validate_event(struct cpu_hw_events *cpuc,
479 struct perf_event *event)
481 struct hw_perf_event fake_hwc = event->hw;
483 /* Allow mixed event group. So return 1 to pass validation. */
484 if (event->pmu != &pmu || event->state <= PERF_EVENT_STATE_OFF)
487 return mipspmu->alloc_counter(cpuc, &fake_hwc) >= 0;
490 static int validate_group(struct perf_event *event)
492 struct perf_event *sibling, *leader = event->group_leader;
493 struct cpu_hw_events fake_cpuc;
495 memset(&fake_cpuc, 0, sizeof(fake_cpuc));
497 if (!validate_event(&fake_cpuc, leader))
500 list_for_each_entry(sibling, &leader->sibling_list, group_entry) {
501 if (!validate_event(&fake_cpuc, sibling))
505 if (!validate_event(&fake_cpuc, event))
511 /* This is needed by specific irq handlers in perf_event_*.c */
512 static void handle_associated_event(struct cpu_hw_events *cpuc,
513 int idx, struct perf_sample_data *data,
514 struct pt_regs *regs)
516 struct perf_event *event = cpuc->events[idx];
517 struct hw_perf_event *hwc = &event->hw;
519 mipspmu_event_update(event, hwc, idx);
520 data->period = event->hw.last_period;
521 if (!mipspmu_event_set_period(event, hwc, idx))
524 if (perf_event_overflow(event, data, regs))
525 mipspmu->disable_event(idx);
528 #define M_CONFIG1_PC (1 << 4)
530 #define M_PERFCTL_EXL (1UL << 0)
531 #define M_PERFCTL_KERNEL (1UL << 1)
532 #define M_PERFCTL_SUPERVISOR (1UL << 2)
533 #define M_PERFCTL_USER (1UL << 3)
534 #define M_PERFCTL_INTERRUPT_ENABLE (1UL << 4)
535 #define M_PERFCTL_EVENT(event) (((event) & 0x3ff) << 5)
536 #define M_PERFCTL_VPEID(vpe) ((vpe) << 16)
537 #define M_PERFCTL_MT_EN(filter) ((filter) << 20)
538 #define M_TC_EN_ALL M_PERFCTL_MT_EN(0)
539 #define M_TC_EN_VPE M_PERFCTL_MT_EN(1)
540 #define M_TC_EN_TC M_PERFCTL_MT_EN(2)
541 #define M_PERFCTL_TCID(tcid) ((tcid) << 22)
542 #define M_PERFCTL_WIDE (1UL << 30)
543 #define M_PERFCTL_MORE (1UL << 31)
545 #define M_PERFCTL_COUNT_EVENT_WHENEVER (M_PERFCTL_EXL | \
548 M_PERFCTL_SUPERVISOR | \
549 M_PERFCTL_INTERRUPT_ENABLE)
551 #ifdef CONFIG_MIPS_MT_SMP
552 #define M_PERFCTL_CONFIG_MASK 0x3fff801f
554 #define M_PERFCTL_CONFIG_MASK 0x1f
556 #define M_PERFCTL_EVENT_MASK 0xfe0
558 #define M_COUNTER_OVERFLOW (1UL << 31)
560 #ifdef CONFIG_MIPS_MT_SMP
561 static int cpu_has_mipsmt_pertccounters;
564 * FIXME: For VSMP, vpe_id() is redefined for Perf-events, because
565 * cpu_data[cpuid].vpe_id reports 0 for _both_ CPUs.
567 #if defined(CONFIG_HW_PERF_EVENTS)
568 #define vpe_id() (cpu_has_mipsmt_pertccounters ? \
569 0 : smp_processor_id())
571 #define vpe_id() (cpu_has_mipsmt_pertccounters ? \
572 0 : cpu_data[smp_processor_id()].vpe_id)
575 /* Copied from op_model_mipsxx.c */
576 static unsigned int vpe_shift(void)
578 if (num_possible_cpus() > 1)
584 static unsigned int counters_total_to_per_cpu(unsigned int counters)
586 return counters >> vpe_shift();
589 static unsigned int counters_per_cpu_to_total(unsigned int counters)
591 return counters << vpe_shift();
594 #else /* !CONFIG_MIPS_MT_SMP */
597 #endif /* CONFIG_MIPS_MT_SMP */
599 #define __define_perf_accessors(r, n, np) \
601 static unsigned int r_c0_ ## r ## n(void) \
603 unsigned int cpu = vpe_id(); \
607 return read_c0_ ## r ## n(); \
609 return read_c0_ ## r ## np(); \
616 static void w_c0_ ## r ## n(unsigned int value) \
618 unsigned int cpu = vpe_id(); \
622 write_c0_ ## r ## n(value); \
625 write_c0_ ## r ## np(value); \
633 __define_perf_accessors(perfcntr, 0, 2)
634 __define_perf_accessors(perfcntr, 1, 3)
635 __define_perf_accessors(perfcntr, 2, 0)
636 __define_perf_accessors(perfcntr, 3, 1)
638 __define_perf_accessors(perfctrl, 0, 2)
639 __define_perf_accessors(perfctrl, 1, 3)
640 __define_perf_accessors(perfctrl, 2, 0)
641 __define_perf_accessors(perfctrl, 3, 1)
643 static int __n_counters(void)
645 if (!(read_c0_config1() & M_CONFIG1_PC))
647 if (!(read_c0_perfctrl0() & M_PERFCTL_MORE))
649 if (!(read_c0_perfctrl1() & M_PERFCTL_MORE))
651 if (!(read_c0_perfctrl2() & M_PERFCTL_MORE))
657 static int n_counters(void)
661 switch (current_cpu_type()) {
672 counters = __n_counters();
678 static void reset_counters(void *arg)
680 int counters = (int)(long)arg;
697 static u64 mipsxx_pmu_read_counter(unsigned int idx)
701 return r_c0_perfcntr0();
703 return r_c0_perfcntr1();
705 return r_c0_perfcntr2();
707 return r_c0_perfcntr3();
709 WARN_ONCE(1, "Invalid performance counter number (%d)\n", idx);
714 static void mipsxx_pmu_write_counter(unsigned int idx, u64 val)
732 static unsigned int mipsxx_pmu_read_control(unsigned int idx)
736 return r_c0_perfctrl0();
738 return r_c0_perfctrl1();
740 return r_c0_perfctrl2();
742 return r_c0_perfctrl3();
744 WARN_ONCE(1, "Invalid performance counter number (%d)\n", idx);
749 static void mipsxx_pmu_write_control(unsigned int idx, unsigned int val)
767 #ifdef CONFIG_MIPS_MT_SMP
768 static DEFINE_RWLOCK(pmuint_rwlock);
771 /* 24K/34K/1004K cores can share the same event map. */
772 static const struct mips_perf_event mipsxxcore_event_map
773 [PERF_COUNT_HW_MAX] = {
774 [PERF_COUNT_HW_CPU_CYCLES] = { 0x00, CNTR_EVEN | CNTR_ODD, P },
775 [PERF_COUNT_HW_INSTRUCTIONS] = { 0x01, CNTR_EVEN | CNTR_ODD, T },
776 [PERF_COUNT_HW_CACHE_REFERENCES] = { UNSUPPORTED_PERF_EVENT_ID },
777 [PERF_COUNT_HW_CACHE_MISSES] = { UNSUPPORTED_PERF_EVENT_ID },
778 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = { 0x02, CNTR_EVEN, T },
779 [PERF_COUNT_HW_BRANCH_MISSES] = { 0x02, CNTR_ODD, T },
780 [PERF_COUNT_HW_BUS_CYCLES] = { UNSUPPORTED_PERF_EVENT_ID },
783 /* 74K core has different branch event code. */
784 static const struct mips_perf_event mipsxx74Kcore_event_map
785 [PERF_COUNT_HW_MAX] = {
786 [PERF_COUNT_HW_CPU_CYCLES] = { 0x00, CNTR_EVEN | CNTR_ODD, P },
787 [PERF_COUNT_HW_INSTRUCTIONS] = { 0x01, CNTR_EVEN | CNTR_ODD, T },
788 [PERF_COUNT_HW_CACHE_REFERENCES] = { UNSUPPORTED_PERF_EVENT_ID },
789 [PERF_COUNT_HW_CACHE_MISSES] = { UNSUPPORTED_PERF_EVENT_ID },
790 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = { 0x27, CNTR_EVEN, T },
791 [PERF_COUNT_HW_BRANCH_MISSES] = { 0x27, CNTR_ODD, T },
792 [PERF_COUNT_HW_BUS_CYCLES] = { UNSUPPORTED_PERF_EVENT_ID },
795 /* 24K/34K/1004K cores can share the same cache event map. */
796 static const struct mips_perf_event mipsxxcore_cache_map
797 [PERF_COUNT_HW_CACHE_MAX]
798 [PERF_COUNT_HW_CACHE_OP_MAX]
799 [PERF_COUNT_HW_CACHE_RESULT_MAX] = {
802 * Like some other architectures (e.g. ARM), the performance
803 * counters don't differentiate between read and write
804 * accesses/misses, so this isn't strictly correct, but it's the
805 * best we can do. Writes and reads get combined.
808 [C(RESULT_ACCESS)] = { 0x0a, CNTR_EVEN, T },
809 [C(RESULT_MISS)] = { 0x0b, CNTR_EVEN | CNTR_ODD, T },
812 [C(RESULT_ACCESS)] = { 0x0a, CNTR_EVEN, T },
813 [C(RESULT_MISS)] = { 0x0b, CNTR_EVEN | CNTR_ODD, T },
816 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
817 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
822 [C(RESULT_ACCESS)] = { 0x09, CNTR_EVEN, T },
823 [C(RESULT_MISS)] = { 0x09, CNTR_ODD, T },
826 [C(RESULT_ACCESS)] = { 0x09, CNTR_EVEN, T },
827 [C(RESULT_MISS)] = { 0x09, CNTR_ODD, T },
830 [C(RESULT_ACCESS)] = { 0x14, CNTR_EVEN, T },
832 * Note that MIPS has only "hit" events countable for
833 * the prefetch operation.
835 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
840 [C(RESULT_ACCESS)] = { 0x15, CNTR_ODD, P },
841 [C(RESULT_MISS)] = { 0x16, CNTR_EVEN, P },
844 [C(RESULT_ACCESS)] = { 0x15, CNTR_ODD, P },
845 [C(RESULT_MISS)] = { 0x16, CNTR_EVEN, P },
848 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
849 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
854 [C(RESULT_ACCESS)] = { 0x06, CNTR_EVEN, T },
855 [C(RESULT_MISS)] = { 0x06, CNTR_ODD, T },
858 [C(RESULT_ACCESS)] = { 0x06, CNTR_EVEN, T },
859 [C(RESULT_MISS)] = { 0x06, CNTR_ODD, T },
862 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
863 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
868 [C(RESULT_ACCESS)] = { 0x05, CNTR_EVEN, T },
869 [C(RESULT_MISS)] = { 0x05, CNTR_ODD, T },
872 [C(RESULT_ACCESS)] = { 0x05, CNTR_EVEN, T },
873 [C(RESULT_MISS)] = { 0x05, CNTR_ODD, T },
876 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
877 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
881 /* Using the same code for *HW_BRANCH* */
883 [C(RESULT_ACCESS)] = { 0x02, CNTR_EVEN, T },
884 [C(RESULT_MISS)] = { 0x02, CNTR_ODD, T },
887 [C(RESULT_ACCESS)] = { 0x02, CNTR_EVEN, T },
888 [C(RESULT_MISS)] = { 0x02, CNTR_ODD, T },
891 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
892 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
897 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
898 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
901 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
902 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
905 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
906 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
911 /* 74K core has completely different cache event map. */
912 static const struct mips_perf_event mipsxx74Kcore_cache_map
913 [PERF_COUNT_HW_CACHE_MAX]
914 [PERF_COUNT_HW_CACHE_OP_MAX]
915 [PERF_COUNT_HW_CACHE_RESULT_MAX] = {
918 * Like some other architectures (e.g. ARM), the performance
919 * counters don't differentiate between read and write
920 * accesses/misses, so this isn't strictly correct, but it's the
921 * best we can do. Writes and reads get combined.
924 [C(RESULT_ACCESS)] = { 0x17, CNTR_ODD, T },
925 [C(RESULT_MISS)] = { 0x18, CNTR_ODD, T },
928 [C(RESULT_ACCESS)] = { 0x17, CNTR_ODD, T },
929 [C(RESULT_MISS)] = { 0x18, CNTR_ODD, T },
932 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
933 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
938 [C(RESULT_ACCESS)] = { 0x06, CNTR_EVEN, T },
939 [C(RESULT_MISS)] = { 0x06, CNTR_ODD, T },
942 [C(RESULT_ACCESS)] = { 0x06, CNTR_EVEN, T },
943 [C(RESULT_MISS)] = { 0x06, CNTR_ODD, T },
946 [C(RESULT_ACCESS)] = { 0x34, CNTR_EVEN, T },
948 * Note that MIPS has only "hit" events countable for
949 * the prefetch operation.
951 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
956 [C(RESULT_ACCESS)] = { 0x1c, CNTR_ODD, P },
957 [C(RESULT_MISS)] = { 0x1d, CNTR_EVEN | CNTR_ODD, P },
960 [C(RESULT_ACCESS)] = { 0x1c, CNTR_ODD, P },
961 [C(RESULT_MISS)] = { 0x1d, CNTR_EVEN | CNTR_ODD, P },
964 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
965 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
969 /* 74K core does not have specific DTLB events. */
971 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
972 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
975 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
976 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
979 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
980 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
985 [C(RESULT_ACCESS)] = { 0x04, CNTR_EVEN, T },
986 [C(RESULT_MISS)] = { 0x04, CNTR_ODD, T },
989 [C(RESULT_ACCESS)] = { 0x04, CNTR_EVEN, T },
990 [C(RESULT_MISS)] = { 0x04, CNTR_ODD, T },
993 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
994 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
998 /* Using the same code for *HW_BRANCH* */
1000 [C(RESULT_ACCESS)] = { 0x27, CNTR_EVEN, T },
1001 [C(RESULT_MISS)] = { 0x27, CNTR_ODD, T },
1004 [C(RESULT_ACCESS)] = { 0x27, CNTR_EVEN, T },
1005 [C(RESULT_MISS)] = { 0x27, CNTR_ODD, T },
1007 [C(OP_PREFETCH)] = {
1008 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
1009 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
1014 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
1015 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
1018 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
1019 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
1021 [C(OP_PREFETCH)] = {
1022 [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
1023 [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
1028 #ifdef CONFIG_MIPS_MT_SMP
1029 static void check_and_calc_range(struct perf_event *event,
1030 const struct mips_perf_event *pev)
1032 struct hw_perf_event *hwc = &event->hw;
1034 if (event->cpu >= 0) {
1035 if (pev->range > V) {
1037 * The user selected an event that is processor
1038 * wide, while expecting it to be VPE wide.
1040 hwc->config_base |= M_TC_EN_ALL;
1043 * FIXME: cpu_data[event->cpu].vpe_id reports 0
1046 hwc->config_base |= M_PERFCTL_VPEID(event->cpu);
1047 hwc->config_base |= M_TC_EN_VPE;
1050 hwc->config_base |= M_TC_EN_ALL;
1053 static void check_and_calc_range(struct perf_event *event,
1054 const struct mips_perf_event *pev)
1059 static int __hw_perf_event_init(struct perf_event *event)
1061 struct perf_event_attr *attr = &event->attr;
1062 struct hw_perf_event *hwc = &event->hw;
1063 const struct mips_perf_event *pev;
1066 /* Returning MIPS event descriptor for generic perf event. */
1067 if (PERF_TYPE_HARDWARE == event->attr.type) {
1068 if (event->attr.config >= PERF_COUNT_HW_MAX)
1070 pev = mipspmu_map_general_event(event->attr.config);
1071 } else if (PERF_TYPE_HW_CACHE == event->attr.type) {
1072 pev = mipspmu_map_cache_event(event->attr.config);
1073 } else if (PERF_TYPE_RAW == event->attr.type) {
1074 /* We are working on the global raw event. */
1075 mutex_lock(&raw_event_mutex);
1076 pev = mipspmu->map_raw_event(event->attr.config);
1078 /* The event type is not (yet) supported. */
1083 if (PERF_TYPE_RAW == event->attr.type)
1084 mutex_unlock(&raw_event_mutex);
1085 return PTR_ERR(pev);
1089 * We allow max flexibility on how each individual counter shared
1090 * by the single CPU operates (the mode exclusion and the range).
1092 hwc->config_base = M_PERFCTL_INTERRUPT_ENABLE;
1094 /* Calculate range bits and validate it. */
1095 if (num_possible_cpus() > 1)
1096 check_and_calc_range(event, pev);
1098 hwc->event_base = mipspmu_perf_event_encode(pev);
1099 if (PERF_TYPE_RAW == event->attr.type)
1100 mutex_unlock(&raw_event_mutex);
1102 if (!attr->exclude_user)
1103 hwc->config_base |= M_PERFCTL_USER;
1104 if (!attr->exclude_kernel) {
1105 hwc->config_base |= M_PERFCTL_KERNEL;
1106 /* MIPS kernel mode: KSU == 00b || EXL == 1 || ERL == 1 */
1107 hwc->config_base |= M_PERFCTL_EXL;
1109 if (!attr->exclude_hv)
1110 hwc->config_base |= M_PERFCTL_SUPERVISOR;
1112 hwc->config_base &= M_PERFCTL_CONFIG_MASK;
1114 * The event can belong to another cpu. We do not assign a local
1115 * counter for it for now.
1120 if (!hwc->sample_period) {
1121 hwc->sample_period = MAX_PERIOD;
1122 hwc->last_period = hwc->sample_period;
1123 local64_set(&hwc->period_left, hwc->sample_period);
1127 if (event->group_leader != event) {
1128 err = validate_group(event);
1133 event->destroy = hw_perf_event_destroy;
1138 static void pause_local_counters(void)
1140 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
1141 int counters = mipspmu->num_counters;
1142 unsigned long flags;
1144 local_irq_save(flags);
1147 cpuc->saved_ctrl[3] = r_c0_perfctrl3();
1148 w_c0_perfctrl3(cpuc->saved_ctrl[3] &
1149 ~M_PERFCTL_COUNT_EVENT_WHENEVER);
1151 cpuc->saved_ctrl[2] = r_c0_perfctrl2();
1152 w_c0_perfctrl2(cpuc->saved_ctrl[2] &
1153 ~M_PERFCTL_COUNT_EVENT_WHENEVER);
1155 cpuc->saved_ctrl[1] = r_c0_perfctrl1();
1156 w_c0_perfctrl1(cpuc->saved_ctrl[1] &
1157 ~M_PERFCTL_COUNT_EVENT_WHENEVER);
1159 cpuc->saved_ctrl[0] = r_c0_perfctrl0();
1160 w_c0_perfctrl0(cpuc->saved_ctrl[0] &
1161 ~M_PERFCTL_COUNT_EVENT_WHENEVER);
1163 local_irq_restore(flags);
1166 static void resume_local_counters(void)
1168 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
1169 int counters = mipspmu->num_counters;
1170 unsigned long flags;
1172 local_irq_save(flags);
1175 w_c0_perfctrl3(cpuc->saved_ctrl[3]);
1177 w_c0_perfctrl2(cpuc->saved_ctrl[2]);
1179 w_c0_perfctrl1(cpuc->saved_ctrl[1]);
1181 w_c0_perfctrl0(cpuc->saved_ctrl[0]);
1183 local_irq_restore(flags);
1186 static int mipsxx_pmu_handle_shared_irq(void)
1188 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
1189 struct perf_sample_data data;
1190 unsigned int counters = mipspmu->num_counters;
1191 unsigned int counter;
1192 int handled = IRQ_NONE;
1193 struct pt_regs *regs;
1195 if (cpu_has_mips_r2 && !(read_c0_cause() & (1 << 26)))
1199 * First we pause the local counters, so that when we are locked
1200 * here, the counters are all paused. When it gets locked due to
1201 * perf_disable(), the timer interrupt handler will be delayed.
1203 * See also mipsxx_pmu_start().
1205 pause_local_counters();
1206 #ifdef CONFIG_MIPS_MT_SMP
1207 read_lock(&pmuint_rwlock);
1210 regs = get_irq_regs();
1212 perf_sample_data_init(&data, 0);
1215 #define HANDLE_COUNTER(n) \
1217 if (test_bit(n, cpuc->used_mask)) { \
1218 counter = r_c0_perfcntr ## n(); \
1219 if (counter & M_COUNTER_OVERFLOW) { \
1220 w_c0_perfcntr ## n(counter & \
1222 if (test_and_change_bit(n, cpuc->msbs)) \
1223 handle_associated_event(cpuc, \
1225 handled = IRQ_HANDLED; \
1235 * Do all the work for the pending perf events. We can do this
1236 * in here because the performance counter interrupt is a regular
1237 * interrupt, not NMI.
1239 if (handled == IRQ_HANDLED)
1242 #ifdef CONFIG_MIPS_MT_SMP
1243 read_unlock(&pmuint_rwlock);
1245 resume_local_counters();
1249 static irqreturn_t mipsxx_pmu_handle_irq(int irq, void *dev)
1251 return mipsxx_pmu_handle_shared_irq();
1254 static void mipsxx_pmu_start(void)
1256 #ifdef CONFIG_MIPS_MT_SMP
1257 write_unlock(&pmuint_rwlock);
1259 resume_local_counters();
1263 * MIPS performance counters can be per-TC. The control registers can
1264 * not be directly accessed across CPUs. Hence if we want to do global
1265 * control, we need cross CPU calls. on_each_cpu() can help us, but we
1266 * can not make sure this function is called with interrupts enabled. So
1267 * here we pause local counters and then grab a rwlock and leave the
1268 * counters on other CPUs alone. If any counter interrupt raises while
1269 * we own the write lock, simply pause local counters on that CPU and
1270 * spin in the handler. Also we know we won't be switched to another
1271 * CPU after pausing local counters and before grabbing the lock.
1273 static void mipsxx_pmu_stop(void)
1275 pause_local_counters();
1276 #ifdef CONFIG_MIPS_MT_SMP
1277 write_lock(&pmuint_rwlock);
1281 static int mipsxx_pmu_alloc_counter(struct cpu_hw_events *cpuc,
1282 struct hw_perf_event *hwc)
1287 * We only need to care the counter mask. The range has been
1288 * checked definitely.
1290 unsigned long cntr_mask = (hwc->event_base >> 8) & 0xffff;
1292 for (i = mipspmu->num_counters - 1; i >= 0; i--) {
1294 * Note that some MIPS perf events can be counted by both
1295 * even and odd counters, wheresas many other are only by
1296 * even _or_ odd counters. This introduces an issue that
1297 * when the former kind of event takes the counter the
1298 * latter kind of event wants to use, then the "counter
1299 * allocation" for the latter event will fail. In fact if
1300 * they can be dynamically swapped, they both feel happy.
1301 * But here we leave this issue alone for now.
1303 if (test_bit(i, &cntr_mask) &&
1304 !test_and_set_bit(i, cpuc->used_mask))
1311 static void mipsxx_pmu_enable_event(struct hw_perf_event *evt, int idx)
1313 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
1314 unsigned long flags;
1316 WARN_ON(idx < 0 || idx >= mipspmu->num_counters);
1318 local_irq_save(flags);
1319 cpuc->saved_ctrl[idx] = M_PERFCTL_EVENT(evt->event_base & 0xff) |
1320 (evt->config_base & M_PERFCTL_CONFIG_MASK) |
1321 /* Make sure interrupt enabled. */
1322 M_PERFCTL_INTERRUPT_ENABLE;
1324 * We do not actually let the counter run. Leave it until start().
1326 local_irq_restore(flags);
1329 static void mipsxx_pmu_disable_event(int idx)
1331 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
1332 unsigned long flags;
1334 WARN_ON(idx < 0 || idx >= mipspmu->num_counters);
1336 local_irq_save(flags);
1337 cpuc->saved_ctrl[idx] = mipsxx_pmu_read_control(idx) &
1338 ~M_PERFCTL_COUNT_EVENT_WHENEVER;
1339 mipsxx_pmu_write_control(idx, cpuc->saved_ctrl[idx]);
1340 local_irq_restore(flags);
1344 #define IS_UNSUPPORTED_24K_EVENT(r, b) \
1345 ((b) == 12 || (r) == 151 || (r) == 152 || (b) == 26 || \
1346 (b) == 27 || (r) == 28 || (r) == 158 || (b) == 31 || \
1347 (b) == 32 || (b) == 34 || (b) == 36 || (r) == 168 || \
1348 (r) == 172 || (b) == 47 || ((b) >= 56 && (b) <= 63) || \
1349 ((b) >= 68 && (b) <= 127))
1350 #define IS_BOTH_COUNTERS_24K_EVENT(b) \
1351 ((b) == 0 || (b) == 1 || (b) == 11)
1354 #define IS_UNSUPPORTED_34K_EVENT(r, b) \
1355 ((b) == 12 || (r) == 27 || (r) == 158 || (b) == 36 || \
1356 (b) == 38 || (r) == 175 || ((b) >= 56 && (b) <= 63) || \
1357 ((b) >= 68 && (b) <= 127))
1358 #define IS_BOTH_COUNTERS_34K_EVENT(b) \
1359 ((b) == 0 || (b) == 1 || (b) == 11)
1360 #ifdef CONFIG_MIPS_MT_SMP
1361 #define IS_RANGE_P_34K_EVENT(r, b) \
1362 ((b) == 0 || (r) == 18 || (b) == 21 || (b) == 22 || \
1363 (b) == 25 || (b) == 39 || (r) == 44 || (r) == 174 || \
1364 (r) == 176 || ((b) >= 50 && (b) <= 55) || \
1365 ((b) >= 64 && (b) <= 67))
1366 #define IS_RANGE_V_34K_EVENT(r) ((r) == 47)
1370 #define IS_UNSUPPORTED_74K_EVENT(r, b) \
1371 ((r) == 5 || ((r) >= 135 && (r) <= 137) || \
1372 ((b) >= 10 && (b) <= 12) || (b) == 22 || (b) == 27 || \
1373 (b) == 33 || (b) == 34 || ((b) >= 47 && (b) <= 49) || \
1374 (r) == 178 || (b) == 55 || (b) == 57 || (b) == 60 || \
1375 (b) == 61 || (r) == 62 || (r) == 191 || \
1376 ((b) >= 64 && (b) <= 127))
1377 #define IS_BOTH_COUNTERS_74K_EVENT(b) \
1378 ((b) == 0 || (b) == 1)
1381 #define IS_UNSUPPORTED_1004K_EVENT(r, b) \
1382 ((b) == 12 || (r) == 27 || (r) == 158 || (b) == 38 || \
1383 (r) == 175 || (b) == 63 || ((b) >= 68 && (b) <= 127))
1384 #define IS_BOTH_COUNTERS_1004K_EVENT(b) \
1385 ((b) == 0 || (b) == 1 || (b) == 11)
1386 #ifdef CONFIG_MIPS_MT_SMP
1387 #define IS_RANGE_P_1004K_EVENT(r, b) \
1388 ((b) == 0 || (r) == 18 || (b) == 21 || (b) == 22 || \
1389 (b) == 25 || (b) == 36 || (b) == 39 || (r) == 44 || \
1390 (r) == 174 || (r) == 176 || ((b) >= 50 && (b) <= 59) || \
1391 (r) == 188 || (b) == 61 || (b) == 62 || \
1392 ((b) >= 64 && (b) <= 67))
1393 #define IS_RANGE_V_1004K_EVENT(r) ((r) == 47)
1397 * User can use 0-255 raw events, where 0-127 for the events of even
1398 * counters, and 128-255 for odd counters. Note that bit 7 is used to
1399 * indicate the parity. So, for example, when user wants to take the
1400 * Event Num of 15 for odd counters (by referring to the user manual),
1401 * then 128 needs to be added to 15 as the input for the event config,
1402 * i.e., 143 (0x8F) to be used.
1404 static const struct mips_perf_event *mipsxx_pmu_map_raw_event(u64 config)
1406 unsigned int raw_id = config & 0xff;
1407 unsigned int base_id = raw_id & 0x7f;
1409 switch (current_cpu_type()) {
1411 if (IS_UNSUPPORTED_24K_EVENT(raw_id, base_id))
1412 return ERR_PTR(-EOPNOTSUPP);
1413 raw_event.event_id = base_id;
1414 if (IS_BOTH_COUNTERS_24K_EVENT(base_id))
1415 raw_event.cntr_mask = CNTR_EVEN | CNTR_ODD;
1417 raw_event.cntr_mask =
1418 raw_id > 127 ? CNTR_ODD : CNTR_EVEN;
1419 #ifdef CONFIG_MIPS_MT_SMP
1421 * This is actually doing nothing. Non-multithreading
1422 * CPUs will not check and calculate the range.
1424 raw_event.range = P;
1428 if (IS_UNSUPPORTED_34K_EVENT(raw_id, base_id))
1429 return ERR_PTR(-EOPNOTSUPP);
1430 raw_event.event_id = base_id;
1431 if (IS_BOTH_COUNTERS_34K_EVENT(base_id))
1432 raw_event.cntr_mask = CNTR_EVEN | CNTR_ODD;
1434 raw_event.cntr_mask =
1435 raw_id > 127 ? CNTR_ODD : CNTR_EVEN;
1436 #ifdef CONFIG_MIPS_MT_SMP
1437 if (IS_RANGE_P_34K_EVENT(raw_id, base_id))
1438 raw_event.range = P;
1439 else if (unlikely(IS_RANGE_V_34K_EVENT(raw_id)))
1440 raw_event.range = V;
1442 raw_event.range = T;
1446 if (IS_UNSUPPORTED_74K_EVENT(raw_id, base_id))
1447 return ERR_PTR(-EOPNOTSUPP);
1448 raw_event.event_id = base_id;
1449 if (IS_BOTH_COUNTERS_74K_EVENT(base_id))
1450 raw_event.cntr_mask = CNTR_EVEN | CNTR_ODD;
1452 raw_event.cntr_mask =
1453 raw_id > 127 ? CNTR_ODD : CNTR_EVEN;
1454 #ifdef CONFIG_MIPS_MT_SMP
1455 raw_event.range = P;
1459 if (IS_UNSUPPORTED_1004K_EVENT(raw_id, base_id))
1460 return ERR_PTR(-EOPNOTSUPP);
1461 raw_event.event_id = base_id;
1462 if (IS_BOTH_COUNTERS_1004K_EVENT(base_id))
1463 raw_event.cntr_mask = CNTR_EVEN | CNTR_ODD;
1465 raw_event.cntr_mask =
1466 raw_id > 127 ? CNTR_ODD : CNTR_EVEN;
1467 #ifdef CONFIG_MIPS_MT_SMP
1468 if (IS_RANGE_P_1004K_EVENT(raw_id, base_id))
1469 raw_event.range = P;
1470 else if (unlikely(IS_RANGE_V_1004K_EVENT(raw_id)))
1471 raw_event.range = V;
1473 raw_event.range = T;
1481 static struct mips_pmu mipsxxcore_pmu = {
1482 .handle_irq = mipsxx_pmu_handle_irq,
1483 .handle_shared_irq = mipsxx_pmu_handle_shared_irq,
1484 .start = mipsxx_pmu_start,
1485 .stop = mipsxx_pmu_stop,
1486 .alloc_counter = mipsxx_pmu_alloc_counter,
1487 .read_counter = mipsxx_pmu_read_counter,
1488 .write_counter = mipsxx_pmu_write_counter,
1489 .enable_event = mipsxx_pmu_enable_event,
1490 .disable_event = mipsxx_pmu_disable_event,
1491 .map_raw_event = mipsxx_pmu_map_raw_event,
1492 .general_event_map = &mipsxxcore_event_map,
1493 .cache_event_map = &mipsxxcore_cache_map,
1496 static struct mips_pmu mipsxx74Kcore_pmu = {
1497 .handle_irq = mipsxx_pmu_handle_irq,
1498 .handle_shared_irq = mipsxx_pmu_handle_shared_irq,
1499 .start = mipsxx_pmu_start,
1500 .stop = mipsxx_pmu_stop,
1501 .alloc_counter = mipsxx_pmu_alloc_counter,
1502 .read_counter = mipsxx_pmu_read_counter,
1503 .write_counter = mipsxx_pmu_write_counter,
1504 .enable_event = mipsxx_pmu_enable_event,
1505 .disable_event = mipsxx_pmu_disable_event,
1506 .map_raw_event = mipsxx_pmu_map_raw_event,
1507 .general_event_map = &mipsxx74Kcore_event_map,
1508 .cache_event_map = &mipsxx74Kcore_cache_map,
1512 init_hw_perf_events(void)
1516 pr_info("Performance counters: ");
1518 counters = n_counters();
1519 if (counters == 0) {
1520 pr_cont("No available PMU.\n");
1524 #ifdef CONFIG_MIPS_MT_SMP
1525 cpu_has_mipsmt_pertccounters = read_c0_config7() & (1<<19);
1526 if (!cpu_has_mipsmt_pertccounters)
1527 counters = counters_total_to_per_cpu(counters);
1530 #ifdef MSC01E_INT_BASE
1533 * Using platform specific interrupt controller defines.
1535 irq = MSC01E_INT_BASE + MSC01E_INT_PERFCTR;
1538 if (cp0_perfcount_irq >= 0)
1539 irq = MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
1542 #ifdef MSC01E_INT_BASE
1546 on_each_cpu(reset_counters, (void *)(long)counters, 1);
1548 switch (current_cpu_type()) {
1550 mipsxxcore_pmu.name = "mips/24K";
1551 mipsxxcore_pmu.num_counters = counters;
1552 mipsxxcore_pmu.irq = irq;
1553 mipspmu = &mipsxxcore_pmu;
1556 mipsxxcore_pmu.name = "mips/34K";
1557 mipsxxcore_pmu.num_counters = counters;
1558 mipsxxcore_pmu.irq = irq;
1559 mipspmu = &mipsxxcore_pmu;
1562 mipsxx74Kcore_pmu.name = "mips/74K";
1563 mipsxx74Kcore_pmu.num_counters = counters;
1564 mipsxx74Kcore_pmu.irq = irq;
1565 mipspmu = &mipsxx74Kcore_pmu;
1568 mipsxxcore_pmu.name = "mips/1004K";
1569 mipsxxcore_pmu.num_counters = counters;
1570 mipsxxcore_pmu.irq = irq;
1571 mipspmu = &mipsxxcore_pmu;
1574 pr_cont("Either hardware does not support performance "
1575 "counters, or not yet implemented.\n");
1580 pr_cont("%s PMU enabled, %d counters available to each "
1581 "CPU, irq %d%s\n", mipspmu->name, counters, irq,
1582 irq < 0 ? " (share with timer interrupt)" : "");
1584 perf_pmu_register(&pmu, "cpu", PERF_TYPE_RAW);
1588 early_initcall(init_hw_perf_events);