[RFC 0/2] qemu-sem-posix: use monotonic clock instead

Longpeng(Mike) via posted 2 patches 2 years, 2 months ago
Test checkpatch failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220221095617.1974-1-longpeng2@huawei.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>
There is a newer version of this series
include/qemu/thread-posix.h |  5 +--
meson.build                 | 12 ++++++-
util/qemu-thread-posix.c    | 82 +++++++++++++++------------------------------
3 files changed, 39 insertions(+), 60 deletions(-)
[RFC 0/2] qemu-sem-posix: use monotonic clock instead
Posted by Longpeng(Mike) via 2 years, 2 months ago
The qemu_sem_timedwait() uses system time as default, it would be affected by
changes to the system time. In the real scenario, the time that goes faster or
slower is a common case and the NTP service could help us to sync time
periodically.

This patchset uses monotonic clock instead of the realtime clock, this could
make sure we would not be affected by the system time anymore.

Longpeng (Mike) (2):
  sem-posix: remove the posix semaphore support
  sem-posix: use monotonic clock instead

 include/qemu/thread-posix.h |  5 +--
 meson.build                 | 12 ++++++-
 util/qemu-thread-posix.c    | 82 +++++++++++++++------------------------------
 3 files changed, 39 insertions(+), 60 deletions(-)

-- 
1.8.3.1


Re: [RFC 0/2] qemu-sem-posix: use monotonic clock instead
Posted by Paolo Bonzini 2 years, 2 months ago
On 2/21/22 10:56, Longpeng(Mike) via wrote:
> The qemu_sem_timedwait() uses system time as default, it would be affected by
> changes to the system time. In the real scenario, the time that goes faster or
> slower is a common case and the NTP service could help us to sync time
> periodically.
> 
> This patchset uses monotonic clock instead of the realtime clock, this could
> make sure we would not be affected by the system time anymore.

This looks good, I don't think there are cases where a more optimized 
semaphore is necessary (if there were, we could introduce a futex 
fallback on Linux).

However, pthread_condattr_t need not be in the struct.  The attributes 
can be allocated on the stack, because they do not have to remain alive 
after pthread_cond_init.

Thanks,

Paolo

> Longpeng (Mike) (2):
>    sem-posix: remove the posix semaphore support
>    sem-posix: use monotonic clock instead
> 
>   include/qemu/thread-posix.h |  5 +--
>   meson.build                 | 12 ++++++-
>   util/qemu-thread-posix.c    | 82 +++++++++++++++------------------------------
>   3 files changed, 39 insertions(+), 60 deletions(-)
> 


RE: [RFC 0/2] qemu-sem-posix: use monotonic clock instead
Posted by longpeng2--- via 2 years, 2 months ago

> -----Original Message-----
> From: Paolo Bonzini [mailto:paolo.bonzini@gmail.com] On Behalf Of Paolo Bonzini
> Sent: Monday, February 21, 2022 7:31 PM
> To: Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
> <longpeng2@huawei.com>; berrange@redhat.com; mst@redhat.com
> Cc: qemu-devel@nongnu.org; Gonglei (Arei) <arei.gonglei@huawei.com>
> Subject: Re: [RFC 0/2] qemu-sem-posix: use monotonic clock instead
> 
> On 2/21/22 10:56, Longpeng(Mike) via wrote:
> > The qemu_sem_timedwait() uses system time as default, it would be affected
> by
> > changes to the system time. In the real scenario, the time that goes faster
> or
> > slower is a common case and the NTP service could help us to sync time
> > periodically.
> >
> > This patchset uses monotonic clock instead of the realtime clock, this could
> > make sure we would not be affected by the system time anymore.
> 
> This looks good, I don't think there are cases where a more optimized
> semaphore is necessary (if there were, we could introduce a futex
> fallback on Linux).
> 
> However, pthread_condattr_t need not be in the struct.  The attributes
> can be allocated on the stack, because they do not have to remain alive
> after pthread_cond_init.
> 

OK, will do in the next version, thanks!

> Thanks,
> 
> Paolo
> 
> > Longpeng (Mike) (2):
> >    sem-posix: remove the posix semaphore support
> >    sem-posix: use monotonic clock instead
> >
> >   include/qemu/thread-posix.h |  5 +--
> >   meson.build                 | 12 ++++++-
> >   util/qemu-thread-posix.c    | 82
> +++++++++++++++------------------------------
> >   3 files changed, 39 insertions(+), 60 deletions(-)
> >