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)
#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")))
/**
#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];
}
}
+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,
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;
{
*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;
}