diff options
author | Tejun Heo <tj@kernel.org> | 2014-04-23 11:13:15 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-04-23 11:13:15 -0400 |
commit | 0f0a2b4fa6210147131082999f1f16d7fb79abf8 (patch) | |
tree | b1528915143e2d106590f798384f446bca1e5d17 /kernel/cgroup.c | |
parent | 3b281afbc3a06cd69c54e6db1a04a8e73997723f (diff) |
cgroup: reorganize css_task_iter
This patch reorganizes css_task_iter so that adding effective css
support is easier.
* s/->cset_link/->cset_pos/ and s/->task/->task_pos/ for consistency
* ->origin_css is used to determine whether the iteration reached the
last css_set. Replace it with explicit ->cset_head so that
css_advance_task_iter() doesn't have to know the termination
condition directly.
* css_task_iter_next() currently assumes that it's walking list of
cgrp_cset_link and reaches into the current cset through the current
link to determine the termination conditions for task walking. As
this won't always be true for effective css walking, add
->tasks_head and ->mg_tasks_head and use them to control task
walking so that css_task_iter_next() doesn't have to know how
css_sets are being walked.
This patch doesn't make any behavior changes. The iteration logic
stays unchanged after the patch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r-- | kernel/cgroup.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 0edc186cd545..d48163b26196 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -2857,27 +2857,30 @@ css_next_descendant_post(struct cgroup_subsys_state *pos, | |||
2857 | */ | 2857 | */ |
2858 | static void css_advance_task_iter(struct css_task_iter *it) | 2858 | static void css_advance_task_iter(struct css_task_iter *it) |
2859 | { | 2859 | { |
2860 | struct list_head *l = it->cset_link; | 2860 | struct list_head *l = it->cset_pos; |
2861 | struct cgrp_cset_link *link; | 2861 | struct cgrp_cset_link *link; |
2862 | struct css_set *cset; | 2862 | struct css_set *cset; |
2863 | 2863 | ||
2864 | /* Advance to the next non-empty css_set */ | 2864 | /* Advance to the next non-empty css_set */ |
2865 | do { | 2865 | do { |
2866 | l = l->next; | 2866 | l = l->next; |
2867 | if (l == &it->origin_css->cgroup->cset_links) { | 2867 | if (l == it->cset_head) { |
2868 | it->cset_link = NULL; | 2868 | it->cset_pos = NULL; |
2869 | return; | 2869 | return; |
2870 | } | 2870 | } |
2871 | link = list_entry(l, struct cgrp_cset_link, cset_link); | 2871 | link = list_entry(l, struct cgrp_cset_link, cset_link); |
2872 | cset = link->cset; | 2872 | cset = link->cset; |
2873 | } while (list_empty(&cset->tasks) && list_empty(&cset->mg_tasks)); | 2873 | } while (list_empty(&cset->tasks) && list_empty(&cset->mg_tasks)); |
2874 | 2874 | ||
2875 | it->cset_link = l; | 2875 | it->cset_pos = l; |
2876 | 2876 | ||
2877 | if (!list_empty(&cset->tasks)) | 2877 | if (!list_empty(&cset->tasks)) |
2878 | it->task = cset->tasks.next; | 2878 | it->task_pos = cset->tasks.next; |
2879 | else | 2879 | else |
2880 | it->task = cset->mg_tasks.next; | 2880 | it->task_pos = cset->mg_tasks.next; |
2881 | |||
2882 | it->tasks_head = &cset->tasks; | ||
2883 | it->mg_tasks_head = &cset->mg_tasks; | ||
2881 | } | 2884 | } |
2882 | 2885 | ||
2883 | /** | 2886 | /** |
@@ -2903,8 +2906,8 @@ void css_task_iter_start(struct cgroup_subsys_state *css, | |||
2903 | 2906 | ||
2904 | down_read(&css_set_rwsem); | 2907 | down_read(&css_set_rwsem); |
2905 | 2908 | ||
2906 | it->origin_css = css; | 2909 | it->cset_pos = &css->cgroup->cset_links; |
2907 | it->cset_link = &css->cgroup->cset_links; | 2910 | it->cset_head = it->cset_pos; |
2908 | 2911 | ||
2909 | css_advance_task_iter(it); | 2912 | css_advance_task_iter(it); |
2910 | } | 2913 | } |
@@ -2920,12 +2923,10 @@ void css_task_iter_start(struct cgroup_subsys_state *css, | |||
2920 | struct task_struct *css_task_iter_next(struct css_task_iter *it) | 2923 | struct task_struct *css_task_iter_next(struct css_task_iter *it) |
2921 | { | 2924 | { |
2922 | struct task_struct *res; | 2925 | struct task_struct *res; |
2923 | struct list_head *l = it->task; | 2926 | struct list_head *l = it->task_pos; |
2924 | struct cgrp_cset_link *link = list_entry(it->cset_link, | ||
2925 | struct cgrp_cset_link, cset_link); | ||
2926 | 2927 | ||
2927 | /* If the iterator cg is NULL, we have no tasks */ | 2928 | /* If the iterator cg is NULL, we have no tasks */ |
2928 | if (!it->cset_link) | 2929 | if (!it->cset_pos) |
2929 | return NULL; | 2930 | return NULL; |
2930 | res = list_entry(l, struct task_struct, cg_list); | 2931 | res = list_entry(l, struct task_struct, cg_list); |
2931 | 2932 | ||
@@ -2936,13 +2937,13 @@ struct task_struct *css_task_iter_next(struct css_task_iter *it) | |||
2936 | */ | 2937 | */ |
2937 | l = l->next; | 2938 | l = l->next; |
2938 | 2939 | ||
2939 | if (l == &link->cset->tasks) | 2940 | if (l == it->tasks_head) |
2940 | l = link->cset->mg_tasks.next; | 2941 | l = it->mg_tasks_head->next; |
2941 | 2942 | ||
2942 | if (l == &link->cset->mg_tasks) | 2943 | if (l == it->mg_tasks_head) |
2943 | css_advance_task_iter(it); | 2944 | css_advance_task_iter(it); |
2944 | else | 2945 | else |
2945 | it->task = l; | 2946 | it->task_pos = l; |
2946 | 2947 | ||
2947 | return res; | 2948 | return res; |
2948 | } | 2949 | } |