Skip to content

Commit

Permalink
x86, apic: refactor ->cpu_mask_to_apicid*()
Browse files Browse the repository at this point in the history
- spread out the namespace on a per driver basis

 - clean up the functions

 - get rid of macros

Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Ingo Molnar committed Jan 28, 2009
1 parent 94af187 commit debccb3
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 80 deletions.
17 changes: 7 additions & 10 deletions arch/x86/include/asm/bigsmp/apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,25 @@ static inline int bigsmp_check_phys_apicid_present(int boot_cpu_physical_apicid)
}

/* As we are using single CPU as destination, pick only one CPU here */
static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
static inline unsigned int bigsmp_cpu_mask_to_apicid(const cpumask_t *cpumask)
{
int cpu;
int apicid;

cpu = first_cpu(*cpumask);
apicid = bigsmp_cpu_to_logical_apicid(cpu);
return apicid;
return bigsmp_cpu_to_logical_apicid(first_cpu(*cpumask));
}

static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
static inline unsigned int
bigsmp_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
{
int cpu;

/*
* We're using fixed IRQ delivery, can only return one phys APIC ID.
* May as well be the first.
*/
for_each_cpu_and(cpu, cpumask, andmask)
for_each_cpu_and(cpu, cpumask, andmask) {
if (cpumask_test_cpu(cpu, cpu_online_mask))
break;
}
if (cpu < nr_cpu_ids)
return bigsmp_cpu_to_logical_apicid(cpu);

Expand Down
29 changes: 18 additions & 11 deletions arch/x86/include/asm/es7000/apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ static inline int es7000_check_phys_apicid_present(int cpu_physical_apicid)
}

