On Sat, May 03, 2008 at 11:11:48AM -0700, Paul E. McKenney wrote:On the off-chance that the answer to the above question is "no", here is a crude patch on top of Jens's earlier patch. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> --- arch/Kconfig | 2 - kernel/smp.c | 107 ++++++++++++++++++----------------------------------------- 2 files changed, 34 insertions(+), 75 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index a5a0184..5ae9360 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -38,4 +38,4 @@ config HAVE_KRETPROBES def_bool n config USE_GENERIC_SMP_HELPERS - def_bool n + def_bool y diff --git a/kernel/smp.c b/kernel/smp.c index 36d3eca..d7e8dd1 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -17,7 +17,6 @@ __cacheline_aligned_in_smp DEFINE_SPINLOCK(call_function_lock); enum { CSD_FLAG_WAIT = 0x01, CSD_FLAG_ALLOC = 0x02, - CSD_FLAG_FALLBACK = 0x04, }; struct call_function_data { @@ -33,9 +32,6 @@ struct call_single_queue { spinlock_t lock; }; -static DEFINE_PER_CPU(struct call_function_data, cfd_fallback); -static DEFINE_PER_CPU(unsigned long, cfd_fallback_used); - void __cpuinit init_call_single_data(void) { int i; @@ -48,7 +44,7 @@ void __cpuinit init_call_single_data(void) } } -static void csd_flag_wait(struct call_single_data *data) +static void csd_flag_wait(struct call_single_data *data, int poll) { /* Wait for response */ do { @@ -59,6 +55,8 @@ static void csd_flag_wait(struct call_single_data *data) if (!(data->flags & CSD_FLAG_WAIT)) break; cpu_relax(); + if (poll) + generic_smp_call_function_interrupt(); } while (1); } @@ -66,7 +64,7 @@ static void csd_flag_wait(struct call_single_data *data) * Insert a previously allocated call_single_data element for execution * on the given CPU. data must already have ->func, ->info, and ->flags set. */ -static void generic_exec_single(int cpu, struct call_single_data *data) +static void generic_exec_single(int cpu, struct call_single_data *data, int poll) { struct call_single_queue *dst = &per_cpu(call_single_queue, cpu); int wait = data->flags & CSD_FLAG_WAIT, ipi; @@ -81,39 +79,7 @@ static void generic_exec_single(int cpu, struct call_single_data *data) arch_send_call_function_single_ipi(cpu); if (wait) - csd_flag_wait(data); -} - -/* - * We need to have a global per-cpu fallback of call_function_data, so - * we can safely proceed with smp_call_function() if dynamic allocation - * fails and we cannot fall back to on-stack allocation (if wait == 0). - */ -static noinline void acquire_cpu_fallback(int cpu) -{ - while (test_and_set_bit_lock(0, &per_cpu(cfd_fallback_used, cpu))) - cpu_relax(); -} - -static noinline void free_cpu_fallback(struct call_single_data *csd) -{ - struct call_function_data *data; - int cpu; - - data = container_of(csd, struct call_function_data, csd); - - /* - * We could drop this loop by embedding a cpu variable in - * csd, but this should happen so extremely rarely (if ever) - * that this seems like a better idea - */ - for_each_possible_cpu(cpu) { - if (&per_cpu(cfd_fallback, cpu) != data) - continue; - - clear_bit_unlock(0, &per_cpu(cfd_fallback_used, cpu)); - break; - } + csd_flag_wait(data, poll); } static void rcu_free_call_data(struct rcu_head *head) @@ -122,10 +88,7 @@ static void rcu_free_call_data(struct rcu_head *head) data = container_of(head, struct call_function_data, rcu_head); - if (data->csd.flags & CSD_FLAG_ALLOC) - kfree(data); - else - free_cpu_fallback(&data->csd); + kfree(data); } /* @@ -222,8 +185,6 @@ void generic_smp_call_function_single_interrupt(void) data->flags &= ~CSD_FLAG_WAIT; } else if (data_flags & CSD_FLAG_ALLOC) kfree(data); - else if (data_flags & CSD_FLAG_FALLBACK) - free_cpu_fallback(data); } /* * See comment on outer loop @@ -244,40 +205,39 @@ void generic_smp_call_function_single_interrupt(void) int smp_call_function_single(int cpu, void (*func) (void *info), void *info, int retry, int wait) { + struct call_single_data d; unsigned long flags; /* prevent preemption and reschedule on another processor */ int me = get_cpu(); + int irqsdisabled = irqs_disabled(); /* Can deadlock when called with interrupts disabled */ - WARN_ON(wait && irqs_disabled()); + WARN_ON(wait && irqsdisabled); if (cpu == me) { local_irq_save(flags); func(info); local_irq_restore(flags); } else { - struct call_single_data *data; - - if (wait) { - struct call_single_data d; + struct call_single_data *data = NULL; - data = &d; - data->flags = CSD_FLAG_WAIT; - } else { + if (!wait) { data = kmalloc(sizeof(*data), GFP_ATOMIC); if (data) data->flags = CSD_FLAG_ALLOC; - else { - acquire_cpu_fallback(me); - - data = &per_cpu(cfd_fallback, me).csd; - data->flags = CSD_FLAG_FALLBACK; + } + if (!data) { + if (irqsdisabled) { + put_cpu(); + return -ENOMEM; } + data = &d; + data->flags = CSD_FLAG_WAIT; } data->func = func; data->info = info; - generic_exec_single(cpu, data); + generic_exec_single(cpu, data, !irqsdisabled); } put_cpu(); @@ -300,7 +260,7 @@ void __smp_call_function_single(int cpu, struct call_single_data *data) /* Can deadlock when called with interrupts disabled */ WARN_ON((data->flags & CSD_FLAG_WAIT) && irqs_disabled()); - generic_exec_single(cpu, data); + generic_exec_single(cpu, data, !irqs_disabled()); } /** @@ -320,13 +280,15 @@ void __smp_call_function_single(int cpu, struct call_single_data *data) int smp_call_function_mask(cpumask_t mask, void (*func)(void *), void *info, int wait) { - struct call_function_data *data; + struct call_function_data d; + struct call_function_data *data = NULL; cpumask_t allbutself; unsigned long flags; int cpu, num_cpus; + int irqsdisabled = irqs_disabled(); /* Can deadlock when called with interrupts disabled */ - WARN_ON(wait && irqs_disabled()); + WARN_ON(wait && irqsdisabled); cpu = smp_processor_id(); allbutself = cpu_online_map; @@ -345,21 +307,18 @@ int smp_call_function_mask(cpumask_t mask, void (*func)(void *), void *info, return smp_call_function_single(cpu, func, info, 0, wait); } - if (wait) { - struct call_function_data d; - - data = &d; - data->csd.flags = CSD_FLAG_WAIT; - } else { + if (!wait) { data = kmalloc(sizeof(*data), GFP_ATOMIC); if (data) data->csd.flags = CSD_FLAG_ALLOC; - else { - acquire_cpu_fallback(cpu); - - data = &per_cpu(cfd_fallback, cpu); - data->csd.flags = CSD_FLAG_FALLBACK; + } + if (!data) { + if (unlikely(irqsdisabled)) { + put_cpu(); + return -ENOMEM; } + data = &d; + data->csd.flags = CSD_FLAG_WAIT; } spin_lock_init(&data->lock); @@ -382,7 +341,7 @@ int smp_call_function_mask(cpumask_t mask, void (*func)(void *), void *info, /* optionally wait for the CPUs to complete */ if (wait) - csd_flag_wait(&data->csd); + csd_flag_wait(&data->csd, !irqsdisabled); return 0; } --
| Bart Van Assche | Integration of SCST in the mainstream Linux kernel |
| Linus Torvalds | Linux 2.6.27-rc5 |
| Jared Hulbert | [PATCH 00/10] AXFS: Advanced XIP filesystem |
| Linus Torvalds | Linux 2.6.27-rc8 |
git: | |
| David Miller | [GIT]: Networking |
| Antonio Almeida | HTB accuracy for high speed |
| Gerrit Renker | [PATCH 27/37] dccp: Integration of dynamic feature activation - part 2 (server side) |
| David Miller | Re: [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
