From: Dongwoo Lee Date: Fri, 27 Aug 2021 05:49:49 +0000 (+0900) Subject: pass: thermal: Fix to handle priority of initial state properly X-Git-Tag: submit/tizen/20210827.070901~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f64ee46b2c4721a529236d5dfa0e3983223bddf;p=platform%2Fcore%2Fsystem%2Fpass.git pass: thermal: Fix to handle priority of initial state properly At first, priority is intended to treat lower value as higher priority, but it is not handled intentionally when monitoring devices. So this fixes to handle it properly and to this end it is required to retrieve highest priority from the corresponding thermal device. Finally, instead of plain scenario string the notifer_data structure is passed as THERMAL_GET_SCENARIO parameter to get both scenario and priority. Change-Id: I330729be2890cdcb89ee7a677af2c0b8d4905fb0 Signed-off-by: Dongwoo Lee --- diff --git a/src/pass/pass-thermal.c b/src/pass/pass-thermal.c index badfc9c..26d7b74 100644 --- a/src/pass/pass-thermal.c +++ b/src/pass/pass-thermal.c @@ -196,10 +196,9 @@ static int thermal_monitor_func(void *result, void *user_data) static void response_scenario(void *data, void *user_data) { - static int cur_priority = INT_MAX; struct pass_resource *res = data; struct pass_thermal *thermal = &res->thermal; - char **resp = user_data; + struct device_notifier_thermal_data *thermal_data = user_data; int priority = res->config_data.res_thermal_priority; char *scenario = thermal->scenarios[thermal->curr_scenario_idx].name; @@ -207,16 +206,17 @@ static void response_scenario(void *data, void *user_data) * Inform the thermal scenario name to * DEVICE_NOTIFIER_THERMAL_GET_SCENARIO client. */ - if (priority < cur_priority || !*resp) { - cur_priority = priority; - *resp = scenario; - } else if (priority == cur_priority) { + if (priority < thermal_data->priority || !thermal_data->scenario) { + thermal_data->priority = priority; + thermal_data->scenario = scenario; + } else if (priority == thermal_data->priority) { + char *cur = thermal_data->scenario; int i; for (i = 0; i < thermal->num_scenarios; i++) { - if (!strncmp(thermal->scenarios[i].name, *resp, strlen(*resp))) { - if (i < thermal->curr_scenario_idx) - *resp = scenario; + if (!strncmp(thermal->scenarios[i].name, cur, strlen(cur))) { + if (i > thermal->curr_scenario_idx) + thermal_data->scenario = scenario; break; } } diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index a58772c..06b0d65 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -106,7 +106,12 @@ static void thermal_free(void) */ static int thermal_init_done(void *data, void *user_data) { - char *scenario = NULL; + struct device_notifier_thermal_data initial_state = { + .scenario = NULL, + .priority = INT_MAX, + }; + char *scenario; + int priority; int ret, i; if (g_thermal) @@ -144,7 +149,10 @@ static int thermal_init_done(void *data, void *user_data) g_thermal->list[i].name); } - device_notify(DEVICE_NOTIFIER_THERMAL_GET_SCENARIO, &scenario); + device_notify(DEVICE_NOTIFIER_THERMAL_GET_SCENARIO, &initial_state); + + scenario = initial_state.scenario; + priority = initial_state.priority; if (!scenario) { _E("failed to get current scenario for thermal\n"); @@ -177,6 +185,7 @@ static int thermal_init_done(void *data, void *user_data) } g_thermal->cur_scenario_idx = i; + g_thermal->cur_priority = priority; return 0; } @@ -276,7 +285,7 @@ static int thermal_handle_notifier_data(struct device_notifier_thermal_data *dat * of current thermal data and if so, updates scenario, or else adds * data into current resource list. */ - if (priority > g_thermal->cur_priority) { + if (priority < g_thermal->cur_priority) { g_thermal->cur_priority = priority; g_ptr_array_free(g_thermal->resources, TRUE); g_thermal->resources = g_ptr_array_new_with_free_func(free); @@ -336,7 +345,7 @@ static int thermal_notifier_cb(void *data, void *user_data) scenario = thermal_data->scenario; /* Ignore the notification of lower priority resources */ - if (thermal_data->priority < g_thermal->cur_priority) + if (thermal_data->priority > g_thermal->cur_priority) return 0; ret = thermal_handle_notifier_data(thermal_data);