linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86, apm: Make on_cpu0() use workqueue instead of work_on_cpu()
@ 2012-08-24  1:11 Tejun Heo
  2012-08-28 22:57 ` Jiri Kosina
  0 siblings, 1 reply; 4+ messages in thread
From: Tejun Heo @ 2012-08-24  1:11 UTC (permalink / raw)
  To: Jiri Kosina, H. Peter Anvin; +Cc: x86, linux-kernel

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>
---
 arch/x86/kernel/apm_32.c |   31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
index d65464e..2bdb8c4 100644
--- a/arch/x86/kernel/apm_32.c
+++ b/arch/x86/kernel/apm_32.c
@@ -605,28 +605,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;
 }
 
 /**

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86, apm: Make on_cpu0() use workqueue instead of work_on_cpu()
  2012-08-24  1:11 [PATCH] x86, apm: Make on_cpu0() use workqueue instead of work_on_cpu() Tejun Heo
@ 2012-08-28 22:57 ` Jiri Kosina
  2012-09-17 21:38   ` Tejun Heo
  0 siblings, 1 reply; 4+ messages in thread
From: Jiri Kosina @ 2012-08-28 22:57 UTC (permalink / raw)
  To: Tejun Heo; +Cc: H. Peter Anvin, x86, linux-kernel

On Thu, 23 Aug 2012, Tejun Heo wrote:

> 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.

Applying to apm.git, thanks Tejun.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86, apm: Make on_cpu0() use workqueue instead of work_on_cpu()
  2012-08-28 22:57 ` Jiri Kosina
@ 2012-09-17 21:38   ` Tejun Heo
  2012-09-18 10:19     ` Jiri Kosina
  0 siblings, 1 reply; 4+ messages in thread
From: Tejun Heo @ 2012-09-17 21:38 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: H. Peter Anvin, x86, linux-kernel

On Tue, Aug 28, 2012 at 03:57:27PM -0700, Jiri Kosina wrote:
> On Thu, 23 Aug 2012, Tejun Heo wrote:
> 
> > 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.
> 
> Applying to apm.git, thanks Tejun.

It seems we need work_on_cpu() after all and I'm planning on
reimplementing it in saner way.  Can you please drop this one?

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86, apm: Make on_cpu0() use workqueue instead of work_on_cpu()
  2012-09-17 21:38   ` Tejun Heo
@ 2012-09-18 10:19     ` Jiri Kosina
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2012-09-18 10:19 UTC (permalink / raw)
  To: Tejun Heo; +Cc: H. Peter Anvin, x86, linux-kernel

On Mon, 17 Sep 2012, Tejun Heo wrote:

> > > 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.
> > 
> > Applying to apm.git, thanks Tejun.
> 
> It seems we need work_on_cpu() after all and I'm planning on
> reimplementing it in saner way.  Can you please drop this one?

Okay, dropped now.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-09-18 10:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-24  1:11 [PATCH] x86, apm: Make on_cpu0() use workqueue instead of work_on_cpu() Tejun Heo
2012-08-28 22:57 ` Jiri Kosina
2012-09-17 21:38   ` Tejun Heo
2012-09-18 10:19     ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).