summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_time.c
diff options
context:
space:
mode:
authorkbyanc <kbyanc@FreeBSD.org>2004-06-21 22:34:57 +0000
committerkbyanc <kbyanc@FreeBSD.org>2004-06-21 22:34:57 +0000
commit1e3cfa985ef55d17e4ff01f07b06e5a736dba907 (patch)
treebea86bd2c64d0b7d635e9a74a48b08143f618674 /sys/kern/kern_time.c
parent95c9bdb62a7bd5836e288a429e5b1e8cc1c7f454 (diff)
downloadFreeBSD-src-1e3cfa985ef55d17e4ff01f07b06e5a736dba907.zip
FreeBSD-src-1e3cfa985ef55d17e4ff01f07b06e5a736dba907.tar.gz
Update previous commit to:
* Obtain/release schedlock around calls to calcru. * Sort switch cases which do not cascade per style(9). * Sort local variables per style(9). * Remove "superfluous" whitespace. * Cleanup handling of NULL uap->tp in clock_getres(). It would probably be better to return EFAULT like clock_gettime() does by passing the pointer to copyout(), but I presume it was written to not fail on purpose in the original code. I'll defer to -standards on this one. Reported by: bde
Diffstat (limited to 'sys/kern/kern_time.c')
-rw-r--r--sys/kern/kern_time.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index 3f11710..1a68198 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -156,27 +156,27 @@ int
clock_gettime(struct thread *td, struct clock_gettime_args *uap)
{
struct timespec ats;
- struct timeval user, sys;
+ struct timeval sys, user;
switch (uap->clock_id) {
case CLOCK_REALTIME:
nanotime(&ats);
break;
- case CLOCK_MONOTONIC:
- nanouptime(&ats);
- break;
case CLOCK_VIRTUAL:
+ mtx_lock_spin(&sched_lock);
calcru(td->td_proc, &user, &sys, NULL);
+ mtx_unlock_spin(&sched_lock);
TIMEVAL_TO_TIMESPEC(&user, &ats);
break;
case CLOCK_PROF:
+ mtx_lock_spin(&sched_lock);
calcru(td->td_proc, &user, &sys, NULL);
- ats.tv_sec = user.tv_sec + sys.tv_sec;
- ats.tv_nsec = (user.tv_usec + sys.tv_usec) * 1000;
- if (ats.tv_nsec > 1000000000) {
- ats.tv_sec++;
- ats.tv_nsec -= 1000000000;
- }
+ mtx_unlock_spin(&sched_lock);
+ timevaladd(&user, &sys);
+ TIMEVAL_TO_TIMESPEC(&user, &ats);
+ break;
+ case CLOCK_MONOTONIC:
+ nanouptime(&ats);
break;
default:
return (EINVAL);
@@ -232,10 +232,8 @@ int
clock_getres(struct thread *td, struct clock_getres_args *uap)
{
struct timespec ts;
- int error;
ts.tv_sec = 0;
-
switch (uap->clock_id) {
case CLOCK_REALTIME:
case CLOCK_MONOTONIC:
@@ -254,12 +252,9 @@ clock_getres(struct thread *td, struct clock_getres_args *uap)
default:
return (EINVAL);
}
-
- error = 0;
- if (uap->tp)
- error = copyout(&ts, uap->tp, sizeof(ts));
-
- return (error);
+ if (uap->tp == NULL)
+ return (0);
+ return (copyout(&ts, uap->tp, sizeof(ts)));
}
static int nanowait;
OpenPOWER on IntegriCloud