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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [sim/] [common/] [sim-profile.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
/* Profile header for simulators using common framework.
2
   Copyright (C) 1996, 1997, 1998 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 2, or (at your option)
10
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 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.  */
20
 
21
#ifndef SIM_PROFILE_H
22
#define SIM_PROFILE_H
23
 
24
#ifndef WITH_PROFILE
25
Error, WITH_PROFILE not defined.
26
#endif
27
 
28
/* Standard profilable entities.  */
29
 
30
enum {
31
  /* Profile insn usage.  */
32
  PROFILE_INSN_IDX = 1,
33
 
34
  /* Profile memory usage.  */
35
  PROFILE_MEMORY_IDX,
36
 
37
  /* Profile the cpu model (cycles, etc.).  */
38
  PROFILE_MODEL_IDX,
39
 
40
  /* Profile the simulator's execution cache.  */
41
  PROFILE_SCACHE_IDX,
42
 
43
  /* Profile the PC.  */
44
  PROFILE_PC_IDX,
45
 
46
  /* Profile sim-core.c stuff.  */
47
  /* ??? The difference between this and PROFILE_MEMORY_IDX is ... ?  */
48
  PROFILE_CORE_IDX,
49
 
50
  /* Simulator specific profile bits begin here.  */
51
  PROFILE_NEXT_IDX
52
};
53
 
54
/* Maximum number of profilable entities.  */
55
#ifndef MAX_PROFILE_VALUES
56
#define MAX_PROFILE_VALUES 32
57
#endif
58
 
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
61
   find.  */
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))
67
 
68
/* Utility to set profile options.  */
69
SIM_RC set_profile_option_mask (SIM_DESC sd_, const char *name_, int mask_,
70
                                const char *arg_);
71
 
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
75
   source is cleaner.   */
76
 
77
SIM_RC sim_profile_set_option (SIM_DESC sd_, const char *name_, int idx_,
78
                               const char *arg_);
79
 
80
/* Masks so WITH_PROFILE can have symbolic values.
81
   The case choice here is on purpose.  The lowercase parts are args to
82
   --with-profile.  */
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)
89
 
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)
97
 
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
104
#endif
105
 
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
110
#endif
111
 
112
/* Profiling install handler.  */
113
MODULE_INSTALL_FN profile_install;
114
 
115
/* Output format macros.  */
116
#ifndef PROFILE_HISTOGRAM_WIDTH
117
#define PROFILE_HISTOGRAM_WIDTH 40
118
#endif
119
#ifndef PROFILE_LABEL_WIDTH
120
#define PROFILE_LABEL_WIDTH 32
121
#endif
122
 
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
126
   section titles.
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.
129
   */
130
 
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);
134
 
135
 
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.  */
139
 
140
typedef struct {
141
  /* Global summary of all the current profiling options.  */
142
  char profile_any_p;
143
 
144
  /* Boolean array of specified profiling flags.  */
145
  char profile_flags[MAX_PROFILE_VALUES];
146
#define PROFILE_FLAGS(p) ((p)->profile_flags)
147
 
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)
152
 
153
#if WITH_PROFILE_INSN_P
154
  unsigned int *insn_count;
155
#define PROFILE_INSN_COUNT(p) ((p)->insn_count)
156
#endif
157
 
158
#if WITH_PROFILE_MEMORY_P
159
  unsigned int read_count[MAX_TARGET_MODES];
160
#define PROFILE_READ_COUNT(p) ((p)->read_count)
161
  unsigned int write_count[MAX_TARGET_MODES];
162
#define PROFILE_WRITE_COUNT(p) ((p)->write_count)
163
#endif
164
 
165
#if WITH_PROFILE_CORE_P
166
  /* Count read/write/exec accesses separatly. */
167
  unsigned int core_count[nr_maps];
168
#define PROFILE_CORE_COUNT(p) ((p)->core_count)
169
#endif
170
 
171
#if WITH_PROFILE_MODEL_P
172
  /* ??? Quick hack until more elaborate scheme is finished.  */
173
  /* Total cycle count, including stalls.  */
174
  unsigned long total_cycles;
175
#define PROFILE_MODEL_TOTAL_CYCLES(p) ((p)->total_cycles)
176
  /* Stalls due to branches.  */
177
  unsigned long cti_stall_cycles;
178
#define PROFILE_MODEL_CTI_STALL_CYCLES(p) ((p)->cti_stall_cycles)
179
  unsigned long load_stall_cycles;
180
#define PROFILE_MODEL_LOAD_STALL_CYCLES(p) ((p)->load_stall_cycles)
181
  /* Number of cycles the current instruction took.  */
182
  unsigned long cur_insn_cycles;
183
#define PROFILE_MODEL_CUR_INSN_CYCLES(p) ((p)->cur_insn_cycles)
184
 
185
  /* Taken and not-taken branches (and other cti's).  */
186
  unsigned long taken_count, untaken_count;
187
#define PROFILE_MODEL_TAKEN_COUNT(p) ((p)->taken_count)
188
#define PROFILE_MODEL_UNTAKEN_COUNT(p) ((p)->untaken_count)
189
#endif
190
 
191
#if WITH_PROFILE_PC_P
192
  /* PC profiling attempts to determine function usage by sampling the PC
193
     every so many instructions.  */
194
  unsigned int profile_pc_freq;
195
#define PROFILE_PC_FREQ(p) ((p)->profile_pc_freq)
196
  unsigned int profile_pc_nr_buckets;
