comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Any leap year issues caused by Ada yesterday?
Date: Tue, 06 Mar 2012 17:59:04 +0000
Date: 2012-03-06T17:59:04+00:00	[thread overview]
Message-ID: <m2wr6xhaqf.fsf@pushface.org> (raw)
In-Reply-To: z3eblji2o1wx.1ts993li80h61$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On Tue, 06 Mar 2012 16:46:35 +0000, Simon Wright wrote:
>
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>> 
>>> Under VxWorks you can read the TSC without assembly, there is a library
>>> function for that (pentiumTscGet64).
>>>
>>>    type Timestamp is new Unsigned_64;
>>>    procedure pentiumTscGet64 (Clock : out Timestamp);
>>>    pragma Import (C, pentiumTscGet64, "pentiumTscGet64");
>>>
>>> should do the work.
>> 
>> Not sure if there was an equivalent for PPC.
>
> AFAIK, PPC has a high resolution real time counter, which is better
> designed than Intel's TSC.

Yes, the Time Base.

Ours was a 32-bit implementation, so you get to read the lower and upper
halves of the timebase separately, which would cause problems at
rollover. So read the TB using an internal Clock like this

   function Clock return Time is

      type Half is (High, Low);
      type High_Low is array (Half) of Interfaces.Unsigned_32;

      Upper, Lower, Upper_Again : Interfaces.Unsigned_32;

      function To_Time is new Ada.Unchecked_Conversion (High_Low, Time);

      use type Interfaces.Unsigned_32;

   begin

      loop
         System.Machine_Code.Asm
           ("mftbu %0" & ASCII.LF & ASCII.HT &
              "mftb %1" & ASCII.LF & ASCII.HT &
              "mftbu %2",
            Outputs =>
              (Interfaces.Unsigned_32'Asm_Output ("=r", Upper),
               Interfaces.Unsigned_32'Asm_Output ("=r", Lower),
               Interfaces.Unsigned_32'Asm_Output ("=r", Upper_Again)),
            Volatile => True);
         exit when Upper_Again = Upper;
      end loop;

      return To_Time ((High => Upper, Low => Lower));

   end Clock;

The timebase ran off the same crystal as the decrementer, so all were
internally sync'd. Internally, our synchronised time was
(Ada.Calendar.Clock (at last clock interrupt, of course) + high-res time
since last clock interrupt). We added the external sync offset on
sending a time off-board, and subtracted it on receiving one.

(I've never used VxWorks on x86).



  reply	other threads:[~2012-03-06 17:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-01 13:06 Any leap year issues caused by Ada yesterday? Georg Bauhaus
2012-03-05 11:07 ` tonyg
2012-03-05 15:59   ` Shark8
2012-03-05 18:03     ` Dmitry A. Kazakov
2012-03-05 18:30       ` Simon Wright
2012-03-05 20:17         ` Dmitry A. Kazakov
2012-03-05 20:56           ` Simon Wright
2012-03-06  8:47             ` Dmitry A. Kazakov
2012-03-06  9:20               ` Simon Wright
2012-03-06 10:07                 ` Dmitry A. Kazakov
2012-03-06 10:51                   ` Georg Bauhaus
2012-03-06 11:16                     ` Dmitry A. Kazakov
2012-03-06 16:46                   ` Simon Wright
2012-03-06 17:37                     ` Dmitry A. Kazakov
2012-03-06 17:59                       ` Simon Wright [this message]
2012-03-06 19:18                         ` Dmitry A. Kazakov
2012-03-06 20:22                           ` Simon Wright
2012-03-06 19:08                       ` Shark8
2012-03-06 19:40                         ` Dmitry A. Kazakov
2012-03-06 21:00                       ` tmoran
2012-03-06 21:37                         ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox