PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/external/valgrind/main/cachegrind/cg-x86-amd64.c

https://gitlab.com/brian0218/rk3066_r-box_android4.2.2_sdk
C | 548 lines | 331 code | 69 blank | 148 comment | 51 complexity | 78d49fd2ad7ca9feb8a4578f99006d6d MD5 | raw file
  1. /*--------------------------------------------------------------------*/
  2. /*--- x86- and AMD64-specific definitions. cg-x86-amd64.c ---*/
  3. /*--------------------------------------------------------------------*/
  4. /*
  5. This file is part of Cachegrind, a Valgrind tool for cache
  6. profiling programs.
  7. Copyright (C) 2002-2011 Nicholas Nethercote
  8. njn@valgrind.org
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License as
  11. published by the Free Software Foundation; either version 2 of the
  12. License, or (at your option) any later version.
  13. This program is distributed in the hope that it will be useful, but
  14. WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  20. 02111-1307, USA.
  21. The GNU General Public License is contained in the file COPYING.
  22. */
  23. #if defined(VGA_x86) || defined(VGA_amd64)
  24. #include "pub_tool_basics.h"
  25. #include "pub_tool_cpuid.h"
  26. #include "pub_tool_libcbase.h"
  27. #include "pub_tool_libcassert.h"
  28. #include "pub_tool_libcprint.h"
  29. #include "cg_arch.h"
  30. // All CPUID info taken from sandpile.org/ia32/cpuid.htm */
  31. // Probably only works for Intel and AMD chips, and probably only for some of
  32. // them.
  33. static void micro_ops_warn(Int actual_size, Int used_size, Int line_size)
  34. {
  35. VG_(dmsg)("warning: Pentium 4 with %d KB micro-op instruction trace cache\n",
  36. actual_size);
  37. VG_(dmsg)(" Simulating a %d KB I-cache with %d B lines\n",
  38. used_size, line_size);
  39. }
  40. /* Intel method is truly wretched. We have to do an insane indexing into an
  41. * array of pre-defined configurations for various parts of the memory
  42. * hierarchy.
  43. * According to Intel Processor Identification, App Note 485.
  44. *
  45. * If a L3 cache is found, then data for it rather than the L2
  46. * is returned via *LLc.
  47. */
  48. static
  49. Int Intel_cache_info(Int level, cache_t* I1c, cache_t* D1c, cache_t* LLc)
  50. {
  51. Int cpuid1_eax;
  52. Int cpuid1_ignore;
  53. Int family;
  54. Int model;
  55. UChar info[16];
  56. Int i, j, trials;
  57. Bool L2_found = False;
  58. /* If we see L3 cache info, copy it into L3c. Then, at the end,
  59. copy it into *LLc. Hence if a L3 cache is specified, *LLc will
  60. eventually contain a description of it rather than the L2 cache.
  61. The use of the L3c intermediary makes this process independent
  62. of the order in which the cache specifications appear in
  63. info[]. */
  64. Bool L3_found = False;
  65. cache_t L3c = { 0, 0, 0 };
  66. if (level < 2) {
  67. VG_(dmsg)("warning: CPUID level < 2 for Intel processor (%d)\n", level);
  68. return -1;
  69. }
  70. /* family/model needed to distinguish code reuse (currently 0x49) */
  71. VG_(cpuid)(1, 0, &cpuid1_eax, &cpuid1_ignore,
  72. &cpuid1_ignore, &cpuid1_ignore);
  73. family = (((cpuid1_eax >> 20) & 0xff) << 4) + ((cpuid1_eax >> 8) & 0xf);
  74. model = (((cpuid1_eax >> 16) & 0xf) << 4) + ((cpuid1_eax >> 4) & 0xf);
  75. VG_(cpuid)(2, 0, (Int*)&info[0], (Int*)&info[4],
  76. (Int*)&info[8], (Int*)&info[12]);
  77. trials = info[0] - 1; /* AL register - bits 0..7 of %eax */
  78. info[0] = 0x0; /* reset AL */
  79. if (0 != trials) {
  80. VG_(dmsg)("warning: non-zero CPUID trials for Intel processor (%d)\n",
  81. trials);
  82. return -1;
  83. }
  84. for (i = 0; i < 16; i++) {
  85. switch (info[i]) {
  86. case 0x0: /* ignore zeros */
  87. break;
  88. /* TLB info, ignore */
  89. case 0x01: case 0x02: case 0x03: case 0x04: case 0x05:
  90. case 0x0b:
  91. case 0x4f: case 0x50: case 0x51: case 0x52: case 0x55:
  92. case 0x56: case 0x57: case 0x59:
  93. case 0x5a: case 0x5b: case 0x5c: case 0x5d:
  94. case 0x76:
  95. case 0xb0: case 0xb1: case 0xb2:
  96. case 0xb3: case 0xb4: case 0xba: case 0xc0:
  97. case 0xca:
  98. break;
  99. case 0x06: *I1c = (cache_t) { 8, 4, 32 }; break;
  100. case 0x08: *I1c = (cache_t) { 16, 4, 32 }; break;
  101. case 0x09: *I1c = (cache_t) { 32, 4, 64 }; break;
  102. case 0x30: *I1c = (cache_t) { 32, 8, 64 }; break;
  103. case 0x0a: *D1c = (cache_t) { 8, 2, 32 }; break;
  104. case 0x0c: *D1c = (cache_t) { 16, 4, 32 }; break;
  105. case 0x0d: *D1c = (cache_t) { 16, 4, 64 }; break;
  106. case 0x0e: *D1c = (cache_t) { 24, 6, 64 }; break;
  107. case 0x2c: *D1c = (cache_t) { 32, 8, 64 }; break;
  108. /* IA-64 info -- panic! */
  109. case 0x10: case 0x15: case 0x1a:
  110. case 0x88: case 0x89: case 0x8a: case 0x8d:
  111. case 0x90: case 0x96: case 0x9b:
  112. VG_(tool_panic)("IA-64 cache detected?!");
  113. /* L3 cache info. */
  114. case 0x22: L3c = (cache_t) { 512, 4, 64 }; L3_found = True; break;
  115. case 0x23: L3c = (cache_t) { 1024, 8, 64 }; L3_found = True; break;
  116. case 0x25: L3c = (cache_t) { 2048, 8, 64 }; L3_found = True; break;
  117. case 0x29: L3c = (cache_t) { 4096, 8, 64 }; L3_found = True; break;
  118. case 0x46: L3c = (cache_t) { 4096, 4, 64 }; L3_found = True; break;
  119. case 0x47: L3c = (cache_t) { 8192, 8, 64 }; L3_found = True; break;
  120. case 0x4a: L3c = (cache_t) { 6144, 12, 64 }; L3_found = True; break;
  121. case 0x4b: L3c = (cache_t) { 8192, 16, 64 }; L3_found = True; break;
  122. case 0x4c: L3c = (cache_t) { 12288, 12, 64 }; L3_found = True; break;
  123. case 0x4d: L3c = (cache_t) { 16384, 16, 64 }; L3_found = True; break;
  124. case 0xd0: L3c = (cache_t) { 512, 4, 64 }; L3_found = True; break;
  125. case 0xd1: L3c = (cache_t) { 1024, 4, 64 }; L3_found = True; break;
  126. case 0xd2: L3c = (cache_t) { 2048, 4, 64 }; L3_found = True; break;
  127. case 0xd6: L3c = (cache_t) { 1024, 8, 64 }; L3_found = True; break;
  128. case 0xd7: L3c = (cache_t) { 2048, 8, 64 }; L3_found = True; break;
  129. case 0xd8: L3c = (cache_t) { 4096, 8, 64 }; L3_found = True; break;
  130. case 0xdc: L3c = (cache_t) { 1536, 12, 64 }; L3_found = True; break;
  131. case 0xdd: L3c = (cache_t) { 3072, 12, 64 }; L3_found = True; break;
  132. case 0xde: L3c = (cache_t) { 6144, 12, 64 }; L3_found = True; break;
  133. case 0xe2: L3c = (cache_t) { 2048, 16, 64 }; L3_found = True; break;
  134. case 0xe3: L3c = (cache_t) { 4096, 16, 64 }; L3_found = True; break;
  135. case 0xe4: L3c = (cache_t) { 8192, 16, 64 }; L3_found = True; break;
  136. case 0xea: L3c = (cache_t) { 12288, 24, 64 }; L3_found = True; break;
  137. case 0xeb: L3c = (cache_t) { 18432, 24, 64 }; L3_found = True; break;
  138. case 0xec: L3c = (cache_t) { 24576, 24, 64 }; L3_found = True; break;
  139. /* Described as "MLC" in Intel documentation */
  140. case 0x21: *LLc = (cache_t) { 256, 8, 64 }; L2_found = True; break;
  141. /* These are sectored, whatever that means */
  142. case 0x39: *LLc = (cache_t) { 128, 4, 64 }; L2_found = True; break;
  143. case 0x3c: *LLc = (cache_t) { 256, 4, 64 }; L2_found = True; break;
  144. /* If a P6 core, this means "no L2 cache".
  145. If a P4 core, this means "no L3 cache".
  146. We don't know what core it is, so don't issue a warning. To detect
  147. a missing L2 cache, we use 'L2_found'. */
  148. case 0x40:
  149. break;
  150. case 0x41: *LLc = (cache_t) { 128, 4, 32 }; L2_found = True; break;
  151. case 0x42: *LLc = (cache_t) { 256, 4, 32 }; L2_found = True; break;
  152. case 0x43: *LLc = (cache_t) { 512, 4, 32 }; L2_found = True; break;
  153. case 0x44: *LLc = (cache_t) { 1024, 4, 32 }; L2_found = True; break;
  154. case 0x45: *LLc = (cache_t) { 2048, 4, 32 }; L2_found = True; break;
  155. case 0x48: *LLc = (cache_t) { 3072, 12, 64 }; L2_found = True; break;
  156. case 0x4e: *LLc = (cache_t) { 6144, 24, 64 }; L2_found = True; break;
  157. case 0x49:
  158. if (family == 15 && model == 6) {
  159. /* On Xeon MP (family F, model 6), this is for L3 */
  160. L3c = (cache_t) { 4096, 16, 64 }; L3_found = True;
  161. } else {
  162. *LLc = (cache_t) { 4096, 16, 64 }; L2_found = True;
  163. }
  164. break;
  165. /* These are sectored, whatever that means */
  166. case 0x60: *D1c = (cache_t) { 16, 8, 64 }; break; /* sectored */
  167. case 0x66: *D1c = (cache_t) { 8, 4, 64 }; break; /* sectored */
  168. case 0x67: *D1c = (cache_t) { 16, 4, 64 }; break; /* sectored */
  169. case 0x68: *D1c = (cache_t) { 32, 4, 64 }; break; /* sectored */
  170. /* HACK ALERT: Instruction trace cache -- capacity is micro-ops based.
  171. * conversion to byte size is a total guess; treat the 12K and 16K
  172. * cases the same since the cache byte size must be a power of two for
  173. * everything to work!. Also guessing 32 bytes for the line size...
  174. */
  175. case 0x70: /* 12K micro-ops, 8-way */
  176. *I1c = (cache_t) { 16, 8, 32 };
  177. micro_ops_warn(12, 16, 32);
  178. break;
  179. case 0x71: /* 16K micro-ops, 8-way */
  180. *I1c = (cache_t) { 16, 8, 32 };
  181. micro_ops_warn(16, 16, 32);
  182. break;
  183. case 0x72: /* 32K micro-ops, 8-way */
  184. *I1c = (cache_t) { 32, 8, 32 };
  185. micro_ops_warn(32, 32, 32);
  186. break;
  187. /* not sectored, whatever that might mean */
  188. case 0x78: *LLc = (cache_t) { 1024, 4, 64 }; L2_found = True; break;
  189. /* These are sectored, whatever that means */
  190. case 0x79: *LLc = (cache_t) { 128, 8, 64 }; L2_found = True; break;
  191. case 0x7a: *LLc = (cache_t) { 256, 8, 64 }; L2_found = True; break;
  192. case 0x7b: *LLc = (cache_t) { 512, 8, 64 }; L2_found = True; break;
  193. case 0x7c: *LLc = (cache_t) { 1024, 8, 64 }; L2_found = True; break;
  194. case 0x7d: *LLc = (cache_t) { 2048, 8, 64 }; L2_found = True; break;
  195. case 0x7e: *LLc = (cache_t) { 256, 8, 128 }; L2_found = True; break;
  196. case 0x7f: *LLc = (cache_t) { 512, 2, 64 }; L2_found = True; break;
  197. case 0x80: *LLc = (cache_t) { 512, 8, 64 }; L2_found = True; break;
  198. case 0x81: *LLc = (cache_t) { 128, 8, 32 }; L2_found = True; break;
  199. case 0x82: *LLc = (cache_t) { 256, 8, 32 }; L2_found = True; break;
  200. case 0x83: *LLc = (cache_t) { 512, 8, 32 }; L2_found = True; break;
  201. case 0x84: *LLc = (cache_t) { 1024, 8, 32 }; L2_found = True; break;
  202. case 0x85: *LLc = (cache_t) { 2048, 8, 32 }; L2_found = True; break;
  203. case 0x86: *LLc = (cache_t) { 512, 4, 64 }; L2_found = True; break;
  204. case 0x87: *LLc = (cache_t) { 1024, 8, 64 }; L2_found = True; break;
  205. /* Ignore prefetch information */
  206. case 0xf0: case 0xf1:
  207. break;
  208. case 0xff:
  209. j = 0;
  210. VG_(cpuid)(4, j++, (Int*)&info[0], (Int*)&info[4],
  211. (Int*)&info[8], (Int*)&info[12]);
  212. while ((info[0] & 0x1f) != 0) {
  213. UInt assoc = ((*(UInt *)&info[4] >> 22) & 0x3ff) + 1;
  214. UInt parts = ((*(UInt *)&info[4] >> 12) & 0x3ff) + 1;
  215. UInt line_size = (*(UInt *)&info[4] & 0x7ff) + 1;
  216. UInt sets = *(UInt *)&info[8] + 1;
  217. cache_t c;
  218. c.size = assoc * parts * line_size * sets / 1024;
  219. c.assoc = assoc;
  220. c.line_size = line_size;
  221. switch ((info[0] & 0xe0) >> 5)
  222. {
  223. case 1:
  224. switch (info[0] & 0x1f)
  225. {
  226. case 1: *D1c = c; break;
  227. case 2: *I1c = c; break;
  228. case 3: VG_(dmsg)("warning: L1 unified cache ignored\n"); break;
  229. default: VG_(dmsg)("warning: L1 cache of unknown type ignored\n"); break;
  230. }
  231. break;
  232. case 2:
  233. switch (info[0] & 0x1f)
  234. {
  235. case 1: VG_(dmsg)("warning: L2 data cache ignored\n"); break;
  236. case 2: VG_(dmsg)("warning: L2 instruction cache ignored\n"); break;
  237. case 3: *LLc = c; L2_found = True; break;
  238. default: VG_(dmsg)("warning: L2 cache of unknown type ignored\n"); break;
  239. }
  240. break;
  241. case 3:
  242. switch (info[0] & 0x1f)
  243. {
  244. case 1: VG_(dmsg)("warning: L3 data cache ignored\n"); break;
  245. case 2: VG_(dmsg)("warning: L3 instruction cache ignored\n"); break;
  246. case 3: L3c = c; L3_found = True; break;
  247. default: VG_(dmsg)("warning: L3 cache of unknown type ignored\n"); break;
  248. }
  249. break;
  250. default:
  251. VG_(dmsg)("warning: L%u cache ignored\n", (info[0] & 0xe0) >> 5);
  252. break;
  253. }
  254. VG_(cpuid)(4, j++, (Int*)&info[0], (Int*)&info[4],
  255. (Int*)&info[8], (Int*)&info[12]);
  256. }
  257. break;
  258. default:
  259. VG_(dmsg)("warning: Unknown Intel cache config value (0x%x), ignoring\n",
  260. info[i]);
  261. break;
  262. }
  263. }
  264. /* If we found a L3 cache, throw away the L2 data and use the L3's instead. */
  265. if (L3_found) {
  266. VG_(dmsg)("warning: L3 cache found, using its data for the LL simulation.\n");
  267. *LLc = L3c;
  268. L2_found = True;
  269. }
  270. if (!L2_found)
  271. VG_(dmsg)("warning: L2 cache not installed, ignore LL results.\n");
  272. return 0;
  273. }
  274. /* AMD method is straightforward, just extract appropriate bits from the
  275. * result registers.
  276. *
  277. * Bits, for D1 and I1:
  278. * 31..24 data L1 cache size in KBs
  279. * 23..16 data L1 cache associativity (FFh=full)
  280. * 15.. 8 data L1 cache lines per tag
  281. * 7.. 0 data L1 cache line size in bytes
  282. *
  283. * Bits, for L2:
  284. * 31..16 unified L2 cache size in KBs
  285. * 15..12 unified L2 cache associativity (0=off, FFh=full)
  286. * 11.. 8 unified L2 cache lines per tag
  287. * 7.. 0 unified L2 cache line size in bytes
  288. *
  289. * #3 The AMD K7 processor's L2 cache must be configured prior to relying
  290. * upon this information. (Whatever that means -- njn)
  291. *
  292. * Also, according to Cyrille Chepelov, Duron stepping A0 processors (model
  293. * 0x630) have a bug and misreport their L2 size as 1KB (it's really 64KB),
  294. * so we detect that.
  295. *
  296. * Returns 0 on success, non-zero on failure. As with the Intel code
  297. * above, if a L3 cache is found, then data for it rather than the L2
  298. * is returned via *LLc.
  299. */
  300. /* A small helper */
  301. static Int decode_AMD_cache_L2_L3_assoc ( Int bits_15_12 )
  302. {
  303. /* Decode a L2/L3 associativity indication. It is encoded
  304. differently from the I1/D1 associativity. Returns 1
  305. (direct-map) as a safe but suboptimal result for unknown
  306. encodings. */
  307. switch (bits_15_12 & 0xF) {
  308. case 1: return 1; case 2: return 2;
  309. case 4: return 4; case 6: return 8;
  310. case 8: return 16; case 0xA: return 32;
  311. case 0xB: return 48; case 0xC: return 64;
  312. case 0xD: return 96; case 0xE: return 128;
  313. case 0xF: /* fully associative */
  314. case 0: /* L2/L3 cache or TLB is disabled */
  315. default:
  316. return 1;
  317. }
  318. }
  319. static
  320. Int AMD_cache_info(cache_t* I1c, cache_t* D1c, cache_t* LLc)
  321. {
  322. UInt ext_level;
  323. UInt dummy, model;
  324. UInt I1i, D1i, L2i, L3i;
  325. VG_(cpuid)(0x80000000, 0, &ext_level, &dummy, &dummy, &dummy);
  326. if (0 == (ext_level & 0x80000000) || ext_level < 0x80000006) {
  327. VG_(dmsg)("warning: ext_level < 0x80000006 for AMD processor (0x%x)\n",
  328. ext_level);
  329. return -1;
  330. }
  331. VG_(cpuid)(0x80000005, 0, &dummy, &dummy, &D1i, &I1i);
  332. VG_(cpuid)(0x80000006, 0, &dummy, &dummy, &L2i, &L3i);
  333. VG_(cpuid)(0x1, 0, &model, &dummy, &dummy, &dummy);
  334. /* Check for Duron bug */
  335. if (model == 0x630) {
  336. VG_(dmsg)("warning: Buggy Duron stepping A0. Assuming L2 size=65536 bytes\n");
  337. L2i = (64 << 16) | (L2i & 0xffff);
  338. }
  339. D1c->size = (D1i >> 24) & 0xff;
  340. D1c->assoc = (D1i >> 16) & 0xff;
  341. D1c->line_size = (D1i >> 0) & 0xff;
  342. I1c->size = (I1i >> 24) & 0xff;
  343. I1c->assoc = (I1i >> 16) & 0xff;
  344. I1c->line_size = (I1i >> 0) & 0xff;
  345. LLc->size = (L2i >> 16) & 0xffff; /* Nb: different bits used for L2 */
  346. LLc->assoc = decode_AMD_cache_L2_L3_assoc((L2i >> 12) & 0xf);
  347. LLc->line_size = (L2i >> 0) & 0xff;
  348. if (((L3i >> 18) & 0x3fff) > 0) {
  349. /* There's an L3 cache. Replace *LLc contents with this info. */
  350. /* NB: the test in the if is "if L3 size > 0 ". I don't know if
  351. this is the right way to test presence-vs-absence of L3. I
  352. can't see any guidance on this in the AMD documentation. */
  353. LLc->size = ((L3i >> 18) & 0x3fff) * 512;
  354. LLc->assoc = decode_AMD_cache_L2_L3_assoc((L3i >> 12) & 0xf);
  355. LLc->line_size = (L3i >> 0) & 0xff;
  356. VG_(dmsg)("warning: L3 cache found, using its data for the L2 simulation.\n");
  357. }
  358. return 0;
  359. }
  360. static
  361. Int get_caches_from_CPUID(cache_t* I1c, cache_t* D1c, cache_t* LLc)
  362. {
  363. Int level, ret;
  364. Char vendor_id[13];
  365. if (!VG_(has_cpuid)()) {
  366. VG_(dmsg)("CPUID instruction not supported\n");
  367. return -1;
  368. }
  369. VG_(cpuid)(0, 0, &level, (int*)&vendor_id[0],
  370. (int*)&vendor_id[8], (int*)&vendor_id[4]);
  371. vendor_id[12] = '\0';
  372. if (0 == level) {
  373. VG_(dmsg)("CPUID level is 0, early Pentium?\n");
  374. return -1;
  375. }
  376. /* Only handling Intel and AMD chips... no Cyrix, Transmeta, etc */
  377. if (0 == VG_(strcmp)(vendor_id, "GenuineIntel")) {
  378. ret = Intel_cache_info(level, I1c, D1c, LLc);
  379. } else if (0 == VG_(strcmp)(vendor_id, "AuthenticAMD")) {
  380. ret = AMD_cache_info(I1c, D1c, LLc);
  381. } else if (0 == VG_(strcmp)(vendor_id, "CentaurHauls")) {
  382. /* Total kludge. Pretend to be a VIA Nehemiah. */
  383. D1c->size = 64;
  384. D1c->assoc = 16;
  385. D1c->line_size = 16;
  386. I1c->size = 64;
  387. I1c->assoc = 4;
  388. I1c->line_size = 16;
  389. LLc->size = 64;
  390. LLc->assoc = 16;
  391. LLc->line_size = 16;
  392. ret = 0;
  393. } else {
  394. VG_(dmsg)("CPU vendor ID not recognised (%s)\n", vendor_id);
  395. return -1;
  396. }
  397. /* Successful! Convert sizes from KB to bytes */
  398. I1c->size *= 1024;
  399. D1c->size *= 1024;
  400. LLc->size *= 1024;
  401. /* If the LL cache config isn't something the simulation functions
  402. can handle, try to adjust it so it is. Caches are characterised
  403. by (total size T, line size L, associativity A), and then we
  404. have
  405. number of sets S = T / (L * A)
  406. The required constraints are:
  407. * L must be a power of 2, but it always is in practice, so
  408. no problem there
  409. * A can be any value >= 1
  410. * T can be any value, but ..
  411. * S must be a power of 2.
  412. That sometimes gives a problem. For example, some Core iX based
  413. Intel CPUs have T = 12MB, A = 16, L = 64, which gives 12288
  414. sets. The "fix" in this case is to increase the associativity
  415. by 50% to 24, which reduces the number of sets to 8192, making
  416. it a power of 2. That's what the following code does (handing
  417. the "3/2 rescaling case".) We might need to deal with other
  418. ratios later (5/4 ?).
  419. The "fix" is "justified" (cough, cough) by alleging that
  420. increases of associativity above about 4 have very little effect
  421. on the actual miss rate. It would be far more inaccurate to
  422. fudge this by changing the size of the simulated cache --
  423. changing the associativity is a much better option.
  424. */
  425. if (LLc->size > 0 && LLc->assoc > 0 && LLc->line_size > 0) {
  426. Long nSets = (Long)LLc->size / (Long)(LLc->line_size * LLc->assoc);
  427. if (/* stay sane */
  428. nSets >= 4
  429. /* nSets is not a power of 2 */
  430. && VG_(log2_64)( (ULong)nSets ) == -1
  431. /* nSets is 50% above a power of 2 */
  432. && VG_(log2_64)( (ULong)((2 * nSets) / (Long)3) ) != -1
  433. /* associativity can be increased by exactly 50% */
  434. && (LLc->assoc % 2) == 0
  435. ) {
  436. /* # sets is 1.5 * a power of two, but the associativity is
  437. even, so we can increase that up by 50% and implicitly
  438. scale the # sets down accordingly. */
  439. Int new_assoc = LLc->assoc + (LLc->assoc / 2);
  440. VG_(dmsg)("warning: pretending that LL cache has associativity"
  441. " %d instead of actual %d\n", new_assoc, LLc->assoc);
  442. LLc->assoc = new_assoc;
  443. }
  444. }
  445. return ret;
  446. }
  447. void VG_(configure_caches)(cache_t* I1c, cache_t* D1c, cache_t* LLc,
  448. Bool all_caches_clo_defined)
  449. {
  450. Int res;
  451. // Set caches to default.
  452. *I1c = (cache_t) { 65536, 2, 64 };
  453. *D1c = (cache_t) { 65536, 2, 64 };
  454. *LLc = (cache_t) { 262144, 8, 64 };
  455. // Then replace with any info we can get from CPUID.
  456. res = get_caches_from_CPUID(I1c, D1c, LLc);
  457. // Warn if CPUID failed and config not completely specified from cmd line.
  458. if (res != 0 && !all_caches_clo_defined) {
  459. VG_(dmsg)("Warning: Couldn't auto-detect cache config, using one "
  460. "or more defaults \n");
  461. }
  462. }
  463. #endif // defined(VGA_x86) || defined(VGA_amd64)
  464. /*--------------------------------------------------------------------*/
  465. /*--- end ---*/
  466. /*--------------------------------------------------------------------*/