From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 315E6C510 for ; Mon, 29 Jun 2015 00:25:33 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 28 Jun 2015 15:25:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,695,1427785200"; d="scan'208";a="736499437" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 28 Jun 2015 15:25:31 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t5SMPUrE030613; Sun, 28 Jun 2015 23:25:30 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t5SMPU09010180; Sun, 28 Jun 2015 23:25:30 +0100 Received: (from pdelarax@localhost) by sivswdev02.ir.intel.com with id t5SMPUs0010176; Sun, 28 Jun 2015 23:25:30 +0100 From: Pablo de Lara To: dev@dpdk.org Date: Sun, 28 Jun 2015 23:25:21 +0100 Message-Id: <1435530330-10132-3-git-send-email-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1435530330-10132-1-git-send-email-pablo.de.lara.guarch@intel.com> References: <1435269919-7007-1-git-send-email-pablo.de.lara.guarch@intel.com> <1435530330-10132-1-git-send-email-pablo.de.lara.guarch@intel.com> Subject: [dpdk-dev] [PATCH v3 02/11] hash: move rte_hash structure to C file and make it internal X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Jun 2015 22:25:34 -0000 rte_hash structure should not be a public structure, and therefore it should be moved to the C file and be declared as internal. This patch also removes part of a unit test that was checking a field of the structure. Signed-off-by: Pablo de Lara --- app/test/test_hash.c | 6 +----- lib/librte_hash/rte_hash.c | 30 +++++++++++++++++++++++++++++- lib/librte_hash/rte_hash.h | 37 +++++-------------------------------- 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/app/test/test_hash.c b/app/test/test_hash.c index 4ecb11b..4300de9 100644 --- a/app/test/test_hash.c +++ b/app/test/test_hash.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -1110,10 +1110,6 @@ test_hash_creation_with_good_parameters(void) printf("Creating hash with null hash_func failed\n"); return -1; } - if (handle->hash_func == NULL) { - printf("Hash function should have been DEFAULT_HASH_FUNC\n"); - return -1; - } /* this test is trying to create a hash with the same name as previous one. * this should return a pointer to the hash we previously created. diff --git a/lib/librte_hash/rte_hash.c b/lib/librte_hash/rte_hash.c index 67dff5b..5100a75 100644 --- a/lib/librte_hash/rte_hash.c +++ b/lib/librte_hash/rte_hash.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -92,6 +92,27 @@ EAL_REGISTER_TAILQ(rte_hash_tailq) /* The high bit is always set in real signatures */ #define NULL_SIGNATURE 0 +struct rte_hash { + char name[RTE_HASH_NAMESIZE]; /**< Name of the hash. */ + uint32_t entries; /**< Total table entries. */ + uint32_t bucket_entries; /**< Bucket entries. */ + uint32_t key_len; /**< Length of hash key. */ + rte_hash_function hash_func; /**< Function used to calculate hash. */ + uint32_t hash_func_init_val; /**< Init value used by hash_func. */ + uint32_t num_buckets; /**< Number of buckets in table. */ + uint32_t bucket_bitmask; /**< Bitmask for getting bucket index + from hash signature. */ + hash_sig_t sig_msb; /**< MSB is always set in valid signatures. */ + uint8_t *sig_tbl; /**< Flat array of hash signature buckets. */ + uint32_t sig_tbl_bucket_size; /**< Signature buckets may be padded for + alignment reasons, and this is the + bucket size used by sig_tbl. */ + uint8_t *key_tbl; /**< Flat array of key value buckets. */ + uint32_t key_tbl_key_size; /**< Keys may be padded for alignment + reasons, and this is the key size + used by key_tbl. */ +}; + /* Returns a pointer to the first signature in specified bucket. */ static inline hash_sig_t * get_sig_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index) @@ -291,6 +312,13 @@ rte_hash_free(struct rte_hash *h) rte_free(te); } +hash_sig_t +rte_hash_hash(const struct rte_hash *h, const void *key) +{ + /* calc hash result by key */ + return h->hash_func(key, h->key_len, h->hash_func_init_val); +} + static inline int32_t __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig) diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h index 821a9d4..79827a6 100644 --- a/lib/librte_hash/rte_hash.h +++ b/lib/librte_hash/rte_hash.h @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,9 +40,6 @@ * RTE Hash Table */ -#include -#include - #ifdef __cplusplus extern "C" { #endif @@ -84,27 +81,8 @@ struct rte_hash_parameters { int socket_id; /**< NUMA Socket ID for memory. */ }; -/** A hash table structure. */ -struct rte_hash { - char name[RTE_HASH_NAMESIZE]; /**< Name of the hash. */ - uint32_t entries; /**< Total table entries. */ - uint32_t bucket_entries; /**< Bucket entries. */ - uint32_t key_len; /**< Length of hash key. */ - rte_hash_function hash_func; /**< Function used to calculate hash. */ - uint32_t hash_func_init_val; /**< Init value used by hash_func. */ - uint32_t num_buckets; /**< Number of buckets in table. */ - uint32_t bucket_bitmask; /**< Bitmask for getting bucket index - from hash signature. */ - hash_sig_t sig_msb; /**< MSB is always set in valid signatures. */ - uint8_t *sig_tbl; /**< Flat array of hash signature buckets. */ - uint32_t sig_tbl_bucket_size; /**< Signature buckets may be padded for - alignment reasons, and this is the - bucket size used by sig_tbl. */ - uint8_t *key_tbl; /**< Flat array of key value buckets. */ - uint32_t key_tbl_key_size; /**< Keys may be padded for alignment - reasons, and this is the key size - used by key_tbl. */ -}; +/** @internal A hash table structure. */ +struct rte_hash; /** * Create a new hash table. @@ -262,7 +240,6 @@ int32_t rte_hash_lookup_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig); - /** * Calc a hash value by key. This operation is not multi-process safe. * @@ -273,12 +250,8 @@ rte_hash_lookup_with_hash(const struct rte_hash *h, * @return * - hash value */ -static inline hash_sig_t -rte_hash_hash(const struct rte_hash *h, const void *key) -{ - /* calc hash result by key */ - return h->hash_func(key, h->key_len, h->hash_func_init_val); -} +hash_sig_t +rte_hash_hash(const struct rte_hash *h, const void *key); #define rte_hash_lookup_multi rte_hash_lookup_bulk /** -- 2.4.2