topology.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * This file contains NUMA specific variables and functions which can
  7. * be split away from DISCONTIGMEM and are used on NUMA machines with
  8. * contiguous memory.
  9. * 2002/08/07 Erich Focht <efocht@ess.nec.de>
  10. * Populate cpu entries in sysfs for non-numa systems as well
  11. * Intel Corporation - Ashok Raj
  12. */
  13. #include <linux/config.h>
  14. #include <linux/cpu.h>
  15. #include <linux/kernel.h>
  16. #include <linux/mm.h>
  17. #include <linux/node.h>
  18. #include <linux/init.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/nodemask.h>
  21. #include <asm/mmzone.h>
  22. #include <asm/numa.h>
  23. #include <asm/cpu.h>
  24. #ifdef CONFIG_NUMA
  25. static struct node *sysfs_nodes;
  26. #endif
  27. static struct ia64_cpu *sysfs_cpus;
  28. int arch_register_cpu(int num)
  29. {
  30. struct node *parent = NULL;
  31. #ifdef CONFIG_NUMA
  32. parent = &sysfs_nodes[cpu_to_node(num)];
  33. #endif /* CONFIG_NUMA */
  34. /*
  35. * If CPEI cannot be re-targetted, and this is
  36. * CPEI target, then dont create the control file
  37. */
  38. if (!can_cpei_retarget() && is_cpu_cpei_target(num))
  39. sysfs_cpus[num].cpu.no_control = 1;
  40. return register_cpu(&sysfs_cpus[num].cpu, num, parent);
  41. }
  42. #ifdef CONFIG_HOTPLUG_CPU
  43. void arch_unregister_cpu(int num)
  44. {
  45. struct node *parent = NULL;
  46. #ifdef CONFIG_NUMA
  47. int node = cpu_to_node(num);
  48. parent = &sysfs_nodes[node];
  49. #endif /* CONFIG_NUMA */
  50. return unregister_cpu(&sysfs_cpus[num].cpu, parent);
  51. }
  52. EXPORT_SYMBOL(arch_register_cpu);
  53. EXPORT_SYMBOL(arch_unregister_cpu);
  54. #endif /*CONFIG_HOTPLUG_CPU*/
  55. static int __init topology_init(void)
  56. {
  57. int i, err = 0;
  58. #ifdef CONFIG_NUMA
  59. sysfs_nodes = kmalloc(sizeof(struct node) * MAX_NUMNODES, GFP_KERNEL);
  60. if (!sysfs_nodes) {
  61. err = -ENOMEM;
  62. goto out;
  63. }
  64. memset(sysfs_nodes, 0, sizeof(struct node) * MAX_NUMNODES);
  65. /* MCD - Do we want to register all ONLINE nodes, or all POSSIBLE nodes? */
  66. for_each_online_node(i)
  67. if ((err = register_node(&sysfs_nodes[i], i, 0)))
  68. goto out;
  69. #endif
  70. sysfs_cpus = kmalloc(sizeof(struct ia64_cpu) * NR_CPUS, GFP_KERNEL);
  71. if (!sysfs_cpus) {
  72. err = -ENOMEM;
  73. goto out;
  74. }
  75. memset(sysfs_cpus, 0, sizeof(struct ia64_cpu) * NR_CPUS);
  76. for_each_present_cpu(i)
  77. if((err = arch_register_cpu(i)))
  78. goto out;
  79. out:
  80. return err;
  81. }
  82. __initcall(topology_init);