Source-Changes-HG archive

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

[src/trunk]: src/sys Move most clock_getres syscall code, except for coypout ...



details:   https://anonhg.NetBSD.org/src/rev/15a5d1538e55
branches:  trunk
changeset: 753612:15a5d1538e55
user:      njoly <njoly%NetBSD.org@localhost>
date:      Sat Apr 03 17:20:05 2010 +0000

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

diffstat:

 sys/compat/common/kern_time_50.c         |  29 ++++++++---------------
 sys/compat/linux/common/linux_time.c     |  11 ++++----
 sys/compat/linux32/common/linux32_time.c |  11 ++++----
 sys/compat/netbsd32/netbsd32_compat_50.c |  14 ++++-------
 sys/compat/netbsd32/netbsd32_time.c      |  15 ++++--------
 sys/kern/kern_time.c                     |  40 +++++++++++++++++++------------
 sys/sys/timevar.h                        |   3 +-
 7 files changed, 58 insertions(+), 65 deletions(-)

diffs (truncated from 316 to 300 lines):

diff -r 199ea6821640 -r 15a5d1538e55 sys/compat/common/kern_time_50.c
--- a/sys/compat/common/kern_time_50.c  Sat Apr 03 16:29:22 2010 +0000
+++ b/sys/compat/common/kern_time_50.c  Sat Apr 03 17:20:05 2010 +0000
@@ -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,27 +164,19 @@
                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)) {
+               timespec_to_timespec50(&ats, &ats50);
+               error = copyout(&ats50, SCARG(uap, tp), sizeof(ats50));
        }
 
-       if (SCARG(uap, tp))
-               error = copyout(&ats50, SCARG(uap, tp), sizeof(*SCARG(uap, tp)));
-
        return error;
 }
 
diff -r 199ea6821640 -r 15a5d1538e55 sys/compat/linux/common/linux_time.c
--- a/sys/compat/linux/common/linux_time.c      Sat Apr 03 16:29:22 2010 +0000
+++ b/sys/compat/linux/common/linux_time.c      Sat Apr 03 17:20:05 2010 +0000
@@ -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);
 }
diff -r 199ea6821640 -r 15a5d1538e55 sys/compat/linux32/common/linux32_time.c
--- a/sys/compat/linux32/common/linux32_time.c  Sat Apr 03 16:29:22 2010 +0000
+++ b/sys/compat/linux32/common/linux32_time.c  Sat Apr 03 17:20:05 2010 +0000
@@ -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);
 }
diff -r 199ea6821640 -r 15a5d1538e55 sys/compat/netbsd32/netbsd32_compat_50.c
--- a/sys/compat/netbsd32/netbsd32_compat_50.c  Sat Apr 03 16:29:22 2010 +0000
+++ b/sys/compat/netbsd32/netbsd32_compat_50.c  Sat Apr 03 17:20:05 2010 +0000
@@ -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));
        }
diff -r 199ea6821640 -r 15a5d1538e55 sys/compat/netbsd32/netbsd32_time.c
--- a/sys/compat/netbsd32/netbsd32_time.c       Sat Apr 03 16:29:22 2010 +0000
+++ b/sys/compat/netbsd32/netbsd32_time.c       Sat Apr 03 17:20:05 2010 +0000
@@ -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));
        }
diff -r 199ea6821640 -r 15a5d1538e55 sys/kern/kern_time.c
--- a/sys/kern/kern_time.c      Sat Apr 03 16:29:22 2010 +0000
+++ b/sys/kern/kern_time.c      Sat Apr 03 17:20:05 2010 +0000
@@ -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 @@
                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 @@
        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,
diff -r 199ea6821640 -r 15a5d1538e55 sys/sys/timevar.h



Home | Main Index | Thread Index | Old Index