This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / base / node.c
1 /*
2  * drivers/base/node.c - basic Node class support
3  */
4
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/cpumask.h>
11 #include <linux/topology.h>
12
13 static struct sysdev_class node_class = {
14         set_kset_name("node"),
15 };
16
17
18 static ssize_t node_read_cpumap(struct sys_device * dev, char * buf)
19 {
20         struct node *node_dev = to_node(dev);
21         cpumask_t mask = node_dev->cpumap;
22         int len;
23
24         /* FIXME - someone should pass us a buffer size (count) or
25          * use seq_file or something to avoid buffer overrun risk. */
26         len = cpumask_scnprintf(buf, 99 /* XXX FIXME */, mask);
27         len += sprintf(buf + len, "\n");
28         return len;
29 }
30
31 static SYSDEV_ATTR(cpumap,S_IRUGO,node_read_cpumap,NULL);
32
33 /* Can be overwritten by architecture specific code. */
34 int __attribute__((weak)) hugetlb_report_node_meminfo(int node, char *buf)
35 {
36         return 0;
37 }
38
39 #define K(x) ((x) << (PAGE_SHIFT - 10))
40 static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
41 {
42         int n;
43         int nid = dev->id;
44         struct sysinfo i;
45         si_meminfo_node(&i, nid);
46         n = sprintf(buf, "\n"
47                        "Node %d MemTotal:     %8lu kB\n"
48                        "Node %d MemFree:      %8lu kB\n"
49                        "Node %d MemUsed:      %8lu kB\n"
50                        "Node %d HighTotal:    %8lu kB\n"
51                        "Node %d HighFree:     %8lu kB\n"
52                        "Node %d LowTotal:     %8lu kB\n"
53                        "Node %d LowFree:      %8lu kB\n",
54                        nid, K(i.totalram),
55                        nid, K(i.freeram),
56                        nid, K(i.totalram-i.freeram),
57                        nid, K(i.totalhigh),
58                        nid, K(i.freehigh),
59                        nid, K(i.totalram-i.totalhigh),
60                        nid, K(i.freeram-i.freehigh));
61         n += hugetlb_report_node_meminfo(nid, buf + n);
62         return n;
63 }
64
65 #undef K 
66 static SYSDEV_ATTR(meminfo,S_IRUGO,node_read_meminfo,NULL);
67
68 static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
69 {
70         unsigned long numa_hit, numa_miss, interleave_hit, numa_foreign;
71         unsigned long local_node, other_node;
72         int i, cpu;
73         pg_data_t *pg = NODE_DATA(dev->id);
74         numa_hit = 0;
75         numa_miss = 0;
76         interleave_hit = 0;
77         numa_foreign = 0;
78         local_node = 0;
79         other_node = 0;
80         for (i = 0; i < MAX_NR_ZONES; i++) {
81                 struct zone *z = &pg->node_zones[i];
82                 for (cpu = 0; cpu < NR_CPUS; cpu++) {
83                         struct per_cpu_pageset *ps = &z->pageset[cpu];
84                         numa_hit += ps->numa_hit;
85                         numa_miss += ps->numa_miss;
86                         numa_foreign += ps->numa_foreign;
87                         interleave_hit += ps->interleave_hit;
88                         local_node += ps->local_node;
89                         other_node += ps->other_node;
90                 }
91         }
92         return sprintf(buf,
93                        "numa_hit %lu\n"
94                        "numa_miss %lu\n"
95                        "numa_foreign %lu\n"
96                        "interleave_hit %lu\n"
97                        "local_node %lu\n"
98                        "other_node %lu\n",
99                        numa_hit,
100                        numa_miss,
101                        numa_foreign,
102                        interleave_hit,
103                        local_node,
104                        other_node);
105 }
106 static SYSDEV_ATTR(numastat,S_IRUGO,node_read_numastat,NULL);
107
108 /*
109  * register_node - Setup a driverfs device for a node.
110  * @num - Node number to use when creating the device.
111  *
112  * Initialize and register the node device.
113  */
114 int __init register_node(struct node *node, int num, struct node *parent)
115 {
116         int error;
117
118         node->cpumap = node_to_cpumask(num);
119         node->sysdev.id = num;
120         node->sysdev.cls = &node_class;
121         error = sysdev_register(&node->sysdev);
122
123         if (!error){
124                 sysdev_create_file(&node->sysdev, &attr_cpumap);
125                 sysdev_create_file(&node->sysdev, &attr_meminfo);
126                 sysdev_create_file(&node->sysdev, &attr_numastat);
127         }
128         return error;
129 }
130
131
132 int __init register_node_type(void)
133 {
134         return sysdev_class_register(&node_class);
135 }
136 postcore_initcall(register_node_type);