Changeset bd41ac52 in mainline for uspace/lib
- Timestamp:
- 2018-08-25T22:21:25Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cca80a2
- Parents:
- e2625b1a
- Location:
- uspace/lib
- Files:
-
- 1 deleted
- 45 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async/client.c
re2625b1a rbd41ac52 110 110 #include <assert.h> 111 111 #include <errno.h> 112 #include < sys/time.h>112 #include <time.h> 113 113 #include <barrier.h> 114 114 #include <stdbool.h> … … 342 342 * 343 343 */ 344 errno_t async_wait_timeout(aid_t amsgid, errno_t *retval, suseconds_t timeout)344 errno_t async_wait_timeout(aid_t amsgid, errno_t *retval, usec_t timeout) 345 345 { 346 346 if (amsgid == 0) { … … 359 359 timeout = 0; 360 360 361 struct time valexpires;361 struct timespec expires; 362 362 getuptime(&expires); 363 t v_add_diff(&expires, timeout);363 ts_add_diff(&expires, USEC2NSEC(timeout)); 364 364 365 365 errno_t rc = fibril_wait_timeout(&msg->received, &expires); -
uspace/lib/c/generic/async/ports.c
re2625b1a rbd41ac52 41 41 #include <assert.h> 42 42 #include <errno.h> 43 #include < sys/time.h>43 #include <time.h> 44 44 #include <barrier.h> 45 45 #include <stdbool.h> -
uspace/lib/c/generic/async/server.c
re2625b1a rbd41ac52 110 110 #include <assert.h> 111 111 #include <errno.h> 112 #include < sys/time.h>112 #include <time.h> 113 113 #include <stdbool.h> 114 114 #include <stdlib.h> … … 916 916 * 917 917 */ 918 bool async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)918 bool async_get_call_timeout(ipc_call_t *call, usec_t usecs) 919 919 { 920 920 assert(call); 921 921 assert(fibril_connection); 922 922 923 struct time val tv;924 struct time val*expires = NULL;923 struct timespec ts; 924 struct timespec *expires = NULL; 925 925 if (usecs) { 926 getuptime(&t v);927 t v_add_diff(&tv, usecs);928 expires = &t v;926 getuptime(&ts); 927 ts_add_diff(&ts, USEC2NSEC(usecs)); 928 expires = &ts; 929 929 } 930 930 -
uspace/lib/c/generic/io/console.c
re2625b1a rbd41ac52 223 223 224 224 bool console_get_event_timeout(console_ctrl_t *ctrl, cons_event_t *event, 225 suseconds_t *timeout)226 { 227 struct time valt0;228 get timeofday(&t0, NULL);225 usec_t *timeout) 226 { 227 struct timespec t0; 228 getuptime(&t0); 229 229 230 230 if (ctrl->input_aid == 0) { … … 257 257 258 258 /* Update timeout */ 259 struct time valt1;260 get timeofday(&t1, NULL);261 *timeout -= tv_sub_diff(&t1, &t0);259 struct timespec t1; 260 getuptime(&t1); 261 *timeout -= NSEC2USEC(ts_sub_diff(&t1, &t0)); 262 262 263 263 return true; -
uspace/lib/c/generic/private/async.h
re2625b1a rbd41ac52 40 40 #include <fibril.h> 41 41 #include <fibril_synch.h> 42 #include < sys/time.h>42 #include <time.h> 43 43 #include <stdbool.h> 44 44 -
uspace/lib/c/generic/private/fibril.h
re2625b1a rbd41ac52 81 81 82 82 extern void fibril_wait_for(fibril_event_t *); 83 extern errno_t fibril_wait_timeout(fibril_event_t *, const struct time val*);83 extern errno_t fibril_wait_timeout(fibril_event_t *, const struct timespec *); 84 84 extern void fibril_notify(fibril_event_t *); 85 85 86 extern errno_t fibril_ipc_wait(ipc_call_t *, const struct time val*);86 extern errno_t fibril_ipc_wait(ipc_call_t *, const struct timespec *); 87 87 extern void fibril_ipc_poke(void); 88 88 -
uspace/lib/c/generic/private/futex.h
re2625b1a rbd41ac52 102 102 * 103 103 */ 104 static inline errno_t futex_down_composable(futex_t *futex, const struct timeval *expires) 104 static inline errno_t futex_down_composable(futex_t *futex, 105 const struct timespec *expires) 105 106 { 106 107 // TODO: Add tests for this. … … 109 110 return EOK; 110 111 111 suseconds_t timeout;112 usec_t timeout; 112 113 113 114 if (!expires) { … … 119 120 timeout = 1; 120 121 } else { 121 struct time valtv;122 struct timespec tv; 122 123 getuptime(&tv); 123 timeout = t v_gteq(&tv, expires) ? 1 :124 tv_sub_diff(expires, &tv);124 timeout = ts_gteq(&tv, expires) ? 1 : 125 NSEC2USEC(ts_sub_diff(expires, &tv)); 125 126 } 126 127 … … 148 149 } 149 150 150 static inline errno_t futex_down_timeout(futex_t *futex, const struct timeval *expires) 151 { 152 if (expires && expires->tv_sec == 0 && expires->tv_usec == 0) { 151 static inline errno_t futex_down_timeout(futex_t *futex, 152 const struct timespec *expires) 153 { 154 if (expires && expires->tv_sec == 0 && expires->tv_nsec == 0) { 153 155 /* Nonblocking down. */ 154 156 … … 209 211 * trydown. 210 212 */ 211 struct time val tv = { .tv_sec = 0, .tv_usec = 0 };213 struct timespec tv = { .tv_sec = 0, .tv_nsec = 0 }; 212 214 return futex_down_timeout(futex, &tv) == EOK; 213 215 } -
uspace/lib/c/generic/private/thread.h
re2625b1a rbd41ac52 49 49 extern void thread_detach(thread_id_t); 50 50 extern thread_id_t thread_get_id(void); 51 extern int thread_usleep(useconds_t);52 extern unsigned int thread_sleep(unsigned int);51 extern void thread_usleep(usec_t); 52 extern void thread_sleep(sec_t); 53 53 54 54 #endif -
uspace/lib/c/generic/rndgen.c
re2625b1a rbd41ac52 52 52 { 53 53 rndgen_t *rndgen; 54 struct time val tv;54 struct timespec ts; 55 55 56 56 rndgen = calloc(1, sizeof(rndgen_t)); … … 59 59 60 60 /* XXX This is a rather poor way of generating random numbers */ 61 get timeofday(&tv, NULL);62 rndgen->seed = t v.tv_sec ^ tv.tv_usec;61 getuptime(&ts); 62 rndgen->seed = ts.tv_sec ^ ts.tv_nsec; 63 63 64 64 *rrndgen = rndgen; -
uspace/lib/c/generic/stdlib.c
re2625b1a rbd41ac52 37 37 #include <fibril_synch.h> 38 38 #include <stdlib.h> 39 #include <errno.h> 39 40 #include "private/libc.h" 40 41 #include "private/scanf.h" -
uspace/lib/c/generic/thread/fibril.c
re2625b1a rbd41ac52 60 60 typedef struct { 61 61 link_t link; 62 struct time valexpires;62 struct timespec expires; 63 63 fibril_event_t *event; 64 64 } _timeout_t; … … 142 142 } 143 143 144 static inline errno_t _ready_down(const struct time val*expires)144 static inline errno_t _ready_down(const struct timespec *expires) 145 145 { 146 146 if (multithreaded) … … 253 253 } 254 254 255 static errno_t _ipc_wait(ipc_call_t *call, const struct time val*expires)255 static errno_t _ipc_wait(ipc_call_t *call, const struct timespec *expires) 256 256 { 257 257 if (!expires) … … 261 261 return ipc_wait(call, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING); 262 262 263 struct time valnow;263 struct timespec now; 264 264 getuptime(&now); 265 265 266 if (t v_gteq(&now, expires))266 if (ts_gteq(&now, expires)) 267 267 return ipc_wait(call, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING); 268 268 269 return ipc_wait(call, tv_sub_diff(expires, &now), SYNCH_FLAGS_NONE); 269 return ipc_wait(call, NSEC2USEC(ts_sub_diff(expires, &now)), 270 SYNCH_FLAGS_NONE); 270 271 } 271 272 … … 275 276 * wait after new ready fibrils are added. 276 277 */ 277 static fibril_t *_ready_list_pop(const struct time val*expires, bool locked)278 static fibril_t *_ready_list_pop(const struct timespec *expires, bool locked) 278 279 { 279 280 if (locked) { … … 370 371 static fibril_t *_ready_list_pop_nonblocking(bool locked) 371 372 { 372 struct time val tv = { .tv_sec = 0, .tv_usec = 0 };373 struct timespec tv = { .tv_sec = 0, .tv_nsec = 0 }; 373 374 return _ready_list_pop(&tv, locked); 374 375 } … … 393 394 394 395 /* Blocks the current fibril until an IPC call arrives. */ 395 static errno_t _wait_ipc(ipc_call_t *call, const struct time val*expires)396 static errno_t _wait_ipc(ipc_call_t *call, const struct timespec *expires) 396 397 { 397 398 futex_assert_is_not_locked(&fibril_futex); … … 430 431 431 432 /** Fire all timeouts that expired. */ 432 static struct time val *_handle_expired_timeouts(struct timeval*next_timeout)433 { 434 struct time val tv;435 getuptime(&t v);433 static struct timespec *_handle_expired_timeouts(struct timespec *next_timeout) 434 { 435 struct timespec ts; 436 getuptime(&ts); 436 437 437 438 futex_lock(&fibril_futex); … … 441 442 _timeout_t *to = list_get_instance(cur, _timeout_t, link); 442 443 443 if (t v_gt(&to->expires, &tv)) {444 if (ts_gt(&to->expires, &ts)) { 444 445 *next_timeout = to->expires; 445 446 futex_unlock(&fibril_futex); … … 535 536 (void) arg; 536 537 537 struct time valnext_timeout;538 struct timespec next_timeout; 538 539 while (true) { 539 struct time val*to = _handle_expired_timeouts(&next_timeout);540 struct timespec *to = _handle_expired_timeouts(&next_timeout); 540 541 fibril_t *f = _ready_list_pop(to, false); 541 542 if (f) { … … 615 616 _timeout_t *cur = list_get_instance(tmp, _timeout_t, link); 616 617 617 if (t v_gteq(&cur->expires, &timeout->expires))618 if (ts_gteq(&cur->expires, &timeout->expires)) 618 619 break; 619 620 … … 634 635 * @return ETIMEOUT if timed out. EOK otherwise. 635 636 */ 636 errno_t fibril_wait_timeout(fibril_event_t *event, const struct timeval *expires) 637 errno_t fibril_wait_timeout(fibril_event_t *event, 638 const struct timespec *expires) 637 639 { 638 640 assert(fibril_self()->rmutex_locks == 0); … … 889 891 } 890 892 891 void fibril_usleep( suseconds_t timeout)892 { 893 struct time valexpires;893 void fibril_usleep(usec_t timeout) 894 { 895 struct timespec expires; 894 896 getuptime(&expires); 895 t v_add_diff(&expires, timeout);897 ts_add_diff(&expires, USEC2NSEC(timeout)); 896 898 897 899 fibril_event_t event = FIBRIL_EVENT_INIT; … … 899 901 } 900 902 901 void fibril_sleep( unsigned int sec)902 { 903 struct time valexpires;903 void fibril_sleep(sec_t sec) 904 { 905 struct timespec expires; 904 906 getuptime(&expires); 905 907 expires.tv_sec += sec; … … 916 918 } 917 919 918 errno_t fibril_ipc_wait(ipc_call_t *call, const struct time val*expires)920 errno_t fibril_ipc_wait(ipc_call_t *call, const struct timespec *expires) 919 921 { 920 922 return _wait_ipc(call, expires); -
uspace/lib/c/generic/thread/fibril_synch.c
re2625b1a rbd41ac52 37 37 #include <async.h> 38 38 #include <adt/list.h> 39 #include < sys/time.h>39 #include <time.h> 40 40 #include <errno.h> 41 41 #include <assert.h> … … 390 390 errno_t 391 391 fibril_condvar_wait_timeout(fibril_condvar_t *fcv, fibril_mutex_t *fm, 392 suseconds_t timeout)392 usec_t timeout) 393 393 { 394 394 assert(fibril_mutex_is_locked(fm)); … … 400 400 wdata.mutex = fm; 401 401 402 struct time val tv;403 struct time val*expires = NULL;402 struct timespec ts; 403 struct timespec *expires = NULL; 404 404 if (timeout) { 405 getuptime(&t v);406 t v_add_diff(&tv, timeout);407 expires = &t v;405 getuptime(&ts); 406 ts_add_diff(&ts, USEC2NSEC(timeout)); 407 expires = &ts; 408 408 } 409 409 … … 557 557 * @param arg Argument for @a fun 558 558 */ 559 void fibril_timer_set(fibril_timer_t *timer, suseconds_t delay,559 void fibril_timer_set(fibril_timer_t *timer, usec_t delay, 560 560 fibril_timer_fun_t fun, void *arg) 561 561 { … … 575 575 * @param arg Argument for @a fun 576 576 */ 577 void fibril_timer_set_locked(fibril_timer_t *timer, suseconds_t delay,577 void fibril_timer_set_locked(fibril_timer_t *timer, usec_t delay, 578 578 fibril_timer_fun_t fun, void *arg) 579 579 { … … 728 728 } 729 729 730 errno_t fibril_semaphore_down_timeout(fibril_semaphore_t *sem, suseconds_t timeout)730 errno_t fibril_semaphore_down_timeout(fibril_semaphore_t *sem, usec_t timeout) 731 731 { 732 732 if (timeout < 0) … … 751 751 futex_unlock(&fibril_synch_futex); 752 752 753 struct time val tv;754 struct time val*expires = NULL;753 struct timespec ts; 754 struct timespec *expires = NULL; 755 755 if (timeout) { 756 getuptime(&t v);757 t v_add_diff(&tv, timeout);758 expires = &t v;756 getuptime(&ts); 757 ts_add_diff(&ts, USEC2NSEC(timeout)); 758 expires = &ts; 759 759 } 760 760 -
uspace/lib/c/generic/thread/mpsc.c
re2625b1a rbd41ac52 146 146 * there is no message left in the queue. 147 147 */ 148 errno_t mpsc_receive(mpsc_t *q, void *b, const struct time val*expires)148 errno_t mpsc_receive(mpsc_t *q, void *b, const struct timespec *expires) 149 149 { 150 150 mpsc_node_t *n; -
uspace/lib/c/generic/thread/thread.c
re2625b1a rbd41ac52 176 176 * 177 177 */ 178 int thread_usleep(useconds_t usec)178 void thread_usleep(usec_t usec) 179 179 { 180 180 (void) __SYSCALL1(SYS_THREAD_USLEEP, usec); 181 return 0;182 181 } 183 182 … … 185 184 * 186 185 */ 187 unsigned int thread_sleep(unsigned int sec)186 void thread_sleep(sec_t sec) 188 187 { 189 188 /* 190 * Sleep in 1000 second steps to support 191 * full argument range 189 * Sleep in 1000 second steps to support full argument range 192 190 */ 193 194 191 while (sec > 0) { 195 192 unsigned int period = (sec > 1000) ? 1000 : sec; 196 193 197 thread_usleep( period * 1000000);194 thread_usleep(SEC2USEC(period)); 198 195 sec -= period; 199 196 } 200 201 return 0;202 197 } 203 198 -
uspace/lib/c/generic/time.c
re2625b1a rbd41ac52 35 35 */ 36 36 37 #include <sys/time.h>38 37 #include <time.h> 39 38 #include <stdbool.h> … … 51 50 #include <loc.h> 52 51 #include <device/clock_dev.h> 52 #include <stats.h> 53 53 54 54 #define ASCTIME_BUF_LEN 26 … … 57 57 #define MINS_PER_HOUR 60 58 58 #define SECS_PER_MIN 60 59 #define USECS_PER_SEC 100000059 #define NSECS_PER_SEC 1000000000ll 60 60 #define MINS_PER_DAY (MINS_PER_HOUR * HOURS_PER_DAY) 61 61 #define SECS_PER_HOUR (SECS_PER_MIN * MINS_PER_HOUR) … … 71 71 static async_sess_t *clock_conn = NULL; 72 72 73 /** 74 * Get CPU time used since the process invocation. 75 * 76 * @return Consumed microseconds by this process or -1 if not available. 77 */ 78 clock_t clock(void) 79 { 80 static_assert(CLOCKS_PER_SEC == 1000000); 81 82 size_t count; 83 stats_cpu_t *cpu_stats = stats_get_cpus(&count); 84 if (!cpu_stats) 85 return (clock_t) -1; 86 if (!cpu_stats->frequency_mhz) { 87 free(cpu_stats); 88 return (clock_t) -1; 89 } 90 91 clock_t total_usecs = -1; 92 if (cpu_stats) { 93 stats_task_t *task_stats = stats_get_task(task_get_id()); 94 if (task_stats) { 95 total_usecs = (clock_t) (task_stats->kcycles + 96 task_stats->ucycles) / cpu_stats->frequency_mhz; 97 free(task_stats); 98 } 99 free(cpu_stats); 100 } 101 102 return total_usecs; 103 } 104 73 105 /** Check whether the year is a leap year. 74 106 * … … 252 284 * 253 285 * @param tm Broken-down time to normalize. 254 * @param t v Timevalto add.286 * @param ts Timespec to add. 255 287 * 256 288 * @return 0 on success, -1 on overflow 257 289 * 258 290 */ 259 static int normalize_tm_t v(struct tm *tm, const struct timeval *tv)291 static int normalize_tm_ts(struct tm *tm, const struct timespec *ts) 260 292 { 261 293 // TODO: DST correction 262 294 263 295 /* Set initial values. */ 264 time_t usec = tm->tm_usec + tv->tv_usec;265 time_t sec = tm->tm_sec + t v->tv_sec;296 time_t nsec = tm->tm_nsec + ts->tv_nsec; 297 time_t sec = tm->tm_sec + ts->tv_sec; 266 298 time_t min = tm->tm_min; 267 299 time_t hour = tm->tm_hour; … … 271 303 272 304 /* Adjust time. */ 273 sec += floor_div( usec, USECS_PER_SEC);274 usec = floor_mod(usec, USECS_PER_SEC);305 sec += floor_div(nsec, NSECS_PER_SEC); 306 nsec = floor_mod(nsec, NSECS_PER_SEC); 275 307 min += floor_div(sec, SECS_PER_MIN); 276 308 sec = floor_mod(sec, SECS_PER_MIN); … … 321 353 322 354 /* And put the values back to the struct. */ 323 tm->tm_ usec = (int) usec;355 tm->tm_nsec = (int) nsec; 324 356 tm->tm_sec = (int) sec; 325 357 tm->tm_min = (int) min; … … 340 372 static int normalize_tm_time(struct tm *tm, time_t time) 341 373 { 342 struct time val tv= {374 struct timespec ts = { 343 375 .tv_sec = time, 344 .tv_ usec = 0376 .tv_nsec = 0 345 377 }; 346 378 347 return normalize_tm_t v(tm, &tv);379 return normalize_tm_ts(tm, &ts); 348 380 } 349 381 … … 456 488 } 457 489 458 static void tv_normalize(struct timeval *tv) 459 { 460 while (tv->tv_usec > USECS_PER_SEC) { 461 tv->tv_sec++; 462 tv->tv_usec -= USECS_PER_SEC; 463 } 464 while (tv->tv_usec < 0) { 465 tv->tv_sec--; 466 tv->tv_usec += USECS_PER_SEC; 467 } 468 } 469 470 /** Add microseconds to given timeval. 471 * 472 * @param tv Destination timeval. 473 * @param usecs Number of microseconds to add. 474 * 475 */ 476 void tv_add_diff(struct timeval *tv, suseconds_t usecs) 477 { 478 tv->tv_sec += usecs / USECS_PER_SEC; 479 tv->tv_usec += usecs % USECS_PER_SEC; 480 tv_normalize(tv); 481 } 482 483 /** Add two timevals. 484 * 485 * @param tv1 First timeval. 486 * @param tv2 Second timeval. 487 */ 488 void tv_add(struct timeval *tv1, const struct timeval *tv2) 489 { 490 tv1->tv_sec += tv2->tv_sec; 491 tv1->tv_usec += tv2->tv_usec; 492 tv_normalize(tv1); 493 } 494 495 /** Subtract two timevals. 496 * 497 * @param tv1 First timeval. 498 * @param tv2 Second timeval. 499 * 500 * @return Difference between tv1 and tv2 (tv1 - tv2) in 501 * microseconds. 502 * 503 */ 504 suseconds_t tv_sub_diff(const struct timeval *tv1, const struct timeval *tv2) 505 { 506 return (tv1->tv_usec - tv2->tv_usec) + 507 ((tv1->tv_sec - tv2->tv_sec) * USECS_PER_SEC); 508 } 509 510 /** Subtract two timevals. 511 * 512 * @param tv1 First timeval. 513 * @param tv2 Second timeval. 514 * 515 */ 516 void tv_sub(struct timeval *tv1, const struct timeval *tv2) 517 { 518 tv1->tv_sec -= tv2->tv_sec; 519 tv1->tv_usec -= tv2->tv_usec; 520 tv_normalize(tv1); 521 } 522 523 /** Decide if one timeval is greater than the other. 524 * 525 * @param t1 First timeval. 526 * @param t2 Second timeval. 527 * 528 * @return True if tv1 is greater than tv2. 529 * @return False otherwise. 530 * 531 */ 532 int tv_gt(const struct timeval *tv1, const struct timeval *tv2) 533 { 534 if (tv1->tv_sec > tv2->tv_sec) 490 static void ts_normalize(struct timespec *ts) 491 { 492 while (ts->tv_nsec >= NSECS_PER_SEC) { 493 ts->tv_sec++; 494 ts->tv_nsec -= NSECS_PER_SEC; 495 } 496 while (ts->tv_nsec < 0) { 497 ts->tv_sec--; 498 ts->tv_nsec += NSECS_PER_SEC; 499 } 500 } 501 502 /** Add nanoseconds to given timespec. 503 * 504 * @param ts Destination timespec. 505 * @param nsecs Number of nanoseconds to add. 506 * 507 */ 508 void ts_add_diff(struct timespec *ts, nsec_t nsecs) 509 { 510 ts->tv_sec += nsecs / NSECS_PER_SEC; 511 ts->tv_nsec += nsecs % NSECS_PER_SEC; 512 ts_normalize(ts); 513 } 514 515 /** Add two timespecs. 516 * 517 * @param ts1 First timespec. 518 * @param ts2 Second timespec. 519 */ 520 void ts_add(struct timespec *ts1, const struct timespec *ts2) 521 { 522 ts1->tv_sec += ts2->tv_sec; 523 ts1->tv_nsec += ts2->tv_nsec; 524 ts_normalize(ts1); 525 } 526 527 /** Subtract two timespecs. 528 * 529 * @param ts1 First timespec. 530 * @param ts2 Second timespec. 531 * 532 * @return Difference between ts1 and ts2 (ts1 - ts2) in nanoseconds. 533 * 534 */ 535 nsec_t ts_sub_diff(const struct timespec *ts1, const struct timespec *ts2) 536 { 537 return (nsec_t) (ts1->tv_nsec - ts2->tv_nsec) + 538 SEC2NSEC((ts1->tv_sec - ts2->tv_sec)); 539 } 540 541 /** Subtract two timespecs. 542 * 543 * @param ts1 First timespec. 544 * @param ts2 Second timespec. 545 * 546 */ 547 void ts_sub(struct timespec *ts1, const struct timespec *ts2) 548 { 549 ts1->tv_sec -= ts2->tv_sec; 550 ts1->tv_nsec -= ts2->tv_nsec; 551 ts_normalize(ts1); 552 } 553 554 /** Decide if one timespec is greater than the other. 555 * 556 * @param ts1 First timespec. 557 * @param ts2 Second timespec. 558 * 559 * @return True if ts1 is greater than ts2. 560 * @return False otherwise. 561 * 562 */ 563 bool ts_gt(const struct timespec *ts1, const struct timespec *ts2) 564 { 565 if (ts1->tv_sec > ts2->tv_sec) 535 566 return true; 536 567 537 if ((t v1->tv_sec == tv2->tv_sec) && (tv1->tv_usec > tv2->tv_usec))568 if ((ts1->tv_sec == ts2->tv_sec) && (ts1->tv_nsec > ts2->tv_nsec)) 538 569 return true; 539 570 … … 541 572 } 542 573 543 /** Decide if one time valis greater than or equal to the other.544 * 545 * @param t v1 First timeval.546 * @param t v2 Second timeval.547 * 548 * @return True if tv1 is greater than or equal to tv2.549 * @return False otherwise.550 * 551 */ 552 int tv_gteq(const struct timeval *tv1, const struct timeval *tv2)553 { 554 if (t v1->tv_sec > tv2->tv_sec)574 /** Decide if one timespec is greater than or equal to the other. 575 * 576 * @param ts1 First timespec. 577 * @param ts2 Second timespec. 578 * 579 * @return True if ts1 is greater than or equal to ts2. 580 * @return False otherwise. 581 * 582 */ 583 bool ts_gteq(const struct timespec *ts1, const struct timespec *ts2) 584 { 585 if (ts1->tv_sec > ts2->tv_sec) 555 586 return true; 556 587 557 if ((t v1->tv_sec == tv2->tv_sec) && (tv1->tv_usec >= tv2->tv_usec))588 if ((ts1->tv_sec == ts2->tv_sec) && (ts1->tv_nsec >= ts2->tv_nsec)) 558 589 return true; 559 590 … … 561 592 } 562 593 563 /** Get time of day. 564 * 565 * The time variables are memory mapped (read-only) from kernel which 566 * updates them periodically. 567 * 568 * As it is impossible to read 2 values atomically, we use a trick: 569 * First we read the seconds, then we read the microseconds, then we 570 * read the seconds again. If a second elapsed in the meantime, set 571 * the microseconds to zero. 572 * 573 * This assures that the values returned by two subsequent calls 574 * to gettimeofday() are monotonous. 575 * 576 */ 577 void gettimeofday(struct timeval *tv, struct timezone *tz) 578 { 579 if (tz) { 580 tz->tz_minuteswest = 0; 581 tz->tz_dsttime = DST_NONE; 582 } 583 594 /** Get real time from a RTC service. 595 * 596 * @param[out] ts Timespec to hold time read from the RTC service (if 597 * available). If no such service exists, the returned time 598 * corresponds to system uptime. 599 */ 600 void getrealtime(struct timespec *ts) 601 { 584 602 if (clock_conn == NULL) { 585 603 category_id_t cat_id; … … 620 638 goto fallback; 621 639 622 t v->tv_usec = time.tm_usec;623 t v->tv_sec = mktime(&time);640 ts->tv_nsec = time.tm_nsec; 641 ts->tv_sec = mktime(&time); 624 642 625 643 return; 626 644 627 645 fallback: 628 getuptime(tv); 629 } 630 631 void getuptime(struct timeval *tv) 646 getuptime(ts); 647 } 648 649 /** Get system uptime. 650 * 651 * @param[out] ts Timespec to hold time current uptime. 652 * 653 * The time variables are memory mapped (read-only) from kernel which 654 * updates them periodically. 655 * 656 * As it is impossible to read 2 values atomically, we use a trick: 657 * First we read the seconds, then we read the microseconds, then we 658 * read the seconds again. If a second elapsed in the meantime, set 659 * the microseconds to zero. 660 * 661 * This assures that the values returned by two subsequent calls 662 * to getuptime() are monotonous. 663 * 664 */ 665 void getuptime(struct timespec *ts) 632 666 { 633 667 if (ktime == NULL) { … … 654 688 655 689 read_barrier(); 656 t v->tv_usec = ktime->useconds;690 ts->tv_nsec = USEC2NSEC(ktime->useconds); 657 691 658 692 read_barrier(); … … 660 694 661 695 if (s1 != s2) { 662 t v->tv_sec = max(s1, s2);663 t v->tv_usec = 0;696 ts->tv_sec = max(s1, s2); 697 ts->tv_nsec = 0; 664 698 } else 665 t v->tv_sec = s1;699 ts->tv_sec = s1; 666 700 667 701 return; 668 702 669 703 fallback: 670 t v->tv_sec = 0;671 t v->tv_usec = 0;704 ts->tv_sec = 0; 705 ts->tv_nsec = 0; 672 706 } 673 707 674 708 time_t time(time_t *tloc) 675 709 { 676 struct time val tv;677 get timeofday(&tv, NULL);710 struct timespec ts; 711 getrealtime(&ts); 678 712 679 713 if (tloc) 680 *tloc = t v.tv_sec;681 682 return t v.tv_sec;683 } 684 685 void udelay( useconds_t time)714 *tloc = ts.tv_sec; 715 716 return ts.tv_sec; 717 } 718 719 void udelay(sysarg_t time) 686 720 { 687 721 (void) __SYSCALL1(SYS_THREAD_UDELAY, (sysarg_t) time); … … 884 918 break; 885 919 case 's': 886 APPEND("%l d", secs_since_epoch(tm));920 APPEND("%lld", secs_since_epoch(tm)); 887 921 break; 888 922 case 'S': … … 961 995 962 996 /* Set result to epoch. */ 963 result->tm_ usec = 0;997 result->tm_nsec = 0; 964 998 result->tm_sec = 0; 965 999 result->tm_min = 0; … … 1038 1072 * 1039 1073 */ 1040 errno_t time_t v2tm(const struct timeval *tv, struct tm *restrict result)1074 errno_t time_ts2tm(const struct timespec *ts, struct tm *restrict result) 1041 1075 { 1042 1076 // TODO: Deal with timezones. … … 1044 1078 1045 1079 /* Set result to epoch. */ 1046 result->tm_ usec = 0;1080 result->tm_nsec = 0; 1047 1081 result->tm_sec = 0; 1048 1082 result->tm_min = 0; … … 1052 1086 result->tm_year = 70; /* 1970 */ 1053 1087 1054 if (normalize_tm_t v(result, tv) == -1)1088 if (normalize_tm_ts(result, ts) == -1) 1055 1089 return EOVERFLOW; 1056 1090 … … 1070 1104 errno_t time_local2tm(const time_t time, struct tm *restrict result) 1071 1105 { 1072 struct time val tv= {1106 struct timespec ts = { 1073 1107 .tv_sec = time, 1074 .tv_ usec = 01108 .tv_nsec = 0 1075 1109 }; 1076 1110 1077 return time_t v2tm(&tv, result);1111 return time_ts2tm(&ts, result); 1078 1112 } 1079 1113 -
uspace/lib/c/include/async.h
re2625b1a rbd41ac52 42 42 #include <ipc/common.h> 43 43 #include <fibril.h> 44 #include < sys/time.h>44 #include <time.h> 45 45 #include <stdbool.h> 46 46 #include <abi/proc/task.h> … … 112 112 async_get_call_timeout(data, 0) 113 113 114 extern bool async_get_call_timeout(ipc_call_t *, suseconds_t);114 extern bool async_get_call_timeout(ipc_call_t *, usec_t); 115 115 116 116 /* … … 140 140 141 141 extern void async_wait_for(aid_t, errno_t *); 142 extern errno_t async_wait_timeout(aid_t, errno_t *, suseconds_t);142 extern errno_t async_wait_timeout(aid_t, errno_t *, usec_t); 143 143 extern void async_forget(aid_t); 144 144 -
uspace/lib/c/include/ddi.h
re2625b1a rbd41ac52 39 39 #include <stddef.h> 40 40 #include <stdint.h> 41 #include < sys/time.h>41 #include <time.h> 42 42 #include <byteorder.h> 43 43 #include <abi/ddi/irq.h> … … 138 138 139 139 static inline uint8_t pio_change_8(ioport8_t *reg, uint8_t val, uint8_t mask, 140 usec onds_t delay)140 usec_t delay) 141 141 { 142 142 uint8_t v = pio_read_8(reg); … … 147 147 148 148 static inline uint16_t pio_change_16(ioport16_t *reg, uint16_t val, 149 uint16_t mask, usec onds_t delay)149 uint16_t mask, usec_t delay) 150 150 { 151 151 uint16_t v = pio_read_16(reg); … … 156 156 157 157 static inline uint32_t pio_change_32(ioport32_t *reg, uint32_t val, 158 uint32_t mask, usec onds_t delay)158 uint32_t mask, usec_t delay) 159 159 { 160 160 uint32_t v = pio_read_32(reg); … … 165 165 166 166 static inline uint64_t pio_change_64(ioport64_t *reg, uint64_t val, 167 uint64_t mask, usec onds_t delay)167 uint64_t mask, usec_t delay) 168 168 { 169 169 uint64_t v = pio_read_64(reg); … … 173 173 } 174 174 175 static inline uint8_t pio_set_8(ioport8_t *r, uint8_t v, usec onds_t d)175 static inline uint8_t pio_set_8(ioport8_t *r, uint8_t v, usec_t d) 176 176 { 177 177 return pio_change_8(r, v, 0, d); 178 178 } 179 static inline uint16_t pio_set_16(ioport16_t *r, uint16_t v, usec onds_t d)179 static inline uint16_t pio_set_16(ioport16_t *r, uint16_t v, usec_t d) 180 180 { 181 181 return pio_change_16(r, v, 0, d); 182 182 } 183 static inline uint32_t pio_set_32(ioport32_t *r, uint32_t v, usec onds_t d)183 static inline uint32_t pio_set_32(ioport32_t *r, uint32_t v, usec_t d) 184 184 { 185 185 return pio_change_32(r, v, 0, d); 186 186 } 187 static inline uint64_t pio_set_64(ioport64_t *r, uint64_t v, usec onds_t d)187 static inline uint64_t pio_set_64(ioport64_t *r, uint64_t v, usec_t d) 188 188 { 189 189 return pio_change_64(r, v, 0, d); 190 190 } 191 191 192 static inline uint8_t pio_clear_8(ioport8_t *r, uint8_t v, usec onds_t d)192 static inline uint8_t pio_clear_8(ioport8_t *r, uint8_t v, usec_t d) 193 193 { 194 194 return pio_change_8(r, 0, v, d); 195 195 } 196 static inline uint16_t pio_clear_16(ioport16_t *r, uint16_t v, usec onds_t d)196 static inline uint16_t pio_clear_16(ioport16_t *r, uint16_t v, usec_t d) 197 197 { 198 198 return pio_change_16(r, 0, v, d); 199 199 } 200 static inline uint32_t pio_clear_32(ioport32_t *r, uint32_t v, usec onds_t d)200 static inline uint32_t pio_clear_32(ioport32_t *r, uint32_t v, usec_t d) 201 201 { 202 202 return pio_change_32(r, 0, v, d); 203 203 } 204 static inline uint64_t pio_clear_64(ioport64_t *r, uint64_t v, usec onds_t d)204 static inline uint64_t pio_clear_64(ioport64_t *r, uint64_t v, usec_t d) 205 205 { 206 206 return pio_change_64(r, 0, v, d); -
uspace/lib/c/include/fibril.h
re2625b1a rbd41ac52 60 60 extern void fibril_yield(void); 61 61 62 extern void fibril_usleep( suseconds_t);63 extern void fibril_sleep( unsigned int);62 extern void fibril_usleep(usec_t); 63 extern void fibril_sleep(sec_t); 64 64 65 65 extern void fibril_enable_multithreaded(void); -
uspace/lib/c/include/fibril_synch.h
re2625b1a rbd41ac52 39 39 #include <adt/list.h> 40 40 #include <tls.h> 41 #include < sys/time.h>41 #include <time.h> 42 42 #include <stdbool.h> 43 43 … … 138 138 fid_t handler_fid; 139 139 140 suseconds_t delay;140 usec_t delay; 141 141 fibril_timer_fun_t fun; 142 142 void *arg; … … 181 181 extern void fibril_condvar_initialize(fibril_condvar_t *); 182 182 extern errno_t fibril_condvar_wait_timeout(fibril_condvar_t *, fibril_mutex_t *, 183 suseconds_t);183 usec_t); 184 184 extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *); 185 185 extern void fibril_condvar_signal(fibril_condvar_t *); … … 188 188 extern fibril_timer_t *fibril_timer_create(fibril_mutex_t *); 189 189 extern void fibril_timer_destroy(fibril_timer_t *); 190 extern void fibril_timer_set(fibril_timer_t *, suseconds_t, fibril_timer_fun_t,190 extern void fibril_timer_set(fibril_timer_t *, usec_t, fibril_timer_fun_t, 191 191 void *); 192 extern void fibril_timer_set_locked(fibril_timer_t *, suseconds_t,192 extern void fibril_timer_set_locked(fibril_timer_t *, usec_t, 193 193 fibril_timer_fun_t, void *); 194 194 extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *); … … 198 198 extern void fibril_semaphore_up(fibril_semaphore_t *); 199 199 extern void fibril_semaphore_down(fibril_semaphore_t *); 200 extern errno_t fibril_semaphore_down_timeout(fibril_semaphore_t *, suseconds_t);200 extern errno_t fibril_semaphore_down_timeout(fibril_semaphore_t *, usec_t); 201 201 extern void fibril_semaphore_close(fibril_semaphore_t *); 202 202 … … 205 205 extern void mpsc_destroy(mpsc_t *); 206 206 extern errno_t mpsc_send(mpsc_t *, const void *); 207 extern errno_t mpsc_receive(mpsc_t *, void *, const struct time val*);207 extern errno_t mpsc_receive(mpsc_t *, void *, const struct timespec *); 208 208 extern void mpsc_close(mpsc_t *); 209 209 -
uspace/lib/c/include/io/con_srv.h
re2625b1a rbd41ac52 45 45 #include <io/style.h> 46 46 #include <stdbool.h> 47 #include < sys/time.h>47 #include <time.h> 48 48 #include <stddef.h> 49 49 … … 55 55 void *sarg; 56 56 /** Period to check for abort */ 57 suseconds_t abort_timeout;57 usec_t abort_timeout; 58 58 bool aborted; 59 59 } con_srvs_t; -
uspace/lib/c/include/io/console.h
re2625b1a rbd41ac52 36 36 #define LIBC_IO_CONSOLE_H_ 37 37 38 #include < sys/time.h>38 #include <time.h> 39 39 #include <io/concaps.h> 40 40 #include <io/kbd_event.h> … … 85 85 extern bool console_get_event(console_ctrl_t *, cons_event_t *); 86 86 extern bool console_get_event_timeout(console_ctrl_t *, cons_event_t *, 87 suseconds_t *);87 usec_t *); 88 88 89 89 #endif -
uspace/lib/c/include/time.h
re2625b1a rbd41ac52 1 1 /* 2 * Copyright (c) 20 07Jakub Jermar2 * Copyright (c) 2018 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 40 40 #endif 41 41 42 #include <sys/time.h>43 42 43 /* ISO/IEC 9899:2011 7.27.1 (2) */ 44 45 #include <_bits/NULL.h> 46 47 #define CLOCKS_PER_SEC ((clock_t) 1000000) 48 49 #define TIME_UTC 1 50 51 52 /* ISO/IEC 9899:2011 7.27.1 (3) */ 53 54 #include <_bits/size_t.h> 55 56 /* ISO/IEC 9899:2011 7.27.1 (3), (4) */ 57 58 typedef long long time_t; 59 typedef long long clock_t; 60 61 struct timespec { 62 time_t tv_sec; 63 long tv_nsec; 64 }; 65 66 struct tm { 67 int tm_sec; 68 int tm_nsec; 69 int tm_min; 70 int tm_hour; 71 int tm_mday; 72 int tm_mon; 73 int tm_year; 74 int tm_wday; 75 int tm_yday; 76 int tm_isdst; 77 }; 78 79 /* ISO/IEC 9899:2011 7.27.2.1 (1) */ 80 extern clock_t clock(void); 81 82 /* ISO/IEC 9899:2011 7.27.2.2 (1) */ 83 extern double difftime(time_t, time_t); 84 85 /* ISO/IEC 9899:2011 7.27.2.3 (1) */ 86 extern time_t mktime(struct tm *); 87 88 /* ISO/IEC 9899:2011 7.27.2.4 (1) */ 44 89 extern time_t time(time_t *); 90 91 /* ISO/IEC 9899:2011 7.27.2.5 (1) */ 92 extern int timespec_get(struct timespec *, int); 93 94 /* ISO/IEC 9899:2011 7.27.3.1 (1) */ 95 extern char *asctime(const struct tm *); 96 97 /* ISO/IEC 9899:2011 7.27.3.2 (1) */ 98 extern char *ctime(const time_t *); 99 100 /* ISO/IEC 9899:2011 7.27.3.3 (1) */ 101 extern struct tm *gmtime(const time_t *); 102 103 /* ISO/IEC 9899:2011 7.27.3.4 (1) */ 104 extern struct tm *localtime(const time_t *); 105 106 /* ISO/IEC 9899:2011 7.27.3.5 (1) */ 107 extern size_t strftime(char *, size_t, const char *, const struct tm *); 108 109 /* 110 * HelenOS specific extensions 111 */ 112 113 #include <stdbool.h> 114 #include <_bits/errno.h> 115 116 typedef long long sec_t; 117 typedef long long msec_t; 118 typedef long long usec_t; 119 typedef long long nsec_t; /* good for +/- 292 years */ 120 121 #define SEC2MSEC(s) ((s) * 1000ll) 122 #define SEC2USEC(s) ((s) * 1000000ll) 123 #define SEC2NSEC(s) ((s) * 1000000000ll) 124 125 #define MSEC2SEC(ms) ((ms) / 1000ll) 126 #define MSEC2USEC(ms) ((ms) * 1000ll) 127 #define MSEC2NSEC(ms) ((ms) * 1000000ll) 128 129 #define USEC2SEC(us) ((us) / 1000000ll) 130 #define USEC2MSEC(us) ((us) / 1000ll) 131 #define USEC2NSEC(us) ((us) * 1000ll) 132 133 #define NSEC2SEC(ns) ((ns) / 1000000000ll) 134 #define NSEC2MSEC(ns) ((ns) / 1000000ll) 135 #define NSEC2USEC(ns) ((ns) / 1000ll) 136 137 extern void getuptime(struct timespec *); 138 extern void getrealtime(struct timespec *); 139 140 extern void ts_add_diff(struct timespec *, nsec_t); 141 extern void ts_add(struct timespec *, const struct timespec *); 142 extern void ts_sub(struct timespec *, const struct timespec *); 143 extern nsec_t ts_sub_diff(const struct timespec *, const struct timespec *); 144 extern bool ts_gt(const struct timespec *, const struct timespec *); 145 extern bool ts_gteq(const struct timespec *, const struct timespec *); 146 147 extern errno_t time_utc2tm(const time_t, struct tm *); 148 extern errno_t time_utc2str(const time_t, char *); 149 extern void time_tm2str(const struct tm *, char *); 150 extern errno_t time_ts2tm(const struct timespec *, struct tm *); 151 extern errno_t time_local2tm(const time_t, struct tm *); 152 extern errno_t time_local2str(const time_t, char *); 153 154 extern void udelay(sysarg_t); 45 155 46 156 #ifdef __cplusplus -
uspace/lib/cpp/include/__bits/chrono.hpp
re2625b1a rbd41ac52 611 611 static time_point now() 612 612 { 613 hel::time val tv{};614 hel::get timeofday(&tv, nullptr);615 616 rep time = tv.tv_usec;617 time += (t v.tv_sec * 1'000'000ul);613 hel::timespec ts{}; 614 hel::getrealtime(&ts); 615 616 rep time = NSEC2USEC(ts.tv_nsec); 617 time += (ts.tv_sec * 1'000'000ul); 618 618 619 619 return time_point{duration{time - epoch_usecs}}; … … 654 654 static time_point now() 655 655 { 656 hel::time val tv{};657 hel::getuptime(&t v);658 659 rep time = tv.tv_usec;660 time += (t v.tv_sec * 1'000'000ul);656 hel::timespec ts{}; 657 hel::getuptime(&ts); 658 659 rep time = NSEC2USEC(ts.tv_nsec); 660 time += (ts.tv_sec * 1'000'000ul); 661 661 662 662 return time_point{duration{time}}; -
uspace/lib/cpp/include/__bits/thread/threading.hpp
re2625b1a rbd41ac52 58 58 using thread_type = hel::fid_t; 59 59 using condvar_type = hel::fibril_condvar_t; 60 using time_unit = hel:: suseconds_t;60 using time_unit = hel::usec_t; 61 61 using shared_mutex_type = hel::fibril_rwlock_t; 62 62 -
uspace/lib/drv/generic/remote_nic.c
re2625b1a rbd41ac52 39 39 #include <errno.h> 40 40 #include <ipc/services.h> 41 #include < sys/time.h>41 #include <time.h> 42 42 #include <macros.h> 43 43 … … 1262 1262 */ 1263 1263 errno_t nic_poll_get_mode(async_sess_t *dev_sess, nic_poll_mode_t *mode, 1264 struct time val*period)1264 struct timespec *period) 1265 1265 { 1266 1266 assert(mode); … … 1280 1280 1281 1281 if (period != NULL) 1282 rc = async_data_read_start(exch, period, sizeof(struct time val));1282 rc = async_data_read_start(exch, period, sizeof(struct timespec)); 1283 1283 1284 1284 async_exchange_end(exch); … … 1296 1296 */ 1297 1297 errno_t nic_poll_set_mode(async_sess_t *dev_sess, nic_poll_mode_t mode, 1298 const struct time val*period)1298 const struct timespec *period) 1299 1299 { 1300 1300 async_exch_t *exch = async_exchange_begin(dev_sess); … … 1305 1305 errno_t rc; 1306 1306 if (period) 1307 rc = async_data_write_start(exch, period, sizeof(struct time val));1307 rc = async_data_write_start(exch, period, sizeof(struct timespec)); 1308 1308 else 1309 1309 rc = EOK; … … 2405 2405 nic_poll_mode_t mode = NIC_POLL_IMMEDIATE; 2406 2406 int request_data = IPC_GET_ARG2(*call); 2407 struct time valperiod = {2407 struct timespec period = { 2408 2408 .tv_sec = 0, 2409 .tv_ usec = 02409 .tv_nsec = 0 2410 2410 }; 2411 2411 … … 2421 2421 } 2422 2422 2423 if (max_len != sizeof(struct time val)) {2423 if (max_len != sizeof(struct timespec)) { 2424 2424 async_answer_0(&data, ELIMIT); 2425 2425 async_answer_0(call, ELIMIT); … … 2428 2428 2429 2429 async_data_read_finalize(&data, &period, 2430 sizeof(struct time val));2430 sizeof(struct timespec)); 2431 2431 } 2432 2432 … … 2441 2441 nic_poll_mode_t mode = IPC_GET_ARG2(*call); 2442 2442 int has_period = IPC_GET_ARG3(*call); 2443 struct time valperiod_buf;2444 struct time val*period = NULL;2443 struct timespec period_buf; 2444 struct timespec *period = NULL; 2445 2445 size_t length; 2446 2446 … … 2453 2453 } 2454 2454 2455 if (length != sizeof(struct time val)) {2455 if (length != sizeof(struct timespec)) { 2456 2456 async_answer_0(&data, ELIMIT); 2457 2457 async_answer_0(call, ELIMIT); -
uspace/lib/drv/include/nic_iface.h
re2625b1a rbd41ac52 106 106 107 107 extern errno_t nic_poll_get_mode(async_sess_t *, nic_poll_mode_t *, 108 struct time val*);108 struct timespec *); 109 109 extern errno_t nic_poll_set_mode(async_sess_t *, nic_poll_mode_t, 110 const struct time val*);110 const struct timespec *); 111 111 extern errno_t nic_poll_now(async_sess_t *); 112 112 -
uspace/lib/drv/include/ops/nic.h
re2625b1a rbd41ac52 39 39 #include <ipc/services.h> 40 40 #include <nic/nic.h> 41 #include < sys/time.h>41 #include <time.h> 42 42 #include "../ddf/driver.h" 43 43 … … 104 104 105 105 errno_t (*poll_get_mode)(ddf_fun_t *, nic_poll_mode_t *, 106 struct time val*);106 struct timespec *); 107 107 errno_t (*poll_set_mode)(ddf_fun_t *, nic_poll_mode_t, 108 const struct time val*);108 const struct timespec *); 109 109 errno_t (*poll_now)(ddf_fun_t *); 110 110 } nic_iface_t; -
uspace/lib/drv/include/pci_dev_iface.h
re2625b1a rbd41ac52 37 37 #ifndef LIBDRV_PCI_DEV_IFACE_H_ 38 38 #define LIBDRV_PCI_DEV_IFACE_H_ 39 40 #include <errno.h> 39 41 40 42 #include "ddf/driver.h" -
uspace/lib/nic/include/nic.h
re2625b1a rbd41ac52 196 196 */ 197 197 typedef errno_t (*poll_mode_change_handler)(nic_t *, 198 nic_poll_mode_t, const struct time val*);198 nic_poll_mode_t, const struct timespec *); 199 199 200 200 /** … … 240 240 extern void nic_set_tx_busy(nic_t *, int); 241 241 extern errno_t nic_report_address(nic_t *, const nic_address_t *); 242 extern errno_t nic_report_poll_mode(nic_t *, nic_poll_mode_t, struct time val*);242 extern errno_t nic_report_poll_mode(nic_t *, nic_poll_mode_t, struct timespec *); 243 243 extern void nic_query_address(nic_t *, nic_address_t *); 244 244 extern void nic_received_frame(nic_t *, nic_frame_t *); 245 245 extern void nic_received_frame_list(nic_t *, nic_frame_list_t *); 246 extern nic_poll_mode_t nic_query_poll_mode(nic_t *, struct time val*);246 extern nic_poll_mode_t nic_query_poll_mode(nic_t *, struct timespec *); 247 247 248 248 /* Statistics updates */ -
uspace/lib/nic/include/nic_driver.h
re2625b1a rbd41ac52 83 83 nic_poll_mode_t poll_mode; 84 84 /** Polling period (applicable when poll_mode == NIC_POLL_PERIODIC) */ 85 struct time valpoll_period;85 struct timespec poll_period; 86 86 /** Current polling mode of the NIC */ 87 87 nic_poll_mode_t default_poll_mode; 88 88 /** Polling period (applicable when default_poll_mode == NIC_POLL_PERIODIC) */ 89 struct time valdefault_poll_period;89 struct timespec default_poll_period; 90 90 /** Software period fibrill information */ 91 91 struct sw_poll_info sw_poll_info; -
uspace/lib/nic/include/nic_impl.h
re2625b1a rbd41ac52 78 78 extern errno_t nic_wol_virtue_get_caps_impl(ddf_fun_t *, nic_wv_type_t, int *); 79 79 extern errno_t nic_poll_get_mode_impl(ddf_fun_t *, 80 nic_poll_mode_t *, struct time val*);80 nic_poll_mode_t *, struct timespec *); 81 81 extern errno_t nic_poll_set_mode_impl(ddf_fun_t *, 82 nic_poll_mode_t, const struct time val*);82 nic_poll_mode_t, const struct timespec *); 83 83 extern errno_t nic_poll_now_impl(ddf_fun_t *); 84 84 -
uspace/lib/nic/src/nic_driver.c
re2625b1a rbd41ac52 384 384 * @return Current polling mode of the controller 385 385 */ 386 nic_poll_mode_t nic_query_poll_mode(nic_t *nic_data, struct time val*period)386 nic_poll_mode_t nic_query_poll_mode(nic_t *nic_data, struct timespec *period) 387 387 { 388 388 if (period) … … 400 400 */ 401 401 errno_t nic_report_poll_mode(nic_t *nic_data, nic_poll_mode_t mode, 402 struct time val*period)402 struct timespec *period) 403 403 { 404 404 errno_t rc = EOK; … … 408 408 if (mode == NIC_POLL_PERIODIC) { 409 409 if (period) { 410 memcpy(&nic_data->default_poll_period, period, sizeof(struct time val));411 memcpy(&nic_data->poll_period, period, sizeof(struct time val));410 memcpy(&nic_data->default_poll_period, period, sizeof(struct timespec)); 411 memcpy(&nic_data->poll_period, period, sizeof(struct timespec)); 412 412 } else { 413 413 rc = EINVAL; … … 1030 1030 * @returns Nonzero if t is zero interval 1031 1031 */ 1032 static int time val_nonpositive(struct timevalt)1033 { 1034 return (t.tv_sec <= 0) && (t.tv_ usec <= 0);1032 static int timespec_nonpositive(struct timespec t) 1033 { 1034 return (t.tv_sec <= 0) && (t.tv_nsec <= 0); 1035 1035 } 1036 1036 … … 1051 1051 int run = info->run; 1052 1052 int running = info->running; 1053 struct time valremaining = nic->poll_period;1053 struct timespec remaining = nic->poll_period; 1054 1054 fibril_rwlock_read_unlock(&nic->main_lock); 1055 1055 1056 1056 if (!running) { 1057 1057 remaining.tv_sec = 5; 1058 remaining.tv_ usec = 0;1058 remaining.tv_nsec = 0; 1059 1059 } 1060 1060 1061 1061 /* Wait the period (keep attention to overflows) */ 1062 while (!time val_nonpositive(remaining)) {1063 suseconds_t wait = 0;1062 while (!timespec_nonpositive(remaining)) { 1063 usec_t wait = 0; 1064 1064 if (remaining.tv_sec > 0) { 1065 1065 time_t wait_sec = remaining.tv_sec; … … 1071 1071 wait_sec = 5; 1072 1072 1073 wait = (suseconds_t) wait_sec * 1000000;1073 wait = SEC2USEC(wait_sec); 1074 1074 1075 1075 remaining.tv_sec -= wait_sec; 1076 1076 } else { 1077 wait = remaining.tv_usec;1077 wait = NSEC2USEC(remaining.tv_nsec); 1078 1078 1079 1079 if (wait > 5 * 1000000) { … … 1081 1081 } 1082 1082 1083 remaining.tv_ usec -= wait;1083 remaining.tv_nsec -= USEC2NSEC(wait); 1084 1084 } 1085 1085 fibril_usleep(wait); -
uspace/lib/nic/src/nic_impl.c
re2625b1a rbd41ac52 121 121 nic_data->poll_mode = nic_data->default_poll_mode; 122 122 memcpy(&nic_data->poll_period, &nic_data->default_poll_period, 123 sizeof(struct time val));123 sizeof(struct timespec)); 124 124 if (rc != EOK) { 125 125 /* … … 714 714 */ 715 715 errno_t nic_poll_get_mode_impl(ddf_fun_t *fun, 716 nic_poll_mode_t *mode, struct time val*period)716 nic_poll_mode_t *mode, struct timespec *period) 717 717 { 718 718 nic_t *nic_data = nic_get_from_ddf_fun(fun); 719 719 fibril_rwlock_read_lock(&nic_data->main_lock); 720 720 *mode = nic_data->poll_mode; 721 memcpy(period, &nic_data->poll_period, sizeof(struct time val));721 memcpy(period, &nic_data->poll_period, sizeof(struct timespec)); 722 722 fibril_rwlock_read_unlock(&nic_data->main_lock); 723 723 return EOK; … … 737 737 */ 738 738 errno_t nic_poll_set_mode_impl(ddf_fun_t *fun, 739 nic_poll_mode_t mode, const struct time val*period)739 nic_poll_mode_t mode, const struct timespec *period) 740 740 { 741 741 nic_t *nic_data = nic_get_from_ddf_fun(fun); … … 753 753 if (period == NULL) 754 754 return EINVAL; 755 if (period->tv_sec == 0 && period->tv_ usec == 0)755 if (period->tv_sec == 0 && period->tv_nsec == 0) 756 756 return EINVAL; 757 if (period->tv_sec < 0 || period->tv_ usec < 0)757 if (period->tv_sec < 0 || period->tv_nsec < 0) 758 758 return EINVAL; 759 759 } -
uspace/lib/pcm/include/pcm/format.h
re2625b1a rbd41ac52 80 80 * @return Number of microseconds. 81 81 */ 82 static inline useconds_t pcm_format_size_to_usec(size_t size, 83 const pcm_format_t *a) 82 static inline usec_t pcm_format_size_to_usec(size_t size, const pcm_format_t *a) 84 83 { 85 84 return pcm_sample_format_size_to_usec(size, a->sampling_rate, -
uspace/lib/pcm/include/pcm/sample_format.h
re2625b1a rbd41ac52 167 167 * @return Number of useconds of audio data. 168 168 */ 169 static inline usec onds_t pcm_sample_format_size_to_usec(size_t size,169 static inline usec_t pcm_sample_format_size_to_usec(size_t size, 170 170 unsigned sample_rate, unsigned channels, pcm_sample_format_t format) 171 171 { -
uspace/lib/pcut/src/os/helenos.c
re2625b1a rbd41ac52 141 141 pcut_item_t *test = arg; 142 142 int timeout_sec = pcut_get_test_timeout(test); 143 suseconds_t timeout_us = (suseconds_t) timeout_sec * 1000 * 1000;143 usec_t timeout_us = SEC2USEC(timeout_sec); 144 144 145 145 fibril_mutex_lock(&forced_termination_mutex); -
uspace/lib/posix/include/posix/sys/time.h
re2625b1a rbd41ac52 34 34 #define POSIX_SYS_TIME_H_ 35 35 36 #include "libc/sys/time.h" 36 #include "libc/time.h" 37 38 struct timeval { 39 time_t tv_sec; /* seconds */ 40 suseconds_t tv_usec; /* microseconds */ 41 }; 42 43 extern int gettimeofday(struct timeval *, void *); 37 44 38 45 #endif -
uspace/lib/posix/include/posix/sys/types.h
re2625b1a rbd41ac52 38 38 39 39 #include "libc/offset.h" 40 #include "libc/sys/time.h"41 40 #include "libc/types/common.h" 42 41 … … 56 55 57 56 /* Clock Types */ 58 typedef long clock_t;59 57 typedef int clockid_t; 60 58 59 typedef long suseconds_t; 61 60 62 61 #endif /* POSIX_SYS_TYPES_H_ */ -
uspace/lib/posix/include/posix/time.h
re2625b1a rbd41ac52 41 41 #include <_bits/NULL.h> 42 42 43 #ifndef CLOCKS_PER_SEC 44 #define CLOCKS_PER_SEC (1000000L) 45 #endif 43 #include "libc/time.h" 46 44 47 45 #ifndef __locale_t_defined … … 57 55 #define CLOCK_REALTIME ((clockid_t) 0) 58 56 59 struct timespec { 60 time_t tv_sec; /* Seconds. */ 61 long tv_nsec; /* Nanoseconds. */ 62 }; 57 #define ASCTIME_BUF_LEN 26 63 58 64 59 struct itimerspec { … … 104 99 const struct timespec *rqtp, struct timespec *rmtp); 105 100 106 /* CPU Time */107 extern clock_t clock(void);108 109 110 101 #endif // POSIX_TIME_H_ 111 102 -
uspace/lib/posix/src/internal/common.h
re2625b1a rbd41ac52 38 38 #include <stdio.h> 39 39 #include <stdlib.h> 40 #include <errno.h> 40 41 #include <offset.h> 41 42 #include <vfs/vfs.h> -
uspace/lib/posix/src/time.c
re2625b1a rbd41ac52 35 35 36 36 #include "internal/common.h" 37 #include "posix/sys/types.h" 38 #include "posix/sys/time.h" 37 39 #include "posix/time.h" 38 40 … … 47 49 #include "libc/malloc.h" 48 50 #include "libc/task.h" 49 #include "libc/stats.h"50 51 #include "libc/stddef.h" 51 #include "libc/ sys/time.h"52 #include "libc/time.h" 52 53 53 54 // TODO: test everything in this file … … 219 220 case CLOCK_REALTIME: 220 221 res->tv_sec = 0; 221 res->tv_nsec = 1000; /* Microsecond resolution. */222 res->tv_nsec = USEC2NSEC(1); /* Microsecond resolution. */ 222 223 return 0; 223 224 default: … … 244 245 gettimeofday(&tv, NULL); 245 246 tp->tv_sec = tv.tv_sec; 246 tp->tv_nsec = tv.tv_usec * 1000;247 tp->tv_nsec = USEC2NSEC(tv.tv_usec); 247 248 return 0; 248 249 default: … … 300 301 } 301 302 if (rqtp->tv_nsec != 0) { 302 fibril_usleep( rqtp->tv_nsec / 1000);303 fibril_usleep(NSEC2USEC(rqtp->tv_nsec)); 303 304 } 304 305 return 0; … … 309 310 } 310 311 311 /** 312 * Get CPU time used since the process invocation. 313 * 314 * @return Consumed CPU cycles by this process or -1 if not available. 315 */ 316 clock_t clock(void) 317 { 318 clock_t total_cycles = -1; 319 stats_task_t *task_stats = stats_get_task(task_get_id()); 320 if (task_stats) { 321 total_cycles = (clock_t) (task_stats->kcycles + 322 task_stats->ucycles); 323 free(task_stats); 324 task_stats = 0; 325 } 326 327 return total_cycles; 312 int gettimeofday(struct timeval *tv, void *tz) 313 { 314 struct timespec ts; 315 316 getrealtime(&ts); 317 tv->tv_sec = ts.tv_sec; 318 tv->tv_usec = NSEC2USEC(ts.tv_nsec); 319 320 return 0; 328 321 } 329 322 -
uspace/lib/usb/include/usb/port.h
re2625b1a rbd41ac52 90 90 91 91 /* And these are to be called from the connected handler. */ 92 int usb_port_condvar_wait_timeout(usb_port_t *port, 93 fibril_condvar_t *, suseconds_t); 92 int usb_port_condvar_wait_timeout(usb_port_t *port, fibril_condvar_t *, usec_t); 94 93 95 94 /** -
uspace/lib/usb/src/port.c
re2625b1a rbd41ac52 237 237 } 238 238 239 int usb_port_condvar_wait_timeout(usb_port_t *port, fibril_condvar_t *cv, suseconds_t timeout) 239 int usb_port_condvar_wait_timeout(usb_port_t *port, fibril_condvar_t *cv, 240 usec_t timeout) 240 241 { 241 242 assert(port); -
uspace/lib/usbhost/include/usb/host/endpoint.h
re2625b1a rbd41ac52 45 45 #include <refcount.h> 46 46 #include <stdbool.h> 47 #include < sys/time.h>47 #include <time.h> 48 48 #include <usb/usb.h> 49 49 #include <usb/host/bus.h> … … 125 125 extern void endpoint_set_offline_locked(endpoint_t *); 126 126 127 extern void endpoint_wait_timeout_locked(endpoint_t *ep, suseconds_t);127 extern void endpoint_wait_timeout_locked(endpoint_t *ep, usec_t); 128 128 extern int endpoint_activate_locked(endpoint_t *, usb_transfer_batch_t *); 129 129 extern void endpoint_deactivate_locked(endpoint_t *); -
uspace/lib/usbhost/src/endpoint.c
re2625b1a rbd41ac52 145 145 * offline (and is interrupted by the endpoint going offline). 146 146 */ 147 void endpoint_wait_timeout_locked(endpoint_t *ep, suseconds_t timeout)147 void endpoint_wait_timeout_locked(endpoint_t *ep, usec_t timeout) 148 148 { 149 149 assert(ep);
Note:
See TracChangeset
for help on using the changeset viewer.