pass: Change the unit for gov_timeout into milliseconds from seconds 34/280234/2
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 25 Aug 2022 08:04:01 +0000 (17:04 +0900)
committerDongwoo Lee <dwlee08@gmail.com>
Tue, 30 Aug 2022 07:10:11 +0000 (00:10 -0700)
Since comparing two floating point number variable causes unintended
result, it converts type of gov_timeout from double to int, and keeps
precison by using unint as milliseconds instead of seconds.
for instance, 0.2sec can represent as 200ms, so despite of converting
type, users can setup gov_timeout with same precision.

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

index 7848399..27cfeb6 100644 (file)
@@ -170,7 +170,7 @@ static int cpuhp_timer_func(void *result, void *user_data)
        struct pass_resource *res = user_data;
        struct pass_level *levels;
        struct pass_cpuhp *cpuhp;
-       double curr_gov_timeout, next_gov_timeout;
+       int curr_gov_timeout, next_gov_timeout;
        int level;
 
        if (!res) {
@@ -206,12 +206,12 @@ static int cpuhp_timer_func(void *result, void *user_data)
         * same as the current one
         */
        if (curr_gov_timeout != next_gov_timeout) {
-               _I("Change the period of governor timer from %fs to %fs\n",
+               _I("Change the period of governor timer from %dms to %dms\n",
                                curr_gov_timeout,
                                next_gov_timeout);
 
                pass_resmon_update_timer_interval(res, cpuhp->timer_id,
-                                               next_gov_timeout * 1000);
+                                               next_gov_timeout);
        }
 
        return TRUE;
@@ -240,7 +240,7 @@ static void cpuhp_governor_start(struct pass_resource *res)
        /* Register the resource-monitor for CPUHP module */
        ret = pass_resmon_register_timer(res, RESMON_SRC_CPUHP,
                        RESMON_TIMER_PERIODIC,
-                       res->config_data.gov_timeout * 1000,
+                       res->config_data.gov_timeout,
                        cpuhp_timer_func,
                        res);
        if (ret < 0) {
@@ -289,7 +289,7 @@ static int cpuhp_governor_init(struct pass_resource *res)
        struct pass_cpuhp *cpuhp = &res->cpuhp;
 
        if (res->config_data.gov_timeout < 0) {
-               _E("invalid timeout value [%lf]!", res->config_data.gov_timeout);
+               _E("invalid timeout value [%d]!", res->config_data.gov_timeout);
                cpuhp_governor_update(res, PASS_OFF);
                return -EINVAL;
        }
index 0c6d4d3..67e3f51 100644 (file)
@@ -45,8 +45,8 @@
 #include "pass.h"
 
 #define MAX_NUM                        255
-#define MIN_TIMEOUT_SEC                0.2     /* 200 millisecond */
-#define MAX_TIMEOUT_SEC                3600.0  /* 1 hour */
+#define MIN_TIMEOUT_MS         200
+#define MAX_TIMEOUT_MS         3600000 /* 1 hour */
 #define INIT_VALUE             -1
 
 static int compare_compatible_name(const char *compatible,
@@ -279,7 +279,7 @@ static int parse_level(struct pass_resource *res, json_object *obj,
        int num_left_cond_freq;
        int num_left_cond_nr_running;
        int num_left_cond_busy_cpu;
-       double governor_timeout_sec;
+       int governor_timeout_ms;
        int fault_around_bytes;
        int cooling_device_state;
        int charging_status;
@@ -334,8 +334,8 @@ static int parse_level(struct pass_resource *res, json_object *obj,
        ret += get_property(obj, "hotplug,num_left_cond_busy_cpu", DATA_TYPE_INT,
                                false, (void *)&num_left_cond_busy_cpu);
 
-       ret += get_property(obj, "hotplug,governor_timeout_sec", DATA_TYPE_DOUBLE,
-                               false, (void *)&governor_timeout_sec);
+       ret += get_property(obj, "hotplug,governor_timeout_ms", DATA_TYPE_INT,
+                               false, (void *)&governor_timeout_ms);
 
        ret += get_property(obj, "memory,fault_around_bytes", DATA_TYPE_INT,
                                false, (void *)&fault_around_bytes);
@@ -418,11 +418,11 @@ static int parse_level(struct pass_resource *res, json_object *obj,
        if (num_right_cond_busy_cpu >= 0)
                target_level->right_cond[0].busy_cpu = num_right_cond_busy_cpu;
 
-       if (governor_timeout_sec >= 0) {
-               if (governor_timeout_sec < MIN_TIMEOUT_SEC
-                       || governor_timeout_sec > MAX_TIMEOUT_SEC)
-                       governor_timeout_sec = MIN_TIMEOUT_SEC;
-               target_level->gov_timeout = governor_timeout_sec;
+       if (governor_timeout_ms >= 0) {
+               if (governor_timeout_ms < MIN_TIMEOUT_MS
+                       || governor_timeout_ms > MAX_TIMEOUT_MS)
+                       governor_timeout_ms = MIN_TIMEOUT_MS;
+               target_level->gov_timeout = governor_timeout_ms;
        }
 
        /*
@@ -583,7 +583,7 @@ static int parse_cpuhp(struct pass_resource *res, json_object *obj)
 {
        int cpuhp_support;
        int cpuhp_governor;
-       double cpuhp_timer_interval_sec;
+       int cpuhp_timer_interval_ms;
        int cpuhp_min_level;
        int cpuhp_max_level;
        int cpuhp_init_level;
@@ -598,8 +598,8 @@ static int parse_cpuhp(struct pass_resource *res, json_object *obj)
                                true, (void *)&cpuhp_support);
        ret += get_property(obj, "cpuhp_governor", DATA_TYPE_INT,
                                false, (void *)&cpuhp_governor);
-       ret += get_property(obj, "cpuhp_timer_interval_sec", DATA_TYPE_DOUBLE,
-                               false, (void *)&cpuhp_timer_interval_sec);
+       ret += get_property(obj, "cpuhp_timer_interval_ms", DATA_TYPE_INT,
+                               false, (void *)&cpuhp_timer_interval_ms);
        ret += get_property(obj, "cpuhp_min_level", DATA_TYPE_INT,
                                false, (void *)&cpuhp_min_level);
        ret += get_property(obj, "cpuhp_max_level", DATA_TYPE_INT,
@@ -638,10 +638,10 @@ static int parse_cpuhp(struct pass_resource *res, json_object *obj)
        /* - core */
        res->config_data.state = cpuhp_support;
        res->config_data.gov_type = cpuhp_governor;
-       res->config_data.gov_timeout = cpuhp_timer_interval_sec;
-       if (res->config_data.gov_timeout < MIN_TIMEOUT_SEC
-               || res->config_data.gov_timeout > MAX_TIMEOUT_SEC)
-               res->config_data.gov_timeout = MIN_TIMEOUT_SEC;
+       res->config_data.gov_timeout = cpuhp_timer_interval_ms;
+       if (res->config_data.gov_timeout < MIN_TIMEOUT_MS
+               || res->config_data.gov_timeout > MAX_TIMEOUT_MS)
+               res->config_data.gov_timeout = MIN_TIMEOUT_MS;
 
        /* - properties for rescon module */
        res->rescon.min_level = cpuhp_min_level;
index 509ed2b..7167688 100644 (file)
@@ -176,7 +176,7 @@ struct pass_level {
         * and this property is used for thefollowing resources:
         * - PASS_RESOURCE_CPU_ID
         */
-       double gov_timeout;
+       int gov_timeout;
 
        /* Properties for the GOV_RADIATION or GOV_STEP governor */
 
@@ -518,7 +518,7 @@ struct pass_resource_config_data {
        /** governor type */
        enum pass_gov_type gov_type;
        /** Interval for periodic timer */
-       double gov_timeout;
+       int gov_timeout;
        /** Default minimum level */
        unsigned int default_min_level;
        /** default maximum level */