From: Henrik Austad <[email protected]>

This allows userspace to set the forced CPU via sysfs in
/sys/kernel/timekeeping/forced_cpu.

CC: Thomas Gleixner <[email protected]>
CC: Peter Zijlstra <[email protected]>
CC: Frederic Weisbecker <[email protected]>
CC: John Stultz <[email protected]>
CC: Paul E. McKenney <[email protected]>
Signed-off-by: Henrik Austad <[email protected]>
---
 kernel/time/timekeeping.c |   36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 4bdfa11..b148062 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -44,23 +44,47 @@ int expose_tick_forced_timer_cpu = -1;
 /*
  * sysfs interface to timer-cpu
  */
-static ssize_t current_cpu_show(struct kobject *kobj,
-                               struct kobj_attribute *attr,
-                               char *buf)
-{
-       return sprintf(buf, "%d\n", tick_expose_cpu());
+static ssize_t cpu_show(struct kobject *kobj,
+                       struct kobj_attribute *attr,
+                       char *buf)
+{
+       int var = -EINVAL;
+       if (strcmp(attr->attr.name, "current_cpu") == 0)
+               var = sprintf(buf, "%d\n", tick_expose_cpu());
+       else if (strcmp(attr->attr.name, "forced_cpu") == 0)
+               var = sprintf(buf, "%d\n", tick_get_forced_cpu());
+       return var;
+}
+
+static ssize_t cpu_store(struct kobject *kobj,
+                       struct kobj_attribute *attr,
+                       const char * buf,
+                       size_t count)
+{
+       int var = 0;
+       if (strcmp(attr->attr.name, "forced_cpu") == 0) {
+               sscanf(buf, "%du", &var);
+               if ((var = tick_set_forced_cpu(var)) != 0) {
+                       pr_err("trouble setting forced CPU (%d)\n", var);
+               }
+       }
+       return count;
 }
 
 static struct kobj_attribute current_cpu_attribute =
-       __ATTR_RO(current_cpu);
+       __ATTR(current_cpu, 0444, cpu_show, NULL);
+static struct kobj_attribute forced_cpu_attribute =
+       __ATTR(forced_cpu, 0644, cpu_show, cpu_store);
 
 static struct attribute *timekeeping_attrs[] = {
        &current_cpu_attribute.attr,
+       &forced_cpu_attribute.attr,
        NULL,
 };
 static struct attribute_group timekeeping_ag = {
        .attrs = timekeeping_attrs,
 };
+
 static struct kobject *timekeeping_kobj;
 
 static __init int timekeeping_sysfs_init(void)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to