This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, fortran] PR 56919 SYSTEM_CLOCK on Windows


On Sat, Apr 13, 2013 at 1:02 AM, Tobias Burnus <burnus@net-b.de> wrote:
> Janne Blomqvist wrote:
>>
>> the attached patch implements the SYSTEM_CLOCK intrinsics on the MinGW
>> and Cygwin targets using the GetTickCount/GetTickCount64 functions.
>> These should be quite robust monotonic clocks and AFAICS are the best
>> we can do on Windows.
>
>
> I think using QueryPerformanceCounter is the better approach. It is
> supported since Windows 2000 and recommended as high-performance counter:
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms644900%28v=vs.85%29.aspx

I didn't want to use QPC, as it can apparently be unreliable, see e.g.
the PEP 418 I linked to previously. But it seems that the worst issues
are caused by old and somewhat rare hardware, or have been fixed in
more recent Windows service packs, so maybe it's not worth worrying
about.

> I really dislike GetTickCount, which overflows after 50 days - that's not
> what you want to have. And GetTickCount64 only exists since Vista/2008. By
> contrast, QueryPerformanceCounter should allow for finer resolution and it
> is already available since Windows 2000.

Attached is an updated patch which uses GetTickCount for
system_clock_4; this should be fine as system_clock_4 wraps around in
~25 days anyways. For system_clock_8 it uses
QueryPerformance{Counter,Frequency}.

> Regarding clock_gettime: I really think we should check check
> _POSIX_MONOTONIC_CLOCK as well. Currently,  only MONOTONIC_CLOCK is checked,
> which is always available (on POSIX conform systems).
>
> See GLIBCXX_ENABLE_LIBSTDCXX_TIME in libstdc++-v3/acinclude.m4 - and in
> particular ac_has_clock_monotonic.

The patch also adds an additional check for _POSIX_MONOTONIC_CLOCK.

Ok for trunk?

Frontend ChangeLog:

2013-04-13  Janne Blomqvist  <jb@gcc.gnu.org>

    PR fortran/56919
    * intrinsics.texi (SYSTEM_CLOCK): Update documentation.

libgfortran ChangeLog:

2013-04-13  Janne Blomqvist  <jb@gcc.gnu.org>

    PR fortran/56919
    * intrinsics/time_1.h: Check __CYGWIN__ in addition to
    __MINGW32__.
    * intrinsics/system_clock.c (GF_CLOCK_MONOTONIC): Check
    _POSIX_MONOTONIC_CLOCK as well.
    (system_clock_4): Use GetTickCount on Windows.
    (system_clock_8): Use QueryPerformanceCounter and
    QueryPerformanceCounterFrequency on Windows.


--
Janne Blomqvist

Attachment: sysclockwin.2.diff
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]