Update copyright year range in all GDB files.
[deliverable/binutils-gdb.git] / sim / common / sim-profile.h
CommitLineData
c906108c 1/* Profile header for simulators using common framework.
b811d2c2 2 Copyright (C) 1996-2020 Free Software Foundation, Inc.
c906108c
SS
3 Contributed by Cygnus Support.
4
5This file is part of GDB, the GNU debugger.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
4744ac1b
JB
9the Free Software Foundation; either version 3 of the License, or
10(at your option) any later version.
c906108c
SS
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
4744ac1b
JB
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#ifndef SIM_PROFILE_H
21#define SIM_PROFILE_H
22
23#ifndef WITH_PROFILE
24Error, WITH_PROFILE not defined.
25#endif
26
27/* Standard profilable entities. */
28
29enum {
30 /* Profile insn usage. */
31 PROFILE_INSN_IDX = 1,
32
33 /* Profile memory usage. */
34 PROFILE_MEMORY_IDX,
35
36 /* Profile the cpu model (cycles, etc.). */
37 PROFILE_MODEL_IDX,
38
39 /* Profile the simulator's execution cache. */
40 PROFILE_SCACHE_IDX,
41
42 /* Profile the PC. */
43 PROFILE_PC_IDX,
44
45 /* Profile sim-core.c stuff. */
46 /* ??? The difference between this and PROFILE_MEMORY_IDX is ... ? */
47 PROFILE_CORE_IDX,
48
49 /* Simulator specific profile bits begin here. */
50 PROFILE_NEXT_IDX
51};
52
53/* Maximum number of profilable entities. */
54#ifndef MAX_PROFILE_VALUES
55#define MAX_PROFILE_VALUES 32
56#endif
57
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
60 find. */
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))
66
ed9a39eb
JM
67/* Utility to set profile options. */
68SIM_RC set_profile_option_mask (SIM_DESC sd_, const char *name_, int mask_,
69 const char *arg_);
70
c906108c
SS
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
74 source is cleaner. */
75
76SIM_RC sim_profile_set_option (SIM_DESC sd_, const char *name_, int idx_,
77 const char *arg_);
78\f
79/* Masks so WITH_PROFILE can have symbolic values.
80 The case choice here is on purpose. The lowercase parts are args to
81 --with-profile. */
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)
88
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)
96
97/* If MAX_TARGET_MODES isn't defined, we can't do memory profiling.
6439295f 98 ??? It is intended that this is a temporary occurrence. Normally
c906108c
SS
99 MAX_TARGET_MODES is defined. */
100#ifndef MAX_TARGET_MODES
101#undef WITH_PROFILE_MEMORY_P
102#define WITH_PROFILE_MEMORY_P 0
103#endif
104
c906108c
SS
105/* Profiling install handler. */
106MODULE_INSTALL_FN profile_install;
107
108/* Output format macros. */
109#ifndef PROFILE_HISTOGRAM_WIDTH
110#define PROFILE_HISTOGRAM_WIDTH 40
111#endif
112#ifndef PROFILE_LABEL_WIDTH
113#define PROFILE_LABEL_WIDTH 32
114#endif
115\f
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
119 section titles.
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.
122 */
123
124typedef void (PROFILE_INFO_CALLBACK_FN) (SIM_DESC, int);
125struct _sim_cpu; /* forward reference */
126typedef void (PROFILE_INFO_CPU_CALLBACK_FN) (struct _sim_cpu *cpu, int verbose);
127
128\f
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. */
132
133typedef struct {
134 /* Global summary of all the current profiling options. */
135 char profile_any_p;
136
137 /* Boolean array of specified profiling flags. */
138 char profile_flags[MAX_PROFILE_VALUES];
139#define PROFILE_FLAGS(p) ((p)->profile_flags)
140
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)
145
09032128
DB
146 /* CPU frequency. Always accepted, regardless of profiling options. */
147 unsigned long cpu_freq;
148#define PROFILE_CPU_FREQ(p) ((p)->cpu_freq)
149
c906108c
SS
150#if WITH_PROFILE_INSN_P
151 unsigned int *insn_count;
152#define PROFILE_INSN_COUNT(p) ((p)->insn_count)
153#endif
154
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)
160#endif
161
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)
166#endif
167
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)
181
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)
186#endif
187
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)
206#endif
207
208 /* Profile output goes to this or stderr if NULL.
209 We can't store `stderr' here as stderr goes through a callback. */
210 FILE *profile_file;
211#define PROFILE_FILE(p) ((p)->profile_file)
212
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)
217
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)
223
224 /* Profile range.
225 ??? Not all cpu's support this. */
226 ADDR_RANGE range;
227#define PROFILE_RANGE(p) (& (p)->range)
228} PROFILE_DATA;
229\f
230/* Predicates. */
231
232#define CPU_PROFILE_FLAGS(cpu) PROFILE_FLAGS (CPU_PROFILE_DATA (cpu))
233
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)
238
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)
247\f
248/* Usage macros. */
249
250#if WITH_PROFILE_INSN_P
251#define PROFILE_COUNT_INSN(cpu, pc, insn_num) \
252do { \
253 if (PROFILE_INSN_P (cpu)) \
254 ++ PROFILE_INSN_COUNT (CPU_PROFILE_DATA (cpu)) [insn_num]; \
255} while (0)
256#else
257#define PROFILE_COUNT_INSN(cpu, pc, insn_num)
258#endif /* ! insn */
259
260#if WITH_PROFILE_MEMORY_P
261#define PROFILE_COUNT_READ(cpu, addr, mode_num) \
262do { \
263 if (PROFILE_MEMORY_P (cpu)) \
264 ++ PROFILE_READ_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
265} while (0)
266#define PROFILE_COUNT_WRITE(cpu, addr, mode_num) \
267do { \
268 if (PROFILE_MEMORY_P (cpu)) \
269 ++ PROFILE_WRITE_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
270} while (0)
271#else
272#define PROFILE_COUNT_READ(cpu, addr, mode_num)
273#define PROFILE_COUNT_WRITE(cpu, addr, mode_num)
274#endif /* ! memory */
275
276#if WITH_PROFILE_CORE_P
277#define PROFILE_COUNT_CORE(cpu, addr, size, map) \
278do { \
279 if (PROFILE_CORE_P (cpu)) \
280 PROFILE_CORE_COUNT (CPU_PROFILE_DATA (cpu)) [map] += 1; \
281} while (0)
282#else
283#define PROFILE_COUNT_CORE(cpu, addr, size, map)
284#endif /* ! core */
285
58f03a40
MF
286#if WITH_PROFILE_MODEL_P
287#define PROFILE_BRANCH_TAKEN(cpu) \
288do { \
289 if (PROFILE_MODEL_P (cpu)) \
290 ++ PROFILE_MODEL_TAKEN_COUNT (CPU_PROFILE_DATA (cpu)); \
291} while (0)
292#define PROFILE_BRANCH_UNTAKEN(cpu) \
293do { \
294 if (PROFILE_MODEL_P (cpu)) \
295 ++ PROFILE_MODEL_UNTAKEN_COUNT (CPU_PROFILE_DATA (cpu)); \
296} while (0)
297#else
298#define PROFILE_BRANCH_TAKEN(cpu)
299#define PROFILE_BRANCH_UNTAKEN(cpu)
300#endif /* ! model */
301
c906108c
SS
302/* Misc. utilities. */
303
f093db8c 304extern void sim_profile_print_bar (SIM_DESC, sim_cpu *, unsigned int, unsigned int, unsigned int);
c906108c
SS
305
306#endif /* SIM_PROFILE_H */
This page took 0.846475 seconds and 4 git commands to generate.