This commit was generated by cvs2svn to track changes on a CVS vendor
[platform/upstream/binutils.git] / sim / common / sim-profile.h
1 /* Profile header for simulators using common framework.
2    Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3    Contributed by Cygnus Support.
4
5 This file is part of GDB, the GNU debugger.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21 #ifndef SIM_PROFILE_H
22 #define SIM_PROFILE_H
23
24 #ifndef WITH_PROFILE
25 Error, WITH_PROFILE not defined.
26 #endif
27
28 /* Standard profilable entities.  */
29
30 enum {
31   /* Profile insn usage.  */
32   PROFILE_INSN_IDX = 1,
33
34   /* Profile memory usage.  */
35   PROFILE_MEMORY_IDX,
36
37   /* Profile the cpu model (cycles, etc.).  */
38   PROFILE_MODEL_IDX,
39
40   /* Profile the simulator's execution cache.  */
41   PROFILE_SCACHE_IDX,
42
43   /* Profile the PC.  */
44   PROFILE_PC_IDX,
45
46   /* Profile sim-core.c stuff.  */
47   /* ??? The difference between this and PROFILE_MEMORY_IDX is ... ?  */
48   PROFILE_CORE_IDX,
49
50   /* Simulator specific profile bits begin here.  */
51   PROFILE_NEXT_IDX
52 };
53
54 /* Maximum number of profilable entities.  */
55 #ifndef MAX_PROFILE_VALUES
56 #define MAX_PROFILE_VALUES 32
57 #endif
58
59 /* The -p option only prints useful values.  It's easy to type and shouldn't
60    splat on the screen everything under the sun making nothing easy to
61    find.  */
62 #define PROFILE_USEFUL_MASK \
63 ((1 << PROFILE_INSN_IDX) \
64  | (1 << PROFILE_MEMORY_IDX) \
65  | (1 << PROFILE_MODEL_IDX) \
66  | (1 << PROFILE_CORE_IDX))
67
68 /* Utility to parse a --profile-<foo> option.  */
69 /* ??? On the one hand all calls could be confined to sim-profile.c, but
70    on the other hand keeping a module's profiling option with the module's
71    source is cleaner.   */
72
73 SIM_RC sim_profile_set_option (SIM_DESC sd_, const char *name_, int idx_,
74                                const char *arg_);
75 \f
76 /* Masks so WITH_PROFILE can have symbolic values.
77    The case choice here is on purpose.  The lowercase parts are args to
78    --with-profile.  */
79 #define PROFILE_insn   (1 << PROFILE_INSN_IDX)
80 #define PROFILE_memory (1 << PROFILE_MEMORY_IDX)
81 #define PROFILE_model  (1 << PROFILE_MODEL_IDX)
82 #define PROFILE_scache (1 << PROFILE_SCACHE_IDX)
83 #define PROFILE_pc     (1 << PROFILE_PC_IDX)
84 #define PROFILE_core   (1 << PROFILE_CORE_IDX)
85
86 /* Preprocessor macros to simplify tests of WITH_PROFILE.  */
87 #define WITH_PROFILE_INSN_P (WITH_PROFILE & PROFILE_insn)
88 #define WITH_PROFILE_MEMORY_P (WITH_PROFILE & PROFILE_memory)
89 #define WITH_PROFILE_MODEL_P (WITH_PROFILE & PROFILE_model)
90 #define WITH_PROFILE_SCACHE_P (WITH_PROFILE & PROFILE_scache)
91 #define WITH_PROFILE_PC_P (WITH_PROFILE & PROFILE_pc)
92 #define WITH_PROFILE_CORE_P (WITH_PROFILE & PROFILE_core)
93
94 /* If MAX_TARGET_MODES isn't defined, we can't do memory profiling.
95    ??? It is intended that this is a temporary occurence.  Normally
96    MAX_TARGET_MODES is defined.  */
97 #ifndef MAX_TARGET_MODES
98 #undef WITH_PROFILE_MEMORY_P
99 #define WITH_PROFILE_MEMORY_P 0
100 #endif
101
102 /* Only build MODEL code when the target simulator has support for it */
103 #ifndef SIM_HAVE_MODEL
104 #undef WITH_PROFILE_MODEL_P
105 #define WITH_PROFILE_MODEL_P 0
106 #endif
107
108 /* Profiling install handler.  */
109 MODULE_INSTALL_FN profile_install;
110
111 /* Output format macros.  */
112 #ifndef PROFILE_HISTOGRAM_WIDTH
113 #define PROFILE_HISTOGRAM_WIDTH 40
114 #endif
115 #ifndef PROFILE_LABEL_WIDTH
116 #define PROFILE_LABEL_WIDTH 32
117 #endif
118 \f
119 /* Callbacks for internal profile_info.
120    The callbacks may be NULL meaning there isn't one.
121    Note that results are indented two spaces to distinguish them from
122    section titles.
123    If non-NULL, PROFILE_CALLBACK is called to print extra non-cpu related data.
124    If non-NULL, PROFILE_CPU_CALLBACK is called to print extra cpu related data.
125    */
126
127 typedef void (PROFILE_INFO_CALLBACK_FN) (SIM_DESC, int);
128 struct _sim_cpu; /* forward reference */
129 typedef void (PROFILE_INFO_CPU_CALLBACK_FN) (struct _sim_cpu *cpu, int verbose);
130
131 \f
132 /* Struct containing most profiling data.
133    It doesn't contain all profiling data because for example scache data
134    is kept with the rest of scache support.  */
135
136 typedef struct {
137   /* Global summary of all the current profiling options.  */
138   char profile_any_p;
139
140   /* Boolean array of specified profiling flags.  */
141   char profile_flags[MAX_PROFILE_VALUES];
142 #define PROFILE_FLAGS(p) ((p)->profile_flags)
143
144   /* The total insn count is tracked separately.
145      It is always computed, regardless of insn profiling.  */
146   unsigned long total_insn_count;
147 #define PROFILE_TOTAL_INSN_COUNT(p) ((p)->total_insn_count)
148
149 #if WITH_PROFILE_INSN_P
150   unsigned int *insn_count;
151 #define PROFILE_INSN_COUNT(p) ((p)->insn_count)
152 #endif
153
154 #if WITH_PROFILE_MEMORY_P
155   unsigned int read_count[MAX_TARGET_MODES];
156 #define PROFILE_READ_COUNT(p) ((p)->read_count)
157   unsigned int write_count[MAX_TARGET_MODES];
158 #define PROFILE_WRITE_COUNT(p) ((p)->write_count)
159 #endif
160
161 #if WITH_PROFILE_CORE_P
162   /* Count read/write/exec accesses separatly. */
163   unsigned int core_count[nr_maps];
164 #define PROFILE_CORE_COUNT(p) ((p)->core_count)
165 #endif
166
167 #if WITH_PROFILE_MODEL_P
168   /* ??? Quick hack until more elaborate scheme is finished.  */
169   /* Total cycle count, including stalls.  */
170   unsigned long total_cycles;
171 #define PROFILE_MODEL_TOTAL_CYCLES(p) ((p)->total_cycles)
172   /* Stalls due to branches.  */
173   unsigned long cti_stall_cycles;
174 #define PROFILE_MODEL_CTI_STALL_CYCLES(p) ((p)->cti_stall_cycles)
175   unsigned long load_stall_cycles;
176 #define PROFILE_MODEL_LOAD_STALL_CYCLES(p) ((p)->load_stall_cycles)
177   /* Number of cycles the current instruction took.  */
178   unsigned long cur_insn_cycles;
179 #define PROFILE_MODEL_CUR_INSN_CYCLES(p) ((p)->cur_insn_cycles)
180
181   /* Taken and not-taken branches (and other cti's).  */
182   unsigned long taken_count, untaken_count;
183 #define PROFILE_MODEL_TAKEN_COUNT(p) ((p)->taken_count)
184 #define PROFILE_MODEL_UNTAKEN_COUNT(p) ((p)->untaken_count)
185 #endif
186
187 #if WITH_PROFILE_PC_P
188   /* PC profiling attempts to determine function usage by sampling the PC
189      every so many instructions.  */
190   unsigned int profile_pc_freq;
191 #define PROFILE_PC_FREQ(p) ((p)->profile_pc_freq)
192   unsigned int profile_pc_nr_buckets;
193 #define PROFILE_PC_NR_BUCKETS(p) ((p)->profile_pc_nr_buckets)
194   address_word profile_pc_start;
195 #define PROFILE_PC_START(p) ((p)->profile_pc_start)
196   address_word profile_pc_end;
197 #define PROFILE_PC_END(p) ((p)->profile_pc_end)
198   unsigned profile_pc_shift;
199 #define PROFILE_PC_SHIFT(p) ((p)->profile_pc_shift)
200 #define PROFILE_PC_BUCKET_SIZE(p) (PROFILE_PC_SHIFT (p) ? (1 << PROFILE_PC_SHIFT (p)) : 0)
201   unsigned *profile_pc_count;
202 #define PROFILE_PC_COUNT(p) ((p)->profile_pc_count)
203   sim_event *profile_pc_event;
204 #define PROFILE_PC_EVENT(p) ((p)->profile_pc_event)
205 #endif
206
207   /* Profile output goes to this or stderr if NULL.
208      We can't store `stderr' here as stderr goes through a callback.  */
209   FILE *profile_file;
210 #define PROFILE_FILE(p) ((p)->profile_file)
211
212   /* When reporting a profile summary, hook to include per-processor
213      target specific profile information */
214   PROFILE_INFO_CPU_CALLBACK_FN *info_cpu_callback;
215 #define PROFILE_INFO_CPU_CALLBACK(p) ((p)->info_cpu_callback)
216
217   /* When reporting a profile summary, hook to include common target
218      specific profile information */
219   PROFILE_INFO_CALLBACK_FN *info_callback;
220 #define STATE_PROFILE_INFO_CALLBACK(sd) \
221 (CPU_PROFILE_DATA (STATE_CPU (sd, 0))->info_callback)
222
223   /* Profile range.
224      ??? Not all cpu's support this.  */
225   ADDR_RANGE range;
226 #define PROFILE_RANGE(p) (& (p)->range)
227 } PROFILE_DATA;
228 \f
229 /* Predicates.  */
230
231 #define CPU_PROFILE_FLAGS(cpu) PROFILE_FLAGS (CPU_PROFILE_DATA (cpu))
232
233 /* Return non-zero if tracing of IDX is enabled for CPU.  */
234 #define PROFILE_P(cpu,idx) \
235 ((WITH_PROFILE & (1 << (idx))) != 0 \
236  && CPU_PROFILE_FLAGS (cpu)[idx] != 0)
237
238 /* Non-zero if --profile-<xxxx> was specified for CPU.  */
239 #define PROFILE_ANY_P(cpu)      ((WITH_PROFILE) && (CPU_PROFILE_DATA (cpu)->profile_any_p))
240 #define PROFILE_INSN_P(cpu)     PROFILE_P (cpu, PROFILE_INSN_IDX)
241 #define PROFILE_MEMORY_P(cpu)   PROFILE_P (cpu, PROFILE_MEMORY_IDX)
242 #define PROFILE_MODEL_P(cpu)    PROFILE_P (cpu, PROFILE_MODEL_IDX)
243 #define PROFILE_SCACHE_P(cpu)   PROFILE_P (cpu, PROFILE_SCACHE_IDX)
244 #define PROFILE_PC_P(cpu)       PROFILE_P (cpu, PROFILE_PC_IDX)
245 #define PROFILE_CORE_P(cpu)     PROFILE_P (cpu, PROFILE_CORE_IDX)
246 \f
247 /* Usage macros.  */
248
249 #if WITH_PROFILE_INSN_P
250 #define PROFILE_COUNT_INSN(cpu, pc, insn_num) \
251 do { \
252   if (PROFILE_INSN_P (cpu)) \
253     ++ PROFILE_INSN_COUNT (CPU_PROFILE_DATA (cpu)) [insn_num]; \
254 } while (0)
255 #else
256 #define PROFILE_COUNT_INSN(cpu, pc, insn_num)
257 #endif /* ! insn */
258
259 #if WITH_PROFILE_MEMORY_P
260 #define PROFILE_COUNT_READ(cpu, addr, mode_num) \
261 do { \
262   if (PROFILE_MEMORY_P (cpu)) \
263     ++ PROFILE_READ_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
264 } while (0)
265 #define PROFILE_COUNT_WRITE(cpu, addr, mode_num) \
266 do { \
267   if (PROFILE_MEMORY_P (cpu)) \
268     ++ PROFILE_WRITE_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
269 } while (0)
270 #else
271 #define PROFILE_COUNT_READ(cpu, addr, mode_num)
272 #define PROFILE_COUNT_WRITE(cpu, addr, mode_num)
273 #endif /* ! memory */
274
275 #if WITH_PROFILE_CORE_P
276 #define PROFILE_COUNT_CORE(cpu, addr, size, map) \
277 do { \
278   if (PROFILE_CORE_P (cpu)) \
279     PROFILE_CORE_COUNT (CPU_PROFILE_DATA (cpu)) [map] += 1; \
280 } while (0)
281 #else
282 #define PROFILE_COUNT_CORE(cpu, addr, size, map)
283 #endif /* ! core */
284
285 /* Misc. utilities.  */
286
287 extern void sim_profile_print_bar (SIM_DESC, unsigned int, unsigned int, unsigned int);
288
289 #endif /* SIM_PROFILE_H */