intel_cacheinfo.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /*
  2. * Routines to indentify caches on Intel CPU.
  3. *
  4. * Changes:
  5. * Venkatesh Pallipadi : Adding cache identification through cpuid(4)
  6. */
  7. #include <linux/init.h>
  8. #include <linux/slab.h>
  9. #include <linux/device.h>
  10. #include <linux/compiler.h>
  11. #include <linux/cpu.h>
  12. #include <asm/processor.h>
  13. #include <asm/smp.h>
  14. #define LVL_1_INST 1
  15. #define LVL_1_DATA 2
  16. #define LVL_2 3
  17. #define LVL_3 4
  18. #define LVL_TRACE 5
  19. struct _cache_table
  20. {
  21. unsigned char descriptor;
  22. char cache_type;
  23. short size;
  24. };
  25. /* all the cache descriptor types we care about (no TLB or trace cache entries) */
  26. static struct _cache_table cache_table[] __devinitdata =
  27. {
  28. { 0x06, LVL_1_INST, 8 }, /* 4-way set assoc, 32 byte line size */
  29. { 0x08, LVL_1_INST, 16 }, /* 4-way set assoc, 32 byte line size */
  30. { 0x0a, LVL_1_DATA, 8 }, /* 2 way set assoc, 32 byte line size */
  31. { 0x0c, LVL_1_DATA, 16 }, /* 4-way set assoc, 32 byte line size */
  32. { 0x22, LVL_3, 512 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  33. { 0x23, LVL_3, 1024 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  34. { 0x25, LVL_3, 2048 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  35. { 0x29, LVL_3, 4096 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  36. { 0x2c, LVL_1_DATA, 32 }, /* 8-way set assoc, 64 byte line size */
  37. { 0x30, LVL_1_INST, 32 }, /* 8-way set assoc, 64 byte line size */
  38. { 0x39, LVL_2, 128 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  39. { 0x3b, LVL_2, 128 }, /* 2-way set assoc, sectored cache, 64 byte line size */
  40. { 0x3c, LVL_2, 256 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  41. { 0x41, LVL_2, 128 }, /* 4-way set assoc, 32 byte line size */
  42. { 0x42, LVL_2, 256 }, /* 4-way set assoc, 32 byte line size */
  43. { 0x43, LVL_2, 512 }, /* 4-way set assoc, 32 byte line size */
  44. { 0x44, LVL_2, 1024 }, /* 4-way set assoc, 32 byte line size */
  45. { 0x45, LVL_2, 2048 }, /* 4-way set assoc, 32 byte line size */
  46. { 0x60, LVL_1_DATA, 16 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  47. { 0x66, LVL_1_DATA, 8 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  48. { 0x67, LVL_1_DATA, 16 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  49. { 0x68, LVL_1_DATA, 32 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  50. { 0x70, LVL_TRACE, 12 }, /* 8-way set assoc */
  51. { 0x71, LVL_TRACE, 16 }, /* 8-way set assoc */
  52. { 0x72, LVL_TRACE, 32 }, /* 8-way set assoc */
  53. { 0x78, LVL_2, 1024 }, /* 4-way set assoc, 64 byte line size */
  54. { 0x79, LVL_2, 128 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  55. { 0x7a, LVL_2, 256 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  56. { 0x7b, LVL_2, 512 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  57. { 0x7c, LVL_2, 1024 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  58. { 0x7d, LVL_2, 2048 }, /* 8-way set assoc, 64 byte line size */
  59. { 0x7f, LVL_2, 512 }, /* 2-way set assoc, 64 byte line size */
  60. { 0x82, LVL_2, 256 }, /* 8-way set assoc, 32 byte line size */
  61. { 0x83, LVL_2, 512 }, /* 8-way set assoc, 32 byte line size */
  62. { 0x84, LVL_2, 1024 }, /* 8-way set assoc, 32 byte line size */
  63. { 0x85, LVL_2, 2048 }, /* 8-way set assoc, 32 byte line size */
  64. { 0x86, LVL_2, 512 }, /* 4-way set assoc, 64 byte line size */
  65. { 0x87, LVL_2, 1024 }, /* 8-way set assoc, 64 byte line size */
  66. { 0x00, 0, 0}
  67. };
  68. enum _cache_type
  69. {
  70. CACHE_TYPE_NULL = 0,
  71. CACHE_TYPE_DATA = 1,
  72. CACHE_TYPE_INST = 2,
  73. CACHE_TYPE_UNIFIED = 3
  74. };
  75. union _cpuid4_leaf_eax {
  76. struct {
  77. enum _cache_type type:5;
  78. unsigned int level:3;
  79. unsigned int is_self_initializing:1;
  80. unsigned int is_fully_associative:1;
  81. unsigned int reserved:4;
  82. unsigned int num_threads_sharing:12;
  83. unsigned int num_cores_on_die:6;
  84. } split;
  85. u32 full;
  86. };
  87. union _cpuid4_leaf_ebx {
  88. struct {
  89. unsigned int coherency_line_size:12;
  90. unsigned int physical_line_partition:10;
  91. unsigned int ways_of_associativity:10;
  92. } split;
  93. u32 full;
  94. };
  95. union _cpuid4_leaf_ecx {
  96. struct {
  97. unsigned int number_of_sets:32;
  98. } split;
  99. u32 full;
  100. };
  101. struct _cpuid4_info {
  102. union _cpuid4_leaf_eax eax;
  103. union _cpuid4_leaf_ebx ebx;
  104. union _cpuid4_leaf_ecx ecx;
  105. unsigned long size;
  106. cpumask_t shared_cpu_map;
  107. };
  108. #define MAX_CACHE_LEAVES 4
  109. static unsigned short num_cache_leaves;
  110. static int __devinit cpuid4_cache_lookup(int index, struct _cpuid4_info *this_leaf)
  111. {
  112. unsigned int eax, ebx, ecx, edx;
  113. union _cpuid4_leaf_eax cache_eax;
  114. cpuid_count(4, index, &eax, &ebx, &ecx, &edx);
  115. cache_eax.full = eax;
  116. if (cache_eax.split.type == CACHE_TYPE_NULL)
  117. return -EIO; /* better error ? */
  118. this_leaf->eax.full = eax;
  119. this_leaf->ebx.full = ebx;
  120. this_leaf->ecx.full = ecx;
  121. this_leaf->size = (this_leaf->ecx.split.number_of_sets + 1) *
  122. (this_leaf->ebx.split.coherency_line_size + 1) *
  123. (this_leaf->ebx.split.physical_line_partition + 1) *
  124. (this_leaf->ebx.split.ways_of_associativity + 1);
  125. return 0;
  126. }
  127. static int __init find_num_cache_leaves(void)
  128. {
  129. unsigned int eax, ebx, ecx, edx;
  130. union _cpuid4_leaf_eax cache_eax;
  131. int i;
  132. int retval;
  133. retval = MAX_CACHE_LEAVES;
  134. /* Do cpuid(4) loop to find out num_cache_leaves */
  135. for (i = 0; i < MAX_CACHE_LEAVES; i++) {
  136. cpuid_count(4, i, &eax, &ebx, &ecx, &edx);
  137. cache_eax.full = eax;
  138. if (cache_eax.split.type == CACHE_TYPE_NULL) {
  139. retval = i;
  140. break;
  141. }
  142. }
  143. return retval;
  144. }
  145. unsigned int __devinit init_intel_cacheinfo(struct cpuinfo_x86 *c)
  146. {
  147. unsigned int trace = 0, l1i = 0, l1d = 0, l2 = 0, l3 = 0; /* Cache sizes */
  148. unsigned int new_l1d = 0, new_l1i = 0; /* Cache sizes from cpuid(4) */
  149. unsigned int new_l2 = 0, new_l3 = 0, i; /* Cache sizes from cpuid(4) */
  150. if (c->cpuid_level > 4) {
  151. static int is_initialized;
  152. if (is_initialized == 0) {
  153. /* Init num_cache_leaves from boot CPU */
  154. num_cache_leaves = find_num_cache_leaves();
  155. is_initialized++;
  156. }
  157. /*
  158. * Whenever possible use cpuid(4), deterministic cache
  159. * parameters cpuid leaf to find the cache details
  160. */
  161. for (i = 0; i < num_cache_leaves; i++) {
  162. struct _cpuid4_info this_leaf;
  163. int retval;
  164. retval = cpuid4_cache_lookup(i, &this_leaf);
  165. if (retval >= 0) {
  166. switch(this_leaf.eax.split.level) {
  167. case 1:
  168. if (this_leaf.eax.split.type ==
  169. CACHE_TYPE_DATA)
  170. new_l1d = this_leaf.size/1024;
  171. else if (this_leaf.eax.split.type ==
  172. CACHE_TYPE_INST)
  173. new_l1i = this_leaf.size/1024;
  174. break;
  175. case 2:
  176. new_l2 = this_leaf.size/1024;
  177. break;
  178. case 3:
  179. new_l3 = this_leaf.size/1024;
  180. break;
  181. default:
  182. break;
  183. }
  184. }
  185. }
  186. }
  187. if (c->cpuid_level > 1) {
  188. /* supports eax=2 call */
  189. int i, j, n;
  190. int regs[4];
  191. unsigned char *dp = (unsigned char *)regs;
  192. /* Number of times to iterate */
  193. n = cpuid_eax(2) & 0xFF;
  194. for ( i = 0 ; i < n ; i++ ) {
  195. cpuid(2, &regs[0], &regs[1], &regs[2], &regs[3]);
  196. /* If bit 31 is set, this is an unknown format */
  197. for ( j = 0 ; j < 3 ; j++ ) {
  198. if ( regs[j] < 0 ) regs[j] = 0;
  199. }
  200. /* Byte 0 is level count, not a descriptor */
  201. for ( j = 1 ; j < 16 ; j++ ) {
  202. unsigned char des = dp[j];
  203. unsigned char k = 0;
  204. /* look up this descriptor in the table */
  205. while (cache_table[k].descriptor != 0)
  206. {
  207. if (cache_table[k].descriptor == des) {
  208. switch (cache_table[k].cache_type) {
  209. case LVL_1_INST:
  210. l1i += cache_table[k].size;
  211. break;
  212. case LVL_1_DATA:
  213. l1d += cache_table[k].size;
  214. break;
  215. case LVL_2:
  216. l2 += cache_table[k].size;
  217. break;
  218. case LVL_3:
  219. l3 += cache_table[k].size;
  220. break;
  221. case LVL_TRACE:
  222. trace += cache_table[k].size;
  223. break;
  224. }
  225. break;
  226. }
  227. k++;
  228. }
  229. }
  230. }
  231. if (new_l1d)
  232. l1d = new_l1d;
  233. if (new_l1i)
  234. l1i = new_l1i;
  235. if (new_l2)
  236. l2 = new_l2;
  237. if (new_l3)
  238. l3 = new_l3;
  239. if ( trace )
  240. printk (KERN_INFO "CPU: Trace cache: %dK uops", trace);
  241. else if ( l1i )
  242. printk (KERN_INFO "CPU: L1 I cache: %dK", l1i);
  243. if ( l1d )
  244. printk(", L1 D cache: %dK\n", l1d);
  245. else
  246. printk("\n");
  247. if ( l2 )
  248. printk(KERN_INFO "CPU: L2 cache: %dK\n", l2);
  249. if ( l3 )
  250. printk(KERN_INFO "CPU: L3 cache: %dK\n", l3);
  251. /*
  252. * This assumes the L3 cache is shared; it typically lives in
  253. * the northbridge. The L1 caches are included by the L2
  254. * cache, and so should not be included for the purpose of
  255. * SMP switching weights.
  256. */
  257. c->x86_cache_size = l2 ? l2 : (l1i+l1d);
  258. }
  259. return l2;
  260. }
  261. /* pointer to _cpuid4_info array (for each cache leaf) */
  262. static struct _cpuid4_info *cpuid4_info[NR_CPUS];
  263. #define CPUID4_INFO_IDX(x,y) (&((cpuid4_info[x])[y]))
  264. #ifdef CONFIG_SMP
  265. static void __devinit cache_shared_cpu_map_setup(unsigned int cpu, int index)
  266. {
  267. struct _cpuid4_info *this_leaf;
  268. unsigned long num_threads_sharing;
  269. #ifdef CONFIG_X86_HT
  270. struct cpuinfo_x86 *c = cpu_data + cpu;
  271. #endif
  272. this_leaf = CPUID4_INFO_IDX(cpu, index);
  273. num_threads_sharing = 1 + this_leaf->eax.split.num_threads_sharing;
  274. if (num_threads_sharing == 1)
  275. cpu_set(cpu, this_leaf->shared_cpu_map);
  276. #ifdef CONFIG_X86_HT
  277. else if (num_threads_sharing == smp_num_siblings)
  278. this_leaf->shared_cpu_map = cpu_sibling_map[cpu];
  279. else if (num_threads_sharing == (c->x86_num_cores * smp_num_siblings))
  280. this_leaf->shared_cpu_map = cpu_core_map[cpu];
  281. else
  282. printk(KERN_DEBUG "Number of CPUs sharing cache didn't match "
  283. "any known set of CPUs\n");
  284. #endif
  285. }
  286. #else
  287. static void __init cache_shared_cpu_map_setup(unsigned int cpu, int index) {}
  288. #endif
  289. static void free_cache_attributes(unsigned int cpu)
  290. {
  291. kfree(cpuid4_info[cpu]);
  292. cpuid4_info[cpu] = NULL;
  293. }
  294. static int __devinit detect_cache_attributes(unsigned int cpu)
  295. {
  296. struct _cpuid4_info *this_leaf;
  297. unsigned long j;
  298. int retval;
  299. cpumask_t oldmask;
  300. if (num_cache_leaves == 0)
  301. return -ENOENT;
  302. cpuid4_info[cpu] = kmalloc(
  303. sizeof(struct _cpuid4_info) * num_cache_leaves, GFP_KERNEL);
  304. if (unlikely(cpuid4_info[cpu] == NULL))
  305. return -ENOMEM;
  306. memset(cpuid4_info[cpu], 0,
  307. sizeof(struct _cpuid4_info) * num_cache_leaves);
  308. oldmask = current->cpus_allowed;
  309. retval = set_cpus_allowed(current, cpumask_of_cpu(cpu));
  310. if (retval)
  311. goto out;
  312. /* Do cpuid and store the results */
  313. retval = 0;
  314. for (j = 0; j < num_cache_leaves; j++) {
  315. this_leaf = CPUID4_INFO_IDX(cpu, j);
  316. retval = cpuid4_cache_lookup(j, this_leaf);
  317. if (unlikely(retval < 0))
  318. break;
  319. cache_shared_cpu_map_setup(cpu, j);
  320. }
  321. set_cpus_allowed(current, oldmask);
  322. out:
  323. if (retval)
  324. free_cache_attributes(cpu);
  325. return retval;
  326. }
  327. #ifdef CONFIG_SYSFS
  328. #include <linux/kobject.h>
  329. #include <linux/sysfs.h>
  330. extern struct sysdev_class cpu_sysdev_class; /* from drivers/base/cpu.c */
  331. /* pointer to kobject for cpuX/cache */
  332. static struct kobject * cache_kobject[NR_CPUS];
  333. struct _index_kobject {
  334. struct kobject kobj;
  335. unsigned int cpu;
  336. unsigned short index;
  337. };
  338. /* pointer to array of kobjects for cpuX/cache/indexY */
  339. static struct _index_kobject *index_kobject[NR_CPUS];
  340. #define INDEX_KOBJECT_PTR(x,y) (&((index_kobject[x])[y]))
  341. #define show_one_plus(file_name, object, val) \
  342. static ssize_t show_##file_name \
  343. (struct _cpuid4_info *this_leaf, char *buf) \
  344. { \
  345. return sprintf (buf, "%lu\n", (unsigned long)this_leaf->object + val); \
  346. }
  347. show_one_plus(level, eax.split.level, 0);
  348. show_one_plus(coherency_line_size, ebx.split.coherency_line_size, 1);
  349. show_one_plus(physical_line_partition, ebx.split.physical_line_partition, 1);
  350. show_one_plus(ways_of_associativity, ebx.split.ways_of_associativity, 1);
  351. show_one_plus(number_of_sets, ecx.split.number_of_sets, 1);
  352. static ssize_t show_size(struct _cpuid4_info *this_leaf, char *buf)
  353. {
  354. return sprintf (buf, "%luK\n", this_leaf->size / 1024);
  355. }
  356. static ssize_t show_shared_cpu_map(struct _cpuid4_info *this_leaf, char *buf)
  357. {
  358. char mask_str[NR_CPUS];
  359. cpumask_scnprintf(mask_str, NR_CPUS, this_leaf->shared_cpu_map);
  360. return sprintf(buf, "%s\n", mask_str);
  361. }
  362. static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf) {
  363. switch(this_leaf->eax.split.type) {
  364. case CACHE_TYPE_DATA:
  365. return sprintf(buf, "Data\n");
  366. break;
  367. case CACHE_TYPE_INST:
  368. return sprintf(buf, "Instruction\n");
  369. break;
  370. case CACHE_TYPE_UNIFIED:
  371. return sprintf(buf, "Unified\n");
  372. break;
  373. default:
  374. return sprintf(buf, "Unknown\n");
  375. break;
  376. }
  377. }
  378. struct _cache_attr {
  379. struct attribute attr;
  380. ssize_t (*show)(struct _cpuid4_info *, char *);
  381. ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count);
  382. };
  383. #define define_one_ro(_name) \
  384. static struct _cache_attr _name = \
  385. __ATTR(_name, 0444, show_##_name, NULL)
  386. define_one_ro(level);
  387. define_one_ro(type);
  388. define_one_ro(coherency_line_size);
  389. define_one_ro(physical_line_partition);
  390. define_one_ro(ways_of_associativity);
  391. define_one_ro(number_of_sets);
  392. define_one_ro(size);
  393. define_one_ro(shared_cpu_map);
  394. static struct attribute * default_attrs[] = {
  395. &type.attr,
  396. &level.attr,
  397. &coherency_line_size.attr,
  398. &physical_line_partition.attr,
  399. &ways_of_associativity.attr,
  400. &number_of_sets.attr,
  401. &size.attr,
  402. &shared_cpu_map.attr,
  403. NULL
  404. };
  405. #define to_object(k) container_of(k, struct _index_kobject, kobj)
  406. #define to_attr(a) container_of(a, struct _cache_attr, attr)
  407. static ssize_t show(struct kobject * kobj, struct attribute * attr, char * buf)
  408. {
  409. struct _cache_attr *fattr = to_attr(attr);
  410. struct _index_kobject *this_leaf = to_object(kobj);
  411. ssize_t ret;
  412. ret = fattr->show ?
  413. fattr->show(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index),
  414. buf) :
  415. 0;
  416. return ret;
  417. }
  418. static ssize_t store(struct kobject * kobj, struct attribute * attr,
  419. const char * buf, size_t count)
  420. {
  421. return 0;
  422. }
  423. static struct sysfs_ops sysfs_ops = {
  424. .show = show,
  425. .store = store,
  426. };
  427. static struct kobj_type ktype_cache = {
  428. .sysfs_ops = &sysfs_ops,
  429. .default_attrs = default_attrs,
  430. };
  431. static struct kobj_type ktype_percpu_entry = {
  432. .sysfs_ops = &sysfs_ops,
  433. };
  434. static void cpuid4_cache_sysfs_exit(unsigned int cpu)
  435. {
  436. kfree(cache_kobject[cpu]);
  437. kfree(index_kobject[cpu]);
  438. cache_kobject[cpu] = NULL;
  439. index_kobject[cpu] = NULL;
  440. free_cache_attributes(cpu);
  441. }
  442. static int __devinit cpuid4_cache_sysfs_init(unsigned int cpu)
  443. {
  444. if (num_cache_leaves == 0)
  445. return -ENOENT;
  446. detect_cache_attributes(cpu);
  447. if (cpuid4_info[cpu] == NULL)
  448. return -ENOENT;
  449. /* Allocate all required memory */
  450. cache_kobject[cpu] = kmalloc(sizeof(struct kobject), GFP_KERNEL);
  451. if (unlikely(cache_kobject[cpu] == NULL))
  452. goto err_out;
  453. memset(cache_kobject[cpu], 0, sizeof(struct kobject));
  454. index_kobject[cpu] = kmalloc(
  455. sizeof(struct _index_kobject ) * num_cache_leaves, GFP_KERNEL);
  456. if (unlikely(index_kobject[cpu] == NULL))
  457. goto err_out;
  458. memset(index_kobject[cpu], 0,
  459. sizeof(struct _index_kobject) * num_cache_leaves);
  460. return 0;
  461. err_out:
  462. cpuid4_cache_sysfs_exit(cpu);
  463. return -ENOMEM;
  464. }
  465. /* Add/Remove cache interface for CPU device */
  466. static int __devinit cache_add_dev(struct sys_device * sys_dev)
  467. {
  468. unsigned int cpu = sys_dev->id;
  469. unsigned long i, j;
  470. struct _index_kobject *this_object;
  471. int retval = 0;
  472. retval = cpuid4_cache_sysfs_init(cpu);
  473. if (unlikely(retval < 0))
  474. return retval;
  475. cache_kobject[cpu]->parent = &sys_dev->kobj;
  476. kobject_set_name(cache_kobject[cpu], "%s", "cache");
  477. cache_kobject[cpu]->ktype = &ktype_percpu_entry;
  478. retval = kobject_register(cache_kobject[cpu]);
  479. for (i = 0; i < num_cache_leaves; i++) {
  480. this_object = INDEX_KOBJECT_PTR(cpu,i);
  481. this_object->cpu = cpu;
  482. this_object->index = i;
  483. this_object->kobj.parent = cache_kobject[cpu];
  484. kobject_set_name(&(this_object->kobj), "index%1lu", i);
  485. this_object->kobj.ktype = &ktype_cache;
  486. retval = kobject_register(&(this_object->kobj));
  487. if (unlikely(retval)) {
  488. for (j = 0; j < i; j++) {
  489. kobject_unregister(
  490. &(INDEX_KOBJECT_PTR(cpu,j)->kobj));
  491. }
  492. kobject_unregister(cache_kobject[cpu]);
  493. cpuid4_cache_sysfs_exit(cpu);
  494. break;
  495. }
  496. }
  497. return retval;
  498. }
  499. static int __devexit cache_remove_dev(struct sys_device * sys_dev)
  500. {
  501. unsigned int cpu = sys_dev->id;
  502. unsigned long i;
  503. for (i = 0; i < num_cache_leaves; i++)
  504. kobject_unregister(&(INDEX_KOBJECT_PTR(cpu,i)->kobj));
  505. kobject_unregister(cache_kobject[cpu]);
  506. cpuid4_cache_sysfs_exit(cpu);
  507. return 0;
  508. }
  509. static struct sysdev_driver cache_sysdev_driver = {
  510. .add = cache_add_dev,
  511. .remove = __devexit_p(cache_remove_dev),
  512. };
  513. /* Register/Unregister the cpu_cache driver */
  514. static int __devinit cache_register_driver(void)
  515. {
  516. if (num_cache_leaves == 0)
  517. return 0;
  518. return sysdev_driver_register(&cpu_sysdev_class,&cache_sysdev_driver);
  519. }
  520. device_initcall(cache_register_driver);
  521. #endif