topology.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2007 Paul Mundt
  3. * Copyright (C) 2010 Imagination Technolohies Ltd.
  4. *
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file "COPYING" in the main directory of this archive
  7. * for more details.
  8. */
  9. #include <linux/cpu.h>
  10. #include <linux/cpumask.h>
  11. #include <linux/init.h>
  12. #include <linux/percpu.h>
  13. #include <linux/node.h>
  14. #include <linux/nodemask.h>
  15. #include <linux/topology.h>
  16. #include <asm/cpu.h>
  17. DEFINE_PER_CPU(struct cpuinfo_metag, cpu_data);
  18. cpumask_t cpu_core_map[NR_CPUS];
  19. EXPORT_SYMBOL(cpu_core_map);
  20. static cpumask_t cpu_coregroup_map(unsigned int cpu)
  21. {
  22. return *cpu_possible_mask;
  23. }
  24. const struct cpumask *cpu_coregroup_mask(unsigned int cpu)
  25. {
  26. return &cpu_core_map[cpu];
  27. }
  28. int arch_update_cpu_topology(void)
  29. {
  30. unsigned int cpu;
  31. for_each_possible_cpu(cpu)
  32. cpu_core_map[cpu] = cpu_coregroup_map(cpu);
  33. return 0;
  34. }
  35. static int __init topology_init(void)
  36. {
  37. int i, ret;
  38. #ifdef CONFIG_NEED_MULTIPLE_NODES
  39. for_each_online_node(i)
  40. register_one_node(i);
  41. #endif
  42. for_each_present_cpu(i) {
  43. struct cpuinfo_metag *cpuinfo = &per_cpu(cpu_data, i);
  44. #ifdef CONFIG_HOTPLUG_CPU
  45. cpuinfo->cpu.hotpluggable = 1;
  46. #endif
  47. ret = register_cpu(&cpuinfo->cpu, i);
  48. if (unlikely(ret))
  49. pr_warn("%s: register_cpu %d failed (%d)\n",
  50. __func__, i, ret);
  51. }
  52. #if defined(CONFIG_NUMA) && !defined(CONFIG_SMP)
  53. /*
  54. * In the UP case, make sure the CPU association is still
  55. * registered under each node. Without this, sysfs fails
  56. * to make the connection between nodes other than node0
  57. * and cpu0.
  58. */
  59. for_each_online_node(i)
  60. if (i != numa_node_id())
  61. register_cpu_under_node(raw_smp_processor_id(), i);
  62. #endif
  63. return 0;
  64. }
  65. subsys_initcall(topology_init);