sched: ems: seperate task util initiialization
authorPark Bumgyu <bumgyu.park@samsung.com>
Fri, 6 Apr 2018 05:41:30 +0000 (14:41 +0900)
committerChungwoo Park <cww.park@samsung.com>
Mon, 21 May 2018 08:35:34 +0000 (17:35 +0900)
Seperate code related to task util initialization to facilitate
code management.

Change-Id: I86244fe3169467b74baca6a34b968ef04c495586
Signed-off-by: Park Bumgyu <bumgyu.park@samsung.com>
kernel/sched/ems/Makefile
kernel/sched/ems/core.c
kernel/sched/ems/ehmp.c
kernel/sched/ems/init_util.c [new file with mode: 0644]

index 2b53ebfdf9bf7ea76389f0677b1ce49a44692242..0e9bcde00f14eaba04795f1f2e651660a157a12b 100644 (file)
@@ -1,4 +1,4 @@
-obj-y += core.o pcf.o global_boost.o lbt.o ontime.o energy.o
+obj-y += core.o pcf.o global_boost.o lbt.o ontime.o energy.o init_util.o
 
 obj-$(CONFIG_SCHED_TUNE) += st_addon.o
 obj-$(CONFIG_SCHED_EMS) += ehmp.o
index c464588e7090d2b3fc9b6dd542b25452f5334364..29bb9a38eb18ff7e7512eb0b814350f70f5ff8d6 100644 (file)
@@ -11,8 +11,6 @@
 #include "ems.h"
 #include "../sched.h"
 
