From: Chanwoo Choi Date: Thu, 25 Jan 2018 23:58:40 +0000 (+0900) Subject: pass: hal: Remove inefficient local variables X-Git-Tag: submit/tizen/20180221.002730~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d79aa1b2103eebcd32cdf0ca1b2edb766d3fac26;p=platform%2Fcore%2Fsystem%2Fpass.git pass: hal: Remove inefficient local variables Almost PASS hal function defines the 'res_type' and 'res_name' local variables. It is not efficient method. Use the variable of struct pass_resource directly instead of defining the separate local variables on each hal functions. Change-Id: Ia6719d65639777a4d90df0326adb0e2c66807e85 Signed-off-by: Chanwoo Choi --- diff --git a/src/pass/pass-hal.c b/src/pass/pass-hal.c index 5ddc2a9..48d1e33 100644 --- a/src/pass/pass-hal.c +++ b/src/pass/pass-hal.c @@ -89,451 +89,349 @@ static struct pass_resource_hotplug_ops *get_hotplug(struct pass_resource *res, int pass_get_curr_governor(struct pass_resource *res, char *governor) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res || !governor) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->get_curr_governor) return -EINVAL; - return dvfs->get_curr_governor(res_name, governor); + return dvfs->get_curr_governor(res->cdata.res_name, governor); } int pass_set_curr_governor(struct pass_resource *res, char *governor) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res || !governor) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->set_curr_governor) return -EINVAL; - return dvfs->set_curr_governor(res_name, governor); + return dvfs->set_curr_governor(res->cdata.res_name, governor); } /* Get and set the current/min/max frequency for DVFS resource. */ int pass_get_curr_freq(struct pass_resource *res) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->get_curr_freq) return -EINVAL; - return dvfs->get_curr_freq(res_name); + return dvfs->get_curr_freq(res->cdata.res_name); } int pass_get_min_freq(struct pass_resource *res) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->get_min_freq) return -EINVAL; - return dvfs->get_min_freq(res_name); + return dvfs->get_min_freq(res->cdata.res_name); } int pass_set_min_freq(struct pass_resource *res, int freq) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res || freq < 0) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->set_min_freq) return -EINVAL; - return dvfs->set_min_freq(res_name, freq); + return dvfs->set_min_freq(res->cdata.res_name, freq); } int pass_get_max_freq(struct pass_resource *res) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->get_max_freq) return -EINVAL; - return dvfs->get_max_freq(res_name); + return dvfs->get_max_freq(res->cdata.res_name); } int pass_set_max_freq(struct pass_resource *res, int freq) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res || freq < 0) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->set_max_freq) return -EINVAL; - return dvfs->set_max_freq(res_name, freq); + return dvfs->set_max_freq(res->cdata.res_name, freq); } /* Get the minimum/maximum frequency which can be set to resource. */ int pass_get_available_min_freq(struct pass_resource *res) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->get_available_min_freq) return -EINVAL; - return dvfs->get_available_min_freq(res_name); + return dvfs->get_available_min_freq(res->cdata.res_name); } int pass_get_available_max_freq(struct pass_resource *res) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->get_available_max_freq) return -EINVAL; - return dvfs->get_available_max_freq(res_name); + return dvfs->get_available_max_freq(res->cdata.res_name); } /* Get and set the up_threshold for DVFS resource. */ int pass_get_up_threshold(struct pass_resource *res) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->get_up_threshold) return -EINVAL; - return dvfs->get_up_threshold(res_name); + return dvfs->get_up_threshold(res->cdata.res_name); } int pass_set_up_threshold(struct pass_resource *res, int up_threshold) { struct pass_resource_dvfs_ops *dvfs; - char *res_name; - int res_type; if (!res || up_threshold < 0) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - dvfs = get_dvfs(res, res_type); + dvfs = get_dvfs(res, res->cdata.res_type); if (!dvfs) return -EINVAL; if (!dvfs->set_up_threshold) return -EINVAL; - return dvfs->set_up_threshold(res_name, up_threshold); + return dvfs->set_up_threshold(res->cdata.res_name, up_threshold); } /* Get and set the online state of HOTPLUG resource (e.g., CPU). */ int pass_get_online_state(struct pass_resource *res, int cpu) { struct pass_resource_hotplug_ops *hotplug; - char *res_name; - int res_type; if (!res || cpu < 0) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - hotplug = get_hotplug(res, res_type); + hotplug = get_hotplug(res, res->cdata.res_type); if (!hotplug) return -EINVAL; if (!hotplug->get_online_state) return -EINVAL; - return hotplug->get_online_state(res_name, cpu); + return hotplug->get_online_state(res->cdata.res_name, cpu); } int pass_set_online_state(struct pass_resource *res, int cpu, int on) { struct pass_resource_hotplug_ops *hotplug; - char *res_name; - int res_type; if (!res || cpu < 0 || on < 0) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - hotplug = get_hotplug(res, res_type); + hotplug = get_hotplug(res, res->cdata.res_type); if (!hotplug) return -EINVAL; if (!hotplug->set_online_state) return -EINVAL; - return hotplug->set_online_state(res_name, cpu, on); + return hotplug->set_online_state(res->cdata.res_name, cpu, on); } int pass_get_online_min_num(struct pass_resource *res) { struct pass_resource_hotplug_ops *hotplug; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - hotplug = get_hotplug(res, res_type); + hotplug = get_hotplug(res, res->cdata.res_type); if (!hotplug) return -EINVAL; if (!hotplug->get_online_min_num) return -EINVAL; - return hotplug->get_online_min_num(res_name); + return hotplug->get_online_min_num(res->cdata.res_name); } int pass_set_online_min_num(struct pass_resource *res, int num) { struct pass_resource_hotplug_ops *hotplug; - char *res_name; - int res_type; if ((!res) || (num < 0)) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - hotplug = get_hotplug(res, res_type); + hotplug = get_hotplug(res, res->cdata.res_type); if (!hotplug) return -EINVAL; if (!hotplug->set_online_min_num) return -EINVAL; - return hotplug->set_online_min_num(res_name, num); + return hotplug->set_online_min_num(res->cdata.res_name, num); } int pass_get_online_max_num(struct pass_resource *res) { struct pass_resource_hotplug_ops *hotplug; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - hotplug = get_hotplug(res, res_type); + hotplug = get_hotplug(res, res->cdata.res_type); if (!hotplug) return -EINVAL; if (!hotplug->get_online_max_num) return -EINVAL; - return hotplug->get_online_max_num(res_name); + return hotplug->get_online_max_num(res->cdata.res_name); } int pass_set_online_max_num(struct pass_resource *res, int num) { struct pass_resource_hotplug_ops *hotplug; - char *res_name; - int res_type; if ((!res) || (num < 0)) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - hotplug = get_hotplug(res, res_type); + hotplug = get_hotplug(res, res->cdata.res_type); if (!hotplug) return -EINVAL; if (!hotplug->set_online_max_num) return -EINVAL; - return hotplug->set_online_max_num(res_name, num); + return hotplug->set_online_max_num(res->cdata.res_name, num); } /* Get the temperature and thermal policy for Thermal resource. */ int pass_get_temp(struct pass_resource *res) { struct pass_resource_tmu_ops *tmu; - char *res_thermal_name; - int res_type; if (!res) return -EINVAL; - /* - * In the case of the HAL TMU ops, - * res_thermal_name is used as the first argument, - * instead of res_name. - */ - res_thermal_name = res->cdata.res_thermal_name; - res_type = res->cdata.res_type; - - tmu = get_tmu(res, res_type); + tmu = get_tmu(res, res->cdata.res_type); if (!tmu) return -EINVAL; if (!tmu->get_temp) return -EINVAL; - return tmu->get_temp(res_thermal_name); + /* + * In the case of the HAL TMU ops, res_thermal_name is used + * as the first argument instead of res_name. + */ + return tmu->get_temp(res->cdata.res_thermal_name); } int pass_get_tmu_policy(struct pass_resource *res, char *policy) { struct pass_resource_tmu_ops *tmu; - char *res_thermal_name; - int res_type; if (!res || !policy) return -EINVAL; - /* - * In the case of the HAL TMU ops, - * res_thermal_name is used as the first argument, - * instead of res_name. - */ - res_thermal_name = res->cdata.res_thermal_name; - res_type = res->cdata.res_type; - - tmu = get_tmu(res, res_type); + tmu = get_tmu(res, res->cdata.res_type); if (!tmu) return -EINVAL; if (!tmu->get_policy) return -EINVAL; - return tmu->get_policy(res_thermal_name, policy); + /* + * In the case of the HAL TMU ops, res_thermal_name is used + * as the first argument instead of res_name. + */ + return tmu->get_policy(res->cdata.res_thermal_name, policy); } int pass_set_fault_around_bytes(struct pass_resource *res, int fault_around_bytes) { struct pass_resource_memory *memory; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - switch (res_type) { + switch (res->cdata.res_type) { case PASS_RESOURCE_MEMORY_ID: memory = res->hal.memory; break; @@ -544,22 +442,17 @@ int pass_set_fault_around_bytes(struct pass_resource *res, if (!memory->set_fault_around_bytes) return -EINVAL; - return memory->set_fault_around_bytes(res_name, fault_around_bytes); + return memory->set_fault_around_bytes(res->cdata.res_name, fault_around_bytes); } int pass_get_fault_around_bytes(struct pass_resource *res) { struct pass_resource_memory *memory; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - switch (res_type) { + switch (res->cdata.res_type) { case PASS_RESOURCE_MEMORY_ID: memory = res->hal.memory; break; @@ -570,22 +463,17 @@ int pass_get_fault_around_bytes(struct pass_resource *res) if (!memory->get_fault_around_bytes) return -EINVAL; - return memory->get_fault_around_bytes(res_name); + return memory->get_fault_around_bytes(res->cdata.res_name); } int pass_set_pmqos_data(struct pass_resource *res, void *data) { struct pass_resource_nonstandard *nonstandard = NULL; - char *res_name; - int res_type; if (!res) return -EINVAL; - res_name = res->cdata.res_name; - res_type = res->cdata.res_type; - - switch (res_type) { + switch (res->cdata.res_type) { case PASS_RESOURCE_NONSTANDARD_ID: nonstandard = (res->hal.nonstandard); break; @@ -596,7 +484,7 @@ int pass_set_pmqos_data(struct pass_resource *res, void *data) if (!nonstandard->set_pmqos_data || !data) return -EINVAL; - return nonstandard->set_pmqos_data(res_name, data); + return nonstandard->set_pmqos_data(res->cdata.res_name, data); } static int pass_save_dvfs_initdata(struct pass_resource *res) @@ -751,24 +639,17 @@ static int pass_restore_memory_initdata(struct pass_resource *res) int pass_save_initdata(struct pass_resource *res) { - struct pass_conf_data *cdata; - char *res_name; - int res_type; int ret; if (!res) return -EINVAL; - cdata = &res->cdata; - res_name = cdata->res_name; - res_type = cdata->res_type; - - switch (res_type) { + switch (res->cdata.res_type) { case PASS_RESOURCE_CPU_ID: ret = pass_save_hotplug_initdata(res); if (ret < 0) { _E("Failed to save hp initdata for '%s' resource", - res_name); + res->cdata.res_name); return ret; } /* fall through */ @@ -777,7 +658,7 @@ int pass_save_initdata(struct pass_resource *res) ret = pass_save_dvfs_initdata(res); if (ret < 0) { _E("Failed to save dvfs initdata for '%s' resource", - res_name); + res->cdata.res_name); return ret; } break; @@ -785,14 +666,15 @@ int pass_save_initdata(struct pass_resource *res) ret = pass_save_memory_initdata(res); if (ret < 0) { _E("Failed to save memory initdata for '%s' resource", - res_name); + res->cdata.res_name); return ret; } break; case PASS_RESOURCE_NONSTANDARD_ID: break; default: - _E("Unsupported resource type (type: %d)\n", res_type); + _E("Unsupported resource type (type: %d)\n", + res->cdata.res_type); return -EINVAL; } @@ -801,24 +683,17 @@ int pass_save_initdata(struct pass_resource *res) int pass_restore_initdata(struct pass_resource *res) { - struct pass_conf_data *cdata; - char *res_name; - int res_type; int ret; if (!res) return -EINVAL; - cdata = &res->cdata; - res_name = cdata->res_name; - res_type = cdata->res_type; - - switch (res_type) { + switch (res->cdata.res_type) { case PASS_RESOURCE_CPU_ID: ret = pass_restore_hotplug_initdata(res); if (ret < 0) { _E("Failed to restore hp initdata for '%s' resource", - res_name); + res->cdata.res_name); return ret; } /* fall through */ @@ -827,7 +702,7 @@ int pass_restore_initdata(struct pass_resource *res) ret = pass_restore_dvfs_initdata(res); if (ret < 0) { _E("Failed to restore dvfs initdata for '%s' resource", - res_name); + res->cdata.res_name); return ret; } break; @@ -835,14 +710,15 @@ int pass_restore_initdata(struct pass_resource *res) ret = pass_restore_memory_initdata(res); if (ret < 0) { _E("Failed to restore memory data for '%s' resource", - res_name); + res->cdata.res_name); return ret; } break; case PASS_RESOURCE_NONSTANDARD_ID: break; default: - _E("Unsupported resource type (type: %d)\n", res_type); + _E("Unsupported resource type (type: %d)\n", + res->cdata.res_type); return -EINVAL; } @@ -851,20 +727,14 @@ int pass_restore_initdata(struct pass_resource *res) int pass_get_resource(struct pass_resource *res) { - struct pass_conf_data *cdata; struct pass_resource_info *info; - char *res_name; const char *name; - int res_type; int ret; if (!res) return -EINVAL; - cdata = &res->cdata; - res_name = cdata->res_name; - res_type = cdata->res_type; - switch (res_type) { + switch (res->cdata.res_type) { case PASS_RESOURCE_CPU_ID: name = PASS_RESOURCE_CPU_NAME; break; @@ -881,7 +751,8 @@ int pass_get_resource(struct pass_resource *res) name = PASS_RESOURCE_NONSTANDARD_NAME; break; default: - _E("Unsupported resource type (type: %d)\n", res_type); + _E("Unsupported resource type (type: %d)\n", + res->cdata.res_type); return -EINVAL; }; @@ -889,42 +760,42 @@ int pass_get_resource(struct pass_resource *res) (const struct pass_resource_info **)&info); if (ret < 0) { _E("Failed to get %s.so for '%s' resource\n", - name, res_name); + name, res->cdata.res_name); return -EINVAL; } if (!info->open || !info->close) { _E("Failed to get functions of %s.so for '%s' resource\n", - name, res_name); + name, res->cdata.res_name); return -EPERM; } - switch (res_type) { + switch (res->cdata.res_type) { case PASS_RESOURCE_CPU_ID: - ret = info->open(res_name, info, + ret = info->open(res->cdata.res_name, info, (struct pass_resource_common**)&res->hal.cpu); break; case PASS_RESOURCE_BUS_ID: - ret = info->open(res_name, info, + ret = info->open(res->cdata.res_name, info, (struct pass_resource_common**)&res->hal.bus); break; case PASS_RESOURCE_GPU_ID: - ret = info->open(res_name, info, + ret = info->open(res->cdata.res_name, info, (struct pass_resource_common**)&res->hal.gpu); break; case PASS_RESOURCE_MEMORY_ID: - ret = info->open(res_name, info, + ret = info->open(res->cdata.res_name, info, (struct pass_resource_common**)&res->hal.memory); break; case PASS_RESOURCE_NONSTANDARD_ID: - ret = info->open(res_name, info, + ret = info->open(res->cdata.res_name, info, (struct pass_resource_common**)&res->hal.nonstandard); break; }; if (ret < 0) { _E("Failed to open %s.so for '%s' resource\n", - name, res_name); + name, res->cdata.res_name); return -EINVAL; } @@ -933,44 +804,38 @@ int pass_get_resource(struct pass_resource *res) int pass_put_resource(struct pass_resource *res) { - struct pass_conf_data *cdata; struct pass_resource_common *common; struct pass_resource_info *info; - char *res_name; - int res_type; int ret; if (!res) return -EINVAL; - cdata = &res->cdata; - res_name = cdata->res_name; - res_type = cdata->res_type; - switch (res_type) { + switch (res->cdata.res_type) { case PASS_RESOURCE_CPU_ID: common = (struct pass_resource_common*)res->hal.cpu; info = res->hal.cpu->common.info; - ret = info->close(res_name, common); + ret = info->close(res->cdata.res_name, common); break; case PASS_RESOURCE_BUS_ID: common = (struct pass_resource_common*)res->hal.bus; info = res->hal.bus->common.info; - ret = info->close(res_name, common); + ret = info->close(res->cdata.res_name, common); break; case PASS_RESOURCE_GPU_ID: common = (struct pass_resource_common*)res->hal.gpu; info = res->hal.gpu->common.info; - ret = info->close(res_name, common); + ret = info->close(res->cdata.res_name, common); break; case PASS_RESOURCE_MEMORY_ID: common = (struct pass_resource_common*)res->hal.memory; info = res->hal.memory->common.info; - ret = info->close(res_name, common); + ret = info->close(res->cdata.res_name, common); break; case PASS_RESOURCE_NONSTANDARD_ID: common = (struct pass_resource_common*)res->hal.nonstandard; info = res->hal.nonstandard->common.info; - ret = info->close(res_name, common); + ret = info->close(res->cdata.res_name, common); break; default: return -EINVAL; @@ -978,7 +843,7 @@ int pass_put_resource(struct pass_resource *res) if (ret < 0) { _E("Failed to close %s.so for '%s' resource\n", - info->name, res_name); + info->name, res->cdata.res_name); return -EINVAL; }