2 * drivers/base/node.c - basic Node class support
5 #include <linux/sysdev.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
9 #include <linux/node.h>
10 #include <linux/hugetlb.h>
11 #include <linux/cpumask.h>
12 #include <linux/topology.h>
14 static struct sysdev_class node_class
= {
15 set_kset_name("node"),
19 static ssize_t
node_read_cpumap(struct sys_device
* dev
, char * buf
)
21 struct node
*node_dev
= to_node(dev
);
22 cpumask_t mask
= node_to_cpumask(node_dev
->sysdev
.id
);
25 /* 2004/06/03: buf currently PAGE_SIZE, need > 1 char per 4 bits. */
26 BUILD_BUG_ON(NR_CPUS
/4 > PAGE_SIZE
/2);
28 len
= cpumask_scnprintf(buf
, PAGE_SIZE
-1, mask
);
29 len
+= sprintf(buf
+ len
, "\n");
33 static SYSDEV_ATTR(cpumap
, S_IRUGO
, node_read_cpumap
, NULL
);
35 #define K(x) ((x) << (PAGE_SHIFT - 10))
36 static ssize_t
node_read_meminfo(struct sys_device
* dev
, char * buf
)
41 unsigned long inactive
;
45 si_meminfo_node(&i
, nid
);
46 __get_zone_counts(&active
, &inactive
, &free
, NODE_DATA(nid
));
49 "Node %d MemTotal: %8lu kB\n"
50 "Node %d MemFree: %8lu kB\n"
51 "Node %d MemUsed: %8lu kB\n"
52 "Node %d Active: %8lu kB\n"
53 "Node %d Inactive: %8lu kB\n"
54 "Node %d HighTotal: %8lu kB\n"
55 "Node %d HighFree: %8lu kB\n"
56 "Node %d LowTotal: %8lu kB\n"
57 "Node %d LowFree: %8lu kB\n",
60 nid
, K(i
.totalram
- i
.freeram
),
65 nid
, K(i
.totalram
- i
.totalhigh
),
66 nid
, K(i
.freeram
- i
.freehigh
));
67 n
+= hugetlb_report_node_meminfo(nid
, buf
+ n
);
72 static SYSDEV_ATTR(meminfo
, S_IRUGO
, node_read_meminfo
, NULL
);
74 static ssize_t
node_read_numastat(struct sys_device
* dev
, char * buf
)
76 unsigned long numa_hit
, numa_miss
, interleave_hit
, numa_foreign
;
77 unsigned long local_node
, other_node
;
79 pg_data_t
*pg
= NODE_DATA(dev
->id
);
86 for (i
= 0; i
< MAX_NR_ZONES
; i
++) {
87 struct zone
*z
= &pg
->node_zones
[i
];
88 for (cpu
= 0; cpu
< NR_CPUS
; cpu
++) {
89 struct per_cpu_pageset
*ps
= &z
->pageset
[cpu
];
90 numa_hit
+= ps
->numa_hit
;
91 numa_miss
+= ps
->numa_miss
;
92 numa_foreign
+= ps
->numa_foreign
;
93 interleave_hit
+= ps
->interleave_hit
;
94 local_node
+= ps
->local_node
;
95 other_node
+= ps
->other_node
;
102 "interleave_hit %lu\n"
112 static SYSDEV_ATTR(numastat
, S_IRUGO
, node_read_numastat
, NULL
);
115 * register_node - Setup a driverfs device for a node.
116 * @num - Node number to use when creating the device.
118 * Initialize and register the node device.
120 int __init
register_node(struct node
*node
, int num
, struct node
*parent
)
124 node
->sysdev
.id
= num
;
125 node
->sysdev
.cls
= &node_class
;
126 error
= sysdev_register(&node
->sysdev
);
129 sysdev_create_file(&node
->sysdev
, &attr_cpumap
);
130 sysdev_create_file(&node
->sysdev
, &attr_meminfo
);
131 sysdev_create_file(&node
->sysdev
, &attr_numastat
);
134 printk("register_node====0=====\n");
139 int __init
register_node_type(void)
141 return sysdev_class_register(&node_class
);
143 postcore_initcall(register_node_type
);