Module Name:    src
Committed By:   njoly
Date:           Sat Apr  3 17:20:06 UTC 2010

Modified Files:
        src/sys/compat/common: kern_time_50.c
        src/sys/compat/linux/common: linux_time.c
        src/sys/compat/linux32/common: linux32_time.c
        src/sys/compat/netbsd32: netbsd32_compat_50.c netbsd32_time.c
        src/sys/kern: kern_time.c
        src/sys/sys: timevar.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/compat/common/kern_time_50.c
cvs rdiff -u -r1.30 -r1.31 src/sys/compat/linux/common/linux_time.c
cvs rdiff -u -r1.30 -r1.31 src/sys/compat/linux32/common/linux32_time.c
cvs rdiff -u -r1.13 -r1.14 src/sys/compat/netbsd32/netbsd32_compat_50.c
cvs rdiff -u -r1.39 -r1.40 src/sys/compat/netbsd32/netbsd32_time.c
cvs rdiff -u -r1.163 -r1.164 src/sys/kern/kern_time.c
cvs rdiff -u -r1.27 -r1.28 src/sys/sys/timevar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/common/kern_time_50.c
diff -u src/sys/compat/common/kern_time_50.c:1.13 src/sys/compat/common/kern_time_50.c:1.14
--- src/sys/compat/common/kern_time_50.c:1.13	Tue Jan 19 22:28:31 2010
+++ src/sys/compat/common/kern_time_50.c	Sat Apr  3 17:20:05 2010
@@ -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 @@
 #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 @@
 		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;
 }

Index: src/sys/compat/linux/common/linux_time.c
diff -u src/sys/compat/linux/common/linux_time.c:1.30 src/sys/compat/linux/common/linux_time.c:1.31
--- src/sys/compat/linux/common/linux_time.c:1.30	Mon Mar 29 15:34:07 2010
+++ src/sys/compat/linux/common/linux_time.c	Sat Apr  3 17:20:05 2010
@@ -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 @@
 #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 @@
 	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);
 }

Index: src/sys/compat/linux32/common/linux32_time.c
diff -u src/sys/compat/linux32/common/linux32_time.c:1.30 src/sys/compat/linux32/common/linux32_time.c:1.31
--- src/sys/compat/linux32/common/linux32_time.c:1.30	Mon Mar 29 15:34:07 2010
+++ src/sys/compat/linux32/common/linux32_time.c	Sat Apr  3 17:20:05 2010
@@ -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 @@
 #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 @@
 	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);
 }

Index: src/sys/compat/netbsd32/netbsd32_compat_50.c
diff -u src/sys/compat/netbsd32/netbsd32_compat_50.c:1.13 src/sys/compat/netbsd32/netbsd32_compat_50.c:1.14
--- src/sys/compat/netbsd32/netbsd32_compat_50.c:1.13	Mon Mar 29 15:34:07 2010
+++ src/sys/compat/netbsd32/netbsd32_compat_50.c	Sat Apr  3 17:20:05 2010
@@ -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 @@
 		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));
 	}

Index: src/sys/compat/netbsd32/netbsd32_time.c
diff -u src/sys/compat/netbsd32/netbsd32_time.c:1.39 src/sys/compat/netbsd32/netbsd32_time.c:1.40
--- src/sys/compat/netbsd32/netbsd32_time.c:1.39	Mon Mar 29 15:34:07 2010
+++ src/sys/compat/netbsd32/netbsd32_time.c	Sat Apr  3 17:20:05 2010
@@ -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 @@
 #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 @@
 		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));
 	}

Index: src/sys/kern/kern_time.c
diff -u src/sys/kern/kern_time.c:1.163 src/sys/kern/kern_time.c:1.164
--- src/sys/kern/kern_time.c:1.163	Thu Dec 10 12:39:12 2009
+++ src/sys/kern/kern_time.c	Sat Apr  3 17:20:05 2010
@@ -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,28 +243,36 @@
 		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);
+	if ((error = clock_getres1(SCARG(uap, clock_id), &ts)) != 0)
+		return error;
+
+	if (SCARG(uap, tp))
+		error = copyout(&ts, SCARG(uap, tp), sizeof(ts));
+
+	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;
+		ts->tv_sec = 0;
 		if (tc_getfrequency() > 1000000000)
-			ts.tv_nsec = 1;
+			ts->tv_nsec = 1;
 		else
-			ts.tv_nsec = 1000000000 / tc_getfrequency();
+			ts->tv_nsec = 1000000000 / tc_getfrequency();
 		break;
 	default:
-		return (EINVAL);
+		return EINVAL;
 	}
 
-	if (SCARG(uap, tp))
-		error = copyout(&ts, SCARG(uap, tp), sizeof(ts));
-
-	return error;
+	return 0;
 }
 
 /* ARGSUSED */

Index: src/sys/sys/timevar.h
diff -u src/sys/sys/timevar.h:1.27 src/sys/sys/timevar.h:1.28
--- src/sys/sys/timevar.h:1.27	Sun Nov  1 21:46:09 2009
+++ src/sys/sys/timevar.h	Sat Apr  3 17:20:05 2010
@@ -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 @@
 /* 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 *);

Reply via email to