lkml.org 
[lkml]   [2012]   [Sep]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 1/4] task_work: make task_work_add() lockless
From
On Sun, Aug 26, 2012 at 9:12 PM, Oleg Nesterov <oleg@redhat.com> 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@infradead.org>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>

> --- 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@linux-m68k.org

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


\
 
 \ /
  Last update: 2012-09-24 23:01    [W:0.147 / U:0.552 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site