From: Juergen Gross <jgross@suse.com>
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 <jgross@suse.com>
Subject: [PATCH 5/6] virt, sched: add cpu pinning to call_sync_on_phys_cpu()
Date: Fri, 11 Mar 2016 12:59:33 +0100 [thread overview]
Message-ID: <1457697574-6710-6-git-send-email-jgross@suse.com> (raw)
In-Reply-To: <1457697574-6710-1-git-send-email-jgross@suse.com>
Add generic virtualization support for pinning the current vcpu to a
specified physical cpu. As this operation isn't performance critical
(a very limited set of operations like BIOS calls and SMIs is expected
to need this) just add a hypervisor specific indirection.
Such a pinning should last as short as possible as it might block
sensible vcpu scheduling and maybe other hypervisor functions like
suspending the system which rely on scheduling. To ensure this don't
let the current thread be preempted while the vcpu is pinned in
call_sync_on_phys_cpu().
Signed-off-by: Juergen Gross <jgross@suse.com>
---
arch/x86/include/asm/hypervisor.h | 9 +++++++++
include/linux/sched.h | 24 +++++++++++++++++++++++-
kernel/sched/core.c | 4 ++++
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h
index 055ea99..13f80a2 100644
--- a/arch/x86/include/asm/hypervisor.h
+++ b/arch/x86/include/asm/hypervisor.h
@@ -43,6 +43,9 @@ struct hypervisor_x86 {
/* X2APIC detection (run once per boot) */
bool (*x2apic_available)(void);
+
+ /* pin current vcpu to specified physical cpu (run rarely) */
+ void (*pin_vcpu)(int);
};
extern const struct hypervisor_x86 *x86_hyper;
@@ -56,6 +59,12 @@ extern const struct hypervisor_x86 x86_hyper_kvm;
extern void init_hypervisor(struct cpuinfo_x86 *c);
extern void init_hypervisor_platform(void);
extern bool hypervisor_x2apic_available(void);
+
+static inline void hypervisor_pin_vcpu(int cpu)
+{
+ if (x86_hyper->pin_vcpu)
+ x86_hyper->pin_vcpu(cpu);
+}
#else
static inline void init_hypervisor(struct cpuinfo_x86 *c) { }
static inline void init_hypervisor_platform(void) { }
diff --git a/include/linux/sched.h b/include/linux/sched.h
index dfadf1a..53b33d5 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -61,6 +61,9 @@ struct sched_param {
#include <linux/cgroup-defs.h>
#include <asm/processor.h>
+#ifdef CONFIG_HYPERVISOR_GUEST
+#include <asm/hypervisor.h>
+#endif
#define SCHED_ATTR_SIZE_VER0 48 /* sizeof first published struct */
@@ -2230,6 +2233,17 @@ static inline void rcu_copy_process(struct task_struct *p)
#endif /* #ifdef CONFIG_TASKS_RCU */
}
+#ifdef CONFIG_HYPERVISOR_GUEST
+static inline void pin_vcpu(int cpu)
+{
+ hypervisor_pin_vcpu(cpu);
+}
+#else
+static inline void pin_vcpu(int cpu)
+{
+}
+#endif
+
static inline void tsk_restore_flags(struct task_struct *task,
unsigned long orig_flags, unsigned long flags)
{
@@ -2263,10 +2277,18 @@ static inline int set_cpus_allowed_ptr(struct task_struct *p,
static inline int call_sync_on_phys_cpu(unsigned cpu, int (*func)(void *),
void *par)
{
+ int ret;
+
if (cpu != 0)
return -EINVAL;
- return func(par);
+ preempt_disable();
+ pin_vcpu(0);
+ ret = func(par);
+ pin_vcpu(-1);
+ preempt_enable();
+
+ return ret;
}
#endif
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index cb9955f..2dc27ca 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1281,7 +1281,11 @@ int call_sync_on_phys_cpu(unsigned cpu, int (*func)(void *), void *par)
if (ret)
goto out;
+ preempt_disable();
+ pin_vcpu(cpu);
ret = func(par);
+ pin_vcpu(-1);
+ preempt_enable();
set_cpus_allowed_ptr(current, old_mask);
--
2.6.2
next prev parent reply other threads:[~2016-03-11 12:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-11 11:59 [PATCH 0/6] Support calling functions on dedicated physical cpu Juergen Gross
2016-03-11 11:59 ` [PATCH 1/6] xen: sync xen header Juergen Gross
2016-03-11 11:59 ` [PATCH 2/6] sched: add function to execute a function synchronously on a physical cpu Juergen Gross
2016-03-11 12:19 ` Peter Zijlstra
2016-03-11 12:42 ` Peter Zijlstra
2016-03-11 12:48 ` Juergen Gross
2016-03-11 12:57 ` Peter Zijlstra
2016-03-11 13:07 ` Juergen Gross
2016-03-11 12:43 ` Juergen Gross
2016-03-11 12:45 ` Peter Zijlstra
2016-03-11 11:59 ` [PATCH 3/6] dcdbas: make use of call_sync_on_phys_cpu() Juergen Gross
2016-03-11 11:59 ` [PATCH 4/6] hwmon: use call_sync_on_phys_cpu() for dell-smm i8k Juergen Gross
2016-03-11 11:59 ` Juergen Gross [this message]
2016-03-11 11:59 ` [PATCH 6/6] xen: add xen_pin_vcpu() to support calling functions on a dedicated pcpu Juergen Gross
2016-03-11 12:25 ` [PATCH 0/6] Support calling functions on dedicated physical cpu Peter Zijlstra
2016-03-11 12:28 ` Pali Rohár
2016-03-11 13:15 ` One Thousand Gnomes
2016-03-11 13:19 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457697574-6710-6-git-send-email-jgross@suse.com \
--to=jgross@suse.com \
--cc=Douglas_Warzecha@dell.com \
--cc=boris.ostrovsky@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=hpa@zytor.com \
--cc=jdelvare@suse.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mingo@redhat.com \
--cc=pali.rohar@gmail.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox