sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 1 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
njn | 101e572 | 2005-04-21 02:37:54 +0000 | [diff] [blame] | 3 | /*--- Cachegrind: everything but the simulation itself. ---*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 4 | /*--- cg_main.c ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 8 | This file is part of Cachegrind, a Valgrind tool for cache |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 9 | profiling programs. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 10 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 11 | Copyright (C) 2002-2005 Nicholas Nethercote |
sewardj | 3c23d43 | 2002-06-01 23:43:49 +0000 | [diff] [blame] | 12 | njn25@cam.ac.uk |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 13 | |
| 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 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 29 | The GNU General Public License is contained in the file COPYING. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 30 | */ |
| 31 | |
nethercote | 4606320 | 2004-09-02 08:51:43 +0000 | [diff] [blame] | 32 | #include "tool.h" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 33 | //#include "vg_profile.c" |
| 34 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 35 | #include "cg_arch.h" |
nethercote | 27fc1da | 2004-01-04 16:56:57 +0000 | [diff] [blame] | 36 | #include "cg_sim.c" |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 37 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 38 | /*------------------------------------------------------------*/ |
| 39 | /*--- Constants ---*/ |
| 40 | /*------------------------------------------------------------*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 41 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 42 | #define MIN_LINE_SIZE 16 |
| 43 | #define FILE_LEN 256 |
| 44 | #define FN_LEN 256 |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 45 | |
| 46 | /*------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 47 | /*--- Profiling events ---*/ |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 48 | /*------------------------------------------------------------*/ |
| 49 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 50 | typedef |
| 51 | enum { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 52 | VgpGetLineCC = VgpFini+1, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 53 | VgpCacheSimulate, |
| 54 | VgpCacheResults |
| 55 | } |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 56 | VgpToolCC; |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 57 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 58 | /*------------------------------------------------------------*/ |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 59 | /*--- Types and Data Structures ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 60 | /*------------------------------------------------------------*/ |
| 61 | |
| 62 | typedef struct _CC CC; |
| 63 | struct _CC { |
| 64 | ULong a; |
| 65 | ULong m1; |
| 66 | ULong m2; |
| 67 | }; |
| 68 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 69 | //------------------------------------------------------------ |
| 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. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 78 | |
| 79 | #define N_FILE_ENTRIES 251 |
| 80 | #define N_FN_ENTRIES 53 |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 81 | #define N_LINE_ENTRIES 37 |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 82 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 83 | typedef struct _lineCC lineCC; |
| 84 | struct _lineCC { |
| 85 | Int line; |
| 86 | CC Ir; |
| 87 | CC Dr; |
| 88 | CC Dw; |
| 89 | lineCC* next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 92 | typedef struct _fnCC fnCC; |
| 93 | struct _fnCC { |
| 94 | Char* fn; |
| 95 | fnCC* next; |
| 96 | lineCC* lines[N_LINE_ENTRIES]; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 99 | typedef struct _fileCC fileCC; |
| 100 | struct _fileCC { |
| 101 | Char* file; |
| 102 | fileCC* next; |
| 103 | fnCC* fns[N_FN_ENTRIES]; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 106 | // Top level of CC table. Auto-zeroed. |
| 107 | static fileCC *CC_table[N_FILE_ENTRIES]; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 108 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 109 | //------------------------------------------------------------ |
| 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 |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 114 | // instruction (instr_len, instr_addr, etc), plus a pointer to its line |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 115 | // CC. This node is what's passed to the simulation function. |
| 116 | // - When BBs are discarded the relevant list(instr_details) is freed. |
| 117 | |
| 118 | typedef struct _instr_info instr_info; |
| 119 | struct _instr_info { |
nethercote | ca1f2dc | 2004-07-21 08:49:02 +0000 | [diff] [blame] | 120 | Addr instr_addr; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 121 | UChar instr_len; |
nethercote | ca1f2dc | 2004-07-21 08:49:02 +0000 | [diff] [blame] | 122 | UChar data_size; |
| 123 | lineCC* parent; // parent line-CC |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | typedef struct _BB_info BB_info; |
| 127 | struct _BB_info { |
| 128 | BB_info* next; // next field |
| 129 | Addr BB_addr; // key |
| 130 | Int n_instrs; |
| 131 | instr_info instrs[0]; |
| 132 | }; |
| 133 | |
| 134 | VgHashTable instr_info_table; // hash(Addr, BB_info) |
| 135 | |
| 136 | //------------------------------------------------------------ |
| 137 | // Stats |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 138 | static Int distinct_files = 0; |
| 139 | static Int distinct_fns = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 140 | static Int distinct_lines = 0; |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 141 | static Int distinct_instrs = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 142 | |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 143 | static Int full_debug_BBs = 0; |
| 144 | static Int file_line_debug_BBs = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 145 | static Int fn_debug_BBs = 0; |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 146 | static Int no_debug_BBs = 0; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 147 | |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 148 | static Int BB_retranslations = 0; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 149 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 150 | /*------------------------------------------------------------*/ |
| 151 | /*--- CC table operations ---*/ |
| 152 | /*------------------------------------------------------------*/ |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 153 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 154 | static void get_debug_info(Addr instr_addr, Char file[FILE_LEN], |
| 155 | Char fn[FN_LEN], Int* line) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 156 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 157 | 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); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 160 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 161 | 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++; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 177 | static UInt hash(Char *s, UInt table_size) |
| 178 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 179 | 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; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 184 | } |
| 185 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 186 | static __inline__ |
| 187 | fileCC* new_fileCC(Char filename[], fileCC* next) |
nethercote | 09d853e | 2004-01-21 16:12:55 +0000 | [diff] [blame] | 188 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 189 | // 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; |
nethercote | 09d853e | 2004-01-21 16:12:55 +0000 | [diff] [blame] | 194 | } |
| 195 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 196 | static __inline__ |
| 197 | fnCC* new_fnCC(Char fn[], fnCC* next) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 198 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 199 | // 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 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 205 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 206 | static __inline__ |
| 207 | lineCC* 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 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 215 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 216 | static __inline__ |
| 217 | instr_info* new_instr_info(Addr instr_addr, lineCC* parent, instr_info* next) |
| 218 | { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 219 | // Using calloc() zeroes instr_len and data_size |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 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. |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 229 | static lineCC* get_lineCC(Addr origAddr) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 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 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 238 | get_debug_info(origAddr, file, fn, &line); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 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; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 247 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 248 | if (NULL == curr_fileCC) { |
| 249 | CC_table[file_hash] = curr_fileCC = |
| 250 | new_fileCC(file, CC_table[file_hash]); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 251 | distinct_files++; |
| 252 | } |
| 253 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 254 | // 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; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 259 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 260 | if (NULL == curr_fnCC) { |
| 261 | curr_fileCC->fns[fn_hash] = curr_fnCC = |
| 262 | new_fnCC(fn, curr_fileCC->fns[fn_hash]); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 263 | distinct_fns++; |
| 264 | } |
| 265 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 266 | // 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; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 271 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 272 | if (NULL == curr_lineCC) { |
| 273 | curr_fnCC->lines[line_hash] = curr_lineCC = |
| 274 | new_lineCC(line, curr_fnCC->lines[line_hash]); |
| 275 | distinct_lines++; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 276 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 277 | |
| 278 | VGP_POPCC(VgpGetLineCC); |
| 279 | return curr_lineCC; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /*------------------------------------------------------------*/ |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 283 | /*--- Cache simulation functions ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 284 | /*------------------------------------------------------------*/ |
| 285 | |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 286 | static VGA_REGPARM(1) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 287 | void log_1I_0D_cache_access(instr_info* n) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 288 | { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 289 | //VG_(printf)("1I_0D : CCaddr=0x%x, iaddr=0x%x, isize=%u\n", |
| 290 | // n, n->instr_addr, n->instr_len); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 291 | VGP_PUSHCC(VgpCacheSimulate); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 292 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 293 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 294 | n->parent->Ir.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 295 | VGP_POPCC(VgpCacheSimulate); |
| 296 | } |
| 297 | |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 298 | static VGA_REGPARM(2) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 299 | void log_1I_1Dr_cache_access(instr_info* n, Addr data_addr) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 300 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 301 | //VG_(printf)("1I_1Dr: CCaddr=%p, iaddr=%p, isize=%u, daddr=%p, dsize=%u\n", |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 302 | // n, n->instr_addr, n->instr_len, data_addr, n->data_size); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 303 | VGP_PUSHCC(VgpCacheSimulate); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 304 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 305 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 306 | n->parent->Ir.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 307 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 308 | cachesim_D1_doref(data_addr, n->data_size, |
| 309 | &n->parent->Dr.m1, &n->parent->Dr.m2); |
| 310 | n->parent->Dr.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 311 | VGP_POPCC(VgpCacheSimulate); |
| 312 | } |
| 313 | |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 314 | static VGA_REGPARM(2) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 315 | void log_1I_1Dw_cache_access(instr_info* n, Addr data_addr) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 316 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 317 | //VG_(printf)("1I_1Dw: CCaddr=%p, iaddr=%p, isize=%u, daddr=%p, dsize=%u\n", |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 318 | // n, n->instr_addr, n->instr_len, data_addr, n->data_size); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 319 | VGP_PUSHCC(VgpCacheSimulate); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 320 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 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++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 327 | VGP_POPCC(VgpCacheSimulate); |
| 328 | } |
| 329 | |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 330 | static VGA_REGPARM(3) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 331 | void log_1I_2D_cache_access(instr_info* n, Addr data_addr1, Addr data_addr2) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 332 | { |
| 333 | //VG_(printf)("1I_2D: CCaddr=%p, iaddr=%p, isize=%u, daddr1=%p, daddr2=%p, dsize=%u\n", |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 334 | // n, n->instr_addr, n->instr_len, data_addr1, data_addr2, n->data_size); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 335 | VGP_PUSHCC(VgpCacheSimulate); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 336 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 337 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 338 | n->parent->Ir.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 339 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 340 | 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++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 346 | VGP_POPCC(VgpCacheSimulate); |
| 347 | } |
| 348 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 349 | /*------------------------------------------------------------*/ |
| 350 | /*--- Instrumentation ---*/ |
| 351 | /*------------------------------------------------------------*/ |
| 352 | |
nethercote | 564b2b0 | 2004-08-07 15:54:53 +0000 | [diff] [blame] | 353 | static |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 354 | BB_info* get_BB_info(IRBB* bbIn, Addr origAddr, Bool* bbSeenBefore) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 355 | { |
| 356 | Int i, n_instrs; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 357 | IRStmt* st; |
| 358 | BB_info* bbInfo; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 359 | VgHashNode** dummy; |
| 360 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 361 | // Count number of original instrs in BB |
| 362 | n_instrs = 0; |
| 363 | for (i = 0; i < bbIn->stmts_used; i++) { |
| 364 | st = bbIn->stmts[i]; |
| 365 | if (Ist_IMark == st->tag) n_instrs++; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | // Get the BB_info |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 369 | bbInfo = (BB_info*)VG_(HT_get_node)(instr_info_table, origAddr, &dummy); |
| 370 | *bbSeenBefore = ( NULL == bbInfo ? False : True ); |
| 371 | if (*bbSeenBefore) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 372 | // BB must have been translated before, but flushed from the TT |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 373 | tl_assert(bbInfo->n_instrs == n_instrs ); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 374 | BB_retranslations++; |
| 375 | } else { |
| 376 | // BB never translated before (at this address, at least; could have |
| 377 | // been unloaded and then reloaded elsewhere in memory) |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 378 | bbInfo = VG_(calloc)(1, sizeof(BB_info) + n_instrs*sizeof(instr_info)); |
| 379 | bbInfo->BB_addr = origAddr; |
| 380 | bbInfo->n_instrs = n_instrs; |
| 381 | VG_(HT_add_node)( instr_info_table, (VgHashNode*)bbInfo ); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 382 | distinct_instrs++; |
| 383 | } |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 384 | return bbInfo; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 385 | } |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 386 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 387 | static |
| 388 | void handleOneStatement(IRTypeEnv* tyenv, IRBB* bbOut, IRStmt* st, |
| 389 | Addr* instrAddr, UInt* instrLen, |
| 390 | IRExpr** loadAddrExpr, IRExpr** storeAddrExpr, |
| 391 | UInt* dataSize) |
| 392 | { |
sewardj | 7f4a862 | 2005-03-26 21:55:21 +0000 | [diff] [blame] | 393 | tl_assert(isFlatIRStmt(st)); |
| 394 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 395 | switch (st->tag) { |
sewardj | 21dc345 | 2005-03-21 00:27:41 +0000 | [diff] [blame] | 396 | case Ist_NoOp: |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 397 | break; |
| 398 | |
| 399 | case Ist_IMark: |
sewardj | 2b641fe | 2005-03-21 11:53:38 +0000 | [diff] [blame] | 400 | /* st->Ist.IMark.addr is a 64-bit int. ULong_to_Ptr casts this |
| 401 | to the host's native pointer type; if that is 32 bits then it |
| 402 | discards the upper 32 bits. If we are cachegrinding on a |
| 403 | 32-bit host then we are also ensured that the guest word size |
| 404 | is 32 bits, due to the assertion in TL_(instrument) that the |
| 405 | host and guest word sizes must be the same. Hence |
| 406 | st->Ist.IMark.addr will have been derived from a 32-bit guest |
| 407 | code address and truncation of it is safe. I believe this |
| 408 | assignment should be correct for both 32- and 64-bit |
| 409 | machines. */ |
| 410 | *instrAddr = (Addr)ULong_to_Ptr(st->Ist.IMark.addr); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 411 | *instrLen = st->Ist.IMark.len; |
| 412 | addStmtToIRBB( bbOut, st ); |
| 413 | break; |
| 414 | |
| 415 | case Ist_Tmp: { |
| 416 | IRExpr* data = st->Ist.Tmp.data; |
| 417 | if (data->tag == Iex_LDle) { |
| 418 | IRExpr* aexpr = data->Iex.LDle.addr; |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 419 | tl_assert( isIRAtom(aexpr) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 420 | |
| 421 | // XXX: repe cmpsb does two loads... the first one is ignored here! |
| 422 | //tl_assert( NULL == *loadAddrExpr ); // XXX: ??? |
| 423 | *loadAddrExpr = aexpr; |
| 424 | *dataSize = sizeofIRType(data->Iex.LDle.ty); |
| 425 | } |
| 426 | addStmtToIRBB( bbOut, st ); |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | case Ist_STle: { |
| 431 | IRExpr* data = st->Ist.STle.data; |
| 432 | IRExpr* aexpr = st->Ist.STle.addr; |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 433 | tl_assert( isIRAtom(aexpr) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 434 | tl_assert( NULL == *storeAddrExpr ); // XXX: ??? |
| 435 | *storeAddrExpr = aexpr; |
| 436 | *dataSize = sizeofIRType(typeOfIRExpr(tyenv, data)); |
| 437 | addStmtToIRBB( bbOut, st ); |
| 438 | break; |
| 439 | } |
| 440 | |
sewardj | 7f4a862 | 2005-03-26 21:55:21 +0000 | [diff] [blame] | 441 | case Ist_Dirty: { |
| 442 | IRDirty* d = st->Ist.Dirty.details; |
| 443 | if (d->mFx != Ifx_None) { |
| 444 | /* This dirty helper accesses memory. Collect the |
| 445 | details. */ |
| 446 | tl_assert(d->mAddr != NULL); |
| 447 | tl_assert(d->mSize != 0); |
| 448 | *dataSize = d->mSize; |
| 449 | if (d->mFx == Ifx_Read || d->mFx == Ifx_Modify) |
| 450 | *loadAddrExpr = d->mAddr; |
| 451 | if (d->mFx == Ifx_Write || d->mFx == Ifx_Modify) |
| 452 | *storeAddrExpr = d->mAddr; |
| 453 | } else { |
| 454 | tl_assert(d->mAddr == NULL); |
| 455 | tl_assert(d->mSize == 0); |
| 456 | } |
| 457 | addStmtToIRBB( bbOut, st ); |
| 458 | break; |
| 459 | } |
| 460 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 461 | case Ist_Put: |
| 462 | case Ist_PutI: |
| 463 | case Ist_Exit: |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 464 | case Ist_MFence: |
| 465 | addStmtToIRBB( bbOut, st ); |
| 466 | break; |
| 467 | |
| 468 | default: |
| 469 | VG_(printf)("\n"); |
| 470 | ppIRStmt(st); |
| 471 | VG_(printf)("\n"); |
| 472 | VG_(tool_panic)("Cachegrind: unhandled IRStmt"); |
| 473 | } |
| 474 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 475 | |
nethercote | 564b2b0 | 2004-08-07 15:54:53 +0000 | [diff] [blame] | 476 | static |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 477 | void do_details( instr_info* n, Bool bbSeenBefore, |
| 478 | Addr instr_addr, Int instr_len, Int data_size ) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 479 | { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 480 | if (bbSeenBefore) { |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 481 | tl_assert( n->instr_addr == instr_addr ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 482 | tl_assert( n->instr_len == instr_len ); |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 483 | tl_assert( n->data_size == data_size ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 484 | // Don't check that (n->parent == parent)... it's conceivable that |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 485 | // the debug info might change; the other asserts should be enough to |
| 486 | // detect anything strange. |
| 487 | } else { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 488 | lineCC* parent = get_lineCC(instr_addr); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 489 | n->instr_addr = instr_addr; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 490 | n->instr_len = instr_len; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 491 | n->data_size = data_size; |
| 492 | n->parent = parent; |
| 493 | } |
| 494 | } |
| 495 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 496 | static Bool loadStoreAddrsMatch(IRExpr* loadAddrExpr, IRExpr* storeAddrExpr) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 497 | { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 498 | // I'm assuming that for 'modify' instructions, that Vex always makes |
| 499 | // the loadAddrExpr and storeAddrExpr be of the same type, ie. both Tmp |
| 500 | // expressions, or both Const expressions. |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 501 | tl_assert(isIRAtom(loadAddrExpr)); |
| 502 | tl_assert(isIRAtom(storeAddrExpr)); |
| 503 | return eqIRAtom(loadAddrExpr, storeAddrExpr); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | // Instrumentation for the end of each original instruction. |
| 507 | static |
| 508 | void endOfInstr(IRBB* bbOut, instr_info* i_node, Bool bbSeenBefore, |
| 509 | UInt instrAddr, UInt instrLen, UInt dataSize, |
| 510 | IRExpr* loadAddrExpr, IRExpr* storeAddrExpr) |
| 511 | { |
| 512 | IRDirty* di; |
| 513 | IRExpr *arg1, *arg2, *arg3, **argv; |
| 514 | Int argc; |
| 515 | Char* helperName; |
| 516 | void* helperAddr; |
sewardj | 17a56bf | 2005-03-21 01:35:02 +0000 | [diff] [blame] | 517 | IRType wordTy; |
| 518 | |
| 519 | // Stay sane ... |
| 520 | tl_assert(sizeof(HWord) == sizeof(void*)); |
| 521 | if (sizeof(HWord) == 4) { |
| 522 | wordTy = Ity_I32; |
| 523 | } else |
| 524 | if (sizeof(HWord) == 8) { |
| 525 | wordTy = Ity_I64; |
| 526 | } else { |
| 527 | VG_(tool_panic)("endOfInstr: strange word size"); |
| 528 | } |
| 529 | |
| 530 | if (loadAddrExpr) |
| 531 | tl_assert(wordTy == typeOfIRExpr(bbOut->tyenv, loadAddrExpr)); |
| 532 | if (storeAddrExpr) |
| 533 | tl_assert(wordTy == typeOfIRExpr(bbOut->tyenv, storeAddrExpr)); |
| 534 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 535 | |
| 536 | // Nb: instrLen will be zero if Vex failed to decode it. |
| 537 | tl_assert( 0 == instrLen || |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 538 | (instrLen >= VGA_MIN_INSTR_SIZE && |
| 539 | instrLen <= VGA_MAX_INSTR_SIZE) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 540 | |
njn | 016712a | 2005-04-04 02:52:16 +0000 | [diff] [blame] | 541 | // Large (eg. 28B, 108B, 512B on x86) data-sized instructions will be |
| 542 | // done inaccurately, but they're very rare and this avoids errors from |
| 543 | // hitting more than two cache lines in the simulation. |
| 544 | if (dataSize > MIN_LINE_SIZE) dataSize = MIN_LINE_SIZE; |
| 545 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 546 | // Setup 1st arg: instr_info node's address |
sewardj | 17a56bf | 2005-03-21 01:35:02 +0000 | [diff] [blame] | 547 | // Believed to be 64-bit clean |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 548 | do_details(i_node, bbSeenBefore, instrAddr, instrLen, dataSize ); |
sewardj | 17a56bf | 2005-03-21 01:35:02 +0000 | [diff] [blame] | 549 | arg1 = mkIRExpr_HWord( (HWord)i_node ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 550 | |
| 551 | if (!loadAddrExpr && !storeAddrExpr) { |
| 552 | // no load/store |
| 553 | tl_assert(0 == dataSize); |
| 554 | helperName = "log_1I_0D_cache_access"; |
| 555 | helperAddr = &log_1I_0D_cache_access; |
| 556 | argc = 1; |
| 557 | argv = mkIRExprVec_1(arg1); |
| 558 | |
| 559 | } else if (loadAddrExpr && !storeAddrExpr) { |
| 560 | // load |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 561 | tl_assert( isIRAtom(loadAddrExpr) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 562 | helperName = "log_1I_1Dr_cache_access"; |
| 563 | helperAddr = &log_1I_1Dr_cache_access; |
| 564 | argc = 2; |
| 565 | arg2 = loadAddrExpr; |
| 566 | argv = mkIRExprVec_2(arg1, arg2); |
| 567 | |
| 568 | } else if (!loadAddrExpr && storeAddrExpr) { |
| 569 | // store |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 570 | tl_assert( isIRAtom(storeAddrExpr) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 571 | helperName = "log_1I_1Dw_cache_access"; |
| 572 | helperAddr = &log_1I_1Dw_cache_access; |
| 573 | argc = 2; |
| 574 | arg2 = storeAddrExpr; |
| 575 | argv = mkIRExprVec_2(arg1, arg2); |
| 576 | |
| 577 | } else { |
| 578 | tl_assert( loadAddrExpr && storeAddrExpr ); |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 579 | tl_assert( isIRAtom(loadAddrExpr) ); |
| 580 | tl_assert( isIRAtom(storeAddrExpr) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 581 | |
| 582 | if ( loadStoreAddrsMatch(loadAddrExpr, storeAddrExpr) ) { |
| 583 | // modify |
| 584 | helperName = "log_1I_1Dr_cache_access"; |
| 585 | helperAddr = &log_1I_1Dr_cache_access; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 586 | argc = 2; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 587 | arg2 = loadAddrExpr; |
| 588 | argv = mkIRExprVec_2(arg1, arg2); |
| 589 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 590 | } else { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 591 | // load/store |
| 592 | helperName = "log_1I_2D_cache_access"; |
| 593 | helperAddr = &log_1I_2D_cache_access; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 594 | argc = 3; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 595 | arg2 = loadAddrExpr; |
| 596 | arg3 = storeAddrExpr; |
| 597 | argv = mkIRExprVec_3(arg1, arg2, arg3); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 601 | // Add call to the instrumentation function |
| 602 | di = unsafeIRDirty_0_N( argc, helperName, helperAddr, argv); |
| 603 | addStmtToIRBB( bbOut, IRStmt_Dirty(di) ); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 604 | } |
njn | 14d01ce | 2004-11-26 11:30:14 +0000 | [diff] [blame] | 605 | |
sewardj | d54babf | 2005-03-21 00:55:49 +0000 | [diff] [blame] | 606 | IRBB* TL_(instrument) ( IRBB* bbIn, VexGuestLayout* layout, |
| 607 | IRType gWordTy, IRType hWordTy ) |
njn | 14d01ce | 2004-11-26 11:30:14 +0000 | [diff] [blame] | 608 | { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 609 | Int i, dataSize = 0, bbInfo_i; |
| 610 | IRBB* bbOut; |
| 611 | IRStmt* st; |
| 612 | BB_info* bbInfo; |
| 613 | Bool bbSeenBefore = False; |
| 614 | Addr instrAddr, origAddr; |
| 615 | UInt instrLen; |
| 616 | IRExpr *loadAddrExpr, *storeAddrExpr; |
| 617 | |
sewardj | d54babf | 2005-03-21 00:55:49 +0000 | [diff] [blame] | 618 | if (gWordTy != hWordTy) { |
| 619 | /* We don't currently support this case. */ |
| 620 | VG_(tool_panic)("host/guest word size mismatch"); |
| 621 | } |
| 622 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 623 | /* Set up BB */ |
| 624 | bbOut = emptyIRBB(); |
| 625 | bbOut->tyenv = dopyIRTypeEnv(bbIn->tyenv); |
| 626 | bbOut->next = dopyIRExpr(bbIn->next); |
| 627 | bbOut->jumpkind = bbIn->jumpkind; |
| 628 | |
| 629 | // Get the first statement, and origAddr from it |
| 630 | i = 0; |
| 631 | tl_assert(bbIn->stmts_used > 0); |
| 632 | st = bbIn->stmts[0]; |
| 633 | tl_assert(Ist_IMark == st->tag); |
| 634 | origAddr = (Addr)st->Ist.IMark.addr; |
| 635 | tl_assert(origAddr == st->Ist.IMark.addr); // XXX: check no overflow |
| 636 | |
| 637 | // Get block info |
| 638 | bbInfo = get_BB_info(bbIn, origAddr, &bbSeenBefore); |
| 639 | bbInfo_i = 0; |
| 640 | |
| 641 | do { |
| 642 | // We should be at an IMark statement |
| 643 | tl_assert(Ist_IMark == st->tag); |
| 644 | |
| 645 | // Reset stuff for this original instruction |
| 646 | loadAddrExpr = storeAddrExpr = NULL; |
| 647 | dataSize = 0; |
| 648 | |
| 649 | // Process all the statements for this original instruction (ie. until |
| 650 | // the next IMark statement, or the end of the block) |
| 651 | do { |
| 652 | handleOneStatement(bbIn->tyenv, bbOut, st, &instrAddr, &instrLen, |
| 653 | &loadAddrExpr, &storeAddrExpr, &dataSize); |
| 654 | i++; |
| 655 | st = ( i < bbIn->stmts_used ? bbIn->stmts[i] : NULL ); |
| 656 | } |
| 657 | while (st && Ist_IMark != st->tag); |
| 658 | |
| 659 | // Add instrumentation for this original instruction. |
| 660 | endOfInstr(bbOut, &bbInfo->instrs[ bbInfo_i ], bbSeenBefore, |
| 661 | instrAddr, instrLen, dataSize, loadAddrExpr, storeAddrExpr); |
| 662 | |
| 663 | bbInfo_i++; |
| 664 | } |
| 665 | while (st); |
| 666 | |
| 667 | return bbOut; |
njn | 14d01ce | 2004-11-26 11:30:14 +0000 | [diff] [blame] | 668 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 669 | |
| 670 | /*------------------------------------------------------------*/ |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 671 | /*--- Cache configuration ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 672 | /*------------------------------------------------------------*/ |
| 673 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 674 | #define UNDEFINED_CACHE { -1, -1, -1 } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 675 | |
| 676 | static cache_t clo_I1_cache = UNDEFINED_CACHE; |
| 677 | static cache_t clo_D1_cache = UNDEFINED_CACHE; |
| 678 | static cache_t clo_L2_cache = UNDEFINED_CACHE; |
| 679 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 680 | /* Checks cache config is ok; makes it so if not. */ |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 681 | static |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 682 | void check_cache(cache_t* cache, Char *name) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 683 | { |
| 684 | /* First check they're all powers of two */ |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 685 | if (-1 == VG_(log2)(cache->size)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 686 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 687 | "error: %s size of %dB not a power of two; aborting.", |
| 688 | name, cache->size); |
| 689 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 690 | } |
| 691 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 692 | if (-1 == VG_(log2)(cache->assoc)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 693 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 694 | "error: %s associativity of %d not a power of two; aborting.", |
| 695 | name, cache->assoc); |
| 696 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 697 | } |
| 698 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 699 | if (-1 == VG_(log2)(cache->line_size)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 700 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 701 | "error: %s line size of %dB not a power of two; aborting.", |
| 702 | name, cache->line_size); |
| 703 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 704 | } |
| 705 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 706 | // Then check line size >= 16 -- any smaller and a single instruction could |
| 707 | // straddle three cache lines, which breaks a simulation assertion and is |
| 708 | // stupid anyway. |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 709 | if (cache->line_size < MIN_LINE_SIZE) { |
| 710 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 711 | "error: %s line size of %dB too small; aborting.", |
| 712 | name, cache->line_size); |
| 713 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | /* Then check cache size > line size (causes seg faults if not). */ |
| 717 | if (cache->size <= cache->line_size) { |
| 718 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 719 | "error: %s cache size of %dB <= line size of %dB; aborting.", |
| 720 | name, cache->size, cache->line_size); |
| 721 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | /* Then check assoc <= (size / line size) (seg faults otherwise). */ |
| 725 | if (cache->assoc > (cache->size / cache->line_size)) { |
| 726 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 727 | "warning: %s associativity > (size / line size); aborting.", name); |
| 728 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 732 | static |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 733 | void configure_caches(cache_t* I1c, cache_t* D1c, cache_t* L2c) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 734 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 735 | #define DEFINED(L) (-1 != L.size || -1 != L.assoc || -1 != L.line_size) |
| 736 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 737 | Int n_clos = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 738 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 739 | // Count how many were defined on the command line. |
| 740 | if (DEFINED(clo_I1_cache)) { n_clos++; } |
| 741 | if (DEFINED(clo_D1_cache)) { n_clos++; } |
| 742 | if (DEFINED(clo_L2_cache)) { n_clos++; } |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 743 | |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 744 | // Set the cache config (using auto-detection, if supported by the |
| 745 | // architecture) |
| 746 | VGA_(configure_caches)( I1c, D1c, L2c, (3 == n_clos) ); |
sewardj | b1a77a4 | 2002-07-13 13:31:20 +0000 | [diff] [blame] | 747 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 748 | // Then replace with any defined on the command line. |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 749 | if (DEFINED(clo_I1_cache)) { *I1c = clo_I1_cache; } |
| 750 | if (DEFINED(clo_D1_cache)) { *D1c = clo_D1_cache; } |
| 751 | if (DEFINED(clo_L2_cache)) { *L2c = clo_L2_cache; } |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 752 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 753 | // Then check values and fix if not acceptable. |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 754 | check_cache(I1c, "I1"); |
| 755 | check_cache(D1c, "D1"); |
| 756 | check_cache(L2c, "L2"); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 757 | |
| 758 | if (VG_(clo_verbosity) > 1) { |
| 759 | VG_(message)(Vg_UserMsg, "Cache configuration used:"); |
| 760 | VG_(message)(Vg_UserMsg, " I1: %dB, %d-way, %dB lines", |
| 761 | I1c->size, I1c->assoc, I1c->line_size); |
| 762 | VG_(message)(Vg_UserMsg, " D1: %dB, %d-way, %dB lines", |
| 763 | D1c->size, D1c->assoc, D1c->line_size); |
| 764 | VG_(message)(Vg_UserMsg, " L2: %dB, %d-way, %dB lines", |
| 765 | L2c->size, L2c->assoc, L2c->line_size); |
| 766 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 767 | #undef CMD_LINE_DEFINED |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 768 | } |
| 769 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 770 | /*------------------------------------------------------------*/ |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 771 | /*--- TL_(fini)() and related function ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 772 | /*------------------------------------------------------------*/ |
| 773 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 774 | // Total reads/writes/misses. Calculated during CC traversal at the end. |
| 775 | // All auto-zeroed. |
| 776 | static CC Ir_total; |
| 777 | static CC Dr_total; |
| 778 | static CC Dw_total; |
| 779 | |
| 780 | static Char* cachegrind_out_file; |
| 781 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 782 | static void fprint_lineCC(Int fd, lineCC* n) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 783 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 784 | Char buf[512]; |
| 785 | VG_(sprintf)(buf, "%u %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
| 786 | n->line, |
| 787 | n->Ir.a, n->Ir.m1, n->Ir.m2, |
| 788 | n->Dr.a, n->Dr.m1, n->Dr.m2, |
| 789 | n->Dw.a, n->Dw.m1, n->Dw.m2); |
| 790 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 791 | |
| 792 | Ir_total.a += n->Ir.a; Ir_total.m1 += n->Ir.m1; Ir_total.m2 += n->Ir.m2; |
| 793 | Dr_total.a += n->Dr.a; Dr_total.m1 += n->Dr.m1; Dr_total.m2 += n->Dr.m2; |
| 794 | Dw_total.a += n->Dw.a; Dw_total.m1 += n->Dw.m1; Dw_total.m2 += n->Dw.m2; |
| 795 | } |
| 796 | |
| 797 | static void fprint_CC_table_and_calc_totals(void) |
| 798 | { |
| 799 | Int fd; |
| 800 | Char buf[512]; |
| 801 | fileCC *curr_fileCC; |
| 802 | fnCC *curr_fnCC; |
| 803 | lineCC *curr_lineCC; |
| 804 | Int i, j, k; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 805 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 806 | VGP_PUSHCC(VgpCacheResults); |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 807 | |
njn | db918dd | 2003-07-22 20:45:11 +0000 | [diff] [blame] | 808 | fd = VG_(open)(cachegrind_out_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY, |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 809 | VKI_S_IRUSR|VKI_S_IWUSR); |
nethercote | 50da0f3 | 2003-10-30 10:33:30 +0000 | [diff] [blame] | 810 | if (fd < 0) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 811 | // If the file can't be opened for whatever reason (conflict |
| 812 | // between multiple cachegrinded processes?), give up now. |
njn | ee0e6a3 | 2005-04-24 00:21:01 +0000 | [diff] [blame^] | 813 | VG_(message)(Vg_UserMsg, |
| 814 | "error: can't open cache simulation output file `%s'", |
| 815 | cachegrind_out_file ); |
| 816 | VG_(message)(Vg_UserMsg, |
| 817 | " ... so simulation results will be missing."); |
sewardj | 0744b6c | 2002-12-11 00:45:42 +0000 | [diff] [blame] | 818 | return; |
| 819 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 820 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 821 | // "desc:" lines (giving I1/D1/L2 cache configuration). The spaces after |
| 822 | // the 2nd colon makes cg_annotate's output look nicer. |
| 823 | VG_(sprintf)(buf, "desc: I1 cache: %s\n" |
| 824 | "desc: D1 cache: %s\n" |
| 825 | "desc: L2 cache: %s\n", |
| 826 | I1.desc_line, D1.desc_line, L2.desc_line); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 827 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 828 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 829 | // "cmd:" line |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 830 | VG_(strcpy)(buf, "cmd:"); |
| 831 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 832 | for (i = 0; i < VG_(client_argc); i++) { |
thughes | 6f7eb9c | 2004-10-06 13:50:12 +0000 | [diff] [blame] | 833 | VG_(write)(fd, " ", 1); |
thughes | 30c43d8 | 2004-10-06 13:49:36 +0000 | [diff] [blame] | 834 | VG_(write)(fd, VG_(client_argv)[i], VG_(strlen)(VG_(client_argv)[i])); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 835 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 836 | // "events:" line |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 837 | VG_(sprintf)(buf, "\nevents: Ir I1mr I2mr Dr D1mr D2mr Dw D1mw D2mw\n"); |
| 838 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 839 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 840 | // Six loops here: three for the hash table arrays, and three for the |
| 841 | // chains hanging off the hash table arrays. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 842 | for (i = 0; i < N_FILE_ENTRIES; i++) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 843 | curr_fileCC = CC_table[i]; |
| 844 | while (curr_fileCC != NULL) { |
| 845 | VG_(sprintf)(buf, "fl=%s\n", curr_fileCC->file); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 846 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 847 | |
| 848 | for (j = 0; j < N_FN_ENTRIES; j++) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 849 | curr_fnCC = curr_fileCC->fns[j]; |
| 850 | while (curr_fnCC != NULL) { |
| 851 | VG_(sprintf)(buf, "fn=%s\n", curr_fnCC->fn); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 852 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 853 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 854 | for (k = 0; k < N_LINE_ENTRIES; k++) { |
| 855 | curr_lineCC = curr_fnCC->lines[k]; |
| 856 | while (curr_lineCC != NULL) { |
| 857 | fprint_lineCC(fd, curr_lineCC); |
| 858 | curr_lineCC = curr_lineCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 859 | } |
| 860 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 861 | curr_fnCC = curr_fnCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 862 | } |
| 863 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 864 | curr_fileCC = curr_fileCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 868 | // Summary stats must come after rest of table, since we calculate them |
| 869 | // during traversal. */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 870 | VG_(sprintf)(buf, "summary: " |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 871 | "%llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 872 | Ir_total.a, Ir_total.m1, Ir_total.m2, |
| 873 | Dr_total.a, Dr_total.m1, Dr_total.m2, |
| 874 | Dw_total.a, Dw_total.m1, Dw_total.m2); |
| 875 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 876 | VG_(close)(fd); |
| 877 | } |
| 878 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 879 | static UInt ULong_width(ULong n) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 880 | { |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 881 | UInt w = 0; |
| 882 | while (n > 0) { |
| 883 | n = n / 10; |
| 884 | w++; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 885 | } |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 886 | return w + (w-1)/3; // add space for commas |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 887 | } |
| 888 | |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 889 | static |
daywalker | 8ad1a40 | 2003-09-18 01:15:32 +0000 | [diff] [blame] | 890 | void percentify(Int n, Int ex, Int field_width, char buf[]) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 891 | { |
| 892 | int i, len, space; |
| 893 | |
daywalker | 8ad1a40 | 2003-09-18 01:15:32 +0000 | [diff] [blame] | 894 | VG_(sprintf)(buf, "%d.%d%%", n / ex, n % ex); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 895 | len = VG_(strlen)(buf); |
| 896 | space = field_width - len; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 897 | if (space < 0) space = 0; /* Allow for v. small field_width */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 898 | i = len; |
| 899 | |
| 900 | /* Right justify in field */ |
| 901 | for ( ; i >= 0; i--) buf[i + space] = buf[i]; |
| 902 | for (i = 0; i < space; i++) buf[i] = ' '; |
| 903 | } |
| 904 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 905 | void TL_(fini)(Int exitcode) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 906 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 907 | static char buf1[128], buf2[128], buf3[128], fmt [128]; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 908 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 909 | CC D_total; |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 910 | ULong L2_total_m, L2_total_mr, L2_total_mw, |
| 911 | L2_total, L2_total_r, L2_total_w; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 912 | Int l1, l2, l3; |
| 913 | Int p; |
| 914 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 915 | fprint_CC_table_and_calc_totals(); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 916 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 917 | if (VG_(clo_verbosity) == 0) |
| 918 | return; |
| 919 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 920 | /* I cache results. Use the I_refs value to determine the first column |
| 921 | * width. */ |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 922 | l1 = ULong_width(Ir_total.a); |
| 923 | l2 = ULong_width(Dr_total.a); |
| 924 | l3 = ULong_width(Dw_total.a); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 925 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 926 | /* Make format string, getting width right for numbers */ |
| 927 | VG_(sprintf)(fmt, "%%s %%,%dld", l1); |
| 928 | |
| 929 | VG_(message)(Vg_UserMsg, fmt, "I refs: ", Ir_total.a); |
| 930 | VG_(message)(Vg_UserMsg, fmt, "I1 misses: ", Ir_total.m1); |
| 931 | VG_(message)(Vg_UserMsg, fmt, "L2i misses: ", Ir_total.m2); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 932 | |
| 933 | p = 100; |
| 934 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 935 | if (0 == Ir_total.a) Ir_total.a = 1; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 936 | percentify(Ir_total.m1 * 100 * p / Ir_total.a, p, l1+1, buf1); |
| 937 | VG_(message)(Vg_UserMsg, "I1 miss rate: %s", buf1); |
| 938 | |
| 939 | percentify(Ir_total.m2 * 100 * p / Ir_total.a, p, l1+1, buf1); |
| 940 | VG_(message)(Vg_UserMsg, "L2i miss rate: %s", buf1); |
| 941 | VG_(message)(Vg_UserMsg, ""); |
| 942 | |
| 943 | /* D cache results. Use the D_refs.rd and D_refs.wr values to determine the |
| 944 | * width of columns 2 & 3. */ |
| 945 | D_total.a = Dr_total.a + Dw_total.a; |
| 946 | D_total.m1 = Dr_total.m1 + Dw_total.m1; |
| 947 | D_total.m2 = Dr_total.m2 + Dw_total.m2; |
| 948 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 949 | /* Make format string, getting width right for numbers */ |
| 950 | VG_(sprintf)(fmt, "%%s %%,%dld (%%,%dld rd + %%,%dld wr)", l1, l2, l3); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 951 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 952 | VG_(message)(Vg_UserMsg, fmt, "D refs: ", |
| 953 | D_total.a, Dr_total.a, Dw_total.a); |
| 954 | VG_(message)(Vg_UserMsg, fmt, "D1 misses: ", |
| 955 | D_total.m1, Dr_total.m1, Dw_total.m1); |
| 956 | VG_(message)(Vg_UserMsg, fmt, "L2d misses: ", |
| 957 | D_total.m2, Dr_total.m2, Dw_total.m2); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 958 | |
| 959 | p = 10; |
| 960 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 961 | if (0 == D_total.a) D_total.a = 1; |
| 962 | if (0 == Dr_total.a) Dr_total.a = 1; |
| 963 | if (0 == Dw_total.a) Dw_total.a = 1; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 964 | percentify( D_total.m1 * 100 * p / D_total.a, p, l1+1, buf1); |
| 965 | percentify(Dr_total.m1 * 100 * p / Dr_total.a, p, l2+1, buf2); |
| 966 | percentify(Dw_total.m1 * 100 * p / Dw_total.a, p, l3+1, buf3); |
| 967 | VG_(message)(Vg_UserMsg, "D1 miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 968 | |
| 969 | percentify( D_total.m2 * 100 * p / D_total.a, p, l1+1, buf1); |
| 970 | percentify(Dr_total.m2 * 100 * p / Dr_total.a, p, l2+1, buf2); |
| 971 | percentify(Dw_total.m2 * 100 * p / Dw_total.a, p, l3+1, buf3); |
| 972 | VG_(message)(Vg_UserMsg, "L2d miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 973 | VG_(message)(Vg_UserMsg, ""); |
| 974 | |
| 975 | /* L2 overall results */ |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 976 | |
| 977 | L2_total = Dr_total.m1 + Dw_total.m1 + Ir_total.m1; |
| 978 | L2_total_r = Dr_total.m1 + Ir_total.m1; |
| 979 | L2_total_w = Dw_total.m1; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 980 | VG_(message)(Vg_UserMsg, fmt, "L2 refs: ", |
| 981 | L2_total, L2_total_r, L2_total_w); |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 982 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 983 | L2_total_m = Dr_total.m2 + Dw_total.m2 + Ir_total.m2; |
| 984 | L2_total_mr = Dr_total.m2 + Ir_total.m2; |
| 985 | L2_total_mw = Dw_total.m2; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 986 | VG_(message)(Vg_UserMsg, fmt, "L2 misses: ", |
| 987 | L2_total_m, L2_total_mr, L2_total_mw); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 988 | |
| 989 | percentify(L2_total_m * 100 * p / (Ir_total.a + D_total.a), p, l1+1, buf1); |
| 990 | percentify(L2_total_mr * 100 * p / (Ir_total.a + Dr_total.a), p, l2+1, buf2); |
| 991 | percentify(L2_total_mw * 100 * p / Dw_total.a, p, l3+1, buf3); |
| 992 | VG_(message)(Vg_UserMsg, "L2 miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 993 | |
| 994 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 995 | // Various stats |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 996 | if (VG_(clo_verbosity) > 1) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 997 | int BB_lookups = full_debug_BBs + fn_debug_BBs + |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 998 | file_line_debug_BBs + no_debug_BBs; |
| 999 | |
| 1000 | VG_(message)(Vg_DebugMsg, ""); |
| 1001 | VG_(message)(Vg_DebugMsg, "Distinct files: %d", distinct_files); |
| 1002 | VG_(message)(Vg_DebugMsg, "Distinct fns: %d", distinct_fns); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1003 | VG_(message)(Vg_DebugMsg, "Distinct lines: %d", distinct_lines); |
| 1004 | VG_(message)(Vg_DebugMsg, "Distinct instrs: %d", distinct_instrs); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1005 | VG_(message)(Vg_DebugMsg, "BB lookups: %d", BB_lookups); |
| 1006 | VG_(message)(Vg_DebugMsg, "With full debug info:%3d%% (%d)", |
| 1007 | full_debug_BBs * 100 / BB_lookups, |
| 1008 | full_debug_BBs); |
| 1009 | VG_(message)(Vg_DebugMsg, "With file/line debug info:%3d%% (%d)", |
| 1010 | file_line_debug_BBs * 100 / BB_lookups, |
| 1011 | file_line_debug_BBs); |
| 1012 | VG_(message)(Vg_DebugMsg, "With fn name debug info:%3d%% (%d)", |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1013 | fn_debug_BBs * 100 / BB_lookups, |
| 1014 | fn_debug_BBs); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1015 | VG_(message)(Vg_DebugMsg, "With no debug info:%3d%% (%d)", |
| 1016 | no_debug_BBs * 100 / BB_lookups, |
| 1017 | no_debug_BBs); |
| 1018 | VG_(message)(Vg_DebugMsg, "BBs Retranslated: %d", BB_retranslations); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1019 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1020 | VGP_POPCC(VgpCacheResults); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1023 | /*--------------------------------------------------------------------*/ |
| 1024 | /*--- Discarding BB info ---*/ |
| 1025 | /*--------------------------------------------------------------------*/ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1026 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1027 | // Called when a translation is invalidated due to code unloading. |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 1028 | void TL_(discard_basic_block_info) ( Addr a, SizeT size ) |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1029 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1030 | VgHashNode** prev_next_ptr; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 1031 | VgHashNode* bbInfo; |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 1032 | |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 1033 | if (0) VG_(printf)( "discard_basic_block_info: %p, %llu\n", a, (ULong)size); |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 1034 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1035 | // Get BB info, remove from table, free BB info. Simple! |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 1036 | bbInfo = VG_(HT_get_node)(instr_info_table, a, &prev_next_ptr); |
| 1037 | tl_assert(NULL != bbInfo); |
| 1038 | *prev_next_ptr = bbInfo->next; |
| 1039 | VG_(free)(bbInfo); |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | /*--------------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1043 | /*--- Command line processing ---*/ |
| 1044 | /*--------------------------------------------------------------------*/ |
| 1045 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1046 | static void parse_cache_opt ( cache_t* cache, char* opt ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1047 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1048 | int i = 0, i2, i3; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1049 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1050 | // Option argument looks like "65536,2,64". |
| 1051 | // Find commas, replace with NULs to make three independent |
| 1052 | // strings, then extract numbers, put NULs back. Yuck. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1053 | while (VG_(isdigit)(opt[i])) i++; |
| 1054 | if (',' == opt[i]) { |
| 1055 | opt[i++] = '\0'; |
| 1056 | i2 = i; |
| 1057 | } else goto bad; |
| 1058 | while (VG_(isdigit)(opt[i])) i++; |
| 1059 | if (',' == opt[i]) { |
| 1060 | opt[i++] = '\0'; |
| 1061 | i3 = i; |
| 1062 | } else goto bad; |
| 1063 | while (VG_(isdigit)(opt[i])) i++; |
| 1064 | if ('\0' != opt[i]) goto bad; |
| 1065 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1066 | cache->size = (Int)VG_(atoll)(opt); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1067 | cache->assoc = (Int)VG_(atoll)(opt + i2); |
| 1068 | cache->line_size = (Int)VG_(atoll)(opt + i3); |
| 1069 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1070 | opt[i2-1] = ','; |
| 1071 | opt[i3-1] = ','; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1072 | return; |
| 1073 | |
| 1074 | bad: |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1075 | VG_(bad_option)(opt); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 1078 | Bool TL_(process_cmd_line_option)(Char* arg) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1079 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1080 | // 5 is length of "--I1=" |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1081 | if (VG_CLO_STREQN(5, arg, "--I1=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1082 | parse_cache_opt(&clo_I1_cache, &arg[5]); |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1083 | else if (VG_CLO_STREQN(5, arg, "--D1=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1084 | parse_cache_opt(&clo_D1_cache, &arg[5]); |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1085 | else if (VG_CLO_STREQN(5, arg, "--L2=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1086 | parse_cache_opt(&clo_L2_cache, &arg[5]); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1087 | else |
| 1088 | return False; |
| 1089 | |
| 1090 | return True; |
| 1091 | } |
| 1092 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 1093 | void TL_(print_usage)(void) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1094 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1095 | VG_(printf)( |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1096 | " --I1=<size>,<assoc>,<line_size> set I1 cache manually\n" |
| 1097 | " --D1=<size>,<assoc>,<line_size> set D1 cache manually\n" |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1098 | " --L2=<size>,<assoc>,<line_size> set L2 cache manually\n" |
| 1099 | ); |
| 1100 | } |
| 1101 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 1102 | void TL_(print_debug_usage)(void) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1103 | { |
| 1104 | VG_(printf)( |
| 1105 | " (none)\n" |
| 1106 | ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /*--------------------------------------------------------------------*/ |
| 1110 | /*--- Setup ---*/ |
| 1111 | /*--------------------------------------------------------------------*/ |
| 1112 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 1113 | void TL_(pre_clo_init)(void) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1114 | { |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 1115 | Char* base_dir = NULL; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1116 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1117 | VG_(details_name) ("Cachegrind"); |
| 1118 | VG_(details_version) (NULL); |
| 1119 | VG_(details_description) ("an I1/D1/L2 cache profiler"); |
| 1120 | VG_(details_copyright_author)( |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 1121 | "Copyright (C) 2002-2005, and GNU GPL'd, by Nicholas Nethercote et al."); |
nethercote | 421281e | 2003-11-20 16:20:55 +0000 | [diff] [blame] | 1122 | VG_(details_bug_reports_to) (VG_BUGS_TO); |
sewardj | 78210aa | 2002-12-01 02:55:46 +0000 | [diff] [blame] | 1123 | VG_(details_avg_translation_sizeB) ( 155 ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1124 | |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 1125 | VG_(basic_tool_funcs) (TL_(post_clo_init), |
| 1126 | TL_(instrument), |
| 1127 | TL_(fini)); |
| 1128 | |
| 1129 | VG_(needs_basic_block_discards)(TL_(discard_basic_block_info)); |
| 1130 | VG_(needs_command_line_options)(TL_(process_cmd_line_option), |
| 1131 | TL_(print_usage), |
| 1132 | TL_(print_debug_usage)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1133 | |
njn | 99ccf08 | 2003-09-30 13:51:23 +0000 | [diff] [blame] | 1134 | /* Get working directory */ |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 1135 | tl_assert( VG_(getcwd_alloc)(&base_dir) ); |
njn | 99ccf08 | 2003-09-30 13:51:23 +0000 | [diff] [blame] | 1136 | |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 1137 | /* Block is big enough for dir name + cachegrind.out.<pid> */ |
| 1138 | cachegrind_out_file = VG_(malloc)((VG_(strlen)(base_dir) + 32)*sizeof(Char)); |
| 1139 | VG_(sprintf)(cachegrind_out_file, "%s/cachegrind.out.%d", |
| 1140 | base_dir, VG_(getpid)()); |
njn | 99ccf08 | 2003-09-30 13:51:23 +0000 | [diff] [blame] | 1141 | VG_(free)(base_dir); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1142 | |
| 1143 | instr_info_table = VG_(HT_construct)(); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 1146 | void TL_(post_clo_init)(void) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1147 | { |
| 1148 | cache_t I1c, D1c, L2c; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1149 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 1150 | configure_caches(&I1c, &D1c, &L2c); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1151 | |
| 1152 | cachesim_I1_initcache(I1c); |
| 1153 | cachesim_D1_initcache(D1c); |
| 1154 | cachesim_L2_initcache(L2c); |
| 1155 | |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 1156 | VG_(register_profile_event)(VgpGetLineCC, "get-lineCC"); |
| 1157 | VG_(register_profile_event)(VgpCacheSimulate, "cache-simulate"); |
| 1158 | VG_(register_profile_event)(VgpCacheResults, "cache-results"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 1161 | VG_DETERMINE_INTERFACE_VERSION(TL_(pre_clo_init), 0) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1162 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1163 | /*--------------------------------------------------------------------*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 1164 | /*--- end cg_main.c ---*/ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1165 | /*--------------------------------------------------------------------*/ |