lkml.org 
[lkml]   [2014]   [Feb]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 6/6] Expose tick_set_forced_cpu() via sysfs
Date
From: Henrik Austad <haustad@cisco.com>

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

CC: Thomas Gleixner <tglx@linutronix.de>
CC: Peter Zijlstra <peterz@infradead.org>
CC: Frederic Weisbecker <fweisbec@gmail.com>
CC: John Stultz <john.stultz@linaro.org>
CC: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Henrik Austad <haustad@cisco.com>
---
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


\
 
 \ /
  Last update: 2014-02-25 16:01    [W:0.137 / U:4.588 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site