-#define cpu_selected(cpu)      (cpu >= 0)
-
 static int select_proper_cpu(struct task_struct *p)
 {
        return -1;
index 35068add52124de684fe4dbee3b373703980eeef..6d91108f6aa483e71a8c6a49a6255a29ca7ffb65 100644 (file)
@@ -106,119 +106,6 @@ int exynos_estimate_idle_state(int cpu_idx, struct cpumask *mask,
        return estimate_state;
 }
 
-/**********************************************************************
- * task initialization                                                *
- **********************************************************************/
-enum {
-       TYPE_BASE_CFS_RQ_UTIL = 0,
-       TYPE_BASE_INHERIT_PARENT_UTIL,
-       TYPE_MAX_NUM,
-};
-
-static unsigned long init_util_type = TYPE_BASE_CFS_RQ_UTIL;
-static unsigned long init_util_ratio = 25;                     /* 25% */
-
-static ssize_t show_initial_util_type(struct kobject *kobj,
-               struct kobj_attribute *attr, char *buf)
-{
-        return snprintf(buf, 10, "%ld\n", init_util_type);
-}
-
-static ssize_t store_initial_util_type(struct kobject *kobj,
-                struct kobj_attribute *attr, const char *buf,
-                size_t count)
-{
-        long input;
-
-        if (!sscanf(buf, "%ld", &input))
-                return -EINVAL;
-
-        input = input < 0 ? 0 : input;
-        input = input >= TYPE_MAX_NUM ? TYPE_MAX_NUM - 1 : input;
-
-        init_util_type = input;
-
-        return count;
-}
-
-static ssize_t show_initial_util_ratio(struct kobject *kobj,
-               struct kobj_attribute *attr, char *buf)
-{
-        return snprintf(buf, 10, "%ld\n", init_util_ratio);
-}
-
-static ssize_t store_initial_util_ratio(struct kobject *kobj,
-                struct kobj_attribute *attr, const char *buf,
-                size_t count)
-{
-        long input;
-
-        if (!sscanf(buf, "%ld", &input))
-                return -EINVAL;
-
-        init_util_ratio = !!input;
-
-        return count;
-}
-
-static struct kobj_attribute initial_util_type =
-__ATTR(initial_util_type, 0644, show_initial_util_type, store_initial_util_type);
-
-static struct kobj_attribute initial_util_ratio =
-__ATTR(initial_util_ratio, 0644, show_initial_util_ratio, store_initial_util_ratio);
-
-void base_cfs_rq_util(struct sched_entity *se)
-{
-       struct cfs_rq *cfs_rq = se->cfs_rq;
-       struct sched_avg *sa = &se->avg;
-       int cpu = cpu_of(cfs_rq->rq);
-       unsigned long cap_org = capacity_orig_of(cpu);
-       long cap = (long)(cap_org - cfs_rq->avg.util_avg) / 2;
-
-       if (cap > 0) {
-               if (cfs_rq->avg.util_avg != 0) {
-                       sa->util_avg  = cfs_rq->avg.util_avg * se->load.weight;
-                       sa->util_avg /= (cfs_rq->avg.load_avg + 1);
-
-                       if (sa->util_avg > cap)
-                               sa->util_avg = cap;
-               } else {
-                       sa->util_avg = cap_org * init_util_ratio / 100;
-               }
-               /*
-                * If we wish to restore tuning via setting initial util,
-                * this is where we should do it.
-                */
-               sa->util_sum = sa->util_avg * LOAD_AVG_MAX;
-       }
-}
-
-void base_inherit_parent_util(struct sched_entity *se)
-{
-       struct sched_avg *sa = &se->avg;
-       struct task_struct *p = current;
-
-       sa->util_avg = p->se.avg.util_avg;
-       sa->util_sum = p->se.avg.util_sum;
-}
-
-void exynos_init_entity_util_avg(struct sched_entity *se)
-{
-       int type = init_util_type;
-
-       switch(type) {
-       case TYPE_BASE_CFS_RQ_UTIL:
-               base_cfs_rq_util(se);
-               break;
-       case TYPE_BASE_INHERIT_PARENT_UTIL:
-               base_inherit_parent_util(se);
-               break;
-       default:
-               pr_info("%s: Not support initial util type %ld\n",
-                               __func__, init_util_type);
-       }
-}
-
 /**********************************************************************
  * load balance                                                       *
  **********************************************************************/
@@ -861,8 +748,6 @@ exit:
 static struct attribute *ehmp_attrs[] = {
        &global_boost_attr.attr,
        &prefer_perf_attr.attr,
-       &initial_util_type.attr,
-       &initial_util_ratio.attr,
        NULL,
 };
 
diff --git a/kernel/sched/ems/init_util.c b/kernel/sched/ems/init_util.c
new file mode 100644 (file)
index 0000000..0059134
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * task util initialization
+ *
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd
+ * Lakkyung Jung <lakkyung.jung@samsung.com>
+ */
+
+#include <linux/sched.h>
+
+#include "ems.h"
+#include "../sched.h"
+
+enum {
+       TYPE_BASE_CFS_RQ_UTIL = 0,
+       TYPE_BASE_INHERIT_PARENT_UTIL,
+       TYPE_MAX_NUM,
+};
+
+static unsigned long init_util_type = TYPE_BASE_CFS_RQ_UTIL;
+static unsigned long init_util_ratio = 25;                     /* 25% */
+
+static void base_cfs_rq_util(struct sched_entity *se)
+{
+       struct cfs_rq *cfs_rq = se->cfs_rq;
+       struct sched_avg *sa = &se->avg;
+       int cpu = cpu_of(cfs_rq->rq);
+       unsigned long cap_org = capacity_orig_of(cpu);
+       long cap = (long)(cap_org - cfs_rq->avg.util_avg) / 2;
+
+       if (cap > 0) {
+               if (cfs_rq->avg.util_avg != 0) {
+                       sa->util_avg  = cfs_rq->avg.util_avg * se->load.weight;
+                       sa->util_avg /= (cfs_rq->avg.load_avg + 1);
+
+                       if (sa->util_avg > cap)
+                               sa->util_avg = cap;
+               } else {
+                       sa->util_avg = cap_org * init_util_ratio / 100;
+               }
+               /*
+                * If we wish to restore tuning via setting initial util,
+                * this is where we should do it.
+                */
+               sa->util_sum = sa->util_avg * LOAD_AVG_MAX;
+       }
+}
+
+static void base_inherit_parent_util(struct sched_entity *se)
+{
+       struct sched_avg *sa = &se->avg;
+       struct task_struct *p = current;
+
+       sa->util_avg = p->se.avg.util_avg;
+       sa->util_sum = p->se.avg.util_sum;
+}
+
+void exynos_init_entity_util_avg(struct sched_entity *se)
+{
+       int type = init_util_type;
+
+       switch(type) {
+       case TYPE_BASE_CFS_RQ_UTIL:
+               base_cfs_rq_util(se);
+               break;
+       case TYPE_BASE_INHERIT_PARENT_UTIL:
+               base_inherit_parent_util(se);
+               break;
+       default:
+               pr_info("%s: Not support initial util type %ld\n",
+                               __func__, init_util_type);
+       }
+}
+
+static ssize_t show_initial_util_type(struct kobject *kobj,
+               struct kobj_attribute *attr, char *buf)
+{
+        return snprintf(buf, 10, "%ld\n", init_util_type);
+}
+
+static ssize_t store_initial_util_type(struct kobject *kobj,
+                struct kobj_attribute *attr, const char *buf,
+                size_t count)
+{
+        long input;
+
+        if (!sscanf(buf, "%ld", &input))
+                return -EINVAL;
+
+        input = input < 0 ? 0 : input;
+        input = input >= TYPE_MAX_NUM ? TYPE_MAX_NUM - 1 : input;
+
+        init_util_type = input;
+
+        return count;
+}
+
+static ssize_t show_initial_util_ratio(struct kobject *kobj,
+               struct kobj_attribute *attr, char *buf)
+{
+        return snprintf(buf, 10, "%ld\n", init_util_ratio);
+}
+
+static ssize_t store_initial_util_ratio(struct kobject *kobj,
+                struct kobj_attribute *attr, const char *buf,
+                size_t count)
+{
+        long input;
+
+        if (!sscanf(buf, "%ld", &input))
+                return -EINVAL;
+
+        init_util_ratio = !!input;
+
+        return count;
+}
+
+static struct kobj_attribute initial_util_type =
+__ATTR(initial_util_type, 0644, show_initial_util_type, store_initial_util_type);
+
+static struct kobj_attribute initial_util_ratio =
+__ATTR(initial_util_ratio, 0644, show_initial_util_ratio, store_initial_util_ratio);
+
+static struct attribute *attrs[] = {
+       &initial_util_type.attr,
+       &initial_util_ratio.attr,
+       NULL,
+};
+
+static const struct attribute_group attr_group = {
+       .attrs = attrs,
+};
+
+static int __init init_util_sysfs(void)
+{
+       struct kobject *kobj;
+
+       kobj = kobject_create_and_add("init_util", ems_kobj);
+       if (!kobj)
+               return -EINVAL;
+
+       if (sysfs_create_group(kobj, &attr_group))
+               return -EINVAL;
+
+       return 0;
+}
+late_initcall(init_util_sysfs);