Commit 29c0177e authored by Rusty Russell's avatar Rusty Russell

cpumask: change cpumask_scnprintf, cpumask_parse_user, cpulist_parse, and...

cpumask: change cpumask_scnprintf, cpumask_parse_user, cpulist_parse, and cpulist_scnprintf to take pointers.

Impact: change calling convention of existing cpumask APIs

Most cpumask functions started with cpus_: these have been replaced by
cpumask_ ones which take struct cpumask pointers as expected.

These four functions don't have good replacement names; fortunately
they're rarely used, so we just change them over.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarMike Travis <travis@sgi.com>
Acked-by: default avatarIngo Molnar <mingo@elte.hu>
Cc: paulus@samba.org
Cc: mingo@redhat.com
Cc: tony.luck@intel.com
Cc: ralf@linux-mips.org
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: cl@linux-foundation.org
Cc: srostedt@redhat.com
parent 98a79d6a
...@@ -219,7 +219,7 @@ static ssize_t show_shared_cpu_map(struct cache_info *this_leaf, char *buf) ...@@ -219,7 +219,7 @@ static ssize_t show_shared_cpu_map(struct cache_info *this_leaf, char *buf)
cpumask_t shared_cpu_map; cpumask_t shared_cpu_map;
cpus_and(shared_cpu_map, this_leaf->shared_cpu_map, cpu_online_map); cpus_and(shared_cpu_map, this_leaf->shared_cpu_map, cpu_online_map);
len = cpumask_scnprintf(buf, NR_CPUS+1, shared_cpu_map); len = cpumask_scnprintf(buf, NR_CPUS+1, &shared_cpu_map);
len += sprintf(buf+len, "\n"); len += sprintf(buf+len, "\n");
return len; return len;
} }
......
...@@ -51,10 +51,10 @@ static int __init allowcpus(char *str) ...@@ -51,10 +51,10 @@ static int __init allowcpus(char *str)
int len; int len;
cpus_clear(cpu_allow_map); cpus_clear(cpu_allow_map);
if (cpulist_parse(str, cpu_allow_map) == 0) { if (cpulist_parse(str, &cpu_allow_map) == 0) {
cpu_set(0, cpu_allow_map); cpu_set(0, cpu_allow_map);
cpus_and(cpu_possible_map, cpu_possible_map, cpu_allow_map); cpus_and(cpu_possible_map, cpu_possible_map, cpu_allow_map);
len = cpulist_scnprintf(buf, sizeof(buf)-1, cpu_possible_map); len = cpulist_scnprintf(buf, sizeof(buf)-1, &cpu_possible_map);
buf[len] = '\0'; buf[len] = '\0';
pr_debug("Allowable CPUs: %s\n", buf); pr_debug("Allowable CPUs: %s\n", buf);
return 1; return 1;
......
...@@ -358,7 +358,7 @@ static void xics_set_affinity(unsigned int virq, cpumask_t cpumask) ...@@ -358,7 +358,7 @@ static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
irq_server = get_irq_server(virq, 1); irq_server = get_irq_server(virq, 1);
if (irq_server == -1) { if (irq_server == -1) {
char cpulist[128]; char cpulist[128];
cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask); cpumask_scnprintf(cpulist, sizeof(cpulist), &cpumask);
printk(KERN_WARNING printk(KERN_WARNING
"%s: No online cpus in the mask %s for irq %d\n", "%s: No online cpus in the mask %s for irq %d\n",
__func__, cpulist, virq); __func__, cpulist, virq);
......
...@@ -626,8 +626,8 @@ static ssize_t show_shared_cpu_map_func(struct _cpuid4_info *this_leaf, ...@@ -626,8 +626,8 @@ static ssize_t show_shared_cpu_map_func(struct _cpuid4_info *this_leaf,
cpumask_t *mask = &this_leaf->shared_cpu_map; cpumask_t *mask = &this_leaf->shared_cpu_map;
n = type? n = type?
cpulist_scnprintf(buf, len-2, *mask): cpulist_scnprintf(buf, len-2, mask) :
cpumask_scnprintf(buf, len-2, *mask); cpumask_scnprintf(buf, len-2, mask);
buf[n++] = '\n'; buf[n++] = '\n';
buf[n] = '\0'; buf[n] = '\0';
} }
......
...@@ -282,7 +282,7 @@ static void __cpuinit numa_set_cpumask(int cpu, int enable) ...@@ -282,7 +282,7 @@ static void __cpuinit numa_set_cpumask(int cpu, int enable)
else else
cpu_clear(cpu, *mask); cpu_clear(cpu, *mask);
cpulist_scnprintf(buf, sizeof(buf), *mask); cpulist_scnprintf(buf, sizeof(buf), mask);
printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n", printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n",
enable? "numa_add_cpu":"numa_remove_cpu", cpu, node, buf); enable? "numa_add_cpu":"numa_remove_cpu", cpu, node, buf);
} }
......
...@@ -109,7 +109,7 @@ static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL); ...@@ -109,7 +109,7 @@ static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL);
*/ */
static ssize_t print_cpus_map(char *buf, cpumask_t *map) static ssize_t print_cpus_map(char *buf, cpumask_t *map)
{ {
int n = cpulist_scnprintf(buf, PAGE_SIZE-2, *map); int n = cpulist_scnprintf(buf, PAGE_SIZE-2, map);
buf[n++] = '\n'; buf[n++] = '\n';
buf[n] = '\0'; buf[n] = '\0';
......
...@@ -30,8 +30,8 @@ static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf) ...@@ -30,8 +30,8 @@ static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf)
BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1)); BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1));
len = type? len = type?
cpulist_scnprintf(buf, PAGE_SIZE-2, *mask): cpulist_scnprintf(buf, PAGE_SIZE-2, mask) :
cpumask_scnprintf(buf, PAGE_SIZE-2, *mask); cpumask_scnprintf(buf, PAGE_SIZE-2, mask);
buf[len++] = '\n'; buf[len++] = '\n';
buf[len] = '\0'; buf[len] = '\0';
return len; return len;
......
...@@ -49,8 +49,8 @@ static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf) ...@@ -49,8 +49,8 @@ static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf)
if (len > 1) { if (len > 1) {
n = type? n = type?
cpulist_scnprintf(buf, len-2, *mask): cpulist_scnprintf(buf, len-2, mask) :
cpumask_scnprintf(buf, len-2, *mask); cpumask_scnprintf(buf, len-2, mask);
buf[n++] = '\n'; buf[n++] = '\n';
buf[n] = '\0'; buf[n] = '\0';
} }
......
...@@ -74,7 +74,7 @@ static ssize_t local_cpus_show(struct device *dev, ...@@ -74,7 +74,7 @@ static ssize_t local_cpus_show(struct device *dev,
int len; int len;
mask = pcibus_to_cpumask(to_pci_dev(dev)->bus); mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask); len = cpumask_scnprintf(buf, PAGE_SIZE-2, &mask);
buf[len++] = '\n'; buf[len++] = '\n';
buf[len] = '\0'; buf[len] = '\0';
return len; return len;
...@@ -88,7 +88,7 @@ static ssize_t local_cpulist_show(struct device *dev, ...@@ -88,7 +88,7 @@ static ssize_t local_cpulist_show(struct device *dev,
int len; int len;
mask = pcibus_to_cpumask(to_pci_dev(dev)->bus); mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
len = cpulist_scnprintf(buf, PAGE_SIZE-2, mask); len = cpulist_scnprintf(buf, PAGE_SIZE-2, &mask);
buf[len++] = '\n'; buf[len++] = '\n';
buf[len] = '\0'; buf[len] = '\0';
return len; return len;
......
...@@ -55,8 +55,8 @@ static ssize_t pci_bus_show_cpuaffinity(struct device *dev, ...@@ -55,8 +55,8 @@ static ssize_t pci_bus_show_cpuaffinity(struct device *dev,
cpumask = pcibus_to_cpumask(to_pci_bus(dev)); cpumask = pcibus_to_cpumask(to_pci_bus(dev));
ret = type? ret = type?
cpulist_scnprintf(buf, PAGE_SIZE-2, cpumask): cpulist_scnprintf(buf, PAGE_SIZE-2, &cpumask) :
cpumask_scnprintf(buf, PAGE_SIZE-2, cpumask); cpumask_scnprintf(buf, PAGE_SIZE-2, &cpumask);
buf[ret++] = '\n'; buf[ret++] = '\n';
buf[ret] = '\0'; buf[ret] = '\0';
return ret; return ret;
......
...@@ -339,36 +339,6 @@ extern cpumask_t cpu_mask_all; ...@@ -339,36 +339,6 @@ extern cpumask_t cpu_mask_all;
#endif #endif
#define CPUMASK_PTR(v, m) cpumask_t *v = &(m->v) #define CPUMASK_PTR(v, m) cpumask_t *v = &(m->v)
#define cpumask_scnprintf(buf, len, src) \
__cpumask_scnprintf((buf), (len), &(src), NR_CPUS)
static inline int __cpumask_scnprintf(char *buf, int len,
const cpumask_t *srcp, int nbits)
{
return bitmap_scnprintf(buf, len, srcp->bits, nbits);
}
#define cpumask_parse_user(ubuf, ulen, dst) \
__cpumask_parse_user((ubuf), (ulen), &(dst), NR_CPUS)
static inline int __cpumask_parse_user(const char __user *buf, int len,
cpumask_t *dstp, int nbits)
{
return bitmap_parse_user(buf, len, dstp->bits, nbits);
}
#define cpulist_scnprintf(buf, len, src) \
__cpulist_scnprintf((buf), (len), &(src), NR_CPUS)
static inline int __cpulist_scnprintf(char *buf, int len,
const cpumask_t *srcp, int nbits)
{
return bitmap_scnlistprintf(buf, len, srcp->bits, nbits);
}
#define cpulist_parse(buf, dst) __cpulist_parse((buf), &(dst), NR_CPUS)
static inline int __cpulist_parse(const char *buf, cpumask_t *dstp, int nbits)
{
return bitmap_parselist(buf, dstp->bits, nbits);
}
#define cpu_remap(oldbit, old, new) \ #define cpu_remap(oldbit, old, new) \
__cpu_remap((oldbit), &(old), &(new), NR_CPUS) __cpu_remap((oldbit), &(old), &(new), NR_CPUS)
static inline int __cpu_remap(int oldbit, static inline int __cpu_remap(int oldbit,
...@@ -945,6 +915,63 @@ static inline void cpumask_copy(struct cpumask *dstp, ...@@ -945,6 +915,63 @@ static inline void cpumask_copy(struct cpumask *dstp,
*/ */
#define cpumask_of(cpu) (get_cpu_mask(cpu)) #define cpumask_of(cpu) (get_cpu_mask(cpu))
/**
* cpumask_scnprintf - print a cpumask into a string as comma-separated hex
* @buf: the buffer to sprintf into
* @len: the length of the buffer
* @srcp: the cpumask to print
*
* If len is zero, returns zero. Otherwise returns the length of the
* (nul-terminated) @buf string.
*/
static inline int cpumask_scnprintf(char *buf, int len,
const struct cpumask *srcp)
{
return bitmap_scnprintf(buf, len, srcp->bits, nr_cpumask_bits);
}
/**
* cpumask_parse_user - extract a cpumask from a user string
* @buf: the buffer to extract from
* @len: the length of the buffer
* @dstp: the cpumask to set.
*
* Returns -errno, or 0 for success.
*/
static inline int cpumask_parse_user(const char __user *buf, int len,
struct cpumask *dstp)
{
return bitmap_parse_user(buf, len, dstp->bits, nr_cpumask_bits);
}
/**
* cpulist_scnprintf - print a cpumask into a string as comma-separated list
* @buf: the buffer to sprintf into
* @len: the length of the buffer
* @srcp: the cpumask to print
*
* If len is zero, returns zero. Otherwise returns the length of the
* (nul-terminated) @buf string.
*/
static inline int cpulist_scnprintf(char *buf, int len,
const struct cpumask *srcp)
{
return bitmap_scnlistprintf(buf, len, srcp->bits, nr_cpumask_bits);
}
/**
* cpulist_parse_user - extract a cpumask from a user string of ranges
* @buf: the buffer to extract from
* @len: the length of the buffer
* @dstp: the cpumask to set.
*
* Returns -errno, or 0 for success.
*/
static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
{
return bitmap_parselist(buf, dstp->bits, nr_cpumask_bits);
}
/** /**
* to_cpumask - convert an NR_CPUS bitmap to a struct cpumask * * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
* @bitmap: the bitmap * @bitmap: the bitmap
......
...@@ -896,7 +896,7 @@ static int update_cpumask(struct cpuset *cs, const char *buf) ...@@ -896,7 +896,7 @@ static int update_cpumask(struct cpuset *cs, const char *buf)
if (!*buf) { if (!*buf) {
cpus_clear(trialcs.cpus_allowed); cpus_clear(trialcs.cpus_allowed);
} else { } else {
retval = cpulist_parse(buf, trialcs.cpus_allowed); retval = cpulist_parse(buf, &trialcs.cpus_allowed);
if (retval < 0) if (retval < 0)
return retval; return retval;
...@@ -1482,7 +1482,7 @@ static int cpuset_sprintf_cpulist(char *page, struct cpuset *cs) ...@@ -1482,7 +1482,7 @@ static int cpuset_sprintf_cpulist(char *page, struct cpuset *cs)
mask = cs->cpus_allowed; mask = cs->cpus_allowed;
mutex_unlock(&callback_mutex); mutex_unlock(&callback_mutex);
return cpulist_scnprintf(page, PAGE_SIZE, mask); return cpulist_scnprintf(page, PAGE_SIZE, &mask);
} }
static int cpuset_sprintf_memlist(char *page, struct cpuset *cs) static int cpuset_sprintf_memlist(char *page, struct cpuset *cs)
......
...@@ -47,7 +47,7 @@ static ssize_t irq_affinity_proc_write(struct file *file, ...@@ -47,7 +47,7 @@ static ssize_t irq_affinity_proc_write(struct file *file,
irq_balancing_disabled(irq)) irq_balancing_disabled(irq))
return -EIO; return -EIO;
err = cpumask_parse_user(buffer, count, new_value); err = cpumask_parse_user(buffer, count, &new_value);
if (err) if (err)
return err; return err;
...@@ -95,7 +95,7 @@ static ssize_t default_affinity_write(struct file *file, ...@@ -95,7 +95,7 @@ static ssize_t default_affinity_write(struct file *file,
cpumask_t new_value; cpumask_t new_value;
int err; int err;
err = cpumask_parse_user(buffer, count, new_value); err = cpumask_parse_user(buffer, count, &new_value);
if (err) if (err)
return err; return err;
......
...@@ -442,7 +442,7 @@ void profile_tick(int type) ...@@ -442,7 +442,7 @@ void profile_tick(int type)
static int prof_cpu_mask_read_proc(char *page, char **start, off_t off, static int prof_cpu_mask_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data) int count, int *eof, void *data)
{ {
int len = cpumask_scnprintf(page, count, *(cpumask_t *)data); int len = cpumask_scnprintf(page, count, (cpumask_t *)data);
if (count - len < 2) if (count - len < 2)
return -EINVAL; return -EINVAL;
len += sprintf(page + len, "\n"); len += sprintf(page + len, "\n");
...@@ -456,7 +456,7 @@ static int prof_cpu_mask_write_proc(struct file *file, ...@@ -456,7 +456,7 @@ static int prof_cpu_mask_write_proc(struct file *file,
unsigned long full_count = count, err; unsigned long full_count = count, err;
cpumask_t new_value; cpumask_t new_value;
err = cpumask_parse_user(buffer, count, new_value); err = cpumask_parse_user(buffer, count, &new_value);
if (err) if (err)
return err; return err;
......
...@@ -6666,7 +6666,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, ...@@ -6666,7 +6666,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
struct sched_group *group = sd->groups; struct sched_group *group = sd->groups;
char str[256]; char str[256];
cpulist_scnprintf(str, sizeof(str), sd->span); cpulist_scnprintf(str, sizeof(str), &sd->span);
cpus_clear(*groupmask); cpus_clear(*groupmask);
printk(KERN_DEBUG "%*s domain %d: ", level, "", level); printk(KERN_DEBUG "%*s domain %d: ", level, "", level);
...@@ -6720,7 +6720,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, ...@@ -6720,7 +6720,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
cpus_or(*groupmask, *groupmask, group->cpumask); cpus_or(*groupmask, *groupmask, group->cpumask);
cpulist_scnprintf(str, sizeof(str), group->cpumask); cpulist_scnprintf(str, sizeof(str), &group->cpumask);
printk(KERN_CONT " %s", str); printk(KERN_CONT " %s", str);
group = group->next; group = group->next;
......
...@@ -42,7 +42,7 @@ static int show_schedstat(struct seq_file *seq, void *v) ...@@ -42,7 +42,7 @@ static int show_schedstat(struct seq_file *seq, void *v)
for_each_domain(cpu, sd) { for_each_domain(cpu, sd) {
enum cpu_idle_type itype; enum cpu_idle_type itype;
cpumask_scnprintf(mask_str, mask_len, sd->span); cpumask_scnprintf(mask_str, mask_len, &sd->span);
seq_printf(seq, "domain%d %s", dcount++, mask_str); seq_printf(seq, "domain%d %s", dcount++, mask_str);
for (itype = CPU_IDLE; itype < CPU_MAX_IDLE_TYPES; for (itype = CPU_IDLE; itype < CPU_MAX_IDLE_TYPES;
itype++) { itype++) {
......
...@@ -352,7 +352,7 @@ static int parse(struct nlattr *na, cpumask_t *mask) ...@@ -352,7 +352,7 @@ static int parse(struct nlattr *na, cpumask_t *mask)
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
nla_strlcpy(data, na, len); nla_strlcpy(data, na, len);
ret = cpulist_parse(data, *mask); ret = cpulist_parse(data, mask);
kfree(data); kfree(data);
return ret; return ret;
} }
......
...@@ -2126,7 +2126,7 @@ tracing_cpumask_read(struct file *filp, char __user *ubuf, ...@@ -2126,7 +2126,7 @@ tracing_cpumask_read(struct file *filp, char __user *ubuf,
mutex_lock(&tracing_cpumask_update_lock); mutex_lock(&tracing_cpumask_update_lock);
len = cpumask_scnprintf(mask_str, count, tracing_cpumask); len = cpumask_scnprintf(mask_str, count, &tracing_cpumask);
if (count - len < 2) { if (count - len < 2) {
count = -EINVAL; count = -EINVAL;
goto out_err; goto out_err;
...@@ -2147,7 +2147,7 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf, ...@@ -2147,7 +2147,7 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,
int err, cpu; int err, cpu;
mutex_lock(&tracing_cpumask_update_lock); mutex_lock(&tracing_cpumask_update_lock);
err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); err = cpumask_parse_user(ubuf, count, &tracing_cpumask_new);
if (err) if (err)
goto err_unlock; goto err_unlock;
......
...@@ -3626,7 +3626,7 @@ static int list_locations(struct kmem_cache *s, char *buf, ...@@ -3626,7 +3626,7 @@ static int list_locations(struct kmem_cache *s, char *buf,
len < PAGE_SIZE - 60) { len < PAGE_SIZE - 60) {
len += sprintf(buf + len, " cpus="); len += sprintf(buf + len, " cpus=");
len += cpulist_scnprintf(buf + len, PAGE_SIZE - len - 50, len += cpulist_scnprintf(buf + len, PAGE_SIZE - len - 50,
l->cpus); &l->cpus);
} }
if (num_online_nodes() > 1 && !nodes_empty(l->nodes) && if (num_online_nodes() > 1 && !nodes_empty(l->nodes) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment