Skip to content

Commit

Permalink
x86 smp: modify send_IPI_mask interface to accept cpumask_t pointers
Browse files Browse the repository at this point in the history
Impact: cleanup, change parameter passing

  * Change genapic interfaces to accept cpumask_t pointers where possible.

  * Modify external callers to use cpumask_t pointers in function calls.

  * Create new send_IPI_mask_allbutself which is the same as the
    send_IPI_mask functions but removes smp_processor_id() from list.
    This removes another common need for a temporary cpumask_t variable.

  * Functions that used a temp cpumask_t variable for:

	cpumask_t allbutme = cpu_online_map;

	cpu_clear(smp_processor_id(), allbutme);
	if (!cpus_empty(allbutme))
		...

    become:

	if (!cpus_equal(cpu_online_map, cpumask_of_cpu(cpu)))
		...

  * Other minor code optimizations (like using cpus_clear instead of
    CPU_MASK_NONE, etc.)

Applies to linux-2.6.tip/master.

Signed-off-by: Mike Travis <travis@sgi.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Mike Travis committed Dec 17, 2008
1 parent 36f5101 commit e798673
Show file tree
Hide file tree
Showing 30 changed files with 380 additions and 273 deletions.
14 changes: 7 additions & 7 deletions arch/x86/include/asm/bigsmp/apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ static inline int apic_id_registered(void)
return (1);
}

static inline cpumask_t target_cpus(void)
static inline const cpumask_t *target_cpus(void)
{
#ifdef CONFIG_SMP
return cpu_online_map;
return &cpu_online_map;
#else
return cpumask_of_cpu(0);
return &cpumask_of_cpu(0);
#endif
}

Expand Down Expand Up @@ -79,7 +79,7 @@ static inline int apicid_to_node(int logical_apicid)

static inline int cpu_present_to_apicid(int mps_cpu)
{
if (mps_cpu < NR_CPUS)
if (mps_cpu < nr_cpu_ids)
return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);

return BAD_APICID;
Expand All @@ -94,7 +94,7 @@ extern u8 cpu_2_logical_apicid[];
/* Mapping from cpu number to logical apicid */
static inline int cpu_to_logical_apicid(int cpu)
{
if (cpu >= NR_CPUS)
if (cpu >= nr_cpu_ids)
return BAD_APICID;
return cpu_physical_id(cpu);
}
Expand All @@ -119,12 +119,12 @@ static inline int 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(cpumask_t cpumask)
static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
{
int cpu;
int apicid;

cpu = first_cpu(cpumask);
cpu = first_cpu(*cpumask);
apicid = cpu_to_logical_apicid(cpu);
return apicid;
}
Expand Down
9 changes: 5 additions & 4 deletions arch/x86/include/asm/bigsmp/ipi.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef __ASM_MACH_IPI_H
#define __ASM_MACH_IPI_H

void send_IPI_mask_sequence(cpumask_t mask, int vector);
void send_IPI_mask_sequence(const cpumask_t *mask, int vector);
void send_IPI_mask_allbutself(const cpumask_t *mask, int vector);

static inline void send_IPI_mask(cpumask_t mask, int vector)
static inline void send_IPI_mask(const cpumask_t *mask, int vector)
{
send_IPI_mask_sequence(mask, vector);
}
Expand All @@ -14,12 +15,12 @@ static inline void send_IPI_allbutself(int vector)
cpu_clear(smp_processor_id(), mask);

if (!cpus_empty(mask))
send_IPI_mask(mask, vector);
send_IPI_mask(&mask, vector);
}

static inline void send_IPI_all(int vector)
{
send_IPI_mask(cpu_online_map, vector);
send_IPI_mask(&cpu_online_map, vector);
}

#endif /* __ASM_MACH_IPI_H */
38 changes: 20 additions & 18 deletions arch/x86/include/asm/es7000/apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ static inline int apic_id_registered(void)
return (1);
}

static inline cpumask_t target_cpus_cluster(void)
static inline const cpumask_t *target_cpus_cluster(void)
{
return CPU_MASK_ALL;
return &CPU_MASK_ALL;
}

static inline cpumask_t target_cpus(void)
static inline const cpumask_t *target_cpus(void)
{
return cpumask_of_cpu(smp_processor_id());
return &cpumask_of_cpu(smp_processor_id());
}

#define APIC_DFR_VALUE_CLUSTER (APIC_DFR_CLUSTER)
Expand Down Expand Up @@ -80,9 +80,10 @@ extern int apic_version [MAX_APICS];
static inline void setup_apic_routing(void)
{
int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id());
printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
(apic_version[apic] == 0x14) ?
"Physical Cluster" : "Logical Cluster", nr_ioapics, cpus_addr(target_cpus())[0]);
"Physical Cluster" : "Logical Cluster",
nr_ioapics, cpus_addr(*target_cpus())[0]);
}

