diff options
author | Julien Grall <julien.grall@citrix.com> | 2013-05-07 12:05:06 +0100 |
---|---|---|
committer | Ian Campbell <ian.campbell@citrix.com> | 2013-05-08 11:06:22 +0100 |
commit | 68385d841171d46985e2c41d751a2b81b3b3813b (patch) | |
tree | d7b97fc50ff811a134e804c29803aa88a354c1f6 /xen/common/smp.c | |
parent | a32dbcef6d917e6019e2a5a1467276a555d7ec34 (diff) | |
download | xen-68385d841171d46985e2c41d751a2b81b3b3813b.tar.gz xen-68385d841171d46985e2c41d751a2b81b3b3813b.tar.bz2 xen-68385d841171d46985e2c41d751a2b81b3b3813b.zip |
xen/arm: implement smp_call_function
Move smp_call_function and on_selected_cpus to common code.
Signed-off-by: Julien Grall <julien.grall@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
Diffstat (limited to 'xen/common/smp.c')
-rw-r--r-- | xen/common/smp.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/xen/common/smp.c b/xen/common/smp.c new file mode 100644 index 0000000000..b2b056b5e5 --- /dev/null +++ b/xen/common/smp.c @@ -0,0 +1,112 @@ +/* + * xen/common/smp.c + * + * Generic SMP function + * + * Copyright (c) 2013 Citrix Systems. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <asm/hardirq.h> +#include <asm/processor.h> +#include <xen/spinlock.h> +#include <xen/smp.h> + +/* + * Structure and data for smp_call_function()/on_selected_cpus(). + */ +static DEFINE_SPINLOCK(call_lock); +static struct call_data_struct { + void (*func) (void *info); + void *info; + int wait; + cpumask_t selected; +} call_data; + +void smp_call_function( + void (*func) (void *info), + void *info, + int wait) +{ + cpumask_t allbutself; + + cpumask_andnot(&allbutself, &cpu_online_map, + cpumask_of(smp_processor_id())); + on_selected_cpus(&allbutself, func, info, wait); +} + +void on_selected_cpus( + const cpumask_t *selected, + void (*func) (void *info), + void *info, + int wait) +{ + unsigned int nr_cpus; + + ASSERT(local_irq_is_enabled()); + + spin_lock(&call_lock); + + cpumask_copy(&call_data.selected, selected); + + nr_cpus = cpumask_weight(&call_data.selected); + if ( nr_cpus == 0 ) + goto out; + + call_data.func = func; + call_data.info = info; + call_data.wait = wait; + + smp_send_call_function_mask(&call_data.selected); + + while ( !cpumask_empty(&call_data.selected) ) + cpu_relax(); + +out: + spin_unlock(&call_lock); +} + +void smp_call_function_interrupt(void) +{ + void (*func)(void *info) = call_data.func; + void *info = call_data.info; + unsigned int cpu = smp_processor_id(); + + if ( !cpumask_test_cpu(cpu, &call_data.selected) ) + return; + + irq_enter(); + + if ( call_data.wait ) + { + (*func)(info); + mb(); + cpumask_clear_cpu(cpu, &call_data.selected); + } + else + { + mb(); + cpumask_clear_cpu(cpu, &call_data.selected); + (*func)(info); + } + + irq_exit(); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ |