[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/6] sched: add function to execute a function synchronously on a physical cpu



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 <jgross@xxxxxxxx>
---
 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, &current->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


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.