From 348b9916269091b15520e1a5c699f00d1dd4023a Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 25 Jan 2018 10:49:46 +0900 Subject: [PATCH] pass: parser: Clean-up exported parsing function to improve readability Clean-up exported parsing function in order to improve readability and keep the consistency. Describe the detailed clean-up as following: - Reorder exported functions into pass-parser.c - Change the function name to improve readability and keep the consistency like pass_get/put_resource_config() as following: pass_get_table() -> pass_get_each_resource_config() pass_put_table() -> pass_put_each_resource_config() - Modify argument name from 'path_conf_path' to 'path' Change-Id: Ic8d517855c95e1a29ba5d6e4b62693c7b150e223 Signed-off-by: Chanwoo Choi --- src/pass/pass-parser.c | 387 ++++++++++++++++++++++++++----------------------- src/pass/pass-parser.h | 8 +- src/pass/pass.c | 4 +- 3 files changed, 211 insertions(+), 188 deletions(-) diff --git a/src/pass/pass-parser.c b/src/pass/pass-parser.c index 0ca513a..125f341 100644 --- a/src/pass/pass-parser.c +++ b/src/pass/pass-parser.c @@ -322,185 +322,6 @@ out: return 0; } -int pass_get_table(struct pass_resource *res, char *pass_conf_path) -{ - struct pass_policy *policy; - int ret; - - if (!res) - return -EINVAL; - - policy = &res->policy; - - policy->state = PASS_UNUSED; - policy->pmqos.state = PASS_UNUSED; - - policy->state = 0; - policy->gov_type = 0; - policy->num_levels = 0; - policy->min_level = 0; - policy->max_level = 0; - policy->num_pass_cpu_stats = 0; - policy->pass_cpu_threshold = 0; - policy->up_threshold = 0; - policy->down_threshold = 0; - policy->init_level = 0; - policy->prev_level = policy->init_level; - policy->level_up_threshold = 0; - policy->gov_timeout = 0; - policy->last_time = 0; - - ret = config_parse(pass_conf_path, pass_load_config, policy); - if (ret < 0) { - _E("cannot parse %s\n", pass_conf_path); - return -EINVAL; - } - - /* - int level; - - _I("%s| policy->state : %d\n", - res->cdata.res_name, policy->state); - _I("%s| policy->gov_type : %d\n", - res->cdata.res_name, policy->gov_type); - _I("%s| policy->num_levels : %d\n", - res->cdata.res_name, policy->num_levels); - _I("%s| policy->min_level : %d\n", - res->cdata.res_name, policy->min_level); - _I("%s| policy->max_level : %d\n", - res->cdata.res_name, policy->max_level); - _I("%s| policy->num_pass_cpu_stats : %d\n", - res->cdata.res_name, policy->num_pass_cpu_stats); - _I("%s| policy->pass_cpu_threshold : %d\n", - res->cdata.res_name, policy->pass_cpu_threshold); - _I("%s| policy->up_threshold : %d\n", - res->cdata.res_name, policy->up_threshold); - _I("%s| policy->down_threshold : %d\n", - res->cdata.res_name, policy->down_threshold); - _I("%s| policy->init_level : %d\n", - res->cdata.res_name, policy->init_level); - _I("%s| policy->level_up_threshold : %d\n", - res->cdata.res_name, policy->level_up_threshold); - _I("%s| policy->gov_timeout : %f\n", - res->cdata.res_name, policy->gov_timeout); - - for (level = 0; level < policy->num_levels; level++) { - _I("================================================\n"); - if (policy->levels[level].limit_max_freq) - _I("%s| policy->levels[%d].limit_max_freq : %d\n", - res->cdata.res_name, level, - policy->levels[level].limit_max_freq); - if (policy->levels[level].limit_min_freq) - _I("%s| policy->levels[%d].limit_min_freq : %d\n", - res->cdata.res_name, level, - policy->levels[level].limit_min_freq); - if (policy->levels[level].limit_min_cpu) - _I("%s| policy->levels[%d].limit_min_cpu : %d\n", - res->cdata.res_name, level, - policy->levels[level].limit_min_cpu); - if (policy->levels[level].gov_timeout) - _I("%s| policy->levels[%d].gov_timeout : %f\n", - res->cdata.res_name, level, - policy->levels[level].gov_timeout); - - if (policy->levels[level].num_down_cond) - _I("%s| policy->levels[%d].num_down_cond : %d\n", - res->cdata.res_name, level, - policy->levels[level].num_down_cond); - if (policy->levels[level].down_cond[0].freq) - _I("%s| policy->levels[%d].down_cond[0].freq : %d\n", - res->cdata.res_name, level, - policy->levels[level].down_cond[0].freq); - if (policy->levels[level].down_cond[0].nr_running) - _I("%s| policy->levels[%d].down_cond[0].nr_running : %d\n", - res->cdata.res_name, level, - policy->levels[level].down_cond[0].nr_running); - if (policy->levels[level].down_cond[0].busy_cpu) - _I("%s| policy->levels[%d].down_cond[0].busy_cpu : %d\n", - res->cdata.res_name, level, - policy->levels[level].down_cond[0].busy_cpu); - - if (policy->levels[level].num_up_cond) - _I("%s| policy->levels[%d].num_up_cond : %d\n", - res->cdata.res_name, level, - policy->levels[level].num_up_cond); - if (policy->levels[level].up_cond[0].freq) - _I("%s| policy->levels[%d].up_cond[0].freq : %d\n", - res->cdata.res_name, level, - policy->levels[level].up_cond[0].freq); - if (policy->levels[level].up_cond[0].nr_running) - _I("%s| policy->levels[%d].up_cond[0].nr_running : %d\n", - res->cdata.res_name, level, - policy->levels[level].up_cond[0].nr_running); - if (policy->levels[level].up_cond[0].busy_cpu) - _I("%s| policy->levels[%d].up_cond[0].busy_cpu : %d\n", - res->cdata.res_name, level, - policy->levels[level].up_cond[0].busy_cpu); - - if (policy->levels[level].num_left_cond) - _I("%s| policy->levels[%d].num_left_cond : %d\n", - res->cdata.res_name, level, - policy->levels[level].num_left_cond); - if (policy->levels[level].left_cond[0].freq) - _I("%s| policy->levels[%d].left_cond[0].freq : %d\n", - res->cdata.res_name, level, policy->levels[level].left_cond[0].freq); - if (policy->levels[level].left_cond[0].nr_running) - _I("%s| policy->levels[%d].left_cond[0].nr_running : %d\n", - res->cdata.res_name, level, policy->levels[level].left_cond[0].nr_running); - if (policy->levels[level].left_cond[0].busy_cpu) - _I("%s| policy->levels[%d].left_cond[0].busy_cpu : %d\n", - res->cdata.res_name, level, policy->levels[level].left_cond[0].busy_cpu); - - if (policy->levels[level].num_right_cond) - _I("%s| policy->levels[%d].num_right_cond : %d\n", - res->cdata.res_name, level, policy->levels[level].num_right_cond); - if (policy->levels[level].right_cond[0].freq) - _I("%s| policy->levels[%d].right_cond[0].freq : %d\n", - res->cdata.res_name, level, policy->levels[level].right_cond[0].freq); - if (policy->levels[level].right_cond[0].nr_running) - _I("%s| policy->levels[%d].right_cond[0].nr_running : %d\n", - res->cdata.res_name, level, policy->levels[level].right_cond[0].nr_running); - if (policy->levels[level].right_cond[0].busy_cpu) - _I("%s| policy->levels[%d].right_cond[0].busy_cpu : %d\n", - res->cdata.res_name, level, policy->levels[level].right_cond[0].busy_cpu); - } - */ - - if (policy->state == PASS_UNUSED) - return -EINVAL; - - if (policy->pmqos.state == PASS_UNUSED) - _W("%s don't include the list of pass-scenario\n"); - else if (policy->pmqos.state == PASS_OFF) - _I("cannot use pass-scenario"); - - return 0; -} - -void pass_put_table(struct pass_resource *res) -{ - struct pass_policy *policy; - - if (!res) { - _E("cannot put pass table\n"); - return; - } - - policy = &res->policy; - - if (policy->levels) { - free(policy->levels); - policy->levels = NULL; - } - - if (policy->pmqos.scenarios) { - free(policy->pmqos.scenarios); - policy->pmqos.scenarios = NULL; - } - - policy->pmqos.num_scenarios = 0; -} - static int pass_parse_resource_data(struct parse_result *result, void *user_data, int id) { @@ -562,6 +383,7 @@ static int pass_parse_resource_data(struct parse_result *result, return 0; } + static int check_compatible(char *compatible, char *path_compatible) { char buf[BUFF_MAX]; @@ -596,7 +418,7 @@ static int check_compatible(char *compatible, char *path_compatible) return 0; } -static int pass_resource_config(struct parse_result *result, void *user_data) +static int parse_resource(struct parse_result *result, void *user_data) { static char path_compatible[BUFF_MAX]; static bool is_compatible = false; @@ -700,14 +522,215 @@ static int pass_resource_config(struct parse_result *result, void *user_data) return 0; } -int pass_get_resource_config(struct pass *pass, char *pass_conf_path) +/* + * pass_get_resource_config - Get all h/w resource information + * + * @pass: the instance of struct pass which contains all information + * @path: the path of configuration files (e.g., /etc/pass/pass.conf) + */ +int pass_get_resource_config(struct pass *pass, char *path) { - return config_parse(pass_conf_path, pass_resource_config, pass); + return config_parse(path, parse_resource, pass); } +/* + * pass_get_resource_config - Free h/w resource information + * + * @pass: the instance of struct pass which contains all information + */ void pass_put_resource_config(struct pass *pass) { free(pass->res); pass->res = NULL; pass->num_resources = 0; } + +/* + * pass_get_each_resource_config - Get each h/w resource information + * + * @res: the instance of struct pass_resource + * @path: the path of configuration file for each h/w resource + */ +int pass_get_each_resource_config(struct pass_resource *res, char *path) +{ + struct pass_policy *policy; + int ret; + + if (!res) + return -EINVAL; + + policy = &res->policy; + + policy->state = PASS_UNUSED; + policy->pmqos.state = PASS_UNUSED; + + policy->state = 0; + policy->gov_type = 0; + policy->num_levels = 0; + policy->min_level = 0; + policy->max_level = 0; + policy->num_pass_cpu_stats = 0; + policy->pass_cpu_threshold = 0; + policy->up_threshold = 0; + policy->down_threshold = 0; + policy->init_level = 0; + policy->prev_level = policy->init_level; + policy->level_up_threshold = 0; + policy->gov_timeout = 0; + policy->last_time = 0; + + ret = config_parse(path, pass_load_config, policy); + if (ret < 0) { + _E("cannot parse %s\n", path); + return -EINVAL; + } + + /* + int level; + + _I("%s| policy->state : %d\n", + res->cdata.res_name, policy->state); + _I("%s| policy->gov_type : %d\n", + res->cdata.res_name, policy->gov_type); + _I("%s| policy->num_levels : %d\n", + res->cdata.res_name, policy->num_levels); + _I("%s| policy->min_level : %d\n", + res->cdata.res_name, policy->min_level); + _I("%s| policy->max_level : %d\n", + res->cdata.res_name, policy->max_level); + _I("%s| policy->num_pass_cpu_stats : %d\n", + res->cdata.res_name, policy->num_pass_cpu_stats); + _I("%s| policy->pass_cpu_threshold : %d\n", + res->cdata.res_name, policy->pass_cpu_threshold); + _I("%s| policy->up_threshold : %d\n", + res->cdata.res_name, policy->up_threshold); + _I("%s| policy->down_threshold : %d\n", + res->cdata.res_name, policy->down_threshold); + _I("%s| policy->init_level : %d\n", + res->cdata.res_name, policy->init_level); + _I("%s| policy->level_up_threshold : %d\n", + res->cdata.res_name, policy->level_up_threshold); + _I("%s| policy->gov_timeout : %f\n", + res->cdata.res_name, policy->gov_timeout); + + for (level = 0; level < policy->num_levels; level++) { + _I("================================================\n"); + if (policy->levels[level].limit_max_freq) + _I("%s| policy->levels[%d].limit_max_freq : %d\n", + res->cdata.res_name, level, + policy->levels[level].limit_max_freq); + if (policy->levels[level].limit_min_freq) + _I("%s| policy->levels[%d].limit_min_freq : %d\n", + res->cdata.res_name, level, + policy->levels[level].limit_min_freq); + if (policy->levels[level].limit_min_cpu) + _I("%s| policy->levels[%d].limit_min_cpu : %d\n", + res->cdata.res_name, level, + policy->levels[level].limit_min_cpu); + if (policy->levels[level].gov_timeout) + _I("%s| policy->levels[%d].gov_timeout : %f\n", + res->cdata.res_name, level, + policy->levels[level].gov_timeout); + + if (policy->levels[level].num_down_cond) + _I("%s| policy->levels[%d].num_down_cond : %d\n", + res->cdata.res_name, level, + policy->levels[level].num_down_cond); + if (policy->levels[level].down_cond[0].freq) + _I("%s| policy->levels[%d].down_cond[0].freq : %d\n", + res->cdata.res_name, level, + policy->levels[level].down_cond[0].freq); + if (policy->levels[level].down_cond[0].nr_running) + _I("%s| policy->levels[%d].down_cond[0].nr_running : %d\n", + res->cdata.res_name, level, + policy->levels[level].down_cond[0].nr_running); + if (policy->levels[level].down_cond[0].busy_cpu) + _I("%s| policy->levels[%d].down_cond[0].busy_cpu : %d\n", + res->cdata.res_name, level, + policy->levels[level].down_cond[0].busy_cpu); + + if (policy->levels[level].num_up_cond) + _I("%s| policy->levels[%d].num_up_cond : %d\n", + res->cdata.res_name, level, + policy->levels[level].num_up_cond); + if (policy->levels[level].up_cond[0].freq) + _I("%s| policy->levels[%d].up_cond[0].freq : %d\n", + res->cdata.res_name, level, + policy->levels[level].up_cond[0].freq); + if (policy->levels[level].up_cond[0].nr_running) + _I("%s| policy->levels[%d].up_cond[0].nr_running : %d\n", + res->cdata.res_name, level, + policy->levels[level].up_cond[0].nr_running); + if (policy->levels[level].up_cond[0].busy_cpu) + _I("%s| policy->levels[%d].up_cond[0].busy_cpu : %d\n", + res->cdata.res_name, level, + policy->levels[level].up_cond[0].busy_cpu); + + if (policy->levels[level].num_left_cond) + _I("%s| policy->levels[%d].num_left_cond : %d\n", + res->cdata.res_name, level, + policy->levels[level].num_left_cond); + if (policy->levels[level].left_cond[0].freq) + _I("%s| policy->levels[%d].left_cond[0].freq : %d\n", + res->cdata.res_name, level, policy->levels[level].left_cond[0].freq); + if (policy->levels[level].left_cond[0].nr_running) + _I("%s| policy->levels[%d].left_cond[0].nr_running : %d\n", + res->cdata.res_name, level, policy->levels[level].left_cond[0].nr_running); + if (policy->levels[level].left_cond[0].busy_cpu) + _I("%s| policy->levels[%d].left_cond[0].busy_cpu : %d\n", + res->cdata.res_name, level, policy->levels[level].left_cond[0].busy_cpu); + + if (policy->levels[level].num_right_cond) + _I("%s| policy->levels[%d].num_right_cond : %d\n", + res->cdata.res_name, level, policy->levels[level].num_right_cond); + if (policy->levels[level].right_cond[0].freq) + _I("%s| policy->levels[%d].right_cond[0].freq : %d\n", + res->cdata.res_name, level, policy->levels[level].right_cond[0].freq); + if (policy->levels[level].right_cond[0].nr_running) + _I("%s| policy->levels[%d].right_cond[0].nr_running : %d\n", + res->cdata.res_name, level, policy->levels[level].right_cond[0].nr_running); + if (policy->levels[level].right_cond[0].busy_cpu) + _I("%s| policy->levels[%d].right_cond[0].busy_cpu : %d\n", + res->cdata.res_name, level, policy->levels[level].right_cond[0].busy_cpu); + } + */ + + if (policy->state == PASS_UNUSED) + return -EINVAL; + + if (policy->pmqos.state == PASS_UNUSED) + _W("%s don't include the list of pass-scenario\n"); + else if (policy->pmqos.state == PASS_OFF) + _I("cannot use pass-scenario"); + + return 0; +} + +/* + * pass_put_each_resource_config - Free each h/w resource information + * + * @res: the instance of struct pass_resource + */ +void pass_put_each_resource_config(struct pass_resource *res) +{ + struct pass_policy *policy; + + if (!res) { + _E("cannot put pass table\n"); + return; + } + + policy = &res->policy; + + if (policy->levels) { + free(policy->levels); + policy->levels = NULL; + } + + if (policy->pmqos.scenarios) { + free(policy->pmqos.scenarios); + policy->pmqos.scenarios = NULL; + } + + policy->pmqos.num_scenarios = 0; +} diff --git a/src/pass/pass-parser.h b/src/pass/pass-parser.h index 5de7643..92726e1 100644 --- a/src/pass/pass-parser.h +++ b/src/pass/pass-parser.h @@ -21,10 +21,10 @@ #include "pass.h" -int pass_get_table(struct pass_resource *res, char *pass_conf_path); -void pass_put_table(struct pass_resource *res); - -int pass_get_resource_config(struct pass *pass, char *pass_conf_path); +int pass_get_resource_config(struct pass *pass, char *path); void pass_put_resource_config(struct pass *pass); +int pass_get_each_resource_config(struct pass_resource *res, char *path); +void pass_put_each_resource_config(struct pass_resource *res); + #endif /* __PASS_PARSER__ */ diff --git a/src/pass/pass.c b/src/pass/pass.c index 3d96a21..9cf90d2 100644 --- a/src/pass/pass.c +++ b/src/pass/pass.c @@ -125,7 +125,7 @@ static int pass_init_resource(struct pass_resource *res) int i; /* Get configuration of each resource from pass-resource*.conf */ - ret = pass_get_table(res, res->cdata.path_conf_file); + ret = pass_get_each_resource_config(res, res->cdata.path_conf_file); if (ret < 0) { _E("cannot parse %s\n", res->cdata.path_conf_file); return -1; @@ -221,7 +221,7 @@ static int pass_exit_resource(struct pass_resource *res) int ret; /* Put configuration of each resource from pass-resource*.conf */ - pass_put_table(res); + pass_put_each_resource_config(res); ret = pass_governor_exit(res); if (ret < 0) { -- 2.7.4