blob: 90cf31e1ed80ae272bffac12c56415edbd57ae2d [file] [log] [blame]
sewardj07133bf2002-06-13 10:25:56 +00001
njn4f9c9342002-04-29 16:03:24 +00002/*--------------------------------------------------------------------*/
nethercote9313ac42004-07-06 21:54:20 +00003/*--- Cachegrind: every but the simulation itself. ---*/
njn25cac76cb2002-09-23 11:21:57 +00004/*--- cg_main.c ---*/
njn4f9c9342002-04-29 16:03:24 +00005/*--------------------------------------------------------------------*/
6
7/*
nethercote137bc552003-11-14 17:47:54 +00008 This file is part of Cachegrind, a Valgrind tool for cache
njnc9539842002-10-02 13:26:35 +00009 profiling programs.
njn4f9c9342002-04-29 16:03:24 +000010
nethercotebb1c9912004-01-04 16:43:23 +000011 Copyright (C) 2002-2004 Nicholas Nethercote
sewardj3c23d432002-06-01 23:43:49 +000012 njn25@cam.ac.uk
njn4f9c9342002-04-29 16:03:24 +000013
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
njn25e49d8e72002-09-23 09:36:25 +000029 The GNU General Public License is contained in the file COPYING.
njn4f9c9342002-04-29 16:03:24 +000030*/
31
nethercote46063202004-09-02 08:51:43 +000032#include "tool.h"
njn25e49d8e72002-09-23 09:36:25 +000033//#include "vg_profile.c"
34
nethercoteb35a8b92004-09-11 16:45:27 +000035#include "cg_arch.h"
nethercote27fc1da2004-01-04 16:56:57 +000036#include "cg_sim.c"
njn4f9c9342002-04-29 16:03:24 +000037
njn25e49d8e72002-09-23 09:36:25 +000038/*------------------------------------------------------------*/
39/*--- Constants ---*/
40/*------------------------------------------------------------*/
njn4f9c9342002-04-29 16:03:24 +000041
nethercote9313ac42004-07-06 21:54:20 +000042#define MIN_LINE_SIZE 16
43#define FILE_LEN 256
44#define FN_LEN 256
njn7cf0bd32002-06-08 13:36:03 +000045
46/*------------------------------------------------------------*/
njn25e49d8e72002-09-23 09:36:25 +000047/*--- Profiling events ---*/
njn7cf0bd32002-06-08 13:36:03 +000048/*------------------------------------------------------------*/
49
njn25e49d8e72002-09-23 09:36:25 +000050typedef
51 enum {
nethercote9313ac42004-07-06 21:54:20 +000052 VgpGetLineCC = VgpFini+1,
njn25e49d8e72002-09-23 09:36:25 +000053 VgpCacheSimulate,
54 VgpCacheResults
55 }
nethercote7cc9c232004-01-21 15:08:04 +000056 VgpToolCC;
sewardj07133bf2002-06-13 10:25:56 +000057
njn4f9c9342002-04-29 16:03:24 +000058/*------------------------------------------------------------*/
nethercote9313ac42004-07-06 21:54:20 +000059/*--- Types and Data Structures ---*/
njn4f9c9342002-04-29 16:03:24 +000060/*------------------------------------------------------------*/
61
62typedef struct _CC CC;
63struct _CC {
64 ULong a;
65 ULong m1;
66 ULong m2;
67};
68
nethercote9313ac42004-07-06 21:54:20 +000069//------------------------------------------------------------
70// Primary data structure #1: CC table
71// - Holds the per-source-line hit/miss stats, grouped by file/function/line.
72// - hash(file, hash(fn, hash(line+CC)))
73// - Each hash table is separately chained.
74// - The array sizes below work fairly well for Konqueror.
75// - Lookups done by instr_addr, which is converted immediately to a source
76// location.
77// - Traversed for dumping stats at end in file/func/line hierarchy.
njn4f9c9342002-04-29 16:03:24 +000078
79#define N_FILE_ENTRIES 251
80#define N_FN_ENTRIES 53
nethercote9313ac42004-07-06 21:54:20 +000081#define N_LINE_ENTRIES 37
njn4f9c9342002-04-29 16:03:24 +000082
nethercote9313ac42004-07-06 21:54:20 +000083typedef struct _lineCC lineCC;
84struct _lineCC {
85 Int line;
86 CC Ir;
87 CC Dr;
88 CC Dw;
89 lineCC* next;
njn4f9c9342002-04-29 16:03:24 +000090};
91
nethercote9313ac42004-07-06 21:54:20 +000092typedef struct _fnCC fnCC;
93struct _fnCC {
94 Char* fn;
95 fnCC* next;
96 lineCC* lines[N_LINE_ENTRIES];
njn4f9c9342002-04-29 16:03:24 +000097};
98
nethercote9313ac42004-07-06 21:54:20 +000099typedef struct _fileCC fileCC;
100struct _fileCC {
101 Char* file;
102 fileCC* next;
103 fnCC* fns[N_FN_ENTRIES];
njn4f9c9342002-04-29 16:03:24 +0000104};
105
nethercote9313ac42004-07-06 21:54:20 +0000106// Top level of CC table. Auto-zeroed.
107static fileCC *CC_table[N_FILE_ENTRIES];
njn4f9c9342002-04-29 16:03:24 +0000108
nethercote9313ac42004-07-06 21:54:20 +0000109//------------------------------------------------------------
110// Primary data structre #2: Instr-info table
111// - Holds the cached info about each instr that is used for simulation.
112// - table(BB_start_addr, list(instr_info))
113// - For each BB, each instr_info in the list holds info about the
nethercote7149b422004-07-20 13:29:02 +0000114// instruction (instr_size, instr_addr, etc), plus a pointer to its line
nethercote9313ac42004-07-06 21:54:20 +0000115// CC. This node is what's passed to the simulation function.
116// - When BBs are discarded the relevant list(instr_details) is freed.
117
118typedef struct _instr_info instr_info;
119struct _instr_info {
nethercoteca1f2dc2004-07-21 08:49:02 +0000120 Addr instr_addr;
121 UChar instr_size;
122 UChar data_size;
123 lineCC* parent; // parent line-CC
nethercote9313ac42004-07-06 21:54:20 +0000124};
125
126typedef struct _BB_info BB_info;
127struct _BB_info {
128 BB_info* next; // next field
129 Addr BB_addr; // key
130 Int n_instrs;
131 instr_info instrs[0];
132};
133
134VgHashTable instr_info_table; // hash(Addr, BB_info)
135
136//------------------------------------------------------------
137// Stats
sewardj4f29ddf2002-05-03 22:29:04 +0000138static Int distinct_files = 0;
139static Int distinct_fns = 0;
nethercote9313ac42004-07-06 21:54:20 +0000140static Int distinct_lines = 0;
sewardj4f29ddf2002-05-03 22:29:04 +0000141static Int distinct_instrs = 0;
nethercote9313ac42004-07-06 21:54:20 +0000142
sewardj4f29ddf2002-05-03 22:29:04 +0000143static Int full_debug_BBs = 0;
144static Int file_line_debug_BBs = 0;
nethercote9313ac42004-07-06 21:54:20 +0000145static Int fn_debug_BBs = 0;
sewardj4f29ddf2002-05-03 22:29:04 +0000146static Int no_debug_BBs = 0;
njn4f9c9342002-04-29 16:03:24 +0000147
sewardj4f29ddf2002-05-03 22:29:04 +0000148static Int BB_retranslations = 0;
njn4f9c9342002-04-29 16:03:24 +0000149
nethercote9313ac42004-07-06 21:54:20 +0000150/*------------------------------------------------------------*/
151/*--- CC table operations ---*/
152/*------------------------------------------------------------*/
njn4294fd42002-06-05 14:41:10 +0000153
nethercote9313ac42004-07-06 21:54:20 +0000154static void get_debug_info(Addr instr_addr, Char file[FILE_LEN],
155 Char fn[FN_LEN], Int* line)
njn4f9c9342002-04-29 16:03:24 +0000156{
nethercote9313ac42004-07-06 21:54:20 +0000157 Bool found_file_line = VG_(get_filename_linenum)(instr_addr, file,
158 FILE_LEN, line);
159 Bool found_fn = VG_(get_fnname)(instr_addr, fn, FN_LEN);
njn4f9c9342002-04-29 16:03:24 +0000160
nethercote9313ac42004-07-06 21:54:20 +0000161 if (!found_file_line) {
162 VG_(strcpy)(file, "???");
163 *line = 0;
164 }
165 if (!found_fn) {
166 VG_(strcpy)(fn, "???");
167 }
168 if (found_file_line) {
169 if (found_fn) full_debug_BBs++;
170 else file_line_debug_BBs++;
171 } else {
172 if (found_fn) fn_debug_BBs++;
173 else no_debug_BBs++;
njn4f9c9342002-04-29 16:03:24 +0000174 }
175}
176
njn4f9c9342002-04-29 16:03:24 +0000177static UInt hash(Char *s, UInt table_size)
178{
nethercote9313ac42004-07-06 21:54:20 +0000179 const int hash_constant = 256;
180 int hash_value = 0;
181 for ( ; *s; s++)
182 hash_value = (hash_constant * hash_value + *s) % table_size;
183 return hash_value;
njn4f9c9342002-04-29 16:03:24 +0000184}
185
nethercote9313ac42004-07-06 21:54:20 +0000186static __inline__
187fileCC* new_fileCC(Char filename[], fileCC* next)
nethercote09d853e2004-01-21 16:12:55 +0000188{
nethercote9313ac42004-07-06 21:54:20 +0000189 // Using calloc() zeroes the fns[] array
190 fileCC* cc = VG_(calloc)(1, sizeof(fileCC));
191 cc->file = VG_(strdup)(filename);
192 cc->next = next;
193 return cc;
nethercote09d853e2004-01-21 16:12:55 +0000194}
195
nethercote9313ac42004-07-06 21:54:20 +0000196static __inline__
197fnCC* new_fnCC(Char fn[], fnCC* next)
njn4f9c9342002-04-29 16:03:24 +0000198{
nethercote9313ac42004-07-06 21:54:20 +0000199 // Using calloc() zeroes the lines[] array
200 fnCC* cc = VG_(calloc)(1, sizeof(fnCC));
201 cc->fn = VG_(strdup)(fn);
202 cc->next = next;
203 return cc;
204}
njn4f9c9342002-04-29 16:03:24 +0000205
nethercote9313ac42004-07-06 21:54:20 +0000206static __inline__
207lineCC* new_lineCC(Int line, lineCC* next)
208{
209 // Using calloc() zeroes the Ir/Dr/Dw CCs and the instrs[] array
210 lineCC* cc = VG_(calloc)(1, sizeof(lineCC));
211 cc->line = line;
212 cc->next = next;
213 return cc;
214}
njn4f9c9342002-04-29 16:03:24 +0000215
nethercote9313ac42004-07-06 21:54:20 +0000216static __inline__
217instr_info* new_instr_info(Addr instr_addr, lineCC* parent, instr_info* next)
218{
219 // Using calloc() zeroes instr_size and data_size
220 instr_info* ii = VG_(calloc)(1, sizeof(instr_info));
221 ii->instr_addr = instr_addr;
222 ii->parent = parent;
223 return ii;
224}
225
226// Do a three step traversal: by file, then fn, then line.
227// In all cases prepends new nodes to their chain. Returns a pointer to the
228// line node, creates a new one if necessary.
229static lineCC* get_lineCC(Addr orig_addr)
230{
231 fileCC *curr_fileCC;
232 fnCC *curr_fnCC;
233 lineCC *curr_lineCC;
234 Char file[FILE_LEN], fn[FN_LEN];
235 Int line;
236 UInt file_hash, fn_hash, line_hash;
237
238 get_debug_info(orig_addr, file, fn, &line);
239
240 VGP_PUSHCC(VgpGetLineCC);
241
242 // level 1
243 file_hash = hash(file, N_FILE_ENTRIES);
244 curr_fileCC = CC_table[file_hash];
245 while (NULL != curr_fileCC && !VG_STREQ(file, curr_fileCC->file)) {
246 curr_fileCC = curr_fileCC->next;
njn4f9c9342002-04-29 16:03:24 +0000247 }
nethercote9313ac42004-07-06 21:54:20 +0000248 if (NULL == curr_fileCC) {
249 CC_table[file_hash] = curr_fileCC =
250 new_fileCC(file, CC_table[file_hash]);
njn4f9c9342002-04-29 16:03:24 +0000251 distinct_files++;
252 }
253
nethercote9313ac42004-07-06 21:54:20 +0000254 // level 2
255 fn_hash = hash(fn, N_FN_ENTRIES);
256 curr_fnCC = curr_fileCC->fns[fn_hash];
257 while (NULL != curr_fnCC && !VG_STREQ(fn, curr_fnCC->fn)) {
258 curr_fnCC = curr_fnCC->next;
njn4f9c9342002-04-29 16:03:24 +0000259 }
nethercote9313ac42004-07-06 21:54:20 +0000260 if (NULL == curr_fnCC) {
261 curr_fileCC->fns[fn_hash] = curr_fnCC =
262 new_fnCC(fn, curr_fileCC->fns[fn_hash]);
njn4f9c9342002-04-29 16:03:24 +0000263 distinct_fns++;
264 }
265
nethercote9313ac42004-07-06 21:54:20 +0000266 // level 3
267 line_hash = line % N_LINE_ENTRIES;
268 curr_lineCC = curr_fnCC->lines[line_hash];
269 while (NULL != curr_lineCC && line != curr_lineCC->line) {
270 curr_lineCC = curr_lineCC->next;
njn4f9c9342002-04-29 16:03:24 +0000271 }
nethercote9313ac42004-07-06 21:54:20 +0000272 if (NULL == curr_lineCC) {
273 curr_fnCC->lines[line_hash] = curr_lineCC =
274 new_lineCC(line, curr_fnCC->lines[line_hash]);
275 distinct_lines++;
njn4f9c9342002-04-29 16:03:24 +0000276 }
nethercote9313ac42004-07-06 21:54:20 +0000277
278 VGP_POPCC(VgpGetLineCC);
279 return curr_lineCC;
njn4f9c9342002-04-29 16:03:24 +0000280}
281
282/*------------------------------------------------------------*/
nethercote9313ac42004-07-06 21:54:20 +0000283/*--- Cache simulation functions ---*/
njn4f9c9342002-04-29 16:03:24 +0000284/*------------------------------------------------------------*/
285
nethercoteeec46302004-08-23 15:06:23 +0000286static REGPARM(1)
nethercote9313ac42004-07-06 21:54:20 +0000287void log_1I_0D_cache_access(instr_info* n)
njn25e49d8e72002-09-23 09:36:25 +0000288{
289 //VG_(printf)("1I_0D: CCaddr=0x%x, iaddr=0x%x, isize=%u\n",
nethercote9313ac42004-07-06 21:54:20 +0000290 // n, n->instr_addr, n->instr_size)
njn25e49d8e72002-09-23 09:36:25 +0000291 VGP_PUSHCC(VgpCacheSimulate);
nethercote9313ac42004-07-06 21:54:20 +0000292 cachesim_I1_doref(n->instr_addr, n->instr_size,
293 &n->parent->Ir.m1, &n->parent->Ir.m2);
294 n->parent->Ir.a++;
njn25e49d8e72002-09-23 09:36:25 +0000295 VGP_POPCC(VgpCacheSimulate);
296}
297
nethercoteeec46302004-08-23 15:06:23 +0000298static REGPARM(2)
nethercote9313ac42004-07-06 21:54:20 +0000299void log_1I_1Dr_cache_access(instr_info* n, Addr data_addr)
njn25e49d8e72002-09-23 09:36:25 +0000300{
nethercote9313ac42004-07-06 21:54:20 +0000301 //VG_(printf)("1I_1Dr: CCaddr=%p, iaddr=%p, isize=%u, daddr=%p, dsize=%u\n",
302 // n, n->instr_addr, n->instr_size, data_addr, n->data_size)
njn25e49d8e72002-09-23 09:36:25 +0000303 VGP_PUSHCC(VgpCacheSimulate);
nethercote9313ac42004-07-06 21:54:20 +0000304 cachesim_I1_doref(n->instr_addr, n->instr_size,
305 &n->parent->Ir.m1, &n->parent->Ir.m2);
306 n->parent->Ir.a++;
njn25e49d8e72002-09-23 09:36:25 +0000307
nethercote9313ac42004-07-06 21:54:20 +0000308 cachesim_D1_doref(data_addr, n->data_size,
309 &n->parent->Dr.m1, &n->parent->Dr.m2);
310 n->parent->Dr.a++;
njn25e49d8e72002-09-23 09:36:25 +0000311 VGP_POPCC(VgpCacheSimulate);
312}
313
nethercoteeec46302004-08-23 15:06:23 +0000314static REGPARM(2)
nethercote9313ac42004-07-06 21:54:20 +0000315void log_1I_1Dw_cache_access(instr_info* n, Addr data_addr)
njn25e49d8e72002-09-23 09:36:25 +0000316{
nethercote9313ac42004-07-06 21:54:20 +0000317 //VG_(printf)("1I_1Dw: CCaddr=%p, iaddr=%p, isize=%u, daddr=%p, dsize=%u\n",
318 // n, n->instr_addr, n->instr_size, data_addr, n->data_size)
njn25e49d8e72002-09-23 09:36:25 +0000319 VGP_PUSHCC(VgpCacheSimulate);
nethercote9313ac42004-07-06 21:54:20 +0000320 cachesim_I1_doref(n->instr_addr, n->instr_size,
321 &n->parent->Ir.m1, &n->parent->Ir.m2);
322 n->parent->Ir.a++;
323
324 cachesim_D1_doref(data_addr, n->data_size,
325 &n->parent->Dw.m1, &n->parent->Dw.m2);
326 n->parent->Dw.a++;
njn25e49d8e72002-09-23 09:36:25 +0000327 VGP_POPCC(VgpCacheSimulate);
328}
329
nethercoteeec46302004-08-23 15:06:23 +0000330static REGPARM(3)
nethercote9313ac42004-07-06 21:54:20 +0000331void log_1I_2D_cache_access(instr_info* n, Addr data_addr1, Addr data_addr2)
njn25e49d8e72002-09-23 09:36:25 +0000332{
333 //VG_(printf)("1I_2D: CCaddr=%p, iaddr=%p, isize=%u, daddr1=%p, daddr2=%p, dsize=%u\n",
nethercote9313ac42004-07-06 21:54:20 +0000334 // n, n->instr_addr, n->instr_size, data_addr1, data_addr2, n->data_size)
njn25e49d8e72002-09-23 09:36:25 +0000335 VGP_PUSHCC(VgpCacheSimulate);
nethercote9313ac42004-07-06 21:54:20 +0000336 cachesim_I1_doref(n->instr_addr, n->instr_size,
337 &n->parent->Ir.m1, &n->parent->Ir.m2);
338 n->parent->Ir.a++;
njn25e49d8e72002-09-23 09:36:25 +0000339
nethercote9313ac42004-07-06 21:54:20 +0000340 cachesim_D1_doref(data_addr1, n->data_size,
341 &n->parent->Dr.m1, &n->parent->Dr.m2);
342 n->parent->Dr.a++;
343 cachesim_D1_doref(data_addr2, n->data_size,
344 &n->parent->Dw.m1, &n->parent->Dw.m2);
345 n->parent->Dw.a++;
njn25e49d8e72002-09-23 09:36:25 +0000346 VGP_POPCC(VgpCacheSimulate);
347}
348
nethercote9313ac42004-07-06 21:54:20 +0000349/*------------------------------------------------------------*/
350/*--- Instrumentation ---*/
351/*------------------------------------------------------------*/
352
njn14d01ce2004-11-26 11:30:14 +0000353#if 0
nethercote564b2b02004-08-07 15:54:53 +0000354static
nethercote9313ac42004-07-06 21:54:20 +0000355BB_info* get_BB_info(UCodeBlock* cb_in, Addr orig_addr, Bool* bb_seen_before)
356{
357 Int i, n_instrs;
358 UInstr* u_in;
359 BB_info* bb_info;
360 VgHashNode** dummy;
361
362 // Count number of x86 instrs in BB
363 n_instrs = 1; // start at 1 because last x86 instr has no INCEIP
364 for (i = 0; i < VG_(get_num_instrs)(cb_in); i++) {
365 u_in = VG_(get_instr)(cb_in, i);
366 if (INCEIP == u_in->opcode) n_instrs++;
367 }
368
369 // Get the BB_info
370 bb_info = (BB_info*)VG_(HT_get_node)(instr_info_table, orig_addr, &dummy);
371 *bb_seen_before = ( NULL == bb_info ? False : True );
372 if (*bb_seen_before) {
373 // BB must have been translated before, but flushed from the TT
njnca82cc02004-11-22 17:18:48 +0000374 tl_assert(bb_info->n_instrs == n_instrs );
nethercote9313ac42004-07-06 21:54:20 +0000375 BB_retranslations++;
376 } else {
377 // BB never translated before (at this address, at least; could have
378 // been unloaded and then reloaded elsewhere in memory)
379 bb_info =
380 VG_(calloc)(1, sizeof(BB_info) + n_instrs*sizeof(instr_info));
381 bb_info->BB_addr = orig_addr;
382 bb_info->n_instrs = n_instrs;
383 VG_(HT_add_node)( instr_info_table, (VgHashNode*)bb_info );
384 distinct_instrs++;
385 }
386 return bb_info;
387}
njn14d01ce2004-11-26 11:30:14 +0000388#endif
nethercote9313ac42004-07-06 21:54:20 +0000389
nethercote564b2b02004-08-07 15:54:53 +0000390static
nethercote9313ac42004-07-06 21:54:20 +0000391void do_details( instr_info* n, Bool bb_seen_before,
392 Addr instr_addr, Int instr_size, Int data_size )
393{
394 lineCC* parent = get_lineCC(instr_addr);
395 if (bb_seen_before) {
njnca82cc02004-11-22 17:18:48 +0000396 tl_assert( n->instr_addr == instr_addr );
397 tl_assert( n->instr_size == instr_size );
398 tl_assert( n->data_size == data_size );
nethercote9313ac42004-07-06 21:54:20 +0000399 // Don't assert that (n->parent == parent)... it's conceivable that
400 // the debug info might change; the other asserts should be enough to
401 // detect anything strange.
402 } else {
403 n->instr_addr = instr_addr;
404 n->instr_size = instr_size;
405 n->data_size = data_size;
406 n->parent = parent;
407 }
408}
409
nethercote564b2b02004-08-07 15:54:53 +0000410static Bool is_valid_data_size(Int data_size)
nethercote9313ac42004-07-06 21:54:20 +0000411{
412 return (4 == data_size || 2 == data_size || 1 == data_size ||
413 8 == data_size || 10 == data_size || MIN_LINE_SIZE == data_size);
414}
415
njn14d01ce2004-11-26 11:30:14 +0000416#if 0
nethercote9313ac42004-07-06 21:54:20 +0000417// Instrumentation for the end of each x86 instruction.
nethercote564b2b02004-08-07 15:54:53 +0000418static
nethercote9313ac42004-07-06 21:54:20 +0000419void end_of_x86_instr(UCodeBlock* cb, instr_info* i_node, Bool bb_seen_before,
420 UInt instr_addr, UInt instr_size, UInt data_size,
421 Int t_read, Int t_read_addr,
422 Int t_write, Int t_write_addr)
423{
424 Addr helper;
425 Int argc;
426 Int t_CC_addr,
427 t_data_addr1 = INVALID_TEMPREG,
428 t_data_addr2 = INVALID_TEMPREG;
429
njnca82cc02004-11-22 17:18:48 +0000430 tl_assert(instr_size >= MIN_INSTR_SIZE &&
nethercotefbfc1082004-09-04 15:28:37 +0000431 instr_size <= MAX_INSTR_SIZE);
nethercote9313ac42004-07-06 21:54:20 +0000432
433#define IS_(X) (INVALID_TEMPREG != t_##X##_addr)
434#define INV(qqt) (INVALID_TEMPREG == (qqt))
435
436 // Work out what kind of x86 instruction it is
437 if (!IS_(read) && !IS_(write)) {
njnca82cc02004-11-22 17:18:48 +0000438 tl_assert( 0 == data_size );
439 tl_assert(INV(t_read) && INV(t_write));
nethercote9313ac42004-07-06 21:54:20 +0000440 helper = (Addr) & log_1I_0D_cache_access;
441 argc = 1;
442
443 } else if (IS_(read) && !IS_(write)) {
njnca82cc02004-11-22 17:18:48 +0000444 tl_assert( is_valid_data_size(data_size) );
445 tl_assert(!INV(t_read) && INV(t_write));
nethercote9313ac42004-07-06 21:54:20 +0000446 helper = (Addr) & log_1I_1Dr_cache_access;
447 argc = 2;
448 t_data_addr1 = t_read_addr;
449
450 } else if (!IS_(read) && IS_(write)) {
njnca82cc02004-11-22 17:18:48 +0000451 tl_assert( is_valid_data_size(data_size) );
452 tl_assert(INV(t_read) && !INV(t_write));
nethercote9313ac42004-07-06 21:54:20 +0000453 helper = (Addr) & log_1I_1Dw_cache_access;
454 argc = 2;
455 t_data_addr1 = t_write_addr;
456
457 } else {
njnca82cc02004-11-22 17:18:48 +0000458 tl_assert(IS_(read) && IS_(write));
459 tl_assert( is_valid_data_size(data_size) );
460 tl_assert(!INV(t_read) && !INV(t_write));
nethercote9313ac42004-07-06 21:54:20 +0000461 if (t_read == t_write) {
462 helper = (Addr) & log_1I_1Dr_cache_access;
463 argc = 2;
464 t_data_addr1 = t_read_addr;
465 } else {
466 helper = (Addr) & log_1I_2D_cache_access;
467 argc = 3;
468 t_data_addr1 = t_read_addr;
469 t_data_addr2 = t_write_addr;
470 }
471 }
472#undef IS_
nethercotef5b74662004-07-06 22:46:41 +0000473#undef INV
474
nethercote9313ac42004-07-06 21:54:20 +0000475 // Setup 1st arg: CC addr
476 do_details( i_node, bb_seen_before, instr_addr, instr_size, data_size );
477 t_CC_addr = newTemp(cb);
478 uInstr2(cb, MOV, 4, Literal, 0, TempReg, t_CC_addr);
479 uLiteral(cb, (Addr)i_node);
480
481 // Call the helper
482 if (1 == argc)
483 uInstr1(cb, CCALL, 0, TempReg, t_CC_addr);
484 else if (2 == argc)
485 uInstr2(cb, CCALL, 0, TempReg, t_CC_addr,
486 TempReg, t_data_addr1);
487 else if (3 == argc)
488 uInstr3(cb, CCALL, 0, TempReg, t_CC_addr,
489 TempReg, t_data_addr1,
490 TempReg, t_data_addr2);
491 else
njn67993252004-11-22 18:02:32 +0000492 VG_(tool_panic)("argc... not 1 or 2 or 3?");
nethercote9313ac42004-07-06 21:54:20 +0000493
494 uCCall(cb, helper, argc, argc, False);
495}
njn14d01ce2004-11-26 11:30:14 +0000496#endif
nethercote9313ac42004-07-06 21:54:20 +0000497
njn14d01ce2004-11-26 11:30:14 +0000498#if 0
njn26f02512004-11-22 18:33:15 +0000499UCodeBlock* TL_(instrument)(UCodeBlock* cb_in, Addr orig_addr)
njn25e49d8e72002-09-23 09:36:25 +0000500{
njn4f9c9342002-04-29 16:03:24 +0000501 UCodeBlock* cb;
njn4f9c9342002-04-29 16:03:24 +0000502 UInstr* u_in;
nethercote9313ac42004-07-06 21:54:20 +0000503 Int i, bb_info_i;
504 BB_info* bb_info;
505 Bool bb_seen_before = False;
506 Int t_read_addr, t_write_addr, t_read, t_write;
njn25e49d8e72002-09-23 09:36:25 +0000507 Addr x86_instr_addr = orig_addr;
nethercote9313ac42004-07-06 21:54:20 +0000508 UInt x86_instr_size, data_size = 0;
509 Bool instrumented_Jcc = False;
njn4f9c9342002-04-29 16:03:24 +0000510
nethercote9313ac42004-07-06 21:54:20 +0000511 bb_info = get_BB_info(cb_in, orig_addr, &bb_seen_before);
512 bb_info_i = 0;
njn4f9c9342002-04-29 16:03:24 +0000513
njn810086f2002-11-14 12:42:47 +0000514 cb = VG_(setup_UCodeBlock)(cb_in);
njn4f9c9342002-04-29 16:03:24 +0000515
nethercote9313ac42004-07-06 21:54:20 +0000516 t_read_addr = t_write_addr = t_read = t_write = INVALID_TEMPREG;
njn4f9c9342002-04-29 16:03:24 +0000517
njn810086f2002-11-14 12:42:47 +0000518 for (i = 0; i < VG_(get_num_instrs)(cb_in); i++) {
519 u_in = VG_(get_instr)(cb_in, i);
njn4f9c9342002-04-29 16:03:24 +0000520
nethercote9313ac42004-07-06 21:54:20 +0000521 // We want to instrument each x86 instruction with a call to the
522 // appropriate simulation function, which depends on whether the
523 // instruction does memory data reads/writes. x86 instructions can
524 // end in three ways, and this is how they are instrumented:
525 //
526 // 1. UCode, INCEIP --> UCode, Instrumentation, INCEIP
527 // 2. UCode, JMP --> UCode, Instrumentation, JMP
528 // 3. UCode, Jcc, JMP --> UCode, Instrumentation, Jcc, JMP
529 //
530 // The last UInstr in a BB is always a JMP. Jccs, when they appear,
531 // are always second last. This is checked with assertions.
532 // Instrumentation must go before any jumps. (JIFZ is the exception;
533 // if a JIFZ succeeds, no simulation is done for the instruction.)
534 //
535 // x86 instruction sizes are obtained from INCEIPs (for case 1) or
536 // from .extra4b field of the final JMP (for case 2 & 3).
537
njnca82cc02004-11-22 17:18:48 +0000538 if (instrumented_Jcc) tl_assert(u_in->opcode == JMP);
njn4f9c9342002-04-29 16:03:24 +0000539
540 switch (u_in->opcode) {
njn4f9c9342002-04-29 16:03:24 +0000541
nethercote9313ac42004-07-06 21:54:20 +0000542 // For memory-ref instrs, copy the data_addr into a temporary to be
543 // passed to the cachesim_* helper at the end of the instruction.
njn4f9c9342002-04-29 16:03:24 +0000544 case LOAD:
nethercote9313ac42004-07-06 21:54:20 +0000545 case SSE3ag_MemRd_RegWr:
njn25e49d8e72002-09-23 09:36:25 +0000546 t_read = u_in->val1;
njn4f9c9342002-04-29 16:03:24 +0000547 t_read_addr = newTemp(cb);
548 uInstr2(cb, MOV, 4, TempReg, u_in->val1, TempReg, t_read_addr);
549 data_size = u_in->size;
njn4ba5a792002-09-30 10:23:54 +0000550 VG_(copy_UInstr)(cb, u_in);
njn4f9c9342002-04-29 16:03:24 +0000551 break;
552
553 case FPU_R:
nethercote9313ac42004-07-06 21:54:20 +0000554 case MMX2_MemRd:
njn25e49d8e72002-09-23 09:36:25 +0000555 t_read = u_in->val2;
njn4f9c9342002-04-29 16:03:24 +0000556 t_read_addr = newTemp(cb);
557 uInstr2(cb, MOV, 4, TempReg, u_in->val2, TempReg, t_read_addr);
nethercote9313ac42004-07-06 21:54:20 +0000558 data_size = u_in->size;
njn4ba5a792002-09-30 10:23:54 +0000559 VG_(copy_UInstr)(cb, u_in);
njn4f9c9342002-04-29 16:03:24 +0000560 break;
thughes96b466a2004-03-15 16:43:58 +0000561 break;
562
563 case MMX2a1_MemRd:
njn21f805d2003-08-25 16:15:40 +0000564 case SSE2a_MemRd:
565 case SSE2a1_MemRd:
njn21f805d2003-08-25 16:15:40 +0000566 case SSE3a_MemRd:
jseward1b58fbc2003-11-04 22:54:28 +0000567 case SSE3a1_MemRd:
jseward1b58fbc2003-11-04 22:54:28 +0000568 t_read = u_in->val3;
569 t_read_addr = newTemp(cb);
570 uInstr2(cb, MOV, 4, TempReg, u_in->val3, TempReg, t_read_addr);
571 data_size = u_in->size;
572 VG_(copy_UInstr)(cb, u_in);
573 break;
574
nethercote9313ac42004-07-06 21:54:20 +0000575 // Note that we must set t_write_addr even for mod instructions;
576 // That's how the code above determines whether it does a write.
577 // Without it, it would think a mod instruction is a read.
578 // As for the MOV, if it's a mod instruction it's redundant, but it's
579 // not expensive and mod instructions are rare anyway. */
njn4f9c9342002-04-29 16:03:24 +0000580 case STORE:
581 case FPU_W:
nethercote9313ac42004-07-06 21:54:20 +0000582 case MMX2_MemWr:
njn25e49d8e72002-09-23 09:36:25 +0000583 t_write = u_in->val2;
njn4f9c9342002-04-29 16:03:24 +0000584 t_write_addr = newTemp(cb);
585 uInstr2(cb, MOV, 4, TempReg, u_in->val2, TempReg, t_write_addr);
nethercote9313ac42004-07-06 21:54:20 +0000586 data_size = u_in->size;
njn4ba5a792002-09-30 10:23:54 +0000587 VG_(copy_UInstr)(cb, u_in);
njn4f9c9342002-04-29 16:03:24 +0000588 break;
589
njn21f805d2003-08-25 16:15:40 +0000590 case SSE2a_MemWr:
njn21f805d2003-08-25 16:15:40 +0000591 case SSE3a_MemWr:
njn21f805d2003-08-25 16:15:40 +0000592 t_write = u_in->val3;
593 t_write_addr = newTemp(cb);
594 uInstr2(cb, MOV, 4, TempReg, u_in->val3, TempReg, t_write_addr);
nethercote9313ac42004-07-06 21:54:20 +0000595 data_size = u_in->size;
njn21f805d2003-08-25 16:15:40 +0000596 VG_(copy_UInstr)(cb, u_in);
597 break;
njn25e49d8e72002-09-23 09:36:25 +0000598
nethercote9313ac42004-07-06 21:54:20 +0000599 // INCEIP: insert instrumentation
njn25e49d8e72002-09-23 09:36:25 +0000600 case INCEIP:
601 x86_instr_size = u_in->val1;
602 goto instrument_x86_instr;
603
nethercote9313ac42004-07-06 21:54:20 +0000604 // JMP: insert instrumentation if the first JMP
njn25e49d8e72002-09-23 09:36:25 +0000605 case JMP:
nethercote9313ac42004-07-06 21:54:20 +0000606 if (instrumented_Jcc) {
njnca82cc02004-11-22 17:18:48 +0000607 tl_assert(CondAlways == u_in->cond);
608 tl_assert(i+1 == VG_(get_num_instrs)(cb_in));
njn4ba5a792002-09-30 10:23:54 +0000609 VG_(copy_UInstr)(cb, u_in);
nethercote9313ac42004-07-06 21:54:20 +0000610 instrumented_Jcc = False; // rest
njn25e49d8e72002-09-23 09:36:25 +0000611 break;
njn25e49d8e72002-09-23 09:36:25 +0000612 } else {
nethercote9313ac42004-07-06 21:54:20 +0000613 // The first JMP... instrument.
614 if (CondAlways != u_in->cond) {
njnca82cc02004-11-22 17:18:48 +0000615 tl_assert(i+2 == VG_(get_num_instrs)(cb_in));
nethercote9313ac42004-07-06 21:54:20 +0000616 instrumented_Jcc = True;
njn25e49d8e72002-09-23 09:36:25 +0000617 } else {
njnca82cc02004-11-22 17:18:48 +0000618 tl_assert(i+1 == VG_(get_num_instrs)(cb_in));
njn25e49d8e72002-09-23 09:36:25 +0000619 }
nethercote9313ac42004-07-06 21:54:20 +0000620 // Get x86 instr size from final JMP.
621 x86_instr_size = VG_(get_last_instr)(cb_in)->extra4b;
622 goto instrument_x86_instr;
njn25e49d8e72002-09-23 09:36:25 +0000623 }
624
nethercote9313ac42004-07-06 21:54:20 +0000625 // Code executed at the end of each x86 instruction.
626 instrument_x86_instr:
627 // Large (eg. 28B, 108B, 512B) data-sized instructions will be
628 // done inaccurately but they're very rare and this avoids
629 // errors from hitting more than two cache lines in the
630 // simulation.
631 if (data_size > MIN_LINE_SIZE) data_size = MIN_LINE_SIZE;
njn25e49d8e72002-09-23 09:36:25 +0000632
nethercote9313ac42004-07-06 21:54:20 +0000633 end_of_x86_instr(cb, &bb_info->instrs[ bb_info_i ], bb_seen_before,
634 x86_instr_addr, x86_instr_size, data_size,
635 t_read, t_read_addr, t_write, t_write_addr);
njn25e49d8e72002-09-23 09:36:25 +0000636
nethercote9313ac42004-07-06 21:54:20 +0000637 // Copy original UInstr (INCEIP or JMP)
njn4ba5a792002-09-30 10:23:54 +0000638 VG_(copy_UInstr)(cb, u_in);
njn25e49d8e72002-09-23 09:36:25 +0000639
nethercote9313ac42004-07-06 21:54:20 +0000640 // Update loop state for next x86 instr
641 bb_info_i++;
njn25e49d8e72002-09-23 09:36:25 +0000642 x86_instr_addr += x86_instr_size;
nethercote9313ac42004-07-06 21:54:20 +0000643 t_read_addr = t_write_addr = t_read = t_write = INVALID_TEMPREG;
644 data_size = 0;
njn4f9c9342002-04-29 16:03:24 +0000645 break;
646
647 default:
njn4ba5a792002-09-30 10:23:54 +0000648 VG_(copy_UInstr)(cb, u_in);
njn4f9c9342002-04-29 16:03:24 +0000649 break;
650 }
651 }
652
nethercote9313ac42004-07-06 21:54:20 +0000653 // BB address should be the same as the first instruction's address.
njnca82cc02004-11-22 17:18:48 +0000654 tl_assert(bb_info->BB_addr == bb_info->instrs[0].instr_addr );
655 tl_assert(bb_info_i == bb_info->n_instrs);
njn4f9c9342002-04-29 16:03:24 +0000656
njn4ba5a792002-09-30 10:23:54 +0000657 VG_(free_UCodeBlock)(cb_in);
njn4f9c9342002-04-29 16:03:24 +0000658 return cb;
njn25e49d8e72002-09-23 09:36:25 +0000659
660#undef INVALID_DATA_SIZE
njn4f9c9342002-04-29 16:03:24 +0000661}
njn14d01ce2004-11-26 11:30:14 +0000662#endif
663
664IRBB* TL_(instrument) ( IRBB* bb_in, VexGuestLayout* layout, IRType hWordTy )
665{
666 VG_(message)(Vg_DebugMsg, "Cachegrind is not yet ready to handle Vex IR");
667 VG_(exit)(1);
668}
njn4f9c9342002-04-29 16:03:24 +0000669
670/*------------------------------------------------------------*/
nethercoteb35a8b92004-09-11 16:45:27 +0000671/*--- Cache configuration ---*/
njn4f9c9342002-04-29 16:03:24 +0000672/*------------------------------------------------------------*/
673
njn25e49d8e72002-09-23 09:36:25 +0000674#define UNDEFINED_CACHE ((cache_t) { -1, -1, -1 })
675
676static cache_t clo_I1_cache = UNDEFINED_CACHE;
677static cache_t clo_D1_cache = UNDEFINED_CACHE;
678static cache_t clo_L2_cache = UNDEFINED_CACHE;
679
njn7cf0bd32002-06-08 13:36:03 +0000680/* Checks cache config is ok; makes it so if not. */
sewardj07133bf2002-06-13 10:25:56 +0000681static
682void check_cache(cache_t* cache, cache_t* dflt, Char *name)
njn7cf0bd32002-06-08 13:36:03 +0000683{
684 /* First check they're all powers of two */
sewardj07133bf2002-06-13 10:25:56 +0000685 if (-1 == VG_(log2)(cache->size)) {
njn7cf0bd32002-06-08 13:36:03 +0000686 VG_(message)(Vg_UserMsg,
sewardj07133bf2002-06-13 10:25:56 +0000687 "warning: %s size of %dB not a power of two; "
688 "defaulting to %dB", name, cache->size, dflt->size);
njn7cf0bd32002-06-08 13:36:03 +0000689 cache->size = dflt->size;
690 }
691
sewardj07133bf2002-06-13 10:25:56 +0000692 if (-1 == VG_(log2)(cache->assoc)) {
njn7cf0bd32002-06-08 13:36:03 +0000693 VG_(message)(Vg_UserMsg,
sewardj07133bf2002-06-13 10:25:56 +0000694 "warning: %s associativity of %d not a power of two; "
695 "defaulting to %d-way", name, cache->assoc, dflt->assoc);
njn7cf0bd32002-06-08 13:36:03 +0000696 cache->assoc = dflt->assoc;
697 }
698
sewardj07133bf2002-06-13 10:25:56 +0000699 if (-1 == VG_(log2)(cache->line_size)) {
njn7cf0bd32002-06-08 13:36:03 +0000700 VG_(message)(Vg_UserMsg,
sewardj07133bf2002-06-13 10:25:56 +0000701 "warning: %s line size of %dB not a power of two; "
702 "defaulting to %dB",
703 name, cache->line_size, dflt->line_size);
njn7cf0bd32002-06-08 13:36:03 +0000704 cache->line_size = dflt->line_size;
705 }
706
707 /* Then check line size >= 16 -- any smaller and a single instruction could
708 * straddle three cache lines, which breaks a simulation assertion and is
709 * stupid anyway. */
710 if (cache->line_size < MIN_LINE_SIZE) {
711 VG_(message)(Vg_UserMsg,
sewardj07133bf2002-06-13 10:25:56 +0000712 "warning: %s line size of %dB too small; "
713 "increasing to %dB", name, cache->line_size, MIN_LINE_SIZE);
njn7cf0bd32002-06-08 13:36:03 +0000714 cache->line_size = MIN_LINE_SIZE;
715 }
716
717 /* Then check cache size > line size (causes seg faults if not). */
718 if (cache->size <= cache->line_size) {
719 VG_(message)(Vg_UserMsg,
sewardj07133bf2002-06-13 10:25:56 +0000720 "warning: %s cache size of %dB <= line size of %dB; "
721 "increasing to %dB", name, cache->size, cache->line_size,
722 cache->line_size * 2);
njn7cf0bd32002-06-08 13:36:03 +0000723 cache->size = cache->line_size * 2;
724 }
725
726 /* Then check assoc <= (size / line size) (seg faults otherwise). */
727 if (cache->assoc > (cache->size / cache->line_size)) {
728 VG_(message)(Vg_UserMsg,
sewardj07133bf2002-06-13 10:25:56 +0000729 "warning: %s associativity > (size / line size); "
730 "increasing size to %dB",
731 name, cache->assoc * cache->line_size);
njn7cf0bd32002-06-08 13:36:03 +0000732 cache->size = cache->assoc * cache->line_size;
733 }
734}
735
sewardj07133bf2002-06-13 10:25:56 +0000736static
nethercoteb35a8b92004-09-11 16:45:27 +0000737void configure_caches(cache_t* I1c, cache_t* D1c, cache_t* L2c)
njn7cf0bd32002-06-08 13:36:03 +0000738{
nethercote9313ac42004-07-06 21:54:20 +0000739#define DEFINED(L) (-1 != L.size || -1 != L.assoc || -1 != L.line_size)
740
nethercoteb35a8b92004-09-11 16:45:27 +0000741 Int n_clos = 0;
742 cache_t I1_dflt, D1_dflt, L2_dflt;
nethercote9313ac42004-07-06 21:54:20 +0000743
nethercoteb35a8b92004-09-11 16:45:27 +0000744 // Count how many were defined on the command line.
745 if (DEFINED(clo_I1_cache)) { n_clos++; }
746 if (DEFINED(clo_D1_cache)) { n_clos++; }
747 if (DEFINED(clo_L2_cache)) { n_clos++; }
njn7cf0bd32002-06-08 13:36:03 +0000748
nethercoteb35a8b92004-09-11 16:45:27 +0000749 // Set the default cache config (using auto-detection, if supported by
750 // current arch)
751 VGA_(configure_caches)( I1c, D1c, L2c, &I1_dflt, &D1_dflt, &L2_dflt,
752 (3 == n_clos) );
sewardjb1a77a42002-07-13 13:31:20 +0000753
nethercote9313ac42004-07-06 21:54:20 +0000754 // Then replace with any defined on the command line.
nethercoteb35a8b92004-09-11 16:45:27 +0000755 if (DEFINED(clo_I1_cache)) { *I1c = clo_I1_cache; }
756 if (DEFINED(clo_D1_cache)) { *D1c = clo_D1_cache; }
757 if (DEFINED(clo_L2_cache)) { *L2c = clo_L2_cache; }
njn7cf0bd32002-06-08 13:36:03 +0000758
nethercote9313ac42004-07-06 21:54:20 +0000759 // Then check values and fix if not acceptable.
njn7cf0bd32002-06-08 13:36:03 +0000760 check_cache(I1c, &I1_dflt, "I1");
761 check_cache(D1c, &D1_dflt, "D1");
762 check_cache(L2c, &L2_dflt, "L2");
763
764 if (VG_(clo_verbosity) > 1) {
765 VG_(message)(Vg_UserMsg, "Cache configuration used:");
766 VG_(message)(Vg_UserMsg, " I1: %dB, %d-way, %dB lines",
767 I1c->size, I1c->assoc, I1c->line_size);
768 VG_(message)(Vg_UserMsg, " D1: %dB, %d-way, %dB lines",
769 D1c->size, D1c->assoc, D1c->line_size);
770 VG_(message)(Vg_UserMsg, " L2: %dB, %d-way, %dB lines",
771 L2c->size, L2c->assoc, L2c->line_size);
772 }
nethercote9313ac42004-07-06 21:54:20 +0000773#undef CMD_LINE_DEFINED
njn7cf0bd32002-06-08 13:36:03 +0000774}
775
njn4f9c9342002-04-29 16:03:24 +0000776/*------------------------------------------------------------*/
njn26f02512004-11-22 18:33:15 +0000777/*--- TL_(fini)() and related function ---*/
njn4f9c9342002-04-29 16:03:24 +0000778/*------------------------------------------------------------*/
779
nethercote9313ac42004-07-06 21:54:20 +0000780// Total reads/writes/misses. Calculated during CC traversal at the end.
781// All auto-zeroed.
782static CC Ir_total;
783static CC Dr_total;
784static CC Dw_total;
785
786static Char* cachegrind_out_file;
787
788static void file_err ( void )
njn4f9c9342002-04-29 16:03:24 +0000789{
nethercote9313ac42004-07-06 21:54:20 +0000790 VG_(message)(Vg_UserMsg,
791 "error: can't open cache simulation output file `%s'",
792 cachegrind_out_file );
793 VG_(message)(Vg_UserMsg,
794 " ... so simulation results will be missing.");
njn4f9c9342002-04-29 16:03:24 +0000795}
796
nethercote9313ac42004-07-06 21:54:20 +0000797static void fprint_lineCC(Int fd, lineCC* n)
njn4f9c9342002-04-29 16:03:24 +0000798{
nethercote9313ac42004-07-06 21:54:20 +0000799 Char buf[512];
800 VG_(sprintf)(buf, "%u %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
801 n->line,
802 n->Ir.a, n->Ir.m1, n->Ir.m2,
803 n->Dr.a, n->Dr.m1, n->Dr.m2,
804 n->Dw.a, n->Dw.m1, n->Dw.m2);
805 VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
806
807 Ir_total.a += n->Ir.a; Ir_total.m1 += n->Ir.m1; Ir_total.m2 += n->Ir.m2;
808 Dr_total.a += n->Dr.a; Dr_total.m1 += n->Dr.m1; Dr_total.m2 += n->Dr.m2;
809 Dw_total.a += n->Dw.a; Dw_total.m1 += n->Dw.m1; Dw_total.m2 += n->Dw.m2;
810}
811
812static void fprint_CC_table_and_calc_totals(void)
813{
814 Int fd;
815 Char buf[512];
816 fileCC *curr_fileCC;
817 fnCC *curr_fnCC;
818 lineCC *curr_lineCC;
819 Int i, j, k;
njn4f9c9342002-04-29 16:03:24 +0000820
njn25e49d8e72002-09-23 09:36:25 +0000821 VGP_PUSHCC(VgpCacheResults);
njn13f02932003-04-30 20:23:58 +0000822
njndb918dd2003-07-22 20:45:11 +0000823 fd = VG_(open)(cachegrind_out_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
njn13f02932003-04-30 20:23:58 +0000824 VKI_S_IRUSR|VKI_S_IWUSR);
nethercote50da0f32003-10-30 10:33:30 +0000825 if (fd < 0) {
nethercote9313ac42004-07-06 21:54:20 +0000826 // If the file can't be opened for whatever reason (conflict
827 // between multiple cachegrinded processes?), give up now.
sewardj0744b6c2002-12-11 00:45:42 +0000828 file_err();
829 return;
830 }
njn4f9c9342002-04-29 16:03:24 +0000831
nethercote9313ac42004-07-06 21:54:20 +0000832 // "desc:" lines (giving I1/D1/L2 cache configuration). The spaces after
833 // the 2nd colon makes cg_annotate's output look nicer.
834 VG_(sprintf)(buf, "desc: I1 cache: %s\n"
835 "desc: D1 cache: %s\n"
836 "desc: L2 cache: %s\n",
837 I1.desc_line, D1.desc_line, L2.desc_line);
njn7cf0bd32002-06-08 13:36:03 +0000838 VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
njn4f9c9342002-04-29 16:03:24 +0000839
nethercote9313ac42004-07-06 21:54:20 +0000840 // "cmd:" line
njn4f9c9342002-04-29 16:03:24 +0000841 VG_(strcpy)(buf, "cmd:");
842 VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
njn25e49d8e72002-09-23 09:36:25 +0000843 for (i = 0; i < VG_(client_argc); i++) {
thughes6f7eb9c2004-10-06 13:50:12 +0000844 VG_(write)(fd, " ", 1);
thughes30c43d82004-10-06 13:49:36 +0000845 VG_(write)(fd, VG_(client_argv)[i], VG_(strlen)(VG_(client_argv)[i]));
njn4f9c9342002-04-29 16:03:24 +0000846 }
nethercote9313ac42004-07-06 21:54:20 +0000847 // "events:" line
njn4f9c9342002-04-29 16:03:24 +0000848 VG_(sprintf)(buf, "\nevents: Ir I1mr I2mr Dr D1mr D2mr Dw D1mw D2mw\n");
849 VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
850
nethercote9313ac42004-07-06 21:54:20 +0000851 // Six loops here: three for the hash table arrays, and three for the
852 // chains hanging off the hash table arrays.
njn4f9c9342002-04-29 16:03:24 +0000853 for (i = 0; i < N_FILE_ENTRIES; i++) {
nethercote9313ac42004-07-06 21:54:20 +0000854 curr_fileCC = CC_table[i];
855 while (curr_fileCC != NULL) {
856 VG_(sprintf)(buf, "fl=%s\n", curr_fileCC->file);
njn4f9c9342002-04-29 16:03:24 +0000857 VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
858
859 for (j = 0; j < N_FN_ENTRIES; j++) {
nethercote9313ac42004-07-06 21:54:20 +0000860 curr_fnCC = curr_fileCC->fns[j];
861 while (curr_fnCC != NULL) {
862 VG_(sprintf)(buf, "fn=%s\n", curr_fnCC->fn);
njn4f9c9342002-04-29 16:03:24 +0000863 VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
864
nethercote9313ac42004-07-06 21:54:20 +0000865 for (k = 0; k < N_LINE_ENTRIES; k++) {
866 curr_lineCC = curr_fnCC->lines[k];
867 while (curr_lineCC != NULL) {
868 fprint_lineCC(fd, curr_lineCC);
869 curr_lineCC = curr_lineCC->next;
njn4f9c9342002-04-29 16:03:24 +0000870 }
871 }
nethercote9313ac42004-07-06 21:54:20 +0000872 curr_fnCC = curr_fnCC->next;
njn4f9c9342002-04-29 16:03:24 +0000873 }
874 }
nethercote9313ac42004-07-06 21:54:20 +0000875 curr_fileCC = curr_fileCC->next;
njn4f9c9342002-04-29 16:03:24 +0000876 }
877 }
878
nethercote9313ac42004-07-06 21:54:20 +0000879 // Summary stats must come after rest of table, since we calculate them
880 // during traversal. */
njn4f9c9342002-04-29 16:03:24 +0000881 VG_(sprintf)(buf, "summary: "
nethercote9313ac42004-07-06 21:54:20 +0000882 "%llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
njn4f9c9342002-04-29 16:03:24 +0000883 Ir_total.a, Ir_total.m1, Ir_total.m2,
884 Dr_total.a, Dr_total.m1, Dr_total.m2,
885 Dw_total.a, Dw_total.m1, Dw_total.m2);
886 VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
887 VG_(close)(fd);
888}
889
njn607adfc2003-09-30 14:15:44 +0000890static UInt ULong_width(ULong n)
njn4f9c9342002-04-29 16:03:24 +0000891{
njn607adfc2003-09-30 14:15:44 +0000892 UInt w = 0;
893 while (n > 0) {
894 n = n / 10;
895 w++;
njn4f9c9342002-04-29 16:03:24 +0000896 }
njn607adfc2003-09-30 14:15:44 +0000897 return w + (w-1)/3; // add space for commas
njn4f9c9342002-04-29 16:03:24 +0000898}
899
sewardj4f29ddf2002-05-03 22:29:04 +0000900static
daywalker8ad1a402003-09-18 01:15:32 +0000901void percentify(Int n, Int ex, Int field_width, char buf[])
njn4f9c9342002-04-29 16:03:24 +0000902{
903 int i, len, space;
904
daywalker8ad1a402003-09-18 01:15:32 +0000905 VG_(sprintf)(buf, "%d.%d%%", n / ex, n % ex);
njn4f9c9342002-04-29 16:03:24 +0000906 len = VG_(strlen)(buf);
907 space = field_width - len;
njn25e49d8e72002-09-23 09:36:25 +0000908 if (space < 0) space = 0; /* Allow for v. small field_width */
njn4f9c9342002-04-29 16:03:24 +0000909 i = len;
910
911 /* Right justify in field */
912 for ( ; i >= 0; i--) buf[i + space] = buf[i];
913 for (i = 0; i < space; i++) buf[i] = ' ';
914}
915
njn26f02512004-11-22 18:33:15 +0000916void TL_(fini)(Int exitcode)
njn4f9c9342002-04-29 16:03:24 +0000917{
nethercote9313ac42004-07-06 21:54:20 +0000918 static char buf1[128], buf2[128], buf3[128], fmt [128];
njn607adfc2003-09-30 14:15:44 +0000919
njn4f9c9342002-04-29 16:03:24 +0000920 CC D_total;
njn1d021fa2002-05-02 13:56:34 +0000921 ULong L2_total_m, L2_total_mr, L2_total_mw,
922 L2_total, L2_total_r, L2_total_w;
njn4f9c9342002-04-29 16:03:24 +0000923 Int l1, l2, l3;
924 Int p;
925
nethercote9313ac42004-07-06 21:54:20 +0000926 fprint_CC_table_and_calc_totals();
njn4f9c9342002-04-29 16:03:24 +0000927
njn7cf0bd32002-06-08 13:36:03 +0000928 if (VG_(clo_verbosity) == 0)
929 return;
930
njn4f9c9342002-04-29 16:03:24 +0000931 /* I cache results. Use the I_refs value to determine the first column
932 * width. */
njn607adfc2003-09-30 14:15:44 +0000933 l1 = ULong_width(Ir_total.a);
934 l2 = ULong_width(Dr_total.a);
935 l3 = ULong_width(Dw_total.a);
njn4f9c9342002-04-29 16:03:24 +0000936
njn607adfc2003-09-30 14:15:44 +0000937 /* Make format string, getting width right for numbers */
938 VG_(sprintf)(fmt, "%%s %%,%dld", l1);
939
940 VG_(message)(Vg_UserMsg, fmt, "I refs: ", Ir_total.a);
941 VG_(message)(Vg_UserMsg, fmt, "I1 misses: ", Ir_total.m1);
942 VG_(message)(Vg_UserMsg, fmt, "L2i misses: ", Ir_total.m2);
njn4f9c9342002-04-29 16:03:24 +0000943
944 p = 100;
945
njn25e49d8e72002-09-23 09:36:25 +0000946 if (0 == Ir_total.a) Ir_total.a = 1;
njn4f9c9342002-04-29 16:03:24 +0000947 percentify(Ir_total.m1 * 100 * p / Ir_total.a, p, l1+1, buf1);
948 VG_(message)(Vg_UserMsg, "I1 miss rate: %s", buf1);
949
950 percentify(Ir_total.m2 * 100 * p / Ir_total.a, p, l1+1, buf1);
951 VG_(message)(Vg_UserMsg, "L2i miss rate: %s", buf1);
952 VG_(message)(Vg_UserMsg, "");
953
954 /* D cache results. Use the D_refs.rd and D_refs.wr values to determine the
955 * width of columns 2 & 3. */
956 D_total.a = Dr_total.a + Dw_total.a;
957 D_total.m1 = Dr_total.m1 + Dw_total.m1;
958 D_total.m2 = Dr_total.m2 + Dw_total.m2;
959
njn607adfc2003-09-30 14:15:44 +0000960 /* Make format string, getting width right for numbers */
961 VG_(sprintf)(fmt, "%%s %%,%dld (%%,%dld rd + %%,%dld wr)", l1, l2, l3);
njn4f9c9342002-04-29 16:03:24 +0000962
njn607adfc2003-09-30 14:15:44 +0000963 VG_(message)(Vg_UserMsg, fmt, "D refs: ",
964 D_total.a, Dr_total.a, Dw_total.a);
965 VG_(message)(Vg_UserMsg, fmt, "D1 misses: ",
966 D_total.m1, Dr_total.m1, Dw_total.m1);
967 VG_(message)(Vg_UserMsg, fmt, "L2d misses: ",
968 D_total.m2, Dr_total.m2, Dw_total.m2);
njn4f9c9342002-04-29 16:03:24 +0000969
970 p = 10;
971
njn25e49d8e72002-09-23 09:36:25 +0000972 if (0 == D_total.a) D_total.a = 1;
973 if (0 == Dr_total.a) Dr_total.a = 1;
974 if (0 == Dw_total.a) Dw_total.a = 1;
njn4f9c9342002-04-29 16:03:24 +0000975 percentify( D_total.m1 * 100 * p / D_total.a, p, l1+1, buf1);
976 percentify(Dr_total.m1 * 100 * p / Dr_total.a, p, l2+1, buf2);
977 percentify(Dw_total.m1 * 100 * p / Dw_total.a, p, l3+1, buf3);
978 VG_(message)(Vg_UserMsg, "D1 miss rate: %s (%s + %s )", buf1, buf2,buf3);
979
980 percentify( D_total.m2 * 100 * p / D_total.a, p, l1+1, buf1);
981 percentify(Dr_total.m2 * 100 * p / Dr_total.a, p, l2+1, buf2);
982 percentify(Dw_total.m2 * 100 * p / Dw_total.a, p, l3+1, buf3);
983 VG_(message)(Vg_UserMsg, "L2d miss rate: %s (%s + %s )", buf1, buf2,buf3);
984 VG_(message)(Vg_UserMsg, "");
985
986 /* L2 overall results */
njn1d021fa2002-05-02 13:56:34 +0000987
988 L2_total = Dr_total.m1 + Dw_total.m1 + Ir_total.m1;
989 L2_total_r = Dr_total.m1 + Ir_total.m1;
990 L2_total_w = Dw_total.m1;
njn607adfc2003-09-30 14:15:44 +0000991 VG_(message)(Vg_UserMsg, fmt, "L2 refs: ",
992 L2_total, L2_total_r, L2_total_w);
njn1d021fa2002-05-02 13:56:34 +0000993
njn4f9c9342002-04-29 16:03:24 +0000994 L2_total_m = Dr_total.m2 + Dw_total.m2 + Ir_total.m2;
995 L2_total_mr = Dr_total.m2 + Ir_total.m2;
996 L2_total_mw = Dw_total.m2;
njn607adfc2003-09-30 14:15:44 +0000997 VG_(message)(Vg_UserMsg, fmt, "L2 misses: ",
998 L2_total_m, L2_total_mr, L2_total_mw);
njn4f9c9342002-04-29 16:03:24 +0000999
1000 percentify(L2_total_m * 100 * p / (Ir_total.a + D_total.a), p, l1+1, buf1);
1001 percentify(L2_total_mr * 100 * p / (Ir_total.a + Dr_total.a), p, l2+1, buf2);
1002 percentify(L2_total_mw * 100 * p / Dw_total.a, p, l3+1, buf3);
1003 VG_(message)(Vg_UserMsg, "L2 miss rate: %s (%s + %s )", buf1, buf2,buf3);
1004
1005
nethercote9313ac42004-07-06 21:54:20 +00001006 // Various stats
njn4f9c9342002-04-29 16:03:24 +00001007 if (VG_(clo_verbosity) > 1) {
nethercote9313ac42004-07-06 21:54:20 +00001008 int BB_lookups = full_debug_BBs + fn_debug_BBs +
njn4f9c9342002-04-29 16:03:24 +00001009 file_line_debug_BBs + no_debug_BBs;
1010
1011 VG_(message)(Vg_DebugMsg, "");
1012 VG_(message)(Vg_DebugMsg, "Distinct files: %d", distinct_files);
1013 VG_(message)(Vg_DebugMsg, "Distinct fns: %d", distinct_fns);
nethercote9313ac42004-07-06 21:54:20 +00001014 VG_(message)(Vg_DebugMsg, "Distinct lines: %d", distinct_lines);
1015 VG_(message)(Vg_DebugMsg, "Distinct instrs: %d", distinct_instrs);
njn4f9c9342002-04-29 16:03:24 +00001016 VG_(message)(Vg_DebugMsg, "BB lookups: %d", BB_lookups);
1017 VG_(message)(Vg_DebugMsg, "With full debug info:%3d%% (%d)",
1018 full_debug_BBs * 100 / BB_lookups,
1019 full_debug_BBs);
1020 VG_(message)(Vg_DebugMsg, "With file/line debug info:%3d%% (%d)",
1021 file_line_debug_BBs * 100 / BB_lookups,
1022 file_line_debug_BBs);
1023 VG_(message)(Vg_DebugMsg, "With fn name debug info:%3d%% (%d)",
nethercote9313ac42004-07-06 21:54:20 +00001024 fn_debug_BBs * 100 / BB_lookups,
1025 fn_debug_BBs);
njn4f9c9342002-04-29 16:03:24 +00001026 VG_(message)(Vg_DebugMsg, "With no debug info:%3d%% (%d)",
1027 no_debug_BBs * 100 / BB_lookups,
1028 no_debug_BBs);
1029 VG_(message)(Vg_DebugMsg, "BBs Retranslated: %d", BB_retranslations);
njn4f9c9342002-04-29 16:03:24 +00001030 }
njn25e49d8e72002-09-23 09:36:25 +00001031 VGP_POPCC(VgpCacheResults);
njn4f9c9342002-04-29 16:03:24 +00001032}
1033
nethercote9313ac42004-07-06 21:54:20 +00001034/*--------------------------------------------------------------------*/
1035/*--- Discarding BB info ---*/
1036/*--------------------------------------------------------------------*/
sewardj18d75132002-05-16 11:06:21 +00001037
nethercote9313ac42004-07-06 21:54:20 +00001038// Called when a translation is invalidated due to code unloading.
njn26f02512004-11-22 18:33:15 +00001039void TL_(discard_basic_block_info) ( Addr a, SizeT size )
sewardj18d75132002-05-16 11:06:21 +00001040{
nethercote9313ac42004-07-06 21:54:20 +00001041 VgHashNode** prev_next_ptr;
1042 VgHashNode* bb_info;
njn4294fd42002-06-05 14:41:10 +00001043
nethercote928a5f72004-11-03 18:10:37 +00001044 if (0) VG_(printf)( "discard_basic_block_info: %p, %llu\n", a, (ULong)size);
njn4294fd42002-06-05 14:41:10 +00001045
nethercote9313ac42004-07-06 21:54:20 +00001046 // Get BB info, remove from table, free BB info. Simple!
1047 bb_info = VG_(HT_get_node)(instr_info_table, a, &prev_next_ptr);
njnca82cc02004-11-22 17:18:48 +00001048 tl_assert(NULL != bb_info);
nethercote9313ac42004-07-06 21:54:20 +00001049 *prev_next_ptr = bb_info->next;
1050 VG_(free)(bb_info);
sewardj18d75132002-05-16 11:06:21 +00001051}
1052
1053/*--------------------------------------------------------------------*/
njn25e49d8e72002-09-23 09:36:25 +00001054/*--- Command line processing ---*/
1055/*--------------------------------------------------------------------*/
1056
nethercote9313ac42004-07-06 21:54:20 +00001057static void parse_cache_opt ( cache_t* cache, char* opt )
njn25e49d8e72002-09-23 09:36:25 +00001058{
nethercote9313ac42004-07-06 21:54:20 +00001059 int i = 0, i2, i3;
njn25e49d8e72002-09-23 09:36:25 +00001060
nethercote9313ac42004-07-06 21:54:20 +00001061 // Option argument looks like "65536,2,64".
1062 // Find commas, replace with NULs to make three independent
1063 // strings, then extract numbers, put NULs back. Yuck.
njn25e49d8e72002-09-23 09:36:25 +00001064 while (VG_(isdigit)(opt[i])) i++;
1065 if (',' == opt[i]) {
1066 opt[i++] = '\0';
1067 i2 = i;
1068 } else goto bad;
1069 while (VG_(isdigit)(opt[i])) i++;
1070 if (',' == opt[i]) {
1071 opt[i++] = '\0';
1072 i3 = i;
1073 } else goto bad;
1074 while (VG_(isdigit)(opt[i])) i++;
1075 if ('\0' != opt[i]) goto bad;
1076
nethercote9313ac42004-07-06 21:54:20 +00001077 cache->size = (Int)VG_(atoll)(opt);
njn25e49d8e72002-09-23 09:36:25 +00001078 cache->assoc = (Int)VG_(atoll)(opt + i2);
1079 cache->line_size = (Int)VG_(atoll)(opt + i3);
1080
nethercote9313ac42004-07-06 21:54:20 +00001081 opt[i2-1] = ',';
1082 opt[i3-1] = ',';
njn25e49d8e72002-09-23 09:36:25 +00001083 return;
1084
1085 bad:
nethercote9313ac42004-07-06 21:54:20 +00001086 VG_(bad_option)(opt);
njn25e49d8e72002-09-23 09:36:25 +00001087}
1088
njn26f02512004-11-22 18:33:15 +00001089Bool TL_(process_cmd_line_option)(Char* arg)
njn25e49d8e72002-09-23 09:36:25 +00001090{
nethercote9313ac42004-07-06 21:54:20 +00001091 // 5 is length of "--I1="
njn39c86652003-05-21 10:13:39 +00001092 if (VG_CLO_STREQN(5, arg, "--I1="))
nethercote9313ac42004-07-06 21:54:20 +00001093 parse_cache_opt(&clo_I1_cache, &arg[5]);
njn39c86652003-05-21 10:13:39 +00001094 else if (VG_CLO_STREQN(5, arg, "--D1="))
nethercote9313ac42004-07-06 21:54:20 +00001095 parse_cache_opt(&clo_D1_cache, &arg[5]);
njn39c86652003-05-21 10:13:39 +00001096 else if (VG_CLO_STREQN(5, arg, "--L2="))
nethercote9313ac42004-07-06 21:54:20 +00001097 parse_cache_opt(&clo_L2_cache, &arg[5]);
njn25e49d8e72002-09-23 09:36:25 +00001098 else
1099 return False;
1100
1101 return True;
1102}
1103
njn26f02512004-11-22 18:33:15 +00001104void TL_(print_usage)(void)
njn25e49d8e72002-09-23 09:36:25 +00001105{
njn3e884182003-04-15 13:03:23 +00001106 VG_(printf)(
njn25e49d8e72002-09-23 09:36:25 +00001107" --I1=<size>,<assoc>,<line_size> set I1 cache manually\n"
1108" --D1=<size>,<assoc>,<line_size> set D1 cache manually\n"
njn3e884182003-04-15 13:03:23 +00001109" --L2=<size>,<assoc>,<line_size> set L2 cache manually\n"
1110 );
1111}
1112
njn26f02512004-11-22 18:33:15 +00001113void TL_(print_debug_usage)(void)
njn3e884182003-04-15 13:03:23 +00001114{
1115 VG_(printf)(
1116" (none)\n"
1117 );
njn25e49d8e72002-09-23 09:36:25 +00001118}
1119
1120/*--------------------------------------------------------------------*/
1121/*--- Setup ---*/
1122/*--------------------------------------------------------------------*/
1123
njn26f02512004-11-22 18:33:15 +00001124void TL_(pre_clo_init)(void)
njn25e49d8e72002-09-23 09:36:25 +00001125{
njn13f02932003-04-30 20:23:58 +00001126 Char* base_dir = NULL;
njn607adfc2003-09-30 14:15:44 +00001127
njn810086f2002-11-14 12:42:47 +00001128 VG_(details_name) ("Cachegrind");
1129 VG_(details_version) (NULL);
1130 VG_(details_description) ("an I1/D1/L2 cache profiler");
1131 VG_(details_copyright_author)(
nethercote08fa9a72004-07-16 17:44:00 +00001132 "Copyright (C) 2002-2004, and GNU GPL'd, by Nicholas Nethercote et al.");
nethercote421281e2003-11-20 16:20:55 +00001133 VG_(details_bug_reports_to) (VG_BUGS_TO);
sewardj78210aa2002-12-01 02:55:46 +00001134 VG_(details_avg_translation_sizeB) ( 155 );
njn25e49d8e72002-09-23 09:36:25 +00001135
njn810086f2002-11-14 12:42:47 +00001136 VG_(needs_basic_block_discards)();
1137 VG_(needs_command_line_options)();
njn25e49d8e72002-09-23 09:36:25 +00001138
njn99ccf082003-09-30 13:51:23 +00001139 /* Get working directory */
njnca82cc02004-11-22 17:18:48 +00001140 tl_assert( VG_(getcwd_alloc)(&base_dir) );
njn99ccf082003-09-30 13:51:23 +00001141
njn13f02932003-04-30 20:23:58 +00001142 /* Block is big enough for dir name + cachegrind.out.<pid> */
1143 cachegrind_out_file = VG_(malloc)((VG_(strlen)(base_dir) + 32)*sizeof(Char));
1144 VG_(sprintf)(cachegrind_out_file, "%s/cachegrind.out.%d",
1145 base_dir, VG_(getpid)());
njn99ccf082003-09-30 13:51:23 +00001146 VG_(free)(base_dir);
nethercote9313ac42004-07-06 21:54:20 +00001147
1148 instr_info_table = VG_(HT_construct)();
njn25e49d8e72002-09-23 09:36:25 +00001149}
1150
njn26f02512004-11-22 18:33:15 +00001151void TL_(post_clo_init)(void)
njn25e49d8e72002-09-23 09:36:25 +00001152{
1153 cache_t I1c, D1c, L2c;
njn25e49d8e72002-09-23 09:36:25 +00001154
nethercoteb35a8b92004-09-11 16:45:27 +00001155 configure_caches(&I1c, &D1c, &L2c);
njn25e49d8e72002-09-23 09:36:25 +00001156
1157 cachesim_I1_initcache(I1c);
1158 cachesim_D1_initcache(D1c);
1159 cachesim_L2_initcache(L2c);
1160
nethercote9313ac42004-07-06 21:54:20 +00001161 VGP_(register_profile_event)(VgpGetLineCC, "get-lineCC");
njn25e49d8e72002-09-23 09:36:25 +00001162 VGP_(register_profile_event)(VgpCacheSimulate, "cache-simulate");
1163 VGP_(register_profile_event)(VgpCacheResults, "cache-results");
njn25e49d8e72002-09-23 09:36:25 +00001164}
1165
njn26f02512004-11-22 18:33:15 +00001166VG_DETERMINE_INTERFACE_VERSION(TL_(pre_clo_init), 0)
fitzhardinge98abfc72003-12-16 02:05:15 +00001167
njn25e49d8e72002-09-23 09:36:25 +00001168/*--------------------------------------------------------------------*/
njn25cac76cb2002-09-23 11:21:57 +00001169/*--- end cg_main.c ---*/
sewardj18d75132002-05-16 11:06:21 +00001170/*--------------------------------------------------------------------*/