diff options
author | netchild <netchild@FreeBSD.org> | 2012-05-05 19:42:38 +0000 |
---|---|---|
committer | netchild <netchild@FreeBSD.org> | 2012-05-05 19:42:38 +0000 |
commit | 9895b5ca9df1f0d045ee00e77007e80d4c202ca4 (patch) | |
tree | 2c944ca220ef9f94f80b967133cbd2ab53caa81c /sys/compat/linux/linux_time.c | |
parent | 096ede817a595e57dafce2910385344f389c8dbd (diff) | |
download | FreeBSD-src-9895b5ca9df1f0d045ee00e77007e80d4c202ca4.zip FreeBSD-src-9895b5ca9df1f0d045ee00e77007e80d4c202ca4.tar.gz |
- >500 static DTrace probes for the linuxulator
- DTrace scripts to check for errors, performance, ...
they serve mostly as examples of what you can do with the static probe;s
with moderate load the scripts may be overwhelmed, excessive lock-tracing
may influence program behavior (see the last design decission)
Design decissions:
- use "linuxulator" as the provider for the native bitsize; add the
bitsize for the non-native emulation (e.g. "linuxuator32" on amd64)
- Add probes only for locks which are acquired in one function and released
in another function. Locks which are aquired and released in the same
function should be easy to pair in the code, inter-function
locking is more easy to verify in DTrace.
- Probes for locks should be fired after locking and before releasing to
prevent races (to provide data/function stability in DTrace, see the
man-page of "dtrace -v ..." and the corresponding DTrace docs).
Diffstat (limited to 'sys/compat/linux/linux_time.c')
-rw-r--r-- | sys/compat/linux/linux_time.c | 221 |
1 files changed, 199 insertions, 22 deletions
diff --git a/sys/compat/linux/linux_time.c b/sys/compat/linux/linux_time.c index 8800d67..1359025 100644 --- a/sys/compat/linux/linux_time.c +++ b/sys/compat/linux/linux_time.c @@ -36,10 +36,13 @@ __KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp #endif #include "opt_compat.h" +#include "opt_kdtrace.h" #include <sys/param.h> +#include <sys/kernel.h> #include <sys/ucred.h> #include <sys/mount.h> +#include <sys/sdt.h> #include <sys/signal.h> #include <sys/stdint.h> #include <sys/syscallsubr.h> @@ -56,6 +59,63 @@ __KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp #include <machine/../linux/linux_proto.h> #endif +#include <compat/linux/linux_dtrace.h> + +/* DTrace init */ +LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); + +/** + * DTrace probes in this module. + */ +LIN_SDT_PROBE_DEFINE2(time, native_to_linux_timespec, entry, + "struct l_timespec *", "struct timespec *"); +LIN_SDT_PROBE_DEFINE0(time, native_to_linux_timespec, return); +LIN_SDT_PROBE_DEFINE2(time, linux_to_native_timespec, entry, + "struct timespec *", "struct l_timespec *"); +LIN_SDT_PROBE_DEFINE1(time, linux_to_native_timespec, return, "int"); +LIN_SDT_PROBE_DEFINE2(time, linux_to_native_clockid, entry, "clockid_t *", + "clockid_t"); +LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, unsupported_clockid, + "clockid_t"); +LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, unknown_clockid, + "clockid_t"); +LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, return, "int"); +LIN_SDT_PROBE_DEFINE2(time, linux_clock_gettime, entry, "clockid_t", + "struct l_timespec *"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, conversion_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, gettime_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, copyout_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, return, "int"); +LIN_SDT_PROBE_DEFINE2(time, linux_clock_settime, entry, "clockid_t", + "struct l_timespec *"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, conversion_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, settime_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, copyin_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, return, "int"); +LIN_SDT_PROBE_DEFINE2(time, linux_clock_getres, entry, "clockid_t", + "struct l_timespec *"); +LIN_SDT_PROBE_DEFINE0(time, linux_clock_getres, nullcall); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, conversion_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, getres_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, copyout_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, return, "int"); +LIN_SDT_PROBE_DEFINE2(time, linux_nanosleep, entry, "const struct l_timespec *", + "struct l_timespec *"); +LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, conversion_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, nanosleep_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyout_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyin_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, return, "int"); +LIN_SDT_PROBE_DEFINE4(time, linux_clock_nanosleep, entry, "clockid_t", "int", + "struct l_timespec *", "struct l_timespec *"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, conversion_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, nanosleep_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, copyout_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, copyin_error, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, unsupported_flags, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, unsupported_clockid, "int"); +LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, return, "int"); + static void native_to_linux_timespec(struct l_timespec *, struct timespec *); static int linux_to_native_timespec(struct timespec *, @@ -65,24 +125,38 @@ static int linux_to_native_clockid(clockid_t *, clockid_t); static void native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp) { + + LIN_SDT_PROBE2(time, native_to_linux_timespec, entry, ltp, ntp); + ltp->tv_sec = ntp->tv_sec; ltp->tv_nsec = ntp->tv_nsec; + + LIN_SDT_PROBE0(time, native_to_linux_timespec, return); } static int linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp) { - if (ltp->tv_sec < 0 || ltp->tv_nsec > (l_long)999999999L) + + LIN_SDT_PROBE2(time, linux_to_native_timespec, entry, ntp, ltp); + + if (ltp->tv_sec < 0 || ltp->tv_nsec > (l_long)999999999L) { + LIN_SDT_PROBE1(time, linux_to_native_timespec, return, EINVAL); return (EINVAL); + } ntp->tv_sec = ltp->tv_sec; ntp->tv_nsec = ltp->tv_nsec; + LIN_SDT_PROBE1(time, linux_to_native_timespec, return, 0); return (0); } static int linux_to_native_clockid(clockid_t *n, clockid_t l) { + + LIN_SDT_PROBE2(time, linux_to_native_clockid, entry, n, l); + switch (l) { case LINUX_CLOCK_REALTIME: *n = CLOCK_REALTIME; @@ -94,11 +168,20 @@ linux_to_native_clockid(clockid_t *n, clockid_t l) case LINUX_CLOCK_THREAD_CPUTIME_ID: case LINUX_CLOCK_REALTIME_HR: case LINUX_CLOCK_MONOTONIC_HR: + LIN_SDT_PROBE1(time, linux_to_native_clockid, + unsupported_clockid, l); + LIN_SDT_PROBE1(time, linux_to_native_clockid, return, EINVAL); + return (EINVAL); + break; default: + LIN_SDT_PROBE1(time, linux_to_native_clockid, + unknown_clockid, l); + LIN_SDT_PROBE1(time, linux_to_native_clockid, return, EINVAL); return (EINVAL); break; } + LIN_SDT_PROBE1(time, linux_to_native_clockid, return, 0); return (0); } @@ -110,15 +193,29 @@ linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args) clockid_t nwhich = 0; /* XXX: GCC */ struct timespec tp; + LIN_SDT_PROBE2(time, linux_clock_gettime, entry, args->which, args->tp); + error = linux_to_native_clockid(&nwhich, args->which); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_gettime, conversion_error, + error); + LIN_SDT_PROBE1(time, linux_clock_gettime, return, error); return (error); + } error = kern_clock_gettime(td, nwhich, &tp); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_gettime, gettime_error, error); + LIN_SDT_PROBE1(time, linux_clock_gettime, return, error); return (error); + } native_to_linux_timespec(<s, &tp); - return (copyout(<s, args->tp, sizeof lts)); + error = copyout(<s, args->tp, sizeof lts); + if (error != 0) + LIN_SDT_PROBE1(time, linux_clock_gettime, copyout_error, error); + + LIN_SDT_PROBE1(time, linux_clock_gettime, return, error); + return (error); } int @@ -129,17 +226,35 @@ linux_clock_settime(struct thread *td, struct linux_clock_settime_args *args) int error; clockid_t nwhich = 0; /* XXX: GCC */ + LIN_SDT_PROBE2(time, linux_clock_settime, entry, args->which, args->tp); + error = linux_to_native_clockid(&nwhich, args->which); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_settime, conversion_error, + error); + LIN_SDT_PROBE1(time, linux_clock_settime, return, error); return (error); + } error = copyin(args->tp, <s, sizeof lts); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_settime, copyin_error, error); + LIN_SDT_PROBE1(time, linux_clock_settime, return, error); return (error); + } error = linux_to_native_timespec(&ts, <s); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_settime, conversion_error, + error); + LIN_SDT_PROBE1(time, linux_clock_settime, return, error); return (error); + } + + error = kern_clock_settime(td, nwhich, &ts); + if (error != 0) + LIN_SDT_PROBE1(time, linux_clock_settime, settime_error, error); - return (kern_clock_settime(td, nwhich, &ts)); + LIN_SDT_PROBE1(time, linux_clock_settime, return, error); + return (error); } int @@ -150,18 +265,35 @@ linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args) int error; clockid_t nwhich = 0; /* XXX: GCC */ - if (args->tp == NULL) + LIN_SDT_PROBE2(time, linux_clock_getres, entry, args->which, args->tp); + + if (args->tp == NULL) { + LIN_SDT_PROBE0(time, linux_clock_getres, nullcall); + LIN_SDT_PROBE1(time, linux_clock_getres, return, 0); return (0); + } error = linux_to_native_clockid(&nwhich, args->which); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_getres, conversion_error, + error); + LIN_SDT_PROBE1(time, linux_clock_getres, return, error); return (error); + } error = kern_clock_getres(td, nwhich, &ts); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_getres, getres_error, error); + LIN_SDT_PROBE1(time, linux_clock_getres, return, error); return (error); + } native_to_linux_timespec(<s, &ts); - return (copyout(<s, args->tp, sizeof lts)); + error = copyout(<s, args->tp, sizeof lts); + if (error != 0) + LIN_SDT_PROBE1(time, linux_clock_getres, copyout_error, error); + + LIN_SDT_PROBE1(time, linux_clock_getres, return, error); + return (error); } int @@ -172,9 +304,14 @@ linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args) struct timespec rqts, rmts; int error; + LIN_SDT_PROBE2(time, linux_nanosleep, entry, args->rqtp, args->rmtp); + error = copyin(args->rqtp, &lrqts, sizeof lrqts); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_nanosleep, copyin_error, error); + LIN_SDT_PROBE1(time, linux_nanosleep, return, error); return (error); + } if (args->rmtp != NULL) rmtp = &rmts; @@ -182,19 +319,30 @@ linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args) rmtp = NULL; error = linux_to_native_timespec(&rqts, &lrqts); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_nanosleep, conversion_error, error); + LIN_SDT_PROBE1(time, linux_nanosleep, return, error); return (error); + } error = kern_nanosleep(td, &rqts, rmtp); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_nanosleep, nanosleep_error, error); + LIN_SDT_PROBE1(time, linux_nanosleep, return, error); return (error); + } if (args->rmtp != NULL) { native_to_linux_timespec(&lrmts, rmtp); error = copyout(&lrmts, args->rmtp, sizeof(lrmts)); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_nanosleep, copyout_error, + error); + LIN_SDT_PROBE1(time, linux_nanosleep, return, error); return (error); + } } + LIN_SDT_PROBE1(time, linux_nanosleep, return, 0); return (0); } @@ -206,15 +354,31 @@ linux_clock_nanosleep(struct thread *td, struct linux_clock_nanosleep_args *args struct timespec rqts, rmts; int error; - if (args->flags != 0) + LIN_SDT_PROBE4(time, linux_clock_nanosleep, entry, args->which, + args->flags, args->rqtp, args->rmtp); + + if (args->flags != 0) { + /* XXX deal with TIMER_ABSTIME */ + LIN_SDT_PROBE1(time, linux_clock_nanosleep, unsupported_flags, + args->flags); + LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, EINVAL); return (EINVAL); /* XXX deal with TIMER_ABSTIME */ + } - if (args->which != LINUX_CLOCK_REALTIME) + if (args->which != LINUX_CLOCK_REALTIME) { + LIN_SDT_PROBE1(time, linux_clock_nanosleep, unsupported_clockid, + args->which); + LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, EINVAL); return (EINVAL); + } error = copyin(args->rqtp, &lrqts, sizeof lrqts); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_nanosleep, copyin_error, + error); + LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error); return (error); + } if (args->rmtp != NULL) rmtp = &rmts; @@ -222,18 +386,31 @@ linux_clock_nanosleep(struct thread *td, struct linux_clock_nanosleep_args *args rmtp = NULL; error = linux_to_native_timespec(&rqts, &lrqts); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_nanosleep, conversion_error, + error); + LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error); return (error); + } error = kern_nanosleep(td, &rqts, rmtp); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_nanosleep, nanosleep_error, + error); + LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error); return (error); + } if (args->rmtp != NULL) { native_to_linux_timespec(&lrmts, rmtp); error = copyout(&lrmts, args->rmtp, sizeof lrmts ); - if (error != 0) + if (error != 0) { + LIN_SDT_PROBE1(time, linux_clock_nanosleep, + copyout_error, error); + LIN_SDT_PROBE1(time, linux_nanosleep, return, error); return (error); + } } + LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, 0); return (0); } |