replace unused attributes
[dpdk.git] / app / test / test_hash_readwrite.c
index 480ae97..73333df 100644 (file)
@@ -55,7 +55,7 @@ static rte_atomic64_t greads;
 static rte_atomic64_t gwrites;
 
 static int
-test_hash_readwrite_worker(__attribute__((unused)) void *arg)
+test_hash_readwrite_worker(__rte_unused void *arg)
 {
        uint64_t i, offset;
        uint32_t lcore_id = rte_lcore_id();
@@ -121,7 +121,7 @@ test_hash_readwrite_worker(__attribute__((unused)) void *arg)
 }
 
 static int
-init_params(int use_ext, int use_htm, int use_jhash)
+init_params(int use_ext, int use_htm, int rw_lf, int use_jhash)
 {
        unsigned int i;
 
@@ -140,15 +140,16 @@ init_params(int use_ext, int use_htm, int use_jhash)
        else
                hash_params.hash_func = rte_hash_crc;
 
+       hash_params.extra_flag = RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
        if (use_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;
+               hash_params.extra_flag |=
+                       RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT;
+       if (rw_lf)
+               hash_params.extra_flag |=
+                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF;
        else
-               hash_params.extra_flag =
-                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY |
-                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
+               hash_params.extra_flag |=
+                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY;
 
        if (use_ext)
                hash_params.extra_flag |=
@@ -195,7 +196,7 @@ err:
 }
 
 static int
-test_hash_readwrite_functional(int use_ext, int use_htm)
+test_hash_readwrite_functional(int use_htm, int use_rw_lf, int use_ext)
 {
        unsigned int i;
        const void *next_key;
@@ -214,7 +215,7 @@ test_hash_readwrite_functional(int use_ext, int use_htm)
        rte_atomic64_init(&ginsertions);
        rte_atomic64_clear(&ginsertions);
 
-       if (init_params(use_ext, use_htm, use_jhash) != 0)
+       if (init_params(use_ext, use_htm, use_rw_lf, use_jhash) != 0)
                goto err;
 
        if (use_ext)
@@ -229,6 +230,8 @@ test_hash_readwrite_functional(int use_ext, int use_htm)
                tbl_rw_test_param.num_insert
                * slave_cnt;
 
+       printf("\nHTM = %d, RW-LF = %d, EXT-Table = %d\n",
+               use_htm, use_rw_lf, use_ext);
        printf("++++++++Start function tests:+++++++++\n");
 
        /* Fire all threads. */
@@ -298,7 +301,7 @@ test_rw_reader(void *arg)
 
        begin = rte_rdtsc_precise();
        for (i = 0; i < read_cnt; i++) {
-               void *data;
+               void *data = arg;
                rte_hash_lookup_data(tbl_rw_test_param.h,
                                tbl_rw_test_param.keys + i,
                                &data);
@@ -379,7 +382,7 @@ test_hash_readwrite_perf(struct perf *perf_results, int use_htm,
        rte_atomic64_init(&gwrite_cycles);
        rte_atomic64_clear(&gwrite_cycles);
 
-       if (init_params(0, use_htm, use_jhash) != 0)
+       if (init_params(0, use_htm, 0, use_jhash) != 0)
                goto err;
 
        /*
@@ -606,7 +609,7 @@ err:
 }
 
 static int
-test_hash_readwrite_main(void)
+test_hash_rw_perf_main(void)
 {
        /*
         * Variables used to choose different tests.
@@ -615,13 +618,12 @@ test_hash_readwrite_main(void)
         * than writer threads. This is to timing either reader threads or
         * writer threads for performance numbers.
         */
-       int use_htm, use_ext,  reader_faster;
+       int use_htm, reader_faster;
        unsigned int i = 0, core_id = 0;
 
-       if (rte_lcore_count() <= 2) {
-               printf("More than two lcores are required "
-                       "to do read write test\n");
-               return -1;
+       if (rte_lcore_count() < 3) {
+               printf("Not enough cores for hash_readwrite_autotest, expecting at least 3\n");
+               return TEST_SKIPPED;
        }
 
        RTE_LCORE_FOREACH_SLAVE(core_id) {
@@ -638,14 +640,6 @@ test_hash_readwrite_main(void)
                printf("Test read-write with Hardware transactional memory\n");
 
                use_htm = 1;
-               use_ext = 0;
-
-               if (test_hash_readwrite_functional(use_ext, use_htm) < 0)
-                       return -1;
-
-               use_ext = 1;
-               if (test_hash_readwrite_functional(use_ext, use_htm) < 0)
-                       return -1;
 
                reader_faster = 1;
                if (test_hash_readwrite_perf(&htm_results, use_htm,
@@ -663,13 +657,6 @@ test_hash_readwrite_main(void)
 
        printf("Test read-write without Hardware transactional memory\n");
        use_htm = 0;
-       use_ext = 0;
-       if (test_hash_readwrite_functional(use_ext, use_htm) < 0)
-               return -1;
-
-       use_ext = 1;
-       if (test_hash_readwrite_functional(use_ext, use_htm) < 0)
-               return -1;
 
        reader_faster = 1;
        if (test_hash_readwrite_perf(&non_htm_results, use_htm,
@@ -706,4 +693,75 @@ test_hash_readwrite_main(void)
        return 0;
 }
 
-REGISTER_TEST_COMMAND(hash_readwrite_autotest, test_hash_readwrite_main);
+static int
+test_hash_rw_func_main(void)
+{
+       /*
+        * Variables used to choose different tests.
+        * use_htm indicates if hardware transactional memory should be used.
+        * reader_faster indicates if the reader threads should finish earlier
+        * than writer threads. This is to timing either reader threads or
+        * writer threads for performance numbers.
+        */
+       unsigned int i = 0, core_id = 0;
+
+       if (rte_lcore_count() < 3) {
+               printf("Not enough cores for hash_readwrite_autotest, expecting at least 3\n");
+               return TEST_SKIPPED;
+       }
+
+       RTE_LCORE_FOREACH_SLAVE(core_id) {
+               slave_core_ids[i] = core_id;
+               i++;
+       }
+
+       setlocale(LC_NUMERIC, "");
+
+       if (rte_tm_supported()) {
+               printf("Hardware transactional memory (lock elision) "
+                       "is supported\n");
+
+               printf("Test read-write with Hardware transactional memory\n");
+
+               /* htm = 1, rw_lf = 0, ext = 0 */
+               if (test_hash_readwrite_functional(1, 0, 0) < 0)
+                       return -1;
+
+               /* htm = 1, rw_lf = 1, ext = 0 */
+               if (test_hash_readwrite_functional(1, 1, 0) < 0)
+                       return -1;
+
+               /* htm = 1, rw_lf = 0, ext = 1 */
+               if (test_hash_readwrite_functional(1, 0, 1) < 0)
+                       return -1;
+
+               /* htm = 1, rw_lf = 1, ext = 1 */
+               if (test_hash_readwrite_functional(1, 1, 1) < 0)
+                       return -1;
+       } else {
+               printf("Hardware transactional memory (lock elision) "
+                       "is NOT supported\n");
+       }
+
+       printf("Test read-write without Hardware transactional memory\n");
+       /* htm = 0, rw_lf = 0, ext = 0 */
+       if (test_hash_readwrite_functional(0, 0, 0) < 0)
+               return -1;
+
+       /* htm = 0, rw_lf = 1, ext = 0 */
+       if (test_hash_readwrite_functional(0, 1, 0) < 0)
+               return -1;
+
+       /* htm = 0, rw_lf = 0, ext = 1 */
+       if (test_hash_readwrite_functional(0, 0, 1) < 0)
+               return -1;
+
+       /* htm = 0, rw_lf = 1, ext = 1 */
+       if (test_hash_readwrite_functional(0, 1, 1) < 0)
+               return -1;
+
+       return 0;
+}
+
+REGISTER_TEST_COMMAND(hash_readwrite_func_autotest, test_hash_rw_func_main);
+REGISTER_TEST_COMMAND(hash_readwrite_perf_autotest, test_hash_rw_perf_main);