test/crypto: change failure condition check
[dpdk.git] / app / test / test_hash_readwrite_lf.c
index 4ab4c8e..1f2fba4 100644 (file)
@@ -86,7 +86,6 @@ static rte_atomic64_t gread_cycles;
 static rte_atomic64_t greads;
 
 static volatile uint8_t writer_done;
-static volatile uint8_t multi_writer_done[4];
 
 uint16_t enabled_core_ids[RTE_MAX_LCORE];
 
@@ -127,11 +126,9 @@ get_enabled_cores_list(void)
        uint32_t i = 0;
        uint16_t core_id;
        uint32_t max_cores = rte_lcore_count();
-       for (core_id = 0; core_id < RTE_MAX_LCORE && i < max_cores; core_id++) {
-               if (rte_lcore_is_enabled(core_id)) {
-                       enabled_core_ids[i] = core_id;
-                       i++;
-               }
+       RTE_LCORE_FOREACH(core_id) {
+               enabled_core_ids[i] = core_id;
+               i++;
        }
 
        if (i != max_cores) {
@@ -142,6 +139,52 @@ get_enabled_cores_list(void)
        return 0;
 }
 
+static int
+init_params(int rwc_lf, int use_jhash, int htm, int ext_bkt)
+{
+       struct rte_hash *handle;
+
+       struct rte_hash_parameters hash_params = {
+               .entries = TOTAL_ENTRY,
+               .key_len = sizeof(uint32_t),
+               .hash_func_init_val = 0,
+               .socket_id = rte_socket_id(),
+       };
+
+       if (use_jhash)
+               hash_params.hash_func = rte_jhash;
+       else
+               hash_params.hash_func = rte_hash_crc;
+
+       if (rwc_lf)
+               hash_params.extra_flag =
+                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF |
+                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
+       else if (htm)
+               hash_params.extra_flag =
+                       RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT |
+                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY |
+                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
+       else
+               hash_params.extra_flag =
+                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY |
+                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
+
+       if (ext_bkt)
+               hash_params.extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
+
+       hash_params.name = "tests";
+
+       handle = rte_hash_create(&hash_params);
+       if (handle == NULL) {
+               printf("hash creation failed");
+               return -1;
+       }
+
+       tbl_rwc_test_param.h = handle;
+       return 0;
+}
+
 static inline int
 check_bucket(uint32_t bkt_idx, uint32_t key)
 {
@@ -216,6 +259,9 @@ generate_keys(void)
        uint32_t count_keys_extbkt = 0;
        uint32_t i;
 
+       if (init_params(0, 0, 0, 0) != 0)
+               return -1;
+
        /*
         * keys will consist of a) keys whose addition to the hash table
         * will result in shifting of the existing keys to their alternate
@@ -489,6 +535,7 @@ generate_keys(void)
               tbl_rwc_test_param.count_keys_ks_extbkt);
 
        rte_free(found);
+       rte_free(scanned_bkts);
        rte_hash_free(tbl_rwc_test_param.h);
        return 0;
 
@@ -499,58 +546,14 @@ err:
        rte_free(keys_absent);
        rte_free(found);
        rte_free(tbl_rwc_test_param.keys_shift_path);
+       rte_free(keys_non_shift_path);
        rte_free(keys_ext_bkt);
        rte_free(keys_ks_extbkt);
        rte_free(scanned_bkts);
+       rte_hash_free(tbl_rwc_test_param.h);
        return -1;
 }
 
-static int
-init_params(int rwc_lf, int use_jhash, int htm, int ext_bkt)
-{
-       struct rte_hash *handle;
-
-       struct rte_hash_parameters hash_params = {
-               .entries = TOTAL_ENTRY,
-               .key_len = sizeof(uint32_t),
-               .hash_func_init_val = 0,
-               .socket_id = rte_socket_id(),
-       };
-
-       if (use_jhash)
-               hash_params.hash_func = rte_jhash;
-       else
-               hash_params.hash_func = rte_hash_crc;
-
-       if (rwc_lf)
-               hash_params.extra_flag =
-                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF |
-                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
-       else if (htm)
-               hash_params.extra_flag =
-                       RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT |
-                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY |
-                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
-       else
-               hash_params.extra_flag =
-                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY |
-                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
-
-       if (ext_bkt)
-               hash_params.extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
-
-       hash_params.name = "tests";
-
-       handle = rte_hash_create(&hash_params);
-       if (handle == NULL) {
-               printf("hash creation failed");
-               return -1;
-       }
-
-       tbl_rwc_test_param.h = handle;
-       return 0;
-}
-
 static int
 test_rwc_reader(__attribute__((unused)) void *arg)
 {
@@ -562,16 +565,9 @@ test_rwc_reader(__attribute__((unused)) void *arg)
        uint32_t read_cnt;
        uint32_t *keys;
        uint32_t extra_keys;
-       int32_t *pos;
+       int32_t pos[BULK_LOOKUP_SIZE];
        void *temp_a[BULK_LOOKUP_SIZE];
 
-       /* Used to identify keys not inserted in the hash table */
-       pos = rte_malloc(NULL, sizeof(uint32_t) * BULK_LOOKUP_SIZE, 0);
-       if (pos == NULL) {
-               printf("RTE_MALLOC failed\n");
-               return -1;
-       }
-
        if (read_type & READ_FAIL) {
                keys = tbl_rwc_test_param.keys_absent;
                read_cnt = tbl_rwc_test_param.count_keys_absent;
@@ -690,7 +686,6 @@ test_rwc_multi_writer(__attribute__((unused)) void *arg)
        for (i = offset; i < offset + tbl_rwc_test_param.single_insert; i++)
                rte_hash_add_key(tbl_rwc_test_param.h,
                                 tbl_rwc_test_param.keys_ks + i);
-       multi_writer_done[pos_core] = 1;
        return 0;
 }
 
@@ -738,10 +733,9 @@ test_hash_add_no_ks_lookup_hit(struct rwc_perf *rwc_perf_results, int rwc_lf,
                                rte_eal_remote_launch(test_rwc_reader,
                                                (void *)(uintptr_t)read_type,
                                                        enabled_core_ids[i]);
-                       rte_eal_mp_wait_lcore();
 
                        for (i = 1; i <= rwc_core_cnt[n]; i++)
-                               if (lcore_config[i].ret < 0)
+                               if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
                                        goto err;
 
                        unsigned long long cycles_per_lookup =
@@ -758,6 +752,7 @@ finish:
        return 0;
 
 err:
+       rte_eal_mp_wait_lcore();
        rte_hash_free(tbl_rwc_test_param.h);
        return -1;
 }
@@ -808,12 +803,11 @@ test_hash_add_no_ks_lookup_miss(struct rwc_perf *rwc_perf_results, int rwc_lf,
                                                        enabled_core_ids[i]);
                        ret = write_keys(write_type);
                        writer_done = 1;
-                       rte_eal_mp_wait_lcore();
 
                        if (ret < 0)
                                goto err;
                        for (i = 1; i <= rwc_core_cnt[n]; i++)
-                               if (lcore_config[i].ret < 0)
+                               if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
                                        goto err;
 
                        unsigned long long cycles_per_lookup =
@@ -830,6 +824,7 @@ finish:
        return 0;
 
 err:
+       rte_eal_mp_wait_lcore();
        rte_hash_free(tbl_rwc_test_param.h);
        return -1;
 }
@@ -884,12 +879,11 @@ test_hash_add_ks_lookup_hit_non_sp(struct rwc_perf *rwc_perf_results,
                        write_type = WRITE_KEY_SHIFT;
                        ret = write_keys(write_type);
                        writer_done = 1;
-                       rte_eal_mp_wait_lcore();
 
                        if (ret < 0)
                                goto err;
                        for (i = 1; i <= rwc_core_cnt[n]; i++)
-                               if (lcore_config[i].ret < 0)
+                               if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
                                        goto err;
 
                        unsigned long long cycles_per_lookup =
@@ -906,6 +900,7 @@ finish:
        return 0;
 
 err:
+       rte_eal_mp_wait_lcore();
        rte_hash_free(tbl_rwc_test_param.h);
        return -1;
 }
@@ -941,7 +936,7 @@ test_hash_add_ks_lookup_hit_sp(struct rwc_perf *rwc_perf_results, int rwc_lf,
                }
                for (n = 0; n < NUM_TEST; n++) {
                        unsigned int tot_lcore = rte_lcore_count();
-                       if (tot_lcore < rwc_core_cnt[n])
+                       if (tot_lcore < rwc_core_cnt[n] + 1)
                                goto finish;
 
                        printf("\nNumber of readers: %u\n", rwc_core_cnt[n]);
@@ -960,12 +955,11 @@ test_hash_add_ks_lookup_hit_sp(struct rwc_perf *rwc_perf_results, int rwc_lf,
                        write_type = WRITE_KEY_SHIFT;
                        ret = write_keys(write_type);
                        writer_done = 1;
-                       rte_eal_mp_wait_lcore();
 
                        if (ret < 0)
                                goto err;
                        for (i = 1; i <= rwc_core_cnt[n]; i++)
-                               if (lcore_config[i].ret < 0)
+                               if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
                                        goto err;
 
                        unsigned long long cycles_per_lookup =
@@ -982,6 +976,7 @@ finish:
        return 0;
 
 err:
+       rte_eal_mp_wait_lcore();
        rte_hash_free(tbl_rwc_test_param.h);
        return -1;
 }
@@ -1035,12 +1030,11 @@ test_hash_add_ks_lookup_miss(struct rwc_perf *rwc_perf_results, int rwc_lf, int
                        write_type = WRITE_KEY_SHIFT;
                        ret = write_keys(write_type);
                        writer_done = 1;
-                       rte_eal_mp_wait_lcore();
 
                        if (ret < 0)
                                goto err;
                        for (i = 1; i <= rwc_core_cnt[n]; i++)
-                               if (lcore_config[i].ret < 0)
+                               if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
                                        goto err;
 
                        unsigned long long cycles_per_lookup =
@@ -1056,6 +1050,7 @@ finish:
        return 0;
 
 err:
+       rte_eal_mp_wait_lcore();
        rte_hash_free(tbl_rwc_test_param.h);
        return -1;
 }
@@ -1108,8 +1103,6 @@ test_hash_multi_add_lookup(struct rwc_perf *rwc_perf_results, int rwc_lf,
 
                                rte_hash_reset(tbl_rwc_test_param.h);
                                writer_done = 0;
-                               for (i = 0; i < 4; i++)
-                                       multi_writer_done[i] = 0;
                                write_type = WRITE_NO_KEY_SHIFT;
                                if (write_keys(write_type) < 0)
                                        goto err;
@@ -1133,15 +1126,15 @@ test_hash_multi_add_lookup(struct rwc_perf *rwc_perf_results, int rwc_lf,
                                }
 
                                /* Wait for writers to complete */
-                               for (i = 0; i < rwc_core_cnt[m]; i++)
-                                       while
-                                               (multi_writer_done[i] == 0);
-                               writer_done = 1;
+                               for (i = rwc_core_cnt[n] + 1;
+                                    i <= rwc_core_cnt[m] + rwc_core_cnt[n];
+                                    i++)
+                                       rte_eal_wait_lcore(enabled_core_ids[i]);
 
-                               rte_eal_mp_wait_lcore();
+                               writer_done = 1;
 
                                for (i = 1; i <= rwc_core_cnt[n]; i++)
-                                       if (lcore_config[i].ret < 0)
+                                       if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
                                                goto err;
 
                                unsigned long long cycles_per_lookup =
@@ -1160,6 +1153,7 @@ finish:
        return 0;
 
 err:
+       rte_eal_mp_wait_lcore();
        rte_hash_free(tbl_rwc_test_param.h);
        return -1;
 }
@@ -1222,10 +1216,9 @@ test_hash_add_ks_lookup_hit_extbkt(struct rwc_perf *rwc_perf_results,
                                }
                        }
                        writer_done = 1;
-                       rte_eal_mp_wait_lcore();
 
                        for (i = 1; i <= rwc_core_cnt[n]; i++)
-                               if (lcore_config[i].ret < 0)
+                               if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
                                        goto err;
 
                        unsigned long long cycles_per_lookup =
@@ -1242,6 +1235,7 @@ finish:
        return 0;
 
 err:
+       rte_eal_mp_wait_lcore();
        rte_hash_free(tbl_rwc_test_param.h);
        return -1;
 }
