From: Richard Henderson <richard.henderson@linaro.org>
To: Warner Losh <imp@bsdimp.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: Question about atomics
Date: Sun, 13 Mar 2022 10:03:24 -0700 [thread overview]
Message-ID: <45371f77-cae6-bf96-802d-6a3e70d5e334@linaro.org> (raw)
In-Reply-To: <CANCZdfoC8ArxyvD3PpBWiYdqONR32oeqioqk42CeoMeKRgecZQ@mail.gmail.com>
On 3/13/22 09:57, Warner Losh wrote:
>
>
> On Sun, Mar 13, 2022, 10:47 AM Richard Henderson <richard.henderson@linaro.org
> <mailto:richard.henderson@linaro.org>> wrote:
>
> On 3/12/22 20:59, Warner Losh wrote:
> > FreeBSD's pthread_mutex is shared between the kernel and user land.
> > So it does a compare and set to take the lock. Uncontested and unheld
> > locks will mean we've taken the lock and return. Contested locks
> > are kicked to the kernel to wait. When userland releases the lock
> > it signals the kernel to wakeup via a system call. The kernel then
> > does a cas to try to acquire the lock. It either returns with the lock
> > held, or goes back to sleep. This we have atomics operating both in
> > the kernel (via standard host atomics) and userland atomics done
> > via start/end_exclusive.
>
> You need to use standard host atomics for this case.
>
>
> Or use the start/end_exclusive for both by emulating the kernel call, I presume? It's the
> mixing that's the problem, right?
Well, preferably no. Use start/end_exclusive only when you have no alternative, which for
a simple CAS should not be the case on any FreeBSD host.
Using start/end_exclusive is entirely local to the current process, and means you don't
have atomicity across processes. Which can cause problems when emulating an entire chroot.
r~
next prev parent reply other threads:[~2022-03-13 17:05 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-08 4:18 Question about atomics Warner Losh
2022-03-08 5:00 ` Richard Henderson
2022-03-08 14:09 ` Warner Losh
2022-03-08 14:26 ` Paolo Bonzini
2022-03-08 16:29 ` Warner Losh
2022-03-13 4:59 ` Warner Losh
2022-03-13 16:47 ` Richard Henderson
2022-03-13 16:57 ` Warner Losh
2022-03-13 17:03 ` Richard Henderson [this message]
2022-03-13 18:29 ` Warner Losh
2022-03-13 20:19 ` Richard Henderson
2022-03-14 4:09 ` Warner Losh
2022-03-14 4:36 ` Richard Henderson
2022-03-14 5:42 ` Warner Losh
2022-03-14 4:43 ` Richard Henderson
2022-03-14 5:34 ` Warner Losh
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=45371f77-cae6-bf96-802d-6a3e70d5e334@linaro.org \
--to=richard.henderson@linaro.org \
--cc=imp@bsdimp.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).