| 1040 | } |
| 1041 | |
| 1042 | static struct rte_hash * |
| 1043 | init_hash(int hash_id) |
| 1044 | { |
| 1045 | int i; |
| 1046 | struct rte_hash *h = NULL; |
| 1047 | |
| 1048 | sprintf(hash_name[hash_id], "hash%d", hash_id); |
| 1049 | struct rte_hash_parameters hash_params = { |
| 1050 | .entries = TOTAL_ENTRY, |
| 1051 | .key_len = sizeof(uint32_t), |
| 1052 | .hash_func_init_val = 0, |
| 1053 | .socket_id = rte_socket_id(), |
| 1054 | .hash_func = rte_hash_crc, |
| 1055 | .extra_flag = |
| 1056 | RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF, |
| 1057 | .name = hash_name[hash_id], |
| 1058 | }; |
| 1059 | |
| 1060 | h = rte_hash_create(&hash_params); |
| 1061 | if (h == NULL) { |
| 1062 | printf("Hash create Failed\n"); |
| 1063 | return NULL; |
| 1064 | } |
| 1065 | |
| 1066 | for (i = 0; i < TOTAL_ENTRY; i++) { |
| 1067 | hash_data[hash_id][i] = |
| 1068 | rte_zmalloc(NULL, sizeof(uint32_t) * RTE_MAX_LCORE, 0); |
| 1069 | if (hash_data[hash_id][i] == NULL) { |
| 1070 | printf("No memory\n"); |
| 1071 | return NULL; |
| 1072 | } |
| 1073 | } |
| 1074 | keys = rte_malloc(NULL, sizeof(uint32_t) * TOTAL_ENTRY, 0); |
| 1075 | if (keys == NULL) { |
| 1076 | printf("No memory\n"); |
| 1077 | return NULL; |
| 1078 | } |
| 1079 | |
| 1080 | for (i = 0; i < TOTAL_ENTRY; i++) |
| 1081 | keys[i] = i; |
| 1082 | |
| 1083 | for (i = 0; i < TOTAL_ENTRY; i++) { |
| 1084 | if (rte_hash_add_key_data(h, keys + i, |
| 1085 | (void *)((uintptr_t)hash_data[hash_id][i])) |
| 1086 | < 0) { |
| 1087 | printf("Hash key add Failed #%d\n", i); |
| 1088 | return NULL; |
| 1089 | } |
| 1090 | } |
| 1091 | return h; |
| 1092 | } |
| 1093 | |
| 1094 | /* |
| 1095 | * Functional test: |
no test coverage detected