nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | 4f6f54b | 2009-01-07 02:34:06 +0000 | [diff] [blame] | 3 | /*--- x86-specific (and AMD64-specific) definitions. cg-x86.c ---*/ |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Cachegrind, a Valgrind tool for cache |
| 8 | profiling programs. |
| 9 | |
njn | 9f20746 | 2009-03-10 22:02:09 +0000 | [diff] [blame] | 10 | Copyright (C) 2002-2009 Nicholas Nethercote |
njn | 2bc1012 | 2005-05-08 02:10:27 +0000 | [diff] [blame] | 11 | njn@valgrind.org |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 31 | #include "pub_tool_basics.h" |
njn | 6898086 | 2005-06-18 18:31:26 +0000 | [diff] [blame] | 32 | #include "pub_tool_cpuid.h" |
njn | 97405b2 | 2005-06-02 03:39:33 +0000 | [diff] [blame] | 33 | #include "pub_tool_libcbase.h" |
njn | f39e9a3 | 2005-06-12 02:43:17 +0000 | [diff] [blame] | 34 | #include "pub_tool_libcassert.h" |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 35 | #include "pub_tool_libcprint.h" |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 36 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 37 | #include "cg_arch.h" |
| 38 | |
| 39 | // All CPUID info taken from sandpile.org/a32/cpuid.htm */ |
| 40 | // Probably only works for Intel and AMD chips, and probably only for some of |
| 41 | // them. |
| 42 | |
| 43 | static void micro_ops_warn(Int actual_size, Int used_size, Int line_size) |
| 44 | { |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 45 | VG_DMSG("warning: Pentium 4 with %d KB micro-op instruction trace cache", |
| 46 | actual_size); |
| 47 | VG_DMSG(" Simulating a %d KB I-cache with %d B lines", |
| 48 | used_size, line_size); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /* Intel method is truly wretched. We have to do an insane indexing into an |
| 52 | * array of pre-defined configurations for various parts of the memory |
weidendo | 1c3e3c5 | 2006-11-23 13:04:30 +0000 | [diff] [blame] | 53 | * hierarchy. |
| 54 | * According to Intel Processor Identification, App Note 485. |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 55 | */ |
| 56 | static |
| 57 | Int Intel_cache_info(Int level, cache_t* I1c, cache_t* D1c, cache_t* L2c) |
| 58 | { |
weidendo | 1c3e3c5 | 2006-11-23 13:04:30 +0000 | [diff] [blame] | 59 | Int cpuid1_eax; |
| 60 | Int cpuid1_ignore; |
| 61 | Int family; |
| 62 | Int model; |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 63 | UChar info[16]; |
| 64 | Int i, trials; |
| 65 | Bool L2_found = False; |
| 66 | |
| 67 | if (level < 2) { |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 68 | VG_DMSG("warning: CPUID level < 2 for Intel processor (%d)", level); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 69 | return -1; |
| 70 | } |
| 71 | |
weidendo | 1c3e3c5 | 2006-11-23 13:04:30 +0000 | [diff] [blame] | 72 | /* family/model needed to distinguish code reuse (currently 0x49) */ |
| 73 | VG_(cpuid)(1, &cpuid1_eax, &cpuid1_ignore, |
| 74 | &cpuid1_ignore, &cpuid1_ignore); |
| 75 | family = (((cpuid1_eax >> 20) & 0xff) << 4) + ((cpuid1_eax >> 8) & 0xf); |
| 76 | model = (((cpuid1_eax >> 16) & 0xf) << 4) + ((cpuid1_eax >> 4) & 0xf); |
| 77 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 78 | VG_(cpuid)(2, (Int*)&info[0], (Int*)&info[4], |
| 79 | (Int*)&info[8], (Int*)&info[12]); |
| 80 | trials = info[0] - 1; /* AL register - bits 0..7 of %eax */ |
| 81 | info[0] = 0x0; /* reset AL */ |
| 82 | |
| 83 | if (0 != trials) { |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 84 | VG_DMSG("warning: non-zero CPUID trials for Intel processor (%d)", |
| 85 | trials); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 86 | return -1; |
| 87 | } |
| 88 | |
| 89 | for (i = 0; i < 16; i++) { |
| 90 | |
| 91 | switch (info[i]) { |
| 92 | |
| 93 | case 0x0: /* ignore zeros */ |
| 94 | break; |
| 95 | |
| 96 | /* TLB info, ignore */ |
weidendo | 966b5bd | 2006-10-12 14:23:38 +0000 | [diff] [blame] | 97 | case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: |
tom | 1e76ff5 | 2009-01-02 11:07:18 +0000 | [diff] [blame] | 98 | case 0x4f: case 0x50: case 0x51: case 0x52: |
| 99 | case 0x56: case 0x57: case 0x59: |
weidendo | 966b5bd | 2006-10-12 14:23:38 +0000 | [diff] [blame] | 100 | case 0x5b: case 0x5c: case 0x5d: |
tom | 1e76ff5 | 2009-01-02 11:07:18 +0000 | [diff] [blame] | 101 | case 0xb0: case 0xb1: |
| 102 | case 0xb3: case 0xb4: case 0xba: case 0xc0: |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 103 | break; |
| 104 | |
| 105 | case 0x06: *I1c = (cache_t) { 8, 4, 32 }; break; |
| 106 | case 0x08: *I1c = (cache_t) { 16, 4, 32 }; break; |
| 107 | case 0x30: *I1c = (cache_t) { 32, 8, 64 }; break; |
| 108 | |
| 109 | case 0x0a: *D1c = (cache_t) { 8, 2, 32 }; break; |
| 110 | case 0x0c: *D1c = (cache_t) { 16, 4, 32 }; break; |
weidendo | 144b76c | 2009-01-26 22:56:14 +0000 | [diff] [blame] | 111 | case 0x0e: *D1c = (cache_t) { 24, 6, 64 }; break; |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 112 | case 0x2c: *D1c = (cache_t) { 32, 8, 64 }; break; |
| 113 | |
| 114 | /* IA-64 info -- panic! */ |
| 115 | case 0x10: case 0x15: case 0x1a: |
| 116 | case 0x88: case 0x89: case 0x8a: case 0x8d: |
| 117 | case 0x90: case 0x96: case 0x9b: |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 118 | VG_(tool_panic)("IA-64 cache detected?!"); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 119 | |
tom | 70c5e5a | 2009-01-02 10:42:27 +0000 | [diff] [blame] | 120 | case 0x22: case 0x23: case 0x25: case 0x29: |
| 121 | case 0x46: case 0x47: case 0x4a: case 0x4b: case 0x4c: case 0x4d: |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 122 | VG_DMSG("warning: L3 cache detected but ignored"); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 123 | break; |
| 124 | |
| 125 | /* These are sectored, whatever that means */ |
| 126 | case 0x39: *L2c = (cache_t) { 128, 4, 64 }; L2_found = True; break; |
| 127 | case 0x3c: *L2c = (cache_t) { 256, 4, 64 }; L2_found = True; break; |
| 128 | |
| 129 | /* If a P6 core, this means "no L2 cache". |
| 130 | If a P4 core, this means "no L3 cache". |
| 131 | We don't know what core it is, so don't issue a warning. To detect |
| 132 | a missing L2 cache, we use 'L2_found'. */ |
| 133 | case 0x40: |
| 134 | break; |
| 135 | |
| 136 | case 0x41: *L2c = (cache_t) { 128, 4, 32 }; L2_found = True; break; |
| 137 | case 0x42: *L2c = (cache_t) { 256, 4, 32 }; L2_found = True; break; |
| 138 | case 0x43: *L2c = (cache_t) { 512, 4, 32 }; L2_found = True; break; |
| 139 | case 0x44: *L2c = (cache_t) { 1024, 4, 32 }; L2_found = True; break; |
| 140 | case 0x45: *L2c = (cache_t) { 2048, 4, 32 }; L2_found = True; break; |
weidendo | 144b76c | 2009-01-26 22:56:14 +0000 | [diff] [blame] | 141 | case 0x48: *L2c = (cache_t) { 3072,12, 64 }; L2_found = True; break; |
weidendo | 1c3e3c5 | 2006-11-23 13:04:30 +0000 | [diff] [blame] | 142 | case 0x49: |
| 143 | if ((family == 15) && (model == 6)) |
| 144 | /* On Xeon MP (family F, model 6), this is for L3 */ |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 145 | VG_DMSG("warning: L3 cache detected but ignored"); |
weidendo | 1c3e3c5 | 2006-11-23 13:04:30 +0000 | [diff] [blame] | 146 | else |
| 147 | *L2c = (cache_t) { 4096, 16, 64 }; L2_found = True; |
| 148 | break; |
weidendo | 144b76c | 2009-01-26 22:56:14 +0000 | [diff] [blame] | 149 | case 0x4e: *L2c = (cache_t) { 6144, 24, 64 }; L2_found = True; break; |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 150 | |
| 151 | /* These are sectored, whatever that means */ |
nethercote | ac7ecd7 | 2004-10-13 11:30:14 +0000 | [diff] [blame] | 152 | case 0x60: *D1c = (cache_t) { 16, 8, 64 }; break; /* sectored */ |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 153 | case 0x66: *D1c = (cache_t) { 8, 4, 64 }; break; /* sectored */ |
| 154 | case 0x67: *D1c = (cache_t) { 16, 4, 64 }; break; /* sectored */ |
| 155 | case 0x68: *D1c = (cache_t) { 32, 4, 64 }; break; /* sectored */ |
| 156 | |
| 157 | /* HACK ALERT: Instruction trace cache -- capacity is micro-ops based. |
| 158 | * conversion to byte size is a total guess; treat the 12K and 16K |
| 159 | * cases the same since the cache byte size must be a power of two for |
| 160 | * everything to work!. Also guessing 32 bytes for the line size... |
| 161 | */ |
| 162 | case 0x70: /* 12K micro-ops, 8-way */ |
| 163 | *I1c = (cache_t) { 16, 8, 32 }; |
| 164 | micro_ops_warn(12, 16, 32); |
| 165 | break; |
| 166 | case 0x71: /* 16K micro-ops, 8-way */ |
| 167 | *I1c = (cache_t) { 16, 8, 32 }; |
| 168 | micro_ops_warn(16, 16, 32); |
| 169 | break; |
| 170 | case 0x72: /* 32K micro-ops, 8-way */ |
| 171 | *I1c = (cache_t) { 32, 8, 32 }; |
| 172 | micro_ops_warn(32, 32, 32); |
| 173 | break; |
| 174 | |
| 175 | /* These are sectored, whatever that means */ |
| 176 | case 0x79: *L2c = (cache_t) { 128, 8, 64 }; L2_found = True; break; |
| 177 | case 0x7a: *L2c = (cache_t) { 256, 8, 64 }; L2_found = True; break; |
| 178 | case 0x7b: *L2c = (cache_t) { 512, 8, 64 }; L2_found = True; break; |
| 179 | case 0x7c: *L2c = (cache_t) { 1024, 8, 64 }; L2_found = True; break; |
njn | 8bc8582 | 2005-07-20 04:32:44 +0000 | [diff] [blame] | 180 | case 0x7d: *L2c = (cache_t) { 2048, 8, 64 }; L2_found = True; break; |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 181 | case 0x7e: *L2c = (cache_t) { 256, 8, 128 }; L2_found = True; break; |
| 182 | |
tom | 1e76ff5 | 2009-01-02 11:07:18 +0000 | [diff] [blame] | 183 | case 0x7f: *L2c = (cache_t) { 512, 2, 64 }; L2_found = True; break; |
| 184 | case 0x80: *L2c = (cache_t) { 512, 8, 64 }; L2_found = True; break; |
| 185 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 186 | case 0x81: *L2c = (cache_t) { 128, 8, 32 }; L2_found = True; break; |
| 187 | case 0x82: *L2c = (cache_t) { 256, 8, 32 }; L2_found = True; break; |
| 188 | case 0x83: *L2c = (cache_t) { 512, 8, 32 }; L2_found = True; break; |
| 189 | case 0x84: *L2c = (cache_t) { 1024, 8, 32 }; L2_found = True; break; |
| 190 | case 0x85: *L2c = (cache_t) { 2048, 8, 32 }; L2_found = True; break; |
| 191 | case 0x86: *L2c = (cache_t) { 512, 4, 64 }; L2_found = True; break; |
| 192 | case 0x87: *L2c = (cache_t) { 1024, 8, 64 }; L2_found = True; break; |
| 193 | |
tom | 942d9ef | 2005-07-27 22:59:50 +0000 | [diff] [blame] | 194 | /* Ignore prefetch information */ |
| 195 | case 0xf0: case 0xf1: |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 196 | break; |
tom | 942d9ef | 2005-07-27 22:59:50 +0000 | [diff] [blame] | 197 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 198 | default: |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 199 | VG_DMSG("warning: Unknown Intel cache config value (0x%x), ignoring", |
| 200 | info[i]); |
| 201 | break; |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | if (!L2_found) |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 206 | VG_DMSG("warning: L2 cache not installed, ignore L2 results."); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | /* AMD method is straightforward, just extract appropriate bits from the |
| 212 | * result registers. |
| 213 | * |
| 214 | * Bits, for D1 and I1: |
| 215 | * 31..24 data L1 cache size in KBs |
| 216 | * 23..16 data L1 cache associativity (FFh=full) |
| 217 | * 15.. 8 data L1 cache lines per tag |
| 218 | * 7.. 0 data L1 cache line size in bytes |
| 219 | * |
| 220 | * Bits, for L2: |
| 221 | * 31..16 unified L2 cache size in KBs |
| 222 | * 15..12 unified L2 cache associativity (0=off, FFh=full) |
| 223 | * 11.. 8 unified L2 cache lines per tag |
| 224 | * 7.. 0 unified L2 cache line size in bytes |
| 225 | * |
| 226 | * #3 The AMD K7 processor's L2 cache must be configured prior to relying |
| 227 | * upon this information. (Whatever that means -- njn) |
| 228 | * |
| 229 | * Also, according to Cyrille Chepelov, Duron stepping A0 processors (model |
| 230 | * 0x630) have a bug and misreport their L2 size as 1KB (it's really 64KB), |
| 231 | * so we detect that. |
| 232 | * |
| 233 | * Returns 0 on success, non-zero on failure. |
| 234 | */ |
| 235 | static |
| 236 | Int AMD_cache_info(cache_t* I1c, cache_t* D1c, cache_t* L2c) |
| 237 | { |
| 238 | UInt ext_level; |
| 239 | UInt dummy, model; |
| 240 | UInt I1i, D1i, L2i; |
| 241 | |
| 242 | VG_(cpuid)(0x80000000, &ext_level, &dummy, &dummy, &dummy); |
| 243 | |
| 244 | if (0 == (ext_level & 0x80000000) || ext_level < 0x80000006) { |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 245 | VG_DMSG("warning: ext_level < 0x80000006 for AMD processor (0x%x)", |
| 246 | ext_level); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 247 | return -1; |
| 248 | } |
| 249 | |
| 250 | VG_(cpuid)(0x80000005, &dummy, &dummy, &D1i, &I1i); |
| 251 | VG_(cpuid)(0x80000006, &dummy, &dummy, &L2i, &dummy); |
| 252 | |
| 253 | VG_(cpuid)(0x1, &model, &dummy, &dummy, &dummy); |
| 254 | |
| 255 | /* Check for Duron bug */ |
| 256 | if (model == 0x630) { |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 257 | VG_DMSG("warning: Buggy Duron stepping A0. Assuming L2 size=65536 bytes"); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 258 | L2i = (64 << 16) | (L2i & 0xffff); |
| 259 | } |
| 260 | |
| 261 | D1c->size = (D1i >> 24) & 0xff; |
| 262 | D1c->assoc = (D1i >> 16) & 0xff; |
| 263 | D1c->line_size = (D1i >> 0) & 0xff; |
| 264 | |
| 265 | I1c->size = (I1i >> 24) & 0xff; |
| 266 | I1c->assoc = (I1i >> 16) & 0xff; |
| 267 | I1c->line_size = (I1i >> 0) & 0xff; |
| 268 | |
| 269 | L2c->size = (L2i >> 16) & 0xffff; /* Nb: different bits used for L2 */ |
| 270 | L2c->assoc = (L2i >> 12) & 0xf; |
| 271 | L2c->line_size = (L2i >> 0) & 0xff; |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 276 | static |
| 277 | Int get_caches_from_CPUID(cache_t* I1c, cache_t* D1c, cache_t* L2c) |
| 278 | { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 279 | Int level, ret; |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 280 | Char vendor_id[13]; |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 281 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 282 | if (!VG_(has_cpuid)()) { |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 283 | VG_DMSG("CPUID instruction not supported"); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 284 | return -1; |
| 285 | } |
tom | f4ed059 | 2005-04-02 17:30:19 +0000 | [diff] [blame] | 286 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 287 | VG_(cpuid)(0, &level, (int*)&vendor_id[0], |
| 288 | (int*)&vendor_id[8], (int*)&vendor_id[4]); |
| 289 | vendor_id[12] = '\0'; |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 290 | |
| 291 | if (0 == level) { |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 292 | VG_DMSG("CPUID level is 0, early Pentium?"); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 293 | return -1; |
| 294 | } |
| 295 | |
| 296 | /* Only handling Intel and AMD chips... no Cyrix, Transmeta, etc */ |
| 297 | if (0 == VG_(strcmp)(vendor_id, "GenuineIntel")) { |
| 298 | ret = Intel_cache_info(level, I1c, D1c, L2c); |
| 299 | |
| 300 | } else if (0 == VG_(strcmp)(vendor_id, "AuthenticAMD")) { |
| 301 | ret = AMD_cache_info(I1c, D1c, L2c); |
| 302 | |
| 303 | } else if (0 == VG_(strcmp)(vendor_id, "CentaurHauls")) { |
| 304 | /* Total kludge. Pretend to be a VIA Nehemiah. */ |
| 305 | D1c->size = 64; |
| 306 | D1c->assoc = 16; |
| 307 | D1c->line_size = 16; |
| 308 | I1c->size = 64; |
| 309 | I1c->assoc = 4; |
| 310 | I1c->line_size = 16; |
| 311 | L2c->size = 64; |
| 312 | L2c->assoc = 16; |
| 313 | L2c->line_size = 16; |
| 314 | ret = 0; |
| 315 | |
| 316 | } else { |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 317 | VG_DMSG("CPU vendor ID not recognised (%s)", vendor_id); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 318 | return -1; |
| 319 | } |
| 320 | |
| 321 | /* Successful! Convert sizes from KB to bytes */ |
| 322 | I1c->size *= 1024; |
| 323 | D1c->size *= 1024; |
| 324 | L2c->size *= 1024; |
| 325 | |
| 326 | return ret; |
| 327 | } |
| 328 | |
| 329 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 330 | void VG_(configure_caches)(cache_t* I1c, cache_t* D1c, cache_t* L2c, |
| 331 | Bool all_caches_clo_defined) |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 332 | { |
| 333 | Int res; |
| 334 | |
| 335 | // Set caches to default. |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 336 | *I1c = (cache_t) { 65536, 2, 64 }; |
| 337 | *D1c = (cache_t) { 65536, 2, 64 }; |
| 338 | *L2c = (cache_t) { 262144, 8, 64 }; |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 339 | |
| 340 | // Then replace with any info we can get from CPUID. |
| 341 | res = get_caches_from_CPUID(I1c, D1c, L2c); |
| 342 | |
| 343 | // Warn if CPUID failed and config not completely specified from cmd line. |
| 344 | if (res != 0 && !all_caches_clo_defined) { |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame^] | 345 | VG_DMSG("Warning: Couldn't auto-detect cache config, using one " |
| 346 | "or more defaults "); |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | /*--------------------------------------------------------------------*/ |
| 351 | /*--- end ---*/ |
| 352 | /*--------------------------------------------------------------------*/ |