MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rte_fbk_hash_create

Function rte_fbk_hash_create

dpdk/lib/hash/rte_fbk_hash.c:72–166  ·  view source on GitHub ↗

* Create a new hash table for use with four byte keys. * * @param params * Parameters used in creation of hash table. * * @return * Pointer to hash table structure that is used in future hash table * operations, or NULL on error. */

Source from the content-addressed store, hash-verified

70 * operations, or NULL on error.
71 */
72struct rte_fbk_hash_table *
73rte_fbk_hash_create(const struct rte_fbk_hash_params *params)
74{
75 struct rte_fbk_hash_table *ht = NULL;
76 struct rte_tailq_entry *te;
77 char hash_name[RTE_FBK_HASH_NAMESIZE];
78 const uint32_t mem_size =
79 sizeof(*ht) + (sizeof(ht->t[0]) * params->entries);
80 uint32_t i;
81 struct rte_fbk_hash_list *fbk_hash_list;
82 rte_fbk_hash_fn default_hash_func = (rte_fbk_hash_fn)rte_jhash_1word;
83
84 fbk_hash_list = RTE_TAILQ_CAST(rte_fbk_hash_tailq.head,
85 rte_fbk_hash_list);
86
87 /* Error checking of parameters. */
88 if ((!rte_is_power_of_2(params->entries)) ||
89 (!rte_is_power_of_2(params->entries_per_bucket)) ||
90 (params->entries == 0) ||
91 (params->entries_per_bucket == 0) ||
92 (params->entries_per_bucket > params->entries) ||
93 (params->entries > RTE_FBK_HASH_ENTRIES_MAX) ||
94 (params->entries_per_bucket > RTE_FBK_HASH_ENTRIES_PER_BUCKET_MAX)){
95 rte_errno = EINVAL;
96 return NULL;
97 }
98
99 snprintf(hash_name, sizeof(hash_name), "FBK_%s", params->name);
100
101 rte_mcfg_tailq_write_lock();
102
103 /* guarantee there's no existing */
104 TAILQ_FOREACH(te, fbk_hash_list, next) {
105 ht = (struct rte_fbk_hash_table *) te->data;
106 if (strncmp(params->name, ht->name, RTE_FBK_HASH_NAMESIZE) == 0)
107 break;
108 }
109 ht = NULL;
110 if (te != NULL) {
111 rte_errno = EEXIST;
112 goto exit;
113 }
114
115 te = rte_zmalloc("FBK_HASH_TAILQ_ENTRY", sizeof(*te), 0);
116 if (te == NULL) {
117 RTE_LOG(ERR, HASH, "Failed to allocate tailq entry\n");
118 goto exit;
119 }
120
121 /* Allocate memory for table. */
122 ht = rte_zmalloc_socket(hash_name, mem_size,
123 0, params->socket_id);
124 if (ht == NULL) {
125 RTE_LOG(ERR, HASH, "Failed to allocate fbk hash table\n");
126 rte_free(te);
127 goto exit;
128 }
129

Callers 6

fbk_create_freeFunction · 0.85
fbk_hash_perf_testFunction · 0.85
fbk_hash_unit_testFunction · 0.85
init_mcast_hashFunction · 0.85

Calls 10

snprintfFunction · 0.85
strncmpFunction · 0.85
rte_zmallocFunction · 0.85
rte_zmalloc_socketFunction · 0.85
rte_freeFunction · 0.85
rte_is_power_of_2Function · 0.50
rte_cpu_get_flag_enabledFunction · 0.50
strlcpyFunction · 0.50

Tested by 5

fbk_create_freeFunction · 0.68
fbk_hash_perf_testFunction · 0.68
fbk_hash_unit_testFunction · 0.68