pass-hal: tm1: Force to restore initial state of resource 74/138874/2 accepted/tizen/4.0/unified/20170816.020150 accepted/tizen/unified/20170804.025538 submit/tizen/20170802.103729 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170814.115522 submit/tizen_4.0_unified/20170814.115522
authorDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 21 Jul 2017 01:54:14 +0000 (10:54 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 21 Jul 2017 02:32:36 +0000 (11:32 +0900)
Though PASS supports save/restore initial state of each resource, but
tm1 has weird pmqos interface and thus it doesn't work well.
To resolve this, pass-hal-tm1 forces to restore initial state when it
is closed.

Change-Id: I8c0591538f44a24577fea4a88d1dd86316c5a94e
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
src/cpu/cpu.c

index 439c9161c30525926cedb4bf543bba5aa3b1de08..9d84c352e66c5fe582a94969bcc4ef89e794c479 100644 (file)
 #define CPUFREQ_MIN_FREQ_PATH_SUFFIX           "/cpufreq_min"
 #define CPUFREQ_CURR_FREQ_PATH_SUFFIX          "/cpufreq/cpuinfo_cur_freq"
 
-#define CPUFREQ_AVAILABLE_FREQ_MAX             1300000
-#define CPUFREQ_AVAILABLE_FREQ_MIN             768000
-#define CPUFREQ_PMQOS_ONLINE_MIN_NUM_UNLOCK    -1
-#define CPUFREQ_PMQOS_ONLINE_MAX_NUM_UNLOCK    -1
+#define CPUFREQ_DEFAULT_MIN_FREQ               0
+#define CPUFREQ_DEFAULT_MAX_FREQ               INT_MAX
+#define CPUFREQ_DEFAULT_ONLINE_MIN_NUM         0
+#define CPUFREQ_DEFAULT_ONLINE_MAX_NUM         4
+
+#define CPUFREQ_PMQOS_REQUEST_UNLOCK           -1
 
 static int tm1_dvfs_get_curr_freq(char *res_name)
 {
@@ -89,12 +91,9 @@ static int tm1_dvfs_set_min_freq(char *res_name, int freq)
        char path[PATH_MAX];
        int ret;
 
-       if ((!res_name) || (freq < 0))
+       if (!res_name)
                return -EINVAL;
 
-       if (freq == CPUFREQ_AVAILABLE_FREQ_MIN)
-               freq = -1;
-
        ret = snprintf(path, PATH_MAX, "%s%s",
                CPUFREQ_PMQOS_PATH_PREFIX,
                CPUFREQ_MIN_FREQ_PATH_SUFFIX);
@@ -131,12 +130,9 @@ static int tm1_dvfs_set_max_freq(char *res_name, int freq)
        char path[PATH_MAX];
        int ret;
 
-       if ((!res_name) || (freq < 0))
+       if (!res_name)
                return -EINVAL;
 
-       if (freq == CPUFREQ_AVAILABLE_FREQ_MAX)
-               freq = -1;
-
        snprintf(path, PATH_MAX, "%s%s",
                CPUFREQ_PMQOS_PATH_PREFIX,
                CPUFREQ_MAX_FREQ_PATH_SUFFIX);
@@ -195,9 +191,6 @@ static int tm1_hotplug_set_online_min_num(char *res_name, int num)
                CPUFREQ_PMQOS_PATH_PREFIX,
                CPUFREQ_CPU_ONLINE_MIN_NUM_PATH_SUFFIX);
 
-       if (num == 0)
-               num = CPUFREQ_PMQOS_ONLINE_MIN_NUM_UNLOCK;
-
        ret = sysfs_write_int(path, num);
        if (ret < 0)
                return ret;
@@ -238,9 +231,6 @@ static int tm1_hotplug_set_online_max_num(char *res_name, int num)
                CPUFREQ_PMQOS_PATH_PREFIX,
                CPUFREQ_CPU_ONLINE_MAX_NUM_PATH_SUFFIX);
 
-       if (num == 0)
-               num = CPUFREQ_PMQOS_ONLINE_MAX_NUM_UNLOCK;
-
        ret = sysfs_write_int(path, num);
        if (ret < 0)
                return ret;
@@ -294,21 +284,47 @@ static int tm1_cpu_close(char *res_name, struct pass_resource_common *common)
 
        cpu_res = (struct pass_resource_cpu *) common;
 
-       ret = cpu_res->hotplug.set_online_max_num(res_name, 0);
+       /*
+        * tm1 has weird pmqos sysfs node, thus we cannot apply save/restore
+        * feature as pass-hal-standard does. Instead of using standard
+        * interface, we manually restore the each resource state; pmqos
+        * request is unlocked by passing argument '-1' first, and resource
+        * state is restored by passing default value.
+        */
+       ret = cpu_res->hotplug.set_online_max_num(res_name,
+                                       CPUFREQ_PMQOS_REQUEST_UNLOCK);
+       if (ret < 0)
+               goto exit;
+       ret = cpu_res->hotplug.set_online_max_num(res_name,
+                                       CPUFREQ_DEFAULT_ONLINE_MAX_NUM);
        if (ret < 0)
                goto exit;
 
-       ret = cpu_res->hotplug.set_online_min_num(res_name, 0);
+       ret = cpu_res->hotplug.set_online_min_num(res_name,
+                                       CPUFREQ_PMQOS_REQUEST_UNLOCK);
+       if (ret < 0)
+               goto exit;
+       ret = cpu_res->hotplug.set_online_min_num(res_name,
+                                       CPUFREQ_DEFAULT_ONLINE_MIN_NUM);
        if (ret < 0)
                goto exit;
 
-       ret = cpu_res->dvfs.set_min_freq(res_name, CPUFREQ_AVAILABLE_FREQ_MIN);
+       ret = cpu_res->dvfs.set_min_freq(res_name,
+                                       CPUFREQ_PMQOS_REQUEST_UNLOCK);
+       if (ret < 0)
+               goto exit;
+       ret = cpu_res->dvfs.set_min_freq(res_name, CPUFREQ_DEFAULT_MIN_FREQ);
        if (ret < 0)
                goto exit;
 
-       ret = cpu_res->dvfs.set_max_freq(res_name, CPUFREQ_AVAILABLE_FREQ_MAX);
+       ret = cpu_res->dvfs.set_max_freq(res_name,
+                                       CPUFREQ_PMQOS_REQUEST_UNLOCK);
+       if (ret < 0)
+               goto exit;
+       ret = cpu_res->dvfs.set_max_freq(res_name, CPUFREQ_DEFAULT_MAX_FREQ);
        if (ret < 0)
                goto exit;
+
 exit:
        free(common);