From: Daniel Borkmann <dborkman@redhat.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: davem@davemloft.net, mingo@elte.hu, tglx@linutronix.de,
ffusco@redhat.com, tgraf@redhat.com,
linux-kernel@vger.kernel.org, hpa@zytor.com
Subject: Re: [PATCH 2/3] x86/hash: swap parameters of crc32_u32()
Date: Mon, 24 Feb 2014 11:22:24 +0100 [thread overview]
Message-ID: <530B1D60.8010602@redhat.com> (raw)
In-Reply-To: <530B0AF2020000780011E97B@nat28.tlf.novell.com>
On 02/24/2014 09:03 AM, Jan Beulich wrote:
>>>> On 22.02.14 at 13:09, Daniel Borkmann <dborkman@redhat.com> wrote:
>> On 02/21/2014 11:33 AM, Jan Beulich wrote:
>>> ... to match its two callers (i.e. the alternative would have been to
>>> swap the arguments at the call sites).
>>>
>>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>> Cc: Francesco Fusco <ffusco@redhat.com>
>>> Cc: Daniel Borkmann <dborkman@redhat.com>
>>> Cc: Thomas Graf <tgraf@redhat.com>
>>> Cc: David S. Miller <davem@davemloft.net>
>>> ---
>>> arch/x86/lib/hash.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> --- 3.14-rc3-x86-hash-crc32.orig/arch/x86/lib/hash.c
>>> +++ 3.14-rc3-x86-hash-crc32/arch/x86/lib/hash.c
>>> @@ -37,7 +37,7 @@
>>> #include <asm/cpufeature.h>
>>> #include <asm/hash.h>
>>>
>>> -static inline u32 crc32_u32(u32 crc, u32 val)
>>> +static inline u32 crc32_u32(u32 val, u32 crc)
>>> {
>>> #ifdef CONFIG_AS_CRC32
>>> asm ("crc32l %1,%0\n" : "+r" (crc) : "rm" (val));
>>
>> Can you elaborate?
>>
>> Sorry, I need to ask here (even if it's a stupid question ;)) if this
>> change is safe to do; are referring to a cleanup or fixing a concrete
>> bug? The code is a modified version of the DPDK hash which you can find
>> in [1]. Arguments of the caller are in the correct order, afaik.
>>
>> [1] http://dpdk.org/browse/dpdk/tree/lib/librte_hash/rte_hash_crc.h
>
> Yes, that file appears to be correct:
>
> rte_hash_crc_4byte(uint32_t data, uint32_t init_val)
>
> as opposed to
>
> static inline u32 crc32_u32(u32 crc, u32 val)
>
> (quite obviously data <-> val and crc <-> init_val, supported
> by the second argument in each caller being named "seed").
If you want a more descriptive name, feel free to rename these vars,
but check it yourself, it's not a bug as you claim; results are the
same:
/* gcc -march=corei7 -Wall -O2 intel_crc.c -lgsl
* ./a.out
* Result: good:10000 bad:0
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <nmmintrin.h>
#include <gsl/gsl_rng.h>
/* Kernel code */
static inline uint32_t crc32_u32(uint32_t crc, uint32_t val)
{
asm ("crc32l %1,%0\n" : "+r" (crc) : "rm" (val));
return crc;
}
static uint32_t intel_crc4_2_hash(const void *data, uint32_t len, uint32_t seed)
{
const uint32_t *p32 = (const uint32_t *) data;
uint32_t i;
for (i = 0; i < len / 4; i++)
seed = crc32_u32(*p32++, seed);
return seed;
}
/* DPDK code */
static inline uint32_t rte_hash_crc_4byte(uint32_t data, uint32_t init_val)
{
return _mm_crc32_u32(data, init_val);
}
static inline uint32_t rte_hash_crc(const void *data, uint32_t data_len,
uint32_t init_val)
{
const uint32_t *p32 = (const uint32_t *) data;
unsigned i;
for (i = 0; i < data_len / 4; i++)
init_val = rte_hash_crc_4byte(*p32++, init_val);
return init_val;
}
/* Test case */
static void fill_foo(gsl_rng *rng, void *foo, size_t len)
{
uint32_t *foo_32 = foo;
int i;
for (i = 0; i < len; i += sizeof(uint32_t))
foo_32[i] = gsl_rng_get(rng);
}
int main(void)
{
int i, good = 0, bad = 0;
gsl_rng *rng;
srand(time(NULL));
gsl_rng_default_seed = rand();
rng = gsl_rng_alloc(gsl_rng_taus113);
if (rng == NULL)
return -1;
for (i = 0; i < 10000; i++) {
char foo[sizeof(uint32_t) * 128];
uint32_t val1, val2, seed = gsl_rng_get(rng);
fill_foo(rng, foo, sizeof(foo));
val1 = rte_hash_crc(foo, sizeof(foo), seed);
val2 = intel_crc4_2_hash(foo, sizeof(foo), seed);
if (val1 != val2)
bad++;
else
good++;
}
gsl_rng_free(rng);
printf("Result: good:%d bad:%d\n", good, bad);
return 0;
}
next prev parent reply other threads:[~2014-02-24 10:22 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-21 10:33 [PATCH 2/3] x86/hash: swap parameters of crc32_u32() Jan Beulich
2014-02-22 12:09 ` Daniel Borkmann
2014-02-24 8:03 ` Jan Beulich
2014-02-24 10:22 ` Daniel Borkmann [this message]
2014-02-24 10:53 ` Jan Beulich
2014-02-24 11:46 ` Daniel Borkmann
2014-02-24 12:16 ` Jan Beulich
2014-02-24 12:32 ` H. Peter Anvin
2014-02-24 12:41 ` Jan Beulich
2014-02-24 12:51 ` H. Peter Anvin
2014-02-24 13:01 ` H. Peter Anvin
2014-02-24 13:07 ` Jan Beulich
2014-02-24 13:09 ` Daniel Borkmann
2014-02-24 13:16 ` H. Peter Anvin
2014-02-24 12:35 ` H. Peter Anvin
2014-02-25 20:26 ` H. Peter Anvin
2014-02-25 20:34 ` Daniel Borkmann
2014-02-25 20:37 ` H. Peter Anvin
2014-02-26 9:29 ` Jan Beulich
2014-02-26 16:06 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=530B1D60.8010602@redhat.com \
--to=dborkman@redhat.com \
--cc=JBeulich@suse.com \
--cc=davem@davemloft.net \
--cc=ffusco@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
--cc=tgraf@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).