Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1536254

Re: [PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake to not use wait-queues

From Oleg Nesterov <oleg@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake to not use wait-queues
Date 2016-12-05 18:20 +0100
Message-ID <sL55L-7o6-27@gated-at.bofh.it> (permalink)
References <sEWye-2tW-9@gated-at.bofh.it> <sEWye-2tW-29@gated-at.bofh.it> <sK85H-3yk-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 12/02, Davidlohr Bueso wrote:
>
> @@ -102,8 +103,13 @@ void __percpu_up_read(struct percpu_rw_semaphore *sem)
> 	 */
> 	__this_cpu_dec(*sem->read_count);
>
> +	rcu_read_lock();
> +	writer = rcu_dereference(sem->writer);
> +
> 	/* Prod writer to recheck readers_active */
> -	wake_up(&sem->writer);
> +	if (writer)
> +		wake_up_process(writer);
> +	rcu_read_unlock();

This needs a barrier between __this_cpu_dec() and rcu_dereference(), I think.

> @@ -159,8 +165,18 @@ void percpu_down_write(struct percpu_rw_semaphore *sem)
> 	 * will wait for them.
> 	 */
>
> -	/* Wait for all now active readers to complete. */
> -	wait_event(sem->writer, readers_active_check(sem));
> +	WRITE_ONCE(sem->writer, current);
> +	for (;;) {
> +		set_current_state(TASK_UNINTERRUPTIBLE);
> +
> +		if (readers_active_check(sem))
> +			break;

This looks fine, we can rely on set_current_state() which inserts a barrier
between WRITE_ONCE() and readers_active_check(). So we do not even need
WRITE_ONCE().

And the fact this needs the barriers and the comments makes me think again
you should add the new helpers.

Oleg.

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake to not  use wait-queues Davidlohr Bueso <dave@stgolabs.net> - 2016-12-03 03:20 +0100
  Re: [PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake to  not use wait-queues Peter Zijlstra <peterz@infradead.org> - 2016-12-05 09:40 +0100
    Re: [PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake         to not use wait-queues Oleg Nesterov <oleg@redhat.com> - 2016-12-05 12:30 +0100
      Re: [PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake         to not use wait-queues Oleg Nesterov <oleg@redhat.com> - 2016-12-05 12:50 +0100
      Re: [PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake to  not use wait-queues Davidlohr Bueso <dave@stgolabs.net> - 2016-12-05 18:40 +0100
    Re: [PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake         to not use wait-queues Oleg Nesterov <oleg@redhat.com> - 2016-12-05 18:20 +0100
  Re: [PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake         to not use wait-queues Oleg Nesterov <oleg@redhat.com> - 2016-12-05 18:20 +0100

csiph-web