topology.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. return register_cpu(&sysfs_cpus[num].cpu, num, parent);
  35. }
  36. #ifdef CONFIG_HOTPLUG_CPU
  37. void arch_unregister_cpu(int num)
  38. {
  39. struct node *parent = NULL;
  40. #ifdef CONFIG_NUMA
  41. int node = cpu_to_node(num);
  42. parent = &sysfs_nodes[node];
  43. #endif /* CONFIG_NUMA */
  44. return unregister_cpu(&sysfs_cpus[num].cpu, parent);
  45. }
  46. EXPORT_SYMBOL(arch_register_cpu);
  47. EXPORT_SYMBOL(arch_unregister_cpu);
  48. #endif /*CONFIG_HOTPLUG_CPU*/
  49. static int __init topology_init(void)
  50. {
  51. int i, err = 0;
  52. #ifdef CONFIG_NUMA
  53. sysfs_nodes = kmalloc(sizeof(struct node) * MAX_NUMNODES, GFP_KERNEL);
  54. if (!sysfs_nodes) {
  55. err = -ENOMEM;
  56. goto out;
  57. }
  58. memset(sysfs_nodes, 0, sizeof(struct node) * MAX_NUMNODES);
  59. /* MCD - Do we want to register all ONLINE nodes, or all POSSIBLE nodes? */
  60. for_each_online_node(i)
  61. if ((err = register_node(&sysfs_nodes[i], i, 0)))
  62. goto out;
  63. #endif
  64. sysfs_cpus = kmalloc(sizeof(struct ia64_cpu) * NR_CPUS, GFP_KERNEL);
  65. if (!sysfs_cpus) {
  66. err = -ENOMEM;
  67. goto out;
  68. }
  69. memset(sysfs_cpus, 0, sizeof(struct ia64_cpu) * NR_CPUS);
  70. for_each_present_cpu(i)
  71. if((err = arch_register_cpu(i)))
  72. goto out;
  73. out:
  74. return err;
  75. }
  76. __initcall(topology_init);