1 /* Profile header for simulators using common framework.
2 Copyright (C) 1996-2019 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 3 of the License, or
10 (at your option) any later version.
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
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 Error
, WITH_PROFILE
not defined
.
27 /* Standard profilable entities. */
30 /* Profile insn usage. */
33 /* Profile memory usage. */
36 /* Profile the cpu model (cycles, etc.). */
39 /* Profile the simulator's execution cache. */
45 /* Profile sim-core.c stuff. */
46 /* ??? The difference between this and PROFILE_MEMORY_IDX is ... ? */
49 /* Simulator specific profile bits begin here. */
53 /* Maximum number of profilable entities. */
54 #ifndef MAX_PROFILE_VALUES
55 #define MAX_PROFILE_VALUES 32
58 /* The -p option only prints useful values. It's easy to type and shouldn't
59 splat on the screen everything under the sun making nothing easy to
61 #define PROFILE_USEFUL_MASK \
62 ((1 << PROFILE_INSN_IDX) \
63 | (1 << PROFILE_MEMORY_IDX) \
64 | (1 << PROFILE_MODEL_IDX) \
65 | (1 << PROFILE_CORE_IDX))
67 /* Utility to set profile options. */
68 SIM_RC
set_profile_option_mask (SIM_DESC sd_
, const char *name_
, int mask_
,
71 /* Utility to parse a --profile-<foo> option. */
72 /* ??? On the one hand all calls could be confined to sim-profile.c, but
73 on the other hand keeping a module's profiling option with the module's
76 SIM_RC
sim_profile_set_option (SIM_DESC sd_
, const char *name_
, int idx_
,
79 /* Masks so WITH_PROFILE can have symbolic values.
80 The case choice here is on purpose. The lowercase parts are args to
82 #define PROFILE_insn (1 << PROFILE_INSN_IDX)
83 #define PROFILE_memory (1 << PROFILE_MEMORY_IDX)
84 #define PROFILE_model (1 << PROFILE_MODEL_IDX)
85 #define PROFILE_scache (1 << PROFILE_SCACHE_IDX)
86 #define PROFILE_pc (1 << PROFILE_PC_IDX)
87 #define PROFILE_core (1 << PROFILE_CORE_IDX)
89 /* Preprocessor macros to simplify tests of WITH_PROFILE. */
90 #define WITH_PROFILE_INSN_P (WITH_PROFILE & PROFILE_insn)
91 #define WITH_PROFILE_MEMORY_P (WITH_PROFILE & PROFILE_memory)
92 #define WITH_PROFILE_MODEL_P (WITH_PROFILE & PROFILE_model)
93 #define WITH_PROFILE_SCACHE_P (WITH_PROFILE & PROFILE_scache)
94 #define WITH_PROFILE_PC_P (WITH_PROFILE & PROFILE_pc)
95 #define WITH_PROFILE_CORE_P (WITH_PROFILE & PROFILE_core)
97 /* If MAX_TARGET_MODES isn't defined, we can't do memory profiling.
98 ??? It is intended that this is a temporary occurrence. Normally
99 MAX_TARGET_MODES is defined. */
100 #ifndef MAX_TARGET_MODES
101 #undef WITH_PROFILE_MEMORY_P
102 #define WITH_PROFILE_MEMORY_P 0
105 /* Profiling install handler. */
106 MODULE_INSTALL_FN profile_install
;
108 /* Output format macros. */
109 #ifndef PROFILE_HISTOGRAM_WIDTH
110 #define PROFILE_HISTOGRAM_WIDTH 40
112 #ifndef PROFILE_LABEL_WIDTH
113 #define PROFILE_LABEL_WIDTH 32
116 /* Callbacks for internal profile_info.
117 The callbacks may be NULL meaning there isn't one.
118 Note that results are indented two spaces to distinguish them from
120 If non-NULL, PROFILE_CALLBACK is called to print extra non-cpu related data.
121 If non-NULL, PROFILE_CPU_CALLBACK is called to print extra cpu related data.
124 typedef void (PROFILE_INFO_CALLBACK_FN
) (SIM_DESC
, int);
125 struct _sim_cpu
; /* forward reference */
126 typedef void (PROFILE_INFO_CPU_CALLBACK_FN
) (struct _sim_cpu
*cpu
, int verbose
);
129 /* Struct containing most profiling data.
130 It doesn't contain all profiling data because for example scache data
131 is kept with the rest of scache support. */
134 /* Global summary of all the current profiling options. */
137 /* Boolean array of specified profiling flags. */
138 char profile_flags
[MAX_PROFILE_VALUES
];
139 #define PROFILE_FLAGS(p) ((p)->profile_flags)
141 /* The total insn count is tracked separately.
142 It is always computed, regardless of insn profiling. */
143 unsigned long total_insn_count
;
144 #define PROFILE_TOTAL_INSN_COUNT(p) ((p)->total_insn_count)
146 /* CPU frequency. Always accepted, regardless of profiling options. */
147 unsigned long cpu_freq
;
148 #define PROFILE_CPU_FREQ(p) ((p)->cpu_freq)
150 #if WITH_PROFILE_INSN_P
151 unsigned int *insn_count
;
152 #define PROFILE_INSN_COUNT(p) ((p)->insn_count)
155 #if WITH_PROFILE_MEMORY_P
156 unsigned int read_count
[MAX_TARGET_MODES
];
157 #define PROFILE_READ_COUNT(p) ((p)->read_count)
158 unsigned int write_count
[MAX_TARGET_MODES
];
159 #define PROFILE_WRITE_COUNT(p) ((p)->write_count)
162 #if WITH_PROFILE_CORE_P
163 /* Count read/write/exec accesses separatly. */
164 unsigned int core_count
[nr_maps
];
165 #define PROFILE_CORE_COUNT(p) ((p)->core_count)
168 #if WITH_PROFILE_MODEL_P
169 /* ??? Quick hack until more elaborate scheme is finished. */
170 /* Total cycle count, including stalls. */
171 unsigned long total_cycles
;
172 #define PROFILE_MODEL_TOTAL_CYCLES(p) ((p)->total_cycles)
173 /* Stalls due to branches. */
174 unsigned long cti_stall_cycles
;
175 #define PROFILE_MODEL_CTI_STALL_CYCLES(p) ((p)->cti_stall_cycles)
176 unsigned long load_stall_cycles
;
177 #define PROFILE_MODEL_LOAD_STALL_CYCLES(p) ((p)->load_stall_cycles)
178 /* Number of cycles the current instruction took. */
179 unsigned long cur_insn_cycles
;
180 #define PROFILE_MODEL_CUR_INSN_CYCLES(p) ((p)->cur_insn_cycles)
182 /* Taken and not-taken branches (and other cti's). */
183 unsigned long taken_count
, untaken_count
;
184 #define PROFILE_MODEL_TAKEN_COUNT(p) ((p)->taken_count)
185 #define PROFILE_MODEL_UNTAKEN_COUNT(p) ((p)->untaken_count)
188 #if WITH_PROFILE_PC_P
189 /* PC profiling attempts to determine function usage by sampling the PC
190 every so many instructions. */
191 unsigned int profile_pc_freq
;
192 #define PROFILE_PC_FREQ(p) ((p)->profile_pc_freq)
193 unsigned int profile_pc_nr_buckets
;
194 #define PROFILE_PC_NR_BUCKETS(p) ((p)->profile_pc_nr_buckets)
195 address_word profile_pc_start
;
196 #define PROFILE_PC_START(p) ((p)->profile_pc_start)
197 address_word profile_pc_end
;
198 #define PROFILE_PC_END(p) ((p)->profile_pc_end)
199 unsigned profile_pc_shift
;
200 #define PROFILE_PC_SHIFT(p) ((p)->profile_pc_shift)
201 #define PROFILE_PC_BUCKET_SIZE(p) (PROFILE_PC_SHIFT (p) ? (1 << PROFILE_PC_SHIFT (p)) : 0)
202 unsigned *profile_pc_count
;
203 #define PROFILE_PC_COUNT(p) ((p)->profile_pc_count)
204 sim_event
*profile_pc_event
;
205 #define PROFILE_PC_EVENT(p) ((p)->profile_pc_event)
208 /* Profile output goes to this or stderr if NULL.
209 We can't store `stderr' here as stderr goes through a callback. */
211 #define PROFILE_FILE(p) ((p)->profile_file)
213 /* When reporting a profile summary, hook to include per-processor
214 target specific profile information */
215 PROFILE_INFO_CPU_CALLBACK_FN
*info_cpu_callback
;
216 #define PROFILE_INFO_CPU_CALLBACK(p) ((p)->info_cpu_callback)
218 /* When reporting a profile summary, hook to include common target
219 specific profile information */
220 PROFILE_INFO_CALLBACK_FN
*info_callback
;
221 #define STATE_PROFILE_INFO_CALLBACK(sd) \
222 (CPU_PROFILE_DATA (STATE_CPU (sd, 0))->info_callback)
225 ??? Not all cpu's support this. */
227 #define PROFILE_RANGE(p) (& (p)->range)
232 #define CPU_PROFILE_FLAGS(cpu) PROFILE_FLAGS (CPU_PROFILE_DATA (cpu))
234 /* Return non-zero if tracing of IDX is enabled for CPU. */
235 #define PROFILE_P(cpu,idx) \
236 ((WITH_PROFILE & (1 << (idx))) != 0 \
237 && CPU_PROFILE_FLAGS (cpu)[idx] != 0)
239 /* Non-zero if --profile-<xxxx> was specified for CPU. */
240 #define PROFILE_ANY_P(cpu) ((WITH_PROFILE) && (CPU_PROFILE_DATA (cpu)->profile_any_p))
241 #define PROFILE_INSN_P(cpu) PROFILE_P (cpu, PROFILE_INSN_IDX)
242 #define PROFILE_MEMORY_P(cpu) PROFILE_P (cpu, PROFILE_MEMORY_IDX)
243 #define PROFILE_MODEL_P(cpu) PROFILE_P (cpu, PROFILE_MODEL_IDX)
244 #define PROFILE_SCACHE_P(cpu) PROFILE_P (cpu, PROFILE_SCACHE_IDX)
245 #define PROFILE_PC_P(cpu) PROFILE_P (cpu, PROFILE_PC_IDX)
246 #define PROFILE_CORE_P(cpu) PROFILE_P (cpu, PROFILE_CORE_IDX)
250 #if WITH_PROFILE_INSN_P
251 #define PROFILE_COUNT_INSN(cpu, pc, insn_num) \
253 if (PROFILE_INSN_P (cpu)) \
254 ++ PROFILE_INSN_COUNT (CPU_PROFILE_DATA (cpu)) [insn_num]; \
257 #define PROFILE_COUNT_INSN(cpu, pc, insn_num)
260 #if WITH_PROFILE_MEMORY_P
261 #define PROFILE_COUNT_READ(cpu, addr, mode_num) \
263 if (PROFILE_MEMORY_P (cpu)) \
264 ++ PROFILE_READ_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
266 #define PROFILE_COUNT_WRITE(cpu, addr, mode_num) \
268 if (PROFILE_MEMORY_P (cpu)) \
269 ++ PROFILE_WRITE_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
272 #define PROFILE_COUNT_READ(cpu, addr, mode_num)
273 #define PROFILE_COUNT_WRITE(cpu, addr, mode_num)
274 #endif /* ! memory */
276 #if WITH_PROFILE_CORE_P
277 #define PROFILE_COUNT_CORE(cpu, addr, size, map) \
279 if (PROFILE_CORE_P (cpu)) \
280 PROFILE_CORE_COUNT (CPU_PROFILE_DATA (cpu)) [map] += 1; \
283 #define PROFILE_COUNT_CORE(cpu, addr, size, map)
286 #if WITH_PROFILE_MODEL_P
287 #define PROFILE_BRANCH_TAKEN(cpu) \
289 if (PROFILE_MODEL_P (cpu)) \
290 ++ PROFILE_MODEL_TAKEN_COUNT (CPU_PROFILE_DATA (cpu)); \
292 #define PROFILE_BRANCH_UNTAKEN(cpu) \
294 if (PROFILE_MODEL_P (cpu)) \
295 ++ PROFILE_MODEL_UNTAKEN_COUNT (CPU_PROFILE_DATA (cpu)); \
298 #define PROFILE_BRANCH_TAKEN(cpu)
299 #define PROFILE_BRANCH_UNTAKEN(cpu)
302 /* Misc. utilities. */
304 extern void sim_profile_print_bar (SIM_DESC
, sim_cpu
*, unsigned int, unsigned int, unsigned int);
306 #endif /* SIM_PROFILE_H */