Skip to content

Commit b0ced9d

Browse files
Chen Ridonghtejun
authored andcommitted
cgroup/cpuset: move v1 interfaces to cpuset-v1.c
Move legacy cpuset controller interfaces files and corresponding code into cpuset-v1.c. 'update_flag', 'cpuset_write_resmask' and 'cpuset_common_seq_show' are also used for v1, so declare them in cpuset-internal.h. 'cpuset_write_s64', 'cpuset_read_s64' and 'fmeter_getrate' are only used cpuset-v1.c now, make it static. Signed-off-by: Chen Ridong <[email protected]> Acked-by: Waiman Long <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent be126b5 commit b0ced9d

File tree

3 files changed

+199
-199
lines changed

3 files changed

+199
-199
lines changed

kernel/cgroup/cpuset-internal.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,16 @@ void callback_lock_irq(void);
271271
void callback_unlock_irq(void);
272272
void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus);
273273
void update_tasks_nodemask(struct cpuset *cs);
274+
int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int turning_on);
275+
ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
276+
char *buf, size_t nbytes, loff_t off);
277+
int cpuset_common_seq_show(struct seq_file *sf, void *v);
274278

275279
/*
276280
* cpuset-v1.c
277281
*/
282+
extern struct cftype legacy_files[];
278283
void fmeter_init(struct fmeter *fmp);
279-
int fmeter_getrate(struct fmeter *fmp);
280-
int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype *cft,
281-
s64 val);
282-
s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft);
283284
void cpuset_update_task_spread_flags(struct cpuset *cs,
284285
struct task_struct *tsk);
285286
void update_tasks_flags(struct cpuset *cs);

kernel/cgroup/cpuset-v1.c

Lines changed: 191 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void fmeter_markevent(struct fmeter *fmp)
100100
}
101101

102102
/* Process any previous ticks, then return current value. */
103-
int fmeter_getrate(struct fmeter *fmp)
103+
static int fmeter_getrate(struct fmeter *fmp)
104104
{
105105
int val;
106106

@@ -161,7 +161,7 @@ static int update_relax_domain_level(struct cpuset *cs, s64 val)
161161
return 0;
162162
}
163163

164-
int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype *cft,
164+
static int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype *cft,
165165
s64 val)
166166
{
167167
struct cpuset *cs = css_cs(css);
@@ -187,7 +187,7 @@ int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype *cft,
187187
return retval;
188188
}
189189

