diff options
author | Tejun Heo <tj@kernel.org> | 2015-10-15 16:41:52 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2015-10-15 16:41:52 -0400 |
commit | ecb9d535df967b3ca565535e14456f612373bf5e (patch) | |
tree | 0a4a5f742715f8d36d764b5ca0fb77db40f75119 | |
parent | f6d7d049c17a29fbc4c2723899a242d6889554aa (diff) |
cgroup: reorganize css_task_iter functions
* Rename css_advance_task_iter() to css_task_iter_advance_css_set()
and make it clear it->task_pos too at the end of the iteration.
* Factor out css_task_iter_advance() from css_task_iter_next(). The
new function whines if called on a terminated iterator.
Except for the termination check, this is pure reorganization and
doesn't introduce any behavior changes. This will help the planned
locking update for css_task_iter.
Signed-off-by: Tejun Heo <tj@kernel.org>
-rw-r--r-- | kernel/cgroup.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 0b6e50c67b65..56e2b772b143 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -3793,12 +3793,12 @@ bool css_has_online_children(struct cgroup_subsys_state *css) | |||
3793 | } | 3793 | } |
3794 | 3794 | ||
3795 | /** | 3795 | /** |
3796 | * css_advance_task_iter - advance a task itererator to the next css_set | 3796 | * css_task_iter_advance_css_set - advance a task itererator to the next css_set |
3797 | * @it: the iterator to advance | 3797 | * @it: the iterator to advance |
3798 | * | 3798 | * |
3799 | * Advance @it to the next css_set to walk. | 3799 | * Advance @it to the next css_set to walk. |
3800 | */ | 3800 | */ |
3801 | static void css_advance_task_iter(struct css_task_iter *it) | 3801 | static void css_task_iter_advance_css_set(struct css_task_iter *it) |
3802 | { | 3802 | { |
3803 | struct list_head *l = it->cset_pos; | 3803 | struct list_head *l = it->cset_pos; |
3804 | struct cgrp_cset_link *link; | 3804 | struct cgrp_cset_link *link; |
@@ -3809,6 +3809,7 @@ static void css_advance_task_iter(struct css_task_iter *it) | |||
3809 | l = l->next; | 3809 | l = l->next; |
3810 | if (l == it->cset_head) { | 3810 | if (l == it->cset_head) { |
3811 | it->cset_pos = NULL; | 3811 | it->cset_pos = NULL; |
3812 | it->task_pos = NULL; | ||
3812 | return; | 3813 | return; |
3813 | } | 3814 | } |
3814 | 3815 | ||
@@ -3832,6 +3833,28 @@ static void css_advance_task_iter(struct css_task_iter *it) | |||
3832 | it->mg_tasks_head = &cset->mg_tasks; | 3833 | it->mg_tasks_head = &cset->mg_tasks; |
3833 | } | 3834 | } |
3834 | 3835 | ||
3836 | static void css_task_iter_advance(struct css_task_iter *it) | ||
3837 | { | ||
3838 | struct list_head *l = it->task_pos; | ||
3839 | |||
3840 | WARN_ON_ONCE(!l); | ||
3841 | |||
3842 | /* | ||
3843 | * Advance iterator to find next entry. cset->tasks is consumed | ||
3844 | * first and then ->mg_tasks. After ->mg_tasks, we move onto the | ||
3845 | * next cset. | ||
3846 | */ | ||
3847 | l = l->next; | ||
3848 | |||
3849 | if (l == it->tasks_head) | ||
3850 | l = it->mg_tasks_head->next; | ||
3851 | |||
3852 | if (l == it->mg_tasks_head) | ||
3853 | css_task_iter_advance_css_set(it); | ||
3854 | else | ||
3855 | it->task_pos = l; | ||
3856 | } | ||
3857 | |||
3835 | /** | 3858 | /** |
3836 | * css_task_iter_start - initiate task iteration | 3859 | * css_task_iter_start - initiate task iteration |
3837 | * @css: the css to walk tasks of | 3860 | * @css: the css to walk tasks of |
@@ -3864,7 +3887,7 @@ void css_task_iter_start(struct cgroup_subsys_state *css, | |||
3864 | 3887 | ||
3865 | it->cset_head = it->cset_pos; | 3888 | it->cset_head = it->cset_pos; |
3866 | 3889 | ||
3867 | css_advance_task_iter(it); | 3890 | css_task_iter_advance_css_set(it); |
3868 | } | 3891 | } |
3869 | 3892 | ||
3870 | /** | 3893 | /** |
@@ -3878,28 +3901,12 @@ void css_task_iter_start(struct cgroup_subsys_state *css, | |||
3878 | struct task_struct *css_task_iter_next(struct css_task_iter *it) | 3901 | struct task_struct *css_task_iter_next(struct css_task_iter *it) |
3879 | { | 3902 | { |
3880 | struct task_struct *res; | 3903 | struct task_struct *res; |
3881 | struct list_head *l = it->task_pos; | ||
3882 | 3904 | ||
3883 | /* If the iterator cg is NULL, we have no tasks */ | ||
3884 | if (!it->cset_pos) | 3905 | if (!it->cset_pos) |
3885 | return NULL; | 3906 | return NULL; |
3886 | res = list_entry(l, struct task_struct, cg_list); | ||
3887 | |||
3888 | /* | ||
3889 | * Advance iterator to find next entry. cset->tasks is consumed | ||
3890 | * first and then ->mg_tasks. After ->mg_tasks, we move onto the | ||
3891 | * next cset. | ||
3892 | */ | ||
3893 | l = l->next; | ||
3894 | |||
3895 | if (l == it->tasks_head) | ||
3896 | l = it->mg_tasks_head->next; | ||
3897 | |||
3898 | if (l == it->mg_tasks_head) | ||
3899 | css_advance_task_iter(it); | ||
3900 | else | ||
3901 | it->task_pos = l; | ||
3902 | 3907 | ||
3908 | res = list_entry(it->task_pos, struct task_struct, cg_list); | ||
3909 | css_task_iter_advance(it); | ||
3903 | return res; | 3910 | return res; |
3904 | } | 3911 | } |
3905 | 3912 | ||