Replace the name with Linux defined hash_long.
The similar patch has already been submitted upstream.
Signed-off-by: Peng Tao <bergwolf@gmail.com>
Change-Id: Ia96bb703284ed4843c4433a1a50539d9c68ed6d1
Reviewed-on: http://review.whamcloud.com/9268
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Liang Zhen <liang.zhen@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
#if (defined __linux__ && defined __KERNEL__)
#include <linux/hash.h>
-
-#define cfs_hash_long(val, bits) hash_long(val, bits)
#else
/* Fast hashing routine for a long.
(C) 2002 William Lee Irwin III, IBM */
#error Define CFS_GOLDEN_RATIO_PRIME for your wordsize.
#endif
-static inline unsigned long cfs_hash_long(unsigned long val, unsigned int bits)
+static inline unsigned long hash_long(unsigned long val, unsigned int bits)
{
unsigned long hash = val;
#if 0
static inline unsigned long hash_ptr(void *ptr, unsigned int bits)
{
- return cfs_hash_long((unsigned long)ptr, bits);
+ return hash_long((unsigned long)ptr, bits);
}
#endif
#define GOLDEN_RATIO_PRIME_32 0x9e370001UL
#if 0 /* defined in libcfs/libcfs_hash.h */
-static inline u32 cfs_hash_long(u32 val, unsigned int bits)
+static inline u32 hash_long(u32 val, unsigned int bits)
{
/* On some cpus multiply is faster, on others gcc will do shifts */
u32 hash = val * GOLDEN_RATIO_PRIME_32;
static inline int
lnet_nid2peerhash(lnet_nid_t nid)
{
- return cfs_hash_long(nid, LNET_PEER_HASH_BITS);
+ return hash_long(nid, LNET_PEER_HASH_BITS);
}
static inline cfs_list_t *
if (number == 1)
return 0;
- val = cfs_hash_long(key, LNET_CPT_BITS);
+ val = hash_long(key, LNET_CPT_BITS);
/* NB: LNET_CP_NUMBER doesn't have to be PO2 */
if (val < number)
return val;
unsigned long hash = mbits + id.nid + id.pid;
LASSERT(lnet_ptl_is_unique(ptl));
- hash = cfs_hash_long(hash, LNET_MT_HASH_BITS);
+ hash = hash_long(hash, LNET_MT_HASH_BITS);
return &mtable->mt_mhash[hash];
}
}
static inline __u32 fid_hash(const struct lu_fid *f, int bits)
{
- /* all objects with same id and different versions will belong to same
- * collisions list. */
- return cfs_hash_long(fid_flatten(f), bits);
+ /* all objects with same id and different versions will belong to same
+ * collisions list. */
+ return hash_long(fid_flatten(f), bits);
}
/**
fid.f_oid = (__u32)id->name[LUSTRE_RES_ID_VER_OID_OFF];
fid.f_ver = (__u32)(id->name[LUSTRE_RES_ID_VER_OID_OFF] >> 32);
- hash = fid_flatten32(&fid);
- hash += (hash >> 4) + (hash << 12); /* mixing oid and seq */
- if (id->name[LUSTRE_RES_ID_HSH_OFF] != 0) {
- val = id->name[LUSTRE_RES_ID_HSH_OFF];
- hash += (val >> 5) + (val << 11);
- } else {
- val = fid_oid(&fid);
- }
- hash = cfs_hash_long(hash, hs->hs_bkt_bits);
- /* give me another random factor */
- hash -= cfs_hash_long((unsigned long)hs, val % 11 + 3);
+ hash = fid_flatten32(&fid);
+ hash += (hash >> 4) + (hash << 12); /* mixing oid and seq */
+ if (id->name[LUSTRE_RES_ID_HSH_OFF] != 0) {
+ val = id->name[LUSTRE_RES_ID_HSH_OFF];
+ hash += (val >> 5) + (val << 11);
+ } else {
+ val = fid_oid(&fid);
+ }
+ hash = hash_long(hash, hs->hs_bkt_bits);
+ /* give me another random factor */
+ hash -= hash_long((unsigned long)hs, val % 11 + 3);
- hash <<= hs->hs_cur_bits - hs->hs_bkt_bits;
- hash |= ldlm_res_hop_hash(hs, key, CFS_HASH_NBKT(hs) - 1);
+ hash <<= hs->hs_cur_bits - hs->hs_bkt_bits;
+ hash |= ldlm_res_hop_hash(hs, key, CFS_HASH_NBKT(hs) - 1);
- return hash & mask;
+ return hash & mask;
}
static void *ldlm_res_hop_key(cfs_hlist_node_t *hnode)
}
static unsigned lu_obj_hop_hash(cfs_hash_t *hs,
- const void *key, unsigned mask)
+ const void *key, unsigned mask)
{
- struct lu_fid *fid = (struct lu_fid *)key;
- __u32 hash;
+ struct lu_fid *fid = (struct lu_fid *)key;
+ __u32 hash;
- hash = fid_flatten32(fid);
- hash += (hash >> 4) + (hash << 12); /* mixing oid and seq */
- hash = cfs_hash_long(hash, hs->hs_bkt_bits);
+ hash = fid_flatten32(fid);
+ hash += (hash >> 4) + (hash << 12); /* mixing oid and seq */
+ hash = hash_long(hash, hs->hs_bkt_bits);
- /* give me another random factor */
- hash -= cfs_hash_long((unsigned long)hs, fid_oid(fid) % 11 + 3);
+ /* give me another random factor */
+ hash -= hash_long((unsigned long)hs, fid_oid(fid) % 11 + 3);
- hash <<= hs->hs_cur_bits - hs->hs_bkt_bits;
- hash |= (fid_seq(fid) + fid_oid(fid)) & (CFS_HASH_NBKT(hs) - 1);
+ hash <<= hs->hs_cur_bits - hs->hs_bkt_bits;
+ hash |= (fid_seq(fid) + fid_oid(fid)) & (CFS_HASH_NBKT(hs) - 1);
- return hash & mask;
+ return hash & mask;
}
static void *lu_obj_hop_object(cfs_hlist_node_t *hnode)
static inline unsigned long hash_mem(char *buf, int length, int bits)
{
- unsigned long hash = 0;
- unsigned long l = 0;
- int len = 0;
- unsigned char c;
-
- do {
- if (len == length) {
- c = (char) len;
- len = -1;
- } else
- c = *buf++;
-
- l = (l << 8) | c;
- len++;
-
- if ((len & (BITS_PER_LONG/8-1)) == 0)
- hash = cfs_hash_long(hash^l, BITS_PER_LONG);
- } while (len);
-
- return hash >> (BITS_PER_LONG - bits);
+ unsigned long hash = 0;
+ unsigned long l = 0;
+ int len = 0;
+ unsigned char c;
+
+ do {
+ if (len == length) {
+ c = (char) len;
+ len = -1;
+ } else
+ c = *buf++;
+
+ l = (l << 8) | c;
+ len++;
+
+ if ((len & (BITS_PER_LONG/8-1)) == 0)
+ hash = hash_long(hash^l, BITS_PER_LONG);
+ } while (len);
+
+ return hash >> (BITS_PER_LONG - bits);
}
/* This compatibility can be removed once kernel 3.3 is used,