Remove useless source code
[platform/core/system/resourced.git] / src / common / cgroup / cpu-cgroup.c
1 #include <assert.h>
2
3 #include "cpu-cgroup.h"
4 #include "trace.h"
5
6 static struct cpucg_conf *cpucg_conf = NULL;
7
8 char *get_cpucg_conf_name(void)
9 {
10         if (cpucg_conf)
11                 return cpucg_conf->name;
12         else
13                 return NULL;
14 }
15
16 char *get_cpucg_conf_value(void)
17 {
18         if (cpucg_conf)
19                 return cpucg_conf->value;
20         else
21                 return NULL;
22 }
23
24 int set_cpucg_conf(const char *name, const char *value)
25 {
26         cpucg_conf = (struct cpucg_conf *)calloc(1, sizeof (struct cpucg_conf));
27         if (!cpucg_conf) {
28                 _E("Failed to alloc memory for cpu configuration");
29                 return RESOURCED_ERROR_OUT_OF_MEMORY;
30         }
31
32         if (strlen(name) + 1 > sizeof(cpucg_conf->name)) {
33                 _E("Size of cpu configuration for name is not enough");
34                 return RESOURCED_ERROR_OUT_OF_MEMORY;
35         }
36         strncpy(cpucg_conf->name, name, sizeof(cpucg_conf->name) - 1);
37
38         if (strlen(value) + 1 > sizeof(cpucg_conf->value)) {
39                 _E("Size of cpu configuration for value is not enough");
40                 return RESOURCED_ERROR_OUT_OF_MEMORY;
41         }
42         strncpy(cpucg_conf->value, value, sizeof(cpucg_conf->value) - 1);
43
44         return RESOURCED_ERROR_NONE;
45 }
46
47 void free_cpucg_conf(void)
48 {
49         if (cpucg_conf)
50                 free(cpucg_conf);
51 }
52
53 static int cpu_move_cgroup(pid_t pid, char *path)
54 {
55         return cgroup_write_pid_fullpath(path, pid);
56 }
57
58 int cpu_move_cgroup_foreach(pid_t pid, struct proc_app_info *pai, char *path)
59 {
60         GSList *iter = NULL;
61         pid_t child_pid;
62
63         if (!path) {
64                 _E("path is NULL");
65                 return RESOURCED_ERROR_INVALID_PARAMETER;
66         }
67
68         /* Don't touch cpu cgroup fixed process' score */
69         if (pai && pai->app_cpucg_update_exclude)
70                 return RESOURCED_ERROR_NONE;
71
72         if (!pai)
73                 return cpu_move_cgroup(pid, path);
74
75         cpu_move_cgroup(pai->main_pid, path);
76         if (pai->childs) {
77                 gslist_for_each_item(iter, pai->childs) {
78                         child_pid = GPOINTER_TO_PID(iter->data);
79                         cpu_move_cgroup(child_pid, path);
80                 }
81         }
82         return RESOURCED_ERROR_NONE;
83 }
84