Module Name:    src
Committed By:   njoly
Date:           Thu Apr  8 11:51:14 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:
Add a new clock_gettime1() function that holds most of the
clock_gettime syscall code (except for the copyout). Adjust all
corresponding syscalls to make use of it.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/compat/common/kern_time_50.c
cvs rdiff -u -r1.31 -r1.32 src/sys/compat/linux/common/linux_time.c
cvs rdiff -u -r1.31 -r1.32 src/sys/compat/linux32/common/linux32_time.c
cvs rdiff -u -r1.14 -r1.15 src/sys/compat/netbsd32/netbsd32_compat_50.c
cvs rdiff -u -r1.40 -r1.41 src/sys/compat/netbsd32/netbsd32_time.c
cvs rdiff -u -r1.164 -r1.165 src/sys/kern/kern_time.c
cvs rdiff -u -r1.28 -r1.29 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.14 src/sys/compat/common/kern_time_50.c:1.15
--- src/sys/compat/common/kern_time_50.c:1.14	Sat Apr  3 17:20:05 2010
+++ src/sys/compat/common/kern_time_50.c	Thu Apr  8 11:51:13 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_time_50.c,v 1.14 2010/04/03 17:20:05 njoly Exp $	*/
+/*	$NetBSD: kern_time_50.c,v 1.15 2010/04/08 11:51:13 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.14 2010/04/03 17:20:05 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_time_50.c,v 1.15 2010/04/08 11:51:13 njoly Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -113,21 +113,14 @@
 		syscallarg(clockid_t) clock_id;
 		syscallarg(struct timespec50 *) tp;
 	} */
-	clockid_t clock_id;
+	int error;
 	struct timespec ats;
 	struct timespec50 ats50;
 
-	clock_id = SCARG(uap, clock_id);
-	switch (clock_id) {
-	case CLOCK_REALTIME:
-		nanotime(&ats);
-		break;
-	case CLOCK_MONOTONIC:
-		nanouptime(&ats);
-		break;
-	default:
-		return (EINVAL);
-	}
+	error = clock_gettime1(SCARG(uap, clock_id), &ats);
+	if (error != 0)
+		return error;
+
 	timespec_to_timespec50(&ats, &ats50);
 
 	return copyout(&ats50, SCARG(uap, tp), sizeof(ats50));

Index: src/sys/compat/linux/common/linux_time.c
diff -u src/sys/compat/linux/common/linux_time.c:1.31 src/sys/compat/linux/common/linux_time.c:1.32
--- src/sys/compat/linux/common/linux_time.c:1.31	Sat Apr  3 17:20:05 2010
+++ src/sys/compat/linux/common/linux_time.c	Thu Apr  8 11:51:13 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_time.c,v 1.31 2010/04/03 17:20:05 njoly Exp $ */
+/*	$NetBSD: linux_time.c,v 1.32 2010/04/08 11:51:13 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.31 2010/04/03 17:20:05 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.32 2010/04/08 11:51:13 njoly Exp $");
 
 #include <sys/param.h>
 #include <sys/ucred.h>
@@ -194,19 +194,18 @@
 		syscallarg(clockid_t) which;
 		syscallarg(struct linux_timespec *)tp;
 	} */
+	int error;
+	clockid_t id;
 	struct timespec ts;
 	struct linux_timespec lts;
 
