Re: [PATCH 1/1] percpu_rw_semaphore: reimplement to not block thereaders unnecessarily

From: Oleg Nesterov
Date: Thu Nov 01 2012 - 14:32:48 EST


Paul, thanks.

Sorry, I can't reply today, just one note...

On 11/01, Paul E. McKenney wrote:
>
> OK, so it looks to me that this code relies on synchronize_sched()
> forcing a memory barrier on each CPU executing in the kernel.

No, the patch tries to avoid this assumption, but probably I missed
something.

> 1. A task running on CPU 0 currently write-holds the lock.
>
> 2. CPU 1 is running in the kernel, executing a longer-than-average
> loop of normal instructions (no atomic instructions or memory
> barriers).
>
> 3. CPU 0 invokes percpu_up_write(), calling up_write(),
> synchronize_sched(), and finally mutex_unlock().

And my expectation was, this should be enough because ...

> 4. CPU 1 executes percpu_down_read(), which calls update_fast_ctr(),

since update_fast_ctr does preempt_disable/enable it should see all
modifications done by CPU 0.

IOW. Suppose that the writer (CPU 0) does

percpu_done_write();
STORE;
percpu_up_write();

This means

STORE;
synchronize_sched();
mutex_unlock();

Now. Do you mean that the next preempt_disable/enable can see the
result of mutex_unlock() but not STORE?

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/