From patchwork Mon Aug 6 14:13:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Emelyanov X-Patchwork-Id: 175363 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 173A12C00A8 for ; Tue, 7 Aug 2012 00:13:56 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754867Ab2HFONy (ORCPT ); Mon, 6 Aug 2012 10:13:54 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:5771 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756074Ab2HFONx (ORCPT ); Mon, 6 Aug 2012 10:13:53 -0400 Received: from [10.30.22.37] ([10.30.22.37]) (authenticated bits=0) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id q76EDm7S023053 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 6 Aug 2012 18:13:48 +0400 (MSK) Message-ID: <501FD11B.6000006@parallels.com> Date: Mon, 06 Aug 2012 18:13:47 +0400 From: Pavel Emelyanov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120209 Thunderbird/10.0.1 MIME-Version: 1.0 To: David Miller , Eric Dumazet , "Eric W. Biederman" , Linux Netdev List Subject: [PATCH 1/6] hash: Introduce ptr_hash_mix routine References: <501FD0F2.4040609@parallels.com> In-Reply-To: <501FD0F2.4040609@parallels.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This one is used to make a salt out of a pointer to be mixed to some hash function later. Idea and implementation are proposed by Eric Dumazet. Signed-off-by: Pavel Emelyanov --- include/linux/hash.h | 10 ++++++++++ include/net/netns/hash.h | 9 ++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/linux/hash.h b/include/linux/hash.h index b80506b..1bd0ab1 100644 --- a/include/linux/hash.h +++ b/include/linux/hash.h @@ -14,6 +14,7 @@ * machines where multiplications are slow. */ +#include #include /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ @@ -67,4 +68,13 @@ static inline unsigned long hash_ptr(const void *ptr, unsigned int bits) { return hash_long((unsigned long)ptr, bits); } + +static inline u32 ptr_hash_mix(const void *ptr) +{ +#if BITS_PER_LONG == 32 + return (u32)(unsigned long)ptr; +#else + return (u32)((unsigned long)ptr >> L1_CACHE_SHIFT); +#endif +} #endif /* _LINUX_HASH_H */ diff --git a/include/net/netns/hash.h b/include/net/netns/hash.h index c06ac58..bcdabe0 100644 --- a/include/net/netns/hash.h +++ b/include/net/netns/hash.h @@ -1,19 +1,14 @@ #ifndef __NET_NS_HASH_H__ #define __NET_NS_HASH_H__ -#include +#include struct net; static inline unsigned int net_hash_mix(struct net *net) { #ifdef CONFIG_NET_NS - /* - * shift this right to eliminate bits, that are - * always zeroed - */ - - return (unsigned)(((unsigned long)net) >> L1_CACHE_SHIFT); + return ptr_hash_mix(net); #else return 0; #endif