aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/node.c')
-rw-r--r--drivers/base/node.c168
1 files changed, 88 insertions, 80 deletions
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 793f796c4da3..44f427a66117 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -1,8 +1,7 @@
1/* 1/*
2 * drivers/base/node.c - basic Node class support 2 * Basic Node interface support
3 */ 3 */
4 4
5#include <linux/sysdev.h>
6#include <linux/module.h> 5#include <linux/module.h>
7#include <linux/init.h> 6#include <linux/init.h>
8#include <linux/mm.h> 7#include <linux/mm.h>
@@ -19,18 +18,16 @@
19#include <linux/swap.h> 18#include <linux/swap.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21 20
22static struct sysdev_class_attribute *node_state_attrs[]; 21static struct bus_type node_subsys = {
23
24static struct sysdev_class node_class = {
25 .name = "node", 22 .name = "node",
26 .attrs = node_state_attrs, 23 .dev_name = "node",
27}; 24};
28 25
29 26
30static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf) 27static ssize_t node_read_cpumap(struct device *dev, int type, char *buf)
31{ 28{
32 struct node *node_dev = to_node(dev); 29 struct node *node_dev = to_node(dev);
33 const struct cpumask *mask = cpumask_of_node(node_dev->sysdev.id); 30 const struct cpumask *mask = cpumask_of_node(node_dev->dev.id);
34 int len; 31 int len;
35 32
36 /* 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. */
@@ -44,23 +41,23 @@ static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf)
44 return len; 41 return len;
45} 42}
46 43
47static inline ssize_t node_read_cpumask(struct sys_device *dev, 44static inline ssize_t node_read_cpumask(struct device *dev,
48 struct sysdev_attribute *attr, char *buf) 45 struct device_attribute *attr, char *buf)
49{ 46{
50 return node_read_cpumap(dev, 0, buf); 47 return node_read_cpumap(dev, 0, buf);
51} 48}
52static inline ssize_t node_read_cpulist(struct sys_device *dev, 49static inline ssize_t node_read_cpulist(struct device *dev,
53 struct sysdev_attribute *attr, char *buf) 50 struct device_attribute *attr, char *buf)
54{ 51{
55 return node_read_cpumap(dev, 1, buf); 52 return node_read_cpumap(dev, 1, buf);
56} 53}
57 54
58static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); 55static DEVICE_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL);
59static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); 56static DEVICE_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL);
60 57
61#define K(x) ((x) << (PAGE_SHIFT - 10)) 58#define K(x) ((x) << (PAGE_SHIFT - 10))
62static ssize_t node_read_meminfo(struct sys_device * dev, 59static ssize_t node_read_meminfo(struct device *dev,
63 struct sysdev_attribute *attr, char * buf) 60 struct device_attribute *attr, char *buf)
64{ 61{
65 int n; 62 int n;
66 int nid = dev->id; 63 int nid = dev->id;
@@ -127,12 +124,13 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
127 nid, K(node_page_state(nid, NR_WRITEBACK)), 124 nid, K(node_page_state(nid, NR_WRITEBACK)),
128 nid, K(node_page_state(nid, NR_FILE_PAGES)), 125 nid, K(node_page_state(nid, NR_FILE_PAGES)),
129 nid, K(node_page_state(nid, NR_FILE_MAPPED)), 126 nid, K(node_page_state(nid, NR_FILE_MAPPED)),
130 nid, K(node_page_state(nid, NR_ANON_PAGES)
131#ifdef CONFIG_TRANSPARENT_HUGEPAGE 127#ifdef CONFIG_TRANSPARENT_HUGEPAGE
128 nid, K(node_page_state(nid, NR_ANON_PAGES)
132 + node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) * 129 + node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) *
133 HPAGE_PMD_NR 130 HPAGE_PMD_NR),
131#else
132 nid, K(node_page_state(nid, NR_ANON_PAGES)),
134#endif 133#endif
135 ),
136 nid, K(node_page_state(nid, NR_SHMEM)), 134 nid, K(node_page_state(nid, NR_SHMEM)),
137 nid, node_page_state(nid, NR_KERNEL_STACK) * 135 nid, node_page_state(nid, NR_KERNEL_STACK) *
138 THREAD_SIZE / 1024, 136 THREAD_SIZE / 1024,
@@ -143,22 +141,23 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
143 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) + 141 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) +
144 node_page_state(nid, NR_SLAB_UNRECLAIMABLE)), 142 node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
145 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)), 143 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)),
146 nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE))
147#ifdef CONFIG_TRANSPARENT_HUGEPAGE 144#ifdef CONFIG_TRANSPARENT_HUGEPAGE
145 nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE))
148 , nid, 146 , nid,
149 K(node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) * 147 K(node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) *
150 HPAGE_PMD_NR) 148 HPAGE_PMD_NR));
149#else
150 nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE)));
151#endif 151#endif
152 );
153 n += hugetlb_report_node_meminfo(nid, buf + n); 152 n += hugetlb_report_node_meminfo(nid, buf + n);
154 return n; 153 return n;
155} 154}
156 155
157#undef K 156#undef K
158static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL); 157static DEVICE_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
159 158
160static ssize_t node_read_numastat(struct sys_device * dev, 159static ssize_t node_read_numastat(struct device *dev,
161 struct sysdev_attribute *attr, char * buf) 160 struct device_attribute *attr, char *buf)
162{ 161{
163 return sprintf(buf, 162 return sprintf(buf,
164 "numa_hit %lu\n" 163 "numa_hit %lu\n"
@@ -174,10 +173,10 @@ static ssize_t node_read_numastat(struct sys_device * dev,
174 node_page_state(dev->id, NUMA_LOCAL), 173 node_page_state(dev->id, NUMA_LOCAL),
175 node_page_state(dev->id, NUMA_OTHER)); 174 node_page_state(dev->id, NUMA_OTHER));
176} 175}
177static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); 176static DEVICE_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
178 177
179static ssize_t node_read_vmstat(struct sys_device *dev, 178static ssize_t node_read_vmstat(struct device *dev,
180 struct sysdev_attribute *attr, char *buf) 179 struct device_attribute *attr, char *buf)
181{ 180{
182 int nid = dev->id; 181 int nid = dev->id;
183 int i; 182 int i;
@@ -189,10 +188,10 @@ static ssize_t node_read_vmstat(struct sys_device *dev,
189 188
190 return n; 189 return n;
191} 190}
192static SYSDEV_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL); 191static DEVICE_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL);
193 192
194static ssize_t node_read_distance(struct sys_device * dev, 193static ssize_t node_read_distance(struct device *dev,
195 struct sysdev_attribute *attr, char * buf) 194 struct device_attribute *attr, char * buf)
196{ 195{
197 int nid = dev->id; 196 int nid = dev->id;
198 int len = 0; 197 int len = 0;
@@ -210,7 +209,7 @@ static ssize_t node_read_distance(struct sys_device * dev,
210 len += sprintf(buf + len, "\n"); 209 len += sprintf(buf + len, "\n");
211 return len; 210 return len;
212} 211}
213static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL); 212static DEVICE_ATTR(distance, S_IRUGO, node_read_distance, NULL);
214 213
215#ifdef CONFIG_HUGETLBFS 214#ifdef CONFIG_HUGETLBFS
216/* 215/*
@@ -228,7 +227,7 @@ static node_registration_func_t __hugetlb_unregister_node;
228static inline bool hugetlb_register_node(struct node *node) 227static inline bool hugetlb_register_node(struct node *node)
229{ 228{
230 if (__hugetlb_register_node && 229 if (__hugetlb_register_node &&
231 node_state(node->sysdev.id, N_HIGH_MEMORY)) { 230 node_state(node->dev.id, N_HIGH_MEMORY)) {
232 __hugetlb_register_node(node); 231 __hugetlb_register_node(node);
233 return true; 232 return true;
234 } 233 }
@@ -264,17 +263,17 @@ int register_node(struct node *node, int num, struct node *parent)
264{ 263{
265 int error; 264 int error;
266 265
267 node->sysdev.id = num; 266 node->dev.id = num;
268 node->sysdev.cls = &node_class; 267 node->dev.bus = &node_subsys;
269 error = sysdev_register(&node->sysdev); 268 error = device_register(&node->dev);
270 269
271 if (!error){ 270 if (!error){
272 sysdev_create_file(&node->sysdev, &attr_cpumap); 271 device_create_file(&node->dev, &dev_attr_cpumap);
273 sysdev_create_file(&node->sysdev, &attr_cpulist); 272 device_create_file(&node->dev, &dev_attr_cpulist);
274 sysdev_create_file(&node->sysdev, &attr_meminfo); 273 device_create_file(&node->dev, &dev_attr_meminfo);
275 sysdev_create_file(&node->sysdev, &attr_numastat); 274 device_create_file(&node->dev, &dev_attr_numastat);
276 sysdev_create_file(&node->sysdev, &attr_distance); 275 device_create_file(&node->dev, &dev_attr_distance);
277 sysdev_create_file(&node->sysdev, &attr_vmstat); 276 device_create_file(&node->dev, &dev_attr_vmstat);
278 277
279 scan_unevictable_register_node(node); 278 scan_unevictable_register_node(node);
280 279
@@ -294,17 +293,17 @@ int register_node(struct node *node, int num, struct node *parent)
294 */ 293 */
295void unregister_node(struct node *node) 294void unregister_node(struct node *node)
296{ 295{
297 sysdev_remove_file(&node->sysdev, &attr_cpumap); 296 device_remove_file(&node->dev, &dev_attr_cpumap);
298 sysdev_remove_file(&node->sysdev, &attr_cpulist); 297 device_remove_file(&node->dev, &dev_attr_cpulist);
299 sysdev_remove_file(&node->sysdev, &attr_meminfo); 298 device_remove_file(&node->dev, &dev_attr_meminfo);
300 sysdev_remove_file(&node->sysdev, &attr_numastat); 299 device_remove_file(&node->dev, &dev_attr_numastat);
301 sysdev_remove_file(&node->sysdev, &attr_distance); 300 device_remove_file(&node->dev, &dev_attr_distance);
302 sysdev_remove_file(&node->sysdev, &attr_vmstat); 301 device_remove_file(&node->dev, &dev_attr_vmstat);
303 302
304 scan_unevictable_unregister_node(node); 303 scan_unevictable_unregister_node(node);
305 hugetlb_unregister_node(node); /* no-op, if memoryless node */ 304 hugetlb_unregister_node(node); /* no-op, if memoryless node */
306 305
307 sysdev_unregister(&node->sysdev); 306 device_unregister(&node->dev);
308} 307}
309 308
310struct node node_devices[MAX_NUMNODES]; 309struct node node_devices[MAX_NUMNODES];
@@ -315,41 +314,41 @@ struct node node_devices[MAX_NUMNODES];
315int register_cpu_under_node(unsigned int cpu, unsigned int nid) 314int register_cpu_under_node(unsigned int cpu, unsigned int nid)
316{ 315{
317 int ret; 316 int ret;
318 struct sys_device *obj; 317 struct device *obj;
319 318
320 if (!node_online(nid)) 319 if (!node_online(nid))
321 return 0; 320 return 0;
322 321
323 obj = get_cpu_sysdev(cpu); 322 obj = get_cpu_device(cpu);
324 if (!obj) 323 if (!obj)
325 return 0; 324 return 0;
326 325
327 ret = sysfs_create_link(&node_devices[nid].sysdev.kobj, 326 ret = sysfs_create_link(&node_devices[nid].dev.kobj,
328 &obj->kobj, 327 &obj->kobj,
329 kobject_name(&obj->kobj)); 328 kobject_name(&obj->kobj));
330 if (ret) 329 if (ret)
331 return ret; 330 return ret;
332 331
333 return sysfs_create_link(&obj->kobj, 332 return sysfs_create_link(&obj->kobj,
334 &node_devices[nid].sysdev.kobj, 333 &node_devices[nid].dev.kobj,
335 kobject_name(&node_devices[nid].sysdev.kobj)); 334 kobject_name(&node_devices[nid].dev.kobj));
336} 335}
337 336
338int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) 337int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
339{ 338{
340 struct sys_device *obj; 339 struct device *obj;
341 340
342 if (!node_online(nid)) 341 if (!node_online(nid))
343 return 0; 342 return 0;
344 343
345 obj = get_cpu_sysdev(cpu); 344 obj = get_cpu_device(cpu);
346 if (!obj) 345 if (!obj)
347 return 0; 346 return 0;
348 347
349 sysfs_remove_link(&node_devices[nid].sysdev.kobj, 348 sysfs_remove_link(&node_devices[nid].dev.kobj,
350 kobject_name(&obj->kobj)); 349 kobject_name(&obj->kobj));
351 sysfs_remove_link(&obj->kobj, 350 sysfs_remove_link(&obj->kobj,
352 kobject_name(&node_devices[nid].sysdev.kobj)); 351 kobject_name(&node_devices[nid].dev.kobj));
353 352
354 return 0; 353 return 0;
355} 354}
@@ -391,15 +390,15 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
391 continue; 390 continue;
392 if (page_nid != nid) 391 if (page_nid != nid)
393 continue; 392 continue;
394 ret = sysfs_create_link_nowarn(&node_devices[nid].sysdev.kobj, 393 ret = sysfs_create_link_nowarn(&node_devices[nid].dev.kobj,
395 &mem_blk->sysdev.kobj, 394 &mem_blk->dev.kobj,
396 kobject_name(&mem_blk->sysdev.kobj)); 395 kobject_name(&mem_blk->dev.kobj));
397 if (ret) 396 if (ret)
398 return ret; 397 return ret;
399 398
400 return sysfs_create_link_nowarn(&mem_blk->sysdev.kobj, 399 return sysfs_create_link_nowarn(&mem_blk->dev.kobj,
401 &node_devices[nid].sysdev.kobj, 400 &node_devices[nid].dev.kobj,
402 kobject_name(&node_devices[nid].sysdev.kobj)); 401 kobject_name(&node_devices[nid].dev.kobj));
403 } 402 }
404 /* mem section does not span the specified node */ 403 /* mem section does not span the specified node */
405 return 0; 404 return 0;
@@ -432,10 +431,10 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
432 continue; 431 continue;
433 if (node_test_and_set(nid, *unlinked_nodes)) 432 if (node_test_and_set(nid, *unlinked_nodes))
434 continue; 433 continue;
435 sysfs_remove_link(&node_devices[nid].sysdev.kobj, 434 sysfs_remove_link(&node_devices[nid].dev.kobj,
436 kobject_name(&mem_blk->sysdev.kobj)); 435 kobject_name(&mem_blk->dev.kobj));
437 sysfs_remove_link(&mem_blk->sysdev.kobj, 436 sysfs_remove_link(&mem_blk->dev.kobj,
438 kobject_name(&node_devices[nid].sysdev.kobj)); 437 kobject_name(&node_devices[nid].dev.kobj));
439 } 438 }
440 NODEMASK_FREE(unlinked_nodes); 439 NODEMASK_FREE(unlinked_nodes);
441 return 0; 440 return 0;
@@ -466,7 +465,7 @@ static int link_mem_sections(int nid)
466 } 465 }
467 466
468 if (mem_blk) 467 if (mem_blk)
469 kobject_put(&mem_blk->sysdev.kobj); 468 kobject_put(&mem_blk->dev.kobj);
470 return err; 469 return err;
471} 470}
472 471
@@ -594,19 +593,19 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
594} 593}
595 594
596struct node_attr { 595struct node_attr {
597 struct sysdev_class_attribute attr; 596 struct device_attribute attr;
598 enum node_states state; 597 enum node_states state;
599}; 598};
600 599
601static ssize_t show_node_state(struct sysdev_class *class, 600static ssize_t show_node_state(struct device *dev,
602 struct sysdev_class_attribute *attr, char *buf) 601 struct device_attribute *attr, char *buf)
603{ 602{
604 struct node_attr *na = container_of(attr, struct node_attr, attr); 603 struct node_attr *na = container_of(attr, struct node_attr, attr);
605 return print_nodes_state(na->state, buf); 604 return print_nodes_state(na->state, buf);
606} 605}
607 606
608#define _NODE_ATTR(name, state) \ 607#define _NODE_ATTR(name, state) \
609 { _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state } 608 { __ATTR(name, 0444, show_node_state, NULL), state }
610 609
611static struct node_attr node_state_attr[] = { 610static struct node_attr node_state_attr[] = {
612 _NODE_ATTR(possible, N_POSSIBLE), 611 _NODE_ATTR(possible, N_POSSIBLE),
@@ -618,17 +617,26 @@ static struct node_attr node_state_attr[] = {
618#endif 617#endif
619}; 618};
620 619
621static struct sysdev_class_attribute *node_state_attrs[] = { 620static struct attribute *node_state_attrs[] = {
622 &node_state_attr[0].attr, 621 &node_state_attr[0].attr.attr,
623 &node_state_attr[1].attr, 622 &node_state_attr[1].attr.attr,
624 &node_state_attr[2].attr, 623 &node_state_attr[2].attr.attr,
625 &node_state_attr[3].attr, 624 &node_state_attr[3].attr.attr,
626#ifdef CONFIG_HIGHMEM 625#ifdef CONFIG_HIGHMEM
627 &node_state_attr[4].attr, 626 &node_state_attr[4].attr.attr,
628#endif 627#endif
629 NULL 628 NULL
630}; 629};
631 630
631static struct attribute_group memory_root_attr_group = {
632 .attrs = node_state_attrs,
633};
634
635static const struct attribute_group *cpu_root_attr_groups[] = {
636 &memory_root_attr_group,
637 NULL,
638};
639
632#define NODE_CALLBACK_PRI 2 /* lower than SLAB */ 640#define NODE_CALLBACK_PRI 2 /* lower than SLAB */
633static int __init register_node_type(void) 641static int __init register_node_type(void)
634{ 642{
@@ -637,7 +645,7 @@ static int __init register_node_type(void)
637 BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES); 645 BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
638 BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES); 646 BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES);
639 647
640 ret = sysdev_class_register(&node_class); 648 ret = subsys_system_register(&node_subsys, cpu_root_attr_groups);
641 if (!ret) { 649 if (!ret) {
642 hotplug_memory_notifier(node_memory_callback, 650 hotplug_memory_notifier(node_memory_callback,
643 NODE_CALLBACK_PRI); 651 NODE_CALLBACK_PRI);