From: Manfred Spraul <manfred@colorfullife.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
Darren Hart <dvhart@linux.intel.com>,
David Miller <davem@davemloft.net>,
Eric Dumazet <eric.dumazet@gmail.com>,
Mike Galbraith <efault@gmx.de>
Subject: Re: [RFC][PATCH 3/3] ipc/sem: Rework wakeup scheme
Date: Thu, 15 Sep 2011 19:29:26 +0200 [thread overview]
Message-ID: <4E7235F6.1030303@colorfullife.com> (raw)
In-Reply-To: <20110914133750.916911903@chello.nl>
Hi Peter,
On 09/14/2011 03:30 PM, Peter Zijlstra wrote:
> This removes the home-brew busy-wait and the requirement to keep
> preemption disabled.
In the initial mail of the patch series, you write:
> Patch 3 converts sysv sems, and is broken
What is broken?
>
> /**
> * newary - Create a new semaphore set
> @@ -406,51 +388,39 @@ static int try_atomic_semop (struct sem_
> return result;
> }
>
> -/** wake_up_sem_queue_prepare(q, error): Prepare wake-up
> +/** wake_up_sem_queue_prepare(wake_list, q, error): Prepare wake-up
> + * @wake_list: list to queue the to be woken task on
> * @q: queue entry that must be signaled
> * @error: Error value for the signal
> *
> * Prepare the wake-up of the queue entry q.
> */
> -static void wake_up_sem_queue_prepare(struct list_head *pt,
> +static void wake_up_sem_queue_prepare(struct wake_list_head *wake_list,
> struct sem_queue *q, int error)
> {
> - if (list_empty(pt)) {
> - /*
> - * Hold preempt off so that we don't get preempted and have the
> - * wakee busy-wait until we're scheduled back on.
> - */
> - preempt_disable();
> - }
> - q->status = IN_WAKEUP;
> - q->pid = error;
> + struct task_struct *p = ACCESS_ONCE(q->sleeper);
>
> - list_add_tail(&q->simple_list, pt);
> + get_task_struct(p);
> + q->status = error;
> + /*
> + * implies a full barrier
> + */
> + wake_list_add(wake_list, p);
> + put_task_struct(p);
> }
I think the get_task_struct()/put_task_struct is not necessary:
Just do the wake_list_add() before writing q->status:
wake_list_add() is identical to list_add_tail(&q->simple_list, pt).
[except that it contains additional locking, which doesn't matter here]
>
> /**
> - * wake_up_sem_queue_do(pt) - do the actual wake-up
> - * @pt: list of tasks to be woken up
> + * wake_up_sem_queue_do(wake_list) - do the actual wake-up
> + * @wake_list: list of tasks to be woken up
> *
> * Do the actual wake-up.
> * The function is called without any locks held, thus the semaphore array
> * could be destroyed already and the tasks can disappear as soon as the
> * status is set to the actual return code.
> */
> -static void wake_up_sem_queue_do(struct list_head *pt)
> +static void wake_up_sem_queue_do(struct wake_list_head *wake_list)
> {
> - struct sem_queue *q, *t;
> - int did_something;
> -
> - did_something = !list_empty(pt);
> - list_for_each_entry_safe(q, t, pt, simple_list) {
> - wake_up_process(q->sleeper);
> - /* q can disappear immediately after writing q->status. */
> - smp_wmb();
> - q->status = q->pid;
> - }
> - if (did_something)
> - preempt_enable();
> + wake_up_list(wake_list, TASK_ALL);
> }
>
wake_up_list() calls wake_up_state() that calls try_to_wake_up().
try_to_wake_up() seems to return immediately when the state is TASK_DEAD.
That leaves: Is it safe to call wake_up_list() in parallel with do_exit()?
The current implementation avoids that.
--
Manfred
next prev parent reply other threads:[~2011-09-15 17:32 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-14 13:30 [RFC][PATCH 0/3] delayed wakeup list Peter Zijlstra
2011-09-14 13:30 ` [RFC][PATCH 1/3] sched: Provide " Peter Zijlstra
2011-09-14 13:50 ` Peter Zijlstra
2011-09-14 14:08 ` Eric Dumazet
2011-09-14 14:12 ` Peter Zijlstra
2011-09-14 15:35 ` Darren Hart
2011-09-14 15:39 ` Peter Zijlstra
2011-09-14 15:49 ` Darren Hart
2011-09-16 7:59 ` Paul Turner
2011-09-16 7:59 ` Paul Turner
2011-09-16 8:48 ` Peter Zijlstra
2011-10-02 14:01 ` Manfred Spraul
2011-10-03 10:23 ` Peter Zijlstra
2011-09-14 13:30 ` [RFC][PATCH 2/3] futex: Reduce hash bucket lock contention Peter Zijlstra
2011-09-14 15:46 ` Darren Hart
2011-09-14 15:51 ` Peter Zijlstra
2011-09-14 16:00 ` Darren Hart
2011-09-14 20:49 ` Thomas Gleixner
2011-09-16 12:34 ` Peter Zijlstra
2011-09-17 12:57 ` Manfred Spraul
2011-09-19 7:37 ` Peter Zijlstra
2011-09-19 8:51 ` Peter Zijlstra
2011-09-14 13:30 ` [RFC][PATCH 3/3] ipc/sem: Rework wakeup scheme Peter Zijlstra
2011-09-15 17:29 ` Manfred Spraul [this message]
2011-09-15 19:32 ` Peter Zijlstra
2011-09-15 19:35 ` Peter Zijlstra
2011-09-15 19:45 ` Peter Zijlstra
2011-09-17 12:36 ` Manfred Spraul
2011-09-16 12:18 ` Peter Zijlstra
2011-09-17 12:32 ` Manfred Spraul
2011-09-16 12:39 ` Peter Zijlstra
2011-09-14 13:51 ` [RFC][PATCH 0/3] delayed wakeup list Eric Dumazet
2011-09-14 13:56 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E7235F6.1030303@colorfullife.com \
--to=manfred@colorfullife.com \
--cc=a.p.zijlstra@chello.nl \
--cc=davem@davemloft.net \
--cc=dvhart@linux.intel.com \
--cc=efault@gmx.de \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.