Support old style vip cgroup 39/277339/6 submit/tizen/20220705.100432
authorUnsung Lee <unsung.lee@samsung.com>
Tue, 5 Jul 2022 08:39:15 +0000 (17:39 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 5 Jul 2022 08:51:14 +0000 (08:51 +0000)
+ add Process type of configuration

Change-Id: Idcc4b1a6da27160a9c164699006cabe17a72cdef
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/common/config-parser.c
src/common/config-parser.h
src/common/proc-common.h
src/process/priority/proc-priority.c
src/process/watchdog/proc-watchdog-handler.c
src/resourced/init.c
src/resourced/init.h
src/resourced/main.c

index 4162aa7..7e4ffc3 100644 (file)
@@ -669,14 +669,21 @@ static int vendor_config(struct parse_result *result, void *user_data)
        if (!result || !user_data)
                return RESOURCED_ERROR_INVALID_PARAMETER;
 
-       if (strncmp(result->section, PRIVATE_SECTION, strlen(PRIVATE_SECTION)+1))
-               return RESOURCED_ERROR_NONE;
+       if (strncmp(result->section, PRIVATE_SECTION, strlen(PRIVATE_SECTION)+1)) {
+               if (strncmp(result->section, OLD_VIP_GROUP_SECTION, strlen(OLD_VIP_GROUP_SECTION)+1)) {
+                       return RESOURCED_ERROR_NONE;
+               }
+       }
 
-       /* common(App or Service) */
-       if (!strncmp(result->name, SERVICE_NAME_CONF, strlen(SERVICE_NAME_CONF)+1) ||
-               !strncmp(result->name, APP_NAME_CONF, strlen(APP_NAME_CONF)+1)) {
+       /* common(App or Service or Process) */
+       if (!strncmp(result->name, APP_NAME_CONF, strlen(APP_NAME_CONF)+1)                 ||
+               !strncmp(result->name, SERVICE_NAME_CONF, strlen(SERVICE_NAME_CONF)+1)         ||
+           !strncmp(result->name, OLD_SERVICE_NAME_CONF, strlen(OLD_SERVICE_NAME_CONF)+1) ||
+               !strncmp(result->name, PROCESS_NAME_CONF, strlen(PROCESS_NAME_CONF)+1)         ||
+               !strncmp(result->name, OLD_PROCESS_NAME_CONF, strlen(OLD_PROCESS_NAME_CONF)+1)) {
                pci = fixed_app_and_service_exist_check(result->value,
-                               result->name[0] == 'A' ? APP_TYPE : SERVICE_TYPE);
+                               result->name[0] == 'A' ? APP_TYPE :
+                               result->name[0] == 'S' ? SERVICE_TYPE : PROCESS_TYPE);
                if (pci == NULL) {
                        pci = (struct proc_conf_info *)calloc(1, sizeof(struct proc_conf_info));
                        if (pci == NULL) {
@@ -691,12 +698,12 @@ static int vendor_config(struct parse_result *result, void *user_data)
                        pci->cpu_boosting_level = CPU_BOOSTING_LEVEL_NONE;
                        strncpy(pci->name, result->value, sizeof(pci->name)-1);
 
-                       if (result->name[0] == 'A') {
+                       if (result->name[0] == 'A')
                                fixed_app_list_insert(pci);
-                       }
-                       else {
+                       else if (result->name[0] == 'S')
                                fixed_service_list_insert(pci);
-                       }
+                       else
+                               fixed_process_list_insert(pci);
                }
        }
        /* limiter.conf.d */
@@ -850,6 +857,23 @@ static int vendor_config(struct parse_result *result, void *user_data)
                        return RESOURCED_ERROR_INVALID_PARAMETER;
                }
        }
