Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_time.c
Show First 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | if (error == 0) | ||||
error = copyout(&ats, uap->tp, sizeof(ats)); | error = copyout(&ats, uap->tp, sizeof(ats)); | ||||
return (error); | return (error); | ||||
} | } | ||||
static inline void | static inline void | ||||
cputick2timespec(uint64_t runtime, struct timespec *ats) | cputick2timespec(uint64_t runtime, struct timespec *ats) | ||||
{ | { | ||||
runtime = cputick2usec(runtime); | uint64_t tr; | ||||
ats->tv_sec = runtime / 1000000; | tr = cpu_tickrate(); | ||||
ats->tv_nsec = runtime % 1000000 * 1000; | ats->tv_sec = runtime / tr; | ||||
ats->tv_nsec = ((runtime % tr) * 1000000000ULL) / tr; | |||||
} | } | ||||
void | void | ||||
kern_thread_cputime(struct thread *targettd, struct timespec *ats) | kern_thread_cputime(struct thread *targettd, struct timespec *ats) | ||||
{ | { | ||||
uint64_t runtime, curtime, switchtime; | uint64_t runtime, curtime, switchtime; | ||||
if (targettd == NULL) { /* current thread */ | if (targettd == NULL) { /* current thread */ | ||||
▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | case CLOCK_PROF: | ||||
break; | break; | ||||
case CLOCK_SECOND: | case CLOCK_SECOND: | ||||
ts->tv_sec = 1; | ts->tv_sec = 1; | ||||
ts->tv_nsec = 0; | ts->tv_nsec = 0; | ||||
break; | break; | ||||
case CLOCK_THREAD_CPUTIME_ID: | case CLOCK_THREAD_CPUTIME_ID: | ||||
case CLOCK_PROCESS_CPUTIME_ID: | case CLOCK_PROCESS_CPUTIME_ID: | ||||
cputime: | cputime: | ||||
/* sync with cputick2usec */ | ts->tv_nsec = 1000000000 / cpu_tickrate() + 1; | ||||
ts->tv_nsec = 1000000 / cpu_tickrate(); | |||||
if (ts->tv_nsec == 0) | |||||
ts->tv_nsec = 1000; | |||||
break; | break; | ||||
default: | default: | ||||
if ((int)clock_id < 0) | if ((int)clock_id < 0) | ||||
goto cputime; | goto cputime; | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,347 Lines • Show Last 20 Lines |