This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: pthread_condattr_setclock() and CLOCK_BOOTTIME
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: Hannu Mallat <hannu dot mallat at jolla dot com>, "libc-help at sourceware dot org" <libc-help at sourceware dot org>
- Date: Thu, 04 Sep 2014 10:04:18 -0400
- Subject: Re: pthread_condattr_setclock() and CLOCK_BOOTTIME
- Authentication-results: sourceware.org; auth=none
- References: <C916EDABDC17FC45A9CF64E949622B45131FB7 at ord2mbx12c dot mex05 dot mlsrvr dot com>
On 09/04/2014 06:14 AM, Hannu Mallat wrote:
> Hi all,
>
> I'm wondering if there would be any ill effects from allowing more
> clock IDs in pthread_condattr_setclock()?
>
> I was investigating a problem of glib2 timeouts not triggering when
> the platform I'm working on (Jolla, a Linux-based smartphone) is
> suspended. This was because glib2 is using CLOCK_MONOTONIC as its time
> source (in g_get_time_monotonic()), and CLOCK_MONOTONIC does not
> increment during suspend; neither does it jump forward when the device
> wakes up. So a timer that would trigger in T seconds at the time of
> entering suspend is still the same when the device wakes up, no matter
> how long it has been suspended. Timed activity with outside entities,
> e.g., DHCP lease renewal, obviously suffers from this.
>
> Using CLOCK_BOOTTIME as the glib2 time source instead solves the
> problem of clock not advancing after waking up, and I can schedule a
> wakeup at a suitable time by platform-specific means; but glib2 also
> makes calls to pthread_condattr_setclock() and currently glibc only
> allows the clock id to be CLOCK_MONOTONIC or CLOCK_REALTIME.
>
> I have made a patch that allows also CLOCK_BOOTTIME to be used (the
> size of the bit field used to store the clock id is widened to 3 bits
> to fit CLOCK_BOOTTIME id) and on the face of it, it works nicely.
>
> However I'd like to get more feedback whether a change like this could
> break something I'm not seeing at the moment. Or are there some other
> arguments against the change?
>
> We're using glibc 2.15 at the moment.
Architecturally speaking this is a good idea. I condone supporting
more of the underlying clocks as long as they make sense and sensible
things happen for the user while using those clocks.
Technically though you must be *very* careful not to break ABI, and
since I haven't seen your patch I don't know where you get the extra
3 bits from. The structure itself must never change size. If you happen
to have padding then you can use that, but I haven't verified this.
Please post to libc-alpha.
Please be aware we are in freeze for 2.20 release, but will reopen
for 2.21 shortly.
Cheers,
Carlos.