Commit 39106dcf85285e78f3b290022122c76f851379b8
Committed by
Ingo Molnar
1 parent
fb0f330e62
Exists in
master
and in
7 other branches
cpumask: use new cpus_scnprintf function
* Cleaned up references to cpumask_scnprintf() and added new cpulist_scnprintf() interfaces where appropriate. * Fix some small bugs (or code efficiency improvments) for various uses of cpumask_scnprintf. * Clean up some checkpatch errors. Signed-off-by: Mike Travis <travis@sgi.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Showing 6 changed files with 108 additions and 20 deletions Side-by-side Diff
drivers/base/node.c
... | ... | @@ -19,23 +19,35 @@ |
19 | 19 | }; |
20 | 20 | |
21 | 21 | |
22 | -static ssize_t node_read_cpumap(struct sys_device * dev, char * buf) | |
22 | +static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf) | |
23 | 23 | { |
24 | 24 | struct node *node_dev = to_node(dev); |
25 | 25 | node_to_cpumask_ptr(mask, node_dev->sysdev.id); |
26 | 26 | int len; |
27 | 27 | |
28 | - /* 2004/06/03: buf currently PAGE_SIZE, need > 1 char per 4 bits. */ | |
29 | - BUILD_BUG_ON(MAX_NUMNODES/4 > PAGE_SIZE/2); | |
28 | + /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */ | |
29 | + BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1)); | |
30 | 30 | |
31 | - len = cpumask_scnprintf(buf, PAGE_SIZE-2, *mask); | |
31 | + len = type? | |
32 | + cpulist_scnprintf(buf, PAGE_SIZE-2, *mask): | |
33 | + cpumask_scnprintf(buf, PAGE_SIZE-2, *mask); | |
32 | 34 | buf[len++] = '\n'; |
33 | 35 | buf[len] = '\0'; |
34 | 36 | return len; |
35 | 37 | } |
36 | 38 | |
37 | -static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumap, NULL); | |
39 | +static inline ssize_t node_read_cpumask(struct sys_device *dev, char *buf) | |
40 | +{ | |
41 | + return node_read_cpumap(dev, 0, buf); | |
42 | +} | |
43 | +static inline ssize_t node_read_cpulist(struct sys_device *dev, char *buf) | |
44 | +{ | |
45 | + return node_read_cpumap(dev, 1, buf); | |
46 | +} | |
38 | 47 | |
48 | +static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); | |
49 | +static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); | |
50 | + | |
39 | 51 | #define K(x) ((x) << (PAGE_SHIFT - 10)) |
40 | 52 | static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) |
41 | 53 | { |
... | ... | @@ -150,6 +162,7 @@ |
150 | 162 | |
151 | 163 | if (!error){ |
152 | 164 | sysdev_create_file(&node->sysdev, &attr_cpumap); |
165 | + sysdev_create_file(&node->sysdev, &attr_cpulist); | |
153 | 166 | sysdev_create_file(&node->sysdev, &attr_meminfo); |
154 | 167 | sysdev_create_file(&node->sysdev, &attr_numastat); |
155 | 168 | sysdev_create_file(&node->sysdev, &attr_distance); |
... | ... | @@ -167,6 +180,7 @@ |
167 | 180 | void unregister_node(struct node *node) |
168 | 181 | { |
169 | 182 | sysdev_remove_file(&node->sysdev, &attr_cpumap); |
183 | + sysdev_remove_file(&node->sysdev, &attr_cpulist); | |
170 | 184 | sysdev_remove_file(&node->sysdev, &attr_meminfo); |
171 | 185 | sysdev_remove_file(&node->sysdev, &attr_numastat); |
172 | 186 | sysdev_remove_file(&node->sysdev, &attr_distance); |
drivers/base/topology.c
... | ... | @@ -40,15 +40,38 @@ |
40 | 40 | return sprintf(buf, "%d\n", topology_##name(cpu)); \ |
41 | 41 | } |
42 | 42 | |
43 | -#define define_siblings_show_func(name) \ | |
44 | -static ssize_t show_##name(struct sys_device *dev, char *buf) \ | |
43 | +static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf) | |
44 | +{ | |
45 | + ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf; | |
46 | + int n = 0; | |
47 | + | |
48 | + if (len > 1) { | |
49 | + n = type? | |
50 | + cpulist_scnprintf(buf, len-2, *mask): | |
51 | + cpumask_scnprintf(buf, len-2, *mask); | |
52 | + buf[n++] = '\n'; | |
53 | + buf[n] = '\0'; | |
54 | + } | |
55 | + return n; | |
56 | +} | |
57 | + | |
58 | +#define define_siblings_show_map(name) \ | |
59 | +static inline ssize_t show_##name(struct sys_device *dev, char *buf) \ | |
45 | 60 | { \ |
46 | - ssize_t len = -1; \ | |
47 | 61 | unsigned int cpu = dev->id; \ |
48 | - len = cpumask_scnprintf(buf, NR_CPUS+1, topology_##name(cpu)); \ | |
49 | - return (len + sprintf(buf + len, "\n")); \ | |
62 | + return show_cpumap(0, &(topology_##name(cpu)), buf); \ | |
50 | 63 | } |
51 | 64 | |
65 | +#define define_siblings_show_list(name) \ | |
66 | +static inline ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ | |
67 | +{ \ | |
68 | + unsigned int cpu = dev->id; \ | |
69 | + return show_cpumap(1, &(topology_##name(cpu)), buf); \ | |
70 | +} | |
71 | + | |
72 | +#define define_siblings_show_func(name) \ | |
73 | + define_siblings_show_map(name); define_siblings_show_list(name) | |
74 | + | |
52 | 75 | #ifdef topology_physical_package_id |
53 | 76 | define_id_show_func(physical_package_id); |
54 | 77 | define_one_ro(physical_package_id); |
... | ... | @@ -68,7 +91,9 @@ |
68 | 91 | #ifdef topology_thread_siblings |
69 | 92 | define_siblings_show_func(thread_siblings); |
70 | 93 | define_one_ro(thread_siblings); |
71 | -#define ref_thread_siblings_attr &attr_thread_siblings.attr, | |
94 | +define_one_ro(thread_siblings_list); | |
95 | +#define ref_thread_siblings_attr \ | |
96 | + &attr_thread_siblings.attr, &attr_thread_siblings_list.attr, | |
72 | 97 | #else |
73 | 98 | #define ref_thread_siblings_attr |
74 | 99 | #endif |
... | ... | @@ -76,7 +101,9 @@ |
76 | 101 | #ifdef topology_core_siblings |
77 | 102 | define_siblings_show_func(core_siblings); |
78 | 103 | define_one_ro(core_siblings); |
79 | -#define ref_core_siblings_attr &attr_core_siblings.attr, | |
104 | +define_one_ro(core_siblings_list); | |
105 | +#define ref_core_siblings_attr \ | |
106 | + &attr_core_siblings.attr, &attr_core_siblings_list.attr, | |
80 | 107 | #else |
81 | 108 | #define ref_core_siblings_attr |
82 | 109 | #endif |
drivers/pci/pci-sysfs.c
... | ... | @@ -73,10 +73,25 @@ |
73 | 73 | |
74 | 74 | mask = pcibus_to_cpumask(to_pci_dev(dev)->bus); |
75 | 75 | len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask); |
76 | - strcat(buf,"\n"); | |
77 | - return 1+len; | |
76 | + buf[len++] = '\n'; | |
77 | + buf[len] = '\0'; | |
78 | + return len; | |
78 | 79 | } |
79 | 80 | |
81 | + | |
82 | +static ssize_t local_cpulist_show(struct device *dev, | |
83 | + struct device_attribute *attr, char *buf) | |
84 | +{ | |
85 | + cpumask_t mask; | |
86 | + int len; | |
87 | + | |
88 | + mask = pcibus_to_cpumask(to_pci_dev(dev)->bus); | |
89 | + len = cpulist_scnprintf(buf, PAGE_SIZE-2, mask); | |
90 | + buf[len++] = '\n'; | |
91 | + buf[len] = '\0'; | |
92 | + return len; | |
93 | +} | |
94 | + | |
80 | 95 | /* show resources */ |
81 | 96 | static ssize_t |
82 | 97 | resource_show(struct device * dev, struct device_attribute *attr, char * buf) |
... | ... | @@ -201,6 +216,7 @@ |
201 | 216 | __ATTR_RO(class), |
202 | 217 | __ATTR_RO(irq), |
203 | 218 | __ATTR_RO(local_cpus), |
219 | + __ATTR_RO(local_cpulist), | |
204 | 220 | __ATTR_RO(modalias), |
205 | 221 | #ifdef CONFIG_NUMA |
206 | 222 | __ATTR_RO(numa_node), |
drivers/pci/probe.c
... | ... | @@ -82,6 +82,7 @@ |
82 | 82 | * PCI Bus Class Devices |
83 | 83 | */ |
84 | 84 | static ssize_t pci_bus_show_cpuaffinity(struct device *dev, |
85 | + int type, | |
85 | 86 | struct device_attribute *attr, |
86 | 87 | char *buf) |
87 | 88 | { |
88 | 89 | |
... | ... | @@ -89,12 +90,30 @@ |
89 | 90 | cpumask_t cpumask; |
90 | 91 | |
91 | 92 | cpumask = pcibus_to_cpumask(to_pci_bus(dev)); |
92 | - ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask); | |
93 | - if (ret < PAGE_SIZE) | |
94 | - buf[ret++] = '\n'; | |
93 | + ret = type? | |
94 | + cpulist_scnprintf(buf, PAGE_SIZE-2, cpumask): | |
95 | + cpumask_scnprintf(buf, PAGE_SIZE-2, cpumask); | |
96 | + buf[ret++] = '\n'; | |
97 | + buf[ret] = '\0'; | |
95 | 98 | return ret; |
96 | 99 | } |
97 | -DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpuaffinity, NULL); | |
100 | + | |
101 | +static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev, | |
102 | + struct device_attribute *attr, | |
103 | + char *buf) | |
104 | +{ | |
105 | + return pci_bus_show_cpuaffinity(dev, 0, attr, buf); | |
106 | +} | |
107 | + | |
108 | +static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev, | |
109 | + struct device_attribute *attr, | |
110 | + char *buf) | |
111 | +{ | |
112 | + return pci_bus_show_cpuaffinity(dev, 1, attr, buf); | |
113 | +} | |
114 | + | |
115 | +DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpumaskaffinity, NULL); | |
116 | +DEVICE_ATTR(cpulistaffinity, S_IRUGO, pci_bus_show_cpulistaffinity, NULL); | |
98 | 117 | |
99 | 118 | /* |
100 | 119 | * PCI Bus Class |
kernel/cpuset.c
... | ... | @@ -2254,8 +2254,16 @@ |
2254 | 2254 | m->count += cpumask_scnprintf(m->buf + m->count, m->size - m->count, |
2255 | 2255 | task->cpus_allowed); |
2256 | 2256 | seq_printf(m, "\n"); |
2257 | + seq_printf(m, "Cpus_allowed_list:\t"); | |
2258 | + m->count += cpulist_scnprintf(m->buf + m->count, m->size - m->count, | |
2259 | + task->cpus_allowed); | |
2260 | + seq_printf(m, "\n"); | |
2257 | 2261 | seq_printf(m, "Mems_allowed:\t"); |
2258 | 2262 | m->count += nodemask_scnprintf(m->buf + m->count, m->size - m->count, |
2263 | + task->mems_allowed); | |
2264 | + seq_printf(m, "\n"); | |
2265 | + seq_printf(m, "Mems_allowed_list:\t"); | |
2266 | + m->count += nodelist_scnprintf(m->buf + m->count, m->size - m->count, | |
2259 | 2267 | task->mems_allowed); |
2260 | 2268 | seq_printf(m, "\n"); |
2261 | 2269 | } |
kernel/sched_stats.h
... | ... | @@ -9,7 +9,12 @@ |
9 | 9 | static int show_schedstat(struct seq_file *seq, void *v) |
10 | 10 | { |
11 | 11 | int cpu; |
12 | + int mask_len = NR_CPUS/32 * 9; | |
13 | + char *mask_str = kmalloc(mask_len, GFP_KERNEL); | |
12 | 14 | |
15 | + if (mask_str == NULL) | |
16 | + return -ENOMEM; | |
17 | + | |
13 | 18 | seq_printf(seq, "version %d\n", SCHEDSTAT_VERSION); |
14 | 19 | seq_printf(seq, "timestamp %lu\n", jiffies); |
15 | 20 | for_each_online_cpu(cpu) { |
16 | 21 | |
... | ... | @@ -36,9 +41,8 @@ |
36 | 41 | preempt_disable(); |
37 | 42 | for_each_domain(cpu, sd) { |
38 | 43 | enum cpu_idle_type itype; |
39 | - char mask_str[NR_CPUS]; | |
40 | 44 | |
41 | - cpumask_scnprintf(mask_str, NR_CPUS, sd->span); | |
45 | + cpumask_scnprintf(mask_str, mask_len, sd->span); | |
42 | 46 | seq_printf(seq, "domain%d %s", dcount++, mask_str); |
43 | 47 | for (itype = CPU_IDLE; itype < CPU_MAX_IDLE_TYPES; |
44 | 48 | itype++) { |