sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 1 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 3 | /*--- Cachegrind: every 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 | |
nethercote | bb1c991 | 2004-01-04 16:43:23 +0000 | [diff] [blame] | 11 | Copyright (C) 2002-2004 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 |
nethercote | 7149b42 | 2004-07-20 13:29:02 +0000 | [diff] [blame] | 114 | // instruction (instr_size, 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; |
| 121 | UChar instr_size; |
| 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 | { |
| 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. |
| 229 | static 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; |
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 | |
nethercote | eec4630 | 2004-08-23 15:06:23 +0000 | [diff] [blame] | 286 | static 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 | { |
| 289 | //VG_(printf)("1I_0D: CCaddr=0x%x, iaddr=0x%x, isize=%u\n", |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 290 | // n, n->instr_addr, n->instr_size) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 291 | VGP_PUSHCC(VgpCacheSimulate); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 292 | cachesim_I1_doref(n->instr_addr, n->instr_size, |
| 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 | |
nethercote | eec4630 | 2004-08-23 15:06:23 +0000 | [diff] [blame] | 298 | static 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", |
| 302 | // n, n->instr_addr, n->instr_size, data_addr, n->data_size) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 303 | VGP_PUSHCC(VgpCacheSimulate); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 304 | cachesim_I1_doref(n->instr_addr, n->instr_size, |
| 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 | |
nethercote | eec4630 | 2004-08-23 15:06:23 +0000 | [diff] [blame] | 314 | static 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", |
| 318 | // n, n->instr_addr, n->instr_size, data_addr, n->data_size) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 319 | VGP_PUSHCC(VgpCacheSimulate); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 320 | 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++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 327 | VGP_POPCC(VgpCacheSimulate); |
| 328 | } |
| 329 | |
nethercote | eec4630 | 2004-08-23 15:06:23 +0000 | [diff] [blame] | 330 | static 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", |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 334 | // n, n->instr_addr, n->instr_size, data_addr1, data_addr2, n->data_size) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 335 | VGP_PUSHCC(VgpCacheSimulate); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 336 | cachesim_I1_doref(n->instr_addr, n->instr_size, |
| 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 |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 354 | BB_info* get_BB_info(UCodeBlock* cb_in, Addr orig_addr, Bool* bb_seen_before) |
| 355 | { |
| 356 | Int i, n_instrs; |
| 357 | UInstr* u_in; |
| 358 | BB_info* bb_info; |
| 359 | VgHashNode** dummy; |
| 360 | |
| 361 | // Count number of x86 instrs in BB |
| 362 | n_instrs = 1; // start at 1 because last x86 instr has no INCEIP |
| 363 | for (i = 0; i < VG_(get_num_instrs)(cb_in); i++) { |
| 364 | u_in = VG_(get_instr)(cb_in, i); |
| 365 | if (INCEIP == u_in->opcode) n_instrs++; |
| 366 | } |
| 367 | |
| 368 | // Get the BB_info |
| 369 | bb_info = (BB_info*)VG_(HT_get_node)(instr_info_table, orig_addr, &dummy); |
| 370 | *bb_seen_before = ( NULL == bb_info ? False : True ); |
| 371 | if (*bb_seen_before) { |
| 372 | // BB must have been translated before, but flushed from the TT |
| 373 | sk_assert(bb_info->n_instrs == n_instrs ); |
| 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) |
| 378 | bb_info = |
| 379 | VG_(calloc)(1, sizeof(BB_info) + n_instrs*sizeof(instr_info)); |
| 380 | bb_info->BB_addr = orig_addr; |
| 381 | bb_info->n_instrs = n_instrs; |
| 382 | VG_(HT_add_node)( instr_info_table, (VgHashNode*)bb_info ); |
| 383 | distinct_instrs++; |
| 384 | } |
| 385 | return bb_info; |
| 386 | } |
| 387 | |
nethercote | 564b2b0 | 2004-08-07 15:54:53 +0000 | [diff] [blame] | 388 | static |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 389 | void do_details( instr_info* n, Bool bb_seen_before, |
| 390 | Addr instr_addr, Int instr_size, Int data_size ) |
| 391 | { |
| 392 | lineCC* parent = get_lineCC(instr_addr); |
| 393 | if (bb_seen_before) { |
| 394 | sk_assert( n->instr_addr == instr_addr ); |
| 395 | sk_assert( n->instr_size == instr_size ); |
| 396 | sk_assert( n->data_size == data_size ); |
| 397 | // Don't assert that (n->parent == parent)... it's conceivable that |
| 398 | // the debug info might change; the other asserts should be enough to |
| 399 | // detect anything strange. |
| 400 | } else { |
| 401 | n->instr_addr = instr_addr; |
| 402 | n->instr_size = instr_size; |
| 403 | n->data_size = data_size; |
| 404 | n->parent = parent; |
| 405 | } |
| 406 | } |
| 407 | |
nethercote | 564b2b0 | 2004-08-07 15:54:53 +0000 | [diff] [blame] | 408 | static Bool is_valid_data_size(Int data_size) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 409 | { |
| 410 | return (4 == data_size || 2 == data_size || 1 == data_size || |
| 411 | 8 == data_size || 10 == data_size || MIN_LINE_SIZE == data_size); |
| 412 | } |
| 413 | |
| 414 | // Instrumentation for the end of each x86 instruction. |
nethercote | 564b2b0 | 2004-08-07 15:54:53 +0000 | [diff] [blame] | 415 | static |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 416 | void end_of_x86_instr(UCodeBlock* cb, instr_info* i_node, Bool bb_seen_before, |
| 417 | UInt instr_addr, UInt instr_size, UInt data_size, |
| 418 | Int t_read, Int t_read_addr, |
| 419 | Int t_write, Int t_write_addr) |
| 420 | { |
| 421 | Addr helper; |
| 422 | Int argc; |
| 423 | Int t_CC_addr, |
| 424 | t_data_addr1 = INVALID_TEMPREG, |
| 425 | t_data_addr2 = INVALID_TEMPREG; |
| 426 | |
nethercote | fbfc108 | 2004-09-04 15:28:37 +0000 | [diff] [blame] | 427 | sk_assert(instr_size >= MIN_INSTR_SIZE && |
| 428 | instr_size <= MAX_INSTR_SIZE); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 429 | |
| 430 | #define IS_(X) (INVALID_TEMPREG != t_##X##_addr) |
| 431 | #define INV(qqt) (INVALID_TEMPREG == (qqt)) |
| 432 | |
| 433 | // Work out what kind of x86 instruction it is |
| 434 | if (!IS_(read) && !IS_(write)) { |
| 435 | sk_assert( 0 == data_size ); |
| 436 | sk_assert(INV(t_read) && INV(t_write)); |
| 437 | helper = (Addr) & log_1I_0D_cache_access; |
| 438 | argc = 1; |
| 439 | |
| 440 | } else if (IS_(read) && !IS_(write)) { |
| 441 | sk_assert( is_valid_data_size(data_size) ); |
| 442 | sk_assert(!INV(t_read) && INV(t_write)); |
| 443 | helper = (Addr) & log_1I_1Dr_cache_access; |
| 444 | argc = 2; |
| 445 | t_data_addr1 = t_read_addr; |
| 446 | |
| 447 | } else if (!IS_(read) && IS_(write)) { |
| 448 | sk_assert( is_valid_data_size(data_size) ); |
| 449 | sk_assert(INV(t_read) && !INV(t_write)); |
| 450 | helper = (Addr) & log_1I_1Dw_cache_access; |
| 451 | argc = 2; |
| 452 | t_data_addr1 = t_write_addr; |
| 453 | |
| 454 | } else { |
| 455 | sk_assert(IS_(read) && IS_(write)); |
| 456 | sk_assert( is_valid_data_size(data_size) ); |
| 457 | sk_assert(!INV(t_read) && !INV(t_write)); |
| 458 | if (t_read == t_write) { |
| 459 | helper = (Addr) & log_1I_1Dr_cache_access; |
| 460 | argc = 2; |
| 461 | t_data_addr1 = t_read_addr; |
| 462 | } else { |
| 463 | helper = (Addr) & log_1I_2D_cache_access; |
| 464 | argc = 3; |
| 465 | t_data_addr1 = t_read_addr; |
| 466 | t_data_addr2 = t_write_addr; |
| 467 | } |
| 468 | } |
| 469 | #undef IS_ |
nethercote | f5b7466 | 2004-07-06 22:46:41 +0000 | [diff] [blame] | 470 | #undef INV |
| 471 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 472 | // Setup 1st arg: CC addr |
| 473 | do_details( i_node, bb_seen_before, instr_addr, instr_size, data_size ); |
| 474 | t_CC_addr = newTemp(cb); |
| 475 | uInstr2(cb, MOV, 4, Literal, 0, TempReg, t_CC_addr); |
| 476 | uLiteral(cb, (Addr)i_node); |
| 477 | |
| 478 | // Call the helper |
| 479 | if (1 == argc) |
| 480 | uInstr1(cb, CCALL, 0, TempReg, t_CC_addr); |
| 481 | else if (2 == argc) |
| 482 | uInstr2(cb, CCALL, 0, TempReg, t_CC_addr, |
| 483 | TempReg, t_data_addr1); |
| 484 | else if (3 == argc) |
| 485 | uInstr3(cb, CCALL, 0, TempReg, t_CC_addr, |
| 486 | TempReg, t_data_addr1, |
| 487 | TempReg, t_data_addr2); |
| 488 | else |
| 489 | VG_(skin_panic)("argc... not 1 or 2 or 3?"); |
| 490 | |
| 491 | uCCall(cb, helper, argc, argc, False); |
| 492 | } |
| 493 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 494 | UCodeBlock* SK_(instrument)(UCodeBlock* cb_in, Addr orig_addr) |
| 495 | { |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 496 | UCodeBlock* cb; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 497 | UInstr* u_in; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 498 | Int i, bb_info_i; |
| 499 | BB_info* bb_info; |
| 500 | Bool bb_seen_before = False; |
| 501 | Int t_read_addr, t_write_addr, t_read, t_write; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 502 | Addr x86_instr_addr = orig_addr; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 503 | UInt x86_instr_size, data_size = 0; |
| 504 | Bool instrumented_Jcc = False; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 505 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 506 | bb_info = get_BB_info(cb_in, orig_addr, &bb_seen_before); |
| 507 | bb_info_i = 0; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 508 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 509 | cb = VG_(setup_UCodeBlock)(cb_in); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 510 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 511 | t_read_addr = t_write_addr = t_read = t_write = INVALID_TEMPREG; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 512 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 513 | for (i = 0; i < VG_(get_num_instrs)(cb_in); i++) { |
| 514 | u_in = VG_(get_instr)(cb_in, i); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 515 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 516 | // We want to instrument each x86 instruction with a call to the |
| 517 | // appropriate simulation function, which depends on whether the |
| 518 | // instruction does memory data reads/writes. x86 instructions can |
| 519 | // end in three ways, and this is how they are instrumented: |
| 520 | // |
| 521 | // 1. UCode, INCEIP --> UCode, Instrumentation, INCEIP |
| 522 | // 2. UCode, JMP --> UCode, Instrumentation, JMP |
| 523 | // 3. UCode, Jcc, JMP --> UCode, Instrumentation, Jcc, JMP |
| 524 | // |
| 525 | // The last UInstr in a BB is always a JMP. Jccs, when they appear, |
| 526 | // are always second last. This is checked with assertions. |
| 527 | // Instrumentation must go before any jumps. (JIFZ is the exception; |
| 528 | // if a JIFZ succeeds, no simulation is done for the instruction.) |
| 529 | // |
| 530 | // x86 instruction sizes are obtained from INCEIPs (for case 1) or |
| 531 | // from .extra4b field of the final JMP (for case 2 & 3). |
| 532 | |
| 533 | if (instrumented_Jcc) sk_assert(u_in->opcode == JMP); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 534 | |
| 535 | switch (u_in->opcode) { |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 536 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 537 | // For memory-ref instrs, copy the data_addr into a temporary to be |
| 538 | // passed to the cachesim_* helper at the end of the instruction. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 539 | case LOAD: |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 540 | case SSE3ag_MemRd_RegWr: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 541 | t_read = u_in->val1; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 542 | t_read_addr = newTemp(cb); |
| 543 | uInstr2(cb, MOV, 4, TempReg, u_in->val1, TempReg, t_read_addr); |
| 544 | data_size = u_in->size; |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 545 | VG_(copy_UInstr)(cb, u_in); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 546 | break; |
| 547 | |
| 548 | case FPU_R: |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 549 | case MMX2_MemRd: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 550 | t_read = u_in->val2; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 551 | t_read_addr = newTemp(cb); |
| 552 | uInstr2(cb, MOV, 4, TempReg, u_in->val2, TempReg, t_read_addr); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 553 | data_size = u_in->size; |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 554 | VG_(copy_UInstr)(cb, u_in); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 555 | break; |
thughes | 96b466a | 2004-03-15 16:43:58 +0000 | [diff] [blame] | 556 | break; |
| 557 | |
| 558 | case MMX2a1_MemRd: |
njn | 21f805d | 2003-08-25 16:15:40 +0000 | [diff] [blame] | 559 | case SSE2a_MemRd: |
| 560 | case SSE2a1_MemRd: |
njn | 21f805d | 2003-08-25 16:15:40 +0000 | [diff] [blame] | 561 | case SSE3a_MemRd: |
jseward | 1b58fbc | 2003-11-04 22:54:28 +0000 | [diff] [blame] | 562 | case SSE3a1_MemRd: |
jseward | 1b58fbc | 2003-11-04 22:54:28 +0000 | [diff] [blame] | 563 | t_read = u_in->val3; |
| 564 | t_read_addr = newTemp(cb); |
| 565 | uInstr2(cb, MOV, 4, TempReg, u_in->val3, TempReg, t_read_addr); |
| 566 | data_size = u_in->size; |
| 567 | VG_(copy_UInstr)(cb, u_in); |
| 568 | break; |
| 569 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 570 | // Note that we must set t_write_addr even for mod instructions; |
| 571 | // That's how the code above determines whether it does a write. |
| 572 | // Without it, it would think a mod instruction is a read. |
| 573 | // As for the MOV, if it's a mod instruction it's redundant, but it's |
| 574 | // not expensive and mod instructions are rare anyway. */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 575 | case STORE: |
| 576 | case FPU_W: |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 577 | case MMX2_MemWr: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 578 | t_write = u_in->val2; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 579 | t_write_addr = newTemp(cb); |
| 580 | uInstr2(cb, MOV, 4, TempReg, u_in->val2, TempReg, t_write_addr); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 581 | data_size = u_in->size; |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 582 | VG_(copy_UInstr)(cb, u_in); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 583 | break; |
| 584 | |
njn | 21f805d | 2003-08-25 16:15:40 +0000 | [diff] [blame] | 585 | case SSE2a_MemWr: |
njn | 21f805d | 2003-08-25 16:15:40 +0000 | [diff] [blame] | 586 | case SSE3a_MemWr: |
njn | 21f805d | 2003-08-25 16:15:40 +0000 | [diff] [blame] | 587 | t_write = u_in->val3; |
| 588 | t_write_addr = newTemp(cb); |
| 589 | uInstr2(cb, MOV, 4, TempReg, u_in->val3, TempReg, t_write_addr); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 590 | data_size = u_in->size; |
njn | 21f805d | 2003-08-25 16:15:40 +0000 | [diff] [blame] | 591 | VG_(copy_UInstr)(cb, u_in); |
| 592 | break; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 593 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 594 | // INCEIP: insert instrumentation |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 595 | case INCEIP: |
| 596 | x86_instr_size = u_in->val1; |
| 597 | goto instrument_x86_instr; |
| 598 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 599 | // JMP: insert instrumentation if the first JMP |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 600 | case JMP: |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 601 | if (instrumented_Jcc) { |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 602 | sk_assert(CondAlways == u_in->cond); |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 603 | sk_assert(i+1 == VG_(get_num_instrs)(cb_in)); |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 604 | VG_(copy_UInstr)(cb, u_in); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 605 | instrumented_Jcc = False; // rest |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 606 | break; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 607 | } else { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 608 | // The first JMP... instrument. |
| 609 | if (CondAlways != u_in->cond) { |
| 610 | sk_assert(i+2 == VG_(get_num_instrs)(cb_in)); |
| 611 | instrumented_Jcc = True; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 612 | } else { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 613 | sk_assert(i+1 == VG_(get_num_instrs)(cb_in)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 614 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 615 | // Get x86 instr size from final JMP. |
| 616 | x86_instr_size = VG_(get_last_instr)(cb_in)->extra4b; |
| 617 | goto instrument_x86_instr; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 618 | } |
| 619 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 620 | // Code executed at the end of each x86 instruction. |
| 621 | instrument_x86_instr: |
| 622 | // Large (eg. 28B, 108B, 512B) data-sized instructions will be |
| 623 | // done inaccurately but they're very rare and this avoids |
| 624 | // errors from hitting more than two cache lines in the |
| 625 | // simulation. |
| 626 | if (data_size > MIN_LINE_SIZE) data_size = MIN_LINE_SIZE; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 627 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 628 | end_of_x86_instr(cb, &bb_info->instrs[ bb_info_i ], bb_seen_before, |
| 629 | x86_instr_addr, x86_instr_size, data_size, |
| 630 | t_read, t_read_addr, t_write, t_write_addr); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 631 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 632 | // Copy original UInstr (INCEIP or JMP) |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 633 | VG_(copy_UInstr)(cb, u_in); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 634 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 635 | // Update loop state for next x86 instr |
| 636 | bb_info_i++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 637 | x86_instr_addr += x86_instr_size; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 638 | t_read_addr = t_write_addr = t_read = t_write = INVALID_TEMPREG; |
| 639 | data_size = 0; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 640 | break; |
| 641 | |
| 642 | default: |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 643 | VG_(copy_UInstr)(cb, u_in); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 644 | break; |
| 645 | } |
| 646 | } |
| 647 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 648 | // BB address should be the same as the first instruction's address. |
| 649 | sk_assert(bb_info->BB_addr == bb_info->instrs[0].instr_addr ); |
| 650 | sk_assert(bb_info_i == bb_info->n_instrs); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 651 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 652 | VG_(free_UCodeBlock)(cb_in); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 653 | return cb; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 654 | |
| 655 | #undef INVALID_DATA_SIZE |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /*------------------------------------------------------------*/ |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame^] | 659 | /*--- Cache configuration ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 660 | /*------------------------------------------------------------*/ |
| 661 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 662 | #define UNDEFINED_CACHE ((cache_t) { -1, -1, -1 }) |
| 663 | |
| 664 | static cache_t clo_I1_cache = UNDEFINED_CACHE; |
| 665 | static cache_t clo_D1_cache = UNDEFINED_CACHE; |
| 666 | static cache_t clo_L2_cache = UNDEFINED_CACHE; |
| 667 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 668 | /* Checks cache config is ok; makes it so if not. */ |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 669 | static |
| 670 | void check_cache(cache_t* cache, cache_t* dflt, Char *name) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 671 | { |
| 672 | /* First check they're all powers of two */ |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 673 | if (-1 == VG_(log2)(cache->size)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 674 | VG_(message)(Vg_UserMsg, |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 675 | "warning: %s size of %dB not a power of two; " |
| 676 | "defaulting to %dB", name, cache->size, dflt->size); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 677 | cache->size = dflt->size; |
| 678 | } |
| 679 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 680 | if (-1 == VG_(log2)(cache->assoc)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 681 | VG_(message)(Vg_UserMsg, |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 682 | "warning: %s associativity of %d not a power of two; " |
| 683 | "defaulting to %d-way", name, cache->assoc, dflt->assoc); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 684 | cache->assoc = dflt->assoc; |
| 685 | } |
| 686 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 687 | if (-1 == VG_(log2)(cache->line_size)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 688 | VG_(message)(Vg_UserMsg, |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 689 | "warning: %s line size of %dB not a power of two; " |
| 690 | "defaulting to %dB", |
| 691 | name, cache->line_size, dflt->line_size); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 692 | cache->line_size = dflt->line_size; |
| 693 | } |
| 694 | |
| 695 | /* Then check line size >= 16 -- any smaller and a single instruction could |
| 696 | * straddle three cache lines, which breaks a simulation assertion and is |
| 697 | * stupid anyway. */ |
| 698 | if (cache->line_size < MIN_LINE_SIZE) { |
| 699 | VG_(message)(Vg_UserMsg, |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 700 | "warning: %s line size of %dB too small; " |
| 701 | "increasing to %dB", name, cache->line_size, MIN_LINE_SIZE); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 702 | cache->line_size = MIN_LINE_SIZE; |
| 703 | } |
| 704 | |
| 705 | /* Then check cache size > line size (causes seg faults if not). */ |
| 706 | if (cache->size <= cache->line_size) { |
| 707 | VG_(message)(Vg_UserMsg, |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 708 | "warning: %s cache size of %dB <= line size of %dB; " |
| 709 | "increasing to %dB", name, cache->size, cache->line_size, |
| 710 | cache->line_size * 2); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 711 | cache->size = cache->line_size * 2; |
| 712 | } |
| 713 | |
| 714 | /* Then check assoc <= (size / line size) (seg faults otherwise). */ |
| 715 | if (cache->assoc > (cache->size / cache->line_size)) { |
| 716 | VG_(message)(Vg_UserMsg, |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 717 | "warning: %s associativity > (size / line size); " |
| 718 | "increasing size to %dB", |
| 719 | name, cache->assoc * cache->line_size); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 720 | cache->size = cache->assoc * cache->line_size; |
| 721 | } |
| 722 | } |
| 723 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 724 | static |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame^] | 725 | void configure_caches(cache_t* I1c, cache_t* D1c, cache_t* L2c) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 726 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 727 | #define DEFINED(L) (-1 != L.size || -1 != L.assoc || -1 != L.line_size) |
| 728 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame^] | 729 | Int n_clos = 0; |
| 730 | cache_t I1_dflt, D1_dflt, L2_dflt; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 731 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame^] | 732 | // Count how many were defined on the command line. |
| 733 | if (DEFINED(clo_I1_cache)) { n_clos++; } |
| 734 | if (DEFINED(clo_D1_cache)) { n_clos++; } |
| 735 | if (DEFINED(clo_L2_cache)) { n_clos++; } |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 736 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame^] | 737 | // Set the default cache config (using auto-detection, if supported by |
| 738 | // current arch) |
| 739 | VGA_(configure_caches)( I1c, D1c, L2c, &I1_dflt, &D1_dflt, &L2_dflt, |
| 740 | (3 == n_clos) ); |
sewardj | b1a77a4 | 2002-07-13 13:31:20 +0000 | [diff] [blame] | 741 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 742 | // Then replace with any defined on the command line. |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame^] | 743 | if (DEFINED(clo_I1_cache)) { *I1c = clo_I1_cache; } |
| 744 | if (DEFINED(clo_D1_cache)) { *D1c = clo_D1_cache; } |
| 745 | if (DEFINED(clo_L2_cache)) { *L2c = clo_L2_cache; } |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 746 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 747 | // Then check values and fix if not acceptable. |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 748 | check_cache(I1c, &I1_dflt, "I1"); |
| 749 | check_cache(D1c, &D1_dflt, "D1"); |
| 750 | check_cache(L2c, &L2_dflt, "L2"); |
| 751 | |
| 752 | if (VG_(clo_verbosity) > 1) { |
| 753 | VG_(message)(Vg_UserMsg, "Cache configuration used:"); |
| 754 | VG_(message)(Vg_UserMsg, " I1: %dB, %d-way, %dB lines", |
| 755 | I1c->size, I1c->assoc, I1c->line_size); |
| 756 | VG_(message)(Vg_UserMsg, " D1: %dB, %d-way, %dB lines", |
| 757 | D1c->size, D1c->assoc, D1c->line_size); |
| 758 | VG_(message)(Vg_UserMsg, " L2: %dB, %d-way, %dB lines", |
| 759 | L2c->size, L2c->assoc, L2c->line_size); |
| 760 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 761 | #undef CMD_LINE_DEFINED |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 762 | } |
| 763 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 764 | /*------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 765 | /*--- SK_(fini)() and related function ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 766 | /*------------------------------------------------------------*/ |
| 767 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 768 | // Total reads/writes/misses. Calculated during CC traversal at the end. |
| 769 | // All auto-zeroed. |
| 770 | static CC Ir_total; |
| 771 | static CC Dr_total; |
| 772 | static CC Dw_total; |
| 773 | |
| 774 | static Char* cachegrind_out_file; |
| 775 | |
| 776 | static void file_err ( void ) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 777 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 778 | VG_(message)(Vg_UserMsg, |
| 779 | "error: can't open cache simulation output file `%s'", |
| 780 | cachegrind_out_file ); |
| 781 | VG_(message)(Vg_UserMsg, |
| 782 | " ... so simulation results will be missing."); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 783 | } |
| 784 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 785 | static void fprint_lineCC(Int fd, lineCC* n) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 786 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 787 | Char buf[512]; |
| 788 | VG_(sprintf)(buf, "%u %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
| 789 | n->line, |
| 790 | n->Ir.a, n->Ir.m1, n->Ir.m2, |
| 791 | n->Dr.a, n->Dr.m1, n->Dr.m2, |
| 792 | n->Dw.a, n->Dw.m1, n->Dw.m2); |
| 793 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 794 | |
| 795 | Ir_total.a += n->Ir.a; Ir_total.m1 += n->Ir.m1; Ir_total.m2 += n->Ir.m2; |
| 796 | Dr_total.a += n->Dr.a; Dr_total.m1 += n->Dr.m1; Dr_total.m2 += n->Dr.m2; |
| 797 | Dw_total.a += n->Dw.a; Dw_total.m1 += n->Dw.m1; Dw_total.m2 += n->Dw.m2; |
| 798 | } |
| 799 | |
| 800 | static void fprint_CC_table_and_calc_totals(void) |
| 801 | { |
| 802 | Int fd; |
| 803 | Char buf[512]; |
| 804 | fileCC *curr_fileCC; |
| 805 | fnCC *curr_fnCC; |
| 806 | lineCC *curr_lineCC; |
| 807 | Int i, j, k; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 808 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 809 | VGP_PUSHCC(VgpCacheResults); |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 810 | |
njn | db918dd | 2003-07-22 20:45:11 +0000 | [diff] [blame] | 811 | 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] | 812 | VKI_S_IRUSR|VKI_S_IWUSR); |
nethercote | 50da0f3 | 2003-10-30 10:33:30 +0000 | [diff] [blame] | 813 | if (fd < 0) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 814 | // If the file can't be opened for whatever reason (conflict |
| 815 | // between multiple cachegrinded processes?), give up now. |
sewardj | 0744b6c | 2002-12-11 00:45:42 +0000 | [diff] [blame] | 816 | file_err(); |
| 817 | return; |
| 818 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 819 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 820 | // "desc:" lines (giving I1/D1/L2 cache configuration). The spaces after |
| 821 | // the 2nd colon makes cg_annotate's output look nicer. |
| 822 | VG_(sprintf)(buf, "desc: I1 cache: %s\n" |
| 823 | "desc: D1 cache: %s\n" |
| 824 | "desc: L2 cache: %s\n", |
| 825 | I1.desc_line, D1.desc_line, L2.desc_line); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 826 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 827 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 828 | // "cmd:" line |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 829 | VG_(strcpy)(buf, "cmd:"); |
| 830 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 831 | for (i = 0; i < VG_(client_argc); i++) { |
| 832 | VG_(sprintf)(buf, " %s", VG_(client_argv)[i]); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 833 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 834 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 835 | // "events:" line |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 836 | VG_(sprintf)(buf, "\nevents: Ir I1mr I2mr Dr D1mr D2mr Dw D1mw D2mw\n"); |
| 837 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 838 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 839 | // Six loops here: three for the hash table arrays, and three for the |
| 840 | // chains hanging off the hash table arrays. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 841 | for (i = 0; i < N_FILE_ENTRIES; i++) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 842 | curr_fileCC = CC_table[i]; |
| 843 | while (curr_fileCC != NULL) { |
| 844 | VG_(sprintf)(buf, "fl=%s\n", curr_fileCC->file); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 845 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 846 | |
| 847 | for (j = 0; j < N_FN_ENTRIES; j++) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 848 | curr_fnCC = curr_fileCC->fns[j]; |
| 849 | while (curr_fnCC != NULL) { |
| 850 | VG_(sprintf)(buf, "fn=%s\n", curr_fnCC->fn); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 851 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 852 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 853 | for (k = 0; k < N_LINE_ENTRIES; k++) { |
| 854 | curr_lineCC = curr_fnCC->lines[k]; |
| 855 | while (curr_lineCC != NULL) { |
| 856 | fprint_lineCC(fd, curr_lineCC); |
| 857 | curr_lineCC = curr_lineCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 858 | } |
| 859 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 860 | curr_fnCC = curr_fnCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 861 | } |
| 862 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 863 | curr_fileCC = curr_fileCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 864 | } |
| 865 | } |
| 866 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 867 | // Summary stats must come after rest of table, since we calculate them |
| 868 | // during traversal. */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 869 | VG_(sprintf)(buf, "summary: " |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 870 | "%llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 871 | Ir_total.a, Ir_total.m1, Ir_total.m2, |
| 872 | Dr_total.a, Dr_total.m1, Dr_total.m2, |
| 873 | Dw_total.a, Dw_total.m1, Dw_total.m2); |
| 874 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 875 | VG_(close)(fd); |
| 876 | } |
| 877 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 878 | static UInt ULong_width(ULong n) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 879 | { |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 880 | UInt w = 0; |
| 881 | while (n > 0) { |
| 882 | n = n / 10; |
| 883 | w++; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 884 | } |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 885 | return w + (w-1)/3; // add space for commas |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 886 | } |
| 887 | |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 888 | static |
daywalker | 8ad1a40 | 2003-09-18 01:15:32 +0000 | [diff] [blame] | 889 | void percentify(Int n, Int ex, Int field_width, char buf[]) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 890 | { |
| 891 | int i, len, space; |
| 892 | |
daywalker | 8ad1a40 | 2003-09-18 01:15:32 +0000 | [diff] [blame] | 893 | VG_(sprintf)(buf, "%d.%d%%", n / ex, n % ex); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 894 | len = VG_(strlen)(buf); |
| 895 | space = field_width - len; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 896 | if (space < 0) space = 0; /* Allow for v. small field_width */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 897 | i = len; |
| 898 | |
| 899 | /* Right justify in field */ |
| 900 | for ( ; i >= 0; i--) buf[i + space] = buf[i]; |
| 901 | for (i = 0; i < space; i++) buf[i] = ' '; |
| 902 | } |
| 903 | |
njn | 7d9f94d | 2003-04-22 21:41:40 +0000 | [diff] [blame] | 904 | void SK_(fini)(Int exitcode) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 905 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 906 | static char buf1[128], buf2[128], buf3[128], fmt [128]; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 907 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 908 | CC D_total; |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 909 | ULong L2_total_m, L2_total_mr, L2_total_mw, |
| 910 | L2_total, L2_total_r, L2_total_w; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 911 | Int l1, l2, l3; |
| 912 | Int p; |
| 913 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 914 | fprint_CC_table_and_calc_totals(); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 915 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 916 | if (VG_(clo_verbosity) == 0) |
| 917 | return; |
| 918 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 919 | /* I cache results. Use the I_refs value to determine the first column |
| 920 | * width. */ |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 921 | l1 = ULong_width(Ir_total.a); |
| 922 | l2 = ULong_width(Dr_total.a); |
| 923 | l3 = ULong_width(Dw_total.a); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 924 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 925 | /* Make format string, getting width right for numbers */ |
| 926 | VG_(sprintf)(fmt, "%%s %%,%dld", l1); |
| 927 | |
| 928 | VG_(message)(Vg_UserMsg, fmt, "I refs: ", Ir_total.a); |
| 929 | VG_(message)(Vg_UserMsg, fmt, "I1 misses: ", Ir_total.m1); |
| 930 | VG_(message)(Vg_UserMsg, fmt, "L2i misses: ", Ir_total.m2); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 931 | |
| 932 | p = 100; |
| 933 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 934 | if (0 == Ir_total.a) Ir_total.a = 1; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 935 | percentify(Ir_total.m1 * 100 * p / Ir_total.a, p, l1+1, buf1); |
| 936 | VG_(message)(Vg_UserMsg, "I1 miss rate: %s", buf1); |
| 937 | |
| 938 | percentify(Ir_total.m2 * 100 * p / Ir_total.a, p, l1+1, buf1); |
| 939 | VG_(message)(Vg_UserMsg, "L2i miss rate: %s", buf1); |
| 940 | VG_(message)(Vg_UserMsg, ""); |
| 941 | |
| 942 | /* D cache results. Use the D_refs.rd and D_refs.wr values to determine the |
| 943 | * width of columns 2 & 3. */ |
| 944 | D_total.a = Dr_total.a + Dw_total.a; |
| 945 | D_total.m1 = Dr_total.m1 + Dw_total.m1; |
| 946 | D_total.m2 = Dr_total.m2 + Dw_total.m2; |
| 947 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 948 | /* Make format string, getting width right for numbers */ |
| 949 | VG_(sprintf)(fmt, "%%s %%,%dld (%%,%dld rd + %%,%dld wr)", l1, l2, l3); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 950 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 951 | VG_(message)(Vg_UserMsg, fmt, "D refs: ", |
| 952 | D_total.a, Dr_total.a, Dw_total.a); |
| 953 | VG_(message)(Vg_UserMsg, fmt, "D1 misses: ", |
| 954 | D_total.m1, Dr_total.m1, Dw_total.m1); |
| 955 | VG_(message)(Vg_UserMsg, fmt, "L2d misses: ", |
| 956 | D_total.m2, Dr_total.m2, Dw_total.m2); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 957 | |
| 958 | p = 10; |
| 959 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 960 | if (0 == D_total.a) D_total.a = 1; |
| 961 | if (0 == Dr_total.a) Dr_total.a = 1; |
| 962 | if (0 == Dw_total.a) Dw_total.a = 1; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 963 | percentify( D_total.m1 * 100 * p / D_total.a, p, l1+1, buf1); |
| 964 | percentify(Dr_total.m1 * 100 * p / Dr_total.a, p, l2+1, buf2); |
| 965 | percentify(Dw_total.m1 * 100 * p / Dw_total.a, p, l3+1, buf3); |
| 966 | VG_(message)(Vg_UserMsg, "D1 miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 967 | |
| 968 | percentify( D_total.m2 * 100 * p / D_total.a, p, l1+1, buf1); |
| 969 | percentify(Dr_total.m2 * 100 * p / Dr_total.a, p, l2+1, buf2); |
| 970 | percentify(Dw_total.m2 * 100 * p / Dw_total.a, p, l3+1, buf3); |
| 971 | VG_(message)(Vg_UserMsg, "L2d miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 972 | VG_(message)(Vg_UserMsg, ""); |
| 973 | |
| 974 | /* L2 overall results */ |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 975 | |
| 976 | L2_total = Dr_total.m1 + Dw_total.m1 + Ir_total.m1; |
| 977 | L2_total_r = Dr_total.m1 + Ir_total.m1; |
| 978 | L2_total_w = Dw_total.m1; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 979 | VG_(message)(Vg_UserMsg, fmt, "L2 refs: ", |
| 980 | L2_total, L2_total_r, L2_total_w); |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 981 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 982 | L2_total_m = Dr_total.m2 + Dw_total.m2 + Ir_total.m2; |
| 983 | L2_total_mr = Dr_total.m2 + Ir_total.m2; |
| 984 | L2_total_mw = Dw_total.m2; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 985 | VG_(message)(Vg_UserMsg, fmt, "L2 misses: ", |
| 986 | L2_total_m, L2_total_mr, L2_total_mw); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 987 | |
| 988 | percentify(L2_total_m * 100 * p / (Ir_total.a + D_total.a), p, l1+1, buf1); |
| 989 | percentify(L2_total_mr * 100 * p / (Ir_total.a + Dr_total.a), p, l2+1, buf2); |
| 990 | percentify(L2_total_mw * 100 * p / Dw_total.a, p, l3+1, buf3); |
| 991 | VG_(message)(Vg_UserMsg, "L2 miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 992 | |
| 993 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 994 | // Various stats |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 995 | if (VG_(clo_verbosity) > 1) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 996 | int BB_lookups = full_debug_BBs + fn_debug_BBs + |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 997 | file_line_debug_BBs + no_debug_BBs; |
| 998 | |
| 999 | VG_(message)(Vg_DebugMsg, ""); |
| 1000 | VG_(message)(Vg_DebugMsg, "Distinct files: %d", distinct_files); |
| 1001 | VG_(message)(Vg_DebugMsg, "Distinct fns: %d", distinct_fns); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1002 | VG_(message)(Vg_DebugMsg, "Distinct lines: %d", distinct_lines); |
| 1003 | VG_(message)(Vg_DebugMsg, "Distinct instrs: %d", distinct_instrs); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1004 | VG_(message)(Vg_DebugMsg, "BB lookups: %d", BB_lookups); |
| 1005 | VG_(message)(Vg_DebugMsg, "With full debug info:%3d%% (%d)", |
| 1006 | full_debug_BBs * 100 / BB_lookups, |
| 1007 | full_debug_BBs); |
| 1008 | VG_(message)(Vg_DebugMsg, "With file/line debug info:%3d%% (%d)", |
| 1009 | file_line_debug_BBs * 100 / BB_lookups, |
| 1010 | file_line_debug_BBs); |
| 1011 | VG_(message)(Vg_DebugMsg, "With fn name debug info:%3d%% (%d)", |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1012 | fn_debug_BBs * 100 / BB_lookups, |
| 1013 | fn_debug_BBs); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1014 | VG_(message)(Vg_DebugMsg, "With no debug info:%3d%% (%d)", |
| 1015 | no_debug_BBs * 100 / BB_lookups, |
| 1016 | no_debug_BBs); |
| 1017 | VG_(message)(Vg_DebugMsg, "BBs Retranslated: %d", BB_retranslations); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1018 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1019 | VGP_POPCC(VgpCacheResults); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1022 | /*--------------------------------------------------------------------*/ |
| 1023 | /*--- Discarding BB info ---*/ |
| 1024 | /*--------------------------------------------------------------------*/ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1025 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1026 | // Called when a translation is invalidated due to code unloading. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1027 | void SK_(discard_basic_block_info) ( Addr a, UInt size ) |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1028 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1029 | VgHashNode** prev_next_ptr; |
| 1030 | VgHashNode* bb_info; |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 1031 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1032 | if (0) VG_(printf)( "discard_basic_block_info: %p, %u\n", a, size); |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 1033 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1034 | // Get BB info, remove from table, free BB info. Simple! |
| 1035 | bb_info = VG_(HT_get_node)(instr_info_table, a, &prev_next_ptr); |
| 1036 | sk_assert(NULL != bb_info); |
| 1037 | *prev_next_ptr = bb_info->next; |
| 1038 | VG_(free)(bb_info); |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | /*--------------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1042 | /*--- Command line processing ---*/ |
| 1043 | /*--------------------------------------------------------------------*/ |
| 1044 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1045 | static void parse_cache_opt ( cache_t* cache, char* opt ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1046 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1047 | int i = 0, i2, i3; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1048 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1049 | // Option argument looks like "65536,2,64". |
| 1050 | // Find commas, replace with NULs to make three independent |
| 1051 | // strings, then extract numbers, put NULs back. Yuck. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1052 | while (VG_(isdigit)(opt[i])) i++; |
| 1053 | if (',' == opt[i]) { |
| 1054 | opt[i++] = '\0'; |
| 1055 | i2 = i; |
| 1056 | } else goto bad; |
| 1057 | while (VG_(isdigit)(opt[i])) i++; |
| 1058 | if (',' == opt[i]) { |
| 1059 | opt[i++] = '\0'; |
| 1060 | i3 = i; |
| 1061 | } else goto bad; |
| 1062 | while (VG_(isdigit)(opt[i])) i++; |
| 1063 | if ('\0' != opt[i]) goto bad; |
| 1064 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1065 | cache->size = (Int)VG_(atoll)(opt); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1066 | cache->assoc = (Int)VG_(atoll)(opt + i2); |
| 1067 | cache->line_size = (Int)VG_(atoll)(opt + i3); |
| 1068 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1069 | opt[i2-1] = ','; |
| 1070 | opt[i3-1] = ','; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1071 | return; |
| 1072 | |
| 1073 | bad: |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1074 | VG_(bad_option)(opt); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | Bool SK_(process_cmd_line_option)(Char* arg) |
| 1078 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1079 | // 5 is length of "--I1=" |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1080 | if (VG_CLO_STREQN(5, arg, "--I1=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1081 | parse_cache_opt(&clo_I1_cache, &arg[5]); |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1082 | else if (VG_CLO_STREQN(5, arg, "--D1=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1083 | parse_cache_opt(&clo_D1_cache, &arg[5]); |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1084 | else if (VG_CLO_STREQN(5, arg, "--L2=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1085 | parse_cache_opt(&clo_L2_cache, &arg[5]); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1086 | else |
| 1087 | return False; |
| 1088 | |
| 1089 | return True; |
| 1090 | } |
| 1091 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1092 | void SK_(print_usage)(void) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1093 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1094 | VG_(printf)( |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1095 | " --I1=<size>,<assoc>,<line_size> set I1 cache manually\n" |
| 1096 | " --D1=<size>,<assoc>,<line_size> set D1 cache manually\n" |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1097 | " --L2=<size>,<assoc>,<line_size> set L2 cache manually\n" |
| 1098 | ); |
| 1099 | } |
| 1100 | |
| 1101 | void SK_(print_debug_usage)(void) |
| 1102 | { |
| 1103 | VG_(printf)( |
| 1104 | " (none)\n" |
| 1105 | ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | /*--------------------------------------------------------------------*/ |
| 1109 | /*--- Setup ---*/ |
| 1110 | /*--------------------------------------------------------------------*/ |
| 1111 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1112 | void SK_(pre_clo_init)(void) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1113 | { |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 1114 | Char* base_dir = NULL; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1115 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1116 | VG_(details_name) ("Cachegrind"); |
| 1117 | VG_(details_version) (NULL); |
| 1118 | VG_(details_description) ("an I1/D1/L2 cache profiler"); |
| 1119 | VG_(details_copyright_author)( |
nethercote | 08fa9a7 | 2004-07-16 17:44:00 +0000 | [diff] [blame] | 1120 | "Copyright (C) 2002-2004, and GNU GPL'd, by Nicholas Nethercote et al."); |
nethercote | 421281e | 2003-11-20 16:20:55 +0000 | [diff] [blame] | 1121 | VG_(details_bug_reports_to) (VG_BUGS_TO); |
sewardj | 78210aa | 2002-12-01 02:55:46 +0000 | [diff] [blame] | 1122 | VG_(details_avg_translation_sizeB) ( 155 ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1123 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1124 | VG_(needs_basic_block_discards)(); |
| 1125 | VG_(needs_command_line_options)(); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1126 | |
| 1127 | VG_(register_compact_helper)((Addr) & log_1I_0D_cache_access); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1128 | VG_(register_compact_helper)((Addr) & log_1I_1Dr_cache_access); |
| 1129 | VG_(register_compact_helper)((Addr) & log_1I_1Dw_cache_access); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1130 | VG_(register_compact_helper)((Addr) & log_1I_2D_cache_access); |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 1131 | |
njn | 99ccf08 | 2003-09-30 13:51:23 +0000 | [diff] [blame] | 1132 | /* Get working directory */ |
| 1133 | sk_assert( VG_(getcwd_alloc)(&base_dir) ); |
| 1134 | |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 1135 | /* Block is big enough for dir name + cachegrind.out.<pid> */ |
| 1136 | cachegrind_out_file = VG_(malloc)((VG_(strlen)(base_dir) + 32)*sizeof(Char)); |
| 1137 | VG_(sprintf)(cachegrind_out_file, "%s/cachegrind.out.%d", |
| 1138 | base_dir, VG_(getpid)()); |
njn | 99ccf08 | 2003-09-30 13:51:23 +0000 | [diff] [blame] | 1139 | VG_(free)(base_dir); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1140 | |
| 1141 | instr_info_table = VG_(HT_construct)(); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | void SK_(post_clo_init)(void) |
| 1145 | { |
| 1146 | cache_t I1c, D1c, L2c; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1147 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame^] | 1148 | configure_caches(&I1c, &D1c, &L2c); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1149 | |
| 1150 | cachesim_I1_initcache(I1c); |
| 1151 | cachesim_D1_initcache(D1c); |
| 1152 | cachesim_L2_initcache(L2c); |
| 1153 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1154 | VGP_(register_profile_event)(VgpGetLineCC, "get-lineCC"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1155 | VGP_(register_profile_event)(VgpCacheSimulate, "cache-simulate"); |
| 1156 | VGP_(register_profile_event)(VgpCacheResults, "cache-results"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1159 | VG_DETERMINE_INTERFACE_VERSION(SK_(pre_clo_init), 0) |
| 1160 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1161 | /*--------------------------------------------------------------------*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 1162 | /*--- end cg_main.c ---*/ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1163 | /*--------------------------------------------------------------------*/ |