From b9cd6df05385341b4aaed46bcdf42203754d8048 Mon Sep 17 00:00:00 2001 From: Sai Gurrappadi Date: Thu, 19 Dec 2013 16:30:02 -0800 Subject: [PATCH] cpuquiet: Add Sysfs node for nr_run_thresholds Added sysfs node that exposes the nr_runnable threshold at which cores are quiesenced/woken up. To write into this node: echo 1core# 2core# ... n_core# > nr_run_thresholds Bug 1427140 Change-Id: I7cabd63692cf92f7fe8d1064437b1d73002d4ba5 Signed-off-by: Sai Gurrappadi Reviewed-on: http://git-master/r/369017 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Diwakar Tundlam --- drivers/cpuquiet/governors/runnable_threads.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/cpuquiet/governors/runnable_threads.c b/drivers/cpuquiet/governors/runnable_threads.c index 77ce4b88566b..f670d1a1aec5 100644 --- a/drivers/cpuquiet/governors/runnable_threads.c +++ b/drivers/cpuquiet/governors/runnable_threads.c @@ -198,12 +198,63 @@ static void runnables_work_func(struct work_struct *work) } } +#define MAX_BYTES 100 + +static ssize_t show_thresholds(struct cpuquiet_attribute *attr, char *buf) +{ + char buffer[MAX_BYTES]; + unsigned int i; + int size = 0; + buffer[0] = 0; + for_each_possible_cpu(i) { + if (i == ARRAY_SIZE(nr_run_thresholds) - 1) + break; + if (size >= sizeof(buffer)) + break; + size += snprintf(buffer + size, sizeof(buffer) - size, + "%u->%u core threshold: %u\n", + i + 1, i + 2, nr_run_thresholds[i]); + } + return snprintf(buf, sizeof(buffer), "%s", buffer); +} + +static ssize_t store_thresholds(struct cpuquiet_attribute *attr, + const char *buf, size_t count) +{ + int ret, i = 0; + char *val, *str, input[MAX_BYTES]; + unsigned int thresholds[NR_CPUS]; + + if (!count || count >= MAX_BYTES) + return -EINVAL; + strncpy(input, buf, count); + input[count] = '\0'; + str = input; + memcpy(thresholds, nr_run_thresholds, sizeof(nr_run_thresholds)); + while ((val = strsep(&str, " ")) != NULL) { + if (*val == '\0') + continue; + if (i == ARRAY_SIZE(nr_run_thresholds) - 1) + break; + ret = kstrtouint(val, 10, &thresholds[i]); + if (ret) + return -EINVAL; + i++; + } + + memcpy(nr_run_thresholds, thresholds, sizeof(thresholds)); + return count; +} + CPQ_BASIC_ATTRIBUTE(sample_rate, 0644, uint); CPQ_BASIC_ATTRIBUTE(nr_run_hysteresis, 0644, uint); +CPQ_ATTRIBUTE_CUSTOM(nr_run_thresholds, 0644, + show_thresholds, store_thresholds); static struct attribute *runnables_attributes[] = { &sample_rate_attr.attr, &nr_run_hysteresis_attr.attr, + &nr_run_thresholds_attr.attr, NULL, }; -- 2.34.1