]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/sim-profile.h
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / sim / common / sim-profile.h
CommitLineData
0e701ac3
AC
1/* Profile header for simulators using common framework.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
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
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
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
17You should have received a copy of the GNU General Public License along
18with this program; if not, write to the Free Software Foundation, Inc.,
1959 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
25Error, WITH_PROFILE not defined.
26#endif
27
28/* Maximum number of profilable entities. */
29#ifndef MAX_PROFILE_VALUES
30#define MAX_PROFILE_VALUES 8
31#endif
32
33/* Standard profilable entities. */
34#define PROFILE_INSN_IDX 0
35#define PROFILE_MEMORY_IDX 1
36#define PROFILE_MODEL_IDX 2
37#define PROFILE_SCACHE_IDX 3
38#define PROFILE_PC_IDX 4
39#define PROFILE_CORE_IDX 5
40#define PROFILE_NEXT_IDX 6 /* simulator specific profile bits begin here */
41
42/* Masks so WITH_PROFILE can have symbolic values. */
43#define PROFILE_insn 1
44#define PROFILE_memory 2
45#define PROFILE_model 4
46#define PROFILE_scache 8
47#define PROFILE_pc 16
48#define PROFILE_core 32
49
50/* Preprocessor macros to simplify tests of WITH_PROFILE. */
51#define WITH_PROFILE_INSN_P (WITH_PROFILE & PROFILE_insn)
52#define WITH_PROFILE_MEMORY_P (WITH_PROFILE & PROFILE_memory)
53#define WITH_PROFILE_MODEL_P (WITH_PROFILE & PROFILE_model)
54#define WITH_PROFILE_SCACHE_P (WITH_PROFILE & PROFILE_scache)
55#define WITH_PROFILE_PC_P (WITH_PROFILE & PROFILE_pc)
56#define WITH_PROFILE_CORE_P (WITH_PROFILE & PROFILE_core)
57
58/* If MAX_INSNS isn't defined, we can't do instruction profiling.
59 ??? It is intended that this is a temporary occurence. Normally
60 MAX_INSNS is defined. */
61#ifndef MAX_INSNS
62#undef WITH_PROFILE_INSN_P
63#define WITH_PROFILE_INSN_P 0
64#endif
65
66/* If MAX_MODES isn't defined, we can't do memory profiling.
67 ??? It is intended that this is a temporary occurence. Normally
68 MAX_MODES is defined. */
69#ifndef MAX_MODES
70#undef WITH_PROFILE_MEMORY_P
71#define WITH_PROFILE_MEMORY_P 0
72#endif
73
74/* Only build MODEL code when the target simulator has support for it */
75#ifndef SIM_HAVE_MODEL
76#undef WITH_PROFILE_MODEL_P
77#define WITH_PROFILE_MODEL_P 0
78#endif
79
80/* Profiling install handler. */
81MODULE_INSTALL_FN profile_install;
82
83/* Output format macros. */
84#ifndef PROFILE_HISTOGRAM_WIDTH
85#define PROFILE_HISTOGRAM_WIDTH 40
86#endif
87#ifndef PROFILE_LABEL_WIDTH
88#define PROFILE_LABEL_WIDTH 32
89#endif
90\f
91/* Callbacks for internal profile_info.
92 The callbacks may be NULL meaning there isn't one.
93 Note that results are indented two spaces to distinguish them from
94 section titles.
95 If non-NULL, PROFILE_CALLBACK is called to print extra non-cpu related data.
96 If non-NULL, PROFILE_CPU_CALLBACK is called to print extra cpu related data.
97 */
98
99typedef void (PROFILE_INFO_CALLBACK_FN) (SIM_DESC, int);
100struct _sim_cpu; /* forward reference */
101typedef void (PROFILE_INFO_CPU_CALLBACK_FN) (struct _sim_cpu *cpu, int verbose);
102
103\f
104/* Struct containing most profiling data.
105 It doesn't contain all profiling data because for example scache data
106 is kept with the rest of scache support. */
107
108typedef struct {
109 /* Boolean array of specified profiling flags. */
110 char profile_flags[MAX_PROFILE_VALUES];
111#define PROFILE_FLAGS(p) ((p)->profile_flags)
112
113 /* The total insn count is tracked separately.
114 It is always computed, regardless of insn profiling. */
115 unsigned long total_insn_count;
116#define PROFILE_TOTAL_INSN_COUNT(p) ((p)->total_insn_count)
117
118 /* Execution time in milliseconds. */
119 unsigned long exec_time;
120#define PROFILE_EXEC_TIME(p) ((p)->exec_time)
121
122#if WITH_PROFILE_INSN_P
123 unsigned int insn_count[MAX_INSNS];
124#define PROFILE_INSN_COUNT(p) ((p)->insn_count)
125#endif
126
127#if WITH_PROFILE_MEMORY_P
128 unsigned int read_count[MAX_MODES];
129#define PROFILE_READ_COUNT(p) ((p)->read_count)
130 unsigned int write_count[MAX_MODES];
131#define PROFILE_WRITE_COUNT(p) ((p)->write_count)
132#endif
133
134#if WITH_PROFILE_CORE_P
135 /* Count read/write/exec accesses separatly. */
136 unsigned int core_count[nr_sim_core_maps];
137#define PROFILE_CORE_COUNT(p) ((p)->core_count)
138#endif
139
140#if WITH_PROFILE_MODEL_P
141 /* Total cycle count (less stalls). */
142 unsigned long cycle_count;
143#define PROFILE_MODEL_CYCLE_COUNT(p) ((p)->cycle_count)
144 /* Stalls due to branches. */
145 unsigned long cti_stall_count;
146#define PROFILE_MODEL_CTI_STALL_COUNT(p) ((p)->cti_stall_count)
147 unsigned long load_stall_count;
148#define PROFILE_MODEL_LOAD_STALL_COUNT(p) ((p)->load_stall_count)
149 /* Taken and not-taken branches (and other cti's). */
150#define PROFILE_TOTAL_CYCLE_COUNT(p) \
151(PROFILE_MODEL_CYCLE_COUNT(p) \
152 + PROFILE_MODEL_CTI_STALL_COUNT(p) \
153 + PROFILE_MODEL_LOAD_STALL_COUNT(p))
154
155 unsigned long taken_count, untaken_count;
156#define PROFILE_MODEL_TAKEN_COUNT(p) ((p)->taken_count)
157#define PROFILE_MODEL_UNTAKEN_COUNT(p) ((p)->untaken_count)
158#endif
159
160#if WITH_PROFILE_PC_P
161 /* PC profiling attempts to determine function usage by sampling the PC
162 every so many instructions. */
163 unsigned int profile_pc_freq;
164#define PROFILE_PC_FREQ(p) ((p)->profile_pc_freq)
165 unsigned int profile_pc_nr_buckets;
166#define PROFILE_PC_NR_BUCKETS(p) ((p)->profile_pc_nr_buckets)
167 address_word profile_pc_start;
168#define PROFILE_PC_START(p) ((p)->profile_pc_start)
169 address_word profile_pc_end;
170#define PROFILE_PC_END(p) ((p)->profile_pc_end)
171 unsigned profile_pc_shift;
172#define PROFILE_PC_SHIFT(p) ((p)->profile_pc_shift)
173#define PROFILE_PC_BUCKET_SIZE(p) (PROFILE_PC_SHIFT (p) ? (1 << PROFILE_PC_SHIFT (p)) : 0)
174 unsigned *profile_pc_count;
175#define PROFILE_PC_COUNT(p) ((p)->profile_pc_count)
176 sim_event *profile_pc_event;
177#define PROFILE_PC_EVENT(p) ((p)->profile_pc_event)
178#endif
179
180 /* Profile output goes to this or stderr if NULL.
181 We can't store `stderr' here as stderr goes through a callback. */
182 FILE *profile_file;
183#define PROFILE_FILE(p) ((p)->profile_file)
184
185 /* When reporting a profile summary, hook to include per-processor
186 target specific profile information */
187 PROFILE_INFO_CPU_CALLBACK_FN *info_cpu_callback;
188#define PROFILE_INFO_CPU_CALLBACK(p) ((p)->info_cpu_callback)
189
190 /* When reporting a profile summary, hook to include common target
191 specific profile information */
192 PROFILE_INFO_CALLBACK_FN *info_callback;
193#define STATE_PROFILE_INFO_CALLBACK(sd) \
194(CPU_PROFILE_DATA (STATE_CPU (sd, 0))->info_callback)
195
196} PROFILE_DATA;
197\f
198/* Usage macros. */
199
200#define CPU_PROFILE_FLAGS(cpu) PROFILE_FLAGS (CPU_PROFILE_DATA (cpu))
201
202#if WITH_PROFILE_INSN_P
203#define PROFILE_COUNT_INSN(cpu, pc, insn_num) \
204do { \
205 if (CPU_PROFILE_FLAGS (cpu) [PROFILE_INSN_IDX]) \
206 ++ PROFILE_INSN_COUNT (CPU_PROFILE_DATA (cpu)) [insn_num]; \
207} while (0)
208#else
209#define PROFILE_COUNT_INSN(cpu, pc, insn_num)
210#endif /* ! insn */
211
212#if WITH_PROFILE_MEMORY_P
213#define PROFILE_COUNT_READ(cpu, addr, mode_num) \
214do { \
215 if (CPU_PROFILE_FLAGS (cpu) [PROFILE_MEMORY_IDX]) \
216 ++ PROFILE_READ_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
217} while (0)
218#define PROFILE_COUNT_WRITE(cpu, addr, mode_num) \
219do { \
220 if (CPU_PROFILE_FLAGS (cpu) [PROFILE_MEMORY_IDX]) \
221 ++ PROFILE_WRITE_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
222} while (0)
223#else
224#define PROFILE_COUNT_READ(cpu, addr, mode_num)
225#define PROFILE_COUNT_WRITE(cpu, addr, mode_num)
226#endif /* ! memory */
227
228#if WITH_PROFILE_CORE_P
229#define PROFILE_COUNT_CORE(cpu, addr, size, map) \
230do { \
231 if (CPU_PROFILE_FLAGS (cpu) [PROFILE_CORE_IDX]) \
232 PROFILE_CORE_COUNT (CPU_PROFILE_DATA (cpu)) [map] += 1; \
233} while (0)
234#else
235#define PROFILE_COUNT_CORE(cpu, addr, size, map)
236#endif /* ! core */
237
238#if WITH_PROFILE_MODEL_P
239/* Model profiling is a bit more complicated so we just provide a macro
240 to say whether to do it or not. */
241#define PROFILE_MODEL_P(cpu) \
242(CPU_PROFILE_FLAGS (cpu) [PROFILE_MODEL_IDX])
243#else
244#define PROFILE_MODEL_P(cpu) 0
245#endif /* ! model */
246
247#endif /* SIM_PROFILE_H */