]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/base/node.c
Driver core: change sysdev classes to use dynamic kobject names
[linux-2.6-omap-h63xx.git] / drivers / base / node.c
index e9b0957f15d12ef522cee3145ba81bd6bf737273..e59861f18ce55616981e7ca9fbc5ad2a6698f04f 100644 (file)
 #include <linux/topology.h>
 #include <linux/nodemask.h>
 #include <linux/cpu.h>
+#include <linux/device.h>
 
 static struct sysdev_class node_class = {
-       set_kset_name("node"),
+       .name = "node",
 };
 
 
@@ -40,13 +41,8 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
        int n;
        int nid = dev->id;
        struct sysinfo i;
-       unsigned long inactive;
-       unsigned long active;
-       unsigned long free;
 
        si_meminfo_node(&i, nid);
-       __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid));
-
 
        n = sprintf(buf, "\n"
                       "Node %d MemTotal:     %8lu kB\n"
@@ -54,10 +50,12 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
                       "Node %d MemUsed:      %8lu kB\n"
                       "Node %d Active:       %8lu kB\n"
                       "Node %d Inactive:     %8lu kB\n"
+#ifdef CONFIG_HIGHMEM
                       "Node %d HighTotal:    %8lu kB\n"
                       "Node %d HighFree:     %8lu kB\n"
                       "Node %d LowTotal:     %8lu kB\n"
                       "Node %d LowFree:      %8lu kB\n"
+#endif
                       "Node %d Dirty:        %8lu kB\n"
                       "Node %d Writeback:    %8lu kB\n"
                       "Node %d FilePages:    %8lu kB\n"
@@ -66,16 +64,20 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
                       "Node %d PageTables:   %8lu kB\n"
                       "Node %d NFS_Unstable: %8lu kB\n"
                       "Node %d Bounce:       %8lu kB\n"
-                      "Node %d Slab:         %8lu kB\n",
+                      "Node %d Slab:         %8lu kB\n"
+                      "Node %d SReclaimable: %8lu kB\n"
+                      "Node %d SUnreclaim:   %8lu kB\n",
                       nid, K(i.totalram),
                       nid, K(i.freeram),
                       nid, K(i.totalram - i.freeram),
-                      nid, K(active),
-                      nid, K(inactive),
+                      nid, node_page_state(nid, NR_ACTIVE),
+                      nid, node_page_state(nid, NR_INACTIVE),
+#ifdef CONFIG_HIGHMEM
                       nid, K(i.totalhigh),
                       nid, K(i.freehigh),
                       nid, K(i.totalram - i.totalhigh),
                       nid, K(i.freeram - i.freehigh),
+#endif
                       nid, K(node_page_state(nid, NR_FILE_DIRTY)),
                       nid, K(node_page_state(nid, NR_WRITEBACK)),
                       nid, K(node_page_state(nid, NR_FILE_PAGES)),
@@ -84,7 +86,10 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
                       nid, K(node_page_state(nid, NR_PAGETABLE)),
                       nid, K(node_page_state(nid, NR_UNSTABLE_NFS)),
                       nid, K(node_page_state(nid, NR_BOUNCE)),
-                      nid, K(node_page_state(nid, NR_SLAB)));
+                      nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) +
+                               node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
+                      nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)),
+                      nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE)));
        n += hugetlb_report_node_meminfo(nid, buf + n);
        return n;
 }
@@ -129,7 +134,7 @@ static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL);
 
 
 /*
- * register_node - Setup a driverfs device for a node.
+ * register_node - Setup a sysfs device for a node.
  * @num - Node number to use when creating the device.
  *
  * Initialize and register the node device.
@@ -228,8 +233,96 @@ void unregister_one_node(int nid)
        unregister_node(&node_devices[nid]);
 }
 
+/*
+ * node states attributes
+ */
+
+static ssize_t print_nodes_state(enum node_states state, char *buf)
+{
+       int n;
+
+       n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
+       if (n > 0 && PAGE_SIZE > n + 1) {
+               *(buf + n++) = '\n';
+               *(buf + n++) = '\0';
+       }
+       return n;
+}
+
+static ssize_t print_nodes_possible(struct sysdev_class *class, char *buf)
+{
+       return print_nodes_state(N_POSSIBLE, buf);
+}
+
+static ssize_t print_nodes_online(struct sysdev_class *class, char *buf)
+{
+       return print_nodes_state(N_ONLINE, buf);
+}
+
+static ssize_t print_nodes_has_normal_memory(struct sysdev_class *class,
+                                               char *buf)
+{
+       return print_nodes_state(N_NORMAL_MEMORY, buf);
+}
+
+static ssize_t print_nodes_has_cpu(struct sysdev_class *class, char *buf)
+{
+       return print_nodes_state(N_CPU, buf);
+}
+
+static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL);
+static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL);
+static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory,
+                                                                       NULL);
+static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL);
+
+#ifdef CONFIG_HIGHMEM
+static ssize_t print_nodes_has_high_memory(struct sysdev_class *class,
+                                                char *buf)
+{
+       return print_nodes_state(N_HIGH_MEMORY, buf);
+}
+
+static SYSDEV_CLASS_ATTR(has_high_memory, 0444, print_nodes_has_high_memory,
+                                                                        NULL);
+#endif
+
+struct sysdev_class_attribute *node_state_attr[] = {
+       &attr_possible,
+       &attr_online,
+       &attr_has_normal_memory,
+#ifdef CONFIG_HIGHMEM
+       &attr_has_high_memory,
+#endif
+       &attr_has_cpu,
+};
+
+static int node_states_init(void)
+{
+       int i;
+       int err = 0;
+
+       for (i = 0;  i < NR_NODE_STATES; i++) {
+               int ret;
+               ret = sysdev_class_create_file(&node_class, node_state_attr[i]);
+               if (!err)
+                       err = ret;
+       }
+       return err;
+}
+
 static int __init register_node_type(void)
 {
-       return sysdev_class_register(&node_class);
+       int ret;
+
+       ret = sysdev_class_register(&node_class);
+       if (!ret)
+               ret = node_states_init();
+
+       /*
+        * Note:  we're not going to unregister the node class if we fail
+        * to register the node state class attribute files.
+        */
+       return ret;
 }
 postcore_initcall(register_node_type);