cpuquiet: Add Sysfs node for nr_run_thresholds
authorSai Gurrappadi <sgurrappadi@nvidia.com>
Fri, 20 Dec 2013 00:30:02 +0000 (16:30 -0800)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 18 May 2015 08:07:12 +0000 (16:07 +0800)
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 <sgurrappadi@nvidia.com>
Reviewed-on: http://git-master/r/369017
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
drivers/cpuquiet/governors/runnable_threads.c

index 77ce4b88566b4191c4ab46d6f729012fb155a069..f670d1a1aec57b1b5a63fc678aaa26b4d4e4464c 100644 (file)
@@ -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,
 };