-	switch (SCARG(uap, which)) {
-	case LINUX_CLOCK_REALTIME:
-		nanotime(&ts);
-		break;
-	case LINUX_CLOCK_MONOTONIC:
-		nanouptime(&ts);
-		break;
-	default:
-		return EINVAL;
-	}
+	error = linux_to_native_clockid(&id, SCARG(uap, which));
+	if (error != 0)
+		return error;
+
+	error = clock_gettime1(id, &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.31 src/sys/compat/linux32/common/linux32_time.c:1.32
--- src/sys/compat/linux32/common/linux32_time.c:1.31	Sat Apr  3 17:20:05 2010
+++ src/sys/compat/linux32/common/linux32_time.c	Thu Apr  8 11:51:13 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_time.c,v 1.31 2010/04/03 17:20:05 njoly Exp $ */
+/*	$NetBSD: linux32_time.c,v 1.32 2010/04/08 11:51:13 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.31 2010/04/03 17:20:05 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.32 2010/04/08 11:51:13 njoly Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -307,19 +307,18 @@
 		syscallarg(clockid_t) which;
 		syscallarg(linux32_timespecp_t) tp;
 	} */
+	int error;
+	clockid_t id;
 	struct timespec ts;
 	struct linux32_timespec lts;
 
-	switch (SCARG(uap, which)) {
-	case LINUX_CLOCK_REALTIME:
-		nanotime(&ts);
-		break;
-	case LINUX_CLOCK_MONOTONIC:
-		nanouptime(&ts);
-		break;
-	default:
-		return EINVAL;
-	}
+	error = linux_to_native_clockid(&id, SCARG(uap, which));
+	if (error != 0)
+		return error;
+
+	error = clock_gettime1(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.14 src/sys/compat/netbsd32/netbsd32_compat_50.c:1.15
--- src/sys/compat/netbsd32/netbsd32_compat_50.c:1.14	Sat Apr  3 17:20:05 2010
+++ src/sys/compat/netbsd32/netbsd32_compat_50.c	Thu Apr  8 11:51:14 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_compat_50.c,v 1.14 2010/04/03 17:20:05 njoly Exp $	*/
+/*	$NetBSD: netbsd32_compat_50.c,v 1.15 2010/04/08 11:51:14 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.14 2010/04/03 17:20:05 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.15 2010/04/08 11:51:14 njoly Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_sysv.h"
@@ -312,17 +312,15 @@
 		syscallarg(netbsd32_clockid_t) clock_id;
 		syscallarg(netbsd32_timespec50p_t) tp;
 	} */
-	clockid_t clock_id;
+	int error;
 	struct timespec ats;
 	struct netbsd32_timespec50 ts32;
 
-	clock_id = SCARG(uap, clock_id);
-	if (clock_id != CLOCK_REALTIME)
-		return (EINVAL);
+	error = clock_gettime1(SCARG(uap, clock_id), &ats);
+	if (error != 0)
+		return error;
 
-	nanotime(&ats);
 	netbsd32_from_timespec50(&ats, &ts32);
-
 	return 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.40 src/sys/compat/netbsd32/netbsd32_time.c:1.41
--- src/sys/compat/netbsd32/netbsd32_time.c:1.40	Sat Apr  3 17:20:05 2010
+++ src/sys/compat/netbsd32/netbsd32_time.c	Thu Apr  8 11:51:14 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_time.c,v 1.40 2010/04/03 17:20:05 njoly Exp $	*/
+/*	$NetBSD: netbsd32_time.c,v 1.41 2010/04/08 11:51:14 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.40 2010/04/03 17:20:05 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_time.c,v 1.41 2010/04/08 11:51:14 njoly Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ntp.h"
@@ -353,17 +353,15 @@
 		syscallarg(netbsd32_clockid_t) clock_id;
 		syscallarg(netbsd32_timespecp_t) tp;
 	} */
-	clockid_t clock_id;
+	int error;
 	struct timespec ats;
 	struct netbsd32_timespec ts32;
 
-	clock_id = SCARG(uap, clock_id);
-	if (clock_id != CLOCK_REALTIME)
-		return (EINVAL);
+	error = clock_gettime1(SCARG(uap, clock_id), &ats);
+	if (error != 0)
+		return error;
 
-	nanotime(&ats);
 	netbsd32_from_timespec(&ats, &ts32);
-
 	return copyout(&ts32, SCARG_P32(uap, tp), sizeof(ts32));
 }
 

Index: src/sys/kern/kern_time.c
diff -u src/sys/kern/kern_time.c:1.164 src/sys/kern/kern_time.c:1.165
--- src/sys/kern/kern_time.c:1.164	Sat Apr  3 17:20:05 2010
+++ src/sys/kern/kern_time.c	Thu Apr  8 11:51:13 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_time.c,v 1.164 2010/04/03 17:20:05 njoly Exp $	*/
+/*	$NetBSD: kern_time.c,v 1.165 2010/04/08 11:51:13 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.164 2010/04/03 17:20:05 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.165 2010/04/08 11:51:13 njoly Exp $");
 
 #include <sys/param.h>
 #include <sys/resourcevar.h>
@@ -178,22 +178,32 @@
 		syscallarg(clockid_t) clock_id;
 		syscallarg(struct timespec *) tp;
 	} */
-	clockid_t clock_id;
+	int error;
 	struct timespec ats;
 
-	clock_id = SCARG(uap, clock_id);
+	error = clock_gettime1(SCARG(uap, clock_id), &ats);
+	if (error != 0)
+		return error;
+
+	return copyout(&ats, SCARG(uap, tp), sizeof(ats));
+}
+
+int
+clock_gettime1(clockid_t clock_id, struct timespec *ts)
+{
+
 	switch (clock_id) {
 	case CLOCK_REALTIME:
-		nanotime(&ats);
+		nanotime(ts);
 		break;
 	case CLOCK_MONOTONIC:
-		nanouptime(&ats);
+		nanouptime(ts);
 		break;
 	default:
-		return (EINVAL);
+		return EINVAL;
 	}
 
-	return copyout(&ats, SCARG(uap, tp), sizeof(ats));
+	return 0;
 }
 
 /* ARGSUSED */

Index: src/sys/sys/timevar.h
diff -u src/sys/sys/timevar.h:1.28 src/sys/sys/timevar.h:1.29
--- src/sys/sys/timevar.h:1.28	Sat Apr  3 17:20:05 2010
+++ src/sys/sys/timevar.h	Thu Apr  8 11:51:13 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: timevar.h,v 1.28 2010/04/03 17:20:05 njoly Exp $	*/
+/*	$NetBSD: timevar.h,v 1.29 2010/04/08 11:51:13 njoly Exp $	*/
 
 /*
  *  Copyright (c) 2005, 2008 The NetBSD Foundation.
@@ -148,6 +148,7 @@
 int	abstimeout2timo(struct timespec *, int *);
 void	adjtime1(const struct timeval *, struct timeval *, struct proc *);
 int	clock_getres1(clockid_t, struct timespec *);
+int	clock_gettime1(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