From ae86af8218f9798ff70696ccc00d8f840fe386e0 Mon Sep 17 00:00:00 2001 From: davidxu Date: Fri, 18 Jan 2008 13:00:28 +0000 Subject: [PATCH] Make sure reading td_runtime in critical section since thread may be preempted and td_runtime will be modified. --- sys/kern/kern_time.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 6df10fa07590..366da9da5007 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -247,8 +247,9 @@ kern_clock_gettime(struct thread *td, clockid_t clock_id, struct timespec *ats) critical_enter(); switchtime = PCPU_GET(switchtime); curtime = cpu_ticks(); + runtime = td->td_runtime; critical_exit(); - runtime = cputick2usec(td->td_runtime + curtime - switchtime); + runtime = cputick2usec(runtime + curtime - switchtime); ats->tv_sec = runtime / 1000000; ats->tv_nsec = runtime % 1000000 * 1000; break;