aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorKelly Yancey <kbyanc@FreeBSD.org>2004-06-21 22:34:57 +0000
committerKelly Yancey <kbyanc@FreeBSD.org>2004-06-21 22:34:57 +0000
commitde0a924120fe2da3e57e6982315f55c86088b5a6 (patch)
treebea86bd2c64d0b7d635e9a74a48b08143f618674 /sys
parentdc0957941727eb13b424fcb0f300dcc2f8f6f104 (diff)
downloadsrc-de0a924120fe2da3e57e6982315f55c86088b5a6.tar.gz
src-de0a924120fe2da3e57e6982315f55c86088b5a6.zip
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
Notes
Notes: svn path=/head/; revision=130884
Diffstat (limited to 'sys')
-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 3f11710d4806..1a6819835a44 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;