| 442 | } |
| 443 | |
| 444 | int |
| 445 | kern_clock_getres(struct thread *td, clockid_t clock_id, struct timespec *ts) |
| 446 | { |
| 447 | |
| 448 | ts->tv_sec = 0; |
| 449 | switch (clock_id) { |
| 450 | case CLOCK_REALTIME: |
| 451 | case CLOCK_REALTIME_FAST: |
| 452 | case CLOCK_REALTIME_PRECISE: |
| 453 | case CLOCK_MONOTONIC: |
| 454 | case CLOCK_MONOTONIC_FAST: |
| 455 | case CLOCK_MONOTONIC_PRECISE: |
| 456 | case CLOCK_UPTIME: |
| 457 | case CLOCK_UPTIME_FAST: |
| 458 | case CLOCK_UPTIME_PRECISE: |
| 459 | /* |
| 460 | * Round up the result of the division cheaply by adding 1. |
| 461 | * Rounding up is especially important if rounding down |
| 462 | * would give 0. Perfect rounding is unimportant. |
| 463 | */ |
| 464 | ts->tv_nsec = 1000000000 / tc_getfrequency() + 1; |
| 465 | break; |
| 466 | case CLOCK_VIRTUAL: |
| 467 | case CLOCK_PROF: |
| 468 | /* Accurately round up here because we can do so cheaply. */ |
| 469 | ts->tv_nsec = howmany(1000000000, hz); |
| 470 | break; |
| 471 | case CLOCK_SECOND: |
| 472 | ts->tv_sec = 1; |
| 473 | ts->tv_nsec = 0; |
| 474 | break; |
| 475 | case CLOCK_THREAD_CPUTIME_ID: |
| 476 | case CLOCK_PROCESS_CPUTIME_ID: |
| 477 | cputime: |
| 478 | /* sync with cputick2usec */ |
| 479 | ts->tv_nsec = 1000000 / cpu_tickrate(); |
| 480 | if (ts->tv_nsec == 0) |
| 481 | ts->tv_nsec = 1000; |
| 482 | break; |
| 483 | default: |
| 484 | if ((int)clock_id < 0) |
| 485 | goto cputime; |
| 486 | return (EINVAL); |
| 487 | } |
| 488 | return (0); |
| 489 | } |
| 490 | |
| 491 | int |
| 492 | kern_nanosleep(struct thread *td, struct timespec *rqt, struct timespec *rmt) |
no test coverage detected