PCI: aerdrv_acpi.c: remove unneeded NULL check
[safe/jmp/linux-2.6] / drivers / base / node.c
index eae2bdc..e59861f 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,24 +41,8 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
        int n;
        int nid = dev->id;
        struct sysinfo i;
-       struct page_state ps;
-       unsigned long inactive;
-       unsigned long active;
-       unsigned long free;
 
        si_meminfo_node(&i, nid);
-       get_page_state_node(&ps, nid);
-       __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid));
-
-       /* Check for negative values in these approximate counters */
-       if ((long)ps.nr_dirty < 0)
-               ps.nr_dirty = 0;
-       if ((long)ps.nr_writeback < 0)
-               ps.nr_writeback = 0;
-       if ((long)ps.nr_mapped < 0)
-               ps.nr_mapped = 0;
-       if ((long)ps.nr_slab < 0)
-               ps.nr_slab = 0;
 
        n = sprintf(buf, "\n"
                       "Node %d MemTotal:     %8lu kB\n"
@@ -65,27 +50,46 @@ 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"
                       "Node %d Mapped:       %8lu kB\n"
-                      "Node %d Slab:         %8lu kB\n",
+                      "Node %d AnonPages:    %8lu kB\n"
+                      "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 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),
-                      nid, K(ps.nr_dirty),
-                      nid, K(ps.nr_writeback),
-                      nid, K(ps.nr_mapped),
-                      nid, K(ps.nr_slab));
+#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)),
+                      nid, K(node_page_state(nid, NR_FILE_MAPPED)),
+                      nid, K(node_page_state(nid, NR_ANON_PAGES)),
+                      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_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;
 }
@@ -95,28 +99,6 @@ static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
 
 static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
 {
-       unsigned long numa_hit, numa_miss, interleave_hit, numa_foreign;
-       unsigned long local_node, other_node;
-       int i, cpu;
-       pg_data_t *pg = NODE_DATA(dev->id);
-       numa_hit = 0;
-       numa_miss = 0;
-       interleave_hit = 0;
-       numa_foreign = 0;
-       local_node = 0;
-       other_node = 0;
-       for (i = 0; i < MAX_NR_ZONES; i++) {
-               struct zone *z = &pg->node_zones[i];
-               for_each_online_cpu(cpu) {
-                       struct per_cpu_pageset *ps = zone_pcp(z,cpu);
-                       numa_hit += ps->numa_hit;
-                       numa_miss += ps->numa_miss;
-                       numa_foreign += ps->numa_foreign;
-                       interleave_hit += ps->interleave_hit;
-                       local_node += ps->local_node;
-                       other_node += ps->other_node;
-               }
-       }
        return sprintf(buf,
                       "numa_hit %lu\n"
                       "numa_miss %lu\n"
@@ -124,12 +106,12 @@ static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
                       "interleave_hit %lu\n"
                       "local_node %lu\n"
                       "other_node %lu\n",
-                      numa_hit,
-                      numa_miss,
-                      numa_foreign,
-                      interleave_hit,
-                      local_node,
-                      other_node);
+                      node_page_state(dev->id, NUMA_HIT),
+                      node_page_state(dev->id, NUMA_MISS),
+                      node_page_state(dev->id, NUMA_FOREIGN),
+                      node_page_state(dev->id, NUMA_INTERLEAVE_HIT),
+                      node_page_state(dev->id, NUMA_LOCAL),
+                      node_page_state(dev->id, NUMA_OTHER));
 }
 static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
 
@@ -152,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.
@@ -251,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);