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/cpumask.h>
11 #include <linux/topology.h>
13 static struct sysdev_class node_class = {
14 set_kset_name("node"),
18 static ssize_t node_read_cpumap(struct sys_device * dev, char * buf)
20 struct node *node_dev = to_node(dev);
21 cpumask_t mask = node_dev->cpumap;
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");
31 static SYSDEV_ATTR(cpumap,S_IRUGO,node_read_cpumap,NULL);
33 /* Can be overwritten by architecture specific code. */
34 int __attribute__((weak)) hugetlb_report_node_meminfo(int node, char *buf)
39 #define K(x) ((x) << (PAGE_SHIFT - 10))
40 static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
45 si_meminfo_node(&i, nid);
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",
56 nid, K(i.totalram-i.freeram),
59 nid, K(i.totalram-i.totalhigh),
60 nid, K(i.freeram-i.freehigh));
61 n += hugetlb_report_node_meminfo(nid, buf + n);
66 static SYSDEV_ATTR(meminfo,S_IRUGO,node_read_meminfo,NULL);
68 static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
70 unsigned long numa_hit, numa_miss, interleave_hit, numa_foreign;
71 unsigned long local_node, other_node;
73 pg_data_t *pg = NODE_DATA(dev->id);
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;
96 "interleave_hit %lu\n"
106 static SYSDEV_ATTR(numastat,S_IRUGO,node_read_numastat,NULL);
109 * register_node - Setup a driverfs device for a node.
110 * @num - Node number to use when creating the device.
112 * Initialize and register the node device.
114 int __init register_node(struct node *node, int num, struct node *parent)
118 node->cpumap = node_to_cpumask(num);
119 node->sysdev.id = num;
120 node->sysdev.cls = &node_class;
121 error = sysdev_register(&node->sysdev);
124 sysdev_create_file(&node->sysdev, &attr_cpumap);
125 sysdev_create_file(&node->sysdev, &attr_meminfo);
126 sysdev_create_file(&node->sysdev, &attr_numastat);
132 int __init register_node_type(void)
134 return sysdev_class_register(&node_class);
136 postcore_initcall(register_node_type);