Re: [PATCH v8 3/7] cpu-topology: Move cpu topology code to common code.

2019-06-28 Thread Hanjun Guo
On 2019/6/28 3:52, Atish Patra wrote:
> Both RISC-V & ARM64 are using cpu-map device tree to describe
> their cpu topology. It's better to move the relevant code to
> a common place instead of duplicate code.
> 
> To: Will Deacon 
> To: Catalin Marinas 

Using Cc: is better.

> Signed-off-by: Atish Patra 
> [Tested on QDF2400]
> Tested-by: Jeffrey Hugo 
> [Tested on Juno and other embedded platforms.]
> Tested-by: Sudeep Holla 
> Reviewed-by: Sudeep Holla 
> Acked-by: Will Deacon 
> Acked-by: Greg Kroah-Hartman 
> ---
>  arch/arm64/include/asm/topology.h |  23 ---
>  arch/arm64/kernel/topology.c  | 303 +-
>  drivers/base/arch_topology.c  | 296 +
>  include/linux/arch_topology.h |  28 +++
>  include/linux/topology.h  |   1 +
>  5 files changed, 329 insertions(+), 322 deletions(-)

Tested on Kunpeng920 ARM64 server, works good,

# lscpu
Architecture:aarch64
Byte Order:  Little Endian
CPU(s):  96
On-line CPU(s) list: 0-95
Thread(s) per core:  1
Core(s) per socket:  48
Socket(s):   2
NUMA node(s):4
Vendor ID:   0x48
Model:   0
Stepping:0x1
CPU max MHz: 2600.
CPU min MHz: 260.
BogoMIPS:200.00
L1d cache:   64K
L1i cache:   64K
L2 cache:512K
L3 cache:32768K
NUMA node0 CPU(s):   0-23
NUMA node1 CPU(s):   24-47
NUMA node2 CPU(s):   48-71
NUMA node3 CPU(s):   72-95
Flags:   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp 
asimdhp cpuid asimdrdm jscvt fcma dcpop asimddp asimdfhm

Tested-by: Hanjun Guo 

For the ACPI code,

Acked-by: Hanjun Guo 

Thanks
Hanjun



[PATCH v8 3/7] cpu-topology: Move cpu topology code to common code.

2019-06-27 Thread Atish Patra
Both RISC-V & ARM64 are using cpu-map device tree to describe
their cpu topology. It's better to move the relevant code to
a common place instead of duplicate code.

To: Will Deacon 
To: Catalin Marinas 
Signed-off-by: Atish Patra 
[Tested on QDF2400]
Tested-by: Jeffrey Hugo 
[Tested on Juno and other embedded platforms.]
Tested-by: Sudeep Holla 
Reviewed-by: Sudeep Holla 
Acked-by: Will Deacon 
Acked-by: Greg Kroah-Hartman 
---
 arch/arm64/include/asm/topology.h |  23 ---
 arch/arm64/kernel/topology.c  | 303 +-
 drivers/base/arch_topology.c  | 296 +
 include/linux/arch_topology.h |  28 +++
 include/linux/topology.h  |   1 +
 5 files changed, 329 insertions(+), 322 deletions(-)

diff --git a/arch/arm64/include/asm/topology.h 
b/arch/arm64/include/asm/topology.h
index 0524f2438649..a4d945db95a2 100644
--- a/arch/arm64/include/asm/topology.h
+++ b/arch/arm64/include/asm/topology.h
@@ -4,29 +4,6 @@
 
 #include 
 
-struct cpu_topology {
-   int thread_id;
-   int core_id;
-   int package_id;
-   int llc_id;
-   cpumask_t thread_sibling;
-   cpumask_t core_sibling;
-   cpumask_t llc_sibling;
-};
-
-extern struct cpu_topology cpu_topology[NR_CPUS];
-
-#define topology_physical_package_id(cpu)  (cpu_topology[cpu].package_id)
-#define topology_core_id(cpu)  (cpu_topology[cpu].core_id)
-#define topology_core_cpumask(cpu) (_topology[cpu].core_sibling)
-#define topology_sibling_cpumask(cpu)  (_topology[cpu].thread_sibling)
-#define topology_llc_cpumask(cpu)  (_topology[cpu].llc_sibling)
-
-void init_cpu_topology(void);
-void store_cpu_topology(unsigned int cpuid);
-void remove_cpu_topology(unsigned int cpuid);
-const struct cpumask *cpu_coregroup_mask(int cpu);
-
 #ifdef CONFIG_NUMA
 
 struct pci_bus;
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index 0825c4a856e3..6b95c91e7d67 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -14,250 +14,13 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
 
 #include 
 #include 
 #include 
 
-static int __init get_cpu_for_node(struct device_node *node)
-{
-   struct device_node *cpu_node;
-   int cpu;
-
-   cpu_node = of_parse_phandle(node, "cpu", 0);
-   if (!cpu_node)
-   return -1;
-
-   cpu = of_cpu_node_to_id(cpu_node);
-   if (cpu >= 0)
-   topology_parse_cpu_capacity(cpu_node, cpu);
-   else
-   pr_crit("Unable to find CPU node for %pOF\n", cpu_node);
-
-   of_node_put(cpu_node);
-   return cpu;
-}
-
-static int __init parse_core(struct device_node *core, int package_id,
-int core_id)
-{
-   char name[10];
-   bool leaf = true;
-   int i = 0;
-   int cpu;
-   struct device_node *t;
-
-   do {
-   snprintf(name, sizeof(name), "thread%d", i);
-   t = of_get_child_by_name(core, name);
-   if (t) {
-   leaf = false;
-   cpu = get_cpu_for_node(t);
-   if (cpu >= 0) {
-   cpu_topology[cpu].package_id = package_id;
-   cpu_topology[cpu].core_id = core_id;
-   cpu_topology[cpu].thread_id = i;
-   } else {
-   pr_err("%pOF: Can't get CPU for thread\n",
-  t);
-   of_node_put(t);
-   return -EINVAL;
-   }
-   of_node_put(t);
-   }
-   i++;
-   } while (t);
-
-   cpu = get_cpu_for_node(core);
-   if (cpu >= 0) {
-   if (!leaf) {
-   pr_err("%pOF: Core has both threads and CPU\n",
-  core);
-   return -EINVAL;
-   }
-
-   cpu_topology[cpu].package_id = package_id;
-   cpu_topology[cpu].core_id = core_id;
-   } else if (leaf) {
-   pr_err("%pOF: Can't get CPU for leaf core\n", core);
-   return -EINVAL;
-   }
-
-   return 0;
-}
-
-static int __init parse_cluster(struct device_node *cluster, int depth)
-{
-   char name[10];
-   bool leaf = true;
-   bool has_cores = false;
-   struct device_node *c;
-   static int package_id __initdata;
-   int core_id = 0;
-   int i, ret;
-
-   /*
-* First check for child clusters; we currently ignore any
-* information about the nesting of clusters and present the
-* scheduler with a flat list of them.
-*/
-   i = 0;
-   do {
-   snprintf(name, sizeof(name), "cluster%d", i);
-   c =