MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / base / node.c
blobb939ae2e586f5a9b5932c83ac0b2fe2446d456ee
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>
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);
23 int len;
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");
30 return len;
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)
38 int n;
39 int nid = dev->id;
40 struct sysinfo i;
41 unsigned long inactive;
42 unsigned long active;
43 unsigned long free;
45 si_meminfo_node(&i, nid);
46 __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid));
48 n = sprintf(buf, "\n"
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",
58 nid, K(i.totalram),
59 nid, K(i.freeram),
60 nid, K(i.totalram - i.freeram),
61 nid, K(active),
62 nid, K(inactive),
63 nid, K(i.totalhigh),
64 nid, K(i.freehigh),
65 nid, K(i.totalram - i.totalhigh),
66 nid, K(i.freeram - i.freehigh));
67 n += hugetlb_report_node_meminfo(nid, buf + n);
68 return n;
71 #undef K
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;
78 int i, cpu;
79 pg_data_t *pg = NODE_DATA(dev->id);
80 numa_hit = 0;
81 numa_miss = 0;
82 interleave_hit = 0;
83 numa_foreign = 0;
84 local_node = 0;
85 other_node = 0;
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;
98 return sprintf(buf,
99 "numa_hit %lu\n"
100 "numa_miss %lu\n"
101 "numa_foreign %lu\n"
102 "interleave_hit %lu\n"
103 "local_node %lu\n"
104 "other_node %lu\n",
105 numa_hit,
106 numa_miss,
107 numa_foreign,
108 interleave_hit,
109 local_node,
110 other_node);
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)
122 int error;
124 node->sysdev.id = num;
125 node->sysdev.cls = &node_class;
126 error = sysdev_register(&node->sysdev);
128 if (!error){
129 sysdev_create_file(&node->sysdev, &attr_cpumap);
130 sysdev_create_file(&node->sysdev, &attr_meminfo);
131 sysdev_create_file(&node->sysdev, &attr_numastat);
133 //prince debug
134 printk("register_node====0=====\n");
135 return error;
139 int __init register_node_type(void)
141 return sysdev_class_register(&node_class);
143 postcore_initcall(register_node_type);