]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
x86, apm: Make on_cpu0() use workqueue instead of work_on_cpu()
authorTejun Heo <tj@kernel.org>
Fri, 24 Aug 2012 01:11:34 +0000 (18:11 -0700)
committerJiri Kosina <jkosina@suse.cz>
Tue, 28 Aug 2012 22:53:02 +0000 (15:53 -0700)
Make APM schedule a work item on CPU0 instead of using the expensive
work_on_cpu(); hopefully, this is the last user of work_on_cpu() and
we can take out work_on_cpu() in not too distant future.

Tested both paths.  Seems to work fine.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
arch/x86/kernel/apm_32.c

index a46bd383953cd1dc299648e5c25e8b83744ae4f8..a7f0914a0a267a28afb625fa6df20ce9d8aea942 100644 (file)
@@ -604,28 +604,43 @@ static long __apm_bios_call(void *_call)
        return call->eax & 0xff;
 }
 
+struct on_cpu0_arg {
+       struct work_struct      work;
+       long                    (*fn)(void *);
+       struct apm_bios_call    *call;
+       int                     ret;
+};
+
+static void on_cpu0_workfn(struct work_struct *work)
+{
+       struct on_cpu0_arg *arg = container_of(work, struct on_cpu0_arg, work);
+
+       arg->ret = arg->fn(arg->call);
+}
+
 /* Run __apm_bios_call or __apm_bios_call_simple on CPU 0 */
 static int on_cpu0(long (*fn)(void *), struct apm_bios_call *call)
 {
-       int ret;
+       struct on_cpu0_arg arg = { .fn = fn, .call = call };
 
-       /* Don't bother with work_on_cpu in the common case, so we don't
-        * have to worry about OOM or overhead. */
+       /* directly invoke on_cpu0_workfn() in the common case */
        if (get_cpu() == 0) {
-               ret = fn(call);
+               on_cpu0_workfn(&arg.work);
                put_cpu();
        } else {
                put_cpu();
-               ret = work_on_cpu(0, fn, call);
+               INIT_WORK_ONSTACK(&arg.work, on_cpu0_workfn);
+               schedule_work_on(0, &arg.work);
+               flush_work(&arg.work);
        }
 
        /* work_on_cpu can fail with -ENOMEM */
-       if (ret < 0)
-               call->err = ret;
+       if (arg.ret < 0)
+               call->err = arg.ret;
        else
                call->err = (call->eax >> 8) & 0xff;
 
-       return ret;
+       return arg.ret;
 }
 
 /**