197
#define PROFILE_PC_NR_BUCKETS(p) ((p)->profile_pc_nr_buckets)
198
  address_word profile_pc_start;
199
#define PROFILE_PC_START(p) ((p)->profile_pc_start)
200
  address_word profile_pc_end;
201
#define PROFILE_PC_END(p) ((p)->profile_pc_end)
202
  unsigned profile_pc_shift;
203
#define PROFILE_PC_SHIFT(p) ((p)->profile_pc_shift)
204
#define PROFILE_PC_BUCKET_SIZE(p) (PROFILE_PC_SHIFT (p) ? (1 << PROFILE_PC_SHIFT (p)) : 0)
205
  unsigned *profile_pc_count;
206
#define PROFILE_PC_COUNT(p) ((p)->profile_pc_count)
207
  sim_event *profile_pc_event;
208
#define PROFILE_PC_EVENT(p) ((p)->profile_pc_event)
209
#endif
210
 
211
  /* Profile output goes to this or stderr if NULL.
212
     We can't store `stderr' here as stderr goes through a callback.  */
213
  FILE *profile_file;
214
#define PROFILE_FILE(p) ((p)->profile_file)
215
 
216
  /* When reporting a profile summary, hook to include per-processor
217
     target specific profile information */
218
  PROFILE_INFO_CPU_CALLBACK_FN *info_cpu_callback;
219
#define PROFILE_INFO_CPU_CALLBACK(p) ((p)->info_cpu_callback)
220
 
221
  /* When reporting a profile summary, hook to include common target
222
     specific profile information */
223
  PROFILE_INFO_CALLBACK_FN *info_callback;
224
#define STATE_PROFILE_INFO_CALLBACK(sd) \
225
(CPU_PROFILE_DATA (STATE_CPU (sd, 0))->info_callback)
226
 
227
  /* Profile range.
228
     ??? Not all cpu's support this.  */
229
  ADDR_RANGE range;
230
#define PROFILE_RANGE(p) (& (p)->range)
231
} PROFILE_DATA;
232
 
233
/* Predicates.  */
234
 
235
#define CPU_PROFILE_FLAGS(cpu) PROFILE_FLAGS (CPU_PROFILE_DATA (cpu))
236
 
237
/* Return non-zero if tracing of IDX is enabled for CPU.  */
238
#define PROFILE_P(cpu,idx) \
239
((WITH_PROFILE & (1 << (idx))) != 0 \
240
 && CPU_PROFILE_FLAGS (cpu)[idx] != 0)
241
 
242
/* Non-zero if --profile-<xxxx> was specified for CPU.  */
243
#define PROFILE_ANY_P(cpu)      ((WITH_PROFILE) && (CPU_PROFILE_DATA (cpu)->profile_any_p))
244
#define PROFILE_INSN_P(cpu)     PROFILE_P (cpu, PROFILE_INSN_IDX)
245
#define PROFILE_MEMORY_P(cpu)   PROFILE_P (cpu, PROFILE_MEMORY_IDX)
246
#define PROFILE_MODEL_P(cpu)    PROFILE_P (cpu, PROFILE_MODEL_IDX)
247
#define PROFILE_SCACHE_P(cpu)   PROFILE_P (cpu, PROFILE_SCACHE_IDX)
248
#define PROFILE_PC_P(cpu)       PROFILE_P (cpu, PROFILE_PC_IDX)
249
#define PROFILE_CORE_P(cpu)     PROFILE_P (cpu, PROFILE_CORE_IDX)
250
 
251
/* Usage macros.  */
252
 
253
#if WITH_PROFILE_INSN_P
254
#define PROFILE_COUNT_INSN(cpu, pc, insn_num) \
255
do { \
256
  if (PROFILE_INSN_P (cpu)) \
257
    ++ PROFILE_INSN_COUNT (CPU_PROFILE_DATA (cpu)) [insn_num]; \
258
} while (0)
259
#else
260
#define PROFILE_COUNT_INSN(cpu, pc, insn_num)
261
#endif /* ! insn */
262
 
263
#if WITH_PROFILE_MEMORY_P
264
#define PROFILE_COUNT_READ(cpu, addr, mode_num) \
265
do { \
266
  if (PROFILE_MEMORY_P (cpu)) \
267
    ++ PROFILE_READ_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
268
} while (0)
269
#define PROFILE_COUNT_WRITE(cpu, addr, mode_num) \
270
do { \
271
  if (PROFILE_MEMORY_P (cpu)) \
272
    ++ PROFILE_WRITE_COUNT (CPU_PROFILE_DATA (cpu)) [mode_num]; \
273
} while (0)
274
#else
275
#define PROFILE_COUNT_READ(cpu, addr, mode_num)
276
#define PROFILE_COUNT_WRITE(cpu, addr, mode_num)
277
#endif /* ! memory */
278
 
279
#if WITH_PROFILE_CORE_P
280
#define PROFILE_COUNT_CORE(cpu, addr, size, map) \
281
do { \
282
  if (PROFILE_CORE_P (cpu)) \
283
    PROFILE_CORE_COUNT (CPU_PROFILE_DATA (cpu)) [map] += 1; \
284
} while (0)
285
#else
286
#define PROFILE_COUNT_CORE(cpu, addr, size, map)
287
#endif /* ! core */
288
 
289
/* Misc. utilities.  */
290
 
291
extern void sim_profile_print_bar (SIM_DESC, unsigned int, unsigned int, unsigned int);
292
 
293
#endif /* SIM_PROFILE_H */

powered by: WebSVN 2.1.0

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