2 * Code related to setting up a blkio cgroup
9 static char *get_cgroup_root(struct thread_data *td)
11 char *str = malloc(64);
14 sprintf(str, "%s/%s", td->o.cgroup_root, td->o.cgroup);
16 sprintf(str, "%s/%s", td->o.cgroup_root, td->o.name);
22 * Add pid to given class
24 static int cgroup_add_pid(struct thread_data *td)
29 root = get_cgroup_root(td);
30 sprintf(tmp, "%s/tasks", root);
34 td_verror(td, errno, "cgroup open tasks");
38 fprintf(f, "%d", td->pid);
45 * Move pid to root class
47 static int cgroup_del_pid(struct thread_data *td)
52 sprintf(tmp, "%s/tasks", td->o.cgroup_root);
55 td_verror(td, errno, "cgroup open tasks");
59 fprintf(f, "%d", td->pid);
65 int cgroup_setup(struct thread_data *td)
71 * Create container, if it doesn't exist
73 root = get_cgroup_root(td);
74 if (mkdir(root, 0755) < 0) {
78 td_verror(td, __e, "cgroup mkdir");
82 td->o.cgroup_was_created = 1;
84 sprintf(tmp, "%s/blkio.weight", root);
87 td_verror(td, errno, "cgroup open weight");
91 fprintf(f, "%d", td->o.cgroup_weight);
95 if (cgroup_add_pid(td))
101 void cgroup_shutdown(struct thread_data *td)
103 if (!td->o.cgroup_weight)
108 if (td->o.cgroup_was_created) {
111 root = get_cgroup_root(td);