public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Is there any API that could achieve a busy-wait for a certain duration, e.g. 500us, 1ms and etc?
@ 2020-09-02  2:36 孙世龙 sunshilong
  2020-09-02  8:42 ` Dmitry Mikushin
  0 siblings, 1 reply; 6+ messages in thread
From: 孙世龙 sunshilong @ 2020-09-02  2:36 UTC (permalink / raw)
  To: 孙世龙 sunshilong via Libc-help

Hi, list

Is there any API provided by GLIBC that could achieve a busy-wait for
a certain duration, e.g. 500us, 1ms and etc?

I would be grateful to have some help with this matter.

Best regards
Sunshilong

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Is there any API that could achieve a busy-wait for a certain duration, e.g. 500us, 1ms and etc?
  2020-09-02  2:36 Is there any API that could achieve a busy-wait for a certain duration, e.g. 500us, 1ms and etc? 孙世龙 sunshilong
@ 2020-09-02  8:42 ` Dmitry Mikushin
  2020-09-02  9:09   ` Mirko Banchi
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Mikushin @ 2020-09-02  8:42 UTC (permalink / raw)
  To: 孙世龙 sunshilong
  Cc: 孙世龙 sunshilong via Libc-help

Do you mean nanosleep() of unistd.h ?

ср, 2 сент. 2020 г. в 04:36, 孙世龙 sunshilong via Libc-help <
libc-help@sourceware.org>:

> Hi, list
>
> Is there any API provided by GLIBC that could achieve a busy-wait for
> a certain duration, e.g. 500us, 1ms and etc?
>
> I would be grateful to have some help with this matter.
>
> Best regards
> Sunshilong
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Is there any API that could achieve a busy-wait for a certain duration, e.g. 500us, 1ms and etc?
  2020-09-02  8:42 ` Dmitry Mikushin
@ 2020-09-02  9:09   ` Mirko Banchi
  2020-09-02 15:37     ` Carlos O'Donell
  0 siblings, 1 reply; 6+ messages in thread
From: Mirko Banchi @ 2020-09-02  9:09 UTC (permalink / raw)
  To: Dmitry Mikushin
  Cc: 孙世龙 sunshilong,
	孙世龙 sunshilong via Libc-help

Hi,

nanosleep() should suspend the thread, i think he asking for a call
performing busy wait.

M.

Il giorno mer 2 set 2020 alle ore 10:43 Dmitry Mikushin <
dmitry@kernelgen.org> ha scritto:

> Do you mean nanosleep() of unistd.h ?
>
> ср, 2 сент. 2020 г. в 04:36, 孙世龙 sunshilong via Libc-help <
> libc-help@sourceware.org>:
>
> > Hi, list
> >
> > Is there any API provided by GLIBC that could achieve a busy-wait for
> > a certain duration, e.g. 500us, 1ms and etc?
> >
> > I would be grateful to have some help with this matter.
> >
> > Best regards
> > Sunshilong
> >
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Is there any API that could achieve a busy-wait for a certain duration, e.g. 500us, 1ms and etc?
  2020-09-02  9:09   ` Mirko Banchi
@ 2020-09-02 15:37     ` Carlos O'Donell
  2020-09-03  1:33       ` 孙世龙 sunshilong
  0 siblings, 1 reply; 6+ messages in thread
From: Carlos O'Donell @ 2020-09-02 15:37 UTC (permalink / raw)
  To: Mirko Banchi, Dmitry Mikushin
  Cc: 孙世龙 sunshilong via Libc-help

On 9/2/20 5:09 AM, Mirko Banchi via Libc-help wrote:
> nanosleep() should suspend the thread, i think he asking for a call
> performing busy wait.

That is how I interpreted the request also.

We do not have any busy-wait-semantic wait functions with timeout.

The C library need not provide *all* utility functions, but must provide
enough utility to create those functions for yourself.

You can write such a function yourself using the various clock_* APIs
to get time, busy wait, and then get the time again.

Resolution will vary depending on the underlying implementation e.g.
vDSO vs. syscall.

We actually have need for this in pthread_rwlock_tryrdlock to implement
a randomized exponential back-off to avoid live-locking (not yet done).

There are valid use cases for busy-waiting, particularly when the wait
period is so short that you don't want to yield the thread.

-- 
Cheers,
Carlos.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Is there any API that could achieve a busy-wait for a certain duration, e.g. 500us, 1ms and etc?
  2020-09-02 15:37     ` Carlos O'Donell
