| 326 | } |
| 327 | |
| 328 | static struct rte_hash *init_hash(void) |
| 329 | { |
| 330 | int i; |
| 331 | struct rte_hash *hash = NULL; |
| 332 | |
| 333 | snprintf(hash_name, 8, "hash"); |
| 334 | struct rte_hash_parameters hash_params = { |
| 335 | .entries = TOTAL_ENTRY, |
| 336 | .key_len = sizeof(uint32_t), |
| 337 | .hash_func_init_val = 0, |
| 338 | .socket_id = rte_socket_id(), |
| 339 | .hash_func = rte_hash_crc, |
| 340 | .extra_flag = |
| 341 | RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF, |
| 342 | .name = hash_name, |
| 343 | }; |
| 344 | |
| 345 | hash = rte_hash_create(&hash_params); |
| 346 | if (hash == NULL) { |
| 347 | printf("Hash create Failed\n"); |
| 348 | return NULL; |
| 349 | } |
| 350 | |
| 351 | for (i = 0; i < TOTAL_ENTRY; i++) { |
| 352 | hash_data[i] = rte_zmalloc(NULL, |
| 353 | sizeof(uint32_t) * RTE_MAX_LCORE, 0); |
| 354 | if (hash_data[i] == NULL) { |
| 355 | printf("No memory\n"); |
| 356 | return NULL; |
| 357 | } |
| 358 | } |
| 359 | keys = rte_malloc(NULL, sizeof(uint32_t) * TOTAL_ENTRY, 0); |
| 360 | if (keys == NULL) { |
| 361 | printf("No memory\n"); |
| 362 | return NULL; |
| 363 | } |
| 364 | |
| 365 | for (i = 0; i < TOTAL_ENTRY; i++) |
| 366 | keys[i] = i; |
| 367 | |
| 368 | for (i = 0; i < TOTAL_ENTRY; i++) { |
| 369 | if (rte_hash_add_key_data(hash, keys + i, |
| 370 | (void *)((uintptr_t)hash_data[i])) < 0) { |
| 371 | printf("Hash key add Failed #%d\n", i); |
| 372 | return NULL; |
| 373 | } |
| 374 | } |
| 375 | return hash; |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * Functional test: |
no test coverage detected