]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
cpumask: use new cpus_scnprintf function
authorMike Travis <travis@sgi.com>
Tue, 8 Apr 2008 18:43:03 +0000 (11:43 -0700)
committerIngo Molnar <mingo@elte.hu>
Sat, 19 Apr 2008 17:44:59 +0000 (19:44 +0200)
  * Cleaned up references to cpumask_scnprintf() and added new
    cpulist_scnprintf() interfaces where appropriate.

  * Fix some small bugs (or code efficiency improvments) for various uses
    of cpumask_scnprintf.

  * Clean up some checkpatch errors.

Signed-off-by: Mike Travis <travis@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
drivers/base/node.c
drivers/base/topology.c
drivers/pci/pci-sysfs.c
drivers/pci/probe.c
kernel/cpuset.c
kernel/sched_stats.h

index 8e3f25bb8f807e9e0fbd42bb4ff33dc99d563f3d..12fde2d03d695a112f02debd25c4fb897a4b937c 100644 (file)
@@ -19,22 +19,34 @@ static struct sysdev_class node_class = {
 };
 
 
-static ssize_t node_read_cpumap(struct sys_device * dev, char * buf)
+static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf)
 {
        struct node *node_dev = to_node(dev);
        node_to_cpumask_ptr(mask, node_dev->sysdev.id);
        int len;
 
-       /* 2004/06/03: buf currently PAGE_SIZE, need > 1 char per 4 bits. */
-       BUILD_BUG_ON(MAX_NUMNODES/4 > PAGE_SIZE/2);
+       /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */
+       BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1));
 
-       len = cpumask_scnprintf(buf, PAGE_SIZE-2, *mask);
+       len = type?
+               cpulist_scnprintf(buf, PAGE_SIZE-2, *mask):
+               cpumask_scnprintf(buf, PAGE_SIZE-2, *mask);
        buf[len++] = '\n';
        buf[len] = '\0';
        return len;
 }
 
-static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumap, NULL);
+static inline ssize_t node_read_cpumask(struct sys_device *dev, char *buf)
+{
+       return node_read_cpumap(dev, 0, buf);
+}
+static inline ssize_t node_read_cpulist(struct sys_device *dev, char *buf)
+{
+       return node_read_cpumap(dev, 1, buf);
+}
+
+static SYSDEV_ATTR(cpumap,  S_IRUGO, node_read_cpumask, NULL);
+static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL);
 
 #define K(x) ((x) << (PAGE_SHIFT - 10))
 static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
