lkml.org 
[lkml]   [2012]   [Mar]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 2/2] firmware_class: Move request_firmware_nowait() to workqueues
Date
On Tuesday, March 27, 2012, Stephen Boyd wrote:
> Oddly enough a work_struct was already part of the firmware_work
> structure but nobody was using it. Instead of creating a new
> kthread for each request_firmware_nowait() call just schedule the
> work on the long system workqueue. This should avoid some overhead
> in forking new threads when they're not strictly necessary.
>
> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
> ---
>
> Is it better to use alloc_workqueue() and not put these on the system
> long workqueue?

I think if that happens to interfere destructively with something,
we can always use a new workqueue. For now, let's try to avoid
adding yet another one if possible.

Thanks,
Rafael


> drivers/base/firmware_class.c | 27 +++++++--------------------
> 1 file changed, 7 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
> index ae00a2f..4d8cb8b 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -16,10 +16,11 @@
> #include <linux/interrupt.h>
> #include <linux/bitops.h>
> #include <linux/mutex.h>
> -#include <linux/kthread.h>
> +#include <linux/workqueue.h>
> #include <linux/highmem.h>
> #include <linux/firmware.h>
> #include <linux/slab.h>
> +#include <linux/sched.h>
>
> #define to_dev(obj) container_of(obj, struct device, kobj)
>
> @@ -630,19 +631,15 @@ struct firmware_work {
> bool uevent;
> };
>
> -static int request_firmware_work_func(void *arg)
> +static void request_firmware_work_func(struct work_struct *work)
> {
> - struct firmware_work *fw_work = arg;
> + struct firmware_work *fw_work;
> const struct firmware *fw;
> struct firmware_priv *fw_priv;
> long timeout;
> int ret;
>
> - if (!arg) {
> - WARN_ON(1);
> - return 0;
> - }
> -
> + fw_work = container_of(work, struct firmware_work, work);
> fw_priv = _request_firmware_prepare(&fw, fw_work->name, fw_work->device,
> fw_work->uevent, true);
> if (IS_ERR_OR_NULL(fw_priv)) {
> @@ -667,8 +664,6 @@ static int request_firmware_work_func(void *arg)
>
> module_put(fw_work->module);
> kfree(fw_work);
> -
> - return ret;
> }
>
> /**
> @@ -694,7 +689,6 @@ request_firmware_nowait(
> const char *name, struct device *device, gfp_t gfp, void *context,
> void (*cont)(const struct firmware *fw, void *context))
> {
> - struct task_struct *task;
> struct firmware_work *fw_work;
>
> fw_work = kzalloc(sizeof (struct firmware_work), gfp);
> @@ -713,15 +707,8 @@ request_firmware_nowait(
> return -EFAULT;
> }
>
> - task = kthread_run(request_firmware_work_func, fw_work,
> - "firmware/%s", name);
> - if (IS_ERR(task)) {
> - fw_work->cont(NULL, fw_work->context);
> - module_put(fw_work->module);
> - kfree(fw_work);
> - return PTR_ERR(task);
> - }
> -
> + INIT_WORK(&fw_work->work, request_firmware_work_func);
> + queue_work(system_long_wq, &fw_work->work);
> return 0;
> }
>
>



\
 
 \ /
  Last update: 2012-03-27 23:47    [W:0.616 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site