tech-kern archive

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

Adding clock_getres1() to be shared with emulations ?



Hi,

The attached patch introduce a new function clock_getres1() function
which has most of the corresponding syscall logic except for the
copyout call.

This has the benefit to have all emulations can use it and are now
automatically synced with the native version (as a side effect, they
all gain CLOCK_MONOTONIC support i was looking for).

I'd like to commit it in a few days, unless someone objects ... And
then do mostly the same for clock_gettime().

Thanks for review/comments.

-- 
Nicolas Joly

Biological Software and Databanks.
Institut Pasteur, Paris.
Index: sys/kern/kern_time.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_time.c,v
retrieving revision 1.163
diff -u -p -r1.163 kern_time.c
--- sys/kern/kern_time.c        10 Dec 2009 12:39:12 -0000      1.163
+++ sys/kern/kern_time.c        30 Mar 2010 07:11:33 -0000
@@ -243,28 +246,36 @@ sys___clock_getres50(struct lwp *l, cons
                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: sys/sys/timevar.h
===================================================================
RCS file: /cvsroot/src/sys/sys/timevar.h,v
retrieving revision 1.27
diff -u -p -r1.27 timevar.h
--- sys/sys/timevar.h   1 Nov 2009 21:46:09 -0000       1.27
+++ sys/sys/timevar.h   30 Mar 2010 07:11:33 -0000
@@ -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 *);
Index: sys/compat/common/kern_time_50.c
===================================================================
RCS file: /cvsroot/src/sys/compat/common/kern_time_50.c,v
retrieving revision 1.13
diff -u -p -r1.13 kern_time_50.c
--- sys/compat/common/kern_time_50.c    19 Jan 2010 22:28:31 -0000      1.13
+++ sys/compat/common/kern_time_50.c    30 Mar 2010 07:11:34 -0000
@@ -54,7 +54,6 @@ __KERNEL_RCSID(0, "$NetBSD: kern_time_50
 #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;
 }
Index: sys/compat/linux/common/linux_time.c
===================================================================
RCS file: /cvsroot/src/sys/compat/linux/common/linux_time.c,v
retrieving revision 1.30
diff -u -p -r1.30 linux_time.c
--- sys/compat/linux/common/linux_time.c        29 Mar 2010 15:34:07 -0000      
1.30
+++ sys/compat/linux/common/linux_time.c        30 Mar 2010 07:11:34 -0000
@@ -39,7 +39,6 @@ __KERNEL_RCSID(0, "$NetBSD: linux_time.c
 #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, co
        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: sys/compat/linux32/common/linux32_time.c
===================================================================
RCS file: /cvsroot/src/sys/compat/linux32/common/linux32_time.c,v
retrieving revision 1.30
diff -u -p -r1.30 linux32_time.c
--- sys/compat/linux32/common/linux32_time.c    29 Mar 2010 15:34:07 -0000      
1.30
+++ sys/compat/linux32/common/linux32_time.c    30 Mar 2010 07:11:34 -0000
@@ -50,7 +50,6 @@ __KERNEL_RCSID(0, "$NetBSD: linux32_time
 #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);
 }
Index: sys/compat/netbsd32/netbsd32_compat_50.c
===================================================================
RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_compat_50.c,v
retrieving revision 1.13
diff -u -p -r1.13 netbsd32_compat_50.c
--- sys/compat/netbsd32/netbsd32_compat_50.c    29 Mar 2010 15:34:07 -0000      
1.13
+++ sys/compat/netbsd32/netbsd32_compat_50.c    30 Mar 2010 07:11:35 -0000
@@ -354,18 +354,14 @@ compat_50_netbsd32_clock_getres(struct 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));
        }
Index: sys/compat/netbsd32/netbsd32_time.c
===================================================================
RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_time.c,v
retrieving revision 1.39
diff -u -p -r1.39 netbsd32_time.c
--- sys/compat/netbsd32/netbsd32_time.c 29 Mar 2010 15:34:07 -0000      1.39
+++ sys/compat/netbsd32/netbsd32_time.c 30 Mar 2010 07:11:35 -0000
@@ -40,7 +40,6 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_tim
 #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,
                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));
        }


Home | Main Index | Thread Index | Old Index