Move most clock_getres syscall code, except for coypout call, to a new

clock_getres1() function which can be used by emulations. Adjust all
clock_getres syscalls to now make of use it.
This commit is contained in:
njoly 2010-04-03 17:20:05 +00:00
parent 7fe08819d5
commit 0876f873dd
7 changed files with 58 additions and 65 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_time_50.c,v 1.13 2010/01/19 22:28:31 pooka Exp $ */
/* $NetBSD: kern_time_50.c,v 1.14 2010/04/03 17:20:05 njoly Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_time_50.c,v 1.13 2010/01/19 22:28:31 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_time_50.c,v 1.14 2010/04/03 17:20:05 njoly Exp $");
#ifdef _KERNEL_OPT
#include "opt_aio.h"
@ -54,7 +54,6 @@ __KERNEL_RCSID(0, "$NetBSD: kern_time_50.c,v 1.13 2010/01/19 22:28:31 pooka Exp
#include <sys/kauth.h>
#include <sys/time.h>
#include <sys/timex.h>
#include <sys/timetc.h>
#include <sys/aio.h>
#include <sys/poll.h>
#include <sys/syscallargs.h>
@ -165,26 +164,18 @@ compat_50_sys_clock_getres(struct lwp *l,
syscallarg(clockid_t) clock_id;
syscallarg(struct timespec50 *) tp;
} */
clockid_t clock_id;
struct timespec50 ats50;
struct timespec ats;
int error = 0;
clock_id = SCARG(uap, clock_id);
switch (clock_id) {
case CLOCK_REALTIME:
case CLOCK_MONOTONIC:
ats50.tv_sec = 0;
if (tc_getfrequency() > 1000000000)
ats50.tv_nsec = 1;
else
ats50.tv_nsec = 1000000000 / tc_getfrequency();
break;
default:
return (EINVAL);
}
error = clock_getres1(SCARG(uap, clock_id), &ats);
if (error != 0)
return error;
if (SCARG(uap, tp))
error = copyout(&ats50, SCARG(uap, tp), sizeof(*SCARG(uap, tp)));
if (SCARG(uap, tp)) {
timespec_to_timespec50(&ats, &ats50);
error = copyout(&ats50, SCARG(uap, tp), sizeof(ats50));
}
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux_time.c,v 1.30 2010/03/29 15:34:07 njoly Exp $ */
/* $NetBSD: linux_time.c,v 1.31 2010/04/03 17:20:05 njoly Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.30 2010/03/29 15:34:07 njoly Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.31 2010/04/03 17:20:05 njoly Exp $");
#include <sys/param.h>
#include <sys/ucred.h>
@ -39,7 +39,6 @@ __KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.30 2010/03/29 15:34:07 njoly Exp $"
#include <sys/signal.h>
#include <sys/stdint.h>
#include <sys/time.h>
#include <sys/timetc.h>
#include <sys/systm.h>
#include <sys/sched.h>
#include <sys/syscallargs.h>
@ -254,8 +253,10 @@ linux_sys_clock_getres(struct lwp *l, const struct linux_sys_clock_getres_args *
if (error != 0 || SCARG(uap, tp) == NULL)
return error;
ts.tv_sec = 0;
ts.tv_nsec = 1000000000 / tc_getfrequency();
error = clock_getres1(nwhich, &ts);
if (error != 0)
return error;
native_to_linux_timespec(&lts, &ts);
return copyout(&lts, SCARG(uap, tp), sizeof lts);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux32_time.c,v 1.30 2010/03/29 15:34:07 njoly Exp $ */
/* $NetBSD: linux32_time.c,v 1.31 2010/04/03 17:20:05 njoly Exp $ */
/*-
* Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@ -33,7 +33,7 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.30 2010/03/29 15:34:07 njoly Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.31 2010/04/03 17:20:05 njoly Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -50,7 +50,6 @@ __KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.30 2010/03/29 15:34:07 njoly Exp
#include <sys/ucred.h>
#include <sys/swap.h>
#include <sys/vfs_syscalls.h>
#include <sys/timetc.h>
#include <machine/types.h>
@ -343,8 +342,10 @@ linux32_sys_clock_getres(struct lwp *l,
if (error != 0 || SCARG_P32(uap, tp) == NULL)
return error;
ts.tv_sec = 0;
ts.tv_nsec = 1000000000 / tc_getfrequency();
error = clock_getres1(id, &ts);
if (error != 0)
return error;
native_to_linux32_timespec(&lts, &ts);
return copyout(&lts, SCARG_P32(uap, tp), sizeof lts);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: netbsd32_compat_50.c,v 1.13 2010/03/29 15:34:07 njoly Exp $ */
/* $NetBSD: netbsd32_compat_50.c,v 1.14 2010/04/03 17:20:05 njoly Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -36,7 +36,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.13 2010/03/29 15:34:07 njoly Exp $");
__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.14 2010/04/03 17:20:05 njoly Exp $");
#if defined(_KERNEL_OPT)
#include "opt_sysv.h"
@ -354,18 +354,14 @@ compat_50_netbsd32_clock_getres(struct lwp *l,
syscallarg(netbsd32_timespec50p_t) tp;
} */
struct netbsd32_timespec50 ts32;
clockid_t clock_id;
struct timespec ts;
int error = 0;
clock_id = SCARG(uap, clock_id);
if (clock_id != CLOCK_REALTIME)
return (EINVAL);
error = clock_getres1(SCARG(uap, clock_id), &ts);
if (error != 0)
return error;
if (SCARG_P32(uap, tp)) {
ts.tv_sec = 0;
ts.tv_nsec = 1000000000 / hz;
netbsd32_from_timespec50(&ts, &ts32);
error = copyout(&ts32, SCARG_P32(uap, tp), sizeof(ts32));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: netbsd32_time.c,v 1.39 2010/03/29 15:34:07 njoly Exp $ */
/* $NetBSD: netbsd32_time.c,v 1.40 2010/04/03 17:20:05 njoly Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_time.c,v 1.39 2010/03/29 15:34:07 njoly Exp $");
__KERNEL_RCSID(0, "$NetBSD: netbsd32_time.c,v 1.40 2010/04/03 17:20:05 njoly Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ntp.h"
@ -40,7 +40,6 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_time.c,v 1.39 2010/03/29 15:34:07 njoly Exp
#include <sys/time.h>
#include <sys/timex.h>
#include <sys/timevar.h>
#include <sys/timetc.h>
#include <sys/proc.h>
#include <sys/pool.h>
#include <sys/resourcevar.h>
@ -394,18 +393,14 @@ netbsd32___clock_getres50(struct lwp *l, const struct netbsd32___clock_getres50_
syscallarg(netbsd32_timespecp_t) tp;
} */
struct netbsd32_timespec ts32;
clockid_t clock_id;
struct timespec ts;
int error = 0;
clock_id = SCARG(uap, clock_id);
if (clock_id != CLOCK_REALTIME)
return (EINVAL);
error = clock_getres1(SCARG(uap, clock_id), &ts);
if (error != 0)
return error;
if (SCARG_P32(uap, tp)) {
ts.tv_sec = 0;
ts.tv_nsec = 1000000000 / hz;
netbsd32_from_timespec(&ts, &ts32);
error = copyout(&ts32, SCARG_P32(uap, tp), sizeof(ts32));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_time.c,v 1.163 2009/12/10 12:39:12 drochner Exp $ */
/* $NetBSD: kern_time.c,v 1.164 2010/04/03 17:20:05 njoly Exp $ */
/*-
* Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.163 2009/12/10 12:39:12 drochner Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.164 2010/04/03 17:20:05 njoly Exp $");
#include <sys/param.h>
#include <sys/resourcevar.h>
@ -243,23 +243,11 @@ sys___clock_getres50(struct lwp *l, const struct sys___clock_getres50_args *uap,
syscallarg(clockid_t) clock_id;
syscallarg(struct timespec *) tp;
} */
clockid_t clock_id;
struct timespec ts;
int error = 0;
clock_id = SCARG(uap, clock_id);
switch (clock_id) {
case CLOCK_REALTIME:
case CLOCK_MONOTONIC:
ts.tv_sec = 0;
if (tc_getfrequency() > 1000000000)
ts.tv_nsec = 1;
else
ts.tv_nsec = 1000000000 / tc_getfrequency();
break;
default:
return (EINVAL);
}
if ((error = clock_getres1(SCARG(uap, clock_id), &ts)) != 0)
return error;
if (SCARG(uap, tp))
error = copyout(&ts, SCARG(uap, tp), sizeof(ts));
@ -267,6 +255,26 @@ sys___clock_getres50(struct lwp *l, const struct sys___clock_getres50_args *uap,
return error;
}
int
clock_getres1(clockid_t clock_id, struct timespec *ts)
{
switch (clock_id) {
case CLOCK_REALTIME:
case CLOCK_MONOTONIC:
ts->tv_sec = 0;
if (tc_getfrequency() > 1000000000)
ts->tv_nsec = 1;
else
ts->tv_nsec = 1000000000 / tc_getfrequency();
break;
default:
return EINVAL;
}
return 0;
}
/* ARGSUSED */
int
sys___nanosleep50(struct lwp *l, const struct sys___nanosleep50_args *uap,

View File

@ -1,4 +1,4 @@
/* $NetBSD: timevar.h,v 1.27 2009/11/01 21:46:09 rmind Exp $ */
/* $NetBSD: timevar.h,v 1.28 2010/04/03 17:20:05 njoly Exp $ */
/*
* Copyright (c) 2005, 2008 The NetBSD Foundation.
@ -147,6 +147,7 @@ void getmicrotime(struct timeval *);
/* Other functions */
int abstimeout2timo(struct timespec *, int *);
void adjtime1(const struct timeval *, struct timeval *, struct proc *);
int clock_getres1(clockid_t, struct timespec *);
int clock_settime1(struct proc *, clockid_t, const struct timespec *, bool);
int dogetitimer(struct proc *, int, struct itimerval *);
int dosetitimer(struct proc *, int, struct itimerval *);