Re: [PATCH 1/4] task_work: make task_work_add() lockless

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Aug 26, 2012 at 9:12 PM, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> Change task_works to use llist-like code to avoid pi_lock
> in task_work_add(), this makes it useable under rq->lock.
>
> task_work_cancel() and task_work_run() still use pi_lock
> to synchronize with each other.
>
> Suggested-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>

> --- a/kernel/task_work.c
> +++ b/kernel/task_work.c

> @@ -30,52 +23,60 @@ task_work_add(struct task_struct *task, struct callback_head *twork, bool notify
>  struct callback_head *
>  task_work_cancel(struct task_struct *task, task_work_func_t func)
>  {
> +       struct callback_head **pprev = &task->task_works;
> +       struct callback_head *work = NULL;
>         unsigned long flags;
> -       struct callback_head *last, *res = NULL;
> -
> +       /*
> +        * If cmpxchg() fails we continue without updating pprev.
> +        * Either we raced with task_work_add() which added the
> +        * new entry before this work, we will find it again. Or
> +        * we raced with task_work_run(), *pprev == NULL.
> +        */
>         raw_spin_lock_irqsave(&task->pi_lock, flags);
> -       last = task->task_works;
> -       if (last) {
> -               struct callback_head *q = last, *p = q->next;
> -               while (1) {
> -                       if (p->func == func) {
> -                               q->next = p->next;
> -                               if (p == last)
> -                                       task->task_works = q == p ? NULL : q;
> -                               res = p;
> -                               break;
> -                       }
> -                       if (p == last)
> -                               break;
> -                       q = p;
> -                       p = q->next;
> -               }
> +       while ((work = ACCESS_ONCE(*pprev))) {
> +               read_barrier_depends();

Woops, h8300 doesn't have read_barrier_depends():
kernel/task_work.c:38:3: error: implicit declaration of function
'read_barrier_depends' [-Werror=implicit-function-declaration]
cc1: some warnings being treated as errors
make[2]: *** [kernel/task_work.o] Error 1

http://kisskb.ellerman.id.au/kisskb/buildresult/7238385/

Perhaps an empty definition is fine? Most architectures have:

#define read_barrier_depends() do { } while(0)

The same issue on c6x just got fixed in -next in commit
2c8c2366077da5645bf9063b3cf5c94ecb16f691 ("c6x: use
asm-generic/barrier.h")

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-next" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel]     [Linux USB Development]     [Yosemite News]     [Linux SCSI]

  Powered by Linux