#define PATH_BUF_MAX 256
#define NAME_BUF_MAX 34
-int g_monitor_id;
-int g_system_resource_id;
+int g_monitor_id = 0;
+int g_system_resource_id = 0;
u_int64_t g_system_attr_mask;
static bool is_in_cgroup_tasks(pid_t tid, const char *path)
static int resourced_cpu_boosting_init(void **data)
{
- *data = (void *)&g_cpu_boosting_funcs;
-
+ /**
+ * TODO: If monitroing of system cpu util from resource-monitor
+ * failed due to some reasons, then replace monitoring source
+ * from resource-monitor to another.
+ */
g_monitor_id = resource_monitor_init();
+ if (g_monitor_id < 0) {
+ *data = NULL;
+ return g_monitor_id;
+ }
+
g_system_resource_id = resource_monitor_create_resource(g_monitor_id,
RESOURCE_MONITOR_TYPE_SYSTEM);
+ if (g_system_resource_id < 0) {
+ *data = NULL;
+ resource_monitor_exit(g_monitor_id);
+ g_monitor_id = 0;
+ return g_system_resource_id;
+ }
+
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);
+ *data = (void *)&g_cpu_boosting_funcs;
+
return 0;
}
static int resourced_cpu_boosting_exit(void *data)
{
+ if (g_system_resource_id > 0)
+ resource_monitor_delete_resource(g_monitor_id, g_system_resource_id);
+
+ if (g_monitor_id > 0)
+ resource_monitor_exit(g_monitor_id);
+
return 0;
}