Skip to content

Commit be126b5

Browse files
Chen Ridonghtejun
authored andcommitted
cgroup/cpuset: move validate_change_legacy to cpuset-v1.c
The validate_change_legacy functions is used for v1, move it to cpuset-v1.c. And two micro 'cpuset_for_each_child' and 'cpuset_for_each_descendant_pre' are common for v1 and v2, move them to cpuset-internal.h. Signed-off-by: Chen Ridong <[email protected]> Acked-by: Waiman Long <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 23ca523 commit be126b5

File tree

3 files changed

+74
-73
lines changed

3 files changed

+74
-73
lines changed

kernel/cgroup/cpuset-internal.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,34 @@ static inline int is_spread_slab(const struct cpuset *cs)
238238
return test_bit(CS_SPREAD_SLAB, &cs->flags);
239239
}
240240

241+
/**
242+
* cpuset_for_each_child - traverse online children of a cpuset
243+
* @child_cs: loop cursor pointing to the current child
244+
* @pos_css: used for iteration
245+
* @parent_cs: target cpuset to walk children of
246+
*
247+
* Walk @child_cs through the online children of @parent_cs. Must be used
248+
* with RCU read locked.
249+
*/
250+
#define cpuset_for_each_child(child_cs, pos_css, parent_cs) \
251+
css_for_each_child((pos_css), &(parent_cs)->css) \
252+
if (is_cpuset_online(((child_cs) = css_cs((pos_css)))))
253+
254+
/**
255+
* cpuset_for_each_descendant_pre - pre-order walk of a cpuset's descendants
256+
* @des_cs: loop cursor pointing to the current descendant
257+
* @pos_css: used for iteration
258+
* @root_cs: target cpuset to walk ancestor of
259+
*
260+
* Walk @des_cs through the online descendants of @root_cs. Must be used
261+
* with RCU read locked. The caller may modify @pos_css by calling
262+
* css_rightmost_descendant() to skip subtree. @root_cs is included in the
263+
* iteration and the first node to be visited.
264+
*/
265+
#define cpuset_for_each_descendant_pre(des_cs, pos_css, root_cs) \
266+
css_for_each_descendant_pre((pos_css), &(root_cs)->css) \
267+
if (is_cpuset_online(((des_cs) = css_cs((pos_css)))))
268+
241269
void rebuild_sched_domains_locked(void);
242270
void callback_lock_irq(void);
243271
void callback_unlock_irq(void);
@@ -258,5 +286,6 @@ void update_tasks_flags(struct cpuset *cs);
258286
void hotplug_update_tasks_legacy(struct cpuset *cs,
259287
struct cpumask *new_cpus, nodemask_t *new_mems,
260288
bool cpus_updated, bool mems_updated);
289+
int validate_change_legacy(struct cpuset *cur, struct cpuset *trial);
261290

262291
#endif /* __CPUSET_INTERNAL_H */

kernel/cgroup/cpuset-v1.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,48 @@ void hotplug_update_tasks_legacy(struct cpuset *cs,
327327
schedule_work(&s->work);
328328
}
329329
}
330+
331+
/*
332+
* is_cpuset_subset(p, q) - Is cpuset p a subset of cpuset q?
333+
*
334+
* One cpuset is a subset of another if all its allowed CPUs and
335+
* Memory Nodes are a subset of the other, and its exclusive flags
336+
* are only set if the other's are set. Call holding cpuset_mutex.
337+
*/
338+
339+
static int is_cpuset_subset(const struct cpuset *p, const struct cpuset *q)
340+
{
341+
return cpumask_subset(p->cpus_allowed, q->cpus_allowed) &&
342+
nodes_subset(p->mems_allowed, q->mems_allowed) &&
343+
is_cpu_exclusive(p) <= is_cpu_exclusive(q) &&
344+
is_mem_exclusive(p) <= is_mem_exclusive(q);
345+
}
346+
347+
/*
348+
* validate_change_legacy() - Validate conditions specific to legacy (v1)
349+
* behavior.
350+
*/
351+
int validate_change_legacy(struct cpuset *cur, struct cpuset *trial)
352+
{
353+
struct cgroup_subsys_state *css;
354+
struct cpuset *c, *par;
355+
int ret;
356+
357+
WARN_ON_ONCE(!rcu_read_lock_held());
358+
359+
/* Each of our child cpusets must be a subset of us */
360+
ret = -EBUSY;
361+
cpuset_for_each_child(c, css, cur)
362+
if (!is_cpuset_subset(c, trial))
363+
goto out;
364+
365+
/* On legacy hierarchy, we must be a subset of our parent cpuset. */
366+
ret = -EACCES;
367+
par = parent_cs(cur);
368+
if (par && !is_cpuset_subset(trial, par))
369+
goto out;
370+
371+
ret = 0;
372+
out:
373+
return ret;
374+
}

