cpu-boosting: Move cpu boosting common struct to libsyscommon 26/297126/5
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 9 Aug 2023 12:52:19 +0000 (21:52 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Mon, 28 Aug 2023 01:49:13 +0000 (10:49 +0900)
Extract cpu boosting common struct and move it to libsyscmmon to be referenced
between resourced cpu boosting module and cpu boosting plugin backend.

structure name is changed like below for consistency:
  - cpu_boosting_info -> syscommon_resourced_cpu_boosting_info
  - cpu_boosting_input -> syscommon_resourced_cpu_boosting_input

Change-Id: Id1296115c984cd03250cbb3cf182b79f4067ecaf
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/common/conf/cpu-common.h
src/resource-optimizer/cpu/cpu-boosting.c

index 74e872f..4e4e0f1 100644 (file)
@@ -41,20 +41,6 @@ enum cpu_sched_type {
        CPU_SCHED_DEADLINE,
 };
 
-struct cpu_boosting_info {
-       pid_t tid;
-       int level;                     /* current boosting level */
-       guint gsource_id;              /* timer id */
-       int ref_cnt;                   /* Ref count */
-};
-
-struct cpu_boosting_input {
-       cpu_boosting_input_t client_input;
-       int sock;
-       guint *gsource_id;
-       bool remove_input;
-};
-
 struct cpu_sched_info {
        enum cpu_sched_type cpu_sched_type;
        int cpu_nice;                        /* fixed cpu nice */
index f68eb7b..458165b 100644 (file)
@@ -11,6 +11,8 @@
 
 #include <systemd/sd-daemon.h>
 
+#include <system/syscommon-plugin-resourced-cpu-boosting.h>
+
 #include "module.h"
 #include "macro.h"
 #include "util.h"
@@ -43,8 +45,8 @@ GMainContext *cpu_boosting_context;
 
 static void free_cpu_boosting_info(gpointer data)
 {
-       struct cpu_boosting_info *cpu_boosting_info =
-               (struct cpu_boosting_info *)data;
+       struct syscommon_resourced_cpu_boosting_info *cpu_boosting_info =
+               (struct syscommon_resourced_cpu_boosting_info *)data;
 
        assert(cpu_boosting_info);
 
@@ -66,7 +68,7 @@ static void remove_cpu_boosting_info_in_tables(int *tid)
 }
 
 static void find_cpu_boosting_info_in_tables(
-               struct cpu_boosting_info **cpu_boosting_info, int *tid)
+               struct syscommon_resourced_cpu_boosting_info **cpu_boosting_info, int *tid)
 {
        assert(cpu_boosting_info);
 
@@ -173,7 +175,8 @@ static int cpu_boosting_get_tids(pid_t pid, resource_pid_t *resource_pid)
 
 static void cpu_boosting_destroy_request(gpointer data)
 {
-       struct cpu_boosting_input *input = (struct cpu_boosting_input *)data;
+       struct syscommon_resourced_cpu_boosting_input *input =
+               (struct syscommon_resourced_cpu_boosting_input *)data;
 
        if (input == NULL)
                return;
@@ -187,12 +190,14 @@ static void cpu_boosting_destroy_request(gpointer data)
        if (input->gsource_id)
                g_free(input->gsource_id);
 
-       g_slice_free(struct cpu_boosting_input, input);
+       g_slice_free(struct syscommon_resourced_cpu_boosting_input, input);
 }
 
-static struct cpu_boosting_input *cpu_boosting_new_request(void)
+static struct syscommon_resourced_cpu_boosting_input *
+cpu_boosting_new_request(void)
 {
-       struct cpu_boosting_input *input = g_slice_new0(struct cpu_boosting_input);
+       struct syscommon_resourced_cpu_boosting_input *input =
+               g_slice_new0(struct syscommon_resourced_cpu_boosting_input);
        if (input == NULL) {
                _E("[CPU-BOOSTING] Failed to allocate memory for cpu boosting input");
                return NULL;
@@ -335,12 +340,14 @@ remove_output:
                free(output.level.tid_level);
 }
 
-static int cpu_boosting_enqueue_by_socket(int sock, struct cpu_boosting_input **input_p)
+static int cpu_boosting_enqueue_by_socket(int sock,
+               struct syscommon_resourced_cpu_boosting_input **input_p)
 {
        int ret = RESOURCED_ERROR_NONE;
        int byte;
 
-       struct cpu_boosting_input *input = cpu_boosting_new_request();
+       struct syscommon_resourced_cpu_boosting_input *input =
+               cpu_boosting_new_request();
        if (input == NULL) {
                ret = RESOURCED_ERROR_OUT_OF_MEMORY;
                goto destroy_input;
@@ -482,7 +489,8 @@ destroy_input:
 }
 
 /* Called by resourced main thread */
-static int cpu_boosting_enqueue_by_conf(void *data, struct cpu_boosting_input **input)
+static int cpu_boosting_enqueue_by_conf(void *data,
+               struct syscommon_resourced_cpu_boosting_input **input)
 {
        assert(data);
 
@@ -523,7 +531,8 @@ static int cpu_boosting_enqueue_by_conf(void *data, struct cpu_boosting_input **
 static gboolean cpu_boosting_timeout(gpointer data)
 {
        int ret;
-       struct cpu_boosting_input *input = (struct cpu_boosting_input *)data;
+       struct syscommon_resourced_cpu_boosting_input *input =
+               (struct syscommon_resourced_cpu_boosting_input *)data;
 
        if (input == NULL) {
                _E("[CPU-BOOSTING] input argument of cpu boosting should not be NULL");
@@ -534,7 +543,7 @@ static gboolean cpu_boosting_timeout(gpointer data)
        int *tid_list = input->client_input.pid.tid;
 
        for (int i = 0; i < tid_count; i++) {
-               struct cpu_boosting_info *cpu_boosting_info = NULL;
+               struct syscommon_resourced_cpu_boosting_info *cpu_boosting_info = NULL;
 
                if (tid_list[i] <= 0) {
                        _W("[CPU-BOOSTING] Thread (id = %d) should be larger than 0", tid_list[i]);
@@ -581,7 +590,7 @@ timer_out:
 static void cpu_boosting_find_and_insert_info(pid_t tid,
                cpu_boosting_level_e cpu_boosting_level, guint id)
 {
-       struct cpu_boosting_info *cpu_boosting_info = NULL;
+       struct syscommon_resourced_cpu_boosting_info *cpu_boosting_info = NULL;
 
        switch (cpu_boosting_level) {
        case CPU_BOOSTING_LEVEL_STRONG:
@@ -596,8 +605,8 @@ static void cpu_boosting_find_and_insert_info(pid_t tid,
 
        find_cpu_boosting_info_in_tables(&cpu_boosting_info, &tid);
        if (cpu_boosting_info == NULL) {
-               cpu_boosting_info = (struct cpu_boosting_info *)
-                       calloc(1, sizeof (struct cpu_boosting_info));
+               cpu_boosting_info = (struct syscommon_resourced_cpu_boosting_info *)
+                       calloc(1, sizeof (struct syscommon_resourced_cpu_boosting_info));
                if (cpu_boosting_info == NULL) {
                        _E("[CPU-BOOSTING] Failed to allocate memory");
                        return;
@@ -628,7 +637,8 @@ static void cpu_boosting_find_and_insert_info(pid_t tid,
        cpu_boosting_info->gsource_id = id;
 }
 
-static void cpu_boosting_set(struct cpu_boosting_input *input)
+static void
+cpu_boosting_set(struct syscommon_resourced_cpu_boosting_input *input)
 {
        guint id = 0;
        int fail_cnt = 0;
@@ -703,7 +713,7 @@ static void cpu_boosting_set(struct cpu_boosting_input *input)
                cpu_boosting_destroy_request(input);
 }
 
-static void cpu_boosting_clear(struct cpu_boosting_input *input)
+static void cpu_boosting_clear(struct syscommon_resourced_cpu_boosting_input *input)
 {
        int ret;
        int fail_cnt = 0;
@@ -737,7 +747,7 @@ static void cpu_boosting_clear(struct cpu_boosting_input *input)
                cpu_boosting_destroy_request(input);
 }
 
-static void cpu_boosting_get(struct cpu_boosting_input *input)
+static void cpu_boosting_get(struct syscommon_resourced_cpu_boosting_input *input)
 {
        int fail_cnt = 0;
        int success_cnt = 0;
@@ -755,7 +765,7 @@ static void cpu_boosting_get(struct cpu_boosting_input *input)
        }
 
        for (int i = 0; i < tid_count; i++) {
-               struct cpu_boosting_info *cpu_boosting_info = NULL;
+               struct syscommon_resourced_cpu_boosting_info *cpu_boosting_info = NULL;
 
                if (tid_list[i] <= 0) {
                        fail_cnt++;
@@ -791,13 +801,15 @@ output_update:
        cpu_boosting_destroy_request(input);
 }
 
-static void cpu_boosting_set_inheritance(struct cpu_boosting_input *input)
+static void
+cpu_boosting_set_inheritance(struct syscommon_resourced_cpu_boosting_input *input)
 {
+       struct syscommon_resourced_cpu_boosting_info *cpu_boosting_info = NULL;
+       struct syscommon_resourced_cpu_boosting_input *input_dest;
        pid_t source_tid;
        struct sched_attr attr;
        cpu_boosting_level_e boosting_level;
-       struct cpu_boosting_info *cpu_boosting_info = NULL;
-       struct cpu_boosting_input *input_dest;
+
 
        source_tid = input->client_input.pid.pid;
        if (source_tid <= 0) {
@@ -848,9 +860,11 @@ destroy_input:
        cpu_boosting_destroy_request(input);
 }
 
-static void cpu_boosting_clear_inheritance(struct cpu_boosting_input *input)
+static void
+cpu_boosting_clear_inheritance(struct syscommon_resourced_cpu_boosting_input *input)
 {
-       struct cpu_boosting_input *input_dest = g_hash_table_lookup(dest_table, input->client_input.dest);
+       struct syscommon_resourced_cpu_boosting_input *input_dest =
+               g_hash_table_lookup(dest_table, input->client_input.dest);
        if (input_dest == NULL) {
                _E("[CPU-BOOSTING] %s is not registered before", input->client_input.dest);
                goto destroy_input;
@@ -875,7 +889,8 @@ destroy_input:
        cpu_boosting_destroy_request(input);
 }
 
-static void cpu_boosting_register_destination(struct cpu_boosting_input *input)
+static void cpu_boosting_register_destination(
+               struct syscommon_resourced_cpu_boosting_input *input)
 {
        if (input->client_input.dest == NULL) {
                _E("[CPU-BOOSTING] Boosting target name cannot be NULL");
@@ -899,7 +914,8 @@ static void cpu_boosting_register_destination(struct cpu_boosting_input *input)
        g_hash_table_insert(dest_table, (gpointer)input->client_input.dest, input);
 }
 
-static void cpu_boosting_unregister_destination(struct cpu_boosting_input *input)
+static void cpu_boosting_unregister_destination(
+               struct syscommon_resourced_cpu_boosting_input *input)
 {
        if (input->client_input.dest == NULL) {
                _E("[CPU-BOOSTING] Boosting target name cannot be NULL");
@@ -907,7 +923,8 @@ static void cpu_boosting_unregister_destination(struct cpu_boosting_input *input
        }
 
 #ifdef CONFIG_DEBUG_CPU_BOOSTING
-       struct cpu_boosting_input *input_dest = g_hash_table_lookup(dest_table, input->client_input.dest);
+       struct syscommon_resourced_cpu_boosting_input *input_dest =
+               g_hash_table_lookup(dest_table, input->client_input.dest);
        if (input_dest == NULL) {
                _E("[CPU-BOOSTING] %s does not registered before", input->client_input.dest);
                return;
@@ -986,7 +1003,8 @@ close_sock:
        return 0;
 }
 
-static void cpu_boosting_handle_command(struct cpu_boosting_input *input)
+static void
+cpu_boosting_handle_command(struct syscommon_resourced_cpu_boosting_input *input)
 {
        if (!input) {
                _E("[CPU-BOOSTING] Cpu boosting input data structure should not be NULL");
@@ -1031,7 +1049,7 @@ static void cpu_boosting_handle_command(struct cpu_boosting_input *input)
 static int cpu_boosting_recv_from_conf(void *data)
 {
        int ret;
-       struct cpu_boosting_input *input = NULL;
+       struct syscommon_resourced_cpu_boosting_input *input = NULL;
 
        if ((ret = cpu_boosting_enqueue_by_conf(data, &input)) < 0 ||
                        input == NULL)
@@ -1052,7 +1070,7 @@ static int cpu_boosting_recv_from_conf(void *data)
 static bool cpu_boosting_recv_from_client(int fd, void *data)
 {
        int client_sock = fd;
-       struct cpu_boosting_input *input = NULL;
+       struct syscommon_resourced_cpu_boosting_input *input = NULL;
 
        if (client_sock <= 0) {
                _E("[CPU-BOOSTING] client socket should be larger than 0");