提交 99d86705 编写于 作者: V Vaidyanathan Srinivasan 提交者: Benjamin Herrenschmidt

powerpc: Cleanup APIs for cpu/thread/core mappings

These APIs take logical cpu number as input
Change cpu_first_thread_in_core() to cpu_first_thread_sibling()
Change cpu_last_thread_in_core() to cpu_last_thread_sibling()

These APIs convert core number (index) to logical cpu/thread numbers
Add cpu_first_thread_of_core(int core)
Changed cpu_thread_to_core() to cpu_core_index_of_thread(int cpu)

The goal is to make 'threads_per_core' accessible to the
pseries_energy module.  Instead of making an API to read
threads_per_core, this is a higher level wrapper function to
convert from logical cpu number to core number.

The current APIs cpu_first_thread_in_core() and
cpu_last_thread_in_core() returns logical CPU number while
cpu_thread_to_core() returns core number or index which is
not a logical CPU number.  The new APIs are now clearly named to
distinguish 'core number' versus first and last 'logical cpu
number' in that core.

The new APIs cpu_{first,last}_thread_sibling() work on
logical cpu numbers.  While cpu_first_thread_of_core() and
cpu_core_index_of_thread() work on core index.

Example usage:  (4 threads per core system)

cpu_first_thread_sibling(5) = 4
cpu_last_thread_sibling(5) = 7
cpu_core_index_of_thread(5) = 1
cpu_first_thread_of_core(1) = 4

cpu_core_index_of_thread() is used in cpu_to_drc_index() in the
module and cpu_first_thread_of_core() is used in
drc_index_to_cpu() in the module.

Make API changes to few callers.  Export symbols for use in modules.
Signed-off-by: NVaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Signed-off-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
上级 787d44ca
...@@ -61,22 +61,25 @@ static inline cpumask_t cpu_online_cores_map(void) ...@@ -61,22 +61,25 @@ static inline cpumask_t cpu_online_cores_map(void)
return cpu_thread_mask_to_cores(cpu_online_map); return cpu_thread_mask_to_cores(cpu_online_map);
} }
static inline int cpu_thread_to_core(int cpu) #ifdef CONFIG_SMP
{ int cpu_core_index_of_thread(int cpu);
return cpu >> threads_shift; int cpu_first_thread_of_core(int core);
} #else
static inline int cpu_core_index_of_thread(int cpu) { return cpu; }
static inline int cpu_first_thread_of_core(int core) { return core; }
#endif
static inline int cpu_thread_in_core(int cpu) static inline int cpu_thread_in_core(int cpu)
{ {
return cpu & (threads_per_core - 1); return cpu & (threads_per_core - 1);
} }
static inline int cpu_first_thread_in_core(int cpu) static inline int cpu_first_thread_sibling(int cpu)
{ {
return cpu & ~(threads_per_core - 1); return cpu & ~(threads_per_core - 1);
} }
static inline int cpu_last_thread_in_core(int cpu) static inline int cpu_last_thread_sibling(int cpu)
{ {
return cpu | (threads_per_core - 1); return cpu | (threads_per_core - 1);
} }
......
...@@ -466,7 +466,20 @@ int cpu_to_core_id(int cpu) ...@@ -466,7 +466,20 @@ int cpu_to_core_id(int cpu)
return id; return id;
} }
/* Must be called when no change can occur to cpu_present_mask, /* Helper routines for cpu to core mapping */
int cpu_core_index_of_thread(int cpu)
{
return cpu >> threads_shift;
}
EXPORT_SYMBOL_GPL(cpu_core_index_of_thread);
int cpu_first_thread_of_core(int core)
{
return core << threads_shift;
}
EXPORT_SYMBOL_GPL(cpu_first_thread_of_core);
/* Must be called when no change can occur to cpu_present_map,
* i.e. during cpu online or offline. * i.e. during cpu online or offline.
*/ */
static struct device_node *cpu_to_l2cache(int cpu) static struct device_node *cpu_to_l2cache(int cpu)
...@@ -514,7 +527,7 @@ int __devinit start_secondary(void *unused) ...@@ -514,7 +527,7 @@ int __devinit start_secondary(void *unused)
notify_cpu_starting(cpu); notify_cpu_starting(cpu);
set_cpu_online(cpu, true); set_cpu_online(cpu, true);
/* Update sibling maps */ /* Update sibling maps */
base = cpu_first_thread_in_core(cpu); base = cpu_first_thread_sibling(cpu);
for (i = 0; i < threads_per_core; i++) { for (i = 0; i < threads_per_core; i++) {
if (cpu_is_offline(base + i)) if (cpu_is_offline(base + i))
continue; continue;
...@@ -600,7 +613,7 @@ int __cpu_disable(void) ...@@ -600,7 +613,7 @@ int __cpu_disable(void)
return err; return err;
/* Update sibling maps */ /* Update sibling maps */
base = cpu_first_thread_in_core(cpu); base = cpu_first_thread_sibling(cpu);
for (i = 0; i < threads_per_core; i++) { for (i = 0; i < threads_per_core; i++) {
cpumask_clear_cpu(cpu, cpu_sibling_mask(base + i)); cpumask_clear_cpu(cpu, cpu_sibling_mask(base + i));
cpumask_clear_cpu(base + i, cpu_sibling_mask(cpu)); cpumask_clear_cpu(base + i, cpu_sibling_mask(cpu));
......
...@@ -111,8 +111,8 @@ static unsigned int steal_context_smp(unsigned int id) ...@@ -111,8 +111,8 @@ static unsigned int steal_context_smp(unsigned int id)
* a core map instead but this will do for now. * a core map instead but this will do for now.
*/ */
for_each_cpu(cpu, mm_cpumask(mm)) { for_each_cpu(cpu, mm_cpumask(mm)) {
for (i = cpu_first_thread_in_core(cpu); for (i = cpu_first_thread_sibling(cpu);
i <= cpu_last_thread_in_core(cpu); i++) i <= cpu_last_thread_sibling(cpu); i++)
__set_bit(id, stale_map[i]); __set_bit(id, stale_map[i]);
cpu = i - 1; cpu = i - 1;
} }
...@@ -264,14 +264,14 @@ void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next) ...@@ -264,14 +264,14 @@ void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next)
*/ */
if (test_bit(id, stale_map[cpu])) { if (test_bit(id, stale_map[cpu])) {
pr_hardcont(" | stale flush %d [%d..%d]", pr_hardcont(" | stale flush %d [%d..%d]",
id, cpu_first_thread_in_core(cpu), id, cpu_first_thread_sibling(cpu),
cpu_last_thread_in_core(cpu)); cpu_last_thread_sibling(cpu));
local_flush_tlb_mm(next); local_flush_tlb_mm(next);
/* XXX This clear should ultimately be part of local_flush_tlb_mm */ /* XXX This clear should ultimately be part of local_flush_tlb_mm */
for (i = cpu_first_thread_in_core(cpu); for (i = cpu_first_thread_sibling(cpu);
i <= cpu_last_thread_in_core(cpu); i++) { i <= cpu_last_thread_sibling(cpu); i++) {
__clear_bit(id, stale_map[i]); __clear_bit(id, stale_map[i]);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册