Acked-by: Jarno Rajahalme <ja...@ovn.org>

> On Jan 18, 2016, at 11:27 PM, Ben Pfaff <b...@ovn.org> wrote:
> 
> All of the callers of hash_words() and hash_words64() actually find it
> easier to pass in the number of bytes instead of the number of 32-bit
> or 64-bit words.  These new functions allow the callers to be a little
> simpler.
> 
> Signed-off-by: Ben Pfaff <b...@ovn.org>
> ---
> lib/flow.h                 |  5 ++---
> lib/hash.h                 | 14 +++++++++++++-
> lib/odp-util.c             |  5 ++---
> lib/ofp-msgs.c             |  6 +++---
> ofproto/ofproto-dpif-rid.c | 19 ++++++++-----------
> 5 files changed, 28 insertions(+), 21 deletions(-)
> 
> diff --git a/lib/flow.h b/lib/flow.h
> index 5d78615..dc7130d 100644
> --- a/lib/flow.h
> +++ b/lib/flow.h
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
> + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 
> Nicira, Inc.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
> @@ -263,8 +263,7 @@ flow_equal(const struct flow *a, const struct flow *b)
> static inline size_t
> flow_hash(const struct flow *flow, uint32_t basis)
> {
> -    return hash_words64((const uint64_t *)flow,
> -                        sizeof *flow / sizeof(uint64_t), basis);
> +    return hash_bytes64((const uint64_t *)flow, sizeof *flow, basis);
> }
> 
> static inline uint16_t
> diff --git a/lib/hash.h b/lib/hash.h
> index 65c52b9..114a419 100644
> --- a/lib/hash.h
> +++ b/lib/hash.h
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2008, 2009, 2010, 2012, 2013, 2014 Nicira, Inc.
> + * Copyright (c) 2008, 2009, 2010, 2012, 2013, 2014, 2016 Nicira, Inc.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
> @@ -323,6 +323,18 @@ hash_words64(const uint64_t p[], size_t n_words, 
> uint32_t basis)
> }
> #endif
> 
> +static inline uint32_t
> +hash_bytes32(const uint32_t p[], size_t n_bytes, uint32_t basis)
> +{
> +    return hash_words(p, n_bytes / 4, basis);
> +}
> +
> +static inline uint32_t
> +hash_bytes64(const uint64_t p[], size_t n_bytes, uint32_t basis)
> +{
> +    return hash_words64(p, n_bytes / 8, basis);
> +}
> +
> static inline uint32_t hash_string(const char *s, uint32_t basis)
> {
>     return hash_bytes(s, strlen(s), basis);
> diff --git a/lib/odp-util.c b/lib/odp-util.c
> index f16e113..6271601 100644
> --- a/lib/odp-util.c
> +++ b/lib/odp-util.c
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
> + * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
> @@ -4532,8 +4532,7 @@ uint32_t
> odp_flow_key_hash(const struct nlattr *key, size_t key_len)
> {
>     BUILD_ASSERT_DECL(!(NLA_ALIGNTO % sizeof(uint32_t)));
> -    return hash_words(ALIGNED_CAST(const uint32_t *, key),
> -                      key_len / sizeof(uint32_t), 0);
> +    return hash_bytes32(ALIGNED_CAST(const uint32_t *, key), key_len, 0);
> }
> 
> static void
> diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c
> index cb27f79..944ab33 100644
> --- a/lib/ofp-msgs.c
> +++ b/lib/ofp-msgs.c
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2012, 2013, 2014, 2015 Nicira, Inc.
> + * Copyright (c) 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
> @@ -118,8 +118,8 @@ alloc_xid(void)
> static uint32_t
> ofphdrs_hash(const struct ofphdrs *hdrs)
> {
> -    BUILD_ASSERT_DECL(sizeof *hdrs == 12);
> -    return hash_words((const uint32_t *) hdrs, 3, 0);
> +    BUILD_ASSERT_DECL(sizeof *hdrs % 4 == 0);
> +    return hash_bytes32((const uint32_t *) hdrs, sizeof *hdrs, 0);
> }
> 
> static bool
> diff --git a/ofproto/ofproto-dpif-rid.c b/ofproto/ofproto-dpif-rid.c
> index d142933..cb00301 100644
> --- a/ofproto/ofproto-dpif-rid.c
> +++ b/ofproto/ofproto-dpif-rid.c
> @@ -135,25 +135,22 @@ recirc_metadata_hash(const struct recirc_state *state)
>     if (flow_tnl_dst_is_set(state->metadata.tunnel)) {
>         /* We may leave remainder bytes unhashed, but that is unlikely as
>          * the tunnel is not in the datapath format. */
> -        hash = hash_words64((const uint64_t *) state->metadata.tunnel,
> -                            flow_tnl_size(state->metadata.tunnel)
> -                            / sizeof(uint64_t), hash);
> +        hash = hash_bytes64((const uint64_t *) state->metadata.tunnel,
> +                            flow_tnl_size(state->metadata.tunnel), hash);
>     }
>     hash = hash_boolean(state->conntracked, hash);
> -    hash = hash_words64((const uint64_t *) &state->metadata.metadata,
> -                        (sizeof state->metadata - sizeof 
> state->metadata.tunnel)
> -                        / sizeof(uint64_t),
> +    hash = hash_bytes64((const uint64_t *) &state->metadata.metadata,
> +                        sizeof state->metadata - sizeof 
> state->metadata.tunnel,
>                         hash);
>     if (state->stack && state->stack->size != 0) {
> -        hash = hash_words64((const uint64_t *) state->stack->data,
> -                            state->stack->size / sizeof(uint64_t), hash);
> +        hash = hash_bytes64((const uint64_t *) state->stack->data,
> +                            state->stack->size, hash);
>     }
>     hash = hash_int(state->mirrors, hash);
>     hash = hash_int(state->action_set_len, hash);
>     if (state->ofpacts_len) {
> -        hash = hash_words64(ALIGNED_CAST(const uint64_t *, state->ofpacts),
> -                            state->ofpacts_len / sizeof(uint64_t),
> -                            hash);
> +        hash = hash_bytes64(ALIGNED_CAST(const uint64_t *, state->ofpacts),
> +                            state->ofpacts_len, hash);
>     }
>     return hash;
> }
> -- 
> 2.1.3
> 
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to