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.c154
1 files changed, 80 insertions, 74 deletions
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 5693ecee9a40..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;
@@ -157,10 +154,10 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
157} 154}
158 155
159#undef K 156#undef K
160static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL); 157static DEVICE_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
161 158
162static ssize_t node_read_numastat(struct sys_device * dev, 159static ssize_t node_read_numastat(struct device *dev,
163 struct sysdev_attribute *attr, char * buf) 160 struct device_attribute *attr, char *buf)
164{ 161{
165 return sprintf(buf, 162 return sprintf(buf,
166 "numa_hit %lu\n" 163 "numa_hit %lu\n"
@@ -176,10 +173,10 @@ static ssize_t node_read_numastat(struct sys_device * dev,
176 node_page_state(dev->id, NUMA_LOCAL), 173 node_page_state(dev->id, NUMA_LOCAL),
177 node_page_state(dev->id, NUMA_OTHER)); 174 node_page_state(dev->id, NUMA_OTHER));
178} 175}
179static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); 176static DEVICE_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
180 177
181static ssize_t node_read_vmstat(struct sys_device *dev, 178static ssize_t node_read_vmstat(struct device *dev,
182 struct sysdev_attribute *attr, char *buf) 179 struct device_attribute *attr, char *buf)
183{ 180{
184 int nid = dev->id; 181 int nid = dev->id;
185 int i; 182 int i;
@@ -191,10 +188,10 @@ static ssize_t node_read_vmstat(struct sys_device *dev,
191 188
192 return n; 189 return n;
193} 190}
194static SYSDEV_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL); 191static DEVICE_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL);
195 192
196static ssize_t node_read_distance(struct sys_device * dev, 193static ssize_t node_read_distance(struct device *dev,
197 struct sysdev_attribute *attr, char * buf) 194 struct device_attribute *attr, char * buf)
198{ 195{
199 int nid = dev->id; 196 int nid = dev->id;
200 int len = 0; 197 int len = 0;
@@ -212,7 +209,7 @@ static ssize_t node_read_distance(struct sys_device * dev,
212 len += sprintf(buf + len, "\n"); 209 len += sprintf(buf + len, "\n");
213 return len; 210 return len;
214} 211}
215static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL); 212static DEVICE_ATTR(distance, S_IRUGO, node_read_distance, NULL);
216 213
217#ifdef CONFIG_HUGETLBFS 214#ifdef CONFIG_HUGETLBFS
218/* 215/*
@@ -230,7 +227,7 @@ static node_registration_func_t __hugetlb_unregister_node;
230static inline bool hugetlb_register_node(struct node *node) 227static inline bool hugetlb_register_node(struct node *node)
231{ 228{
232 if (__hugetlb_register_node && 229 if (__hugetlb_register_node &&
233 node_state(node->sysdev.id, N_HIGH_MEMORY)) { 230 node_state(node->dev.id, N_HIGH_MEMORY)) {
234 __hugetlb_register_node(node); 231 __hugetlb_register_node(node);
235 return true; 232 return true;
236 } 233 }
@@ -266,17 +263,17 @@ int register_node(struct node *node, int num, struct node *parent)
266{ 263{
267 int error; 264 int error;
268 265
269 node->sysdev.id = num; 266 node->dev.id = num;
270 node->sysdev.cls = &node_class; 267 node->dev.bus = &node_subsys;
271 error = sysdev_register(&node->sysdev); 268 error = device_register(&node->dev);
272 269
273 if (!error){ 270 if (!error){
274 sysdev_create_file(&node->sysdev, &attr_cpumap); 271 device_create_file(&node->dev, &dev_attr_cpumap);
275 sysdev_create_file(&node->sysdev, &attr_cpulist); 272 device_create_file(&node->dev, &dev_attr_cpulist);
276 sysdev_create_file(&node->sysdev, &attr_meminfo); 273 device_create_file(&node->dev, &dev_attr_meminfo);
277 sysdev_create_file(&node->sysdev, &attr_numastat); 274 device_create_file(&node->dev, &dev_attr_numastat);
278 sysdev_create_file(&node->sysdev, &attr_distance); 275 device_create_file(&node->dev, &dev_attr_distance);
279 sysdev_create_file(&node->sysdev, &attr_vmstat); 276 device_create_file(&node->dev, &dev_attr_vmstat);
280 277
281 scan_unevictable_register_node(node); 278 scan_unevictable_register_node(node);
282 279
@@ -296,17 +293,17 @@ int register_node(struct node *node, int num, struct node *parent)
296 */ 293 */
297void unregister_node(struct node *node) 294void unregister_node(struct node *node)
298{ 295{
299 sysdev_remove_file(&node->sysdev, &attr_cpumap); 296 device_remove_file(&node->dev, &dev_attr_cpumap);
300 sysdev_remove_file(&node->sysdev, &attr_cpulist); 297 device_remove_file(&node->dev, &dev_attr_cpulist);
301 sysdev_remove_file(&node->sysdev, &attr_meminfo); 298 device_remove_file(&node->dev, &dev_attr_meminfo);
302 sysdev_remove_file(&node->sysdev, &attr_numastat); 299 device_remove_file(&node->dev, &dev_attr_numastat);
303 sysdev_remove_file(&node->sysdev, &attr_distance); 300 device_remove_file(&node->dev, &dev_attr_distance);
304 sysdev_remove_file(&node->sysdev, &attr_vmstat); 301 device_remove_file(&node->dev, &dev_attr_vmstat);
305 302
306 scan_unevictable_unregister_node(node); 303 scan_unevictable_unregister_node(node);
307 hugetlb_unregister_node(node); /* no-op, if memoryless node */ 304 hugetlb_unregister_node(node); /* no-op, if memoryless node */
308 305
309 sysdev_unregister(&node->sysdev); 306 device_unregister(&node->dev);
310} 307}
311 308
312struct node node_devices[MAX_NUMNODES]; 309struct node node_devices[MAX_NUMNODES];
@@ -317,41 +314,41 @@ struct node node_devices[MAX_NUMNODES];
317int register_cpu_under_node(unsigned int cpu, unsigned int nid) 314int register_cpu_under_node(unsigned int cpu, unsigned int nid)
318{ 315{
319 int ret; 316 int ret;
320 struct sys_device *obj; 317 struct device *obj;
321 318
322 if (!node_online(nid)) 319 if (!node_online(nid))
323 return 0; 320 return 0;
324 321
325 obj = get_cpu_sysdev(cpu); 322 obj = get_cpu_device(cpu);
326 if (!obj) 323 if (!obj)
327 return 0; 324 return 0;
328 325
329 ret = sysfs_create_link(&node_devices[nid].sysdev.kobj, 326 ret = sysfs_create_link(&node_devices[nid].dev.kobj,
330 &obj->kobj, 327 &obj->kobj,
331 kobject_name(&obj->kobj)); 328 kobject_name(&obj->kobj));
332 if (ret) 329 if (ret)
333 return ret; 330 return ret;
334 331
335 return sysfs_create_link(&obj->kobj, 332 return sysfs_create_link(&obj->kobj,
336 &node_devices[nid].sysdev.kobj, 333 &node_devices[nid].dev.kobj,
337 kobject_name(&node_devices[nid].sysdev.kobj)); 334 kobject_name(&node_devices[nid].dev.kobj));
338} 335}
339 336
340int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) 337int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
341{ 338{
342 struct sys_device *obj; 339 struct device *obj;
343 340
344 if (!node_online(nid)) 341 if (!node_online(nid))
345 return 0; 342 return 0;
346 343
347 obj = get_cpu_sysdev(cpu); 344 obj = get_cpu_device(cpu);
348 if (!obj) 345 if (!obj)
349 return 0; 346 return 0;
350 347
351 sysfs_remove_link(&node_devices[nid].sysdev.kobj, 348 sysfs_remove_link(&node_devices[nid].dev.kobj,
352 kobject_name(&obj->kobj)); 349 kobject_name(&obj->kobj));
353 sysfs_remove_link(&obj->kobj, 350 sysfs_remove_link(&obj->kobj,
354 kobject_name(&node_devices[nid].sysdev.kobj)); 351 kobject_name(&node_devices[nid].dev.kobj));
355 352
356 return 0; 353 return 0;
357} 354}
@@ -393,15 +390,15 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
393 continue; 390 continue;
394 if (page_nid != nid) 391 if (page_nid != nid)
395 continue; 392 continue;
396 ret = sysfs_create_link_nowarn(&node_devices[nid].sysdev.kobj, 393 ret = sysfs_create_link_nowarn(&node_devices[nid].dev.kobj,
397 &mem_blk->sysdev.kobj, 394 &mem_blk->dev.kobj,
398 kobject_name(&mem_blk->sysdev.kobj)); 395 kobject_name(&mem_blk->dev.kobj));
399 if (ret) 396 if (ret)
400 return ret; 397 return ret;
401 398
402 return sysfs_create_link_nowarn(&mem_blk->sysdev.kobj, 399 return sysfs_create_link_nowarn(&mem_blk->dev.kobj,
403 &node_devices[nid].sysdev.kobj, 400 &node_devices[nid].dev.kobj,
404 kobject_name(&node_devices[nid].sysdev.kobj)); 401 kobject_name(&node_devices[nid].dev.kobj));
405 } 402 }
406 /* mem section does not span the specified node */ 403 /* mem section does not span the specified node */
407 return 0; 404 return 0;
@@ -434,10 +431,10 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
434 continue; 431 continue;
435 if (node_test_and_set(nid, *unlinked_nodes)) 432 if (node_test_and_set(nid, *unlinked_nodes))
436 continue; 433 continue;
437 sysfs_remove_link(&node_devices[nid].sysdev.kobj, 434 sysfs_remove_link(&node_devices[nid].dev.kobj,
438 kobject_name(&mem_blk->sysdev.kobj)); 435 kobject_name(&mem_blk->dev.kobj));
439 sysfs_remove_link(&mem_blk->sysdev.kobj, 436 sysfs_remove_link(&mem_blk->dev.kobj,
440 kobject_name(&node_devices[nid].sysdev.kobj)); 437 kobject_name(&node_devices[nid].dev.kobj));
441 } 438 }
442 NODEMASK_FREE(unlinked_nodes); 439 NODEMASK_FREE(unlinked_nodes);
443 return 0; 440 return 0;
@@ -468,7 +465,7 @@ static int link_mem_sections(int nid)
468 } 465 }
469 466
470 if (mem_blk) 467 if (mem_blk)
471 kobject_put(&mem_blk->sysdev.kobj); 468 kobject_put(&mem_blk->dev.kobj);
472 return err; 469 return err;
473} 470}
474 471
@@ -596,19 +593,19 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
596} 593}
597 594
598struct node_attr { 595struct node_attr {
599 struct sysdev_class_attribute attr; 596 struct device_attribute attr;
600 enum node_states state; 597 enum node_states state;
601}; 598};
602 599
603static ssize_t show_node_state(struct sysdev_class *class, 600static ssize_t show_node_state(struct device *dev,
604 struct sysdev_class_attribute *attr, char *buf) 601 struct device_attribute *attr, char *buf)
605{ 602{
606 struct node_attr *na = container_of(attr, struct node_attr, attr); 603 struct node_attr *na = container_of(attr, struct node_attr, attr);
607 return print_nodes_state(na->state, buf); 604 return print_nodes_state(na->state, buf);
608} 605}
609 606
610#define _NODE_ATTR(name, state) \ 607#define _NODE_ATTR(name, state) \
611 { _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state } 608 { __ATTR(name, 0444, show_node_state, NULL), state }
612 609
613static struct node_attr node_state_attr[] = { 610static struct node_attr node_state_attr[] = {
614 _NODE_ATTR(possible, N_POSSIBLE), 611 _NODE_ATTR(possible, N_POSSIBLE),
@@ -620,17 +617,26 @@ static struct node_attr node_state_attr[] = {
620#endif 617#endif
621}; 618};
622 619
623static struct sysdev_class_attribute *node_state_attrs[] = { 620static struct attribute *node_state_attrs[] = {
624 &node_state_attr[0].attr, 621 &node_state_attr[0].attr.attr,
625 &node_state_attr[1].attr, 622 &node_state_attr[1].attr.attr,
626 &node_state_attr[2].attr, 623 &node_state_attr[2].attr.attr,
627 &node_state_attr[3].attr, 624 &node_state_attr[3].attr.attr,
628#ifdef CONFIG_HIGHMEM 625#ifdef CONFIG_HIGHMEM
629 &node_state_attr[4].attr, 626 &node_state_attr[4].attr.attr,
630#endif 627#endif
631 NULL 628 NULL
632}; 629};
633 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
634#define NODE_CALLBACK_PRI 2 /* lower than SLAB */ 640#define NODE_CALLBACK_PRI 2 /* lower than SLAB */
635static int __init register_node_type(void) 641static int __init register_node_type(void)
636{ 642{
@@ -639,7 +645,7 @@ static int __init register_node_type(void)
639 BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES); 645 BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
640 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);
641 647
642 ret = sysdev_class_register(&node_class); 648 ret = subsys_system_register(&node_subsys, cpu_root_attr_groups);
643 if (!ret) { 649 if (!ret) {
644 hotplug_memory_notifier(node_memory_callback, 650 hotplug_memory_notifier(node_memory_callback,
645 NODE_CALLBACK_PRI); 651 NODE_CALLBACK_PRI);