Skip to content

Commit

Permalink
Jhash: add linux kernel jhashtable in qemu
Browse files Browse the repository at this point in the history
Jhash will be used by colo-compare and filter-rewriter
to save and lookup net connection info

Signed-off-by: Zhang Chen <[email protected]>
Signed-off-by: Li Zhijian <[email protected]>
Signed-off-by: Wen Congyang <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
  • Loading branch information
zhangckid authored and jasowang committed Sep 27, 2016
1 parent 59509ec commit ccf0426
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
59 changes: 59 additions & 0 deletions include/qemu/jhash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* jhash.h: Jenkins hash support.
*
* Copyright (C) 2006. Bob Jenkins ([email protected])
*
* http://burtleburtle.net/bob/hash/
*
* These are the credits from Bob's sources:
*
* lookup3.c, by Bob Jenkins, May 2006, Public Domain.
*
* These are functions for producing 32-bit hashes for hash table lookup.
* hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
* are externally useful functions. Routines to test the hash are included
* if SELF_TEST is defined. You can use this free for any purpose. It's in
* the public domain. It has no warranty.
*
* Copyright (C) 2009-2010 Jozsef Kadlecsik ([email protected])
*
* I've modified Bob's hash to be useful in the Linux kernel, and
* any bugs present are my fault.
* Jozsef
*/

#ifndef QEMU_JHASH_H__
#define QEMU_JHASH_H__

#include "qemu/bitops.h"

/*
* hashtable relation copy from linux kernel jhash
*/

/* __jhash_mix -- mix 3 32-bit values reversibly. */
#define __jhash_mix(a, b, c) \
{ \
a -= c; a ^= rol32(c, 4); c += b; \
b -= a; b ^= rol32(a, 6); a += c; \
c -= b; c ^= rol32(b, 8); b += a; \
a -= c; a ^= rol32(c, 16); c += b; \
b -= a; b ^= rol32(a, 19); a += c; \
c -= b; c ^= rol32(b, 4); b += a; \
}

/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
#define __jhash_final(a, b, c) \
{ \
c ^= b; c -= rol32(b, 14); \
a ^= c; a -= rol32(c, 11); \
b ^= a; b -= rol32(a, 25); \
c ^= b; c -= rol32(b, 16); \
a ^= c; a -= rol32(c, 4); \
b ^= a; b -= rol32(a, 14); \
c ^= b; c -= rol32(b, 24); \
}

/* An arbitrary initial parameter */
#define JHASH_INITVAL 0xdeadbeef

#endif /* QEMU_JHASH_H__ */
1 change: 1 addition & 0 deletions net/colo.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define QEMU_COLO_PROXY_H

#include "slirp/slirp.h"
#include "qemu/jhash.h"

#define HASHTABLE_MAX_SIZE 16384

Expand Down

0 comments on commit ccf0426

Please sign in to comment.