aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSudeep Holla <sudeep.holla@arm.com>2014-09-30 09:48:22 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-11-07 14:45:00 -0500
commit5aaba36318e5995e8c95d077a46d9a4d00fcc1cd (patch)
treeedf9eb1ea758b82f1f04963a0fc54fab8bc8bc50
parent0372ffb35d00288802265586a29c117911d02fb8 (diff)
cpumask: factor out show_cpumap into separate helper function
Many sysfs *_show function use cpu{list,mask}_scnprintf to copy cpumap to the buffer aligned to PAGE_SIZE, append '\n' and '\0' to return null terminated buffer with newline. This patch creates a new helper function cpumap_print_to_pagebuf in cpumask.h using newly added bitmap_print_to_pagebuf and consolidates most of those sysfs functions using the new helper function. Signed-off-by: Sudeep Holla <sudeep.holla@arm.com> Suggested-by: Stephen Boyd <sboyd@codeaurora.org> Tested-by: Stephen Boyd <sboyd@codeaurora.org> Acked-by: "Rafael J. Wysocki" <rjw@rjwysocki.net> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: x86@kernel.org Cc: linux-acpi@vger.kernel.org Cc: linux-pci@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-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}