@ 2020-09-03  1:33       ` 孙世龙 sunshilong
  2020-09-09  8:14         ` Tadeus Prastowo
  0 siblings, 1 reply; 6+ messages in thread
From: 孙世龙 sunshilong @ 2020-09-03  1:33 UTC (permalink / raw)
  To: Carlos O'Donell
  Cc: Mirko Banchi, Dmitry Mikushin,
	孙世龙 sunshilong via Libc-help

Hi,

Thank you for your reply.

Yes, I am asking for a call performing busy wait.

>Resolution will vary depending on the underlying implementation e.g.
>vDSO vs. syscall.
How to verify which kind of underlying implementation is used by
certain API(e.g. clock_gettime) on a specific platform?

Thank you for your attention to this matter.

Best regards
Sunshilong

On Wed, Sep 2, 2020 at 11:38 PM Carlos O'Donell via Libc-help
<libc-help@sourceware.org> wrote:
>
> On 9/2/20 5:09 AM, Mirko Banchi via Libc-help wrote:
> > nanosleep() should suspend the thread, i think he asking for a call
> > performing busy wait.
>
> That is how I interpreted the request also.
>
> We do not have any busy-wait-semantic wait functions with timeout.
>
> The C library need not provide *all* utility functions, but must provide
> enough utility to create those functions for yourself.
>
> You can write such a function yourself using the various clock_* APIs
> to get time, busy wait, and then get the time again.
>
> Resolution will vary depending on the underlying implementation e.g.
> vDSO vs. syscall.
>
> We actually have need for this in pthread_rwlock_tryrdlock to implement
> a randomized exponential back-off to avoid live-locking (not yet done).
>
> There are valid use cases for busy-waiting, particularly when the wait
> period is so short that you don't want to yield the thread.
>
> --
> Cheers,
> Carlos.
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Is there any API that could achieve a busy-wait for a certain duration, e.g. 500us, 1ms and etc?
  2020-09-03  1:33       ` 孙世龙 sunshilong
@ 2020-09-09  8:14         ` Tadeus Prastowo
  0 siblings, 0 replies; 6+ messages in thread
From: Tadeus Prastowo @ 2020-09-09  8:14 UTC (permalink / raw)
  To: 孙世龙 sunshilong
  Cc: Carlos O'Donell, 孙世龙 sunshilong via Libc-help

On Thu, Sep 3, 2020 at 3:33 AM 孙世龙 sunshilong via Libc-help
<libc-help@sourceware.org> wrote:
>>Resolution will vary depending on the underlying implementation e.g.
>>vDSO vs. syscall.

> How to verify which kind of underlying implementation is used by
> certain API(e.g. clock_gettime) on a specific platform?

I think you have asked the question on the other day
(https://sourceware.org/pipermail/libc-help/2020-July/005357.html and
https://sourceware.org/pipermail/libc-help/2020-August/005380.html),
the conclusion of which as far as I understand says that it cannot be
known for sure.

In that case, I think you don't have to perform the verification to
get the resolution.  Instead, you can perform some runtime
determination of the resolution when the application is started to
know the smallest resolution of the busy-wait that can be performed by
the application during runtime.

Hope this helps.

> Best regards
> Sunshilong

-- 
Best regards,
Tadeus

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-09-09  8:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-02  2:36 Is there any API that could achieve a busy-wait for a certain duration, e.g. 500us, 1ms and etc? 孙世龙 sunshilong
2020-09-02  8:42 ` Dmitry Mikushin
2020-09-02  9:09   ` Mirko Banchi
2020-09-02 15:37     ` Carlos O'Donell
2020-09-03  1:33       ` 孙世龙 sunshilong
2020-09-09  8:14         ` Tadeus Prastowo

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 read-only IMAP folder(s) and NNTP newsgroup(s).