pass: thermal: Set a separate threshold for warning level reduction 88/263888/5
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 14 Sep 2021 04:22:42 +0000 (13:22 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 16 Sep 2021 05:33:12 +0000 (14:33 +0900)
To prevent warning level is continuously changing at the edge of the
temperature range, this adds distinct thresholds for warning level
reduction.

Change-Id: I0f0e911c1b3a6ee88fa7b26162d076f811a8ffea
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
src/pass/pass-parser.c
src/pass/pass-thermal.c
src/pass/pass.h

index 323553097ff95439eb13cbb1e9752210a770c0ba..357ab1d8070939c109eb34f8b9823e98ad5a4699 100644 (file)
@@ -111,6 +111,7 @@ static int parse_scenario(struct pass_resource *res, json_object *obj,
        json_object *temperature;
        int temp_start;
        int temp_end;
+       int threshold;
        int timer_interval_ms;
 
        /* Get property values */
@@ -127,8 +128,12 @@ static int parse_scenario(struct pass_resource *res, json_object *obj,
        if (temperature) {
                temp_start = get_int_from_object(temperature, "start");
                temp_end = get_int_from_object(temperature, "end");
+               threshold = get_int_from_object(temperature, "threshold");
+               /* if threshold is not presented, using temp_end as default */
+               if (threshold < 0)
+                       threshold = temp_end;
        } else {
-               temp_start = temp_end = 0;
+               temp_start = temp_end = threshold = 0;
        }
 
        timer_interval_ms = get_int_from_object(obj, "timer_interval_ms");
@@ -140,9 +145,14 @@ static int parse_scenario(struct pass_resource *res, json_object *obj,
        } else if (target_level < 0) {
                _E("Failed to get 'target_level' property in scenario section\n");
                return -EINVAL;
-       } else if (temp_start < 0 || temp_end < 0 || temp_end < temp_start) {
-               _E("Invalid values for temperature property\n");
-               return -EINVAL;
+       } else if (temperature) {
+               if (temp_start < 0 || temp_end < 0 || temp_end < temp_start) {
+                       _E("Invalid temperature range in scenario section\n");
+                       return -EINVAL;
+               } else if (threshold < temp_start || threshold > temp_end) {
+                       _W("Invalid thermal 'threshold', using default as range 'end'\n");
+                       threshold = temp_end;
+               }
        }
 
        /* Initialize config_data from property values of confiugartion file */
@@ -157,6 +167,7 @@ static int parse_scenario(struct pass_resource *res, json_object *obj,
        /* - property for only thermal module */
        scenario->thermal.temp_start = temp_start;
        scenario->thermal.temp_end = temp_end;
+       scenario->thermal.threshold = threshold;
        scenario->thermal.timer_interval = timer_interval_ms;
 
        return 0;
index 585cd8c60d9b84a6e92dca66007c993c88bc7f94..fb3f159f0381d065ff23bb6ea0e938e6ef913888 100644 (file)
@@ -61,13 +61,22 @@ static int thermal_update(struct pass_resource *res,
        for (i = 0; i < thermal->num_scenarios; i++) {
                int temp_start = thermal->scenarios[i].thermal.temp_start;
                int temp_end = thermal->scenarios[i].thermal.temp_end;
+               int threshold = thermal->scenarios[i].thermal.threshold;
 
                if (thermal->scenarios[i].state != PASS_ON)
                        continue;
 
-               if (temp_start < new_temp && new_temp <= temp_end) {
-                       new_scenario_idx = i;
-                       break;
+               /* check if scenario level can be lower */
+               if (i < thermal->curr_scenario_idx) {
+                       if (temp_start < new_temp && new_temp <= threshold) {
+                               new_scenario_idx = i;
+                               break;
+                       }
+               } else {
+                       if (temp_start < new_temp && new_temp <= temp_end) {
+                               new_scenario_idx = i;
+                               break;
+                       }
                }
        }
 
index b2104f039df31901da08032b91aea35b7c8aa9a4..0fb09d08c934cfb01bef8b59692eaecca96e798e 100644 (file)
@@ -261,10 +261,14 @@ struct pass_scenario {
        struct {
                /**
                 * Range of temperature to determine scenario level represented
-                * as (temp_start, temp_end].
+                * as (temp_start, temp_end]. For scenario level reduction,
+                * temperature should be in range of (temp_start, threshold] to
+                * prevent scenario is repeatedly changed at edge of original
+                * range.
                 */
                int temp_start;
                int temp_end;
+               int threshold;
                /** Interval of timer-based monitor (unit: millisecond) */
                int timer_interval;
        } thermal;