| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2006-2007, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bperf_counter.h $ |
|---|
| 11 | * $brcm_Revision: 7 $ |
|---|
| 12 | * $brcm_Date: 1/15/07 10:50a $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Perfomance counter module |
|---|
| 17 | * |
|---|
| 18 | * Revision History: |
|---|
| 19 | * |
|---|
| 20 | * $brcm_Log: /BSEAV/lib/bprofile/bperf_counter.h $ |
|---|
| 21 | * |
|---|
| 22 | * 7 1/15/07 10:50a vsilyaev |
|---|
| 23 | * PR 25997: Added 7038 performance counters |
|---|
| 24 | * |
|---|
| 25 | * 6 12/22/06 12:03p vsilyaev |
|---|
| 26 | * PR 26792: Added rac_access, rac_prefetch and rac_hits configurations |
|---|
| 27 | * for the peformance counter |
|---|
| 28 | * |
|---|
| 29 | * 5 12/14/06 4:38p vsilyaev |
|---|
| 30 | * PR 25997: Added counter configuration to capture issue rate |
|---|
| 31 | * |
|---|
| 32 | * 4 12/8/06 7:24p vsilyaev |
|---|
| 33 | * PR 25997: Fixed warning |
|---|
| 34 | * |
|---|
| 35 | * 3 12/7/06 2:44p vsilyaev |
|---|
| 36 | * PR 25997: Added fixes for 3.4 GCC compiler |
|---|
| 37 | * |
|---|
| 38 | * 2 12/5/06 11:08a vsilyaev |
|---|
| 39 | * PR 25997: Improved perf counter interface |
|---|
| 40 | * |
|---|
| 41 | * 1 12/1/06 5:58p vsilyaev |
|---|
| 42 | * PR 25997: CPU perfomance counter interface |
|---|
| 43 | * |
|---|
| 44 | * |
|---|
| 45 | *******************************************************************************/ |
|---|
| 46 | #ifndef __BPERF_COUNT_H__ |
|---|
| 47 | #define __BPERF_COUNT_H__ |
|---|
| 48 | |
|---|
| 49 | #ifdef __cplusplus |
|---|
| 50 | extern "C" |
|---|
| 51 | { |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | #if BCHP_CHIP==7401 || BCHP_CHIP==3560 || BCHP_CHIP==3543 || BCHP_CHIP==7550 |
|---|
| 55 | #define B_PERF_BMIPS3300 1 |
|---|
| 56 | #ifndef BSTD_INLINE |
|---|
| 57 | #define BSTD_INLINE extern inline __attribute__((always_inline)) |
|---|
| 58 | #endif |
|---|
| 59 | #elif BCHP_CHIP==7038 |
|---|
| 60 | #define B_PERF_MIPSR5K 1 |
|---|
| 61 | #else |
|---|
| 62 | #error "Not supported" |
|---|
| 63 | #endif |
|---|
| 64 | |
|---|
| 65 | #if B_PERF_BMIPS3300 |
|---|
| 66 | #define BPERF_N_COUNTERS 4 |
|---|
| 67 | #define BPERF_SAMPLE_INITIALIZER {{0,0,0,0}} |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | #define b_perf_read_one(sel) __extension__ \ |
|---|
| 71 | ({ unsigned int b_perf_read_res; \ |
|---|
| 72 | __asm__ __volatile__(".set\tpush\n\t" \ |
|---|
| 73 | ".set\tmips32\n\t" \ |
|---|
| 74 | "mfc0\t%0, $25, " #sel "\n\t" \ |
|---|
| 75 | ".set\tpop\n\t" \ |
|---|
| 76 | : "=r" (b_perf_read_res)); \ |
|---|
| 77 | b_perf_read_res; \ |
|---|
| 78 | }) |
|---|
| 79 | |
|---|
| 80 | BSTD_INLINE unsigned bperf_sample_diff(unsigned stop, unsigned start) |
|---|
| 81 | { |
|---|
| 82 | return start-stop; /* perfomance timers are count down */ |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | #elif B_PERF_MIPSR5K |
|---|
| 86 | #define BPERF_N_COUNTERS 2 |
|---|
| 87 | #define BPERF_SAMPLE_INITIALIZER {{0,0}} |
|---|
| 88 | #define b_perf_read_one(sel) __extension__ \ |
|---|
| 89 | ({ unsigned int b_perf_read_res; \ |
|---|
| 90 | __asm__ __volatile__(".set\tpush\n\t" \ |
|---|
| 91 | ".set\tmips32\n\t" \ |
|---|
| 92 | "mfc0\t%0, $25, " #sel "\n\t" \ |
|---|
| 93 | ".set\tpop\n\t" \ |
|---|
| 94 | : "=r" (b_perf_read_res)); \ |
|---|
| 95 | b_perf_read_res; \ |
|---|
| 96 | }) |
|---|
| 97 | |
|---|
| 98 | BSTD_INLINE unsigned bperf_sample_diff(unsigned stop, unsigned start) |
|---|
| 99 | { |
|---|
| 100 | return stop-start; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | #else /* BCHP_CHIP */ |
|---|
| 104 | #error "Not supported" |
|---|
| 105 | #endif /* BCHP_CHIP */ |
|---|
| 106 | |
|---|
| 107 | typedef struct bperf_counter_mode { |
|---|
| 108 | const char *counter_names[BPERF_N_COUNTERS]; |
|---|
| 109 | unsigned config[3]; /* opaque HW configuration */ |
|---|
| 110 | } bperf_counter_mode; |
|---|
| 111 | |
|---|
| 112 | typedef struct bperf_sample { |
|---|
| 113 | unsigned data[BPERF_N_COUNTERS]; |
|---|
| 114 | } bperf_sample; |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | extern const bperf_counter_mode bperf_counter_dcache; |
|---|
| 118 | extern const bperf_counter_mode bperf_counter_icache; |
|---|
| 119 | extern const bperf_counter_mode bperf_counter_instructions; |
|---|
| 120 | #if B_PERF_BMIPS3300 |
|---|
| 121 | extern const bperf_counter_mode bperf_counter_rac_access; |
|---|
| 122 | extern const bperf_counter_mode bperf_counter_rac_prefetch; |
|---|
| 123 | extern const bperf_counter_mode bperf_counter_rac_hit; |
|---|
| 124 | #endif |
|---|
| 125 | |
|---|
| 126 | int b_perf_init(const bperf_counter_mode *mode); |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | const bperf_counter_mode *bperf_get_mode(void); |
|---|
| 130 | |
|---|
| 131 | void bperf_print(const bperf_counter_mode *mode, const bperf_sample *stop, const bperf_sample *start); |
|---|
| 132 | |
|---|
| 133 | BSTD_INLINE void __attribute__((no_instrument_function)) |
|---|
| 134 | b_perf_read(bperf_sample *sample) |
|---|
| 135 | { |
|---|
| 136 | #if B_PERF_BMIPS3300 |
|---|
| 137 | sample->data[0] = b_perf_read_one(0); |
|---|
| 138 | sample->data[1] = b_perf_read_one(1); |
|---|
| 139 | sample->data[2] = b_perf_read_one(2); |
|---|
| 140 | sample->data[3] = b_perf_read_one(3); |
|---|
| 141 | #elif B_PERF_MIPSR5K |
|---|
| 142 | sample->data[0] = b_perf_read_one(1); |
|---|
| 143 | sample->data[1] = b_perf_read_one(3); |
|---|
| 144 | #endif |
|---|
| 145 | return; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | #ifndef bperf_read |
|---|
| 149 | #define bperf_read b_perf_read |
|---|
| 150 | #endif |
|---|
| 151 | |
|---|
| 152 | #ifndef bperf_init |
|---|
| 153 | #define bperf_init b_perf_init |
|---|
| 154 | #endif |
|---|
| 155 | |
|---|
| 156 | #ifdef __cplusplus |
|---|
| 157 | } |
|---|
| 158 | #endif |
|---|
| 159 | |
|---|
| 160 | #endif /* __BPERF_COUNT_H__ */ |
|---|
| 161 | |
|---|