resourced-cpu-boosting: Add is_system_cpu_busy() to check cpu contention 47/298247/3
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 30 Aug 2023 08:25:05 +0000 (17:25 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Mon, 4 Sep 2023 10:02:51 +0000 (19:02 +0900)
Add is_system_cpu_busy() function to check cpu contention. Although stall event
is monitored by resourced, do not change cpu boosting level unless
cpu contention.

Change-Id: Ie6e7287dd1ad3d0596423673bec695439596c29f
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
packaging/system-plugin-resourced-generic.spec
src/resourced-cpu-boosting/CMakeLists.txt
src/resourced-cpu-boosting/resourced-cpu-boosting.c

index 0c12cfce1a44876e526c288468dd0a7951794680..ab2fd851af4265bc82fd3f19102f7febd2b18363 100644 (file)
@@ -17,6 +17,7 @@ BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(libsyscommon)
 BuildRequires:  pkgconfig(libsyscommon-plugin-api-resourced)
 BuildRequires:  pkgconfig(capi-system-resource)
+BuildRequires:  pkgconfig(capi-system-resource-monitor)
 
 %description
 System plugin backend for resourced and generic profile
index 7f1942b51b4dcecf12ce9239122b555a3271ec54..50fc8c37cd3ac46c9e6f0e4ec0f4a0ad517ab7dd 100644 (file)
@@ -8,14 +8,16 @@ if (${PLUGIN_RESOURCED_CPU_BOOSTING_ENABLE_DLOG})
                libsyscommon
                libsyscommon-plugin-api-resourced
                glib-2.0
-               capi-system-resource)
+               capi-system-resource
+               capi-system-resource-monitor)
        ADD_DEFINITIONS("-DENABLE_DLOG")
        ADD_DEFINITIONS("-DLOG_TAG=\"SYSTEM_PLUGIN_RESOURCED_CPU_BOOSTING\"")
 else()
        SET(PKG_MODULES
                libsyscommon
                libsyscommon-plugin-api-resourced
-               capi-system-resource)
+               capi-system-resource
+               capi-system-resource-monitor)
 endif()
 
 INCLUDE(FindPkgConfig)
index 9657fe789af912c2d9839f18043d222d6e054ed9..bc90a35f8c76f4646848153e51ed71c571d36958 100644 (file)
 #include <assert.h>
 #include <glib.h>
 
+#include <system/resource-monitor.h>
 #include <system/syscommon-plugin-common-interface.h>
 #include <system/syscommon-plugin-resourced-cpu-boosting-interface.h>
 
 #include <libsyscommon/log.h>
 
+#define BOOSTING_LEVEL_DECREASE_CPU_UTIL_THRESHOLD     99.0
+
 #define EXPORT __attribute__ ((visibility("default")))
 
 /**
@@ -58,6 +61,10 @@ static syscommon_plugin_backend_resourced_cpu_boosting_funcs g_cpu_boosting_func
 #define PATH_BUF_MAX           256
 #define NAME_BUF_MAX           34
 
+int g_monitor_id;
+int g_system_resource_id;
+u_int64_t g_system_attr_mask;
+
 static bool is_in_cgroup_tasks(pid_t tid, const char *path)
 {
        char filename[PATH_BUF_MAX];
@@ -154,6 +161,21 @@ static void destroy_cpu_boosting_controller_action(
        }
 }
 
+static bool is_system_cpu_busy(double threshold)
+{
+       double cpu_util;
+
+       resource_monitor_update(g_monitor_id);
+
+       resource_monitor_get_value_double(g_monitor_id, g_system_resource_id,
+                       RESOURCE_MONITOR_SYSTEM_ATTR_CPU_UTIL, &cpu_util);
+
+       if (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,
@@ -180,6 +202,9 @@ static int cpu_boosting_governor_govern_request (
                goto error;
        }
 
+       if(!is_system_cpu_busy(BOOSTING_LEVEL_DECREASE_CPU_UTIL_THRESHOLD))
+               return 0;
+
        hash_size = g_hash_table_size(cpu_boosting_info_table);
        if (hash_size == 0)
                return 0;
@@ -308,6 +333,14 @@ static int resourced_cpu_boosting_init(void **data)
 {
        *data = (void *)&g_cpu_boosting_funcs;
 
+       g_monitor_id = resource_monitor_init();
+       g_system_resource_id = resource_monitor_create_resource(g_monitor_id,
+                       RESOURCE_MONITOR_TYPE_SYSTEM);
+       g_system_attr_mask = (RESOURCE_MONITOR_SYSTEM_ATTR_CPU_UTIL);
+
+       resource_monitor_set_resource_attr(g_monitor_id, g_system_resource_id,
+                       g_system_attr_mask);
+
        return 0;
 }