pass: parser: Simplify parsing function of 'Level' section 30/168230/1
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 25 Jan 2018 00:34:13 +0000 (09:34 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 25 Jan 2018 01:05:47 +0000 (10:05 +0900)
The pass_parse_level() function is used for parsing 'Level%d' section.
Simplify the function's definition as following. Now, PASS uses the 'level'
concept which indicating the basic unit in order to initialize the h/w resource.
In the next time, PASS will use both 'global level' and 'local level' concept.
The changed pass_parse_level() is better to support both 'global level' and
'local level'.

[Before]
- pass_parse_level(struct parse_result *result, void *user_data, int level)
[After]
- pass_parse_level(struct parse_result *result, struct pass_level level)

Change-Id: Ib98b419d14e46f36de559b0f2b32c9fe63fc5bf4
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
[cw00.choi: Apply dongwoo's patch and document the description]
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/pass/pass-parser.c

index ade6407f559d1f6af01ae2dc7c2cc257e5bdbae9..0ca513a725a385e777f6b2537d99c868104e3375 100644 (file)
@@ -116,11 +116,9 @@ static int pass_parse_pmqos(struct parse_result *result, void *user_data,
 }
 
 static int pass_parse_level(struct parse_result *result,
-                                   void *user_data, int level)
+                               struct pass_level *level)
 {
-       struct pass_policy *policy = user_data;
-
-       if (!result)
+       if (!result || !level)
                return 0;
 
        if (!result->section || !result->name || !result->value)
@@ -133,58 +131,58 @@ static int pass_parse_level(struct parse_result *result,
         * - PASS_RESOURCE_GPU_ID
         */
        if (MATCH(result->name, "limit_max_freq"))
-               policy->levels[level].limit_max_freq = atoi(result->value);
+               level->limit_max_freq = atoi(result->value);
        else if (MATCH(result->name, "limit_min_freq"))
-               policy->levels[level].limit_min_freq = atoi(result->value);
+               level->limit_min_freq = atoi(result->value);
        else if (MATCH(result->name, "limit_min_cpu"))
-               policy->levels[level].limit_min_cpu = atoi(result->value);
+               level->limit_min_cpu = atoi(result->value);
 
        /*
         * Properties for the following h/w resources:
         * - PASS_RESOURCE_CPU_ID
         */
        else if (MATCH(result->name, "num_down_cond"))
-               policy->levels[level].num_down_cond = atoi(result->value);
+               level->num_down_cond = atoi(result->value);
        else if (MATCH(result->name, "num_down_cond_freq"))
-               policy->levels[level].down_cond[0].freq = atoi(result->value);
+               level->down_cond[0].freq = atoi(result->value);
        else if (MATCH(result->name, "num_down_cond_nr_running"))
-               policy->levels[level].down_cond[0].nr_running = atoi(result->value);
+               level->down_cond[0].nr_running = atoi(result->value);
        else if (MATCH(result->name, "num_down_cond_busy_cpu"))
-               policy->levels[level].down_cond[0].busy_cpu = atoi(result->value);
+               level->down_cond[0].busy_cpu = atoi(result->value);
 
        else if (MATCH(result->name, "num_up_cond"))
-               policy->levels[level].num_up_cond = atoi(result->value);
+               level->num_up_cond = atoi(result->value);
        else if (MATCH(result->name, "num_up_cond_freq"))
-               policy->levels[level].up_cond[0].freq = atoi(result->value);
+               level->up_cond[0].freq = atoi(result->value);
        else if (MATCH(result->name, "num_up_cond_nr_running"))
-               policy->levels[level].up_cond[0].nr_running = atoi(result->value);
+               level->up_cond[0].nr_running = atoi(result->value);
        else if (MATCH(result->name, "num_up_cond_busy_cpu"))
-               policy->levels[level].up_cond[0].busy_cpu = atoi(result->value);
+               level->up_cond[0].busy_cpu = atoi(result->value);
 
        else if (MATCH(result->name, "num_left_cond"))
-               policy->levels[level].num_left_cond = atoi(result->value);
+               level->num_left_cond = atoi(result->value);
        else if (MATCH(result->name, "num_left_cond_freq"))
-               policy->levels[level].left_cond[0].freq = atoi(result->value);
+               level->left_cond[0].freq = atoi(result->value);
        else if (MATCH(result->name, "num_left_cond_nr_running"))
-               policy->levels[level].left_cond[0].nr_running = atoi(result->value);
+               level->left_cond[0].nr_running = atoi(result->value);
        else if (MATCH(result->name, "num_left_cond_busy_cpu"))
-               policy->levels[level].left_cond[0].busy_cpu = atoi(result->value);
+               level->left_cond[0].busy_cpu = atoi(result->value);
 
        else if (MATCH(result->name, "num_right_cond"))
-               policy->levels[level].num_right_cond = atoi(result->value);
+               level->num_right_cond = atoi(result->value);
        else if (MATCH(result->name, "num_right_cond_freq"))
-               policy->levels[level].right_cond[0].freq = atoi(result->value);
+               level->right_cond[0].freq = atoi(result->value);
        else if (MATCH(result->name, "num_right_cond_nr_running"))
-               policy->levels[level].right_cond[0].nr_running = atoi(result->value);
+               level->right_cond[0].nr_running = atoi(result->value);
        else if (MATCH(result->name, "num_right_cond_busy_cpu"))
-               policy->levels[level].right_cond[0].busy_cpu = atoi(result->value);
+               level->right_cond[0].busy_cpu = atoi(result->value);
        else if (MATCH(result->name, "gov_timeout")) {
                double gov_timeout = atof(result->value);
 
                if (gov_timeout < MIN_TIMEOUT_SEC)
                        gov_timeout = MIN_TIMEOUT_SEC;
 
-               policy->levels[level].gov_timeout = gov_timeout;
+               level->gov_timeout = gov_timeout;
        }
 
        /*
@@ -192,7 +190,7 @@ static int pass_parse_level(struct parse_result *result,
         * - PASS_RESOURCE_MEMORY_ID
         */
        else if (MATCH(result->name, "fault_around_bytes"))
-               policy->levels[level].fault_around_bytes = atoi(result->value);
+               level->fault_around_bytes = atoi(result->value);
 
        return 0;
 }
@@ -279,12 +277,12 @@ static int pass_load_config(struct parse_result *result, void *user_data)
                goto out;
        }
 
-       /* Parsing 'Level' section to get pass-table */
+       /* Parsing 'Level' section */
        for (level = 0; level < policy->num_levels; level++) {
                ret = snprintf(section_name, BUFF_MAX, "Level%d", level);
 
                if (MATCH(result->section, section_name)) {
-                       ret = pass_parse_level(result, user_data, level);
+                       ret = pass_parse_level(result, &policy->levels[level]);
                        if (ret < 0) {
                                _E("cannot parse 'Level' section\n");
                                return ret;