kernel/cgroup/cpuset.c

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -186,34 +186,6 @@ static struct cpuset top_cpuset = {
186186
.remote_sibling = LIST_HEAD_INIT(top_cpuset.remote_sibling),
187187
};
188188

189-
/**
190-
* cpuset_for_each_child - traverse online children of a cpuset
191-
* @child_cs: loop cursor pointing to the current child
192-
* @pos_css: used for iteration
193-
* @parent_cs: target cpuset to walk children of
194-
*
195-
* Walk @child_cs through the online children of @parent_cs. Must be used
196-
* with RCU read locked.
197-
*/
198-
#define cpuset_for_each_child(child_cs, pos_css, parent_cs) \
199-
css_for_each_child((pos_css), &(parent_cs)->css) \
200-
if (is_cpuset_online(((child_cs) = css_cs((pos_css)))))
201-
202-
/**
203-
* cpuset_for_each_descendant_pre - pre-order walk of a cpuset's descendants
204-
* @des_cs: loop cursor pointing to the current descendant
205-
* @pos_css: used for iteration
206-
* @root_cs: target cpuset to walk ancestor of
207-
*
208-
* Walk @des_cs through the online descendants of @root_cs. Must be used
209-
* with RCU read locked. The caller may modify @pos_css by calling
210-
* css_rightmost_descendant() to skip subtree. @root_cs is included in the
211-
* iteration and the first node to be visited.
212-
*/
213-
#define cpuset_for_each_descendant_pre(des_cs, pos_css, root_cs) \
214-
css_for_each_descendant_pre((pos_css), &(root_cs)->css) \
215-
if (is_cpuset_online(((des_cs) = css_cs((pos_css)))))
216-
217189
/*
218190
* There are two global locks guarding cpuset structures - cpuset_mutex and
219191
* callback_lock. We also require taking task_lock() when dereferencing a
@@ -409,22 +381,6 @@ static void guarantee_online_mems(struct cpuset *cs, nodemask_t *pmask)
409381
nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]);
410382
}
411383

412-
/*
413-
* is_cpuset_subset(p, q) - Is cpuset p a subset of cpuset q?
414-
*
415-
* One cpuset is a subset of another if all its allowed CPUs and
416-
* Memory Nodes are a subset of the other, and its exclusive flags
417-
* are only set if the other's are set. Call holding cpuset_mutex.
418-
*/
419-
420-
static int is_cpuset_subset(const struct cpuset *p, const struct cpuset *q)
421-
{
422-
return cpumask_subset(p->cpus_allowed, q->cpus_allowed) &&
423-
nodes_subset(p->mems_allowed, q->mems_allowed) &&
424-
is_cpu_exclusive(p) <= is_cpu_exclusive(q) &&
425-
is_mem_exclusive(p) <= is_mem_exclusive(q);
426-
}
427-
428384
/**
429385
* alloc_cpumasks - allocate three cpumasks for cpuset
430386
* @cs: the cpuset that have cpumasks to be allocated.
@@ -555,35 +511,6 @@ static inline bool cpusets_are_exclusive(struct cpuset *cs1, struct cpuset *cs2)
555511
return true;
556512
}
557513

558-
/*
559-
* validate_change_legacy() - Validate conditions specific to legacy (v1)
560-
* behavior.
561-
*/
562-
static int validate_change_legacy(struct cpuset *cur, struct cpuset *trial)
563-
{
564-
struct cgroup_subsys_state *css;
565-
struct cpuset *c, *par;
566-
int ret;
567-
568-
WARN_ON_ONCE(!rcu_read_lock_held());
569-
570-
/* Each of our child cpusets must be a subset of us */
571-
ret = -EBUSY;
572-
cpuset_for_each_child(c, css, cur)
573-
if (!is_cpuset_subset(c, trial))
574-
goto out;
575-
576-
/* On legacy hierarchy, we must be a subset of our parent cpuset. */
577-
ret = -EACCES;
578-
par = parent_cs(cur);
579-
if (par && !is_cpuset_subset(trial, par))
580-
goto out;
581-
582-
ret = 0;
583-
out:
584-
return ret;
585-
}
586-
587514
/*
588515
* validate_change() - Used to validate that any proposed cpuset change
589516
* follows the structural rules for cpusets.

0 commit comments

Comments
 (0)