]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/mips/rmi/perfmon.h
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / mips / rmi / perfmon.h
1 /*-
2  * Copyright (c) 2003-2009 RMI Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of RMI Corporation, nor the names of its contributors,
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * RMI_BSD */
30
31 #ifndef PERFMON_H
32 #define PERFMON_H
33
34 #include <mips/rmi/perfmon_xlrconfig.h>
35
36 /*
37  * category events reported by the perfmon library
38  */
39 enum event_category_t {
40         PERF_CP0_COUNTER = 1, PERF_CP2_CREDITS, PERF_L2_COUNTER,
41         PERF_SBC_COUNTER, PERF_SBC_CREDITS, PERF_GMAC0_COUNTER, PERF_GMAC1_COUNTER,
42         PERF_GMAC2_COUNTER, PERF_GMAC_STAT_COM, PERF_GMAC_STAT_TX,
43 PERF_GMAC_STAT_RX, PERF_DRAM_COUNTER, PERF_PARAMETER_CONF = 127};
44
45
46 enum perf_param_t {
47         PERF_CPU_SAMPLING_INTERVAL, PERF_SYS_SAMPLING_INTERVAL, PERF_CC_SAMPLE_RATE, PERF_CP0_FLAGS
48 };
49
50 #define CPO_EVENTS_TEMPLATE  0x06       /* enable kernel and user events */
51
52 #define PERFMON_ACTIVE_MAGIC 0xc001
53 #define PERFMON_ENABLED_MAGIC 0xb007
54 #define PERFMON_INITIAL_GENERATION 0x0101
55
56 #define PERFMON_SERVER_PORT 7007
57
58 enum system_bridge_credits_t {
59         PCIX_CREDITS, HT_CREDITS, GIO_CREDITS, OTHER_CREDITS
60 };
61
62 struct perf_config_data {
63         uint16_t magic;         /* monitor start when this is initialized */
64         uint16_t generation;    /* incremented when the config changes */
65         uint16_t flags;
66         uint16_t cc_sample_rate;/* rate at which credit counters are sampled
67                                  * relative to sampling_rate */
68         uint32_t sampling_rate; /* rate at which events are sampled */
69         uint32_t cc_register_mask;      /* credit counters registers to be
70                                          * sampled */
71         uint64_t events[NTHREADS];      /* events bitmap for each thread */
72 };
73
74 struct perf_sample {
75         uint32_t counter;
76         uint32_t timestamp;
77         uint32_t sample_tag;
78         uint32_t duration;
79 };
80
81 struct sample_q {
82         int32_t head, tail;
83         struct perf_sample samples[PERF_SAMPLE_BUFSZ];
84         uint32_t overflows;
85 };
86
87 struct perf_area {
88         struct perf_config_data perf_config;
89         struct sample_q sample_fifo;
90 };
91
92 /*
93  * We have a shared location to keep a global tick counter for all the
94  * CPUS  - TODO is this optimal? effect on cache?
95  */
96 extern uint32_t *xlr_perfmon_timer_loc;
97
98 #define PERFMON_TIMESTAMP_LOC (xlr_perfmon_timer_loc)
99
100 static __inline__ uint32_t 
101 perfmon_timestamp_get(void)
102 {
103         return *PERFMON_TIMESTAMP_LOC;
104 }
105
106 static __inline__ void 
107 perfmon_timestamp_set(uint32_t val)
108 {
109         *PERFMON_TIMESTAMP_LOC = val;
110 }
111
112 static __inline__ void 
113 perfmon_timestamp_incr(int val)
114 {
115         (*PERFMON_TIMESTAMP_LOC) += val;
116 }
117
118 static __inline__ void 
119 send_sample_gts(uint32_t tag, uint32_t value, uint32_t td)
120 {
121         xlr_send_sample(tag, value, perfmon_timestamp_get(), td);
122 }
123
124 /*
125  * Simple FIFO, one producer - one consumer - circlar queue - no locking
126  */
127
128 static __inline__ void 
129 init_fifo(struct sample_q *q)
130 {
131         q->head = q->tail = 0;
132 }
133
134 static __inline__ void 
135 put_sample(struct sample_q *q, uint32_t sample_tag, uint32_t counter,
136     uint32_t duration)
137 {
138         uint32_t timestamp = perfmon_timestamp_get();
139         int new_tail = (q->tail + 1) % PERF_SAMPLE_BUFSZ;
140
141         if (q->head == new_tail) {
142                 q->overflows++;
143                 return;
144         }
145         q->samples[new_tail].sample_tag = sample_tag;
146         q->samples[new_tail].counter = counter;
147         q->samples[new_tail].timestamp = timestamp;
148         q->samples[new_tail].duration = duration;
149
150         q->tail = new_tail;
151 }
152
153 static __inline__ int 
154 get_sample(struct sample_q *q, uint32_t * sample_tag, uint32_t * counter,
155     uint32_t * timestamp, uint32_t * duration)
156 {
157         int head = q->head;
158
159         if (head == q->tail)
160                 return 0;
161         *sample_tag = q->samples[head].sample_tag;
162         *counter = q->samples[head].counter;
163         *timestamp = q->samples[head].timestamp;
164         *duration = q->samples[head].duration;
165
166         q->head = (head + 1) % PERF_SAMPLE_BUFSZ;
167         return 1;
168 }
169
170 static __inline__ void 
171 clear_queue(struct sample_q *q)
172 {
173         q->head = q->tail;
174 }
175 void xlr_perfmon_init_cpu(void *);
176 void xlr_perfmon_sampler(void *);
177 void log_active_core(int core);
178 int get_start_generation(void);
179
180 void xlr_perfmon_clockhandler(void);
181 extern int xlr_perfmon_started;
182
183 #endif                          /* PERFMON_H */