Changeset 4aa495f


Ignore:
Timestamp:
Apr 18, 2021, 8:21:14 AM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d2fadeb
Parents:
e54d0c3
Message:

More fixes after another change to getTimeNsec()

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • example/io/batch-readv.c

    re54d0c3 r4aa495f  
    6666}
    6767
    68 uint64_t getTimeNsec() {
     68uint64_t timeHiRes() {
    6969        timespec curr;
    7070        clock_gettime( CLOCK_REALTIME, &curr );
     
    163163
    164164        printf("Running for %f second, reading %d bytes in batches of %d\n", duration, buflen, batch);
    165         uint64_t start = getTimeNsec();
    166         uint64_t end   = getTimeNsec();
    167         uint64_t prev  = getTimeNsec();
     165        uint64_t start = timeHiRes();
     166        uint64_t end   = timeHiRes();
     167        uint64_t prev  = timeHiRes();
    168168        for(;;) {
    169169                submit_and_drain(&iov, batch);
    170                 end = getTimeNsec();
     170                end = timeHiRes();
    171171                uint64_t delta = end - start;
    172172                if( to_fseconds(end - prev) > 0.1 ) {
  • libcfa/src/clock.hfa

    re54d0c3 r4aa495f  
    1010// Created On       : Thu Apr 12 14:36:06 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 14 17:48:25 2021
    13 // Update Count     : 20
     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 reset( 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
    3637        } // reset
    3738
    38         void ?{}( Clock & clk ) { reset( clk, (Duration){ 0 } ); }
    39         void ?{}( Clock & clk, Duration adj ) { reset( 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
    4041
    4142        // System-wide clock that measures real, i.e., wall-clock) time. This clock is affected by discontinuous jumps in
    4243        // the system time. For example, manual changes of the clock, and incremental adjustments performed by adjtime(3)
    4344        // and NTP (daylight saving (Fall back).
    44         Duration resolutionNsec() {
     45        Duration resolutionHi() {                                                       // clock resolution in nanoseconds (fine)
    4546                struct timespec res;
    4647                clock_getres( CLOCK_REALTIME, &res );
    4748                return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
    48         } // resolutionNsec
     49        } // resolutionHi
    4950
    50         Duration resolution() {
     51        Duration resolution() {                                                         // clock resolution without nanoseconds (coarse)
    5152                struct timespec res;
    5253                clock_getres( CLOCK_REALTIME_COARSE, &res );
     
    5455        } // resolution
    5556
    56         Time timeNsec() {                                                                       // with nanoseconds
     57        Time timeHiRes() {                                                                      // real time with nanoseconds
    5758                timespec curr;
    5859                clock_gettime( CLOCK_REALTIME, &curr );
    5960                return (Time){ curr };
    60         } // timeNsec
     61        } // timeHiRes
    6162
    62         Time time() {                                                                           // without nanoseconds
     63        Time time() {                                                                           // real time without nanoseconds
    6364                timespec curr;
    6465                clock_gettime( CLOCK_REALTIME_COARSE, &curr );
     
    6768        } // time
    6869
    69         Time time( Clock & clk ) with( clk ) {
     70        Time time( Clock & clk ) with( clk ) {                          // real time for given clock
    7071                return time() + offset;
    7172        } // time
     
    7576        } // ?()
    7677
    77         timeval time( Clock & clk ) {
     78        timeval time( Clock & clk ) {                                           // convert to C time format
    7879                return (timeval){ clk() };
    7980        } // time
     
    8889        // discontinuous jumps when the OS is not running the kernal thread. A duration is returned because the value is
    8990        // relative and cannot be converted to real-time (wall-clock) time.
    90         Duration processor() {
     91        Duration processor() {                                                          // non-monotonic duration of kernel thread
    9192                timespec ts;
    9293                clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts );
     
    9798        // watch is affected by discontinuous jumps when the OS is not running the kernel threads. A duration is returned
    9899        // because the value is relative and cannot be converted to real-time (wall-clock) time.
    99         Duration program() {
     100        Duration program() {                                                            // non-monotonic duration of program CPU
    100101                timespec ts;
    101102                clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts );
     
    103104        } // program
    104105
    105         // Monotonic stopwatch starting at machine boot and includes system suspension. This watch is unaffected by
    106         // discontinuous jumps resulting from manual changes of the clock, and incremental adjustments performed by
    107         // adjtime(3) and NTP (Fall back). A duration is returned because the value is relative and cannot be converted to
    108         // real-time (wall-clock) time.
    109         Duration boot() {
     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
    110111                timespec ts;
    111112                clock_gettime( CLOCK_BOOTTIME, &ts );
  • tests/time.cfa

    re54d0c3 r4aa495f  
    1010// Created On       : Tue Mar 27 17:24:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 18 18:14:49 2020
    13 // Update Count     : 37
     12// Last Modified On : Fri Apr 16 14:59:53 2021
     13// Update Count     : 38
    1414//
    1515
     
    5353        //       | "Newfoundland" | getTime( Newfoundland )
    5454        //       | "local" | getTime()
    55         //       | "local nsec" | getTimeNsec()
     55        //       | "local nsec" | timeHiRes()
    5656        //       | "PST" | PST();                                                               // getTime short form
    5757        // sout | nl;
Note: See TracChangeset for help on using the changeset viewer.