aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/kernel/cpu/perf_event_amd_iommu.c5
-rw-r--r--arch/x86/kernel/cpu/perf_event_amd_uncore.c6
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_rapl.c6
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_uncore.c6
-rw-r--r--drivers/acpi/acpi_pad.c8
-rw-r--r--drivers/base/cpu.c5
-rw-r--r--drivers/base/node.c14
-rw-r--r--drivers/base/topology.c22
-rw-r--r--drivers/pci/pci-sysfs.c39
-rw-r--r--include/linux/bitmap.h3
-rw-r--r--include/linux/cpumask.h17
-rw-r--r--lib/bitmap.c29
12 files changed, 73 insertions, 87 deletions
diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
index 639d1289b1ba..97242a9242bd 100644
--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
@@ -130,10 +130,7 @@ static ssize_t _iommu_cpumask_show(struct device *dev,
130 struct device_attribute *attr, 130 struct device_attribute *attr,
131 char *buf) 131 char *buf)
132{ 132{
133 int n = cpulist_scnprintf(buf, PAGE_SIZE - 2, &iommu_cpumask); 133 return cpumap_print_to_pagebuf(true, buf, &iommu_cpumask);
134 buf[n++] = '\n';
135 buf[n] = '\0';
136 return n;
137} 134}
138static DEVICE_ATTR(cpumask, S_IRUGO, _iommu_cpumask_show, NULL); 135static DEVICE_ATTR(cpumask, S_IRUGO, _iommu_cpumask_show, NULL);
139 136
diff --git a/arch/x86/kernel/cpu/perf_event_amd_uncore.c b/arch/x86/kernel/cpu/perf_event_amd_uncore.c
index 30790d798e6b..cc6cedb8f25d 100644
--- a/arch/x86/kernel/cpu/perf_event_amd_uncore.c
+++ b/arch/x86/kernel/cpu/perf_event_amd_uncore.c
@@ -219,7 +219,6 @@ static ssize_t amd_uncore_attr_show_cpumask(struct device *dev,
219 struct device_attribute *attr, 219 struct device_attribute *attr,
220 char *buf) 220 char *buf)
221{ 221{
222 int n;
223 cpumask_t *active_mask; 222 cpumask_t *active_mask;
224 struct pmu *pmu = dev_get_drvdata(dev); 223 struct pmu *pmu = dev_get_drvdata(dev);
225 224
@@ -230,10 +229,7 @@ static ssize_t amd_uncore_attr_show_cpumask(struct device *dev,
230 else 229 else
231 return 0; 230 return 0;
232 231
233 n = cpulist_scnprintf(buf, PAGE_SIZE - 2, active_mask); 232 return cpumap_print_to_pagebuf(true, buf, active_mask);
234 buf[n++] = '\n';
235 buf[n] = '\0';
236 return n;
237} 233}
238static DEVICE_ATTR(cpumask, S_IRUGO, amd_uncore_attr_show_cpumask, NULL); 234static DEVICE_ATTR(cpumask, S_IRUGO, amd_uncore_attr_show_cpumask, NULL);
239 235
diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
index d64f275fe274..673f930c700f 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
@@ -365,11 +365,7 @@ static void rapl_pmu_event_read(struct perf_event *event)
365static ssize_t rapl_get_attr_cpumask(struct device *dev, 365static ssize_t rapl_get_attr_cpumask(struct device *dev,
366 struct device_attribute *attr, char *buf) 366 struct device_attribute *attr, char *buf)
367{ 367{
368 int n = cpulist_scnprintf(buf, PAGE_SIZE - 2, &rapl_cpu_mask); 368 return cpumap_print_to_pagebuf(true, buf, &rapl_cpu_mask);
369
370 buf[n++] = '\n';
371 buf[n] = '\0';
372 return n;
373} 369}
374 370
375static DEVICE_ATTR(cpumask, S_IRUGO, rapl_get_attr_cpumask, NULL); 371static DEVICE_ATTR(cpumask, S_IRUGO, rapl_get_attr_cpumask, NULL);
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
index 9762dbd9f3f7..08f3fed2b0f2 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
@@ -647,11 +647,7 @@ static int uncore_pmu_event_init(struct perf_event *event)
647static ssize_t uncore_get_attr_cpumask(struct device *dev, 647static ssize_t uncore_get_attr_cpumask(struct device *dev,
648 struct device_attribute *attr, char *buf) 648 struct device_attribute *attr, char *buf)
649{ 649{
650 int n = cpulist_scnprintf(buf, PAGE_SIZE - 2, &uncore_cpu_mask); 650 return cpumap_print_to_pagebuf(true, buf, &uncore_cpu_mask);
651
652 buf[n++] = '\n';
653 buf[n] = '\0';
654 return n;
655} 651}
656 652
657static DEVICE_ATTR(cpumask, S_IRUGO, uncore_get_attr_cpumask, NULL); 653static DEVICE_ATTR(cpumask, S_IRUGO, uncore_get_attr_cpumask, NULL);
diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index f148a0580e04..c7b105c0e1d3 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -350,12 +350,10 @@ static ssize_t acpi_pad_idlecpus_store(struct device *dev,
350static ssize_t acpi_pad_idlecpus_show(struct device *dev, 350static ssize_t acpi_pad_idlecpus_show(struct device *dev,
351 struct device_attribute *attr, char *buf) 351 struct device_attribute *attr, char *buf)
352{ 352{
353 int n = 0; 353 return cpumap_print_to_pagebuf(false, buf,
354 n = cpumask_scnprintf(buf, PAGE_SIZE-2, to_cpumask(pad_busy_cpus_bits)); 354 to_cpumask(pad_busy_cpus_bits));
355 buf[n++] = '\n';
356 buf[n] = '\0';
357 return n;
358} 355}
356
359static DEVICE_ATTR(idlecpus, S_IRUGO|S_IWUSR, 357static DEVICE_ATTR(idlecpus, S_IRUGO|S_IWUSR,
360 acpi_pad_idlecpus_show, 358 acpi_pad_idlecpus_show,
361 acpi_pad_idlecpus_store); 359 acpi_pad_idlecpus_store);
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 006b1bc5297d..4d8a56406fbb 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -207,11 +207,8 @@ static ssize_t show_cpus_attr(struct device *dev,
207 char *buf) 207 char *buf)
208{ 208{
209 struct cpu_attr *ca = container_of(attr, struct cpu_attr, attr); 209 struct cpu_attr *ca = container_of(attr, struct cpu_attr, attr);
210 int n = cpulist_scnprintf(buf, PAGE_SIZE-2, *(ca->map));
211 210
212 buf[n++] = '\n'; 211 return cpumap_print_to_pagebuf(true, buf, *ca->map);
213 buf[n] = '\0';
214 return n;
215} 212}
216 213
217#define _CPU_ATTR(name, map) \ 214#define _CPU_ATTR(name, map) \
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 472168cd0c97..a3b82e9c7f20 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -25,32 +25,26 @@ static struct bus_type node_subsys = {
25}; 25};
26 26
27 27
28static ssize_t node_read_cpumap(struct device *dev, int type, char *buf) 28static ssize_t node_read_cpumap(struct device *dev, bool list, char *buf)
29{ 29{
30 struct node *node_dev = to_node(dev); 30 struct node *node_dev = to_node(dev);
31 const struct cpumask *mask = cpumask_of_node(node_dev->dev.id); 31 const struct cpumask *mask = cpumask_of_node(node_dev->dev.id);
32 int len;
33 32
34 /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */ 33 /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */
35 BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1)); 34 BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1));
36 35
37 len = type? 36 return cpumap_print_to_pagebuf(list, buf, mask);
38 cpulist_scnprintf(buf, PAGE_SIZE-2, mask) :
39 cpumask_scnprintf(buf, PAGE_SIZE-2, mask);
40 buf[len++] = '\n';
41 buf[len] = '\0';
42 return len;
43} 37}
44 38
45static inline ssize_t node_read_cpumask(struct device *dev, 39static inline ssize_t node_read_cpumask(struct device *dev,
46 struct device_attribute *attr, char *buf) 40 struct device_attribute *attr, char *buf)
47{ 41{
48 return node_read_cpumap(dev, 0, buf); 42 return node_read_cpumap(dev, false, buf);
49} 43}
50static inline ssize_t node_read_cpulist(struct device *dev, 44static inline ssize_t node_read_cpulist(struct device *dev,
51 struct device_attribute *attr, char *buf) 45 struct device_attribute *attr, char *buf)
52{ 46{
53 return node_read_cpumap(dev, 1, buf); 47 return node_read_cpumap(dev, true, buf);
54} 48}
55 49
56static DEVICE_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); 50static DEVICE_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL);
diff --git a/drivers/base/topology.c b/drivers/base/topology.c
index be7c1fb7c0c9..f7c353843ddf 100644
--- a/drivers/base/topology.c
+++ b/drivers/base/topology.c
@@ -42,29 +42,11 @@ static ssize_t show_##name(struct device *dev, \
42 return sprintf(buf, "%d\n", topology_##name(dev->id)); \ 42 return sprintf(buf, "%d\n", topology_##name(dev->id)); \
43} 43}
44 44
45#if defined(topology_thread_cpumask) || defined(topology_core_cpumask) || \
46 defined(topology_book_cpumask)
47static ssize_t show_cpumap(int type, const struct cpumask *mask, char *buf)
48{
49 ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf;
50 int n = 0;
51
52 if (len > 1) {
53 n = type?
54 cpulist_scnprintf(buf, len-2, mask) :
55 cpumask_scnprintf(buf, len-2, mask);
56 buf[n++] = '\n';
57 buf[n] = '\0';
58 }
59 return n;
60}
61#endif
62
63#define define_siblings_show_map(name) \ 45#define define_siblings_show_map(name) \
64static ssize_t show_##name(struct device *dev, \ 46static ssize_t show_##name(struct device *dev, \
65 struct device_attribute *attr, char *buf) \ 47 struct device_attribute *attr, char *buf) \
66{ \ 48{ \
67 return show_cpumap(0, topology_##name(dev->id), buf); \ 49 return cpumap_print_to_pagebuf(false, buf, topology_##name(dev->id));\
68} 50}
69 51
70#define define_siblings_show_list(name) \ 52#define define_siblings_show_list(name) \
@@ -72,7 +54,7 @@ static ssize_t show_##name##_list(struct device *dev, \
72 struct device_attribute *attr, \ 54 struct device_attribute *attr, \
73 char *buf) \ 55 char *buf) \
74{ \ 56{ \
75 return show_cpumap(1, topology_##name(dev->id), buf); \ 57 return cpumap_print_to_pagebuf(true, buf, topology_##name(dev->id));\
76} 58}
77 59
78#define define_siblings_show_func(name) \ 60#define define_siblings_show_func(name) \
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 2c6643fdc0cf..368bdac42603 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -77,11 +77,10 @@ static ssize_t broken_parity_status_store(struct device *dev,
77} 77}
78static DEVICE_ATTR_RW(broken_parity_status); 78static DEVICE_ATTR_RW(broken_parity_status);
79 79
80static ssize_t pci_dev_show_local_cpu(struct device *dev, int type, 80static ssize_t pci_dev_show_local_cpu(struct device *dev, bool list,
81 struct device_attribute *attr, char *buf) 81 struct device_attribute *attr, char *buf)
82{ 82{
83 const struct cpumask *mask; 83 const struct cpumask *mask;
84 int len;
85 84
86#ifdef CONFIG_NUMA 85#ifdef CONFIG_NUMA
87 mask = (dev_to_node(dev) == -1) ? cpu_online_mask : 86 mask = (dev_to_node(dev) == -1) ? cpu_online_mask :
@@ -89,59 +88,41 @@ static ssize_t pci_dev_show_local_cpu(struct device *dev, int type,
89#else 88#else
90 mask = cpumask_of_pcibus(to_pci_dev(dev)->bus); 89 mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
91#endif 90#endif
92 len = type ? 91 return cpumap_print_to_pagebuf(list, buf, mask);
93 cpumask_scnprintf(buf, PAGE_SIZE-2, mask) :
94 cpulist_scnprintf(buf, PAGE_SIZE-2, mask);
95
96 buf[len++] = '\n';
97 buf[len] = '\0';
98 return len;
99} 92}
100 93
101static ssize_t local_cpus_show(struct device *dev, 94static ssize_t local_cpus_show(struct device *dev,
102 struct device_attribute *attr, char *buf) 95 struct device_attribute *attr, char *buf)
103{ 96{
104 return pci_dev_show_local_cpu(dev, 1, attr, buf); 97 return pci_dev_show_local_cpu(dev, false, attr, buf);
105} 98}
106static DEVICE_ATTR_RO(local_cpus); 99static DEVICE_ATTR_RO(local_cpus);
107 100
108static ssize_t local_cpulist_show(struct device *dev, 101static ssize_t local_cpulist_show(struct device *dev,
109 struct device_attribute *attr, char *buf) 102 struct device_attribute *attr, char *buf)
110{ 103{
111 return pci_dev_show_local_cpu(dev, 0, attr, buf); 104 return pci_dev_show_local_cpu(dev, true, attr, buf);
112} 105}
113static DEVICE_ATTR_RO(local_cpulist); 106static DEVICE_ATTR_RO(local_cpulist);
114 107
115/* 108/*
116 * PCI Bus Class Devices 109 * PCI Bus Class Devices
117 */ 110 */
118static ssize_t pci_bus_show_cpuaffinity(struct device *dev, int type,
119 struct device_attribute *attr,
120 char *buf)
121{
122 int ret;
123 const struct cpumask *cpumask;
124
125 cpumask = cpumask_of_pcibus(to_pci_bus(dev));
126 ret = type ?
127 cpulist_scnprintf(buf, PAGE_SIZE-2, cpumask) :
128 cpumask_scnprintf(buf, PAGE_SIZE-2, cpumask);
129 buf[ret++] = '\n';
130 buf[ret] = '\0';
131 return ret;
132}
133
134static ssize_t cpuaffinity_show(struct device *dev, 111static ssize_t cpuaffinity_show(struct device *dev,
135 struct device_attribute *attr, char *buf) 112 struct device_attribute *attr, char *buf)
136{ 113{
137 return pci_bus_show_cpuaffinity(dev, 0, attr, buf); 114 const struct cpumask *cpumask = cpumask_of_pcibus(to_pci_bus(dev));
115
116 return cpumap_print_to_pagebuf(false, buf, cpumask);
138} 117}
139static DEVICE_ATTR_RO(cpuaffinity); 118static DEVICE_ATTR_RO(cpuaffinity);
140 119
141static ssize_t cpulistaffinity_show(struct device *dev, 120static ssize_t cpulistaffinity_show(struct device *dev,
142 struct device_attribute *attr, char *buf) 121 struct device_attribute *attr, char *buf)
143{ 122{
144 return pci_bus_show_cpuaffinity(dev, 1, attr, buf); 123 const struct cpumask *cpumask = cpumask_of_pcibus(to_pci_bus(dev));
124
125 return cpumap_print_to_pagebuf(true, buf, cpumask);
145} 126}
146static DEVICE_ATTR_RO(cpulistaffinity); 127static DEVICE_ATTR_RO(cpulistaffinity);
147 128
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index e1c8d080c427..9d5c3224a1e2 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -60,6 +60,7 @@
60 * bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region 60 * bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region
61 * bitmap_release_region(bitmap, pos, order) Free specified bit region 61 * bitmap_release_region(bitmap, pos, order) Free specified bit region
62 * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region 62 * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region
63 * bitmap_print_to_pagebuf(list, buf, mask, nbits) Print bitmap src as list/hex
63 */ 64 */
64 65
65/* 66/*
@@ -145,6 +146,8 @@ extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int o
145extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order); 146extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order);
146extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits); 147extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits);
147extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits); 148extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits);
149extern int bitmap_print_to_pagebuf(bool list, char *buf,
150 const unsigned long *maskp, int nmaskbits);
148 151
149#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG)) 152#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
150#define BITMAP_LAST_WORD_MASK(nbits) \ 153#define BITMAP_LAST_WORD_MASK(nbits) \
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 0a9a6da21e74..b950e9d6008b 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -803,6 +803,23 @@ static inline const struct cpumask *get_cpu_mask(unsigned int cpu)
803} 803}
804#endif /* NR_CPUS > BITS_PER_LONG */ 804#endif /* NR_CPUS > BITS_PER_LONG */
805 805
806/**
807 * cpumap_print_to_pagebuf - copies the cpumask into the buffer either
808 * as comma-separated list of cpus or hex values of cpumask
809 * @list: indicates whether the cpumap must be list
810 * @mask: the cpumask to copy
811 * @buf: the buffer to copy into
812 *
813 * Returns the length of the (null-terminated) @buf string, zero if
814 * nothing is copied.
815 */
816static inline ssize_t
817cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
818{
819 return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask),
820 nr_cpumask_bits);
821}
822
806/* 823/*
807 * 824 *
808 * From here down, all obsolete. Use cpumask_ variants! 825 * From here down, all obsolete. Use cpumask_ variants!
diff --git a/lib/bitmap.c b/lib/bitmap.c
index b499ab6ada29..5bc7a1128fe8 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -12,6 +12,8 @@
12#include <linux/bitmap.h> 12#include <linux/bitmap.h>
13#include <linux/bitops.h> 13#include <linux/bitops.h>
14#include <linux/bug.h> 14#include <linux/bug.h>
15
16#include <asm/page.h>
15#include <asm/uaccess.h> 17#include <asm/uaccess.h>
16 18
17/* 19/*
@@ -584,6 +586,33 @@ int bitmap_scnlistprintf(char *buf, unsigned int buflen,
584EXPORT_SYMBOL(bitmap_scnlistprintf); 586EXPORT_SYMBOL(bitmap_scnlistprintf);
585 587
586/** 588/**
589 * bitmap_print_to_pagebuf - convert bitmap to list or hex format ASCII string
590 * @list: indicates whether the bitmap must be list
591 * @buf: page aligned buffer into which string is placed
592 * @maskp: pointer to bitmap to convert
593 * @nmaskbits: size of bitmap, in bits
594 *
595 * Output format is a comma-separated list of decimal numbers and
596 * ranges if list is specified or hex digits grouped into comma-separated
597 * sets of 8 digits/set. Returns the number of characters written to buf.
598 */
599int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp,
600 int nmaskbits)
601{
602 ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf - 2;
603 int n = 0;
604
605 if (len > 1) {
606 n = list ? bitmap_scnlistprintf(buf, len, maskp, nmaskbits) :
607 bitmap_scnprintf(buf, len, maskp, nmaskbits);
608 buf[n++] = '\n';
609 buf[n] = '\0';
610 }
611 return n;
612}
613EXPORT_SYMBOL(bitmap_print_to_pagebuf);
614
615/**
587 * __bitmap_parselist - convert list format ASCII string to bitmap 616 * __bitmap_parselist - convert list format ASCII string to bitmap
588 * @buf: read nul-terminated user string from this buffer 617 * @buf: read nul-terminated user string from this buffer
589 * @buflen: buffer size in bytes. If string is smaller than this 618 * @buflen: buffer size in bytes. If string is smaller than this