From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2256 invoked by alias); 7 Jan 2015 10:23:22 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 2244 invoked by uid 89); 7 Jan 2015 10:23:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 07 Jan 2015 10:23:13 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id A9A3711653D; Wed, 7 Jan 2015 05:23:11 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id AKhSpVjSVE+1; Wed, 7 Jan 2015 05:23:11 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 86D6E1164FD; Wed, 7 Jan 2015 05:23:11 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 82E9A91A7D; Wed, 7 Jan 2015 05:23:11 -0500 (EST) Date: Wed, 07 Jan 2015 10:23:00 -0000 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: "Douglas B. Rupp" Subject: [Ada] Implement RT_Resolution properly Message-ID: <20150107102311.GA4891@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Kj7319i9nmIyA2yE" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2015-01/txt/msg00302.txt.bz2 --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1098 Previously RT_Resolution was returning a hard coded dummy value. With this change we now use the relevant system call to compute the clock resolution. Tested on x86_64-pc-linux-gnu, committed on trunk 2015-01-07 Doug Rupp * s-osinte-mingw.ads (LARGE_INTEGR): New subtype. (QueryPerformanceFrequency): New imported procedure. * s-taprop-mingw.adb (RT_Resolution): Call above and return resolution vice a hardcoded value. * s-taprop-solaris.adb (RT_Resolution): Call clock_getres and return resolution vice a hardcoded value. * s-linux-android.ads (clockid_t): New subtype. * s-osinte-aix.ads (clock_getres): New imported subprogram. * s-osinte-android.ads (clock_getres): Likewise. * s-osinte-freebsd.ads (clock_getres): Likewise. * s-osinte-solaris-posix.ads (clock_getres): Likewise. * s-osinte-darwin.ads (clock_getres): New subprogram. * s-osinte-darwin.adb (clock_getres): New subprogram. * thread.c (__gnat_clock_get_res) [__APPLE__]: New function. * s-taprop-posix.adb (RT_Resolution): Call clock_getres to calculate resolution vice hard coded value. --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=difs Content-length: 7429 Index: s-linux-android.ads =================================================================== --- s-linux-android.ads (revision 219191) +++ s-linux-android.ads (working copy) @@ -47,6 +47,7 @@ subtype long is Interfaces.C.long; subtype suseconds_t is Interfaces.C.long; subtype time_t is Interfaces.C.long; + subtype clockid_t is Interfaces.C.int; type timespec is record tv_sec : time_t; Index: s-osinte-aix.ads =================================================================== --- s-osinte-aix.ads (revision 219191) +++ s-osinte-aix.ads (working copy) @@ -206,6 +206,11 @@ tp : access timespec) return int; pragma Import (C, clock_gettime, "clock_gettime"); + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int; + pragma Import (C, clock_getres, "clock_getres"); + function To_Duration (TS : timespec) return Duration; pragma Inline (To_Duration); Index: s-osinte-android.ads =================================================================== --- s-osinte-android.ads (revision 219191) +++ s-osinte-android.ads (working copy) @@ -211,6 +211,11 @@ (clock_id : clockid_t; tp : access timespec) return int; + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int; + pragma Import (C, clock_getres, "clock_getres"); + function To_Duration (TS : timespec) return Duration; pragma Inline (To_Duration); Index: s-osinte-darwin.adb =================================================================== --- s-osinte-darwin.adb (revision 219191) +++ s-osinte-darwin.adb (working copy) @@ -129,6 +129,36 @@ return Result; end clock_gettime; + ------------------ + -- clock_getres -- + ------------------ + + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int + is + pragma Unreferenced (clock_id); + + -- Darwin Threads don't have clock_getres. + + Nano : constant := 10**9; + nsec : int := 0; + Result : int := -1; + + function clock_get_res return int; + pragma Import (C, clock_get_res, "__gnat_clock_get_res"); + + begin + nsec := clock_get_res; + res.all := To_Timespec (Duration (0.0) + Duration (nsec) / Nano); + + if nsec > 0 then + Result := 0; + end if; + + return Result; + end clock_getres; + ----------------- -- sched_yield -- ----------------- Index: s-osinte-darwin.ads =================================================================== --- s-osinte-darwin.ads (revision 219191) +++ s-osinte-darwin.ads (working copy) @@ -189,6 +189,10 @@ (clock_id : clockid_t; tp : access timespec) return int; + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int; + function To_Duration (TS : timespec) return Duration; pragma Inline (To_Duration); Index: s-osinte-freebsd.ads =================================================================== --- s-osinte-freebsd.ads (revision 219191) +++ s-osinte-freebsd.ads (working copy) @@ -202,6 +202,11 @@ type clockid_t is new int; + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int; + pragma Import (C, clock_getres, "clock_getres"); + function clock_gettime (clock_id : clockid_t; tp : access timespec) Index: s-osinte-mingw.ads =================================================================== --- s-osinte-mingw.ads (revision 219191) +++ s-osinte-mingw.ads (working copy) @@ -53,6 +53,8 @@ subtype int is Interfaces.C.int; subtype long is Interfaces.C.long; + subtype LARGE_INTEGER is System.Win32.LARGE_INTEGER; + ------------------- -- General Types -- ------------------- @@ -104,6 +106,18 @@ procedure kill (sig : Signal); pragma Import (C, kill, "raise"); + ------------ + -- Clock -- + ------------ + + procedure QueryPerformanceFrequency + (lpPerformanceFreq : access LARGE_INTEGER); + pragma Import + (Stdcall, QueryPerformanceFrequency, "QueryPerformanceFrequency"); + + -- According to the spec, on XP and later than function cannot fail, + -- so we ignore the return value and import it as a procedure. + ------------- -- Threads -- ------------- Index: s-osinte-solaris-posix.ads =================================================================== --- s-osinte-solaris-posix.ads (revision 219191) +++ s-osinte-solaris-posix.ads (working copy) @@ -189,6 +189,11 @@ type clockid_t is new int; + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int; + pragma Import (C, clock_getres, "clock_getres"); + function clock_gettime (clock_id : clockid_t; tp : access timespec) return int; Index: s-taprop-mingw.adb =================================================================== --- s-taprop-mingw.adb (revision 219191) +++ s-taprop-mingw.adb (working copy) @@ -1076,8 +1076,10 @@ ------------------- function RT_Resolution return Duration is + Ticks_Per_Second : aliased LARGE_INTEGER; begin - return 0.000_001; -- 1 micro-second + QueryPerformanceFrequency (Ticks_Per_Second'Access); + return Duration (1.0 / Ticks_Per_Second); end RT_Resolution; ---------------- Index: s-taprop-posix.adb =================================================================== --- s-taprop-posix.adb (revision 219191) +++ s-taprop-posix.adb (working copy) @@ -743,8 +743,13 @@ ------------------- function RT_Resolution return Duration is + TS : aliased timespec; + Result : Interfaces.C.int; begin - return 10#1.0#E-6; + Result := clock_getres (OSC.CLOCK_REALTIME, TS'Unchecked_Access); + pragma Assert (Result = 0); + + return To_Duration (TS); end RT_Resolution; ------------ Index: s-taprop-solaris.adb =================================================================== --- s-taprop-solaris.adb (revision 219191) +++ s-taprop-solaris.adb (working copy) @@ -785,8 +785,13 @@ ------------------- function RT_Resolution return Duration is + TS : aliased timespec; + Result : Interfaces.C.int; begin - return 10#1.0#E-6; + Result := clock_getres (OSC.CLOCK_REALTIME, TS'Unchecked_Access); + pragma Assert (Result = 0); + + return To_Duration (TS); end RT_Resolution; ----------- Index: thread.c =================================================================== --- thread.c (revision 219191) +++ thread.c (working copy) @@ -54,3 +54,35 @@ } #endif + +#if defined (__APPLE__) +#include +#include +#endif + +/* Return the clock ticks per nanosecond for Posix systems lacking the + Posix extension function clock_getres, or else 0 nsecs on error. */ + +int +__gnat_clock_get_res (void) +{ +#if defined (__APPLE__) + clock_serv_t clock_port; + mach_msg_type_number_t count; + int nsecs; + int result; + + count = 1; + result = host_get_clock_service + (mach_host_self (), SYSTEM_CLOCK, &clock_port); + + if (result == KERN_SUCCESS) + result = clock_get_attributes (clock_port, CLOCK_GET_TIME_RES, + (clock_attr_t) &nsecs, &count); + + if (result == KERN_SUCCESS) + return nsecs; +#endif + + return 0; +} --Kj7319i9nmIyA2yE--