From patchwork Tue Nov 17 22:27:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 60805 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAHMU4Za027087 for ; Tue, 17 Nov 2009 22:30:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756441AbZKQW3V (ORCPT ); Tue, 17 Nov 2009 17:29:21 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756439AbZKQW3U (ORCPT ); Tue, 17 Nov 2009 17:29:20 -0500 Received: from smtp1.linux-foundation.org ([140.211.169.13]:42346 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756437AbZKQW3R (ORCPT ); Tue, 17 Nov 2009 17:29:17 -0500 Received: from imap1.linux-foundation.org (imap1.linux-foundation.org [140.211.169.55]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id nAHMRS1r015082 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 17 Nov 2009 14:27:29 -0800 Received: from localhost.localdomain (localhost [127.0.0.1]) by imap1.linux-foundation.org (8.13.5.20060308/8.13.5/Debian-3ubuntu1.1) with ESMTP id nAHMRR3j023114; Tue, 17 Nov 2009 14:27:27 -0800 Message-Id: <200911172227.nAHMRR3j023114@imap1.linux-foundation.org> Subject: [patch 01/12] kernel core: add smp_call_function_any() To: lenb@kernel.org Cc: linux-acpi@vger.kernel.org, akpm@linux-foundation.org, rusty@rustcorp.com.au, davej@redhat.com, efault@gmx.de, jaswinder@kernel.org, len.brown@intel.com, mingo@elte.hu, tglx@linutronix.de, venkatesh.pallipadi@intel.com, yakui.zhao@intel.com, yanmin_zhang@linux.intel.com From: akpm@linux-foundation.org Date: Tue, 17 Nov 2009 14:27:27 -0800 MIME-Version: 1.0 X-Spam-Status: No, hits=-3.518 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.13 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org diff -puN include/linux/smp.h~kernel-core-add-smp_call_function_any include/linux/smp.h --- a/include/linux/smp.h~kernel-core-add-smp_call_function_any +++ a/include/linux/smp.h @@ -27,6 +27,9 @@ extern unsigned int total_cpus; int smp_call_function_single(int cpuid, void (*func) (void *info), void *info, int wait); +int smp_call_function_any(const struct cpumask *mask, + void (*func)(void *info), void *info, int wait); + #ifdef CONFIG_SMP #include diff -puN kernel/smp.c~kernel-core-add-smp_call_function_any kernel/smp.c --- a/kernel/smp.c~kernel-core-add-smp_call_function_any +++ a/kernel/smp.c @@ -319,6 +319,46 @@ int smp_call_function_single(int cpu, vo } EXPORT_SYMBOL(smp_call_function_single); +/* + * smp_call_function_any - Run a function on any of the given cpus + * @mask: The mask of cpus it can run on. + * @func: The function to run. This must be fast and non-blocking. + * @info: An arbitrary pointer to pass to the function. + * @wait: If true, wait until function has completed. + * + * Returns 0 on success, else a negative status code (if no cpus were online). + * Note that @wait will be implicitly turned on in case of allocation failures, + * since we fall back to on-stack allocation. + */ +int smp_call_function_any(const struct cpumask *mask, + void (*func)(void *info), void *info, int wait) +{ + unsigned int cpu; + const struct cpumask *nodemask; + int ret; + + /* Try for same CPU (cheapest) */ + cpu = get_cpu(); + if (cpumask_test_cpu(cpu, mask)) + goto call; + + /* Try for same node. */ + nodemask = cpumask_of_node(cpu); + for (cpu = cpumask_first_and(nodemask, mask); cpu < nr_cpu_ids; + cpu = cpumask_next_and(cpu, nodemask, mask)) { + if (cpu_online(cpu)) + goto call; + } + + /* Any online will do: smp_call_function_single handles nr_cpu_ids. */ + cpu = cpumask_any_and(mask, cpu_online_mask); +call: + ret = smp_call_function_single(cpu, func, info, wait); + put_cpu(); + return ret; +} +EXPORT_SYMBOL_GPL(smp_call_function_any); + /** * __smp_call_function_single(): Run a function on another CPU * @cpu: The CPU to run on. diff -puN kernel/up.c~kernel-core-add-smp_call_function_any kernel/up.c --- a/kernel/up.c~kernel-core-add-smp_call_function_any +++ a/kernel/up.c @@ -19,3 +19,15 @@ int smp_call_function_single(int cpu, vo return 0; } EXPORT_SYMBOL(smp_call_function_single); + +int smp_call_function_any(const struct cpumask *mask, + void (*func)(void *info), void *info, + int wait) +{ + local_irq_disable(); + (func)(info); + local_irq_enable(); + + return 0; +} +EXPORT_SYMBOL_GPL(smp_call_function_any);