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_dev->cpumap;
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 si_meminfo_node(&i, nid);
43 "Node %d MemTotal: %8lu kB\n"
44 "Node %d MemFree: %8lu kB\n"
45 "Node %d MemUsed: %8lu kB\n"
46 "Node %d HighTotal: %8lu kB\n"
47 "Node %d HighFree: %8lu kB\n"
48 "Node %d LowTotal: %8lu kB\n"
49 "Node %d LowFree: %8lu kB\n",
52 nid, K(i.totalram - i.freeram),
55 nid, K(i.totalram - i.totalhigh),
56 nid, K(i.freeram - i.freehigh));
57 n += hugetlb_report_node_meminfo(nid, buf + n);
62 static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
64 static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
66 unsigned long numa_hit, numa_miss, interleave_hit, numa_foreign;
67 unsigned long local_node, other_node;
69 pg_data_t *pg = NODE_DATA(dev->id);
76 for (i = 0; i < MAX_NR_ZONES; i++) {
77 struct zone *z = &pg->node_zones[i];
78 for (cpu = 0; cpu < NR_CPUS; cpu++) {
79 struct per_cpu_pageset *ps = &z->pageset[cpu];
80 numa_hit += ps->numa_hit;
81 numa_miss += ps->numa_miss;
82 numa_foreign += ps->numa_foreign;
83 interleave_hit += ps->interleave_hit;
84 local_node += ps->local_node;
85 other_node += ps->other_node;
92 "interleave_hit %lu\n"
102 static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
105 * register_node - Setup a driverfs device for a node.
106 * @num - Node number to use when creating the device.
108 * Initialize and register the node device.
110 int __init register_node(struct node *node, int num, struct node *parent)
114 node->cpumap = node_to_cpumask(num);
115 node->sysdev.id = num;
116 node->sysdev.cls = &node_class;
117 error = sysdev_register(&node->sysdev);
120 sysdev_create_file(&node->sysdev, &attr_cpumap);
121 sysdev_create_file(&node->sysdev, &attr_meminfo);
122 sysdev_create_file(&node->sysdev, &attr_numastat);
128 int __init register_node_type(void)
130 return sysdev_class_register(&node_class);
132 postcore_initcall(register_node_type);