cpumask: convert rest of files in kernel/
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Dec 2008 23:42:28 +0000 (10:12 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Dec 2008 23:42:28 +0000 (10:12 +1030)
Impact: Reduce stack usage, use new cpumask API.

Mainly changing cpumask_t to 'struct cpumask' and similar simple API
conversion.  Two conversions worth mentioning:

1) we use cpumask_any_but to avoid a temporary in kernel/softlockup.c,
2) Use cpumask_var_t in taskstats_user_cmd().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
include/linux/stop_machine.h
kernel/power/poweroff.c
kernel/softlockup.c
kernel/stop_machine.c
kernel/taskstats.c

index faf1519..74d59a6 100644 (file)
@@ -23,7 +23,7 @@
  *
  * This can be thought of as a very heavy write lock, equivalent to
  * grabbing every spinlock in the kernel. */
-int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus);
+int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
 
 /**
  * __stop_machine: freeze the machine on all CPUs and run this function
@@ -34,11 +34,11 @@ int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus);
  * Description: This is a special version of the above, which assumes cpus
  * won't come or go while it's being called.  Used by hotplug cpu.
  */
-int __stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus);
+int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
 #else
 
 static inline int stop_machine(int (*fn)(void *), void *data,
-                              const cpumask_t *cpus)
+                              const struct cpumask *cpus)
 {
        int ret;
        local_irq_disable();
index 72016f0..9789083 100644 (file)
@@ -27,7 +27,7 @@ static DECLARE_WORK(poweroff_work, do_poweroff);
 static void handle_poweroff(int key, struct tty_struct *tty)
 {
        /* run sysrq poweroff on boot cpu */
-       schedule_work_on(first_cpu(cpu_online_map), &poweroff_work);
+       schedule_work_on(cpumask_first(cpu_online_mask), &poweroff_work);
 }
 
 static struct sysrq_key_op     sysrq_poweroff_op = {
index 492f0c7..d9188c6 100644 (file)
@@ -310,10 +310,8 @@ cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
        case CPU_DOWN_PREPARE:
        case CPU_DOWN_PREPARE_FROZEN:
                if (hotcpu == check_cpu) {
-                       cpumask_t temp_cpu_online_map = cpu_online_map;
-
-                       cpu_clear(hotcpu, temp_cpu_online_map);
-                       check_cpu = cpumask_any(&temp_cpu_online_map);
+                       /* Pick any other online cpu. */
+                       check_cpu = cpumask_any_but(cpu_online_mask, hotcpu);
                }
                break;
 
index 24e8cea..286c417 100644 (file)
@@ -69,10 +69,10 @@ static void stop_cpu(struct work_struct *unused)
        int err;
 
        if (!active_cpus) {
-               if (cpu == first_cpu(cpu_online_map))
+               if (cpu == cpumask_first(cpu_online_mask))
                        smdata = &active;
        } else {
-               if (cpu_isset(cpu, *active_cpus))
+               if (cpumask_test_cpu(cpu, active_cpus))
                        smdata = &active;
        }
        /* Simple state machine */
@@ -109,7 +109,7 @@ static int chill(void *unused)
        return 0;
 }
 
-int __stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus)
+int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus)
 {
        struct work_struct *sm_work;
        int i, ret;
@@ -142,7 +142,7 @@ int __stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus)
        return ret;
 }
 
-int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus)
+int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus)
 {
        int ret;
 
index 6d7dc4e..888adbc 100644 (file)
@@ -290,18 +290,17 @@ ret:
        return;
 }
 
-static int add_del_listener(pid_t pid, cpumask_t *maskp, int isadd)
+static int add_del_listener(pid_t pid, const struct cpumask *mask, int isadd)
 {
        struct listener_list *listeners;
        struct listener *s, *tmp;
        unsigned int cpu;
-       cpumask_t mask = *maskp;
 
-       if (!cpus_subset(mask, cpu_possible_map))
+       if (!cpumask_subset(mask, cpu_possible_mask))
                return -EINVAL;
 
        if (isadd == REGISTER) {
-               for_each_cpu_mask_nr(cpu, mask) {
+               for_each_cpu(cpu, mask) {
                        s = kmalloc_node(sizeof(struct listener), GFP_KERNEL,
                                         cpu_to_node(cpu));
                        if (!s)
@@ -320,7 +319,7 @@ static int add_del_listener(pid_t pid, cpumask_t *maskp, int isadd)
 
        /* Deregister or cleanup */
 cleanup:
-       for_each_cpu_mask_nr(cpu, mask) {
+       for_each_cpu(cpu, mask) {
                listeners = &per_cpu(listener_array, cpu);
                down_write(&listeners->sem);
                list_for_each_entry_safe(s, tmp, &listeners->list, list) {
@@ -335,7 +334,7 @@ cleanup:
        return 0;
 }
 
-static int parse(struct nlattr *na, cpumask_t *mask)
+static int parse(struct nlattr *na, struct cpumask *mask)
 {
        char *data;
        int len;
@@ -428,23 +427,33 @@ err:
 
 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
 {
-       int rc = 0;
+       int rc;
        struct sk_buff *rep_skb;
        struct taskstats *stats;
        size_t size;
-       cpumask_t mask;
+       cpumask_var_t mask;
+
+       if (!alloc_cpumask_var(&mask, GFP_KERNEL))
+               return -ENOMEM;
 
-       rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], &mask);
+       rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], mask);
        if (rc < 0)
-               return rc;
-       if (rc == 0)
-               return add_del_listener(info->snd_pid, &mask, REGISTER);
+               goto free_return_rc;
+       if (rc == 0) {
+               rc = add_del_listener(info->snd_pid, mask, REGISTER);
+               goto free_return_rc;
+       }
 
-       rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], &mask);
+       rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], mask);
        if (rc < 0)
+               goto free_return_rc;
+       if (rc == 0) {
+               rc = add_del_listener(info->snd_pid, mask, DEREGISTER);
+free_return_rc:
+               free_cpumask_var(mask);
                return rc;
-       if (rc == 0)
-               return add_del_listener(info->snd_pid, &mask, DEREGISTER);
+       }
+       free_cpumask_var(mask);
 
        /*
         * Size includes space for nested attributes