Changeset bd41ac52 in mainline for uspace/app/bnchmark/bnchmark.c


Ignore:
Timestamp:
2018-08-25T22:21:25Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cca80a2
Parents:
e2625b1a
Message:

Get rid of sys/time.h

This commit moves the POSIX-like time functionality from libc's
sys/time.h to libposix and introduces C11-like or HelenOS-specific
interfaces to libc.

Specifically, use of sys/time.h, struct timeval, suseconds_t and
gettimeofday is replaced by time.h (C11), struct timespec (C11), usec_t
(HelenOS) and getuptime / getrealtime (HelenOS).

Also attempt to fix the implementation of clock() to return microseconds
(clocks) rather than processor cycles and move it to libc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bnchmark/bnchmark.c

    re2625b1a rbd41ac52  
    5656
    5757typedef errno_t (*measure_func_t)(void *);
    58 typedef unsigned long umseconds_t; /* milliseconds */
    5958
    6059static void syntax_print(void);
    6160
    62 static errno_t measure(measure_func_t fn, void *data, umseconds_t *result)
    63 {
    64         struct timeval start_time;
    65         gettimeofday(&start_time, NULL);
     61static errno_t measure(measure_func_t fn, void *data, msec_t *result)
     62{
     63        struct timespec start_time;
     64        getuptime(&start_time);
    6665
    6766        errno_t rc = fn(data);
     
    7170        }
    7271
    73         struct timeval final_time;
    74         gettimeofday(&final_time, NULL);
     72        struct timespec final_time;
     73        getuptime(&final_time);
    7574
    7675        /* Calculate time difference in milliseconds */
    77         *result = ((final_time.tv_usec - start_time.tv_usec) / 1000) +
    78             ((final_time.tv_sec - start_time.tv_sec) * 1000);
     76        *result = NSEC2USEC(ts_sub_diff(&final_time, &start_time));
    7977        return EOK;
    8078}
     
    133131{
    134132        errno_t rc;
    135         umseconds_t milliseconds_taken = 0;
     133        msec_t milliseconds_taken = 0;
    136134        char *path = NULL;
    137135        measure_func_t fn = NULL;
     
    194192                }
    195193
    196                 printf("%s;%s;%s;%lu;ms\n", test_type, path, log_str, milliseconds_taken);
     194                printf("%s;%s;%s;%lld;ms\n", test_type, path, log_str, milliseconds_taken);
    197195        }
    198196
Note: See TracChangeset for help on using the changeset viewer.