@@ -150,6 +162,7 @@ int register_node(struct node *node, int num, struct node *parent)
 
        if (!error){
                sysdev_create_file(&node->sysdev, &attr_cpumap);
+               sysdev_create_file(&node->sysdev, &attr_cpulist);
                sysdev_create_file(&node->sysdev, &attr_meminfo);
                sysdev_create_file(&node->sysdev, &attr_numastat);
                sysdev_create_file(&node->sysdev, &attr_distance);
@@ -167,6 +180,7 @@ int register_node(struct node *node, int num, struct node *parent)
 void unregister_node(struct node *node)
 {
        sysdev_remove_file(&node->sysdev, &attr_cpumap);
+       sysdev_remove_file(&node->sysdev, &attr_cpulist);
        sysdev_remove_file(&node->sysdev, &attr_meminfo);
        sysdev_remove_file(&node->sysdev, &attr_numastat);
        sysdev_remove_file(&node->sysdev, &attr_distance);
index e1d3ad4db2f04355631efd8120946c07313789c8..fdf4044d2e74a90a24ff7b5e44a16efcab52c7a4 100644 (file)
@@ -40,15 +40,38 @@ static ssize_t show_##name(struct sys_device *dev, char *buf)       \
        return sprintf(buf, "%d\n", topology_##name(cpu));      \
 }
 
-#define define_siblings_show_func(name)                                        \
-static ssize_t show_##name(struct sys_device *dev, char *buf)          \
+static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf)
+{
+       ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf;
+       int n = 0;
+
+       if (len > 1) {
+               n = type?
+                       cpulist_scnprintf(buf, len-2, *mask):
+                       cpumask_scnprintf(buf, len-2, *mask);
+               buf[n++] = '\n';
+               buf[n] = '\0';
+       }
+       return n;
+}
+
+#define define_siblings_show_map(name)                                 \
+static inline ssize_t show_##name(struct sys_device *dev, char *buf)   \
 {                                                                      \
-       ssize_t len = -1;                                               \
        unsigned int cpu = dev->id;                                     \
-       len = cpumask_scnprintf(buf, NR_CPUS+1, topology_##name(cpu));  \
-       return (len + sprintf(buf + len, "\n"));                        \
+       return show_cpumap(0, &(topology_##name(cpu)), buf);            \
 }
 
+#define define_siblings_show_list(name)                                        \
+static inline ssize_t show_##name##_list(struct sys_device *dev, char *buf) \
+{                                                                      \
+       unsigned int cpu = dev->id;                                     \
+       return show_cpumap(1, &(topology_##name(cpu)), buf);            \
+}
+
+#define define_siblings_show_func(name)                \
+       define_siblings_show_map(name); define_siblings_show_list(name)
+
 #ifdef topology_physical_package_id
 define_id_show_func(physical_package_id);
 define_one_ro(physical_package_id);
@@ -68,7 +91,9 @@ define_one_ro(core_id);
 #ifdef topology_thread_siblings
 define_siblings_show_func(thread_siblings);
 define_one_ro(thread_siblings);
-#define ref_thread_siblings_attr       &attr_thread_siblings.attr,
+define_one_ro(thread_siblings_list);
+#define ref_thread_siblings_attr       \
+               &attr_thread_siblings.attr, &attr_thread_siblings_list.attr,
 #else
 #define ref_thread_siblings_attr
 #endif
@@ -76,7 +101,9 @@ define_one_ro(thread_siblings);
 #ifdef topology_core_siblings
 define_siblings_show_func(core_siblings);
 define_one_ro(core_siblings);
-#define ref_core_siblings_attr         &attr_core_siblings.attr,
+define_one_ro(core_siblings_list);
+#define ref_core_siblings_attr         \
+               &attr_core_siblings.attr, &attr_core_siblings_list.attr,
 #else
 #define ref_core_siblings_attr
 #endif
index 8dcf1458aa2fafe6e0433efd1dfb515ce503271a..8d9d648daeba74123a6f9cf9c74434f903292bac 100644 (file)
@@ -73,8 +73,23 @@ static ssize_t local_cpus_show(struct device *dev,
 
        mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
        len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask);
-       strcat(buf,"\n"); 
-       return 1+len;
+       buf[len++] = '\n';
+       buf[len] = '\0';
+       return len;
+}
+
+
+static ssize_t local_cpulist_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       cpumask_t mask;
+       int len;
+
+       mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
+       len = cpulist_scnprintf(buf, PAGE_SIZE-2, mask);
+       buf[len++] = '\n';
+       buf[len] = '\0';
+       return len;
 }
 
 /* show resources */
@@ -201,6 +216,7 @@ struct device_attribute pci_dev_attrs[] = {
        __ATTR_RO(class),
        __ATTR_RO(irq),
        __ATTR_RO(local_cpus),
+       __ATTR_RO(local_cpulist),
        __ATTR_RO(modalias),
 #ifdef CONFIG_NUMA
        __ATTR_RO(numa_node),
index 2db2e4bb0d1ed6073b6ec9d3e0dec604868974ab..4b3011a23effa43f9053d2889430e43225bfb2ea 100644 (file)
@@ -82,6 +82,7 @@ void pci_remove_legacy_files(struct pci_bus *bus) { return; }
  * PCI Bus Class Devices
  */
 static ssize_t pci_bus_show_cpuaffinity(struct device *dev,
+                                       int type,
                                        struct device_attribute *attr,
                                        char *buf)
 {
@@ -89,12 +90,30 @@ static ssize_t pci_bus_show_cpuaffinity(struct device *dev,
        cpumask_t cpumask;
 
        cpumask = pcibus_to_cpumask(to_pci_bus(dev));
-       ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask);
-       if (ret < PAGE_SIZE)
-               buf[ret++] = '\n';
+       ret = type?
+               cpulist_scnprintf(buf, PAGE_SIZE-2, cpumask):
+               cpumask_scnprintf(buf, PAGE_SIZE-2, cpumask);
+       buf[ret++] = '\n';
+       buf[ret] = '\0';
        return ret;
 }
-DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpuaffinity, NULL);
+
+static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)
+{
+       return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
+}
+
+static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)
+{
+       return pci_bus_show_cpuaffinity(dev, 1, attr, buf);
+}
+
+DEVICE_ATTR(cpuaffinity,     S_IRUGO, pci_bus_show_cpumaskaffinity, NULL);
+DEVICE_ATTR(cpulistaffinity, S_IRUGO, pci_bus_show_cpulistaffinity, NULL);
 
 /*
  * PCI Bus Class
index 6b9ac296a05cd7c68e22c53a3b3243d4ffdecd03..b0c870b2ac30adc7a69fb0d48d51ae83d7a79d43 100644 (file)
@@ -2254,8 +2254,16 @@ void cpuset_task_status_allowed(struct seq_file *m, struct task_struct *task)
        m->count += cpumask_scnprintf(m->buf + m->count, m->size - m->count,
                                        task->cpus_allowed);
        seq_printf(m, "\n");
+       seq_printf(m, "Cpus_allowed_list:\t");
+       m->count += cpulist_scnprintf(m->buf + m->count, m->size - m->count,
+                                       task->cpus_allowed);
+       seq_printf(m, "\n");
        seq_printf(m, "Mems_allowed:\t");
        m->count += nodemask_scnprintf(m->buf + m->count, m->size - m->count,
                                        task->mems_allowed);
        seq_printf(m, "\n");
+       seq_printf(m, "Mems_allowed_list:\t");
+       m->count += nodelist_scnprintf(m->buf + m->count, m->size - m->count,
+                                       task->mems_allowed);
+       seq_printf(m, "\n");
 }
index 5b32433e7ee5719cb061956e53ec4ef2a242d903..5bae2e0c3ff293b665e0428ce2942c6e9ac1db0b 100644 (file)
@@ -9,6 +9,11 @@
 static int show_schedstat(struct seq_file *seq, void *v)
 {
        int cpu;
+       int mask_len = NR_CPUS/32 * 9;
+       char *mask_str = kmalloc(mask_len, GFP_KERNEL);
+
+       if (mask_str == NULL)
+               return -ENOMEM;
 
        seq_printf(seq, "version %d\n", SCHEDSTAT_VERSION);
        seq_printf(seq, "timestamp %lu\n", jiffies);
@@ -36,9 +41,8 @@ static int show_schedstat(struct seq_file *seq, void *v)
                preempt_disable();
                for_each_domain(cpu, sd) {
                        enum cpu_idle_type itype;
-                       char mask_str[NR_CPUS];
 
-                       cpumask_scnprintf(mask_str, NR_CPUS, sd->span);
+                       cpumask_scnprintf(mask_str, mask_len, sd->span);
                        seq_printf(seq, "domain%d %s", dcount++, mask_str);
                        for (itype = CPU_IDLE; itype < CPU_MAX_IDLE_TYPES;
                                        itype++) {