pass: thermal: Fix to handle priority of initial state properly 67/263167/1
authorDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 27 Aug 2021 05:49:49 +0000 (14:49 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 27 Aug 2021 06:18:11 +0000 (15:18 +0900)
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 <dwoo08.lee@samsung.com>
src/pass/pass-thermal.c
src/thermal/thermal.c

index badfc9c4f930a914a548a773014b8e62525d4edc..26d7b74c7ac4b2be608a572e1aba0726127124e4 100644 (file)
@@ -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;
                        }
                }
index a58772cc8be457c894a936edba9d74c945c7ba5b..06b0d6546fad52db96b27173d179b32d0aad3b0f 100644 (file)
@@ -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);