Changeset bd41ac52 in mainline for uspace/drv/bus/usb/usbdiag/tests.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/drv/bus/usb/usbdiag/tests.c

    re2625b1a rbd41ac52  
    7272        uint32_t transfer_count = 0;
    7373
    74         struct timeval start_time, final_time, stop_time;
    75         gettimeofday(&start_time, NULL);
    76         gettimeofday(&stop_time, NULL);
    77 
    78         tv_add_diff(&stop_time, params->min_duration * 1000);
    79         gettimeofday(&final_time, NULL);
    80 
    81         while (!tv_gt(&final_time, &stop_time)) {
     74        struct timespec start_time, final_time, stop_time;
     75        getuptime(&start_time);
     76        getuptime(&stop_time);
     77
     78        ts_add_diff(&stop_time, MSEC2NSEC(params->min_duration));
     79        getuptime(&final_time);
     80
     81        while (!ts_gt(&final_time, &stop_time)) {
    8282                ++transfer_count;
    8383
     
    121121                }
    122122
    123                 gettimeofday(&final_time, NULL);
    124         }
    125 
    126         usbdiag_dur_t in_duration = ((final_time.tv_usec - start_time.tv_usec) / 1000) +
    127             ((final_time.tv_sec - start_time.tv_sec) * 1000);
     123                getuptime(&final_time);
     124        }
     125
     126        usbdiag_dur_t in_duration = NSEC2MSEC(final_time.tv_nsec - start_time.tv_nsec) +
     127            SEC2MSEC(final_time.tv_sec - start_time.tv_sec);
    128128
    129129        usb_log_info("Test on %s IN endpoint completed in %lu ms.", usb_str_transfer_type(pipe->desc.transfer_type), in_duration);
     
    170170        uint32_t transfer_count = 0;
    171171
    172         struct timeval start_time, final_time, stop_time;
    173         gettimeofday(&start_time, NULL);
    174         gettimeofday(&stop_time, NULL);
    175 
    176         tv_add_diff(&stop_time, params->min_duration * 1000);
    177         gettimeofday(&final_time, NULL);
    178 
    179         while (!tv_gt(&final_time, &stop_time)) {
     172        struct timespec start_time, final_time, stop_time;
     173        getuptime(&start_time);
     174        getuptime(&stop_time);
     175
     176        ts_add_diff(&stop_time, MSEC2NSEC(params->min_duration));
     177        getuptime(&final_time);
     178
     179        while (!ts_gt(&final_time, &stop_time)) {
    180180                ++transfer_count;
    181181
     
    186186                }
    187187
    188                 gettimeofday(&final_time, NULL);
    189         }
    190 
    191         usbdiag_dur_t in_duration = ((final_time.tv_usec - start_time.tv_usec) / 1000) +
    192             ((final_time.tv_sec - start_time.tv_sec) * 1000);
     188                getuptime(&final_time);
     189        }
     190
     191        usbdiag_dur_t in_duration = NSEC2MSEC(final_time.tv_nsec - start_time.tv_nsec) +
     192            SEC2MSEC(final_time.tv_sec - start_time.tv_sec);
    193193
    194194        usb_log_info("Test on %s OUT endpoint completed in %ld ms.", usb_str_transfer_type(pipe->desc.transfer_type), in_duration);
Note: See TracChangeset for help on using the changeset viewer.