Changeset bd41ac52 in mainline for uspace/drv


Ignore:
Timestamp:
2018-08-25T22:21:25Z (7 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.

Location:
uspace/drv
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/uhci_rh.c

    re2625b1a rbd41ac52  
    3434#include <macros.h>
    3535#include <mem.h>
    36 #include <sys/time.h>
     36#include <time.h>
    3737
    3838#include <usb/debug.h>
  • 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);
  • uspace/drv/bus/usb/vhc/hub/hub.c

    re2625b1a rbd41ac52  
    6464static void clear_port_status_change(hub_port_t *, uint16_t);
    6565static errno_t set_port_state_delayed_fibril(void *);
    66 static void set_port_state_delayed(hub_t *, size_t, suseconds_t,
    67     hub_port_state_t, hub_port_state_t);
     66static void set_port_state_delayed(hub_t *, size_t, usec_t, hub_port_state_t,
     67    hub_port_state_t);
    6868
    6969/** Convert hub port state to a char. */
     
    444444struct delay_port_state_change {
    445445        /** Delay in microseconds. */
    446         suseconds_t delay;
     446        usec_t delay;
    447447        /** Old state of the port. */
    448448        hub_port_state_t old_state;
     
    496496 */
    497497static void set_port_state_delayed(hub_t *hub, size_t port_index,
    498     suseconds_t delay_time_ms,
    499     hub_port_state_t old_state, hub_port_state_t new_state)
     498    usec_t delay_time_ms, hub_port_state_t old_state,
     499    hub_port_state_t new_state)
    500500{
    501501        struct delay_port_state_change *change =
     
    504504        change->hub = hub;
    505505        change->port = port_index;
    506         change->delay = delay_time_ms * 1000;
     506        change->delay = MSEC2USEC(delay_time_ms);
    507507        change->old_state = old_state;
    508508        change->new_state = new_state;
  • uspace/drv/bus/usb/xhci/hc.c

    re2625b1a rbd41ac52  
    229229        hc->max_slots = XHCI_REG_RD(hc->cap_regs, XHCI_CAP_MAX_SLOTS);
    230230
    231         struct timeval tv;
    232         getuptime(&tv);
    233         hc->wrap_time = tv.tv_sec * 1000000 + tv.tv_usec;
     231        struct timespec ts;
     232        getuptime(&ts);
     233        hc->wrap_time = SEC2USEC(ts.tv_sec) + NSEC2USEC(ts.tv_nsec);
    234234        hc->wrap_count = 0;
    235235
     
    591591static errno_t xhci_handle_mfindex_wrap_event(xhci_hc_t *hc, xhci_trb_t *trb)
    592592{
    593         struct timeval tv;
    594         getuptime(&tv);
    595         usb_log_debug("Microframe index wrapped (@%lu.%li, %" PRIu64 " total).",
    596             tv.tv_sec, tv.tv_usec, hc->wrap_count);
    597         hc->wrap_time = ((uint64_t) tv.tv_sec) * 1000000 + ((uint64_t) tv.tv_usec);
     593        struct timespec ts;
     594        getuptime(&ts);
     595        usb_log_debug("Microframe index wrapped (@%lld.%lld, %" PRIu64 " total).",
     596            ts.tv_sec, NSEC2USEC(ts.tv_nsec), hc->wrap_count);
     597        hc->wrap_time = SEC2USEC(ts.tv_sec) + NSEC2USEC(ts.tv_nsec);
    598598        ++hc->wrap_count;
    599599        return EOK;
  • uspace/drv/bus/usb/xhci/isoch.c

    re2625b1a rbd41ac52  
    113113{
    114114        xhci_isoch_t *const isoch = ep->isoch;
    115         const suseconds_t delay = isoch->buffer_count * ep->interval * 125 +
     115        const usec_t delay = isoch->buffer_count * ep->interval * 125 +
    116116            RESET_TIMER_DELAY;
    117117
     
    210210static inline uint64_t get_system_time()
    211211{
    212         struct timeval tv;
    213         getuptime(&tv);
    214         return ((uint64_t) tv.tv_sec) * 1000000 + ((uint64_t) tv.tv_usec);
     212        struct timespec ts;
     213        getuptime(&ts);
     214        return SEC2USEC(ts.tv_sec) + NSEC2USEC(ts.tv_nsec);
    215215}
    216216
     
    314314        while (isoch->transfers[isoch->hw_enqueue].state == ISOCH_FILLED) {
    315315                xhci_isoch_transfer_t *const it = &isoch->transfers[isoch->hw_enqueue];
    316                 suseconds_t delay;
     316                usec_t delay;
    317317
    318318                assert(it->state == ISOCH_FILLED);
     
    324324                case WINDOW_TOO_SOON:
    325325                        delay = wd.offset * 125;
    326                         usb_log_debug("[isoch] delaying feeding buffer %zu for %ldus",
     326                        usb_log_debug("[isoch] delaying feeding buffer %zu for %lldus",
    327327                            it - isoch->transfers, delay);
    328328                        fibril_timer_set_locked(isoch->feeding_timer, delay,
     
    400400        while (isoch->transfers[isoch->enqueue].state <= ISOCH_FILLED) {
    401401                xhci_isoch_transfer_t *const it = &isoch->transfers[isoch->enqueue];
    402                 suseconds_t delay;
     402                usec_t delay;
    403403
    404404                /* IN buffers are "filled" with free space */
     
    416416                        /* Not allowed to feed yet. Defer to later. */
    417417                        delay = wd.offset * 125;
    418                         usb_log_debug("[isoch] delaying feeding buffer %zu for %ldus",
     418                        usb_log_debug("[isoch] delaying feeding buffer %zu for %lldus",
    419419                            it - isoch->transfers, delay);
    420420                        fibril_timer_set_locked(isoch->feeding_timer, delay,
  • uspace/drv/nic/e1k/e1k.c

    re2625b1a rbd41ac52  
    327327}
    328328
    329 static uint16_t e1000_calculate_itr_interval_from_usecs(suseconds_t useconds)
     329static uint16_t e1000_calculate_itr_interval_from_usecs(usec_t useconds)
    330330{
    331331        return useconds * 4;
     
    12991299}
    13001300
    1301 /** Calculates ITR register interrupt from timeval structure
     1301/** Calculates ITR register interrupt from timespec structure
    13021302 *
    13031303 * @param period Period
    13041304 *
    13051305 */
    1306 static uint16_t e1000_calculate_itr_interval(const struct timeval *period)
     1306static uint16_t e1000_calculate_itr_interval(const struct timespec *period)
    13071307{
    13081308        // TODO: use also tv_sec
    1309         return e1000_calculate_itr_interval_from_usecs(period->tv_usec);
     1309        return e1000_calculate_itr_interval_from_usecs(NSEC2USEC(period->tv_nsec));
    13101310}
    13111311
     
    13211321 */
    13221322static errno_t e1000_poll_mode_change(nic_t *nic, nic_poll_mode_t mode,
    1323     const struct timeval *period)
     1323    const struct timespec *period)
    13241324{
    13251325        assert(nic);
     
    21822182                goto err_rx_structure;
    21832183
    2184         struct timeval period;
     2184        struct timespec period;
    21852185        period.tv_sec = 0;
    2186         period.tv_usec = E1000_DEFAULT_INTERRUPT_INTERVAL_USEC;
     2186        period.tv_nsec = USEC2NSEC(E1000_DEFAULT_INTERRUPT_INTERVAL_USEC);
    21872187        rc = nic_report_poll_mode(nic, NIC_POLL_PERIODIC, &period);
    21882188        if (rc != EOK)
  • uspace/drv/nic/rtl8139/driver.c

    re2625b1a rbd41ac52  
    313313
    314314static errno_t rtl8139_poll_mode_change(nic_t *nic_data, nic_poll_mode_t mode,
    315     const struct timeval *period);
     315    const struct timespec *period);
    316316static void rtl8139_poll(nic_t *nic_data);
    317317
     
    20682068 */
    20692069static errno_t rtl8139_poll_mode_change(nic_t *nic_data, nic_poll_mode_t mode,
    2070     const struct timeval *period)
     2070    const struct timespec *period)
    20712071{
    20722072        assert(nic_data);
  • uspace/drv/nic/rtl8139/general.c

    re2625b1a rbd41ac52  
    8585 */
    8686errno_t rtl8139_timer_act_init(rtl8139_timer_act_t *ta, uint32_t timer_freq,
    87     const struct timeval *time)
     87    const struct timespec *time)
    8888{
    8989        if (!ta || timer_freq == 0 || !time)
     
    9595        ta->full_val = seconds_in_reg * tics_per_ms * 1000;
    9696
    97         struct timeval remains = *time;
     97        struct timespec remains = *time;
    9898        ta->full_skips = remains.tv_sec / seconds_in_reg;
    9999        remains.tv_sec = remains.tv_sec % seconds_in_reg;
    100100
    101         if (remains.tv_usec > RTL8139_USEC_IN_SEC) {
    102                 remains.tv_sec += remains.tv_usec / RTL8139_USEC_IN_SEC;
    103                 remains.tv_usec = remains.tv_usec % RTL8139_USEC_IN_SEC;
     101        if (NSEC2USEC(remains.tv_nsec) > RTL8139_USEC_IN_SEC) {
     102                remains.tv_sec += NSEC2USEC(remains.tv_nsec) / RTL8139_USEC_IN_SEC;
     103                remains.tv_nsec = NSEC2USEC(remains.tv_nsec) % RTL8139_USEC_IN_SEC;
    104104
    105105                /* it can be increased above seconds_in_reg again */
     
    108108        }
    109109
    110         ta->last_val = remains.tv_sec * 1000 + remains.tv_usec / 1000;
     110        ta->last_val = SEC2MSEC(remains.tv_sec) + NSEC2MSEC(remains.tv_nsec);
    111111        ta->last_val *= tics_per_ms;
    112112
  • uspace/drv/nic/rtl8139/general.h

    re2625b1a rbd41ac52  
    3636
    3737#include <stddef.h>
     38#include <stdint.h>
    3839#include <time.h>
    3940
     
    6263    size_t);
    6364extern errno_t rtl8139_timer_act_init(rtl8139_timer_act_t *, uint32_t,
    64     const struct timeval *);
     65    const struct timespec *);
    6566extern int rtl8139_timer_act_step(rtl8139_timer_act_t *, uint32_t *);
    6667
  • uspace/drv/time/cmos-rtc/cmos-rtc.c

    re2625b1a rbd41ac52  
    7575        int clients_connected;
    7676        /** time at which the system booted */
    77         struct timeval boot_time;
     77        struct timespec boot_time;
    7878} rtc_t;
    7979
     
    204204
    205205        rtc->boot_time.tv_sec = 0;
    206         rtc->boot_time.tv_usec = 0;
     206        rtc->boot_time.tv_nsec = 0;
    207207        rtc->clients_connected = 0;
    208208
     
    331331                 */
    332332
    333                 struct timeval curtime;
     333                struct timespec curtime;
    334334
    335335                getuptime(&curtime);
    336                 tv_add(&curtime, &rtc->boot_time);
     336                ts_add(&curtime, &rtc->boot_time);
    337337                fibril_mutex_unlock(&rtc->mutex);
    338338
    339                 return time_tv2tm(&curtime, t);
     339                return time_ts2tm(&curtime, t);
    340340        }
    341341
     
    346346        }
    347347
    348         /* Microseconds are below RTC's resolution, assume 0. */
    349         t->tm_usec = 0;
     348        /* Nanoseconds are below RTC's resolution, assume 0. */
     349        t->tm_nsec = 0;
    350350
    351351        /* now read the registers */
     
    419419                result = EINVAL;
    420420        else {
    421                 struct timeval uptime;
     421                struct timespec uptime;
    422422
    423423                getuptime(&uptime);
    424424                rtc->boot_time.tv_sec = r;
    425                 rtc->boot_time.tv_usec = t->tm_usec;    /* normalized */
    426                 tv_sub(&rtc->boot_time, &uptime);
     425                rtc->boot_time.tv_nsec = t->tm_nsec;    /* normalized */
     426                ts_sub(&rtc->boot_time, &uptime);
    427427                result = EOK;
    428428        }
     
    445445        bool bcd_mode;
    446446        time_t norm_time;
    447         struct timeval uptime;
    448         struct timeval ntv;
     447        struct timespec uptime;
     448        struct timespec ntv;
    449449        int  reg_b;
    450450        int  reg_a;
     
    457457
    458458        ntv.tv_sec = norm_time;
    459         ntv.tv_usec = t->tm_usec;
     459        ntv.tv_nsec = t->tm_nsec;
    460460        getuptime(&uptime);
    461461
    462         if (tv_gteq(&uptime, &ntv)) {
     462        if (ts_gteq(&uptime, &ntv)) {
    463463                /* This is not acceptable */
    464464                return EINVAL;
     
    474474        /* boot_time must be recomputed */
    475475        rtc->boot_time.tv_sec = 0;
    476         rtc->boot_time.tv_usec = 0;
     476        rtc->boot_time.tv_nsec = 0;
    477477
    478478        /* Detect the RTC epoch */
Note: See TracChangeset for help on using the changeset viewer.