From: Peter Zijlstra <peterz@infradead.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Will Deacon <will.deacon@kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org, bigeasy@linutronix.de,
juri.lelli@redhat.com, williams@redhat.com, bristot@redhat.com,
longman@redhat.com, dave@stgolabs.net, jack@suse.com
Subject: Re: [PATCH] locking/percpu_rwsem: Rewrite to not use rwsem
Date: Thu, 31 Oct 2019 07:11:18 +0100 [thread overview]
Message-ID: <20191031061118.GH5671@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20191030175231.GF5671@hirez.programming.kicks-ass.net>
On Wed, Oct 30, 2019 at 06:52:31PM +0100, Peter Zijlstra wrote:
> +enum wake_state {
> + unknown = -1,
> + writer = 0,
> + reader = 1,
> +};
> +
> +/*
> + * percpu_rwsem_wake_function -- provide FIFO fair reader/writer wakeups
> + *
> + * As per percpu_rwsem_wait() all waiters are queued exclusive (tail/FIFO)
> + * without autoremove to preserve FIFO order.
> + */
> +static int percpu_rwsem_wake_function(struct wait_queue_entry *wq_entry,
> + unsigned int mode, int wake_flags,
> + void *key)
> +{
> + enum wake_state state = (wq_entry->flags & WQ_FLAG_CUSTOM) ? reader : writer;
> + enum wake_state *statep = key;
> +
> + if (*statep != unknown && (*statep == writer || state == writer))
> + return 1; /* stop; woken 1 writer or exhausted readers */
> +
> + if (default_wake_function(wq_entry, mode, wake_flags, NULL))
> + *statep = state;
> +
> + return 0; /* continue waking */
> +}
> +
> +#define percpu_rwsem_wait(sem, reader, cond) \
> +do { \
> + DEFINE_WAIT_FUNC(wq_entry, percpu_rwsem_wake_function); \
> + \
> + if (reader) \
> + wq_entry.flags |= WQ_FLAG_CUSTOM; \
> + \
> + add_wait_queue_exclusive(&(sem)->waiters, &wq_entry); \
> + for (;;) { \
> + set_current_state(TASK_UNINTERRUPTIBLE); \
> + if (cond) \
> + break; \
> + schedule(); \
> + } \
> + __set_current_state(TASK_RUNNING); \
> + remove_wait_queue(&(sem)->waiters, &wq_entry); \
> +} while (0)
> +
> +#define percpu_rwsem_wake(sem) \
> +do { \
> + enum wake_state ____state = unknown; \
> + __wake_up(&(sem)->waiters, TASK_NORMAL, 1, &____state); \
> +} while (0)
That isn't quite right, when it has readers and a pending writer, things
go sideways.
I'm going to have to poke a little more at this.
next prev parent reply other threads:[~2019-10-31 6:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-05 14:02 Peter Zijlstra
2019-08-05 14:43 ` Boqun Feng
2019-08-05 14:58 ` Boqun Feng
2019-08-05 15:43 ` Peter Zijlstra
2019-08-06 14:15 ` Boqun Feng
2019-08-06 16:17 ` Oleg Nesterov
2019-08-06 17:15 ` Peter Zijlstra
2019-08-07 9:56 ` Oleg Nesterov
2019-10-29 18:47 ` Peter Zijlstra
2019-10-30 14:21 ` Oleg Nesterov
2019-10-30 16:09 ` Peter Zijlstra
2019-10-30 17:52 ` Peter Zijlstra
2019-10-30 18:47 ` Peter Zijlstra
2019-10-30 19:31 ` Peter Zijlstra
2019-10-31 6:11 ` Peter Zijlstra [this message]
2019-08-07 14:45 ` Will Deacon
2019-10-29 19:06 ` Peter Zijlstra
2019-10-30 15:57 ` Oleg Nesterov
2019-10-30 16:47 ` 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=20191031061118.GH5671@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bigeasy@linutronix.de \
--cc=bristot@redhat.com \
--cc=dave@stgolabs.net \
--cc=jack@suse.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=tglx@linutronix.de \
--cc=will.deacon@kernel.org \
--cc=williams@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®