static inline unsigned int
cpu_mask_to_apicid_cluster(const struct cpumask *cpumask)
es7000_cpu_mask_to_apicid_cluster(const struct cpumask *cpumask)
{
int num_bits_set;
int cpus_found = 0;
int cpu;
int num_bits_set;
int apicid;
int cpu;

num_bits_set = cpumask_weight(cpumask);
/* Return id to all */
Expand All @@ -154,12 +154,15 @@ cpu_mask_to_apicid_cluster(const struct cpumask *cpumask)
*/
cpu = cpumask_first(cpumask);
apicid = es7000_cpu_to_logical_apicid(cpu);

while (cpus_found < num_bits_set) {
if (cpumask_test_cpu(cpu, cpumask)) {
int new_apicid = es7000_cpu_to_logical_apicid(cpu);

if (apicid_cluster(apicid) !=
apicid_cluster(new_apicid)){
apicid_cluster(new_apicid)) {
printk ("%s: Not a valid mask!\n", __func__);

return 0xFF;
}
apicid = new_apicid;
Expand All @@ -170,12 +173,12 @@ cpu_mask_to_apicid_cluster(const struct cpumask *cpumask)
return apicid;
}

static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
static inline unsigned int es7000_cpu_mask_to_apicid(const cpumask_t *cpumask)
{
int num_bits_set;
int cpus_found = 0;
int cpu;
int num_bits_set;
int apicid;
int cpu;

num_bits_set = cpus_weight(*cpumask);
/* Return id to all */
Expand All @@ -190,9 +193,11 @@ static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
while (cpus_found < num_bits_set) {
if (cpu_isset(cpu, *cpumask)) {
int new_apicid = es7000_cpu_to_logical_apicid(cpu);

if (apicid_cluster(apicid) !=
apicid_cluster(new_apicid)){
apicid_cluster(new_apicid)) {
printk ("%s: Not a valid mask!\n", __func__);

return es7000_cpu_to_logical_apicid(0);
}
apicid = new_apicid;
Expand All @@ -204,8 +209,9 @@ static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
}


static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *inmask,
const struct cpumask *andmask)
static inline unsigned int
es7000_cpu_mask_to_apicid_and(const struct cpumask *inmask,
const struct cpumask *andmask)
{
int apicid = es7000_cpu_to_logical_apicid(0);
cpumask_var_t cpumask;
Expand All @@ -215,9 +221,10 @@ static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *inmask,

cpumask_and(cpumask, inmask, andmask);
cpumask_and(cpumask, cpumask, cpu_online_mask);
apicid = cpu_mask_to_apicid(cpumask);
apicid = es7000_cpu_mask_to_apicid(cpumask);

free_cpumask_var(cpumask);

return apicid;
}

Expand Down
10 changes: 5 additions & 5 deletions arch/x86/include/asm/mach-default/mach_apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ static inline const struct cpumask *default_target_cpus(void)

#ifdef CONFIG_X86_64
#include <asm/genapic.h>
#define cpu_mask_to_apicid (apic->cpu_mask_to_apicid)
#define cpu_mask_to_apicid_and (apic->cpu_mask_to_apicid_and)
#define read_apic_id() (apic->get_apic_id(apic_read(APIC_ID)))
#define send_IPI_self (apic->send_IPI_self)
#define wakeup_secondary_cpu (apic->wakeup_cpu)
Expand Down Expand Up @@ -49,13 +47,15 @@ static inline int default_apic_id_registered(void)
return physid_isset(read_apic_id(), phys_cpu_present_map);
}

static inline unsigned int cpu_mask_to_apicid(const struct cpumask *cpumask)
static inline unsigned int
default_cpu_mask_to_apicid(const struct cpumask *cpumask)
{
return cpumask_bits(cpumask)[0];
}

static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
static inline unsigned int
default_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
{
unsigned long mask1 = cpumask_bits(cpumask)[0];
unsigned long mask2 = cpumask_bits(andmask)[0];
Expand Down
2 changes: 0 additions & 2 deletions arch/x86/include/asm/mach-generic/mach_apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include <asm/genapic.h>

#define cpu_mask_to_apicid (apic->cpu_mask_to_apicid)
#define cpu_mask_to_apicid_and (apic->cpu_mask_to_apicid_and)
#define wakeup_secondary_cpu (apic->wakeup_cpu)

extern void generic_bigsmp_probe(void);
Expand Down
11 changes: 6 additions & 5 deletions arch/x86/include/asm/numaq/apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,16 @@ static inline int numaq_check_phys_apicid_present(int boot_cpu_physical_apicid)
* We use physical apicids here, not logical, so just return the default
* physical broadcast to stop people from breaking us
*/
static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
static inline unsigned int numaq_cpu_mask_to_apicid(const cpumask_t *cpumask)
{
return (int) 0xF;
return 0x0F;
}

static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
static inline unsigned int
numaq_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
{
return (int) 0xF;
return 0x0F;
}

/* No NUMA-Q box has a HT CPU, but it can't hurt to use the default code. */
Expand Down
21 changes: 13 additions & 8 deletions arch/x86/include/asm/summit/apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,32 @@ static inline int summit_check_phys_apicid_present(int boot_cpu_physical_apicid)
return 1;
}

static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
static inline unsigned int summit_cpu_mask_to_apicid(const cpumask_t *cpumask)
{
int num_bits_set;
int cpus_found = 0;
int cpu;
int num_bits_set;
int apicid;
int cpu;

num_bits_set = cpus_weight(*cpumask);
/* Return id to all */
if (num_bits_set >= nr_cpu_ids)
return (int) 0xFF;
return 0xFF;
/*
* The cpus in the mask must all be on the apic cluster. If are not
* on the same apicid cluster return default value of target_cpus():
*/
cpu = first_cpu(*cpumask);
apicid = summit_cpu_to_logical_apicid(cpu);

while (cpus_found < num_bits_set) {
if (cpu_isset(cpu, *cpumask)) {
int new_apicid = summit_cpu_to_logical_apicid(cpu);

if (apicid_cluster(apicid) !=
apicid_cluster(new_apicid)){
apicid_cluster(new_apicid)) {
printk ("%s: Not a valid mask!\n", __func__);

return 0xFF;
}
apicid = apicid | new_apicid;
Expand All @@ -158,8 +161,9 @@ static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
return apicid;
}

static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *inmask,
const struct cpumask *andmask)
static inline unsigned int
summit_cpu_mask_to_apicid_and(const struct cpumask *inmask,
const struct cpumask *andmask)
{
int apicid = summit_cpu_to_logical_apicid(0);
cpumask_var_t cpumask;
Expand All @@ -169,9 +173,10 @@ static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *inmask,

cpumask_and(cpumask, inmask, andmask);
cpumask_and(cpumask, cpumask, cpu_online_mask);
apicid = cpu_mask_to_apicid(cpumask);
apicid = summit_cpu_mask_to_apicid(cpumask);

free_cpumask_var(cpumask);

return apicid;
}

Expand Down
4 changes: 3 additions & 1 deletion arch/x86/kernel/genapic_flat_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,13 @@ physflat_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
* We're using fixed IRQ delivery, can only return one phys APIC ID.
* May as well be the first.
*/
for_each_cpu_and(cpu, cpumask, andmask)
for_each_cpu_and(cpu, cpumask, andmask) {
if (cpumask_test_cpu(cpu, cpu_online_mask))
break;
}
if (cpu < nr_cpu_ids)
return per_cpu(x86_cpu_to_apicid, cpu);

return BAD_APICID;
}

Expand Down
15 changes: 9 additions & 6 deletions arch/x86/kernel/genx2apic_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,33 +111,36 @@ static int x2apic_apic_id_registered(void)

static unsigned int x2apic_cpu_mask_to_apicid(const struct cpumask *cpumask)
{
int cpu;

/*
* We're using fixed IRQ delivery, can only return one logical APIC ID.
* May as well be the first.
*/
cpu = cpumask_first(cpumask);
int cpu = cpumask_first(cpumask);

if ((unsigned)cpu < nr_cpu_ids)
return per_cpu(x86_cpu_to_logical_apicid, cpu);
else
return BAD_APICID;
}

static unsigned int x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
static unsigned int
x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
{
int cpu;

/*
* We're using fixed IRQ delivery, can only return one logical APIC ID.
* May as well be the first.
*/
for_each_cpu_and(cpu, cpumask, andmask)
for_each_cpu_and(cpu, cpumask, andmask) {
if (cpumask_test_cpu(cpu, cpu_online_mask))
break;
}

if (cpu < nr_cpu_ids)
return per_cpu(x86_cpu_to_logical_apicid, cpu);

return BAD_APICID;
}

Expand Down
15 changes: 9 additions & 6 deletions arch/x86/kernel/genx2apic_phys.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,33 +110,36 @@ static int x2apic_apic_id_registered(void)

static unsigned int x2apic_cpu_mask_to_apicid(const struct cpumask *cpumask)
{
int cpu;

/*
* We're using fixed IRQ delivery, can only return one phys APIC ID.
* May as well be the first.
*/
cpu = cpumask_first(cpumask);
int cpu = cpumask_first(cpumask);

if ((unsigned)cpu < nr_cpu_ids)
return per_cpu(x86_cpu_to_apicid, cpu);
else
return BAD_APICID;
}

static unsigned int x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
static unsigned int
x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
{
int cpu;

/*
* We're using fixed IRQ delivery, can only return one phys APIC ID.
* May as well be the first.
*/
for_each_cpu_and(cpu, cpumask, andmask)
for_each_cpu_and(cpu, cpumask, andmask) {
if (cpumask_test_cpu(cpu, cpu_online_mask))
break;
}

if (cpu < nr_cpu_ids)
return per_cpu(x86_cpu_to_apicid, cpu);

return BAD_APICID;
}

Expand Down
14 changes: 8 additions & 6 deletions arch/x86/kernel/genx2apic_uv_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,33 +171,35 @@ static void uv_init_apic_ldr(void)

static unsigned int uv_cpu_mask_to_apicid(const struct cpumask *cpumask)
{
int cpu;

/*
* We're using fixed IRQ delivery, can only return one phys APIC ID.
* May as well be the first.
*/
cpu = cpumask_first(cpumask);
int cpu = cpumask_first(cpumask);

if ((unsigned)cpu < nr_cpu_ids)
return per_cpu(x86_cpu_to_apicid, cpu);
else
return BAD_APICID;
}

static unsigned int uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
static unsigned int
uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask)
{
int cpu;

/*
* We're using fixed IRQ delivery, can only return one phys APIC ID.
* May as well be the first.
*/
for_each_cpu_and(cpu, cpumask, andmask)
for_each_cpu_and(cpu, cpumask, andmask) {
if (cpumask_test_cpu(cpu, cpu_online_mask))
break;
}
if (cpu < nr_cpu_ids)
return per_cpu(x86_cpu_to_apicid, cpu);

return BAD_APICID;
}

Expand Down
Loading

0 comments on commit debccb3

Please sign in to comment.