diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-12-21 14:53:53 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-12-21 14:53:53 +0000 |
commit | dec7a4d4bd3a0b56799e9068b8e093b76e9cbdec (patch) | |
tree | 49891298b4b6776b958260fef74ad680b92661d3 /lib/libarch | |
parent | 7dee9b01014df5e7dd734c79e87c1b2933a73fd7 (diff) |
from netbsd; memory mapped clock functions for a start
Diffstat (limited to 'lib/libarch')
-rw-r--r-- | lib/libarch/alpha/Makefile.inc | 5 | ||||
-rw-r--r-- | lib/libarch/alpha/alpha_mmclock_gettime.c | 55 | ||||
-rw-r--r-- | lib/libarch/alpha/alpha_mmclock_init.c | 68 | ||||
-rw-r--r-- | lib/libarch/alpha/gettimeofday.c | 82 | ||||
-rw-r--r-- | lib/libarch/alpha/libalpha.h | 30 |
5 files changed, 240 insertions, 0 deletions
diff --git a/lib/libarch/alpha/Makefile.inc b/lib/libarch/alpha/Makefile.inc new file mode 100644 index 00000000000..c6d059d58a4 --- /dev/null +++ b/lib/libarch/alpha/Makefile.inc @@ -0,0 +1,5 @@ +# Makefile.inc,v 1.1 1993/09/03 19:04:23 jtc Exp + +#.PATH: ${LIBC}/i386 + +SRCS+= alpha_mmclock_gettime.c alpha_mmclock_init.c gettimeofday.c diff --git a/lib/libarch/alpha/alpha_mmclock_gettime.c b/lib/libarch/alpha/alpha_mmclock_gettime.c new file mode 100644 index 00000000000..ca56c77bfcf --- /dev/null +++ b/lib/libarch/alpha/alpha_mmclock_gettime.c @@ -0,0 +1,55 @@ +/* $NetBSD: alpha_mmclock_gettime.c,v 1.1 1995/12/20 12:54:24 cgd Exp $ */ + +/* + * Copyright (c) 1995 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Chris G. Demetriou + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +#include <sys/types.h> +#include <sys/fcntl.h> +#include <sys/mman.h> +#include <sys/syscall.h> +#include <machine/sysarch.h> + +#include "libalpha.h" + +void +alpha_mmclock_gettime(tdp) + struct alpha_timedata *tdp; +{ + u_long npcc, pccdiff; + + do { + tdp->td_tv.tv_usec = alpha_mmclockdata->td_tv.tv_usec; + tdp->td_tv.tv_sec = alpha_mmclockdata->td_tv.tv_sec; + tdp->td_cc = alpha_mmclockdata->td_cc; + } while (tdp->td_tv.tv_usec != alpha_mmclockdata->td_tv.tv_usec || + tdp->td_tv.tv_sec != alpha_mmclockdata->td_tv.tv_sec); + + npcc = rpcc() & 0x00000000ffffffffUL; + if (npcc < tdp->td_cc) + npcc += 0x0000000100000000UL; + tdp->td_cc = npcc - tdp->td_cc; +} diff --git a/lib/libarch/alpha/alpha_mmclock_init.c b/lib/libarch/alpha/alpha_mmclock_init.c new file mode 100644 index 00000000000..5a83f2750ce --- /dev/null +++ b/lib/libarch/alpha/alpha_mmclock_init.c @@ -0,0 +1,68 @@ +/* $NetBSD: alpha_mmclock_init.c,v 1.1 1995/12/20 12:55:21 cgd Exp $ */ + +/* + * Copyright (c) 1995 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Chris G. Demetriou + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +#include <sys/types.h> +#include <sys/fcntl.h> +#include <sys/mman.h> +#include <machine/sysarch.h> + +#include "libalpha.h" + +volatile struct alpha_timedata *alpha_mmclockdata; +u_long alpha_cycles_per_second; + +int __alpha_mmclock_init_failed; + +volatile struct alpha_timedata * +alpha_mmclock_init() +{ + int fd; + + if (alpha_mmclockdata != NULL) + return (alpha_mmclockdata); + + fd = open("/dev/mmclock", O_RDONLY, 0); + if (fd == -1) + goto fail; + + alpha_mmclockdata = (struct alpha_timedata *) + mmap(NULL, getpagesize(), PROT_READ, MAP_FILE, fd, 0); + close(fd); + if (alpha_mmclockdata == NULL) + goto fail; + + alpha_cycles_per_second = alpha_mmclockdata->td_cpc; + + __alpha_mmclock_init_failed = 0; + return (alpha_mmclockdata); + +fail: + __alpha_mmclock_init_failed = 1; + return (NULL); +} diff --git a/lib/libarch/alpha/gettimeofday.c b/lib/libarch/alpha/gettimeofday.c new file mode 100644 index 00000000000..6ef009b37b4 --- /dev/null +++ b/lib/libarch/alpha/gettimeofday.c @@ -0,0 +1,82 @@ +/* $NetBSD: gettimeofday.c,v 1.1 1995/12/20 12:56:06 cgd Exp $ */ + +/* + * Copyright (c) 1995 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Chris G. Demetriou + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +#include <sys/types.h> +#include <sys/fcntl.h> +#include <sys/mman.h> +#include <sys/syscall.h> +#include <machine/sysarch.h> + +#include "libalpha.h" + +int +gettimeofday(tvp, tzp) + struct timeval *tvp; + struct timezone *tzp; +{ + u_long opcc, npcc, pccdiff; + static struct timeval lasttime; + + if (tzp == NULL && alpha_mmclockdata == NULL && + !__alpha_mmclock_init_failed) + alpha_mmclockdata = alpha_mmclock_init(); + if (tzp != NULL || alpha_mmclockdata == NULL) + return (syscall(SYS_gettimeofday, tvp, tzp)); + + if (tvp == NULL) + return 0; + + do { + tvp->tv_usec = alpha_mmclockdata->td_tv.tv_usec; + tvp->tv_sec = alpha_mmclockdata->td_tv.tv_sec; + opcc = alpha_mmclockdata->td_cc; + } while (tvp->tv_usec != alpha_mmclockdata->td_tv.tv_usec || + tvp->tv_sec != alpha_mmclockdata->td_tv.tv_sec); + + npcc = rpcc() & 0x00000000ffffffffUL; + if (npcc < opcc) + npcc += 0x0000000100000000UL; + pccdiff = npcc - opcc; + + tvp->tv_usec += (pccdiff * 1000000) / alpha_cycles_per_second; + if (tvp->tv_usec > 1000000) { + tvp->tv_sec++; + tvp->tv_usec -= 1000000; + } + + if ((tvp->tv_sec == lasttime.tv_sec && + tvp->tv_usec <= lasttime.tv_usec) && + (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) { + tvp->tv_sec++; + tvp->tv_usec -= 1000000; + } + + lasttime = *tvp; + return 0; +} diff --git a/lib/libarch/alpha/libalpha.h b/lib/libarch/alpha/libalpha.h new file mode 100644 index 00000000000..358f2ec3cbe --- /dev/null +++ b/lib/libarch/alpha/libalpha.h @@ -0,0 +1,30 @@ +/* $NetBSD: libalpha.h,v 1.1 1995/12/20 12:56:44 cgd Exp $ */ + +/* + * Copyright (c) 1995 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Chris G. Demetriou + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +extern int __alpha_mmclock_init_failed; |