+       /* old style */
+       else if (!strncmp(result->name, OLD_ACTION_ON_FAILURE_NAME_CONF,
+                               strlen(OLD_ACTION_ON_FAILURE_NAME_CONF)+1) && *config_type == VIP_CONFIG) {
+               if (!pci) {
+                       _E("process configuration information pointer should not be NULL");
+                       return RESOURCED_ERROR_FAIL;
+               }
+
+               if (!strncmp(result->value, ACTION_REBOOT_VALUE_CONF,
+                                       strlen(ACTION_REBOOT_VALUE_CONF) +1)) {
+                       pci->fail_action = PROC_ACTION_REBOOT;
+               }
+               else {
+                       _E("invalid parameter (%s)", result->value);
+                       return RESOURCED_ERROR_INVALID_PARAMETER;
+               }
+       }
        else {
                _E("Unknown configuration name (%s) and value (%s) on section (%s)",
                                result->name, result->value, result->section);
@@ -903,6 +927,10 @@ void resourced_parse_vendor_configs(void)
        /* Load configuration in process.conf */
        config_type = PROCESS_CONFIG;
        load_per_vendor_configs(PROC_CONF_DIR, vendor_config, &config_type);
+
+       /* old style */
+       config_type = VIP_CONFIG;
+       load_per_vendor_configs(VIP_CONF_DIR, vendor_config, &config_type);
 }
 
 void resourced_free_vendor_configs(void)
index 5e82945..66787d7 100644 (file)
@@ -35,6 +35,8 @@ extern "C" {
 #define LIMITER_CONF_DIR                    RD_CONFIG_PATH"/limiter.conf.d"
 #define OPTIMIZER_CONF_DIR                  RD_CONFIG_PATH"/optimizer.conf.d"
 #define PROC_CONF_DIR                       RD_CONFIG_PATH"/process.conf.d"
+/* old style */
+#define VIP_CONF_DIR                        RD_CONFIG_PATH"/vip-process.d"
 
 /* section name */
 /* limiter.conf */
@@ -44,6 +46,7 @@ extern "C" {
 #define MEMORY_APP_STATUS_LIMIT_SECTION     "MemoryAppStatusLimit"
 #define MEMORY_THROTTLING_SECTION           "MemoryThrottling"
 #define CPU_THROTTLING_SECTION              "CpuThrottling"
+#define OLD_VIP_GROUP_SECTION               "VIP_GROUP"
 
 /* optimizer.conf */
 #define SWAP_SECTION                        "MemorySwap"
@@ -60,11 +63,15 @@ extern "C" {
 
 /* configuration name */
 /* limiter.conf */
-#define SERVICE_NAME_CONF                            "Service"
 #define APP_NAME_CONF                                "App"
+#define SERVICE_NAME_CONF                            "Service"
+#define OLD_SERVICE_NAME_CONF                        "SERVICE"  /* old style */
+#define PROCESS_NAME_CONF                            "Process"
+#define OLD_PROCESS_NAME_CONF                        "PROCESS" /* old style */
 #define MEM_CGROUP_NAME_CONF                         "MemGroup"
 #define MEM_LIMIT_ACTION_NAME_CONF                   "MemLimitAction"
 #define ACTION_ON_FAILURE_NAME_CONF                  "ActionOnFailure"
+#define OLD_ACTION_ON_FAILURE_NAME_CONF              "ACTION_ON_FAILURE"
 #define        WATCHDOG_ACTION_NAME_CONF                    "WatchdogAction"
 #define THROTTLING_LIMIT_NAME_CONF                   "ThrottlingLimit"
 #define MEDIUM_LEVEL_NAME_CONF                       "MediumLevel"
@@ -139,6 +146,7 @@ enum config_type {
        OPTIMIZER_CONFIG,
        MONITOR_CONFIG,
        PROCESS_CONFIG,
+       VIP_CONFIG, /* old style */
 };
 
 struct parse_result {
index 9ac5960..ce9df5c 100644 (file)
@@ -58,6 +58,7 @@ enum proc_action {
 enum proc_type {
        APP_TYPE,
        SERVICE_TYPE,
+       PROCESS_TYPE,
 };
 
 struct proc_conf_info {
@@ -285,10 +286,10 @@ void fixed_app_and_service_list_init(void);
 void fixed_app_and_service_list_exit(void);
 void fixed_app_list_insert(struct proc_conf_info *pci);
 void fixed_service_list_insert(struct proc_conf_info *pci);
-void fixed_limit_pid_list_insert(pid_t pid, void *value);
-void fixed_limit_pid_list_remove(pid_t pid);
+void fixed_process_list_insert(struct proc_conf_info *pci);
 GHashTable* fixed_app_list_get(void);
 GHashTable * fixed_service_list_get(void);
+GHashTable * fixed_process_list_get(void);
 struct proc_conf_info* fixed_app_and_service_exist_check(const char *name, enum proc_type proc_type);
 enum proc_action fixed_app_and_service_watchdog_action(const char *name, enum proc_type proc_type);
 
index 483f0c6..ea62ad0 100644 (file)
 
 static GHashTable *fixed_app_list;
 static GHashTable *fixed_service_list;
+static GHashTable *fixed_process_list;
 
 void fixed_app_and_service_list_init(void)
 {
        fixed_app_list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free);
        fixed_service_list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free);
-       g_assert(fixed_app_list && fixed_service_list);
+       fixed_process_list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free);
+       g_assert(fixed_app_list && fixed_service_list && fixed_process_list);
 }
 
 void fixed_app_and_service_list_exit(void)
@@ -55,6 +57,8 @@ void fixed_app_and_service_list_exit(void)
                g_hash_table_destroy(fixed_app_list);
        if (fixed_service_list)
                g_hash_table_destroy(fixed_service_list);
+       if (fixed_process_list)
+               g_hash_table_destroy(fixed_process_list);
 }
 
 void fixed_app_list_insert(struct proc_conf_info *pci)
@@ -67,9 +71,9 @@ void fixed_service_list_insert(struct proc_conf_info *pci)
        g_hash_table_insert(fixed_service_list, (gpointer)pci->name, (gpointer)pci);
 }
 
-GHashTable* fixed_service_list_get(void)
+void fixed_process_list_insert(struct proc_conf_info *pci)
 {
-       return fixed_service_list;
+       g_hash_table_insert(fixed_process_list, (gpointer)pci->name, (gpointer)pci);
 }
 
 GHashTable* fixed_app_list_get(void)
@@ -77,10 +81,20 @@ GHashTable* fixed_app_list_get(void)
        return fixed_app_list;
 }
 
