]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - kernel/cpuset.c
cgroup: pass around cgroup_subsys_state instead of cgroup in subsystem methods
[mirror_ubuntu-zesty-kernel.git] / kernel / cpuset.c
index e5657788feddfefaaed5f7ce3ce2ac26ca80a9c1..8ce3fdc3dfcc6f454d11a4d5d5c8c2dee4137e66 100644 (file)
@@ -70,7 +70,6 @@ int number_of_cpusets __read_mostly;
 
 /* Forward declare cgroup structures */
 struct cgroup_subsys cpuset_subsys;
-struct cpuset;
 
 /* See "Frequency meter" comments, below. */
 
@@ -115,27 +114,26 @@ struct cpuset {
        int relax_domain_level;
 };
 
+static inline struct cpuset *css_cs(struct cgroup_subsys_state *css)
+{
+       return css ? container_of(css, struct cpuset, css) : NULL;
+}
+
 /* Retrieve the cpuset for a cgroup */
 static inline struct cpuset *cgroup_cs(struct cgroup *cgrp)
 {
-       return container_of(cgroup_subsys_state(cgrp, cpuset_subsys_id),
-                           struct cpuset, css);
+       return css_cs(cgroup_css(cgrp, cpuset_subsys_id));
 }
 
 /* Retrieve the cpuset for a task */
 static inline struct cpuset *task_cs(struct task_struct *task)
 {
-       return container_of(task_subsys_state(task, cpuset_subsys_id),
-                           struct cpuset, css);
+       return css_cs(task_css(task, cpuset_subsys_id));
 }
 
-static inline struct cpuset *parent_cs(const struct cpuset *cs)
+static inline struct cpuset *parent_cs(struct cpuset *cs)
 {
-       struct cgroup *pcgrp = cs->css.cgroup->parent;
-
-       if (pcgrp)
-               return cgroup_cs(pcgrp);
-       return NULL;
+       return css_cs(css_parent(&cs->css));
 }
 
 #ifdef CONFIG_NUMA