static inline int multi_timer_check(int apic, int irq)
Expand All @@ -100,7 +101,7 @@ static inline int cpu_present_to_apicid(int mps_cpu)
{
if (!mps_cpu)
return boot_cpu_physical_apicid;
else if (mps_cpu < NR_CPUS)
else if (mps_cpu < nr_cpu_ids)
return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
else
return BAD_APICID;
Expand All @@ -120,9 +121,9 @@ extern u8 cpu_2_logical_apicid[];
static inline int cpu_to_logical_apicid(int cpu)
{
#ifdef CONFIG_SMP
if (cpu >= NR_CPUS)
return BAD_APICID;
return (int)cpu_2_logical_apicid[cpu];
if (cpu >= nr_cpu_ids)
return BAD_APICID;
return (int)cpu_2_logical_apicid[cpu];
#else
return logical_smp_processor_id();
#endif
Expand All @@ -146,25 +147,26 @@ static inline int check_phys_apicid_present(int cpu_physical_apicid)
return (1);
}

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

num_bits_set = cpus_weight(cpumask);
num_bits_set = cpumask_weight(cpumask);
/* Return id to all */
if (num_bits_set == NR_CPUS)
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);
cpu = cpumask_first(cpumask);
apicid = cpu_to_logical_apicid(cpu);
while (cpus_found < num_bits_set) {
if (cpu_isset(cpu, cpumask)) {
if (cpumask_test_cpu(cpu, cpumask)) {
int new_apicid = cpu_to_logical_apicid(cpu);
if (apicid_cluster(apicid) !=
apicid_cluster(new_apicid)){
Expand All @@ -179,25 +181,25 @@ static inline unsigned int cpu_mask_to_apicid_cluster(cpumask_t cpumask)
return apicid;
}

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

num_bits_set = cpus_weight(cpumask);
num_bits_set = cpus_weight(*cpumask);
/* Return id to all */
if (num_bits_set == NR_CPUS)
return cpu_to_logical_apicid(0);
/*
* 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);
cpu = first_cpu(*cpumask);
apicid = cpu_to_logical_apicid(cpu);
while (cpus_found < num_bits_set) {
if (cpu_isset(cpu, cpumask)) {
if (cpu_isset(cpu, *cpumask)) {
int new_apicid = cpu_to_logical_apicid(cpu);
if (apicid_cluster(apicid) !=
apicid_cluster(new_apicid)){
Expand Down
9 changes: 5 additions & 4 deletions arch/x86/include/asm/es7000/ipi.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef __ASM_ES7000_IPI_H
#define __ASM_ES7000_IPI_H

void send_IPI_mask_sequence(cpumask_t mask, int vector);
void send_IPI_mask_sequence(const cpumask_t *mask, int vector);
void send_IPI_mask_allbutself(const cpumask_t *mask, int vector);

static inline void send_IPI_mask(cpumask_t mask, int vector)
static inline void send_IPI_mask(const cpumask_t *mask, int vector)
{
send_IPI_mask_sequence(mask, vector);
}
Expand All @@ -13,12 +14,12 @@ static inline void send_IPI_allbutself(int vector)
cpumask_t mask = cpu_online_map;
cpu_clear(smp_processor_id(), mask);
if (!cpus_empty(mask))
send_IPI_mask(mask, vector);
send_IPI_mask(&mask, vector);
}

static inline void send_IPI_all(int vector)
{
send_IPI_mask(cpu_online_map, vector);
send_IPI_mask(&cpu_online_map, vector);
}

#endif /* __ASM_ES7000_IPI_H */
9 changes: 5 additions & 4 deletions arch/x86/include/asm/genapic_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct genapic {
int (*probe)(void);

int (*apic_id_registered)(void);
cpumask_t (*target_cpus)(void);
const cpumask_t *(*target_cpus)(void);
int int_delivery_mode;
int int_dest_mode;
int ESR_DISABLE;
Expand Down Expand Up @@ -57,12 +57,13 @@ struct genapic {

unsigned (*get_apic_id)(unsigned long x);
unsigned long apic_id_mask;
unsigned int (*cpu_mask_to_apicid)(cpumask_t cpumask);
cpumask_t (*vector_allocation_domain)(int cpu);
unsigned int (*cpu_mask_to_apicid)(const cpumask_t *cpumask);
void (*vector_allocation_domain)(int cpu, cpumask_t *retmask);

#ifdef CONFIG_SMP
/* ipi */
void (*send_IPI_mask)(cpumask_t mask, int vector);
void (*send_IPI_mask)(const cpumask_t *mask, int vector);
void (*send_IPI_mask_allbutself)(const cpumask_t *mask, int vector);
void (*send_IPI_allbutself)(int vector);
void (*send_IPI_all)(int vector);
#endif
Expand Down
11 changes: 7 additions & 4 deletions arch/x86/include/asm/genapic_64.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _ASM_X86_GENAPIC_64_H
#define _ASM_X86_GENAPIC_64_H

#include <linux/cpumask.h>

/*
* Copyright 2004 James Cleverdon, IBM.
* Subject to the GNU Public License, v.2
Expand All @@ -18,16 +20,17 @@ struct genapic {
u32 int_delivery_mode;
u32 int_dest_mode;
int (*apic_id_registered)(void);
cpumask_t (*target_cpus)(void);
cpumask_t (*vector_allocation_domain)(int cpu);
const cpumask_t *(*target_cpus)(void);
void (*vector_allocation_domain)(int cpu, cpumask_t *retmask);
void (*init_apic_ldr)(void);
/* ipi */
void (*send_IPI_mask)(cpumask_t mask, int vector);
void (*send_IPI_mask)(const cpumask_t *mask, int vector);
void (*send_IPI_mask_allbutself)(const cpumask_t *mask, int vector);
void (*send_IPI_allbutself)(int vector);
void (*send_IPI_all)(int vector);
void (*send_IPI_self)(int vector);
/* */
unsigned int (*cpu_mask_to_apicid)(cpumask_t cpumask);
unsigned int (*cpu_mask_to_apicid)(const cpumask_t *cpumask);
unsigned int (*phys_pkg_id)(int index_msb);
unsigned int (*get_apic_id)(unsigned long x);
unsigned long (*set_apic_id)(unsigned int id);
Expand Down
21 changes: 19 additions & 2 deletions arch/x86/include/asm/ipi.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static inline void __send_IPI_dest_field(unsigned int mask, int vector,
native_apic_mem_write(APIC_ICR, cfg);
}

static inline void send_IPI_mask_sequence(cpumask_t mask, int vector)
static inline void send_IPI_mask_sequence(const cpumask_t *mask, int vector)
{
unsigned long flags;
unsigned long query_cpu;
Expand All @@ -128,11 +128,28 @@ static inline void send_IPI_mask_sequence(cpumask_t mask, int vector)
* - mbligh
*/
local_irq_save(flags);
for_each_cpu_mask_nr(query_cpu, mask) {
for_each_cpu_mask_nr(query_cpu, *mask) {
__send_IPI_dest_field(per_cpu(x86_cpu_to_apicid, query_cpu),
vector, APIC_DEST_PHYSICAL);
}
local_irq_restore(flags);
}

static inline void send_IPI_mask_allbutself(const cpumask_t *mask, int vector)
{
unsigned long flags;
unsigned int query_cpu;
unsigned int this_cpu = smp_processor_id();

/* See Hack comment above */

local_irq_save(flags);
for_each_cpu_mask_nr(query_cpu, *mask)
if (query_cpu != this_cpu)
__send_IPI_dest_field(
per_cpu(x86_cpu_to_apicid, query_cpu),
vector, APIC_DEST_PHYSICAL);
local_irq_restore(flags);
}

#endif /* _ASM_X86_IPI_H */
17 changes: 8 additions & 9 deletions arch/x86/include/asm/mach-default/mach_apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#define APIC_DFR_VALUE (APIC_DFR_FLAT)

static inline cpumask_t target_cpus(void)
static inline const cpumask_t *target_cpus(void)
{
#ifdef CONFIG_SMP
return cpu_online_map;
return &cpu_online_map;
#else
return cpumask_of_cpu(0);
return &cpumask_of_cpu(0);
#endif
}

Expand Down Expand Up @@ -61,9 +61,9 @@ static inline int apic_id_registered(void)
return physid_isset(read_apic_id(), phys_cpu_present_map);
}

static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
{
return cpus_addr(cpumask)[0];
return cpus_addr(*cpumask)[0];
}

static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
Expand All @@ -88,7 +88,7 @@ static inline int apicid_to_node(int logical_apicid)
#endif
}

static inline cpumask_t vector_allocation_domain(int cpu)
static inline void vector_allocation_domain(int cpu, cpumask_t *retmask)
{
/* Careful. Some cpus do not strictly honor the set of cpus
* specified in the interrupt destination when using lowest
Expand All @@ -98,8 +98,7 @@ static inline cpumask_t vector_allocation_domain(int cpu)
* deliver interrupts to the wrong hyperthread when only one
* hyperthread was specified in the interrupt desitination.
*/
cpumask_t domain = { { [0] = APIC_ALL_CPUS, } };
return domain;
*retmask = (cpumask_t) { { [0] = APIC_ALL_CPUS } };
}
#endif

Expand Down Expand Up @@ -131,7 +130,7 @@ static inline int cpu_to_logical_apicid(int cpu)

static inline int cpu_present_to_apicid(int mps_cpu)
{
if (mps_cpu < NR_CPUS && cpu_present(mps_cpu))
if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu))
return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
else
return BAD_APICID;
Expand Down
Loading

0 comments on commit e798673

Please sign in to comment.