+GHashTable* fixed_service_list_get(void)
+{
+       return fixed_service_list;
+}
+
+GHashTable* fixed_process_list_get(void)
+{
+       return fixed_process_list;
+}
+
 struct proc_conf_info* fixed_app_and_service_exist_check(const char *name, enum proc_type proc_type)
 {
-       if (proc_type != APP_TYPE && proc_type != SERVICE_TYPE) {
-               _E("Unknown type (we support only service and app types)");
+       if (proc_type != APP_TYPE && proc_type != SERVICE_TYPE && proc_type != PROCESS_TYPE) {
+               _E("Unknown type (we support only app, service, and process types)");
                return NULL;
        }
 
@@ -90,12 +104,18 @@ struct proc_conf_info* fixed_app_and_service_exist_check(const char *name, enum
 
                return (struct proc_conf_info *)g_hash_table_lookup(fixed_app_list, name);
        }
-       else {
+       else if (proc_type == SERVICE_TYPE) {
                if (g_hash_table_size(fixed_service_list) == 0)
                        return NULL;
 
                return (struct proc_conf_info *)g_hash_table_lookup(fixed_service_list, name);
        }
+       else {
+               if (g_hash_table_size(fixed_process_list) == 0)
+                       return NULL;
+
+               return (struct proc_conf_info *)g_hash_table_lookup(fixed_process_list, name);
+       }
 }
 
 enum proc_action fixed_app_and_service_watchdog_action(const char *name, enum proc_type proc_type)
index 63d900c..c9aad68 100644 (file)
@@ -82,6 +82,7 @@ int main(int argc, char *argv[])
 
        fd = open(CHECK_RELEASE_PROGRESS, O_RDWR);
        if (fd >= 0) {
+               _D("[WATCHDOG] Release_agent is currently running.");
                close(fd);
                return 0;
        }
index 10451f2..b12d65f 100644 (file)
@@ -106,16 +106,33 @@ write_pid:
        return fwrite_uint(RUNTIME_RESOURCED_PID_PATH, (u_int32_t)pid);
 }
 
-static void sig_term_handler(int sig)
+static void sig_int_handler(int sig)
 {
-       _E("sigterm or sigint received");
+       _E("signal = %d is received", sig);
        resourced_quit_mainloop();
 }
 
+static void sig_term_handler(int sig, siginfo_t *siginfo, void *context)
+{
+       char appname[PROC_NAME_MAX];
+       pid_t sender_pid = siginfo->si_pid;
+
+       proc_get_cmdline(sender_pid, appname, sizeof(appname));
+       _D("signal = %d sender pid = %d (%s)", sig, sender_pid, appname);
+       _I("Do not quit resourced");
+//     resourced_quit_mainloop();
+}
+
 static void add_signal_handler(void)
 {
-       signal(SIGTERM, sig_term_handler);
-       signal(SIGINT, sig_term_handler);
+       struct sigaction sig_act;
+
+       sig_act.sa_sigaction = sig_term_handler;
+       sig_act.sa_flags = 0;
+       sig_act.sa_flags |= SA_SIGINFO;
+       sigaction(SIGTERM, &sig_act, NULL);
+//     signal(SIGTERM, sig_term_handler);
+       signal(SIGINT, sig_int_handler);
 }
 
 GMainLoop *get_main_loop(void)
@@ -214,7 +231,7 @@ void resourced_quit_mainloop(void)
        g_source_attach(shared_data->darg->mainloop_quit, NULL);
 }
 
