Ada Conformity Assessment Authority      Home Conformity Assessment   Test Suite ARGAda Standard
Annotated Ada Reference Manual (Ada 2022)Legal Information
Contents   Index   References   Search   Previous   Next 

D.14 Execution Time

{AI95-00307-01} {AI05-0299-1} This subclause describes a language-defined package to measure execution time. 

Static Semantics

{AI95-00307-01} The following language-defined library package exists: 
{AI12-0241-1} {AI12-0302-1} with Ada.Task_Identification;
with Ada.Real_Time; use Ada.Real_Time;
package Ada.Execution_Time
   with Nonblocking, Global => in out synchronized
   type CPU_Time is private;
   CPU_Time_First : constant CPU_Time;
   CPU_Time_Last  : constant CPU_Time;
   CPU_Time_Unit  : constant := implementation-defined-real-number;
   CPU_Tick : constant Time_Span;
   function Clock
     (T : Ada.Task_Identification.Task_Id
          := Ada.Task_Identification.Current_Task)
     return CPU_Time;
   function "+"  (Left : CPU_Time; Right : Time_Span) return CPU_Time;
   function "+"  (Left : Time_Span; Right : CPU_Time) return CPU_Time;
   function "-"  (Left : CPU_Time; Right : Time_Span) return CPU_Time;
   function "-"  (Left : CPU_Time; Right : CPU_Time)  return Time_Span;
   function "<"  (Left, Right : CPU_Time) return Boolean;
   function "<=" (Left, Right : CPU_Time) return Boolean;
   function ">"  (Left, Right : CPU_Time) return Boolean;
   function ">=" (Left, Right : CPU_Time) return Boolean;
   procedure Split
     (T : in CPU_Time; SC : out Seconds_Count; TS : out Time_Span);
   function Time_Of (SC : Seconds_Count;
                     TS : Time_Span := Time_Span_Zero) return CPU_Time;
{AI05-0170-1}    Interrupt_Clocks_Supported : constant Boolean := implementation-defined;
{AI05-0170-1}    Separate_Interrupt_Clocks_Supported : constant Boolean :=
{AI05-0170-1}    function Clock_For_Interrupts return CPU_Time;
   ... -- not specified by the language
end Ada.Execution_Time;
{AI95-00307-01} {AI05-0170-1} {AI05-0269-1} The execution time or CPU time of a given task is defined as the time spent by the system executing that task, including the time spent executing run-time or system services on its behalf. The mechanism used to measure execution time is implementation defined. The Boolean constant Interrupt_Clocks_Supported is set to True if the implementation separately accounts for the execution time of interrupt handlers. If it is set to False it is implementation defined which task, if any, is charged the execution time that is consumed by interrupt handlers. The Boolean constant Separate_Interrupt_Clocks_Supported is set to True if the implementation separately accounts for the execution time of individual interrupt handlers (see D.14.3). 
Discussion: The implementation-defined properties above and of the values declared in the package are repeated in Documentation Requirements, so we don't mark them as implementation-defined.
{AI95-00307-01} The type CPU_Time represents the execution time of a task. The set of values of this type corresponds one-to-one with an implementation-defined range of mathematical integers.
{AI95-00307-01} The CPU_Time value I represents the half-open execution-time interval that starts with I*CPU_Time_Unit and is limited by (I+1)*CPU_Time_Unit, where CPU_Time_Unit is an implementation-defined real number. For each task, the execution time value is set to zero at the creation of the task.
Ramification: Since it is implementation-defined which task is charged execution time for system services, the execution time value may become nonzero even before the start of the activation of the task. 
{AI95-00307-01} CPU_Time_First and CPU_Time_Last are the smallest and largest values of the CPU_Time type, respectively. 
  {AI05-0170-1} The execution time value for the function Clock_For_Interrupts is initialized to zero.

Dynamic Semantics