@@ -320,8 +318,7 @@ static struct file_system_type cpuset_fs_type = {
  *
  * Call with callback_mutex held.
  */
-static void guarantee_online_cpus(const struct cpuset *cs,
-                                 struct cpumask *pmask)
+static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask)
 {
        while (!cpumask_intersects(cs->cpus_allowed, cpu_online_mask))
                cs = parent_cs(cs);
@@ -339,7 +336,7 @@ static void guarantee_online_cpus(const struct cpuset *cs,
  *
  * Call with callback_mutex held.
  */
-static void guarantee_online_mems(const struct cpuset *cs, nodemask_t *pmask)
+static void guarantee_online_mems(struct cpuset *cs, nodemask_t *pmask)
 {
        while (!nodes_intersects(cs->mems_allowed, node_states[N_MEMORY]))
                cs = parent_cs(cs);
@@ -384,7 +381,7 @@ static int is_cpuset_subset(const struct cpuset *p, const struct cpuset *q)
  * alloc_trial_cpuset - allocate a trial cpuset
  * @cs: the cpuset that the trial cpuset duplicates
  */
-static struct cpuset *alloc_trial_cpuset(const struct cpuset *cs)
+static struct cpuset *alloc_trial_cpuset(struct cpuset *cs)
 {
        struct cpuset *trial;
 
@@ -431,7 +428,7 @@ static void free_trial_cpuset(struct cpuset *trial)
  * Return 0 if valid, -errno if not.
  */
 
-static int validate_change(const struct cpuset *cur, const struct cpuset *trial)
+static int validate_change(struct cpuset *cur, struct cpuset *trial)
 {
        struct cgroup *cgrp;
        struct cpuset *c, *par;
@@ -846,7 +843,7 @@ static void cpuset_change_cpumask(struct task_struct *tsk,
 {
        struct cpuset *cpus_cs;
 
-       cpus_cs = effective_cpumask_cpuset(cgroup_cs(scan->cg));
+       cpus_cs = effective_cpumask_cpuset(cgroup_cs(scan->cgrp));
        set_cpus_allowed_ptr(tsk, cpus_cs->cpus_allowed);
 }
 
@@ -867,7 +864,7 @@ static void update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap)
 {
        struct cgroup_scanner scan;
 
-       scan.cg = cs->css.cgroup;
+       scan.cgrp = cs->css.cgroup;
        scan.test_task = NULL;
        scan.process_task = cpuset_change_cpumask;
        scan.heap = heap;
@@ -1063,7 +1060,7 @@ static void cpuset_change_task_nodemask(struct task_struct *tsk,
 static void cpuset_change_nodemask(struct task_struct *p,
                                   struct cgroup_scanner *scan)
 {
-       struct cpuset *cs = cgroup_cs(scan->cg);
+       struct cpuset *cs = cgroup_cs(scan->cgrp);
        struct mm_struct *mm;
        int migrate;
        nodemask_t *newmems = scan->data;
@@ -1103,7 +1100,7 @@ static void update_tasks_nodemask(struct cpuset *cs, struct ptr_heap *heap)
 
        guarantee_online_mems(mems_cs, &newmems);
 
-       scan.cg = cs->css.cgroup;
+       scan.cgrp = cs->css.cgroup;
        scan.test_task = NULL;
        scan.process_task = cpuset_change_nodemask;
        scan.heap = heap;
@@ -1276,7 +1273,7 @@ static int update_relax_domain_level(struct cpuset *cs, s64 val)
 static void cpuset_change_flag(struct task_struct *tsk,
                                struct cgroup_scanner *scan)
 {
-       cpuset_update_task_spread_flag(cgroup_cs(scan->cg), tsk);
+       cpuset_update_task_spread_flag(cgroup_cs(scan->cgrp), tsk);
 }
 
 /*
@@ -1296,7 +1293,7 @@ static void update_tasks_flags(struct cpuset *cs, struct ptr_heap *heap)
 {
        struct cgroup_scanner scan;
 
-       scan.cg = cs->css.cgroup;
+       scan.cgrp = cs->css.cgroup;
        scan.test_task = NULL;
        scan.process_task = cpuset_change_flag;
        scan.heap = heap;
@@ -1458,9 +1455,10 @@ static int fmeter_getrate(struct fmeter *fmp)
 }
 
 /* Called by cgroups to determine if a cpuset is usable; cpuset_mutex held */
-static int cpuset_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
+static int cpuset_can_attach(struct cgroup_subsys_state *css,
+                            struct cgroup_taskset *tset)
 {
-       struct cpuset *cs = cgroup_cs(cgrp);
+       struct cpuset *cs = css_cs(css);
        struct task_struct *task;
        int ret;
 
@@ -1471,11 +1469,11 @@ static int cpuset_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
         * flag is set.
         */
        ret = -ENOSPC;
-       if (!cgroup_sane_behavior(cgrp) &&
+       if (!cgroup_sane_behavior(css->cgroup) &&
            (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed)))
                goto out_unlock;
 
-       cgroup_taskset_for_each(task, cgrp, tset) {
+       cgroup_taskset_for_each(task, css->cgroup, tset) {
                /*
                 * Kthreads which disallow setaffinity shouldn't be moved
                 * to a new cpuset; we don't want to change their cpu
@@ -1504,11 +1502,11 @@ out_unlock:
        return ret;
 }
 
-static void cpuset_cancel_attach(struct cgroup *cgrp,
+static void cpuset_cancel_attach(struct cgroup_subsys_state *css,
                                 struct cgroup_taskset *tset)
 {
        mutex_lock(&cpuset_mutex);
-       cgroup_cs(cgrp)->attach_in_progress--;
+       css_cs(css)->attach_in_progress--;
        mutex_unlock(&cpuset_mutex);
 }
 
@@ -1519,7 +1517,8 @@ static void cpuset_cancel_attach(struct cgroup *cgrp,
  */
 static cpumask_var_t cpus_attach;
 
-static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
+static void cpuset_attach(struct cgroup_subsys_state *css,
+                         struct cgroup_taskset *tset)
 {
        /* static buf protected by cpuset_mutex */
        static nodemask_t cpuset_attach_nodemask_to;
@@ -1527,7 +1526,7 @@ static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
        struct task_struct *task;
        struct task_struct *leader = cgroup_taskset_first(tset);
        struct cgroup *oldcgrp = cgroup_taskset_cur_cgroup(tset);
-       struct cpuset *cs = cgroup_cs(cgrp);
+       struct cpuset *cs = css_cs(css);
        struct cpuset *oldcs = cgroup_cs(oldcgrp);
        struct cpuset *cpus_cs = effective_cpumask_cpuset(cs);
        struct cpuset *mems_cs = effective_nodemask_cpuset(cs);
@@ -1542,7 +1541,7 @@ static void cpuset_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
 
        guarantee_online_mems(mems_cs, &cpuset_attach_nodemask_to);
 
-       cgroup_taskset_for_each(task, cgrp, tset) {
+       cgroup_taskset_for_each(task, css->cgroup, tset) {
                /*
                 * can_attach beforehand should guarantee that this doesn't
                 * fail.  TODO: have a better way to handle failure here
@@ -1943,11 +1942,12 @@ static struct cftype files[] = {
  *     cgrp:   control group that the new cpuset will be part of
  */
 
-static struct cgroup_subsys_state *cpuset_css_alloc(struct cgroup *cgrp)
+static struct cgroup_subsys_state *
+cpuset_css_alloc(struct cgroup_subsys_state *parent_css)
 {
        struct cpuset *cs;
 
-       if (!cgrp->parent)
+       if (!parent_css)
                return &top_cpuset.css;
 
        cs = kzalloc(sizeof(*cs), GFP_KERNEL);
@@ -1967,12 +1967,12 @@ static struct cgroup_subsys_state *cpuset_css_alloc(struct cgroup *cgrp)
        return &cs->css;
 }
 
-static int cpuset_css_online(struct cgroup *cgrp)
+static int cpuset_css_online(struct cgroup_subsys_state *css)
 {
-       struct cpuset *cs = cgroup_cs(cgrp);
+       struct cpuset *cs = css_cs(css);
        struct cpuset *parent = parent_cs(cs);
        struct cpuset *tmp_cs;
-       struct cgroup *pos_cg;
+       struct cgroup *pos_cgrp;
 
        if (!parent)
                return 0;
@@ -1987,7 +1987,7 @@ static int cpuset_css_online(struct cgroup *cgrp)
 
        number_of_cpusets++;
 
-       if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &cgrp->flags))
+       if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags))
                goto out_unlock;
 
        /*
@@ -2004,7 +2004,7 @@ static int cpuset_css_online(struct cgroup *cgrp)
         * (and likewise for mems) to the new cgroup.
         */
        rcu_read_lock();
-       cpuset_for_each_child(tmp_cs, pos_cg, parent) {
+       cpuset_for_each_child(tmp_cs, pos_cgrp, parent) {
                if (is_mem_exclusive(tmp_cs) || is_cpu_exclusive(tmp_cs)) {
                        rcu_read_unlock();
                        goto out_unlock;
@@ -2021,9 +2021,15 @@ out_unlock:
        return 0;
 }
 
-static void cpuset_css_offline(struct cgroup *cgrp)
+/*
+ * If the cpuset being removed has its flag 'sched_load_balance'
+ * enabled, then simulate turning sched_load_balance off, which
+ * will call rebuild_sched_domains_locked().
+ */
+
+static void cpuset_css_offline(struct cgroup_subsys_state *css)
 {
-       struct cpuset *cs = cgroup_cs(cgrp);
+       struct cpuset *cs = css_cs(css);
 
        mutex_lock(&cpuset_mutex);
 
@@ -2036,15 +2042,9 @@ static void cpuset_css_offline(struct cgroup *cgrp)
        mutex_unlock(&cpuset_mutex);
 }
 
-/*
- * If the cpuset being removed has its flag 'sched_load_balance'
- * enabled, then simulate turning sched_load_balance off, which
- * will call rebuild_sched_domains_locked().
- */
-
-static void cpuset_css_free(struct cgroup *cgrp)
+static void cpuset_css_free(struct cgroup_subsys_state *css)
 {
-       struct cpuset *cs = cgroup_cs(cgrp);
+       struct cpuset *cs = css_cs(css);
 
        free_cpumask_var(cs->cpus_allowed);
        kfree(cs);
@@ -2344,7 +2344,7 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
 
 void cpuset_cpus_allowed_fallback(struct task_struct *tsk)
 {
-       const struct cpuset *cpus_cs;
+       struct cpuset *cpus_cs;
 
        rcu_read_lock();
        cpus_cs = effective_cpumask_cpuset(task_cs(tsk));
@@ -2417,7 +2417,7 @@ int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
  * callback_mutex.  If no ancestor is mem_exclusive or mem_hardwall
  * (an unusual configuration), then returns the root cpuset.
  */
-static const struct cpuset *nearest_hardwall_ancestor(const struct cpuset *cs)
+static struct cpuset *nearest_hardwall_ancestor(struct cpuset *cs)
 {
        while (!(is_mem_exclusive(cs) || is_mem_hardwall(cs)) && parent_cs(cs))
                cs = parent_cs(cs);
@@ -2487,7 +2487,7 @@ static const struct cpuset *nearest_hardwall_ancestor(const struct cpuset *cs)
  */
 int __cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
 {
-       const struct cpuset *cs;        /* current cpuset ancestors */
+       struct cpuset *cs;              /* current cpuset ancestors */
        int allowed;                    /* is allocation in zone z allowed? */
 
        if (in_interrupt() || (gfp_mask & __GFP_THISNODE))
@@ -2725,7 +2725,7 @@ int proc_cpuset_show(struct seq_file *m, void *unused_v)
                goto out_free;
 
        rcu_read_lock();
-       css = task_subsys_state(tsk, cpuset_subsys_id);
+       css = task_css(tsk, cpuset_subsys_id);
        retval = cgroup_path(css->cgroup, buf, PAGE_SIZE);
        rcu_read_unlock();
        if (retval < 0)