resourced-cpu-boosting: Add is_cpu_contention_alleviated() to check cpu contention 48/298248/3
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 1 Sep 2023 06:53:09 +0000 (15:53 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Mon, 4 Sep 2023 10:03:28 +0000 (19:03 +0900)
Add is_cpu_contention_alleviated to check whether cpu contention is alleviated
for restoring cpu boosting level.

Prototype of new function is like below:
  - bool is_cpu_contention_alleviated(
               guint timer_id, guint latest_timer_id);
    * After a stall event is monitored, a timer with some interval set.
      If no more stall events between setting timer and timeout,
      timer_id is equal to latest_timer_id.

Change-Id: I709414ff982ee08fb8a5465142e552e8e441fe04
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/resourced-cpu-boosting/resourced-cpu-boosting.c

index bc90a35f8c76f4646848153e51ed71c571d36958..3f7c043ddc85962331ba8ea229efbde6512d5e67 100644 (file)
@@ -29,6 +29,7 @@
 #include <libsyscommon/log.h>
 
 #define BOOSTING_LEVEL_DECREASE_CPU_UTIL_THRESHOLD     99.0
+#define BOOSTING_LEVEL_RESTORE_CPU_UTIL_THRESHOLD       90.0
 
 #define EXPORT __attribute__ ((visibility("default")))
 
@@ -176,6 +177,21 @@ static bool is_system_cpu_busy(double threshold)
        return true;
 }
 
+static bool is_cpu_contention_alleviated(guint timer_id, guint latest_timer_id)
+{
+       /**
+        * If additional monitor events are not triggered
+        * for interval, then restore CPU boosting level.
+        */
+       if (timer_id != latest_timer_id)
+               return false;
+
+       if (is_system_cpu_busy(BOOSTING_LEVEL_RESTORE_CPU_UTIL_THRESHOLD))
+               return false;
+
+       return true;
+}
+
 static int cpu_boosting_governor_govern_request (
                GHashTable *cpu_boosting_info_table,
                cpu_boosting_level_e cpu_boosting_level,
@@ -351,6 +367,7 @@ static int resourced_cpu_boosting_exit(void *data)
 
 static syscommon_plugin_backend_resourced_cpu_boosting_funcs g_cpu_boosting_funcs = {
        .cpu_boosting_governor_govern_request = cpu_boosting_governor_govern_request,
+       .is_cpu_contention_alleviated = is_cpu_contention_alleviated,
 };
 
 syscommon_plugin_backend EXPORT system_plugin_backend_resourced_cpu_boosting_data = {