From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752551AbcCKL7y (ORCPT ); Fri, 11 Mar 2016 06:59:54 -0500 Received: from mx2.suse.de ([195.135.220.15]:35447 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752086AbcCKL7k (ORCPT ); Fri, 11 Mar 2016 06:59:40 -0500 From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, david.vrabel@citrix.com, mingo@redhat.com, peterz@infradead.org, Douglas_Warzecha@dell.com, pali.rohar@gmail.com, jdelvare@suse.com, linux@roeck-us.net, tglx@linutronix.de, hpa@zytor.com, x86@kernel.org, Juergen Gross Subject: [PATCH 2/6] sched: add function to execute a function synchronously on a physical cpu Date: Fri, 11 Mar 2016 12:59:30 +0100 Message-Id: <1457697574-6710-3-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1457697574-6710-1-git-send-email-jgross@suse.com> References: <1457697574-6710-1-git-send-email-jgross@suse.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On some hardware models (e.g. Dell Studio 1555 laptop) some hardware related functions (e.g. SMIs) are to be executed on physical cpu 0 only. Instead of open coding such a functionality multiple times in the kernel add a service function for this purpose. This will enable the possibility to take special measures in virtualized environments like Xen, too. Signed-off-by: Juergen Gross --- include/linux/sched.h | 9 +++++++++ kernel/sched/core.c | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index a10494a..dfadf1a 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2247,6 +2247,7 @@ extern void do_set_cpus_allowed(struct task_struct *p, extern int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask); +int call_sync_on_phys_cpu(unsigned cpu, int (*func)(void *), void *par); #else static inline void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask) @@ -2259,6 +2260,14 @@ static inline int set_cpus_allowed_ptr(struct task_struct *p, return -EINVAL; return 0; } +static inline int call_sync_on_phys_cpu(unsigned cpu, int (*func)(void *), + void *par) +{ + if (cpu != 0) + return -EINVAL; + + return func(par); +} #endif #ifdef CONFIG_NO_HZ_COMMON diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 41f6b22..cb9955f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1265,6 +1265,32 @@ int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) } EXPORT_SYMBOL_GPL(set_cpus_allowed_ptr); +int call_sync_on_phys_cpu(unsigned cpu, int (*func)(void *), void *par) +{ + cpumask_var_t old_mask; + int ret; + + if (cpu >= nr_cpu_ids) + return -EINVAL; + + if (!alloc_cpumask_var(&old_mask, GFP_KERNEL)) + return -ENOMEM; + + cpumask_copy(old_mask, ¤t->cpus_allowed); + ret = set_cpus_allowed_ptr(current, cpumask_of(cpu)); + if (ret) + goto out; + + ret = func(par); + + set_cpus_allowed_ptr(current, old_mask); + +out: + free_cpumask_var(old_mask); + return ret; +} +EXPORT_SYMBOL_GPL(call_sync_on_phys_cpu); + void set_task_cpu(struct task_struct *p, unsigned int new_cpu) { #ifdef CONFIG_SCHED_DEBUG -- 2.6.2