mailing list of musl libc
 help / color / mirror / code / Atom feed
* src/thread/__timedwait.c: Clock type
@ 2019-05-13  1:36 zhaohang (F)
  2019-05-13 12:41 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: zhaohang (F) @ 2019-05-13  1:36 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 394 bytes --]

In the function _timedwait_cp, 'clk' indicates the type of clock used, CLOCK_REALTIME or CLOCK_MONOTONIC.

when we call __syscall_cp in this function, the fifth parameter 'top' is calculated based on the clock type.

However, the third parameter is not set according to the clock type. CLOCK_MONOTONIC is used by default.

Is this a bug? Or other considerations?

Thanks,

Zhao Hang

[-- Attachment #2: Type: text/html, Size: 3010 bytes --]

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

* Re: src/thread/__timedwait.c: Clock type
  2019-05-13  1:36 src/thread/__timedwait.c: Clock type zhaohang (F)
@ 2019-05-13 12:41 ` Rich Felker
  2019-05-15 12:27   ` 答复: [musl] " zhaohang (F)
  0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2019-05-13 12:41 UTC (permalink / raw)
  To: musl

On Mon, May 13, 2019 at 01:36:15AM +0000, zhaohang (F) wrote:
> In the function _timedwait_cp, 'clk' indicates the type of clock used, CLOCK_REALTIME or CLOCK_MONOTONIC.
> 
> when we call __syscall_cp in this function, the fifth parameter 'top' is calculated based on the clock type.
> 
> However, the third parameter is not set according to the clock type. CLOCK_MONOTONIC is used by default.
> 
> Is this a bug? Or other considerations?

The timeout argument to the FUTEX_WAIT operation is always relative,
and does not support choosing a clock. To support the more exotic
clocks (e.g. cputime for a given thread) it would need explicit
support here, but for just realtime and monotonic, it suffices to
compute the relative sleep based on the argument and the current time
in the given clock.

The behavior is of course different under non-continuous changes to
the clock. This is a fundamental limitation of the FUTEX_WAIT
operation; using the FUTEX_WAIT_BITSET operation if available would
avoid this, but seems less likely to be able to support arbitrary
other clocks in the future, and the behavior distinction only appears
when you do something fundamentally broken (setting the clock wrong)
and half the time it's worse rather than better...

Rich


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

* 答复: [musl] src/thread/__timedwait.c: Clock type
  2019-05-13 12:41 ` Rich Felker
@ 2019-05-15 12:27   ` zhaohang (F)
  0 siblings, 0 replies; 3+ messages in thread
From: zhaohang (F) @ 2019-05-15 12:27 UTC (permalink / raw)
  To: musl

Thank you Rich for the analysis.

Bests,
Zhao Hang

-----邮件原件-----
发件人: Rich Felker [mailto:dalias@aerifal.cx] 代表 Rich Felker
发送时间: 2019年5月13日 20:41
收件人: musl@lists.openwall.com
主题: Re: [musl] src/thread/__timedwait.c: Clock type

On Mon, May 13, 2019 at 01:36:15AM +0000, zhaohang (F) wrote:
> In the function _timedwait_cp, 'clk' indicates the type of clock used, CLOCK_REALTIME or CLOCK_MONOTONIC.
> 
> when we call __syscall_cp in this function, the fifth parameter 'top' is calculated based on the clock type.
> 
> However, the third parameter is not set according to the clock type. CLOCK_MONOTONIC is used by default.
> 
> Is this a bug? Or other considerations?

The timeout argument to the FUTEX_WAIT operation is always relative, and does not support choosing a clock. To support the more exotic clocks (e.g. cputime for a given thread) it would need explicit support here, but for just realtime and monotonic, it suffices to compute the relative sleep based on the argument and the current time in the given clock.

The behavior is of course different under non-continuous changes to the clock. This is a fundamental limitation of the FUTEX_WAIT operation; using the FUTEX_WAIT_BITSET operation if available would avoid this, but seems less likely to be able to support arbitrary other clocks in the future, and the behavior distinction only appears when you do something fundamentally broken (setting the clock wrong) and half the time it's worse rather than better...

Rich

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

end of thread, other threads:[~2019-05-15 12:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-13  1:36 src/thread/__timedwait.c: Clock type zhaohang (F)
2019-05-13 12:41 ` Rich Felker
2019-05-15 12:27   ` 答复: [musl] " zhaohang (F)

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).