From owner-freebsd-arch Thu Nov 16 22:55:26 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 61D9537B4C5 for ; Thu, 16 Nov 2000 22:55:17 -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 eAH6tCJ05746 for ; Fri, 17 Nov 2000 08:55:12 +0200 (SAST) (envelope-from mark@grondar.za) Message-Id: <200011170655.eAH6tCJ05746@gratis.grondar.za> To: arch@freebsd.org Subject: new monotime() call for all architectures. Date: Fri, 17 Nov 2000 08:55:04 +0200 From: Mark Murray Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi all I need a fast-as-possible "time" inside the kernel to help speed up the /dev/random device. I say "time", because although it needs to be a function of time (preferably accurate and linear), it has no need whatsoever to be "real time", so a simple counter is quite OK. Pentiums, Alphas and IA64's all have a suitable register on chip, while I have to make do with nanotime(9) on i386 and i486. I have prepared a monotime(9) call for the i386, alpha and ia64 architectures (patch enclosed). I have been running this for a week or two now with promising results (on a Pentium). With the exception of the minimum of "glue" (and nanotime on older architectures), these functions reduce to one instruction. Comments? Suggestions? Nobel Prize nominations? I'd like to commit this soonish if possible. M Index: alpha/include/clock.h =================================================================== RCS file: /home/ncvs/src/sys/alpha/include/clock.h,v retrieving revision 1.6 diff -u -d -r1.6 clock.h --- alpha/include/clock.h 2000/10/15 09:51:44 1.6 +++ alpha/include/clock.h 2000/11/08 06:02:24 @@ -19,6 +19,18 @@ int acquire_timer2 __P((int mode)); int release_timer2 __P((void)); +/* + * Standardised monotonic counter interface + */ +static __inline u_int64_t +monotime(void) +{ + u_int64_t retval; + + __asm__ __volatile__ ("rpcc %0" : "=r" (retval)); + return retval; +} + #endif #endif /* !_MACHINE_CLOCK_H_ */ Index: i386/include/clock.h =================================================================== RCS file: /home/ncvs/src/sys/i386/include/clock.h,v retrieving revision 1.39 diff -u -d -r1.39 clock.h --- i386/include/clock.h 2000/10/15 09:51:48 1.39 +++ i386/include/clock.h 2000/11/08 06:47:24 @@ -45,6 +45,23 @@ int sysbeep __P((int pitch, int period)); void i8254_restore __P((void)); +/* + * Standardised monotonic counter interface + */ +static __inline u_int64_t +monotime(void) +{ + u_int64_t retval; + +#if defined(I386_CPU) || defined(I486_CPU) + if (!tsc_present) + retval = nanotime(); + else +#endif + __asm __volatile("rdtsc" : "=A" (retval)); + return retval; +} + #endif /* _KERNEL */ #endif /* !_MACHINE_CLOCK_H_ */ Index: ia64/include/clock.h =================================================================== RCS file: /home/ncvs/src/sys/ia64/include/clock.h,v retrieving revision 1.2 diff -u -d -r1.2 clock.h --- ia64/include/clock.h 2000/10/15 09:51:48 1.2 +++ ia64/include/clock.h 2000/11/08 06:02:47 @@ -19,6 +19,18 @@ int acquire_timer2 __P((int mode)); int release_timer2 __P((void)); +/* + * Standardised monotonic counter interface + */ +static __inline u_int64_t +monotime(void) +{ + u_int64_t retval; + + __asm __volatile("mov %0=ar.itc" : "=r" (retval)); + return retval; +} + #endif #endif /* !_MACHINE_CLOCK_H_ */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message