Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_time.c
Show First 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
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 */ | ||||
critical_enter(); | spinlock_enter(); | ||||
switchtime = PCPU_GET(switchtime); | switchtime = PCPU_GET(switchtime); | ||||
curtime = cpu_ticks(); | curtime = cpu_ticks(); | ||||
runtime = curthread->td_runtime; | runtime = curthread->td_runtime; | ||||
critical_exit(); | spinlock_exit(); | ||||
runtime += curtime - switchtime; | runtime += curtime - switchtime; | ||||
} else { | } else { | ||||
PROC_LOCK_ASSERT(targettd->td_proc, MA_OWNED); | PROC_LOCK_ASSERT(targettd->td_proc, MA_OWNED); | ||||
thread_lock(targettd); | thread_lock(targettd); | ||||
runtime = targettd->td_runtime; | runtime = targettd->td_runtime; | ||||
thread_unlock(targettd); | thread_unlock(targettd); | ||||
} | } | ||||
cputick2timespec(runtime, ats); | cputick2timespec(runtime, ats); | ||||
▲ Show 20 Lines • Show All 1,567 Lines • Show Last 20 Lines |