@@ -1257,23 +1251,23 @@ test_hash_readwrite_lf_main(void)
         */
        int rwc_lf = 0;
        int htm;
-       int use_jhash = 0;
        int ext_bkt = 0;
-       if (rte_lcore_count() == 1) {
-               printf("More than one lcore is required "
-                       "to do read write lock-free concurrency test\n");
-               return -1;
+
+       if (rte_lcore_count() < 2) {
+               printf("Not enough cores for hash_readwrite_lf_autotest, expecting at least 2\n");
+               return TEST_SKIPPED;
        }
 
        setlocale(LC_NUMERIC, "");
 
+       /* Reset tbl_rwc_test_param to discard values from previous run */
+       memset(&tbl_rwc_test_param, 0, sizeof(tbl_rwc_test_param));
+
        if (rte_tm_supported())
                htm = 1;
        else
                htm = 0;
 
-       if (init_params(rwc_lf, use_jhash, htm, ext_bkt) != 0)
-               return -1;
        if (generate_keys() != 0)
                return -1;
        if (get_enabled_cores_list() != 0)
@@ -1431,7 +1425,9 @@ results:
        rte_free(tbl_rwc_test_param.keys_ks);
        rte_free(tbl_rwc_test_param.keys_absent);
        rte_free(tbl_rwc_test_param.keys_shift_path);
-       rte_free(scanned_bkts);
+       rte_free(tbl_rwc_test_param.keys_non_shift_path);
+       rte_free(tbl_rwc_test_param.keys_ext_bkt);
+       rte_free(tbl_rwc_test_param.keys_ks_extbkt);
        return 0;
 }