Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add a new clock_gettime1() function that holds most of the



details:   https://anonhg.NetBSD.org/src/rev/bf02e4e7f282
branches:  trunk
changeset: 753731:bf02e4e7f282
user:      njoly <njoly%NetBSD.org@localhost>
date:      Thu Apr 08 11:51:13 2010 +0000

description:
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.

diffstat:

 sys/compat/common/kern_time_50.c         |  21 +++++++--------------
 sys/compat/linux/common/linux_time.c     |  23 +++++++++++------------
 sys/compat/linux32/common/linux32_time.c |  23 +++++++++++------------
 sys/compat/netbsd32/netbsd32_compat_50.c |  14 ++++++--------
 sys/compat/netbsd32/netbsd32_time.c      |  14 ++++++--------
 sys/kern/kern_time.c                     |  26 ++++++++++++++++++--------
 sys/sys/timevar.h                        |   3 ++-
 7 files changed, 61 insertions(+), 63 deletions(-)

diffs (293 lines):

diff -r 3ae850ce38f5 -r bf02e4e7f282 sys/compat/common/kern_time_50.c
--- a/sys/compat/common/kern_time_50.c  Thu Apr 08 10:33:13 2010 +0000
+++ b/sys/compat/common/kern_time_50.c  Thu Apr 08 11:51:13 2010 +0000
@@ -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));
diff -r 3ae850ce38f5 -r bf02e4e7f282 sys/compat/linux/common/linux_time.c
--- a/sys/compat/linux/common/linux_time.c      Thu Apr 08 10:33:13 2010 +0000
+++ b/sys/compat/linux/common/linux_time.c      Thu Apr 08 11:51:13 2010 +0000
@@ -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);
diff -r 3ae850ce38f5 -r bf02e4e7f282 sys/compat/linux32/common/linux32_time.c
--- a/sys/compat/linux32/common/linux32_time.c  Thu Apr 08 10:33:13 2010 +0000
+++ b/sys/compat/linux32/common/linux32_time.c  Thu Apr 08 11:51:13 2010 +0000
@@ -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);
diff -r 3ae850ce38f5 -r bf02e4e7f282 sys/compat/netbsd32/netbsd32_compat_50.c
--- a/sys/compat/netbsd32/netbsd32_compat_50.c  Thu Apr 08 10:33:13 2010 +0000
+++ b/sys/compat/netbsd32/netbsd32_compat_50.c  Thu Apr 08 11:51:13 2010 +0000
@@ -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));
 }
 
diff -r 3ae850ce38f5 -r bf02e4e7f282 sys/compat/netbsd32/netbsd32_time.c
--- a/sys/compat/netbsd32/netbsd32_time.c       Thu Apr 08 10:33:13 2010 +0000
+++ b/sys/compat/netbsd32/netbsd32_time.c       Thu Apr 08 11:51:13 2010 +0000
@@ -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));
 }
 
diff -r 3ae850ce38f5 -r bf02e4e7f282 sys/kern/kern_time.c
--- a/sys/kern/kern_time.c      Thu Apr 08 10:33:13 2010 +0000
+++ b/sys/kern/kern_time.c      Thu Apr 08 11:51:13 2010 +0000
@@ -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 */
diff -r 3ae850ce38f5 -r bf02e4e7f282 sys/sys/timevar.h
--- a/sys/sys/timevar.h Thu Apr 08 10:33:13 2010 +0000
+++ b/sys/sys/timevar.h Thu Apr 08 11:51:13 2010 +0000
@@ -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 *);



Home | Main Index | Thread Index | Old Index