[PATCH 6/6] Expose tick_set_forced_cpu() via sysfs

From: Henrik Austad
Date: Tue Feb 25 2014 - 07:37:47 EST


From: Henrik Austad <haustad@xxxxxxxxx>

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

CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CC: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CC: Frederic Weisbecker <fweisbec@xxxxxxxxx>
CC: John Stultz <john.stultz@xxxxxxxxxx>
CC: Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Henrik Austad <haustad@xxxxxxxxx>
---
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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/