[COMMON] soc: samsung: topology: Configure exynos_topology based on DT
authorDaeyeong Lee <daeyeong.lee@samsung.com>
Mon, 19 Feb 2018 13:27:15 +0000 (22:27 +0900)
committerChungwoo Park <cww.park@samsung.com>
Mon, 21 May 2018 08:32:58 +0000 (17:32 +0900)
Change-Id: If9b7e2086e99e5b9ac1e8348c58da7eee363e490
Signed-off-by: Daeyeong Lee <daeyeong.lee@samsung.com>
drivers/soc/samsung/exynos-topology.c

index a76f50c9ad4146c632f18037b2eb40efad9da53e..35cfa92447ac675dde51cde4662ac9e362abe74c 100644 (file)
@@ -300,12 +300,10 @@ void store_cpu_topology(unsigned int cpuid)
        topology_detect_flags();
 }
 
-#ifdef CONFIG_SCHED_MC
 static int core_flags(void)
 {
        return cpu_core_flags() | topology_core_flags();
 }
-#endif
 
 static int cluster_flags(void)
 {
@@ -381,14 +379,60 @@ const struct sched_group_energy * const cpu_cluster_energy(int cpu)
        return sge;
 }
 
-static struct sched_domain_topology_level arm64_topology[] = {
-#ifdef CONFIG_SCHED_MC
-       { cpu_coregroup_mask, core_flags, cpu_core_energy, SD_INIT_NAME(MC) },
+static struct sched_domain_topology_level exynos_topology[NR_SD_LEVELS];
+
+#ifdef CONFIG_SCHED_DEBUG
+#define sd_init_name(topology, type)   topology.name = #type
+#else
+#define sd_init_name(topology, type)
 #endif
-       { cpu_cluster_mask, cluster_flags, cpu_coregroup_energy, SD_INIT_NAME(DSU) },
-       { cpu_cpu_mask, cpu_flags, cpu_cluster_energy, SD_INIT_NAME(DIE) },
-       { NULL, }
-};
+
+static void __init build_sched_topology(void)
+{
+       struct cpu_topology *cpuid_topo, *cpu_topo = &cpu_topology[0];
+       bool cluster_level = false;
+       bool coregroup_level = false;
+       bool core_level = false;
+       int cpu;
+       int level = 0;
+
+       for_each_possible_cpu(cpu) {
+               cpuid_topo = &cpu_topology[cpu];
+
+               if (cpuid_topo->cluster_id != cpu_topo->cluster_id)
+                       cluster_level = true;
+               if (cpuid_topo->coregroup_id != cpu_topo->coregroup_id)
+                       coregroup_level = true;
+               if (cpuid_topo->core_id != cpu_topo->core_id)
+                       core_level = true;
+       }
+
+       if (core_level) {
+               exynos_topology[level].mask = cpu_coregroup_mask;
+               exynos_topology[level].sd_flags = core_flags;
+               exynos_topology[level].energy = cpu_core_energy;
+               sd_init_name(exynos_topology[level], MC);
+
+               level++;
+       }
+       if (coregroup_level) {
+               exynos_topology[level].mask = cpu_cluster_mask;
+               exynos_topology[level].sd_flags = cluster_flags;
+               exynos_topology[level].energy = cpu_coregroup_energy;
+               sd_init_name(exynos_topology[level], DSU);
+
+               level++;
+       }
+       if (cluster_level) {
+               exynos_topology[level].mask = cpu_cpu_mask;
+               exynos_topology[level].sd_flags = cpu_flags;
+               exynos_topology[level].energy = cpu_cluster_energy;
+               sd_init_name(exynos_topology[level], DIE);
+
+               level++;
+       }
+       exynos_topology[level].mask = NULL;
+}
 
 static void __init reset_cpu_topology(void)
 {
@@ -425,6 +469,8 @@ void __init init_cpu_topology(void)
         */
        if (of_have_populated_dt() && parse_dt_topology())
                reset_cpu_topology();
-       else
-               set_sched_topology(arm64_topology);
+       else {
+               build_sched_topology();
+               set_sched_topology(exynos_topology);
+       }
 }