-int fixed_service_list_init(void *data)
+int fixed_list_init(enum proc_type proc_type)
 {
        int error;
        gpointer key;
@@ -222,7 +239,14 @@ int fixed_service_list_init(void *data)
        GHashTableIter iter;
        struct sched_attr attr;
 
-       g_hash_table_iter_init(&iter, fixed_service_list_get());
+       if (proc_type == SERVICE_TYPE)
+               g_hash_table_iter_init(&iter, fixed_service_list_get());
+       else if (proc_type == PROCESS_TYPE)
+               g_hash_table_iter_init(&iter, fixed_process_list_get());
+       else {
+               _E("Unknown proc_type = %d", proc_type);
+               return RESOURCED_ERROR_FAIL;
+       }
 
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                struct proc_conf_info *pci = (struct proc_conf_info *)value;
@@ -236,13 +260,17 @@ int fixed_service_list_init(void *data)
                }
 
                if (strncmp(pci->name, name, strlen(name) +1)) {
-                       _E("key (%s) should be same with service name (%s)", name, pci->name);
+                       _E("key (%s) should be same with name (%s)", name, pci->name);
                        continue;
                }
 
-               variant = systemd_get_service_property(pci->name, "ExecMainPID");
-               if (!g_variant_get_safe(variant, "u", &pid))
-                       _E("Failed to get pid of a service (%s)", pci->name);
+               if (proc_type == SERVICE_TYPE) {
+                       variant = systemd_get_service_property(pci->name, "ExecMainPID");
+                       if (!g_variant_get_safe(variant, "u", &pid))
+                               _E("Failed to get pid of a service (%s)", pci->name);
+               }
+               else
+                       pid = find_pid_from_cmdline(pci->name);
 
                if (pid <= 0) {
                        _W("name (%s) pid should be larger than 0", pci->name);
@@ -251,7 +279,7 @@ int fixed_service_list_init(void *data)
 
                pci->pid = pid;
 
-               /* Put a system service into (cpu) throttling group */
+               /* Put a system service or process into (cpu) throttling group */
                if (pci->cpu_throttling_enable) {
                        struct proc_status ps = {0, };
                        ps.pid = pid;
@@ -265,17 +293,15 @@ int fixed_service_list_init(void *data)
                        pci->cpu_sched_info.cpu_nice <= CPU_MAX_NICE) {
                        attr.sched_nice = pci->cpu_sched_info.cpu_nice;
                }
-               else {
+               else
                        attr.sched_nice = CPU_INIT_NICE;
-               }
 
                if (pci->cpu_sched_info.cpu_rt_priority >= CPU_MIN_PRIO &&
                    pci->cpu_sched_info.cpu_rt_priority <= CPU_MAX_PRIO) {
                        attr.sched_priority = pci->cpu_sched_info.cpu_rt_priority;
                }
-               else {
+               else
                        attr.sched_priority = CPU_INIT_PRIO;
-               }
 
                switch (pci->cpu_sched_info.cpu_sched_type) {
                        case CPU_SCHED_NONE:
@@ -356,7 +382,7 @@ int fixed_service_list_init(void *data)
                _I("[CPU-SCHED] %s's priority = %d", pci->name, attr.sched_priority);
 
 skip_scheduler_update:
-               /* Put a system service into (cpu) boosting group */
+               /* Put a system service or process into (cpu) boosting group */
                if (pci->cpu_boosting_level != CPU_BOOSTING_LEVEL_NONE) {
                        struct proc_status ps = {0, };
                        ps.pid = pid;
@@ -364,7 +390,7 @@ skip_scheduler_update:
                        resourced_notify(RESOURCED_NOTIFIER_BOOSTING_RESOURCE, &ps);
                }
 
-               /* register a notification when this service is released */
+               /* register a notification when this service or process is released */
                switch (pci->fail_action) {
                        case PROC_ACTION_REBOOT:
                                proc_watchdog_booting_done(pci->name, pid);
@@ -375,11 +401,11 @@ skip_scheduler_update:
                                _W("[WATCHDOG] Currently we support only REBOOT when a service is released");
                }
 
-               /* Put a system service into (memory) throttling group */
+               /* Put a system service or process into (memory) throttling group */
                if (pci->memory_throttling_enable)
                        cgroup_write_pid_fullpath(MEMCG_THROTTLING_PATH, pid);
 
-               /* register a notification when this service memory is over a threshold */
+               /* register a notification when this service or process memory is over a threshold */
                if (pci->mem_action.memory_bytes && pci->mem_action.action) {
                        struct proc_limit_status pls = {0, };
 
@@ -394,3 +420,10 @@ skip_scheduler_update:
        return RESOURCED_ERROR_NONE;
 }
 
+int fixed_service_and_process_list_init(void *data)
+{
+       fixed_list_init(SERVICE_TYPE);
+       fixed_list_init(PROCESS_TYPE);
+
+       return RESOURCED_ERROR_NONE;
+}
index fbba3c2..c4ec969 100644 (file)
@@ -50,7 +50,7 @@ int resourced_deinit(void);
 GMainLoop *get_main_loop(void);
 
 void resourced_quit_mainloop(void);
-int fixed_service_list_init(void *data);
+int fixed_service_and_process_list_init(void *data);
 
 struct counter_arg;
 
index bb09959..97e0748 100644 (file)
@@ -57,7 +57,7 @@ int main(int argc, char **argv)
         * ex) /etc/resourced/xxx.d/yyy.conf
         */
        resourced_parse_vendor_configs();
-       register_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, fixed_service_list_init);
+       register_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, fixed_service_and_process_list_init);
 
        if (resourced_restarted()) {
                _I("Relaunched. Start to initialize and restore");
@@ -78,7 +78,7 @@ int main(int argc, char **argv)
        g_main_loop_run(mainloop);
        g_main_loop_quit(mainloop);
 
-       unregister_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, fixed_service_list_init);
+       unregister_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, fixed_service_and_process_list_init);
        /* free all allocated memory to store configuration information */
        resourced_free_vendor_configs();