From patchwork Fri Mar 11 11:59:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 8565201 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BE5399F6E4 for ; Fri, 11 Mar 2016 12:02:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E3E8D20165 for ; Fri, 11 Mar 2016 12:02:38 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C64320340 for ; Fri, 11 Mar 2016 12:02:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aeLjJ-0004d4-U7; Fri, 11 Mar 2016 11:59:41 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aeLjI-0004c2-HB for xen-devel@lists.xenproject.org; Fri, 11 Mar 2016 11:59:40 +0000 Received: from [85.158.139.211] by server-4.bemta-5.messagelabs.com id 45/89-10867-B23B2E65; Fri, 11 Mar 2016 11:59:39 +0000 X-Env-Sender: jgross@suse.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1457697579!28054291!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 62088 invoked from network); 11 Mar 2016 11:59:39 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-6.tower-206.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 11 Mar 2016 11:59:39 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7354EABED; Fri, 11 Mar 2016 11:59:37 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org 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> Cc: Juergen Gross , jdelvare@suse.com, peterz@infradead.org, hpa@zytor.com, x86@kernel.org, mingo@redhat.com, david.vrabel@citrix.com, Douglas_Warzecha@dell.com, pali.rohar@gmail.com, boris.ostrovsky@oracle.com, tglx@linutronix.de, linux@roeck-us.net Subject: [Xen-devel] [PATCH 2/6] sched: add function to execute a function synchronously on a physical cpu X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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