Skip to content

Commit e8e6d97

Browse files
htejuntorvalds
authored andcommitted
cpuset: use %*pb[l] to print bitmaps including cpumasks and nodemasks
printk and friends can now format bitmaps using '%*pb[l]'. cpumask and nodemask also provide cpumask_pr_args() and nodemask_pr_args() respectively which can be used to generate the two printf arguments necessary to format the specified cpu/nodemask. * kernel/cpuset.c::cpuset_print_task_mems_allowed() used a static buffer which is protected by a dedicated spinlock. Removed. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Li Zefan <lizefan@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 660e5ec commit e8e6d97

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

kernel/cpuset.c

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,40 +1707,27 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
17071707
{
17081708
struct cpuset *cs = css_cs(seq_css(sf));
17091709
cpuset_filetype_t type = seq_cft(sf)->private;
1710-
ssize_t count;
1711-
char *buf, *s;
17121710
int ret = 0;
17131711

1714-
count = seq_get_buf(sf, &buf);
1715-
s = buf;
1716-
17171712
spin_lock_irq(&callback_lock);
17181713

17191714
switch (type) {
17201715
case FILE_CPULIST:
1721-
s += cpulist_scnprintf(s, count, cs->cpus_allowed);
1716+
seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->cpus_allowed));
17221717
break;
17231718
case FILE_MEMLIST:
1724-
s += nodelist_scnprintf(s, count, cs->mems_allowed);
1719+
seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->mems_allowed));
17251720
break;
17261721
case FILE_EFFECTIVE_CPULIST:
1727-
s += cpulist_scnprintf(s, count, cs->effective_cpus);
1722+
seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->effective_cpus));
17281723
break;
17291724
case FILE_EFFECTIVE_MEMLIST:
1730-
s += nodelist_scnprintf(s, count, cs->effective_mems);
1725+
seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems));
17311726
break;
17321727
default:
17331728
ret = -EINVAL;
1734-
goto out_unlock;
17351729
}
17361730

1737-
if (s < buf + count - 1) {
1738-
*s++ = '\n';
1739-
seq_commit(sf, s - buf);
1740-
} else {
1741-
seq_commit(sf, -1);
1742-
}
1743-
out_unlock:
17441731
spin_unlock_irq(&callback_lock);
17451732
return ret;
17461733
}
@@ -2610,8 +2597,6 @@ int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
26102597
return nodes_intersects(tsk1->mems_allowed, tsk2->mems_allowed);
26112598
}
26122599

2613-
#define CPUSET_NODELIST_LEN (256)
2614-
26152600
/**
26162601
* cpuset_print_task_mems_allowed - prints task's cpuset and mems_allowed
26172602
* @tsk: pointer to task_struct of some task.
@@ -2621,23 +2606,16 @@ int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
26212606
*/
26222607
void cpuset_print_task_mems_allowed(struct task_struct *tsk)
26232608
{
2624-
/* Statically allocated to prevent using excess stack. */
2625-
static char cpuset_nodelist[CPUSET_NODELIST_LEN];
2626-
static DEFINE_SPINLOCK(cpuset_buffer_lock);
26272609
struct cgroup *cgrp;
26282610

2629-
spin_lock(&cpuset_buffer_lock);
26302611
rcu_read_lock();
26312612

26322613
cgrp = task_cs(tsk)->css.cgroup;
2633-
nodelist_scnprintf(cpuset_nodelist, CPUSET_NODELIST_LEN,
2634-
tsk->mems_allowed);
26352614
pr_info("%s cpuset=", tsk->comm);
26362615
pr_cont_cgroup_name(cgrp);
2637-
pr_cont(" mems_allowed=%s\n", cpuset_nodelist);
2616+
pr_cont(" mems_allowed=%*pbl\n", nodemask_pr_args(&tsk->mems_allowed));
26382617

26392618
rcu_read_unlock();
2640-
spin_unlock(&cpuset_buffer_lock);
26412619
}
26422620

26432621
/*
@@ -2715,10 +2693,8 @@ int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns,
27152693
/* Display task mems_allowed in /proc/<pid>/status file. */
27162694
void cpuset_task_status_allowed(struct seq_file *m, struct task_struct *task)
27172695
{
2718-
seq_puts(m, "Mems_allowed:\t");
2719-
seq_nodemask(m, &task->mems_allowed);
2720-
seq_puts(m, "\n");
2721-
seq_puts(m, "Mems_allowed_list:\t");
2722-
seq_nodemask_list(m, &task->mems_allowed);
2723-
seq_puts(m, "\n");
2696+
seq_printf(m, "Mems_allowed:\t%*pb\n",
2697+
nodemask_pr_args(&task->mems_allowed));
2698+
seq_printf(m, "Mems_allowed_list:\t%*pbl\n",
2699+
nodemask_pr_args(&task->mems_allowed));
27242700
}

0 commit comments

Comments
 (0)