diff options
author | bde <bde@FreeBSD.org> | 1998-02-12 21:41:10 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1998-02-12 21:41:10 +0000 |
commit | 7da6f05e3f9270f13abfe8ac90a58b5fdc05b97b (patch) | |
tree | 4065d7644e973586908ace61d400871f977921a2 | |
parent | 796a7e782cfa2ded67846c227e063974ac5cb66e (diff) | |
download | FreeBSD-src-7da6f05e3f9270f13abfe8ac90a58b5fdc05b97b.zip FreeBSD-src-7da6f05e3f9270f13abfe8ac90a58b5fdc05b97b.tar.gz |
Only use the i586-optimized copying and zeroing functions if they are
actually faster (more than 20% faster for zeroing 1 MB at boot time).
This fixes pessimized copying and zeroing on K6's and perhaps on other
CPUs that are misclassified as i586's.
-rw-r--r-- | sys/amd64/amd64/fpu.c | 41 | ||||
-rw-r--r-- | sys/amd64/isa/npx.c | 41 | ||||
-rw-r--r-- | sys/i386/isa/npx.c | 41 |
3 files changed, 114 insertions, 9 deletions
diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index c6f2b09..7dccaa5 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -32,7 +32,7 @@ * SUCH DAMAGE. * * from: @(#)npx.c 7.2 (Berkeley) 5/12/91 - * $Id: npx.c,v 1.54 1997/11/18 11:32:31 bde Exp $ + * $Id: npx.c,v 1.55 1998/01/31 07:23:09 eivind Exp $ */ #include "npx.h" @@ -44,6 +44,7 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> +#include <sys/malloc.h> #include <sys/sysctl.h> #include <sys/conf.h> #include <sys/proc.h> @@ -132,6 +133,8 @@ typedef u_char bool_t; static int npxattach __P((struct isa_device *dvp)); static int npxprobe __P((struct isa_device *dvp)); static int npxprobe1 __P((struct isa_device *dvp)); +static long timezero __P((const char *funcname, + void (*func)(void *buf, size_t len))); struct isa_driver npxdriver = { npxprobe, npxattach, "npx", @@ -408,8 +411,10 @@ npxattach(dvp) } npxinit(__INITIAL_NPXCW__); -#if defined(I586_CPU) - if (cpu_class == CPUCLASS_586 && npx_ex16) { +#ifdef I586_CPU + if (cpu_class == CPUCLASS_586 && npx_ex16 && + timezero("i586_bzero()", i586_bzero) < + timezero("bzero()", bzero) * 4 / 5) { if (!(dvp->id_flags & NPX_DISABLE_I586_OPTIMIZED_BCOPY)) { bcopy_vector = i586_bcopy; ovbcopy_vector = i586_bcopy; @@ -663,4 +668,34 @@ npxsave(addr) #endif /* SMP */ } +#ifdef I586_CPU +static long +timezero(funcname, func) + const char *funcname; + void (*func) __P((void *buf, size_t len)); + +{ + void *buf; +#define BUFSIZE 1000000 + long usec; + struct timeval finish, start; + + buf = malloc(BUFSIZE, M_TEMP, M_NOWAIT); + if (buf == NULL) + return (BUFSIZE); + microtime(&start); + (*func)(buf, BUFSIZE); + microtime(&finish); + usec = 1000000 * (finish.tv_sec - start.tv_sec) + + finish.tv_usec - start.tv_usec; + if (usec <= 0) + usec = 1; + if (bootverbose) + printf("%s bandwidth = %ld bytes/sec\n", + funcname, (long)(BUFSIZE * 1000000ll / usec)); + free(buf, M_TEMP); + return (usec); +} +#endif /* I586_CPU */ + #endif /* NNPX > 0 */ diff --git a/sys/amd64/isa/npx.c b/sys/amd64/isa/npx.c index c6f2b09..7dccaa5 100644 --- a/sys/amd64/isa/npx.c +++ b/sys/amd64/isa/npx.c @@ -32,7 +32,7 @@ * SUCH DAMAGE. * * from: @(#)npx.c 7.2 (Berkeley) 5/12/91 - * $Id: npx.c,v 1.54 1997/11/18 11:32:31 bde Exp $ + * $Id: npx.c,v 1.55 1998/01/31 07:23:09 eivind Exp $ */ #include "npx.h" @@ -44,6 +44,7 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> +#include <sys/malloc.h> #include <sys/sysctl.h> #include <sys/conf.h> #include <sys/proc.h> @@ -132,6 +133,8 @@ typedef u_char bool_t; static int npxattach __P((struct isa_device *dvp)); static int npxprobe __P((struct isa_device *dvp)); static int npxprobe1 __P((struct isa_device *dvp)); +static long timezero __P((const char *funcname, + void (*func)(void *buf, size_t len))); struct isa_driver npxdriver = { npxprobe, npxattach, "npx", @@ -408,8 +411,10 @@ npxattach(dvp) } npxinit(__INITIAL_NPXCW__); -#if defined(I586_CPU) - if (cpu_class == CPUCLASS_586 && npx_ex16) { +#ifdef I586_CPU + if (cpu_class == CPUCLASS_586 && npx_ex16 && + timezero("i586_bzero()", i586_bzero) < + timezero("bzero()", bzero) * 4 / 5) { if (!(dvp->id_flags & NPX_DISABLE_I586_OPTIMIZED_BCOPY)) { bcopy_vector = i586_bcopy; ovbcopy_vector = i586_bcopy; @@ -663,4 +668,34 @@ npxsave(addr) #endif /* SMP */ } +#ifdef I586_CPU +static long +timezero(funcname, func) + const char *funcname; + void (*func) __P((void *buf, size_t len)); + +{ + void *buf; +#define BUFSIZE 1000000 + long usec; + struct timeval finish, start; + + buf = malloc(BUFSIZE, M_TEMP, M_NOWAIT); + if (buf == NULL) + return (BUFSIZE); + microtime(&start); + (*func)(buf, BUFSIZE); + microtime(&finish); + usec = 1000000 * (finish.tv_sec - start.tv_sec) + + finish.tv_usec - start.tv_usec; + if (usec <= 0) + usec = 1; + if (bootverbose) + printf("%s bandwidth = %ld bytes/sec\n", + funcname, (long)(BUFSIZE * 1000000ll / usec)); + free(buf, M_TEMP); + return (usec); +} +#endif /* I586_CPU */ + #endif /* NNPX > 0 */ diff --git a/sys/i386/isa/npx.c b/sys/i386/isa/npx.c index c6f2b09..7dccaa5 100644 --- a/sys/i386/isa/npx.c +++ b/sys/i386/isa/npx.c @@ -32,7 +32,7 @@ * SUCH DAMAGE. * * from: @(#)npx.c 7.2 (Berkeley) 5/12/91 - * $Id: npx.c,v 1.54 1997/11/18 11:32:31 bde Exp $ + * $Id: npx.c,v 1.55 1998/01/31 07:23:09 eivind Exp $ */ #include "npx.h" @@ -44,6 +44,7 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> +#include <sys/malloc.h> #include <sys/sysctl.h> #include <sys/conf.h> #include <sys/proc.h> @@ -132,6 +133,8 @@ typedef u_char bool_t; static int npxattach __P((struct isa_device *dvp)); static int npxprobe __P((struct isa_device *dvp)); static int npxprobe1 __P((struct isa_device *dvp)); +static long timezero __P((const char *funcname, + void (*func)(void *buf, size_t len))); struct isa_driver npxdriver = { npxprobe, npxattach, "npx", @@ -408,8 +411,10 @@ npxattach(dvp) } npxinit(__INITIAL_NPXCW__); -#if defined(I586_CPU) - if (cpu_class == CPUCLASS_586 && npx_ex16) { +#ifdef I586_CPU + if (cpu_class == CPUCLASS_586 && npx_ex16 && + timezero("i586_bzero()", i586_bzero) < + timezero("bzero()", bzero) * 4 / 5) { if (!(dvp->id_flags & NPX_DISABLE_I586_OPTIMIZED_BCOPY)) { bcopy_vector = i586_bcopy; ovbcopy_vector = i586_bcopy; @@ -663,4 +668,34 @@ npxsave(addr) #endif /* SMP */ } +#ifdef I586_CPU +static long +timezero(funcname, func) + const char *funcname; + void (*func) __P((void *buf, size_t len)); + +{ + void *buf; +#define BUFSIZE 1000000 + long usec; + struct timeval finish, start; + + buf = malloc(BUFSIZE, M_TEMP, M_NOWAIT); + if (buf == NULL) + return (BUFSIZE); + microtime(&start); + (*func)(buf, BUFSIZE); + microtime(&finish); + usec = 1000000 * (finish.tv_sec - start.tv_sec) + + finish.tv_usec - start.tv_usec; + if (usec <= 0) + usec = 1; + if (bootverbose) + printf("%s bandwidth = %ld bytes/sec\n", + funcname, (long)(BUFSIZE * 1000000ll / usec)); + free(buf, M_TEMP); + return (usec); +} +#endif /* I586_CPU */ + #endif /* NNPX > 0 */ |