m68knommu: remove local gettimeofday code
[wrt350n-kernel.git] / drivers / base / node.c
blobe59861f18ce55616981e7ca9fbc5ad2a6698f04f
1 /*
2 * drivers/base/node.c - basic Node class support
3 */
5 #include <linux/sysdev.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
8 #include <linux/mm.h>
9 #include <linux/node.h>
10 #include <linux/hugetlb.h>
11 #include <linux/cpumask.h>
12 #include <linux/topology.h>
13 #include <linux/nodemask.h>
14 #include <linux/cpu.h>
15 #include <linux/device.h>
17 static struct sysdev_class node_class = {
18 .name = "node",
22 static ssize_t node_read_cpumap(struct sys_device * dev, char * buf)
24 struct node *node_dev = to_node(dev);
25 cpumask_t mask = node_to_cpumask(node_dev->sysdev.id);
26 int len;
28 /* 2004/06/03: buf currently PAGE_SIZE, need > 1 char per 4 bits. */
29 BUILD_BUG_ON(MAX_NUMNODES/4 > PAGE_SIZE/2);
31 len = cpumask_scnprintf(buf, PAGE_SIZE-1, mask);
32 len += sprintf(buf + len, "\n");
33 return len;
36 static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumap, NULL);
38 #define K(x) ((x) << (PAGE_SHIFT - 10))
39 static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
41 int n;
42 int nid = dev->id;
43 struct sysinfo i;
45 si_meminfo_node(&i, nid);
47 n = sprintf(buf, "\n"
48 "Node %d MemTotal: %8lu kB\n"
49 "Node %d MemFree: %8lu kB\n"
50 "Node %d MemUsed: %8lu kB\n"
51 "Node %d Active: %8lu kB\n"
52 "Node %d Inactive: %8lu kB\n"
53 #ifdef CONFIG_HIGHMEM
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"
58 #endif
59 "Node %d Dirty: %8lu kB\n"
60 "Node %d Writeback: %8lu kB\n"
61 "Node %d FilePages: %8lu kB\n"
62 "Node %d Mapped: %8lu kB\n"
63 "Node %d AnonPages: %8lu kB\n"
64 "Node %d PageTables: %8lu kB\n"
65 "Node %d NFS_Unstable: %8lu kB\n"
66 "Node %d Bounce: %8lu kB\n"
67 "Node %d Slab: %8lu kB\n"
68 "Node %d SReclaimable: %8lu kB\n"
69 "Node %d SUnreclaim: %8lu kB\n",
70 nid, K(i.totalram),
71 nid, K(i.freeram),
72 nid, K(i.totalram - i.freeram),
73 nid, node_page_state(nid, NR_ACTIVE),
74 nid, node_page_state(nid, NR_INACTIVE),
75 #ifdef CONFIG_HIGHMEM
76 nid, K(i.totalhigh),
77 nid, K(i.freehigh),
78 nid, K(i.totalram - i.totalhigh),
79 nid, K(i.freeram - i.freehigh),
80 #endif
81 nid, K(node_page_state(nid, NR_FILE_DIRTY)),
82 nid, K(node_page_state(nid, NR_WRITEBACK)),
83 nid, K(node_page_state(nid, NR_FILE_PAGES)),
84 nid, K(node_page_state(nid, NR_FILE_MAPPED)),
85 nid, K(node_page_state(nid, NR_ANON_PAGES)),
86 nid, K(node_page_state(nid, NR_PAGETABLE)),
87 nid, K(node_page_state(nid, NR_UNSTABLE_NFS)),
88 nid, K(node_page_state(nid, NR_BOUNCE)),
89 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) +
90 node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
91 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)),
92 nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE)));
93 n += hugetlb_report_node_meminfo(nid, buf + n);
94 return n;
97 #undef K
98 static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
100 static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
102 return sprintf(buf,
103 "numa_hit %lu\n"
104 "numa_miss %lu\n"
105 "numa_foreign %lu\n"
106 "interleave_hit %lu\n"
107 "local_node %lu\n"
108 "other_node %lu\n",
109 node_page_state(dev->id, NUMA_HIT),
110 node_page_state(dev->id, NUMA_MISS),
111 node_page_state(dev->id, NUMA_FOREIGN),
112 node_page_state(dev->id, NUMA_INTERLEAVE_HIT),
113 node_page_state(dev->id, NUMA_LOCAL),
114 node_page_state(dev->id, NUMA_OTHER));
116 static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
118 static ssize_t node_read_distance(struct sys_device * dev, char * buf)
120 int nid = dev->id;
121 int len = 0;
122 int i;
124 /* buf currently PAGE_SIZE, need ~4 chars per node */
125 BUILD_BUG_ON(MAX_NUMNODES*4 > PAGE_SIZE/2);
127 for_each_online_node(i)
128 len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i));
130 len += sprintf(buf + len, "\n");
131 return len;
133 static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL);
137 * register_node - Setup a sysfs device for a node.
138 * @num - Node number to use when creating the device.
140 * Initialize and register the node device.
142 int register_node(struct node *node, int num, struct node *parent)
144 int error;
146 node->sysdev.id = num;
147 node->sysdev.cls = &node_class;
148 error = sysdev_register(&node->sysdev);
150 if (!error){
151 sysdev_create_file(&node->sysdev, &attr_cpumap);
152 sysdev_create_file(&node->sysdev, &attr_meminfo);
153 sysdev_create_file(&node->sysdev, &attr_numastat);
154 sysdev_create_file(&node->sysdev, &attr_distance);
156 return error;
160 * unregister_node - unregister a node device
161 * @node: node going away
163 * Unregisters a node device @node. All the devices on the node must be
164 * unregistered before calling this function.
166 void unregister_node(struct node *node)
168 sysdev_remove_file(&node->sysdev, &attr_cpumap);
169 sysdev_remove_file(&node->sysdev, &attr_meminfo);
170 sysdev_remove_file(&node->sysdev, &attr_numastat);
171 sysdev_remove_file(&node->sysdev, &attr_distance);
173 sysdev_unregister(&node->sysdev);
176 struct node node_devices[MAX_NUMNODES];
179 * register cpu under node
181 int register_cpu_under_node(unsigned int cpu, unsigned int nid)
183 if (node_online(nid)) {
184 struct sys_device *obj = get_cpu_sysdev(cpu);
185 if (!obj)
186 return 0;
187 return sysfs_create_link(&node_devices[nid].sysdev.kobj,
188 &obj->kobj,
189 kobject_name(&obj->kobj));
192 return 0;
195 int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
197 if (node_online(nid)) {
198 struct sys_device *obj = get_cpu_sysdev(cpu);
199 if (obj)
200 sysfs_remove_link(&node_devices[nid].sysdev.kobj,
201 kobject_name(&obj->kobj));
203 return 0;
206 int register_one_node(int nid)
208 int error = 0;
209 int cpu;
211 if (node_online(nid)) {
212 int p_node = parent_node(nid);
213 struct node *parent = NULL;
215 if (p_node != nid)
216 parent = &node_devices[p_node];
218 error = register_node(&node_devices[nid], nid, parent);
220 /* link cpu under this node */
221 for_each_present_cpu(cpu) {
222 if (cpu_to_node(cpu) == nid)
223 register_cpu_under_node(cpu, nid);
227 return error;
231 void unregister_one_node(int nid)
233 unregister_node(&node_devices[nid]);
237 * node states attributes
240 static ssize_t print_nodes_state(enum node_states state, char *buf)
242 int n;
244 n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
245 if (n > 0 && PAGE_SIZE > n + 1) {
246 *(buf + n++) = '\n';
247 *(buf + n++) = '\0';
249 return n;
252 static ssize_t print_nodes_possible(struct sysdev_class *class, char *buf)
254 return print_nodes_state(N_POSSIBLE, buf);
257 static ssize_t print_nodes_online(struct sysdev_class *class, char *buf)
259 return print_nodes_state(N_ONLINE, buf);
262 static ssize_t print_nodes_has_normal_memory(struct sysdev_class *class,
263 char *buf)
265 return print_nodes_state(N_NORMAL_MEMORY, buf);
268 static ssize_t print_nodes_has_cpu(struct sysdev_class *class, char *buf)
270 return print_nodes_state(N_CPU, buf);
273 static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL);
274 static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL);
275 static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory,
276 NULL);
277 static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL);
279 #ifdef CONFIG_HIGHMEM
280 static ssize_t print_nodes_has_high_memory(struct sysdev_class *class,
281 char *buf)
283 return print_nodes_state(N_HIGH_MEMORY, buf);
286 static SYSDEV_CLASS_ATTR(has_high_memory, 0444, print_nodes_has_high_memory,
287 NULL);
288 #endif
290 struct sysdev_class_attribute *node_state_attr[] = {
291 &attr_possible,
292 &attr_online,
293 &attr_has_normal_memory,
294 #ifdef CONFIG_HIGHMEM
295 &attr_has_high_memory,
296 #endif
297 &attr_has_cpu,
300 static int node_states_init(void)
302 int i;
303 int err = 0;
305 for (i = 0; i < NR_NODE_STATES; i++) {
306 int ret;
307 ret = sysdev_class_create_file(&node_class, node_state_attr[i]);
308 if (!err)
309 err = ret;
311 return err;
314 static int __init register_node_type(void)
316 int ret;
318 ret = sysdev_class_register(&node_class);
319 if (!ret)
320 ret = node_states_init();
323 * Note: we're not going to unregister the node class if we fail
324 * to register the node state class attribute files.
326 return ret;
328 postcore_initcall(register_node_type);