Ignore:
Timestamp:
Apr 28, 2021, 4:56:50 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8d66610
Parents:
feacef9 (diff), b7fd2db6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/clock.hfa

    rfeacef9 r5407cdc  
    1010// Created On       : Thu Apr 12 14:36:06 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan  6 12:49:58 2020
    13 // Update Count     : 9
     12// Last Modified On : Sun Apr 18 08:12:16 2021
     13// Update Count     : 28
    1414//
    1515
     
    2727//######################### Clock #########################
    2828
    29 struct Clock {                                                                                  // private
    30         Duration offset;                                                                        // for virtual clock: contains offset from real-time
     29struct Clock {                                                                                  // virtual clock
     30        // private
     31        Duration offset;                                                                        // offset from computer real-time
    3132};
    3233
    3334static inline {
    34         void resetClock( Clock & clk, Duration adj ) with( clk ) {
     35        void reset( Clock & clk, Duration adj ) with( clk ) { // change offset
    3536                offset = adj + __timezone`s;                                    // timezone (global) is (UTC - local time) in seconds
    36         } // resetClock
     37        } // reset
    3738
    38         void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); }
     39        void ?{}( Clock & clk ) { reset( clk, (Duration){ 0 } ); } // create no offset
     40        void ?{}( Clock & clk, Duration adj ) { reset( clk, adj ); } // create with offset
    3941
    40         Duration getResNsec() {
     42        // System-wide clock that measures real, i.e., wall-clock) time. This clock is affected by discontinuous jumps in
     43        // the system time. For example, manual changes of the clock, and incremental adjustments performed by adjtime(3)
     44        // and NTP (daylight saving (Fall back).
     45        Duration resolutionHi() {                                                       // clock resolution in nanoseconds (fine)
    4146                struct timespec res;
    4247                clock_getres( CLOCK_REALTIME, &res );
    4348                return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
    44         } // getRes
     49        } // resolutionHi
    4550
    46         Duration getRes() {
     51        Duration resolution() {                                                         // clock resolution without nanoseconds (coarse)
    4752                struct timespec res;
    4853                clock_getres( CLOCK_REALTIME_COARSE, &res );
    4954                return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
    50         } // getRes
     55        } // resolution
    5156
    52         Time getTimeNsec() {                                                            // with nanoseconds
     57        Time timeHiRes() {                                                                      // real time with nanoseconds
    5358                timespec curr;
    5459                clock_gettime( CLOCK_REALTIME, &curr );
    5560                return (Time){ curr };
    56         } // getTimeNsec
     61        } // timeHiRes
    5762
    58         Time getTime() {                                                                        // without nanoseconds
     63        Time time() {                                                                           // real time without nanoseconds
    5964                timespec curr;
    6065                clock_gettime( CLOCK_REALTIME_COARSE, &curr );
    6166                curr.tv_nsec = 0;
    6267                return (Time){ curr };
    63         } // getTime
     68        } // time
    6469
    65         Time getTime( Clock & clk ) with( clk ) {
    66                 return getTime() + offset;
    67         } // getTime
     70        Time time( Clock & clk ) with( clk ) {                          // real time for given clock
     71                return time() + offset;
     72        } // time
    6873
    6974        Time ?()( Clock & clk ) with( clk ) {                           // alternative syntax
    70                 return getTime() + offset;
    71         } // getTime
     75                return time() + offset;
     76        } // ?()
    7277
    73         timeval getTime( Clock & clk ) {
     78        timeval time( Clock & clk ) {                                           // convert to C time format
    7479                return (timeval){ clk() };
    75         } // getTime
     80        } // time
    7681
    77         tm getTime( Clock & clk ) with( clk ) {
     82        tm time( Clock & clk ) with( clk ) {
    7883                tm ret;
    79                 localtime_r( getTime( clk ).tv_sec, &ret );
     84                localtime_r( time( clk ).tv_sec, &ret );
    8085                return ret;
    81         } // getTime
     86        } // time
    8287
    83         Time getCPUTime() {
     88        // CFA processor CPU-time watch that ticks when the processor (kernel thread) is running. This watch is affected by
     89        // discontinuous jumps when the OS is not running the kernal thread. A duration is returned because the value is
     90        // relative and cannot be converted to real-time (wall-clock) time.
     91        Duration processor() {                                                          // non-monotonic duration of kernel thread
    8492                timespec ts;
    8593                clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts );
    86                 return (Time){ ts };
    87     } // getCPUTime
     94                return (Duration){ ts };
     95        } // processor
     96
     97        // Program CPU-time watch measures CPU time consumed by all processors (kernel threads) in the UNIX process.  This
     98        // watch is affected by discontinuous jumps when the OS is not running the kernel threads. A duration is returned
     99        // because the value is relative and cannot be converted to real-time (wall-clock) time.
     100        Duration program() {                                                            // non-monotonic duration of program CPU
     101                timespec ts;
     102                clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts );
     103                return (Duration){ ts };
     104        } // program
     105
     106        // Monotonic duration from machine boot and including system suspension. This watch is unaffected by discontinuous
     107        // jumps resulting from manual changes of the clock, and incremental adjustments performed by adjtime(3) and NTP
     108        // (Fall back). A duration is returned because the value is relative and cannot be converted to real-time
     109        // (wall-clock) time.
     110        Duration boot() {                                                                       // monotonic duration since computer boot
     111                timespec ts;
     112                clock_gettime( CLOCK_BOOTTIME, &ts );
     113                return (Duration){ ts };
     114        } // boot
    88115} // distribution
    89116
Note: See TracChangeset for help on using the changeset viewer.