Date: Tue, 29 Dec 2020 12:07:10 +0100 From: Hans Petter Selasky <hps@selasky.org> To: Sebastian Huber <sebastian.huber@embedded-brains.de>, freebsd-hackers@freebsd.org Subject: Re: Why is there e_drain_sx and e_drain_mtx? Message-ID: <529e7ef5-18e9-0e56-16d3-000d324f42d0@selasky.org> In-Reply-To: <5eeae691-b7d4-932b-14cc-065a368e77de@embedded-brains.de> References: <5eeae691-b7d4-932b-14cc-065a368e77de@embedded-brains.de>
next in thread | previous in thread | raw e-mail | index | archive | help
On 12/29/20 11:49 AM, Sebastian Huber wrote:
> Hello,
>
> in the epoch based reclamation implementation we have
>
> struct epoch {
> struct ck_epoch e_epoch __aligned(EPOCH_ALIGN);
> epoch_record_t e_pcpu_record;
> int e_in_use;
> int e_flags;
> struct sx e_drain_sx;
> struct mtx e_drain_mtx;
> volatile int e_drain_count;
> const char *e_name;
> };
>
> The e_drain_sx and e_drain_mtx are only used in
>
> void
> epoch_drain_callbacks(epoch_t epoch)
> {
> ...
> DROP_GIANT();
>
> sx_xlock(&epoch->e_drain_sx);
> mtx_lock(&epoch->e_drain_mtx);
>
> ...
>
> mtx_unlock(&epoch->e_drain_mtx);
> sx_xunlock(&epoch->e_drain_sx);
>
> PICKUP_GIANT();
> }
>
> Why is there a combination of a shared/exclusive lock and a mutex used
> like this? Why is a single mutex insufficient?
>
Hi Sebastian,
The sx_xlock() is there because the operation may sleep and mutexes must
be dropped when sleeping. We only allow one drain at a time.
The mtx_lock() is there to make the operation atomic with regards to the
msleep/wakeup sequence. Search for the use of e_drain_mtx . Else the
msleep and wakeup calls may miss eachother.
How is the porting going otherwise? Do you see any performance
improvements using EPOCH?
--HPS
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?529e7ef5-18e9-0e56-16d3-000d324f42d0>
