intel_cacheinfo.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. /*
  2. * Routines to indentify caches on Intel CPU.
  3. *
  4. * Changes:
  5. * Venkatesh Pallipadi : Adding cache identification through cpuid(4)
  6. * Ashok Raj <ashok.raj@intel.com>: Work with CPU hotplug infrastructure.
  7. * Andi Kleen / Andreas Herrmann : CPUID4 emulation on AMD.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/slab.h>
  11. #include <linux/device.h>
  12. #include <linux/compiler.h>
  13. #include <linux/cpu.h>
  14. #include <linux/sched.h>
  15. #include <linux/pci.h>
  16. #include <asm/processor.h>
  17. #include <linux/smp.h>
  18. #include <asm/amd_nb.h>
  19. #include <asm/smp.h>
  20. #define LVL_1_INST 1
  21. #define LVL_1_DATA 2
  22. #define LVL_2 3
  23. #define LVL_3 4
  24. #define LVL_TRACE 5
  25. struct _cache_table {
  26. unsigned char descriptor;
  27. char cache_type;
  28. short size;
  29. };
  30. #define MB(x) ((x) * 1024)
  31. /* All the cache descriptor types we care about (no TLB or
  32. trace cache entries) */
  33. static const struct _cache_table __cpuinitconst cache_table[] =
  34. {
  35. { 0x06, LVL_1_INST, 8 }, /* 4-way set assoc, 32 byte line size */
  36. { 0x08, LVL_1_INST, 16 }, /* 4-way set assoc, 32 byte line size */
  37. { 0x09, LVL_1_INST, 32 }, /* 4-way set assoc, 64 byte line size */
  38. { 0x0a, LVL_1_DATA, 8 }, /* 2 way set assoc, 32 byte line size */
  39. { 0x0c, LVL_1_DATA, 16 }, /* 4-way set assoc, 32 byte line size */
  40. { 0x0d, LVL_1_DATA, 16 }, /* 4-way set assoc, 64 byte line size */
  41. { 0x21, LVL_2, 256 }, /* 8-way set assoc, 64 byte line size */
  42. { 0x22, LVL_3, 512 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  43. { 0x23, LVL_3, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte line size */
  44. { 0x25, LVL_3, MB(2) }, /* 8-way set assoc, sectored cache, 64 byte line size */
  45. { 0x29, LVL_3, MB(4) }, /* 8-way set assoc, sectored cache, 64 byte line size */
  46. { 0x2c, LVL_1_DATA, 32 }, /* 8-way set assoc, 64 byte line size */
  47. { 0x30, LVL_1_INST, 32 }, /* 8-way set assoc, 64 byte line size */
  48. { 0x39, LVL_2, 128 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  49. { 0x3a, LVL_2, 192 }, /* 6-way set assoc, sectored cache, 64 byte line size */
  50. { 0x3b, LVL_2, 128 }, /* 2-way set assoc, sectored cache, 64 byte line size */
  51. { 0x3c, LVL_2, 256 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  52. { 0x3d, LVL_2, 384 }, /* 6-way set assoc, sectored cache, 64 byte line size */
  53. { 0x3e, LVL_2, 512 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  54. { 0x3f, LVL_2, 256 }, /* 2-way set assoc, 64 byte line size */
  55. { 0x41, LVL_2, 128 }, /* 4-way set assoc, 32 byte line size */
  56. { 0x42, LVL_2, 256 }, /* 4-way set assoc, 32 byte line size */
  57. { 0x43, LVL_2, 512 }, /* 4-way set assoc, 32 byte line size */
  58. { 0x44, LVL_2, MB(1) }, /* 4-way set assoc, 32 byte line size */
  59. { 0x45, LVL_2, MB(2) }, /* 4-way set assoc, 32 byte line size */
  60. { 0x46, LVL_3, MB(4) }, /* 4-way set assoc, 64 byte line size */
  61. { 0x47, LVL_3, MB(8) }, /* 8-way set assoc, 64 byte line size */
  62. { 0x49, LVL_3, MB(4) }, /* 16-way set assoc, 64 byte line size */
  63. { 0x4a, LVL_3, MB(6) }, /* 12-way set assoc, 64 byte line size */
  64. { 0x4b, LVL_3, MB(8) }, /* 16-way set assoc, 64 byte line size */
  65. { 0x4c, LVL_3, MB(12) }, /* 12-way set assoc, 64 byte line size */
  66. { 0x4d, LVL_3, MB(16) }, /* 16-way set assoc, 64 byte line size */
  67. { 0x4e, LVL_2, MB(6) }, /* 24-way set assoc, 64 byte line size */
  68. { 0x60, LVL_1_DATA, 16 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  69. { 0x66, LVL_1_DATA, 8 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  70. { 0x67, LVL_1_DATA, 16 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  71. { 0x68, LVL_1_DATA, 32 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  72. { 0x70, LVL_TRACE, 12 }, /* 8-way set assoc */
  73. { 0x71, LVL_TRACE, 16 }, /* 8-way set assoc */
  74. { 0x72, LVL_TRACE, 32 }, /* 8-way set assoc */
  75. { 0x73, LVL_TRACE, 64 }, /* 8-way set assoc */
  76. { 0x78, LVL_2, MB(1) }, /* 4-way set assoc, 64 byte line size */
  77. { 0x79, LVL_2, 128 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  78. { 0x7a, LVL_2, 256 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  79. { 0x7b, LVL_2, 512 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  80. { 0x7c, LVL_2, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte line size */
  81. { 0x7d, LVL_2, MB(2) }, /* 8-way set assoc, 64 byte line size */
  82. { 0x7f, LVL_2, 512 }, /* 2-way set assoc, 64 byte line size */
  83. { 0x82, LVL_2, 256 }, /* 8-way set assoc, 32 byte line size */
  84. { 0x83, LVL_2, 512 }, /* 8-way set assoc, 32 byte line size */
  85. { 0x84, LVL_2, MB(1) }, /* 8-way set assoc, 32 byte line size */
  86. { 0x85, LVL_2, MB(2) }, /* 8-way set assoc, 32 byte line size */
  87. { 0x86, LVL_2, 512 }, /* 4-way set assoc, 64 byte line size */
  88. { 0x87, LVL_2, MB(1) }, /* 8-way set assoc, 64 byte line size */
  89. { 0xd0, LVL_3, 512 }, /* 4-way set assoc, 64 byte line size */
  90. { 0xd1, LVL_3, MB(1) }, /* 4-way set assoc, 64 byte line size */
  91. { 0xd2, LVL_3, MB(2) }, /* 4-way set assoc, 64 byte line size */
  92. { 0xd6, LVL_3, MB(1) }, /* 8-way set assoc, 64 byte line size */
  93. { 0xd7, LVL_3, MB(2) }, /* 8-way set assoc, 64 byte line size */
  94. { 0xd8, LVL_3, MB(4) }, /* 12-way set assoc, 64 byte line size */
  95. { 0xdc, LVL_3, MB(2) }, /* 12-way set assoc, 64 byte line size */
  96. { 0xdd, LVL_3, MB(4) }, /* 12-way set assoc, 64 byte line size */
  97. { 0xde, LVL_3, MB(8) }, /* 12-way set assoc, 64 byte line size */
  98. { 0xe2, LVL_3, MB(2) }, /* 16-way set assoc, 64 byte line size */
  99. { 0xe3, LVL_3, MB(4) }, /* 16-way set assoc, 64 byte line size */
  100. { 0xe4, LVL_3, MB(8) }, /* 16-way set assoc, 64 byte line size */
  101. { 0xea, LVL_3, MB(12) }, /* 24-way set assoc, 64 byte line size */
  102. { 0xeb, LVL_3, MB(18) }, /* 24-way set assoc, 64 byte line size */
  103. { 0xec, LVL_3, MB(24) }, /* 24-way set assoc, 64 byte line size */
  104. { 0x00, 0, 0}
  105. };
  106. enum _cache_type {
  107. CACHE_TYPE_NULL = 0,
  108. CACHE_TYPE_DATA = 1,
  109. CACHE_TYPE_INST = 2,
  110. CACHE_TYPE_UNIFIED = 3
  111. };
  112. union _cpuid4_leaf_eax {
  113. struct {
  114. enum _cache_type type:5;
  115. unsigned int level:3;
  116. unsigned int is_self_initializing:1;
  117. unsigned int is_fully_associative:1;
  118. unsigned int reserved:4;
  119. unsigned int num_threads_sharing:12;
  120. unsigned int num_cores_on_die:6;
  121. } split;
  122. u32 full;
  123. };
  124. union _cpuid4_leaf_ebx {
  125. struct {
  126. unsigned int coherency_line_size:12;
  127. unsigned int physical_line_partition:10;
  128. unsigned int ways_of_associativity:10;
  129. } split;
  130. u32 full;
  131. };
  132. union _cpuid4_leaf_ecx {
  133. struct {
  134. unsigned int number_of_sets:32;
  135. } split;
  136. u32 full;
  137. };
  138. struct amd_l3_cache {
  139. struct amd_northbridge *nb;
  140. unsigned indices;
  141. u8 subcaches[4];
  142. };
  143. struct _cpuid4_info {
  144. union _cpuid4_leaf_eax eax;
  145. union _cpuid4_leaf_ebx ebx;
  146. union _cpuid4_leaf_ecx ecx;
  147. unsigned long size;
  148. struct amd_l3_cache *l3;
  149. DECLARE_BITMAP(shared_cpu_map, NR_CPUS);
  150. };
  151. /* subset of above _cpuid4_info w/o shared_cpu_map */
  152. struct _cpuid4_info_regs {
  153. union _cpuid4_leaf_eax eax;
  154. union _cpuid4_leaf_ebx ebx;
  155. union _cpuid4_leaf_ecx ecx;
  156. unsigned long size;
  157. struct amd_l3_cache *l3;
  158. };
  159. unsigned short num_cache_leaves;
  160. /* AMD doesn't have CPUID4. Emulate it here to report the same
  161. information to the user. This makes some assumptions about the machine:
  162. L2 not shared, no SMT etc. that is currently true on AMD CPUs.
  163. In theory the TLBs could be reported as fake type (they are in "dummy").
  164. Maybe later */
  165. union l1_cache {
  166. struct {
  167. unsigned line_size:8;
  168. unsigned lines_per_tag:8;
  169. unsigned assoc:8;
  170. unsigned size_in_kb:8;
  171. };
  172. unsigned val;
  173. };
  174. union l2_cache {
  175. struct {
  176. unsigned line_size:8;
  177. unsigned lines_per_tag:4;
  178. unsigned assoc:4;
  179. unsigned size_in_kb:16;
  180. };
  181. unsigned val;
  182. };
  183. union l3_cache {
  184. struct {
  185. unsigned line_size:8;
  186. unsigned lines_per_tag:4;
  187. unsigned assoc:4;
  188. unsigned res:2;
  189. unsigned size_encoded:14;
  190. };
  191. unsigned val;
  192. };
  193. static const unsigned short __cpuinitconst assocs[] = {
  194. [1] = 1,
  195. [2] = 2,
  196. [4] = 4,
  197. [6] = 8,
  198. [8] = 16,
  199. [0xa] = 32,
  200. [0xb] = 48,
  201. [0xc] = 64,
  202. [0xd] = 96,
  203. [0xe] = 128,
  204. [0xf] = 0xffff /* fully associative - no way to show this currently */
  205. };
  206. static const unsigned char __cpuinitconst levels[] = { 1, 1, 2, 3 };
  207. static const unsigned char __cpuinitconst types[] = { 1, 2, 3, 3 };
  208. static void __cpuinit
  209. amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax,
  210. union _cpuid4_leaf_ebx *ebx,
  211. union _cpuid4_leaf_ecx *ecx)
  212. {
  213. unsigned dummy;
  214. unsigned line_size, lines_per_tag, assoc, size_in_kb;
  215. union l1_cache l1i, l1d;
  216. union l2_cache l2;
  217. union l3_cache l3;
  218. union l1_cache *l1 = &l1d;
  219. eax->full = 0;
  220. ebx->full = 0;
  221. ecx->full = 0;
  222. cpuid(0x80000005, &dummy, &dummy, &l1d.val, &l1i.val);
  223. cpuid(0x80000006, &dummy, &dummy, &l2.val, &l3.val);
  224. switch (leaf) {
  225. case 1:
  226. l1 = &l1i;
  227. case 0:
  228. if (!l1->val)
  229. return;
  230. assoc = assocs[l1->assoc];
  231. line_size = l1->line_size;
  232. lines_per_tag = l1->lines_per_tag;
  233. size_in_kb = l1->size_in_kb;
  234. break;
  235. case 2:
  236. if (!l2.val)
  237. return;
  238. assoc = assocs[l2.assoc];
  239. line_size = l2.line_size;
  240. lines_per_tag = l2.lines_per_tag;
  241. /* cpu_data has errata corrections for K7 applied */
  242. size_in_kb = __this_cpu_read(cpu_info.x86_cache_size);
  243. break;
  244. case 3:
  245. if (!l3.val)
  246. return;
  247. assoc = assocs[l3.assoc];
  248. line_size = l3.line_size;
  249. lines_per_tag = l3.lines_per_tag;
  250. size_in_kb = l3.size_encoded * 512;
  251. if (boot_cpu_has(X86_FEATURE_AMD_DCM)) {
  252. size_in_kb = size_in_kb >> 1;
  253. assoc = assoc >> 1;
  254. }
  255. break;
  256. default:
  257. return;
  258. }
  259. eax->split.is_self_initializing = 1;
  260. eax->split.type = types[leaf];
  261. eax->split.level = levels[leaf];
  262. eax->split.num_threads_sharing = 0;
  263. eax->split.num_cores_on_die = __this_cpu_read(cpu_info.x86_max_cores) - 1;
  264. if (assoc == 0xffff)
  265. eax->split.is_fully_associative = 1;
  266. ebx->split.coherency_line_size = line_size - 1;
  267. ebx->split.ways_of_associativity = assoc - 1;
  268. ebx->split.physical_line_partition = lines_per_tag - 1;
  269. ecx->split.number_of_sets = (size_in_kb * 1024) / line_size /
  270. (ebx->split.ways_of_associativity + 1) - 1;
  271. }
  272. struct _cache_attr {
  273. struct attribute attr;
  274. ssize_t (*show)(struct _cpuid4_info *, char *);
  275. ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count);
  276. };
  277. #ifdef CONFIG_AMD_NB
  278. /*
  279. * L3 cache descriptors
  280. */
  281. static void __cpuinit amd_calc_l3_indices(struct amd_l3_cache *l3)
  282. {
  283. unsigned int sc0, sc1, sc2, sc3;
  284. u32 val = 0;
  285. pci_read_config_dword(l3->nb->misc, 0x1C4, &val);
  286. /* calculate subcache sizes */
  287. l3->subcaches[0] = sc0 = !(val & BIT(0));
  288. l3->subcaches[1] = sc1 = !(val & BIT(4));
  289. l3->subcaches[2] = sc2 = !(val & BIT(8)) + !(val & BIT(9));
  290. l3->subcaches[3] = sc3 = !(val & BIT(12)) + !(val & BIT(13));
  291. l3->indices = (max(max(max(sc0, sc1), sc2), sc3) << 10) - 1;
  292. l3->indices = (max(max3(sc0, sc1, sc2), sc3) << 10) - 1;
  293. }
  294. static void __cpuinit amd_init_l3_cache(struct _cpuid4_info_regs *this_leaf,
  295. int index)
  296. {
  297. static struct amd_l3_cache *__cpuinitdata l3_caches;
  298. int node;
  299. /* only for L3, and not in virtualized environments */
  300. if (index < 3 || amd_nb_num() == 0)
  301. return;
  302. /*
  303. * Strictly speaking, the amount in @size below is leaked since it is
  304. * never freed but this is done only on shutdown so it doesn't matter.
  305. */
  306. if (!l3_caches) {
  307. int size = amd_nb_num() * sizeof(struct amd_l3_cache);
  308. l3_caches = kzalloc(size, GFP_ATOMIC);
  309. if (!l3_caches)
  310. return;
  311. }
  312. node = amd_get_nb_id(smp_processor_id());
  313. if (!l3_caches[node].nb) {
  314. l3_caches[node].nb = node_to_amd_nb(node);
  315. amd_calc_l3_indices(&l3_caches[node]);
  316. }
  317. this_leaf->l3 = &l3_caches[node];
  318. }
  319. /*
  320. * check whether a slot used for disabling an L3 index is occupied.
  321. * @l3: L3 cache descriptor
  322. * @slot: slot number (0..1)
  323. *
  324. * @returns: the disabled index if used or negative value if slot free.
  325. */
  326. int amd_get_l3_disable_slot(struct amd_l3_cache *l3, unsigned slot)
  327. {
  328. unsigned int reg = 0;
  329. pci_read_config_dword(l3->nb->misc, 0x1BC + slot * 4, &reg);
  330. /* check whether this slot is activated already */
  331. if (reg & (3UL << 30))
  332. return reg & 0xfff;
  333. return -1;
  334. }
  335. static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf,
  336. unsigned int slot)
  337. {
  338. int index;
  339. if (!this_leaf->l3 ||
  340. !amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
  341. return -EINVAL;
  342. index = amd_get_l3_disable_slot(this_leaf->l3, slot);
  343. if (index >= 0)
  344. return sprintf(buf, "%d\n", index);
  345. return sprintf(buf, "FREE\n");
  346. }
  347. #define SHOW_CACHE_DISABLE(slot) \
  348. static ssize_t \
  349. show_cache_disable_##slot(struct _cpuid4_info *this_leaf, char *buf) \
  350. { \
  351. return show_cache_disable(this_leaf, buf, slot); \
  352. }
  353. SHOW_CACHE_DISABLE(0)
  354. SHOW_CACHE_DISABLE(1)
  355. static void amd_l3_disable_index(struct amd_l3_cache *l3, int cpu,
  356. unsigned slot, unsigned long idx)
  357. {
  358. int i;
  359. idx |= BIT(30);
  360. /*
  361. * disable index in all 4 subcaches
  362. */
  363. for (i = 0; i < 4; i++) {
  364. u32 reg = idx | (i << 20);
  365. if (!l3->subcaches[i])
  366. continue;
  367. pci_write_config_dword(l3->nb->misc, 0x1BC + slot * 4, reg);
  368. /*
  369. * We need to WBINVD on a core on the node containing the L3
  370. * cache which indices we disable therefore a simple wbinvd()
  371. * is not sufficient.
  372. */
  373. wbinvd_on_cpu(cpu);
  374. reg |= BIT(31);
  375. pci_write_config_dword(l3->nb->misc, 0x1BC + slot * 4, reg);
  376. }
  377. }
  378. /*
  379. * disable a L3 cache index by using a disable-slot
  380. *
  381. * @l3: L3 cache descriptor
  382. * @cpu: A CPU on the node containing the L3 cache
  383. * @slot: slot number (0..1)
  384. * @index: index to disable
  385. *
  386. * @return: 0 on success, error status on failure
  387. */
  388. int amd_set_l3_disable_slot(struct amd_l3_cache *l3, int cpu, unsigned slot,
  389. unsigned long index)
  390. {
  391. int ret = 0;
  392. #define SUBCACHE_MASK (3UL << 20)
  393. #define SUBCACHE_INDEX 0xfff
  394. /*
  395. * check whether this slot is already used or
  396. * the index is already disabled
  397. */
  398. ret = amd_get_l3_disable_slot(l3, slot);
  399. if (ret >= 0)
  400. return -EINVAL;
  401. /*
  402. * check whether the other slot has disabled the
  403. * same index already
  404. */
  405. if (index == amd_get_l3_disable_slot(l3, !slot))
  406. return -EINVAL;
  407. /* do not allow writes outside of allowed bits */
  408. if ((index & ~(SUBCACHE_MASK | SUBCACHE_INDEX)) ||
  409. ((index & SUBCACHE_INDEX) > l3->indices))
  410. return -EINVAL;
  411. amd_l3_disable_index(l3, cpu, slot, index);
  412. return 0;
  413. }
  414. static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
  415. const char *buf, size_t count,
  416. unsigned int slot)
  417. {
  418. unsigned long val = 0;
  419. int cpu, err = 0;
  420. if (!capable(CAP_SYS_ADMIN))
  421. return -EPERM;
  422. if (!this_leaf->l3 ||
  423. !amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
  424. return -EINVAL;
  425. cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));
  426. if (strict_strtoul(buf, 10, &val) < 0)
  427. return -EINVAL;
  428. err = amd_set_l3_disable_slot(this_leaf->l3, cpu, slot, val);
  429. if (err) {
  430. if (err == -EEXIST)
  431. printk(KERN_WARNING "L3 disable slot %d in use!\n",
  432. slot);
  433. return err;
  434. }
  435. return count;
  436. }
  437. #define STORE_CACHE_DISABLE(slot) \
  438. static ssize_t \
  439. store_cache_disable_##slot(struct _cpuid4_info *this_leaf, \
  440. const char *buf, size_t count) \
  441. { \
  442. return store_cache_disable(this_leaf, buf, count, slot); \
  443. }
  444. STORE_CACHE_DISABLE(0)
  445. STORE_CACHE_DISABLE(1)
  446. static struct _cache_attr cache_disable_0 = __ATTR(cache_disable_0, 0644,
  447. show_cache_disable_0, store_cache_disable_0);
  448. static struct _cache_attr cache_disable_1 = __ATTR(cache_disable_1, 0644,
  449. show_cache_disable_1, store_cache_disable_1);
  450. #else /* CONFIG_AMD_NB */
  451. #define amd_init_l3_cache(x, y)
  452. #endif /* CONFIG_AMD_NB */
  453. static int
  454. __cpuinit cpuid4_cache_lookup_regs(int index,
  455. struct _cpuid4_info_regs *this_leaf)
  456. {
  457. union _cpuid4_leaf_eax eax;
  458. union _cpuid4_leaf_ebx ebx;
  459. union _cpuid4_leaf_ecx ecx;
  460. unsigned edx;
  461. if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
  462. amd_cpuid4(index, &eax, &ebx, &ecx);
  463. amd_init_l3_cache(this_leaf, index);
  464. } else {
  465. cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx);
  466. }
  467. if (eax.split.type == CACHE_TYPE_NULL)
  468. return -EIO; /* better error ? */
  469. this_leaf->eax = eax;
  470. this_leaf->ebx = ebx;
  471. this_leaf->ecx = ecx;
  472. this_leaf->size = (ecx.split.number_of_sets + 1) *
  473. (ebx.split.coherency_line_size + 1) *
  474. (ebx.split.physical_line_partition + 1) *
  475. (ebx.split.ways_of_associativity + 1);
  476. return 0;
  477. }
  478. static int __cpuinit find_num_cache_leaves(void)
  479. {
  480. unsigned int eax, ebx, ecx, edx;
  481. union _cpuid4_leaf_eax cache_eax;
  482. int i = -1;
  483. do {
  484. ++i;
  485. /* Do cpuid(4) loop to find out num_cache_leaves */
  486. cpuid_count(4, i, &eax, &ebx, &ecx, &edx);
  487. cache_eax.full = eax;
  488. } while (cache_eax.split.type != CACHE_TYPE_NULL);
  489. return i;
  490. }
  491. unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)
  492. {
  493. /* Cache sizes */
  494. unsigned int trace = 0, l1i = 0, l1d = 0, l2 = 0, l3 = 0;
  495. unsigned int new_l1d = 0, new_l1i = 0; /* Cache sizes from cpuid(4) */
  496. unsigned int new_l2 = 0, new_l3 = 0, i; /* Cache sizes from cpuid(4) */
  497. unsigned int l2_id = 0, l3_id = 0, num_threads_sharing, index_msb;
  498. #ifdef CONFIG_X86_HT
  499. unsigned int cpu = c->cpu_index;
  500. #endif
  501. if (c->cpuid_level > 3) {
  502. static int is_initialized;
  503. if (is_initialized == 0) {
  504. /* Init num_cache_leaves from boot CPU */
  505. num_cache_leaves = find_num_cache_leaves();
  506. is_initialized++;
  507. }
  508. /*
  509. * Whenever possible use cpuid(4), deterministic cache
  510. * parameters cpuid leaf to find the cache details
  511. */
  512. for (i = 0; i < num_cache_leaves; i++) {
  513. struct _cpuid4_info_regs this_leaf;
  514. int retval;
  515. retval = cpuid4_cache_lookup_regs(i, &this_leaf);
  516. if (retval >= 0) {
  517. switch (this_leaf.eax.split.level) {
  518. case 1:
  519. if (this_leaf.eax.split.type ==
  520. CACHE_TYPE_DATA)
  521. new_l1d = this_leaf.size/1024;
  522. else if (this_leaf.eax.split.type ==
  523. CACHE_TYPE_INST)
  524. new_l1i = this_leaf.size/1024;
  525. break;
  526. case 2:
  527. new_l2 = this_leaf.size/1024;
  528. num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing;
  529. index_msb = get_count_order(num_threads_sharing);
  530. l2_id = c->apicid >> index_msb;
  531. break;
  532. case 3:
  533. new_l3 = this_leaf.size/1024;
  534. num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing;
  535. index_msb = get_count_order(
  536. num_threads_sharing);
  537. l3_id = c->apicid >> index_msb;
  538. break;
  539. default:
  540. break;
  541. }
  542. }
  543. }
  544. }
  545. /*
  546. * Don't use cpuid2 if cpuid4 is supported. For P4, we use cpuid2 for
  547. * trace cache
  548. */
  549. if ((num_cache_leaves == 0 || c->x86 == 15) && c->cpuid_level > 1) {
  550. /* supports eax=2 call */
  551. int j, n;
  552. unsigned int regs[4];
  553. unsigned char *dp = (unsigned char *)regs;
  554. int only_trace = 0;
  555. if (num_cache_leaves != 0 && c->x86 == 15)
  556. only_trace = 1;
  557. /* Number of times to iterate */
  558. n = cpuid_eax(2) & 0xFF;
  559. for (i = 0 ; i < n ; i++) {
  560. cpuid(2, &regs[0], &regs[1], &regs[2], &regs[3]);
  561. /* If bit 31 is set, this is an unknown format */
  562. for (j = 0 ; j < 3 ; j++)
  563. if (regs[j] & (1 << 31))
  564. regs[j] = 0;
  565. /* Byte 0 is level count, not a descriptor */
  566. for (j = 1 ; j < 16 ; j++) {
  567. unsigned char des = dp[j];
  568. unsigned char k = 0;
  569. /* look up this descriptor in the table */
  570. while (cache_table[k].descriptor != 0) {
  571. if (cache_table[k].descriptor == des) {
  572. if (only_trace && cache_table[k].cache_type != LVL_TRACE)
  573. break;
  574. switch (cache_table[k].cache_type) {
  575. case LVL_1_INST:
  576. l1i += cache_table[k].size;
  577. break;
  578. case LVL_1_DATA:
  579. l1d += cache_table[k].size;
  580. break;
  581. case LVL_2:
  582. l2 += cache_table[k].size;
  583. break;
  584. case LVL_3:
  585. l3 += cache_table[k].size;
  586. break;
  587. case LVL_TRACE:
  588. trace += cache_table[k].size;
  589. break;
  590. }
  591. break;
  592. }
  593. k++;
  594. }
  595. }
  596. }
  597. }
  598. if (new_l1d)
  599. l1d = new_l1d;
  600. if (new_l1i)
  601. l1i = new_l1i;
  602. if (new_l2) {
  603. l2 = new_l2;
  604. #ifdef CONFIG_X86_HT
  605. per_cpu(cpu_llc_id, cpu) = l2_id;
  606. #endif
  607. }
  608. if (new_l3) {
  609. l3 = new_l3;
  610. #ifdef CONFIG_X86_HT
  611. per_cpu(cpu_llc_id, cpu) = l3_id;
  612. #endif
  613. }
  614. c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d));
  615. return l2;
  616. }
  617. #ifdef CONFIG_SYSFS
  618. /* pointer to _cpuid4_info array (for each cache leaf) */
  619. static DEFINE_PER_CPU(struct _cpuid4_info *, ici_cpuid4_info);
  620. #define CPUID4_INFO_IDX(x, y) (&((per_cpu(ici_cpuid4_info, x))[y]))
  621. #ifdef CONFIG_SMP
  622. static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index)
  623. {
  624. struct _cpuid4_info *this_leaf, *sibling_leaf;
  625. unsigned long num_threads_sharing;
  626. int index_msb, i, sibling;
  627. struct cpuinfo_x86 *c = &cpu_data(cpu);
  628. if ((index == 3) && (c->x86_vendor == X86_VENDOR_AMD)) {
  629. for_each_cpu(i, c->llc_shared_map) {
  630. if (!per_cpu(ici_cpuid4_info, i))
  631. continue;
  632. this_leaf = CPUID4_INFO_IDX(i, index);
  633. for_each_cpu(sibling, c->llc_shared_map) {
  634. if (!cpu_online(sibling))
  635. continue;
  636. set_bit(sibling, this_leaf->shared_cpu_map);
  637. }
  638. }
  639. return;
  640. }
  641. this_leaf = CPUID4_INFO_IDX(cpu, index);
  642. num_threads_sharing = 1 + this_leaf->eax.split.num_threads_sharing;
  643. if (num_threads_sharing == 1)
  644. cpumask_set_cpu(cpu, to_cpumask(this_leaf->shared_cpu_map));
  645. else {
  646. index_msb = get_count_order(num_threads_sharing);
  647. for_each_online_cpu(i) {
  648. if (cpu_data(i).apicid >> index_msb ==
  649. c->apicid >> index_msb) {
  650. cpumask_set_cpu(i,
  651. to_cpumask(this_leaf->shared_cpu_map));
  652. if (i != cpu && per_cpu(ici_cpuid4_info, i)) {
  653. sibling_leaf =
  654. CPUID4_INFO_IDX(i, index);
  655. cpumask_set_cpu(cpu, to_cpumask(
  656. sibling_leaf->shared_cpu_map));
  657. }
  658. }
  659. }
  660. }
  661. }
  662. static void __cpuinit cache_remove_shared_cpu_map(unsigned int cpu, int index)
  663. {
  664. struct _cpuid4_info *this_leaf, *sibling_leaf;
  665. int sibling;
  666. this_leaf = CPUID4_INFO_IDX(cpu, index);
  667. for_each_cpu(sibling, to_cpumask(this_leaf->shared_cpu_map)) {
  668. sibling_leaf = CPUID4_INFO_IDX(sibling, index);
  669. cpumask_clear_cpu(cpu,
  670. to_cpumask(sibling_leaf->shared_cpu_map));
  671. }
  672. }
  673. #else
  674. static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index)
  675. {
  676. }
  677. static void __cpuinit cache_remove_shared_cpu_map(unsigned int cpu, int index)
  678. {
  679. }
  680. #endif
  681. static void __cpuinit free_cache_attributes(unsigned int cpu)
  682. {
  683. int i;
  684. for (i = 0; i < num_cache_leaves; i++)
  685. cache_remove_shared_cpu_map(cpu, i);
  686. kfree(per_cpu(ici_cpuid4_info, cpu)->l3);
  687. kfree(per_cpu(ici_cpuid4_info, cpu));
  688. per_cpu(ici_cpuid4_info, cpu) = NULL;
  689. }
  690. static int
  691. __cpuinit cpuid4_cache_lookup(int index, struct _cpuid4_info *this_leaf)
  692. {
  693. struct _cpuid4_info_regs *leaf_regs =
  694. (struct _cpuid4_info_regs *)this_leaf;
  695. return cpuid4_cache_lookup_regs(index, leaf_regs);
  696. }
  697. static void __cpuinit get_cpu_leaves(void *_retval)
  698. {
  699. int j, *retval = _retval, cpu = smp_processor_id();
  700. /* Do cpuid and store the results */
  701. for (j = 0; j < num_cache_leaves; j++) {
  702. struct _cpuid4_info *this_leaf;
  703. this_leaf = CPUID4_INFO_IDX(cpu, j);
  704. *retval = cpuid4_cache_lookup(j, this_leaf);
  705. if (unlikely(*retval < 0)) {
  706. int i;
  707. for (i = 0; i < j; i++)
  708. cache_remove_shared_cpu_map(cpu, i);
  709. break;
  710. }
  711. cache_shared_cpu_map_setup(cpu, j);
  712. }
  713. }
  714. static int __cpuinit detect_cache_attributes(unsigned int cpu)
  715. {
  716. int retval;
  717. if (num_cache_leaves == 0)
  718. return -ENOENT;
  719. per_cpu(ici_cpuid4_info, cpu) = kzalloc(
  720. sizeof(struct _cpuid4_info) * num_cache_leaves, GFP_KERNEL);
  721. if (per_cpu(ici_cpuid4_info, cpu) == NULL)
  722. return -ENOMEM;
  723. smp_call_function_single(cpu, get_cpu_leaves, &retval, true);
  724. if (retval) {
  725. kfree(per_cpu(ici_cpuid4_info, cpu));
  726. per_cpu(ici_cpuid4_info, cpu) = NULL;
  727. }
  728. return retval;
  729. }
  730. #include <linux/kobject.h>
  731. #include <linux/sysfs.h>
  732. extern struct sysdev_class cpu_sysdev_class; /* from drivers/base/cpu.c */
  733. /* pointer to kobject for cpuX/cache */
  734. static DEFINE_PER_CPU(struct kobject *, ici_cache_kobject);
  735. struct _index_kobject {
  736. struct kobject kobj;
  737. unsigned int cpu;
  738. unsigned short index;
  739. };
  740. /* pointer to array of kobjects for cpuX/cache/indexY */
  741. static DEFINE_PER_CPU(struct _index_kobject *, ici_index_kobject);
  742. #define INDEX_KOBJECT_PTR(x, y) (&((per_cpu(ici_index_kobject, x))[y]))
  743. #define show_one_plus(file_name, object, val) \
  744. static ssize_t show_##file_name \
  745. (struct _cpuid4_info *this_leaf, char *buf) \
  746. { \
  747. return sprintf(buf, "%lu\n", (unsigned long)this_leaf->object + val); \
  748. }
  749. show_one_plus(level, eax.split.level, 0);
  750. show_one_plus(coherency_line_size, ebx.split.coherency_line_size, 1);
  751. show_one_plus(physical_line_partition, ebx.split.physical_line_partition, 1);
  752. show_one_plus(ways_of_associativity, ebx.split.ways_of_associativity, 1);
  753. show_one_plus(number_of_sets, ecx.split.number_of_sets, 1);
  754. static ssize_t show_size(struct _cpuid4_info *this_leaf, char *buf)
  755. {
  756. return sprintf(buf, "%luK\n", this_leaf->size / 1024);
  757. }
  758. static ssize_t show_shared_cpu_map_func(struct _cpuid4_info *this_leaf,
  759. int type, char *buf)
  760. {
  761. ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf;
  762. int n = 0;
  763. if (len > 1) {
  764. const struct cpumask *mask;
  765. mask = to_cpumask(this_leaf->shared_cpu_map);
  766. n = type ?
  767. cpulist_scnprintf(buf, len-2, mask) :
  768. cpumask_scnprintf(buf, len-2, mask);
  769. buf[n++] = '\n';
  770. buf[n] = '\0';
  771. }
  772. return n;
  773. }
  774. static inline ssize_t show_shared_cpu_map(struct _cpuid4_info *leaf, char *buf)
  775. {
  776. return show_shared_cpu_map_func(leaf, 0, buf);
  777. }
  778. static inline ssize_t show_shared_cpu_list(struct _cpuid4_info *leaf, char *buf)
  779. {
  780. return show_shared_cpu_map_func(leaf, 1, buf);
  781. }
  782. static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf)
  783. {
  784. switch (this_leaf->eax.split.type) {
  785. case CACHE_TYPE_DATA:
  786. return sprintf(buf, "Data\n");
  787. case CACHE_TYPE_INST:
  788. return sprintf(buf, "Instruction\n");
  789. case CACHE_TYPE_UNIFIED:
  790. return sprintf(buf, "Unified\n");
  791. default:
  792. return sprintf(buf, "Unknown\n");
  793. }
  794. }
  795. #define to_object(k) container_of(k, struct _index_kobject, kobj)
  796. #define to_attr(a) container_of(a, struct _cache_attr, attr)
  797. #define define_one_ro(_name) \
  798. static struct _cache_attr _name = \
  799. __ATTR(_name, 0444, show_##_name, NULL)
  800. define_one_ro(level);
  801. define_one_ro(type);
  802. define_one_ro(coherency_line_size);
  803. define_one_ro(physical_line_partition);
  804. define_one_ro(ways_of_associativity);
  805. define_one_ro(number_of_sets);
  806. define_one_ro(size);
  807. define_one_ro(shared_cpu_map);
  808. define_one_ro(shared_cpu_list);
  809. static struct attribute *default_attrs[] = {
  810. &type.attr,
  811. &level.attr,
  812. &coherency_line_size.attr,
  813. &physical_line_partition.attr,
  814. &ways_of_associativity.attr,
  815. &number_of_sets.attr,
  816. &size.attr,
  817. &shared_cpu_map.attr,
  818. &shared_cpu_list.attr,
  819. NULL
  820. };
  821. #ifdef CONFIG_AMD_NB
  822. static struct attribute ** __cpuinit amd_l3_attrs(void)
  823. {
  824. static struct attribute **attrs;
  825. int n;
  826. if (attrs)
  827. return attrs;
  828. n = sizeof (default_attrs) / sizeof (struct attribute *);
  829. if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
  830. n += 2;
  831. attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
  832. if (attrs == NULL)
  833. return attrs = default_attrs;
  834. for (n = 0; default_attrs[n]; n++)
  835. attrs[n] = default_attrs[n];
  836. if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
  837. attrs[n++] = &cache_disable_0.attr;
  838. attrs[n++] = &cache_disable_1.attr;
  839. }
  840. return attrs;
  841. }
  842. #endif
  843. static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
  844. {
  845. struct _cache_attr *fattr = to_attr(attr);
  846. struct _index_kobject *this_leaf = to_object(kobj);
  847. ssize_t ret;
  848. ret = fattr->show ?
  849. fattr->show(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index),
  850. buf) :
  851. 0;
  852. return ret;
  853. }
  854. static ssize_t store(struct kobject *kobj, struct attribute *attr,
  855. const char *buf, size_t count)
  856. {
  857. struct _cache_attr *fattr = to_attr(attr);
  858. struct _index_kobject *this_leaf = to_object(kobj);
  859. ssize_t ret;
  860. ret = fattr->store ?
  861. fattr->store(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index),
  862. buf, count) :
  863. 0;
  864. return ret;
  865. }
  866. static const struct sysfs_ops sysfs_ops = {
  867. .show = show,
  868. .store = store,
  869. };
  870. static struct kobj_type ktype_cache = {
  871. .sysfs_ops = &sysfs_ops,
  872. .default_attrs = default_attrs,
  873. };
  874. static struct kobj_type ktype_percpu_entry = {
  875. .sysfs_ops = &sysfs_ops,
  876. };
  877. static void __cpuinit cpuid4_cache_sysfs_exit(unsigned int cpu)
  878. {
  879. kfree(per_cpu(ici_cache_kobject, cpu));
  880. kfree(per_cpu(ici_index_kobject, cpu));
  881. per_cpu(ici_cache_kobject, cpu) = NULL;
  882. per_cpu(ici_index_kobject, cpu) = NULL;
  883. free_cache_attributes(cpu);
  884. }
  885. static int __cpuinit cpuid4_cache_sysfs_init(unsigned int cpu)
  886. {
  887. int err;
  888. if (num_cache_leaves == 0)
  889. return -ENOENT;
  890. err = detect_cache_attributes(cpu);
  891. if (err)
  892. return err;
  893. /* Allocate all required memory */
  894. per_cpu(ici_cache_kobject, cpu) =
  895. kzalloc(sizeof(struct kobject), GFP_KERNEL);
  896. if (unlikely(per_cpu(ici_cache_kobject, cpu) == NULL))
  897. goto err_out;
  898. per_cpu(ici_index_kobject, cpu) = kzalloc(
  899. sizeof(struct _index_kobject) * num_cache_leaves, GFP_KERNEL);
  900. if (unlikely(per_cpu(ici_index_kobject, cpu) == NULL))
  901. goto err_out;
  902. return 0;
  903. err_out:
  904. cpuid4_cache_sysfs_exit(cpu);
  905. return -ENOMEM;
  906. }
  907. static DECLARE_BITMAP(cache_dev_map, NR_CPUS);
  908. /* Add/Remove cache interface for CPU device */
  909. static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
  910. {
  911. unsigned int cpu = sys_dev->id;
  912. unsigned long i, j;
  913. struct _index_kobject *this_object;
  914. struct _cpuid4_info *this_leaf;
  915. int retval;
  916. retval = cpuid4_cache_sysfs_init(cpu);
  917. if (unlikely(retval < 0))
  918. return retval;
  919. retval = kobject_init_and_add(per_cpu(ici_cache_kobject, cpu),
  920. &ktype_percpu_entry,
  921. &sys_dev->kobj, "%s", "cache");
  922. if (retval < 0) {
  923. cpuid4_cache_sysfs_exit(cpu);
  924. return retval;
  925. }
  926. for (i = 0; i < num_cache_leaves; i++) {
  927. this_object = INDEX_KOBJECT_PTR(cpu, i);
  928. this_object->cpu = cpu;
  929. this_object->index = i;
  930. this_leaf = CPUID4_INFO_IDX(cpu, i);
  931. ktype_cache.default_attrs = default_attrs;
  932. #ifdef CONFIG_AMD_NB
  933. if (this_leaf->l3)
  934. ktype_cache.default_attrs = amd_l3_attrs();
  935. #endif
  936. retval = kobject_init_and_add(&(this_object->kobj),
  937. &ktype_cache,
  938. per_cpu(ici_cache_kobject, cpu),
  939. "index%1lu", i);
  940. if (unlikely(retval)) {
  941. for (j = 0; j < i; j++)
  942. kobject_put(&(INDEX_KOBJECT_PTR(cpu, j)->kobj));
  943. kobject_put(per_cpu(ici_cache_kobject, cpu));
  944. cpuid4_cache_sysfs_exit(cpu);
  945. return retval;
  946. }
  947. kobject_uevent(&(this_object->kobj), KOBJ_ADD);
  948. }
  949. cpumask_set_cpu(cpu, to_cpumask(cache_dev_map));
  950. kobject_uevent(per_cpu(ici_cache_kobject, cpu), KOBJ_ADD);
  951. return 0;
  952. }
  953. static void __cpuinit cache_remove_dev(struct sys_device * sys_dev)
  954. {
  955. unsigned int cpu = sys_dev->id;
  956. unsigned long i;
  957. if (per_cpu(ici_cpuid4_info, cpu) == NULL)
  958. return;
  959. if (!cpumask_test_cpu(cpu, to_cpumask(cache_dev_map)))
  960. return;
  961. cpumask_clear_cpu(cpu, to_cpumask(cache_dev_map));
  962. for (i = 0; i < num_cache_leaves; i++)
  963. kobject_put(&(INDEX_KOBJECT_PTR(cpu, i)->kobj));
  964. kobject_put(per_cpu(ici_cache_kobject, cpu));
  965. cpuid4_cache_sysfs_exit(cpu);
  966. }
  967. static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
  968. unsigned long action, void *hcpu)
  969. {
  970. unsigned int cpu = (unsigned long)hcpu;
  971. struct sys_device *sys_dev;
  972. sys_dev = get_cpu_sysdev(cpu);
  973. switch (action) {
  974. case CPU_ONLINE:
  975. case CPU_ONLINE_FROZEN:
  976. cache_add_dev(sys_dev);
  977. break;
  978. case CPU_DEAD:
  979. case CPU_DEAD_FROZEN:
  980. cache_remove_dev(sys_dev);
  981. break;
  982. }
  983. return NOTIFY_OK;
  984. }
  985. static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
  986. .notifier_call = cacheinfo_cpu_callback,
  987. };
  988. static int __cpuinit cache_sysfs_init(void)
  989. {
  990. int i;
  991. if (num_cache_leaves == 0)
  992. return 0;
  993. for_each_online_cpu(i) {
  994. int err;
  995. struct sys_device *sys_dev = get_cpu_sysdev(i);
  996. err = cache_add_dev(sys_dev);
  997. if (err)
  998. return err;
  999. }
  1000. register_hotcpu_notifier(&cacheinfo_cpu_notifier);
  1001. return 0;
  1002. }
  1003. device_initcall(cache_sysfs_init);
  1004. #endif