{AI95-00307-01} CPU_Time_Unit is the smallest amount of execution time representable by the CPU_Time type; it is expressed in seconds. A CPU clock tick is an execution time interval during which the clock value (as observed by calling the Clock function) remains constant. CPU_Tick is the average length of such intervals.
{AI95-00307-01} The effects of the operators on CPU_Time and Time_Span are as for the operators defined for integer types.
{AI95-00307-01} The function Clock returns the current execution time of the task identified by T; Tasking_Error is raised if that task has terminated; Program_Error is raised if the value of T is Task_Identification.Null_Task_Id.
{AI95-00307-01} The effects of the Split and Time_Of operations are defined as follows, treating values of type CPU_Time, Time_Span, and Seconds_Count as mathematical integers. The effect of Split (T, SC, TS) is to set SC and TS to values such that T*CPU_Time_Unit = SC*1.0 + TS*CPU_Time_Unit, and 0.0 <= TS*CPU_Time_Unit < 1.0. The value returned by Time_Of(SC,TS) is the execution-time value T such that T*CPU_Time_Unit=SC*1.0 + TS*CPU_Time_Unit.
  {AI05-0170-1} The function Clock_For_Interrupts returns the total cumulative time spent executing within all interrupt handlers. This time is not allocated to any task execution time clock. If Interrupt_Clocks_Supported is set to False the function raises Program_Error.

Erroneous Execution

{AI95-00307-01} For a call of Clock, if the task identified by T no longer exists, the execution of the program is erroneous. 

Implementation Requirements

{AI95-00307-01} The range of CPU_Time values shall be sufficient to uniquely represent the range of execution times from the task start-up to 50 years of execution time later. CPU_Tick shall be no greater than 1 millisecond. 

Documentation Requirements

{AI95-00307-01} The implementation shall document the values of CPU_Time_First, CPU_Time_Last, CPU_Time_Unit, and CPU_Tick. 
Documentation Requirement: The values of CPU_Time_First, CPU_Time_Last, CPU_Time_Unit, and CPU_Tick of package Execution_Time.
{AI95-00307-01} The implementation shall document the properties of the underlying mechanism used to measure execution times, such as the range of values supported and any relevant aspects of the underlying hardware or operating system facilities used. 
Documentation Requirement: The properties of the mechanism used to implement package Execution_Time, including the values of the constants defined in the package.


{AI95-00307-01} The implementation shall document the following metrics:
An upper bound on the execution-time duration of a clock tick. This is a value D such that if t1 and t2 are any execution times of a given task such that t1 < t2 and Clockt1 = Clockt2 then t2 – t1 <= D.
An upper bound on the size of a clock jump. A clock jump is the difference between two successive distinct values of an execution-time clock (as observed by calling the Clock function with the same Task_Id).
An upper bound on the execution time of a call to the Clock function, in processor clock cycles.
Upper bounds on the execution times of the operators of the type CPU_Time, in processor clock cycles. 
Documentation Requirement: The metrics for execution time.

Implementation Permissions

{AI95-00307-01} {AI12-0444-1} Implementations targeted to machines with word size smaller than 32 bits may omit need not support for the full range and granularity of the CPU_Time type.

Implementation Advice

{AI95-00307-01} When appropriate, implementations should provide configuration mechanisms to change the value of CPU_Tick. 
Implementation Advice: When appropriate, implementations should provide configuration mechanisms to change the value of Execution_Time.CPU_Tick.

Extensions to Ada 95

{AI95-00307-01} The package Execution_Time is new. 

Incompatibilities With Ada 2005

{AI05-0170-1} Function Clock_For_Interrupts, and constants Interrupt_Clocks_Supported and Separate_Interrupt_Clocks_Supported are added to Execution_Time. If Execution_Time is referenced in a use_clause, and an entity E with a defining_identifier of one of the added entities is defined in a package that is also referenced in a use_clause, the entity E may no longer be use-visible, resulting in errors. This should be rare and is easily fixed if it does occur. 

Wording Changes from Ada 2005

{AI05-0170-1} If Interrupt_Clocks_Supported is True, it is now possible to determine the execution time of interrupt handlers. This is not an inconsistency, as not charging any task for such time was a legitimate implementation for Ada 2005. 

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe