1 /* Profile header for simulators using common framework.
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
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)
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.
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. */
25 Error, WITH_PROFILE not defined.
28 /* Standard profilable entities. */
31 /* Profile insn usage. */
34 /* Profile memory usage. */
37 /* Profile the cpu model (cycles, etc.). */
40 /* Profile the simulator's execution cache. */
46 /* Profile sim-core.c stuff. */
47 /* ??? The difference between this and PROFILE_MEMORY_IDX is ... ? */
50 /* Simulator specific profile bits begin here. */
54 /* Maximum number of profilable entities. */
55 #ifndef MAX_PROFILE_VALUES
56 #define MAX_PROFILE_VALUES 32
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
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))
68 /* Utility to set profile options. */
69 SIM_RC set_profile_option_mask (SIM_DESC sd_, const char *name_, int mask_,
72 /* Utility to parse a --profile-<foo> option. */
73 /* ??? On the one hand all calls could be confined to sim-profile.c, but
74 on the other hand keeping a module's profiling option with the module's
77 SIM_RC sim_profile_set_option (SIM_DESC sd_, const char *name_, int idx_,
80 /* Masks so WITH_PROFILE can have symbolic values.
81 The case choice here is on purpose. The lowercase parts are args to
83 #define PROFILE_insn (1 << PROFILE_INSN_IDX)
84 #define PROFILE_memory (1 << PROFILE_MEMORY_IDX)
85 #define PROFILE_model (1 << PROFILE_MODEL_IDX)
86 #define PROFILE_scache (1 << PROFILE_SCACHE_IDX)
87 #define PROFILE_pc (1 << PROFILE_PC_IDX)
88 #define PROFILE_core (1 << PROFILE_CORE_IDX)
90 /* Preprocessor macros to simplify tests of WITH_PROFILE. */
91 #define WITH_PROFILE_INSN_P (WITH_PROFILE & PROFILE_insn)
92 #define WITH_PROFILE_MEMORY_P (WITH_PROFILE & PROFILE_memory)
93 #define WITH_PROFILE_MODEL_P (WITH_PROFILE & PROFILE_model)
94 #define WITH_PROFILE_SCACHE_P (WITH_PROFILE & PROFILE_scache)
95 #define WITH_PROFILE_PC_P (WITH_PROFILE & PROFILE_pc)
96 #define WITH_PROFILE_CORE_P (WITH_PROFILE & PROFILE_core)
98 /* If MAX_TARGET_MODES isn't defined, we can't do memory profiling.
99 ??? It is intended that this is a temporary occurence. Normally
100 MAX_TARGET_MODES is defined. */
101 #ifndef MAX_TARGET_MODES
102 #undef WITH_PROFILE_MEMORY_P
103 #define WITH_PROFILE_MEMORY_P 0
106 /* Only build MODEL code when the target simulator has support for it */
107 #ifndef SIM_HAVE_MODEL
108 #undef WITH_PROFILE_MODEL_P
109 #define WITH_PROFILE_MODEL_P 0
112 /* Profiling install handler. */
113 MODULE_INSTALL_FN profile_install;
115 /* Output format macros. */
116 #ifndef PROFILE_HISTOGRAM_WIDTH
117 #define PROFILE_HISTOGRAM_WIDTH 40
119 #ifndef PROFILE_LABEL_WIDTH
120 #define PROFILE_LABEL_WIDTH 32
123 /* Callbacks for internal profile_info.
124 The callbacks may be NULL meaning there isn't one.
125 Note that results are indented two spaces to distinguish them from
127 If non-NULL, PROFILE_CALLBACK is called to print extra non-cpu related data.
128 If non-NULL, PROFILE_CPU_CALLBACK is called to print extra cpu related data.
131 typedef void (PROFILE_INFO_CALLBACK_FN) (SIM_DESC, int);
132 struct _sim_cpu; /* forward reference */
133 typedef void (PROFILE_INFO_CPU_CALLBACK_FN) (struct _sim_cpu *cpu, int verbose);
136 /* Struct containing most profiling data.
137 It doesn't contain all profiling data because for example scache data
138 is kept with the rest of scache support. */
141 /* Global summary of all the current profiling options. */
144 /* Boolean array of specified profiling flags. */
145 char profile_flags[MAX_PROFILE_VALUES];
146 #define PROFILE_FLAGS(p) ((p)->profile_flags)
148 /* The total insn count is tracked separately.
149 It is always computed, regardless of insn profiling. */
150 unsigned long total_insn_count;
151 #define PROFILE_TOTAL_INSN_COUNT(p) ((p)->total_insn_count)
153 /* CPU frequency. Always accepted, regardless of profiling options. */
154 unsigned long cpu_freq;
155 #define PROFILE_CPU_FREQ(p) ((p)->cpu_freq)
157 #if WITH_PROFILE_INSN_P
158 unsigned int *insn_count;
159 #define PROFILE_INSN_COUNT(p) ((p)->insn_count)
162 #if WITH_PROFILE_MEMORY_P
163 unsigned int read_count[MAX_TARGET_MODES];
164 #define PROFILE_READ_COUNT(p) ((p)->read_count)
165 unsigned int write_count[MAX_TARGET_MODES];
166 #define PROFILE_WRITE_COUNT(p) ((p)->write_count)
169 #if WITH_PROFILE_CORE_P
170 /* Count read/write/exec accesses separatly. */
171 unsigned int core_count[nr_maps];
172 #define PROFILE_CORE_COUNT(p) ((p)->core_count)
175 #if WITH_PROFILE_MODEL_P
176 /* ??? Quick hack until more elaborate scheme is finished. */
177 /* Total cycle count, including stalls. */
178 unsigned long total_cycles;
179 #define PROFILE_MODEL_TOTAL_CYCLES(p) ((p)->total_cycles)
180 /* Stalls due to branches. */
181 unsigned long cti_stall_cycles;
182 #define PROFILE_MODEL_CTI_STALL_CYCLES(p) ((p)->cti_stall_cycles)
183 unsigned long load_stall_cycles;
184 #define PROFILE_MODEL_LOAD_STALL_CYCLES(p) ((p)->load_stall_cycles)
185 /* Number of cycles the current instruction took. */
186 unsigned long cur_insn_cycles;
187 #define PROFILE_MODEL_CUR_INSN_CYCLES(p) ((p)->cur_insn_cycles)
189 /* Taken and not-taken branches (and other cti's). */
190 unsigned long taken_count, untaken_count;
191 #define PROFILE_MODEL_TAKEN_COUNT(p) ((p)->taken_count)
192 #define PROFILE_MODEL_UNTAKEN_COUNT(p) ((p)->untaken_count)
195 #if WITH_PROFILE_PC_P
196 /* PC profiling attempts to determine function usage by sampling the PC
197 every so many instructions. */
198 unsigned int profile_pc_freq;
199 #define PROFILE_PC_FREQ(p) ((p)->profile_pc_freq)
200 unsigned int profile_pc_nr_buckets;
201 #define PROFILE_PC_NR_BUCKETS(p) ((p)->profile_pc_nr_buckets)
202 address_word profile_pc_start;
203 #define PROFILE_PC_START(p) ((p)->profile_pc_start)
204 address_word profile_pc_end;
205 #define PROFILE_PC_END(p) ((p)->profile_pc_end)
206 unsigned profile_pc_shift;
207 #define PROFILE_PC_SHIFT(p) ((p)->profile_pc_shift)
208 #define PROFILE_PC_BUCKET_SIZE(p) (PROFILE_PC_SHIFT (p) ? (1 << PROFILE_PC_SHIFT (p)) : 0)
209 unsigned *profile_pc_count;
210 #define PROFILE_PC_COUNT(p) ((p)->profile_pc_count)
211 sim_event *profile_pc_event;
212 #define PROFILE_PC_EVENT(p) ((p)->profile_pc_event)
215 /* Profile output goes to this or stderr if NULL.
216 We can't store `stderr' here as stderr goes through a callback. */
218 #define PROFILE_FILE(p) ((p)->profile_file)
220 /* When reporting a profile summary, hook to include per-processor
221 target specific profile information */
222 PROFILE_INFO_CPU_CALLBACK_FN *info_cpu_callback;
223 #define PROFILE_INFO_CPU_CALLBACK(p) ((p)->info_cpu_callback)
225 /* When reporting a profile summary, hook to include common target
226 specific profile information */
227 PROFILE_INFO_CALLBACK_FN *info_callback;
228 #define STATE_PROFILE_INFO_CALLBACK(sd) \
229 (CPU_PROFILE_DATA (STATE_CPU (sd, 0))->info_callback)
232 ??? Not all cpu's support this. */
234 #define PROFILE_RANGE(p) (& (p)->range)
239 #define CPU_PROFILE_FLAGS(cpu) PROFILE_FLAGS (CPU_PROFILE_DATA (cpu))
241 /* Return non-zero if tracing of IDX is enabled for CPU. */
242 #define PROFILE_P(cpu,idx) \
243 ((WITH_PROFILE & (1 << (idx))) != 0 \
244 && CPU_PROFILE_FLAGS (cpu)[idx] != 0)
246 /* Non-zero if --profile-<xxxx> was specified for CPU. */
247 #define PROFILE_ANY_P(cpu) ((WITH_PROFILE) && (CPU_PROFILE_DATA (cpu)->profile_any_p))
248 #define PROFILE_INSN_P(cpu) PROFILE_P (cpu, PROFILE_INSN_IDX)
249 #define PROFILE_MEMORY_P(cpu) PROFILE_P (cpu, PROFILE_MEMORY_IDX)
250 #define PROFILE_MODEL_P(cpu) PROFILE_P (cpu, PROFILE_MODEL_IDX)
251 #define PROFILE_SCACHE_P(cpu) PROFILE_P (cpu, PROFILE_SCACHE_IDX)
252 #define PROFILE_PC_P(cpu) PROFILE_P (cpu, PROFILE_PC_IDX)
253 #define PROFILE_CORE_P(cpu) PROFILE_P (cpu, PROFILE_CORE_IDX)
257 #if WITH_PROFILE_INSN_P
258 #define PROFILE_COUNT_INSN(cpu, pc, insn_num) \
260 if (PROFILE_INSN_P (cpu)) \
261 ++ PROFILE_INSN_COUNT (CPU_PROFILE_DATA (cpu)) [insn_num]; \
264 #define PROFILE_COUNT_INSN(cpu, pc, insn_num)
267 #if WITH_PROFILE_MEMORY_P
268 #define PROFILE_COUNT_READ(cpu, addr, mode_num) \
270 if (PROFILE_MEMORY_P (cpu)) \
271 ++ PROFILE_READ_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
273 #define PROFILE_COUNT_WRITE(cpu, addr, mode_num) \
275 if (PROFILE_MEMORY_P (cpu)) \
276 ++ PROFILE_WRITE_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
279 #define PROFILE_COUNT_READ(cpu, addr, mode_num)
280 #define PROFILE_COUNT_WRITE(cpu, addr, mode_num)
281 #endif /* ! memory */
283 #if WITH_PROFILE_CORE_P
284 #define PROFILE_COUNT_CORE(cpu, addr, size, map) \
286 if (PROFILE_CORE_P (cpu)) \
287 PROFILE_CORE_COUNT (CPU_PROFILE_DATA (cpu)) [map] += 1; \
290 #define PROFILE_COUNT_CORE(cpu, addr, size, map)
293 /* Misc. utilities. */
295 extern void sim_profile_print_bar (SIM_DESC, unsigned int, unsigned int, unsigned int);
297 #endif /* SIM_PROFILE_H */