From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Longpeng(Mike)" <longpeng2@huawei.com>
Cc: pbonzini@redhat.com, arei.gonglei@huawei.com,
qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [RFC 1/2] sem-posix: remove the posix semaphore support
Date: Mon, 21 Feb 2022 11:11:51 +0000 [thread overview]
Message-ID: <YhNzd6bGT2ejTRLx@redhat.com> (raw)
In-Reply-To: <20220221095617.1974-2-longpeng2@huawei.com>
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:
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]
> 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 ?
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 11:14 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é [this message]
2022-02-21 14:35 ` longpeng2--- via
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=YhNzd6bGT2ejTRLx@redhat.com \
--to=berrange@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=longpeng2@huawei.com \
--cc=mst@redhat.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 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.