From: longpeng2--- via <qemu-devel@nongnu.org>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "pbonzini@redhat.com" <pbonzini@redhat.com>,
"mst@redhat.com" <mst@redhat.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"Gonglei (Arei)" <arei.gonglei@huawei.com>
Subject: RE: [RFC 1/2] sem-posix: remove the posix semaphore support
Date: Mon, 21 Feb 2022 14:35:54 +0000 [thread overview]
Message-ID: <012c3b918b9b494e97b34a44e791636f@huawei.com> (raw)
In-Reply-To: <YhNzd6bGT2ejTRLx@redhat.com>
Hi Daniel,
> -----Original Message-----
> From: Daniel P. Berrangé [mailto:berrange@redhat.com]
> Sent: Monday, February 21, 2022 7:12 PM
> To: Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
> <longpeng2@huawei.com>
> Cc: pbonzini@redhat.com; mst@redhat.com; qemu-devel@nongnu.org; Gonglei (Arei)
> <arei.gonglei@huawei.com>
> Subject: Re: [RFC 1/2] sem-posix: remove the posix semaphore support
>
> On Mon, Feb 21, 2022 at 05:56:16PM +0800, Longpeng(Mike) via wrote:
> > POSIX specifies an absolute time for sem_timedwait(), it would be
> > affected if the system time is changing, but there is not a relative
> > time or monotonic clock version of sem_timedwait, so we cannot gain
> > from POSIX semaphore anymore.
>
> It doesn't appear in any man pages on my systems, but there is a
> new-ish API sem_clockwait() that accepts a choice of clock as a
> parameter.
>
> This is apparently a proposed POSIX standard API introduced in
> glibc 2.30, along with several others:
>
But the API is only supported in glibc.
https://www.gnu.org/software/gnulib/manual/html_node/sem_005fclockwait.html
> https://sourceware.org/legacy-ml/libc-announce/2019/msg00001.html
>
> [quote]
> * Add new POSIX-proposed pthread_cond_clockwait, pthread_mutex_clocklock,
> pthread_rwlock_clockrdlock, pthread_rwlock_clockwrlock and sem_clockwait
> functions. These behave similarly to their "timed" equivalents, but also
> accept a clockid_t parameter to determine which clock their timeout should
> be measured against. All functions allow waiting against CLOCK_MONOTONIC
> and CLOCK_REALTIME. The decision of which clock to be used is made at the
> time of the wait (unlike with pthread_condattr_setclock, which requires
> the clock choice at initialization time).
> [/quote]
>
It seems pthread_condattr_setclock() can meet our requirement here, it's OK
for us to choose the clock at initialization time.
> > diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h
> > index b792e6e..5466608 100644
> > --- a/include/qemu/thread-posix.h
> > +++ b/include/qemu/thread-posix.h
> > @@ -27,13 +27,9 @@ struct QemuCond {
> > };
> >
> > struct QemuSemaphore {
> > -#ifndef CONFIG_SEM_TIMEDWAIT
> > pthread_mutex_t lock;
> > pthread_cond_t cond;
> > unsigned int count;
> > -#else
> > - sem_t sem;
> > -#endif
> > bool initialized;
> > };
>
> As a point of history, the original code only used sem_t. The pthreads
> based fallback was introduced by Paolo in
>
> commit c166cb72f1676855816340666c3b618beef4b976
> Author: Paolo Bonzini <pbonzini@redhat.com>
> Date: Fri Nov 2 15:43:21 2012 +0100
>
> semaphore: implement fallback counting semaphores with mutex+condvar
>
> OpenBSD and Darwin do not have sem_timedwait. Implement a fallback
> for them.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
>
> I'm going to assume this fallback impl is less efficient than the
> native sem_t impl as the reason for leaving the original impl, or
> maybe Paolo just want to risk accidental bugs by removing the
> existing usage ?
>
Paolo has replied, seems this change is acceptable, so I'll continue to
work on this solution. Thanks :)
>
> Regards,
> Daniel
> --
> |: https://berrange.com -o-
> https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o- https://fstop138.berrange.com :|
> |: https://entangle-photo.org -o-
> https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2022-02-21 14:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-21 9:56 [RFC 0/2] qemu-sem-posix: use monotonic clock instead Longpeng(Mike) via
2022-02-21 9:56 ` [RFC 1/2] sem-posix: remove the posix semaphore support Longpeng(Mike) via
2022-02-21 11:11 ` Daniel P. Berrangé
2022-02-21 14:35 ` longpeng2--- via [this message]
2022-02-23 9:42 ` Paolo Bonzini
2022-02-21 9:56 ` [RFC 2/2] sem-posix: use monotonic clock instead Longpeng(Mike) via
2022-02-21 11:42 ` Paolo Bonzini
2022-02-21 14:39 ` longpeng2--- via
2022-02-21 11:31 ` [RFC 0/2] qemu-sem-posix: " Paolo Bonzini
2022-02-21 14:37 ` longpeng2--- via
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=012c3b918b9b494e97b34a44e791636f@huawei.com \
--to=qemu-devel@nongnu.org \
--cc=arei.gonglei@huawei.com \
--cc=berrange@redhat.com \
--cc=longpeng2@huawei.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
/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).