From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Jürgen Groß" <jgross@suse.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Julien Grall" <julien@xen.org>, "Wei Liu" <wl@xen.org>,
"Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com>,
"George Dunlap" <George.Dunlap@eu.citrix.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Ian Jackson" <ian.jackson@eu.citrix.com>,
xen-devel@lists.xenproject.org
Subject: Re: [Xen-devel] [PATCH] rwlock: allow recursive read locking when already locked in write mode
Date: Thu, 20 Feb 2020 16:20:04 +0100 [thread overview]
Message-ID: <20200220152004.GN4679@Air-de-Roger> (raw)
In-Reply-To: <a2111136-e91c-4077-5bea-ea310a43979e@suse.com>
On Thu, Feb 20, 2020 at 04:11:08PM +0100, Jan Beulich wrote:
> On 20.02.2020 15:38, Roger Pau Monné wrote:
> > On Thu, Feb 20, 2020 at 03:23:38PM +0100, Jürgen Groß wrote:
> >> On 20.02.20 15:11, Roger Pau Monné wrote:
> >>> On Thu, Feb 20, 2020 at 01:48:54PM +0100, Jan Beulich wrote:
> >>>> On 20.02.2020 13:02, Roger Pau Monne wrote:
> >>>>> @@ -166,7 +180,8 @@ static inline void _write_unlock(rwlock_t *lock)
> >>>>> * If the writer field is atomic, it can be cleared directly.
> >>>>> * Otherwise, an atomic subtraction will be used to clear it.
> >>>>> */
> >>>>> - atomic_sub(_QW_LOCKED, &lock->cnts);
> >>>>> + ASSERT(_is_write_locked_by_me(atomic_read(&lock->cnts)));
> >>>>> + atomic_sub(_write_lock_val(), &lock->cnts);
> >>>>
> >>>> I think this would be more efficient with atomic_and(), not
> >>>> the least because of the then avoided smp_processor_id().
> >>>> Whether to mask off just _QW_WMASK or also the CPU number of
> >>>> the last write owner would need to be determined. But with
> >>>> using subtraction, in case of problems it'll likely be
> >>>> harder to understand what actually went on, from looking at
> >>>> the resulting state of the lock (this is in part a pre-
> >>>> existing problem, but gets worse with subtraction of CPU
> >>>> numbers).
> >>>
> >>> Right, a mask would be better. Right now both need to be cleared (the
> >>> LOCKED and the CPU fields) as there's code that relies on !lock->cnts
> >>> as a way to determine that the lock is not read or write locked. If we
> >>> left the CPU lying around those checks would need to be adjusted.
> >>
> >> In case you make _QR_SHIFT 16 it is possible to just write a 2-byte zero
> >> value for write_unlock() (like its possible to do so today using a
> >> single byte write).
> >
> > That would limit the readers count to 65536, what do you think Jan?
>
> If the recurse_cpu approach is considered bad, I think this would
> be acceptable. But of course you'll need to consult with the Arm
> guys regarding the correctness of such a "half" store in their
> memory model; I would hope this to be universally okay, but I'm
> not entirely certain.
I would like to get confirmation from the Arm folks, but I see Arm has
write_atomic and supports such operation against a uint16_t, so I
don't see why it wouldn't work.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-02-20 15:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-20 12:02 [Xen-devel] [PATCH] rwlock: allow recursive read locking when already locked in write mode Roger Pau Monne
2020-02-20 12:48 ` Jan Beulich
2020-02-20 14:11 ` Roger Pau Monné
2020-02-20 14:23 ` Jürgen Groß
2020-02-20 14:38 ` Roger Pau Monné
2020-02-20 15:11 ` Jan Beulich
2020-02-20 15:20 ` Roger Pau Monné [this message]
2020-02-20 15:52 ` Jan Beulich
2020-02-20 15:02 ` Jan Beulich
2020-02-20 15:17 ` Roger Pau Monné
2020-02-20 15:50 ` Jan Beulich
2020-02-20 15:57 ` Roger Pau Monné
2020-02-20 16:00 ` Jürgen Groß
2020-02-20 16:54 ` Roger Pau Monné
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=20200220152004.GN4679@Air-de-Roger \
--to=roger.pau@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=julien@xen.org \
--cc=konrad.wilk@oracle.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/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.