pass: Clean up duplicate variables for num_cpus 17/114517/2
authorWook Song <wook16.song@samsung.com>
Mon, 13 Feb 2017 09:03:43 +0000 (18:03 +0900)
committerWook Song <wook16.song@samsung.com>
Tue, 14 Feb 2017 01:49:22 +0000 (10:49 +0900)
This patch cleans up duplicate variables meaning number of CPUs in a
resource. From now, there are only two variables that indicate the
number of CPUs. One is num_cpus in struct pass_conf_data and this is the
value from the resource conf file. The other is the num_cpus in struct
pass_hotplug and this means the possible maximum number of online CPUs.
Currently, the values of these two variables are equivalently assigned
the value in the conf file.However, the latter would be changed by the
upcoming patch as its original intention.

Change-Id: I289247d7dd5611ccfb2030dc5eeefdda83408307
Signed-off-by: Wook Song <wook16.song@samsung.com>
src/pass/pass-gov-radiation.c
src/pass/pass-gov.c
src/pass/pass-hal.c
src/pass/pass.c
src/pass/pass.h

index 8ad4673ae0fcab1743ba93e4ec7cc65769f36750..a4e745534d0f158227bb852ae33381d8702e5c14 100644 (file)
@@ -172,12 +172,12 @@ int pass_radiation_governor(struct pass_policy *policy)
                return level;
 
        if (up_count * 100 >= num_pass_gov * up_threshold) {
-               level += policy->freq.num_nr_cpus;
+               level += policy->hotplug->num_cpus;
 
                if (level > policy->max_level)
-                       level -= policy->freq.num_nr_cpus;
+                       level -= policy->hotplug->num_cpus;
        } else if (down_count * 100 >= num_pass_gov * down_threshold) {
-               level -= policy->freq.num_nr_cpus;
+               level -= policy->hotplug->num_cpus;
        }
 
        if (right_count * 100 >= num_pass_gov * up_threshold) {
index 0745138b6a1964effc0c8bd9903f7bbf275e4ee9..534fb042ca1d4c7e4daff83057e32586c7574e1a 100644 (file)
@@ -132,10 +132,10 @@ static void pass_hotplug_set_online(struct pass_policy *policy,
        if (!hotplug || min_num == hotplug->online)
                return;
 
-       if (min_num > hotplug->max_online)
-               min_num = hotplug->max_online;
+       if (min_num > hotplug->num_cpus)
+               min_num = hotplug->num_cpus;
 
-       for (i = 0 ; i < policy->freq.num_nr_cpus; i++) {
+       for (i = 0 ; i < hotplug->num_cpus; i++) {
                if (i < min_num) {
                        pass_set_online_state(pass_res, hotplug->sequence[i],
                                                PASS_CPU_UP);
@@ -161,6 +161,8 @@ static void pass_hotplug_set_online(struct pass_policy *policy,
  */
 static void pass_hotplug_stop(struct pass_policy *policy)
 {
+       struct pass_resource *pass_res = to_pass_resource(policy);
+       struct pass_conf_data *cdata = &pass_res->cdata;
        struct pass_table *table = policy->pass_table;
        int level = policy->max_level;
 
@@ -168,7 +170,6 @@ static void pass_hotplug_stop(struct pass_policy *policy)
                return;
 
        policy->hotplug->online = table[level].limit_min_cpu;
-       policy->hotplug->max_online = policy->freq.num_nr_cpus;
 }
 
 static int pass_hotplug_dummy_governor(struct pass_policy *policy)
@@ -254,9 +255,6 @@ static int pass_governor_change_level(struct pass_policy *policy, int new_level)
 
        /* Turn on/off CPUs according the maximum number of online CPU */
        if (hotplug) {
-               if (hotplug->max_online != limit_min_cpu)
-                       hotplug->max_online = limit_min_cpu;
-
                if (hotplug->governor)
                        online = hotplug->governor(policy);
                else
@@ -305,7 +303,9 @@ static int pass_governor_change_level(struct pass_policy *policy, int new_level)
 static void pass_calculate_busy_cpu(struct pass_policy *policy)
 {
        struct pass_cpu_stats *stats = policy->pass_cpu_stats;
+       struct pass_resource *res = to_pass_resource(policy);
        struct pass_table *table = policy->pass_table;
+       struct pass_conf_data *cdata = &res->cdata;
        unsigned int level = policy->curr_level;
        unsigned int cpu_threshold = 0;
        unsigned int busy_cpu;
@@ -335,7 +335,7 @@ static void pass_calculate_busy_cpu(struct pass_policy *policy)
                sum_runnable_load = 0;
 
                /* Calculate the number of busy cpu */
-               for (j = 0; j < policy->freq.num_nr_cpus; j++) {
+               for (j = 0; j < cdata->num_cpus; j++) {
                        load = stats[i].load[j];
                        sum_load += stats[i].load[j];
                        sum_runnable_load += stats[i].runnable_load[j];
index ceb65f3c5e3f8ce740bcba3516c0013e9a60de22..bd7438a409d6a55736d66e9cbe6a85b9b0c1f326 100644 (file)
@@ -502,7 +502,7 @@ int pass_get_cpu_stats(struct pass_policy *policy)
                if (ret < 0)
                        return -EIO;
 
-               for (j = 0; j < policy->freq.num_nr_cpus; j++) {
+               for (j = 0; j < pass_res->cdata.num_cpus; j++) {
                        ret = fscanf(fp_stats, "%d", &stats[i].load[j]);
                        if (ret < 0)
                                return -EIO;
index 4bd2cccc039ab7947de602ef59e3cbda29667776..382e0e28fc8f95a5647fc3336d6e49e4aaea7b0f 100644 (file)
@@ -160,7 +160,6 @@ static int pass_resource_init(struct pass_policy *policy)
                        max_cpu = policy->pass_table[i].limit_min_cpu;
        }
        policy->freq.max_freq = max_freq;
-       policy->freq.num_nr_cpus = max_cpu;
 
        /* Allocate memory according to the number of data and cpu */
        policy->pass_cpu_stats = calloc(policy->num_pass_cpu_stats,
@@ -168,11 +167,11 @@ static int pass_resource_init(struct pass_policy *policy)
 
        for (i = 0; i < policy->num_pass_cpu_stats; i++) {
                policy->pass_cpu_stats[i].load =
-                       calloc(policy->freq.num_nr_cpus, sizeof(unsigned int));
+                       calloc(pass_res->cdata.num_cpus, sizeof(unsigned int));
                policy->pass_cpu_stats[i].nr_running =
-                       calloc(policy->freq.num_nr_cpus, sizeof(unsigned int));
+                       calloc(pass_res->cdata.num_cpus, sizeof(unsigned int));
                policy->pass_cpu_stats[i].runnable_load =
-                       calloc(policy->freq.num_nr_cpus, sizeof(unsigned int));
+                       calloc(pass_res->cdata.num_cpus, sizeof(unsigned int));
        }
 
        /* Get the instance of PASS governor */
@@ -186,10 +185,12 @@ static int pass_resource_init(struct pass_policy *policy)
        /* Get the instance of PASS hotplulg */
        policy->hotplug = pass_get_hotplug(policy, policy->gov_type);
        if (policy->hotplug) {
-               policy->hotplug->sequence = calloc(policy->freq.num_nr_cpus,
+               policy->hotplug->sequence = calloc(pass_res->cdata.num_cpus,
                                                sizeof(int));
-               for (i = 0; i < policy->freq.num_nr_cpus; i++)
+               for (i = 0; i < pass_res->cdata.num_cpus; i++)
                        policy->hotplug->sequence[i] = i + pass_res->cdata.cpu;
+
+               policy->hotplug->num_cpus = pass_res->cdata.num_cpus;
        }
 
        ret = pass_governor_init(policy);
index b7719e526de08a7f1c5cabf5b13e287faae27d15..000a39c8b13ed091fdc3e7208f00270a347c82b1 100644 (file)
@@ -159,13 +159,13 @@ struct pass_table {
 
 /*
  * struct pass_hotplug - store information of cpu hotplug
- * @max_online: the possible maximum number of online cpu
+ * @num_cpus: the possible maximum number of online cpus
  * @online: the current number of online cpu
  * @sequence: the sequence to turn on/off cpu
  */
 struct pass_hotplug {
        char name[PASS_NAME_LEN];
-       unsigned int max_online;
+       unsigned int num_cpus;
        unsigned int online;
        unsigned int *sequence;
        int (*governor)(struct pass_policy *);
@@ -174,7 +174,6 @@ struct pass_hotplug {
 
 struct pass_freq_policy {
        unsigned int max_freq;
-       unsigned int num_nr_cpus;
        unsigned int sampling_rate;
        unsigned int up_threshold;
 };