190-
s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft)
190+
static s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft)
191191
{
192192
struct cpuset *cs = css_cs(css);
193193
cpuset_filetype_t type = cft->private;
@@ -372,3 +372,191 @@ int validate_change_legacy(struct cpuset *cur, struct cpuset *trial)
372372
out:
373373
return ret;
374374
}
375+
376+
static u64 cpuset_read_u64(struct cgroup_subsys_state *css, struct cftype *cft)
377+
{
378+
struct cpuset *cs = css_cs(css);
379+
cpuset_filetype_t type = cft->private;
380+
381+
switch (type) {
382+
case FILE_CPU_EXCLUSIVE:
383+
return is_cpu_exclusive(cs);
384+
case FILE_MEM_EXCLUSIVE:
385+
return is_mem_exclusive(cs);
386+
case FILE_MEM_HARDWALL:
387+
return is_mem_hardwall(cs);
388+
case FILE_SCHED_LOAD_BALANCE:
389+
return is_sched_load_balance(cs);
390+
case FILE_MEMORY_MIGRATE:
391+
return is_memory_migrate(cs);
392+
case FILE_MEMORY_PRESSURE_ENABLED:
393+
return cpuset_memory_pressure_enabled;
394+
case FILE_MEMORY_PRESSURE:
395+
return fmeter_getrate(&cs->fmeter);
396+
case FILE_SPREAD_PAGE:
397+
return is_spread_page(cs);
398+
case FILE_SPREAD_SLAB:
399+
return is_spread_slab(cs);
400+
default:
401+
BUG();
402+
}
403+
404+
/* Unreachable but makes gcc happy */
405+
return 0;
406+
}
407+
408+
static int cpuset_write_u64(struct cgroup_subsys_state *css, struct cftype *cft,
409+
u64 val)
410+
{
411+
struct cpuset *cs = css_cs(css);
412+
cpuset_filetype_t type = cft->private;
413+
int retval = 0;
414+
415+
cpus_read_lock();
416+
cpuset_lock();
417+
if (!is_cpuset_online(cs)) {
418+
retval = -ENODEV;
419+
goto out_unlock;
420+
}
421+
422+
switch (type) {
423+
case FILE_CPU_EXCLUSIVE:
424+
retval = update_flag(CS_CPU_EXCLUSIVE, cs, val);
425+
break;
426+
case FILE_MEM_EXCLUSIVE:
427+
retval = update_flag(CS_MEM_EXCLUSIVE, cs, val);
428+
break;
429+
case FILE_MEM_HARDWALL:
430+
retval = update_flag(CS_MEM_HARDWALL, cs, val);
431+
break;
432+
case FILE_SCHED_LOAD_BALANCE:
433+
retval = update_flag(CS_SCHED_LOAD_BALANCE, cs, val);
434+
break;
435+
case FILE_MEMORY_MIGRATE:
436+
retval = update_flag(CS_MEMORY_MIGRATE, cs, val);
437+
break;
438+
case FILE_MEMORY_PRESSURE_ENABLED:
439+
cpuset_memory_pressure_enabled = !!val;
440+
break;
441+
case FILE_SPREAD_PAGE:
442+
retval = update_flag(CS_SPREAD_PAGE, cs, val);
443+
break;
444+
case FILE_SPREAD_SLAB:
445+
retval = update_flag(CS_SPREAD_SLAB, cs, val);
446+
break;
447+
default:
448+
retval = -EINVAL;
449+
break;
450+
}
451+
out_unlock:
452+
cpuset_unlock();
453+
cpus_read_unlock();
454+
return retval;
455+
}
456+
457+
/*
458+
* for the common functions, 'private' gives the type of file
459+
*/
460+
461+
struct cftype legacy_files[] = {
462+
{
463+
.name = "cpus",
464+
.seq_show = cpuset_common_seq_show,
465+
.write = cpuset_write_resmask,
466+
.max_write_len = (100U + 6 * NR_CPUS),
467+
.private = FILE_CPULIST,
468+
},
469+
470+
{
471+
.name = "mems",
472+
.seq_show = cpuset_common_seq_show,
473+
.write = cpuset_write_resmask,
474+
.max_write_len = (100U + 6 * MAX_NUMNODES),
475+
.private = FILE_MEMLIST,
476+
},
477+
478+
{
479+
.name = "effective_cpus",
480+
.seq_show = cpuset_common_seq_show,
481+
.private = FILE_EFFECTIVE_CPULIST,
482+
},
483+
484+
{
485+
.name = "effective_mems",
486+
.seq_show = cpuset_common_seq_show,
487+
.private = FILE_EFFECTIVE_MEMLIST,
488+
},
489+
490+
{
491+
.name = "cpu_exclusive",
492+
.read_u64 = cpuset_read_u64,
493+
.write_u64 = cpuset_write_u64,
494+
.private = FILE_CPU_EXCLUSIVE,
495+
},
496+
497+
{
498+
.name = "mem_exclusive",
499+
.read_u64 = cpuset_read_u64,
500+
.write_u64 = cpuset_write_u64,
501+
.private = FILE_MEM_EXCLUSIVE,
502+
},
503+
504+
{
505+
.name = "mem_hardwall",
506+
.read_u64 = cpuset_read_u64,
507+
.write_u64 = cpuset_write_u64,
508+
.private = FILE_MEM_HARDWALL,
509+
},
510+
511+
{
512+
.name = "sched_load_balance",
513+
.read_u64 = cpuset_read_u64,
514+
.write_u64 = cpuset_write_u64,
515+
.private = FILE_SCHED_LOAD_BALANCE,
516+
},
517+
518+
{
519+
.name = "sched_relax_domain_level",
520+
.read_s64 = cpuset_read_s64,
521+
.write_s64 = cpuset_write_s64,
522+
.private = FILE_SCHED_RELAX_DOMAIN_LEVEL,
523+
},
524+
525+
{
526+
.name = "memory_migrate",
527+
.read_u64 = cpuset_read_u64,
528+
.write_u64 = cpuset_write_u64,
529+
.private = FILE_MEMORY_MIGRATE,
530+
},
531+
532+
{
533+
.name = "memory_pressure",
534+
.read_u64 = cpuset_read_u64,
535+
.private = FILE_MEMORY_PRESSURE,
536+
},
537+
538+
{
539+
.name = "memory_spread_page",
540+
.read_u64 = cpuset_read_u64,
541+
.write_u64 = cpuset_write_u64,
542+
.private = FILE_SPREAD_PAGE,
543+
},
544+
545+
{
546+
/* obsolete, may be removed in the future */
547+
.name = "memory_spread_slab",
548+
.read_u64 = cpuset_read_u64,
549+
.write_u64 = cpuset_write_u64,
550+
.private = FILE_SPREAD_SLAB,
551+
},
552+
553+
{
554+
.name = "memory_pressure_enabled",
555+
.flags = CFTYPE_ONLY_ON_ROOT,
556+
.read_u64 = cpuset_read_u64,
557+
.write_u64 = cpuset_write_u64,
558+
.private = FILE_MEMORY_PRESSURE_ENABLED,
559+
},
560+
561+
{ } /* terminate */
562+
};

0 commit comments

Comments
 (0)