From owner-freebsd-arch Sun Nov 19 11:44:52 2000 Delivered-To: freebsd-arch@freebsd.org Received: from gratis.grondar.za (grouter.grondar.za [196.7.18.65]) by hub.freebsd.org (Postfix) with ESMTP id 099E037B479 for ; Sun, 19 Nov 2000 11:44:45 -0800 (PST) Received: from grondar.za (grapevine.grondar.za [196.7.18.17]) by gratis.grondar.za (8.11.1/8.11.1) with ESMTP id eAJJieJ15985 for ; Sun, 19 Nov 2000 21:44:41 +0200 (SAST) (envelope-from mark@grondar.za) Message-Id: <200011191944.eAJJieJ15985@gratis.grondar.za> To: arch@freebsd.org Subject: "monotime" counter - commit candidate #2 Date: Sun, 19 Nov 2000 21:44:40 +0200 From: Mark Murray Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi It looks like we are converging, and that the bikeshed factor is gone! BDE has sent some useful comments, and I have incorporated them. We are ready for go. Green Light? M Index: alpha/include/cpu.h =================================================================== RCS file: /home/ncvs/src/sys/alpha/include/cpu.h,v retrieving revision 1.18 diff -u -d -r1.18 cpu.h --- alpha/include/cpu.h 2000/10/06 02:20:10 1.18 +++ alpha/include/cpu.h 2000/11/19 19:01:36 @@ -173,6 +173,16 @@ void trap __P((unsigned long, unsigned long, unsigned long, unsigned long, struct trapframe *)); +/* + * Return contents of in-cpu fast counter as a sort of "bogo-time" + * for non-critical timing. + */ +static __inline u_int64_t +get_cyclecount(void) +{ + return (alpha_rpcc()); +} + #endif /* _KERNEL */ #endif /* _ALPHA_CPU_H_ */ Index: i386/include/cpu.h =================================================================== RCS file: /home/ncvs/src/sys/i386/include/cpu.h,v retrieving revision 1.49 diff -u -d -r1.49 cpu.h --- i386/include/cpu.h 2000/10/27 08:30:56 1.49 +++ i386/include/cpu.h 2000/11/19 19:38:46 @@ -47,6 +47,8 @@ #include #include #include +#include +#include /* * definitions of cpu-dependent requirements @@ -133,6 +135,25 @@ void fork_trampoline __P((void)); void fork_return __P((struct proc *, struct trapframe)); + +/* + * Return contents of in-cpu fast counter as a sort of "bogo-time" + * for non-critical timing. + */ +static __inline u_int64_t +get_cyclecount(void) +{ +#if defined(I386_CPU) || defined(I486_CPU) + struct timespec tv; + + if ((cpu_feature & CPUID_TSC) == 0) { + nanotime(&tv); + return (tv.tv_sec * (u_int64_t)1000000000 + tv.tv_nsec); + } +#endif + return (rdtsc()); +} + #endif #endif /* !_MACHINE_CPU_H_ */ Index: i386/include/cpufunc.h =================================================================== RCS file: /home/ncvs/src/sys/i386/include/cpufunc.h,v retrieving revision 1.99 diff -u -d -r1.99 cpufunc.h --- i386/include/cpufunc.h 2000/10/12 17:05:33 1.99 +++ i386/include/cpufunc.h 2000/11/18 21:29:08 @@ -397,7 +397,7 @@ { u_int64_t rv; - __asm __volatile(".byte 0x0f, 0x31" : "=A" (rv)); + __asm __volatile("rdtsc" : "=A" (rv)); return (rv); } @@ -416,7 +416,7 @@ static __inline void wrmsr(u_int msr, u_int64_t newval) { - __asm __volatile(".byte 0x0f, 0x30" : : "A" (newval), "c" (msr)); + __asm __volatile("wrmsr" : : "A" (newval), "c" (msr)); } static __inline u_int Index: ia64/include/cpu.h =================================================================== RCS file: /home/ncvs/src/sys/ia64/include/cpu.h,v retrieving revision 1.5 diff -u -d -r1.5 cpu.h --- ia64/include/cpu.h 2000/10/16 08:54:40 1.5 +++ ia64/include/cpu.h 2000/11/19 19:01:21 @@ -166,6 +166,16 @@ void syscall __P((int, u_int64_t *, struct trapframe *)); void trap __P((int vector, int imm, struct trapframe *framep)); +/* + * Return contents of in-cpu fast counter as a sort of "bogo-time" + * for non-critical timing. + */ +static __inline u_int64_t +get_cyclecount(void) +{ + return (ia64_get_itc()); +} + #endif /* _KERNEL */ #endif /* _MACHINE_CPU_H_ */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message