topology.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * arch/parisc/kernel/topology.c
  3. *
  4. * Copyright (C) 2017 Helge Deller <[email protected]>
  5. *
  6. * based on arch/arm/kernel/topology.c
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/percpu.h>
  13. #include <linux/sched.h>
  14. #include <linux/sched/topology.h>
  15. #include <linux/cpu.h>
  16. #include <asm/topology.h>
  17. #include <asm/sections.h>
  18. static DEFINE_PER_CPU(struct cpu, cpu_devices);
  19. /*
  20. * store_cpu_topology is called at boot when only one cpu is running
  21. * and with the mutex cpu_hotplug.lock locked, when several cpus have booted,
  22. * which prevents simultaneous write access to cpu_topology array
  23. */
  24. void store_cpu_topology(unsigned int cpuid)
  25. {
  26. struct cpu_topology *cpuid_topo = &cpu_topology[cpuid];
  27. struct cpuinfo_parisc *p;
  28. int max_socket = -1;
  29. unsigned long cpu;
  30. /* If the cpu topology has been already set, just return */
  31. if (cpuid_topo->core_id != -1)
  32. return;
  33. #ifdef CONFIG_HOTPLUG_CPU
  34. per_cpu(cpu_devices, cpuid).hotpluggable = 1;
  35. #endif
  36. if (register_cpu(&per_cpu(cpu_devices, cpuid), cpuid))
  37. pr_warn("Failed to register CPU%d device", cpuid);
  38. /* create cpu topology mapping */
  39. cpuid_topo->thread_id = -1;
  40. cpuid_topo->core_id = 0;
  41. p = &per_cpu(cpu_data, cpuid);
  42. for_each_online_cpu(cpu) {
  43. const struct cpuinfo_parisc *cpuinfo = &per_cpu(cpu_data, cpu);
  44. if (cpu == cpuid) /* ignore current cpu */
  45. continue;
  46. if (cpuinfo->cpu_loc == p->cpu_loc) {
  47. cpuid_topo->core_id = cpu_topology[cpu].core_id;
  48. if (p->cpu_loc) {
  49. cpuid_topo->core_id++;
  50. cpuid_topo->package_id = cpu_topology[cpu].package_id;
  51. continue;
  52. }
  53. }
  54. if (cpuid_topo->package_id == -1)
  55. max_socket = max(max_socket, cpu_topology[cpu].package_id);
  56. }
  57. if (cpuid_topo->package_id == -1)
  58. cpuid_topo->package_id = max_socket + 1;
  59. update_siblings_masks(cpuid);
  60. pr_info("CPU%u: cpu core %d of socket %d\n",
  61. cpuid,
  62. cpu_topology[cpuid].core_id,
  63. cpu_topology[cpuid].package_id);
  64. }
  65. /*
  66. * init_cpu_topology is called at boot when only one cpu is running
  67. * which prevent simultaneous write access to cpu_topology array
  68. */
  69. void __init init_cpu_topology(void)
  70. {
  71. reset_cpu_topology();
  72. }