• libc0.1: clock() has wrong scaling factor on hurd

    From James Cowgill@21:1/5 to Debian Bug Tracking System on Fri Aug 18 16:40:03 2017
    XPost: linux.debian.bugs.dist

    This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --MBX9jjCPr00gB4fAtOarn4q9SvwxXXcku
    Content-Type: multipart/mixed;
    boundary="------------6649FC4CFDE1DCE53E020711"
    Content-Language: en-US

    This is a multi-part message in MIME format. --------------6649FC4CFDE1DCE53E020711
    Content-Type: text/plain; charset=utf-8
    Content-Transfer-Encoding: quoted-printable

    Package: libc0.1
    Version: 2.24-14
    Severity: normal
    Control: affects -1 src:ffmpeg

    Hi,

    The clock() function on hurd has the wrong scaling factor. It generates
    only 100 clock ticks per second, even though CLOCKS_PER_SEC is 1000000.
    I has written a small testcase (attached) which illustrates the difference:

    amd64:
    CLOCKS_PER_SEC = 1000000
    clock() = 444
    sleeping for 1 second...
    clock() = 1000464

    hurd-i386:
    CLOCKS_PER_SEC = 1000000
    clock() = 0
    sleeping for 1 second...
    clock() = 100

    I raised this issue on debian-hurd here: https://lists.debian.org/debian-hurd/2017/07/msg00054.html

    While I appreciate that hurd's clock may not be able to be as precise as
    on Linux, but it should still return values which corresponds in some
    way to CLOCKS_PER_SEC.

    As far as I can tell, this bug is caused by the Debian patch: debian/patches/hurd-i386/unsubmitted-clock_t_centiseconds.diff

    The patch header contains a description about applications failing with
    high precision. IMHO those applications are broken. Their bugs should
    not be worked around in libc and that patch should be dropped.

    This was originally found after debugging ffmpeg. I believe the FTBFS on
    hurd is caused by this bug.

    Thanks,
    James

    --------------6649FC4CFDE1DCE53E020711
    Content-Type: text/x-csrc;
    name="clock-test.c"
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: attachment;
    filename="clock-test.c"

    #include <time.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <unistd.h>

    static void busy_wait(int seconds)
    {
    struct timespec start, current;
    if (clock_gettime(CLOCK_MONOTONIC, &start) != 0)
    abort();

    for (;;)
    {
    if (clock_gettime(CLOCK_MONOTONIC, &current) != 0)
    abort();

    if (current.tv_sec - start.tv_sec > seconds ||
    (current.tv_sec - start.tv_sec == seconds &&
    current.tv_nsec >= start.tv_nsec))
    break;
    }
    }

    int main(void)
    {
    printf("CLOCKS_PER_SEC = %ld\n", CLOCKS_PER_SEC);
    printf("clock() = %ld\n", clock());
    printf("sleeping for 1 second...\n");
    busy_wait(1);
    printf("clock() = %ld\n", clock());
    return 0;
    }

    --------------6649FC4CFDE1DCE53E020711--

    --MBX9jjCPr00gB4fAtOarn4q9SvwxXXcku--

    -----BEGIN PGP SIGNATURE-----

    iQIzBAEBCgAdFiEE+Ixt5DaZ6POztUwQx/FnbeotAe8FAlmW7FYACgkQx/Fnbeot Ae+K7Q//azg5dpA38LgDueZQPbGMePod/OOVz3llL0qC34kpmChJXbSx56Xc1Luk tkPjwvuTmDMFIAUJU9SiNOCoHdhsHt0YNAo72H3Qj6BgBsxXV7T3oSTKYfNF2Cw7 3MpuzIO3o3pVlhwFUsXAgqrkxHRhI4zJYwKEmZyM/lABdJoBWEHFCjbXZHVHoZV9 8JgZIZTHveEOfkyJcD+K9sJVURlVJsAduqK9CafH6BrotxNikLI1f6htIE8PZIcS HeUIHKZmek0eEYedESgPmbJ1sgMN/xe+iV4G8bb+ImsnXW/5xIJZQsXdQzmoNOzY Zmw0+6Gp1MdJYCyeIcvkT05RN5kBi5nvEUdwCxzASscv3/ZIrQAHF1caRYgeiaHa i5Tb2tyquEnpI9Wncsmmnkb9W8HGmroeATSGJgZvg4RUOOBIIGXMR5uJolQXqZlz SJR1m9ceiLCGqh6aHbyJcd15RjYSBu+QF1l8De2EoOXFK/4ojzTEtBoecfinvShD MxXMqpSwT+fUE++EcZeZpipq0pEybzsgcSSZpG+Xj9f4PqrH5oicHJZpARlsM57o vufeXfB3993LTMlS5PCefqSJ51Vp7YCNATi1JKBus+MWTnymp1K/JzVIcgzMxUvx QmXPLmjkmpLTyIoyxjJJSSBxMWVOUD+41ZLEApbpO8ptPI92w3A=
    =qqES
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)