? nfs/nfshashstat.c ? nfs/nfshashstat ? nfs/nameihash.c ? nfs/nameihash Index: alpha/include/types.h =================================================================== RCS file: /home/ncvs/src/sys/alpha/include/types.h,v retrieving revision 1.13 diff -u -r1.13 types.h --- alpha/include/types.h 2000/09/13 18:33:21 1.13 +++ alpha/include/types.h 2001/03/17 09:04:38 @@ -56,8 +56,8 @@ typedef unsigned long vm_pindex_t; typedef unsigned long vm_size_t; - typedef __int64_t register_t; +typedef __uint64_t u_register_t; #ifdef _KERNEL typedef long intfptr_t; Index: i386/include/types.h =================================================================== RCS file: /home/ncvs/src/sys/i386/include/types.h,v retrieving revision 1.20 diff -u -r1.20 types.h --- i386/include/types.h 2000/09/13 18:33:22 1.20 +++ i386/include/types.h 2001/03/17 09:04:38 @@ -53,7 +53,7 @@ typedef unsigned int vm_size_t; typedef __int32_t register_t; - +typedef __uint32_t u_register_t; #ifdef _KERNEL typedef int intfptr_t; Index: ia64/include/types.h =================================================================== RCS file: /home/ncvs/src/sys/ia64/include/types.h,v retrieving revision 1.1 diff -u -r1.1 types.h --- ia64/include/types.h 2000/09/29 13:46:06 1.1 +++ ia64/include/types.h 2001/03/17 09:04:38 @@ -56,8 +56,8 @@ typedef unsigned long vm_pindex_t; typedef unsigned long vm_size_t; - typedef __int64_t register_t; +typedef __uint64_t u_register_t; #ifdef _KERNEL typedef long intfptr_t; Index: powerpc/include/types.h =================================================================== RCS file: /home/ncvs/src/sys/powerpc/include/types.h,v retrieving revision 1.1 diff -u -r1.1 types.h --- powerpc/include/types.h 2001/01/02 00:30:49 1.1 +++ powerpc/include/types.h 2001/03/17 09:04:38 @@ -55,6 +55,7 @@ typedef unsigned int vm_size_t; typedef __int32_t register_t; +typedef __uint32_t u_register_t; #ifdef _KERNEL typedef int intfptr_t; Index: kern/vfs_cache.c =================================================================== RCS file: /home/ncvs/src/sys/kern/vfs_cache.c,v retrieving revision 1.52 diff -u -r1.52 vfs_cache.c --- kern/vfs_cache.c 2000/12/08 20:08:26 1.52 +++ kern/vfs_cache.c 2001/03/17 09:04:38 @@ -48,6 +48,7 @@ #include #include #include +#include /* * This structure describes the elements in the cache of recent @@ -180,9 +181,7 @@ struct componentname *cnp; { struct namecache *ncp; - u_long hash; - u_char *cp; - int len; + u_int32_t hash; if (!doingcache) { cnp->cn_flags &= ~MAKEENTRY; @@ -209,10 +208,7 @@ } } - hash = 0; - len = cnp->cn_namelen; - for (cp = cnp->cn_nameptr; len; len--, cp++) - hash += *cp; + hash = fnv32_hashbuf(cnp->cn_nameptr, cnp->cn_namelen); LIST_FOREACH(ncp, (NCHHASH(dvp, hash)), nc_hash) { numchecks++; if (ncp->nc_dvp == dvp && ncp->nc_nlen == cnp->cn_namelen && @@ -279,8 +275,7 @@ { struct namecache *ncp; struct nchashhead *ncpp; - u_long hash; - u_char *cp, *dp; + u_int32_t hash; int len; if (!doingcache) @@ -323,10 +318,8 @@ ncp->nc_vp = vp; ncp->nc_dvp = dvp; len = ncp->nc_nlen = cnp->cn_namelen; - hash = 0; - dp = ncp->nc_name; - for (cp = cnp->cn_nameptr; len; len--, cp++, dp++) - hash += (*dp = *cp); + hash = fnv32_hashbuf(cnp->cn_nameptr, len); + bcopy(cnp->cn_nameptr, ncp->nc_name, len); ncpp = NCHHASH(dvp, hash); LIST_INSERT_HEAD(ncpp, ncp, nc_hash); if (LIST_EMPTY(&dvp->v_cache_src)) Index: sys/fnv_hash.h =================================================================== RCS file: fnv_hash.h diff -N fnv_hash.h --- /dev/null Sat Mar 17 00:15:51 2001 +++ fnv_hash.h Sat Mar 17 01:04:38 2001 @@ -0,0 +1,72 @@ +/* + * Fowler / Noll / Vo Hash (FNV Hash) + * http://www.isthe.com/chongo/tech/comp/fnv/ + * + * This is an implementation of the algorithms posted above. + * This file is placed in the public domain by Peter Wemm. + * + * $FreeBSD$ + */ + +#define FNV_32_PRIME ((u_int32_t) 0x01000193UL) +#define FNV1_32_INIT ((u_int32_t) 33554467UL) + +#define FNV_64_PRIME ((u_int64_t) 0x100000001b3ULL) +#define FNV1_64_INIT ((u_int64_t) 0xcbf29ce484222325ULL) + +static __inline u_int32_t +fnv32_hashbuf(const void *buf, size_t len) +{ + const u_int8_t *s = (const u_int8_t *)buf; + u_int32_t hval; + + hval = FNV1_32_INIT; + while (len-- != 0) { + hval *= FNV_32_PRIME; + hval ^= *s++; + } + return hval; +} + +static __inline u_int32_t +fnv32_hashstr(const char *str) +{ + const u_int8_t *s = (const u_int8_t *)str; + u_int32_t hval, c; + + hval = FNV1_32_INIT; + while ((c = *s++) != 0) { + hval *= FNV_32_PRIME; + hval ^= c; + } + return hval; +} + +static __inline u_int64_t +fnv64_hashbuf(const void *buf, size_t len) +{ + const u_int8_t *s = (const u_int8_t *)buf; + u_int64_t hval; + + hval = FNV1_64_INIT; + while (len-- != 0) { + hval *= FNV_64_PRIME; + hval ^= *s++; + } + return hval; +} + +static __inline u_int64_t +fnv64_hashstr(const char *str) +{ + const u_int8_t *s = (const u_int8_t *)str; + u_int64_t hval; + u_register_t c; /* 32 bit on i386, 64 bit on alpha,ia64 */ + + hval = FNV1_64_INIT; + while ((c = *s++) != 0) { + hval *= FNV_64_PRIME; + hval ^= c; + } + return hval; +} Index: nfs/nfs.h =================================================================== RCS file: /home/ncvs/src/sys/nfs/nfs.h,v retrieving revision 1.57 diff -u -r1.57 nfs.h --- nfs/nfs.h 2001/02/18 13:30:19 1.57 +++ nfs/nfs.h 2001/03/17 09:04:38 @@ -633,7 +633,6 @@ int nfs_adv __P((struct mbuf **, caddr_t *, int, int)); void nfs_nhinit __P((void)); void nfs_timer __P((void*)); -u_long nfs_hash __P((nfsfh_t *, int)); int nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *, struct nfsrv_descript **)); int nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *, Index: nfs/nfs_node.c =================================================================== RCS file: /home/ncvs/src/sys/nfs/nfs_node.c,v retrieving revision 1.43 diff -u -r1.43 nfs_node.c --- nfs/nfs_node.c 2001/03/17 05:43:01 1.43 +++ nfs/nfs_node.c 2001/03/17 09:04:39 @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -72,33 +73,6 @@ } /* - * Compute an entry in the NFS hash table structure - * - * Hash based on: http://www.isthe.com/chongo/tech/comp/fnv/ - * by Glenn Fowler, Phong Vo and Landon Curt Noll - * aka the "Fowler / Noll / Vo Hash" (FNV) - */ -#define FNV_32_PRIME ((u_int32_t) 0x01000193UL) -#define FNV1_32_INIT ((u_int32_t) 33554467UL) -u_long -nfs_hash(fhp, fhsize) - nfsfh_t *fhp; - int fhsize; -{ - u_char *fhpp; - u_int32_t hval; - int i; - - fhpp = &fhp->fh_bytes[0]; - hval = FNV1_32_INIT; - for (i = 0; i < fhsize; i++) { - hval *= FNV_32_PRIME; - hval ^= (u_int32_t)*fhpp++; - } - return (hval); -} - -/* * Look up a vnode/nfsnode by file handle. * Callers must check for mount points!! * In all cases, a pointer to a @@ -133,7 +107,7 @@ rsflags = 0; retry: - nhpp = NFSNOHASH(nfs_hash(fhp, fhsize)); + nhpp = NFSNOHASH(fnv32_hashbuf(fhp->fh_bytes, fhsize)); loop: for (np = nhpp->lh_first; np != 0; np = np->n_hash.le_next) { if (mntp != NFSTOV(np)->v_mount || np->n_fhsize != fhsize ||