Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 29 Dec 2022 21:20:34 -0600
From: "A. Wilcox" <awilfox@...lielinux.org>
To: musl@...ts.openwall.com
Subject: Re: Prefer monotonic clock for DNS lookup timeouts

On Dec 1, 2022, at 9:11 AM, Rich Felker <dalias@...c.org> wrote:
> 
>> http://git.musl-libc.org/cgit/musl/tree/src/network/res_msend.c#n28
>> 
>> Is this a bug or intentional?
> 
> It was intentional, based on a belief that the monotonic clock might
> not be present on all kernels. That seems to be incorrect for the
> range of versions we "support" (>=2.6.0) but some archs unofficially
> work back to mid 2.4.x or earlier with limited functionality (no
> threads). Note for example that clock_gettime has fallback to the
> gettimeofday syscall despite all kernels >=2.6.0 having clock_gettime
> (though was it perhaps gated under some CONFIG_ for "realtime
> features" at some point? this probably calls for some research...)
> 
> Switching to monotonic here has been on my radar for a while. I see
> two decent ways to do it without any possibility of regression:
> 
> 1. Have the above mtime() function fall back to CLOCK_REALTIME on
>   ENOSYS, or
> 
> 2. Go through with integrating a fallback for CLOCK_MONOTONIC I've had
>   in draft for a long time that works on ancient kernels. It works by
>   combining the seconds-resolution time from SYS_sysinfo uptime with
>   the finer-grained-but-wrapping jiffy count from SYS_times too get a
>   monotonic jiffies-resolution uptime.
> 
> The latter is cute/fun but a little bit of work to get right and I'm
> not sure it's sufficiently useful to justify doing it. Option 1 seems
> very reasonable.
> 
> Rich

clock_gettime was added in 2.5.63 and 2.6.0 and was always obj-y.

There is no CONFIG knob that controls it in early 2.6, though I stopped
my search at 2.6.16.

I have written this patch out, but I don’t have a box without monotonic
clock, so I can’t test the validity of the patch.  I will send the patch
to the list for review.

Best,
-A.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.