OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [sim/] [common/] [sim-profile.h] - Blame information for rev 481

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
/* Profile header for simulators using common framework.
2
   Copyright (C) 1996, 1997, 1998, 2007, 2008 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 3 of the License, or
10
(at your option) 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
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
 
20
#ifndef SIM_PROFILE_H
21
#define SIM_PROFILE_H
22
 
23
#ifndef WITH_PROFILE
24
Error, WITH_PROFILE not defined.
25
#endif
26
 
27
/* Standard profilable entities.  */
28
 
29
enum {
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
 
67
/* Utility to set profile options.  */
68
SIM_RC set_profile_option_mask (SIM_DESC sd_, const char *name_, int mask_,
69
                                const char *arg_);
70
 
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
 
76
SIM_RC sim_profile_set_option (SIM_DESC sd_, const char *name_, int idx_,
77
                               const char *arg_);
78
 
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.
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
103
#endif
104
 
105
/* Only build MODEL code when the target simulator has support for it */
106
#ifndef SIM_HAVE_MODEL
107
#undef WITH_PROFILE_MODEL_P
108
#define WITH_PROFILE_MODEL_P 0
109
#endif
110
 
111
/* Profiling install handler.  */
112
MODULE_INSTALL_FN profile_install;
113
 
114
/* Output format macros.  */
115
#ifndef PROFILE_HISTOGRAM_WIDTH
116
#define PROFILE_HISTOGRAM_WIDTH 40
117
#endif
118
#ifndef PROFILE_LABEL_WIDTH
119
#define PROFILE_LABEL_WIDTH 32
120
#endif
121
 
122
/* Callbacks for internal profile_info.
123
   The callbacks may be NULL meaning there isn't one.
124
   Note that results are indented two spaces to distinguish them from
125
   section titles.
126
   If non-NULL, PROFILE_CALLBACK is called to print extra non-cpu related data.
127
   If non-NULL, PROFILE_CPU_CALLBACK is called to print extra cpu related data.
128
   */
129
 
130
typedef void (PROFILE_INFO_CALLBACK_FN) (SIM_DESC, int);
131
struct _sim_cpu; /* forward reference */
132
typedef void (PROFILE_INFO_CPU_CALLBACK_FN) (struct _sim_cpu *cpu, int verbose);
133
 
134
 
135
/* Struct containing most profiling data.
136
   It doesn't contain all profiling data because for example scache data
137
   is kept with the rest of scache support.  */
138
 
139
typedef struct {
140
  /* Global summary of all the current profiling options.  */
141
  char profile_any_p;
142
 
143
  /* Boolean array of specified profiling flags.  */
144
  char profile_flags[MAX_PROFILE_VALUES];
145
#define PROFILE_FLAGS(p) ((p)->profile_flags)
146
 
147
  /* The total insn count is tracked separately.
148
     It is always computed, regardless of insn profiling.  */
149
  unsigned long total_insn_count;
150
#define PROFILE_TOTAL_INSN_COUNT(p) ((p)->total_insn_count)
151
 
152
  /* CPU frequency.  Always accepted, regardless of profiling options.  */
153
  unsigned long cpu_freq;
154
#define PROFILE_CPU_FREQ(p) ((p)->cpu_freq)
155
 
156
#if WITH_PROFILE_INSN_P
157
  unsigned int *insn_count;
158
#define PROFILE_INSN_COUNT(p) ((p)->insn_count)
159
#endif
160
 
161
#if WITH_PROFILE_MEMORY_P
162
  unsigned int read_count[MAX_TARGET_MODES];
163
#define PROFILE_READ_COUNT(p) ((p)->read_count)
164
  unsigned int write_count[MAX_TARGET_MODES];
165
#define PROFILE_WRITE_COUNT(p) ((p)->write_count)
166
#endif
167
 
168
#if WITH_PROFILE_CORE_P
169
  /* Count read/write/exec accesses separatly. */
170
  unsigned int core_count[nr_maps];
171
#define PROFILE_CORE_COUNT(p) ((p)->core_count)
172
#endif
173
 
174
#if WITH_PROFILE_MODEL_P
175
  /* ??? Quick hack until more elaborate scheme is finished.  */
176
  /* Total cycle count, including stalls.  */
177
  unsigned long total_cycles;
178
#define PROFILE_MODEL_TOTAL_CYCLES(p) ((p)->total_cycles)
179
  /* Stalls due to branches.  */
180
  unsigned long cti_stall_cycles;
181
#define PROFILE_MODEL_CTI_STALL_CYCLES(p) ((p)->cti_stall_cycles)
182
  unsigned long load_stall_cycles;
183
#define PROFILE_MODEL_LOAD_STALL_CYCLES(p) ((p)->load_stall_cycles)
184
  /* Number of cycles the current instruction took.  */
185
  unsigned long cur_insn_cycles;
186
#define PROFILE_MODEL_CUR_INSN_CYCLES(p) ((p)->cur_insn_cycles)
187
 
188
  /* Taken and not-taken branches (and other cti's).  */
189
  unsigned long taken_count, untaken_count;
190
#define PROFILE_MODEL_TAKEN_COUNT(p) ((p)->taken_count)
191
#define PROFILE_MODEL_UNTAKEN_COUNT(p) ((p)->untaken_count)
192
#endif
193
 
194
#if WITH_PROFILE_PC_P
195
  /* PC profiling attempts to determine function usage by sampling the PC
196
     every so many instructions.  */
197
  unsigned int profile_pc_freq;
198
#define PROFILE_PC_FREQ(p) ((p)->profile_pc_freq)
199
  unsigned int profile_pc_nr_buckets;
200
#define PROFILE_PC_NR_BUCKETS(p) ((p)->profile_pc_nr_buckets)
201
  address_word profile_pc_start;
202
#define PROFILE_PC_START(p) ((p)->profile_pc_start)
203
  address_word profile_pc_end;
204
#define PROFILE_PC_END(p) ((p)->profile_pc_end)
205
  unsigned profile_pc_shift;
206
#define PROFILE_PC_SHIFT(p) ((p)->profile_pc_shift)
207
#define PROFILE_PC_BUCKET_SIZE(p) (PROFILE_PC_SHIFT (p) ? (1 << PROFILE_PC_SHIFT (p)) : 0)
208
  unsigned *profile_pc_count;
209
#define PROFILE_PC_COUNT(p) ((p)->profile_pc_count)
210
  sim_event *profile_pc_event;
211
#define PROFILE_PC_EVENT(p) ((p)->profile_pc_event)
212
#endif
213
 
214
  /* Profile output goes to this or stderr if NULL.
215
     We can't store `stderr' here as stderr goes through a callback.  */
216
  FILE *profile_file;
217
#define PROFILE_FILE(p) ((p)->profile_file)
218
 
219
  /* When reporting a profile summary, hook to include per-processor
220
     target specific profile information */
221
  PROFILE_INFO_CPU_CALLBACK_FN *info_cpu_callback;
222
#define PROFILE_INFO_CPU_CALLBACK(p) ((p)->info_cpu_callback)
223
 
224
  /* When reporting a profile summary, hook to include common target
225
     specific profile information */
226
  PROFILE_INFO_CALLBACK_FN *info_callback;
227
#define STATE_PROFILE_INFO_CALLBACK(sd) \
228
(CPU_PROFILE_DATA (STATE_CPU (sd, 0))->info_callback)
229
 
230
  /* Profile range.
231
     ??? Not all cpu's support this.  */
232
  ADDR_RANGE range;
233
#define PROFILE_RANGE(p) (& (p)->range)
234
} PROFILE_DATA;
235
 
236
/* Predicates.  */
237
 
238
#define CPU_PROFILE_FLAGS(cpu) PROFILE_FLAGS (CPU_PROFILE_DATA (cpu))
239
 
240
/* Return non-zero if tracing of IDX is enabled for CPU.  */
241
#define PROFILE_P(cpu,idx) \
242
((WITH_PROFILE & (1 << (idx))) != 0 \
243
 && CPU_PROFILE_FLAGS (cpu)[idx] != 0)
244
 
245
/* Non-zero if --profile-<xxxx> was specified for CPU.  */
246
#define PROFILE_ANY_P(cpu)      ((WITH_PROFILE) && (CPU_PROFILE_DATA (cpu)->profile_any_p))
247
#define PROFILE_INSN_P(cpu)     PROFILE_P (cpu, PROFILE_INSN_IDX)
248
#define PROFILE_MEMORY_P(cpu)   PROFILE_P (cpu, PROFILE_MEMORY_IDX)
249
#define PROFILE_MODEL_P(cpu)    PROFILE_P (cpu, PROFILE_MODEL_IDX)
250
#define PROFILE_SCACHE_P(cpu)   PROFILE_P (cpu, PROFILE_SCACHE_IDX)
251
#define PROFILE_PC_P(cpu)       PROFILE_P (cpu, PROFILE_PC_IDX)
252
#define PROFILE_CORE_P(cpu)     PROFILE_P (cpu, PROFILE_CORE_IDX)
253
 
254
/* Usage macros.  */
255
 
256
#if WITH_PROFILE_INSN_P
257
#define PROFILE_COUNT_INSN(cpu, pc, insn_num) \
258
do { \
259
  if (PROFILE_INSN_P (cpu)) \
260
    ++ PROFILE_INSN_COUNT (CPU_PROFILE_DATA (cpu)) [insn_num]; \
261
} while (0)
262
#else
263
#define PROFILE_COUNT_INSN(cpu, pc, insn_num)
264
#endif /* ! insn */
265
 
266
#if WITH_PROFILE_MEMORY_P
267
#define PROFILE_COUNT_READ(cpu, addr, mode_num) \
268
do { \
269
  if (PROFILE_MEMORY_P (cpu)) \
270
    ++ PROFILE_READ_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
271
} while (0)
272
#define PROFILE_COUNT_WRITE(cpu, addr, mode_num) \
273
do { \
274
  if (PROFILE_MEMORY_P (cpu)) \
275
    ++ PROFILE_WRITE_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
276
} while (0)
277
#else
278
#define PROFILE_COUNT_READ(cpu, addr, mode_num)
279
#define PROFILE_COUNT_WRITE(cpu, addr, mode_num)
280
#endif /* ! memory */
281
 
282
#if WITH_PROFILE_CORE_P
283
#define PROFILE_COUNT_CORE(cpu, addr, size, map) \
284
do { \
285
  if (PROFILE_CORE_P (cpu)) \
286
    PROFILE_CORE_COUNT (CPU_PROFILE_DATA (cpu)) [map] += 1; \
287
} while (0)
288
#else
289
#define PROFILE_COUNT_CORE(cpu, addr, size, map)
290
#endif /* ! core */
291
 
292
/* Misc. utilities.  */
293
 
294
extern void sim_profile_print_bar (SIM_DESC, unsigned int, unsigned int, unsigned int);
295
 
296
#endif /* SIM_PROFILE_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.