LCOV - code coverage report
Current view: top level - app/test - test_rcu_qsbr.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 443 574 77.2 %
Date: 2025-03-01 20:23:48 Functions: 25 27 92.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 236 414 57.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (c) 2019-2020 Arm Limited
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <string.h>
       7                 :            : #include <rte_pause.h>
       8                 :            : #include <rte_rcu_qsbr.h>
       9                 :            : #include <rte_hash.h>
      10                 :            : #include <rte_hash_crc.h>
      11                 :            : #include <rte_malloc.h>
      12                 :            : #include <rte_cycles.h>
      13                 :            : #include <rte_random.h>
      14                 :            : #include <unistd.h>
      15                 :            : 
      16                 :            : #include "test.h"
      17                 :            : 
      18                 :            : /* Check condition and return an error if true. */
      19                 :            : #define TEST_RCU_QSBR_RETURN_IF_ERROR(cond, str, ...) \
      20                 :            : do { \
      21                 :            :         if (cond) { \
      22                 :            :                 printf("ERROR file %s, line %d: " str "\n", __FILE__, \
      23                 :            :                         __LINE__, ##__VA_ARGS__); \
      24                 :            :                 return -1; \
      25                 :            :         } \
      26                 :            : } while (0)
      27                 :            : 
      28                 :            : /* Check condition and go to label if true. */
      29                 :            : #define TEST_RCU_QSBR_GOTO_IF_ERROR(label, cond, str, ...) \
      30                 :            : do { \
      31                 :            :         if (cond) { \
      32                 :            :                 printf("ERROR file %s, line %d: " str "\n", __FILE__, \
      33                 :            :                         __LINE__, ##__VA_ARGS__); \
      34                 :            :                 goto label; \
      35                 :            :         } \
      36                 :            : } while (0)
      37                 :            : 
      38                 :            : /* Make sure that this has the same value as __RTE_QSBR_CNT_INIT */
      39                 :            : #define TEST_RCU_QSBR_CNT_INIT 1
      40                 :            : 
      41                 :            : static uint16_t enabled_core_ids[RTE_MAX_LCORE];
      42                 :            : static unsigned int num_cores;
      43                 :            : 
      44                 :            : static uint32_t *keys;
      45                 :            : #define TOTAL_ENTRY (1024 * 8)
      46                 :            : #define COUNTER_VALUE 4096
      47                 :            : static uint32_t *hash_data[RTE_MAX_LCORE][TOTAL_ENTRY];
      48                 :            : static uint8_t writer_done;
      49                 :            : static uint8_t cb_failed;
      50                 :            : 
      51                 :            : static struct rte_rcu_qsbr *t[RTE_MAX_LCORE];
      52                 :            : static struct rte_hash *h[RTE_MAX_LCORE];
      53                 :            : static char hash_name[RTE_MAX_LCORE][8];
      54                 :            : 
      55                 :            : struct test_rcu_thread_info {
      56                 :            :         /* Index in RCU array */
      57                 :            :         int ir;
      58                 :            :         /* Index in hash array */
      59                 :            :         int ih;
      60                 :            :         /* lcore IDs registered on the RCU variable */
      61                 :            :         uint16_t r_core_ids[2];
      62                 :            : };
      63                 :            : static struct test_rcu_thread_info thread_info[RTE_MAX_LCORE/4];
      64                 :            : 
      65                 :            : static int
      66                 :          1 : alloc_rcu(void)
      67                 :            : {
      68                 :            :         int i;
      69                 :            :         size_t sz;
      70                 :            : 
      71                 :          1 :         sz = rte_rcu_qsbr_get_memsize(RTE_MAX_LCORE);
      72                 :            : 
      73         [ +  + ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++)
      74                 :        128 :                 t[i] = (struct rte_rcu_qsbr *)rte_zmalloc(NULL, sz,
      75                 :            :                                                 RTE_CACHE_LINE_SIZE);
      76                 :            : 
      77                 :          1 :         return 0;
      78                 :            : }
      79                 :            : 
      80                 :            : static int
      81                 :            : free_rcu(void)
      82                 :            : {
      83                 :            :         int i;
      84                 :            : 
      85   [ +  +  -  - ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++)
      86                 :        128 :                 rte_free(t[i]);
      87                 :            : 
      88                 :            :         return 0;
      89                 :            : }
      90                 :            : 
      91                 :            : /*
      92                 :            :  * rte_rcu_qsbr_thread_register: Add a reader thread, to the list of threads
      93                 :            :  * reporting their quiescent state on a QS variable.
      94                 :            :  */
      95                 :            : static int
      96                 :          1 : test_rcu_qsbr_get_memsize(void)
      97                 :            : {
      98                 :            :         size_t sz;
      99                 :            : 
     100                 :            :         printf("\nTest rte_rcu_qsbr_thread_register()\n");
     101                 :            : 
     102                 :          1 :         sz = rte_rcu_qsbr_get_memsize(0);
     103         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((sz != 1), "Get Memsize for 0 threads");
     104                 :            : 
     105                 :          1 :         sz = rte_rcu_qsbr_get_memsize(128);
     106                 :            :         /* For 128 threads,
     107                 :            :          * for machines with cache line size of 64B - 8384
     108                 :            :          * for machines with cache line size of 128 - 16768
     109                 :            :          */
     110                 :            :         if (RTE_CACHE_LINE_SIZE == 64)
     111         [ -  + ]:          1 :                 TEST_RCU_QSBR_RETURN_IF_ERROR((sz != 8384),
     112                 :            :                         "Get Memsize for 128 threads");
     113                 :            :         else if (RTE_CACHE_LINE_SIZE == 128)
     114                 :            :                 TEST_RCU_QSBR_RETURN_IF_ERROR((sz != 16768),
     115                 :            :                         "Get Memsize for 128 threads");
     116                 :            : 
     117                 :            :         return 0;
     118                 :            : }
     119                 :            : 
     120                 :            : /*
     121                 :            :  * rte_rcu_qsbr_init: Initialize a QSBR variable.
     122                 :            :  */
     123                 :            : static int
     124                 :          1 : test_rcu_qsbr_init(void)
     125                 :            : {
     126                 :            :         int r;
     127                 :            : 
     128                 :            :         printf("\nTest rte_rcu_qsbr_init()\n");
     129                 :            : 
     130                 :          1 :         r = rte_rcu_qsbr_init(NULL, RTE_MAX_LCORE);
     131         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((r != 1), "NULL variable");
     132                 :            : 
     133                 :            :         return 0;
     134                 :            : }
     135                 :            : 
     136                 :            : /*
     137                 :            :  * rte_rcu_qsbr_thread_register: Add a reader thread, to the list of threads
     138                 :            :  * reporting their quiescent state on a QS variable.
     139                 :            :  */
     140                 :            : static int
     141                 :          1 : test_rcu_qsbr_thread_register(void)
     142                 :            : {
     143                 :            :         int ret;
     144                 :            : 
     145                 :            :         printf("\nTest rte_rcu_qsbr_thread_register()\n");
     146                 :            : 
     147                 :          1 :         ret = rte_rcu_qsbr_thread_register(NULL, enabled_core_ids[0]);
     148         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "NULL variable check");
     149                 :            : 
     150                 :          1 :         ret = rte_rcu_qsbr_thread_register(NULL, 100000);
     151         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0),
     152                 :            :                 "NULL variable, invalid thread id");
     153                 :            : 
     154                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     155                 :            : 
     156                 :            :         /* Register valid thread id */
     157                 :          1 :         ret = rte_rcu_qsbr_thread_register(t[0], enabled_core_ids[0]);
     158         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 1), "Valid thread id");
     159                 :            : 
     160                 :            :         /* Re-registering should not return error */
     161                 :          1 :         ret = rte_rcu_qsbr_thread_register(t[0], enabled_core_ids[0]);
     162         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 1),
     163                 :            :                 "Already registered thread id");
     164                 :            : 
     165                 :            :         /* Register valid thread id - max allowed thread id */
     166                 :          1 :         ret = rte_rcu_qsbr_thread_register(t[0], RTE_MAX_LCORE - 1);
     167         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 1), "Max thread id");
     168                 :            : 
     169                 :          1 :         ret = rte_rcu_qsbr_thread_register(t[0], 100000);
     170         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0),
     171                 :            :                 "NULL variable, invalid thread id");
     172                 :            : 
     173                 :            :         return 0;
     174                 :            : }
     175                 :            : 
     176                 :            : /*
     177                 :            :  * rte_rcu_qsbr_thread_unregister: Remove a reader thread, from the list of
     178                 :            :  * threads reporting their quiescent state on a QS variable.
     179                 :            :  */
     180                 :            : static int
     181                 :          1 : test_rcu_qsbr_thread_unregister(void)
     182                 :            : {
     183                 :          1 :         unsigned int num_threads[3] = {1, RTE_MAX_LCORE, 1};
     184                 :            :         unsigned int i, j;
     185                 :            :         unsigned int skip_thread_id;
     186                 :            :         uint64_t token;
     187                 :            :         int ret;
     188                 :            : 
     189                 :            :         printf("\nTest rte_rcu_qsbr_thread_unregister()\n");
     190                 :            : 
     191                 :          1 :         ret = rte_rcu_qsbr_thread_unregister(NULL, enabled_core_ids[0]);
     192         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "NULL variable check");
     193                 :            : 
     194                 :          1 :         ret = rte_rcu_qsbr_thread_unregister(NULL, 100000);
     195         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0),
     196                 :            :                 "NULL variable, invalid thread id");
     197                 :            : 
     198                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     199                 :            : 
     200                 :          1 :         rte_rcu_qsbr_thread_register(t[0], enabled_core_ids[0]);
     201                 :            : 
     202                 :          1 :         ret = rte_rcu_qsbr_thread_unregister(t[0], 100000);
     203         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0),
     204                 :            :                 "NULL variable, invalid thread id");
     205                 :            : 
     206                 :            :         /* Find first disabled core */
     207         [ +  - ]:          2 :         for (i = 0; i < RTE_MAX_LCORE; i++) {
     208         [ +  + ]:          2 :                 if (enabled_core_ids[i] == 0)
     209                 :            :                         break;
     210                 :            :         }
     211                 :            :         /* Test with disabled lcore */
     212                 :          1 :         ret = rte_rcu_qsbr_thread_unregister(t[0], i);
     213         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 1),
     214                 :            :                 "disabled thread id");
     215                 :            :         /* Unregister already unregistered core */
     216                 :          1 :         ret = rte_rcu_qsbr_thread_unregister(t[0], i);
     217         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 1),
     218                 :            :                 "Already unregistered core");
     219                 :            : 
     220                 :            :         /* Test with enabled lcore */
     221                 :          1 :         ret = rte_rcu_qsbr_thread_unregister(t[0], enabled_core_ids[0]);
     222         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 1),
     223                 :            :                 "enabled thread id");
     224                 :            :         /* Unregister already unregistered core */
     225                 :          1 :         ret = rte_rcu_qsbr_thread_unregister(t[0], enabled_core_ids[0]);
     226         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 1),
     227                 :            :                 "Already unregistered core");
     228                 :            : 
     229                 :            :         /*
     230                 :            :          * Test with different thread_ids:
     231                 :            :          * 1 - thread_id = 0
     232                 :            :          * 2 - All possible thread_ids, from 0 to RTE_MAX_LCORE
     233                 :            :          * 3 - thread_id = RTE_MAX_LCORE - 1
     234                 :            :          */
     235         [ +  + ]:          4 :         for (j = 0; j < 3; j++) {
     236                 :          3 :                 rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     237                 :            : 
     238         [ +  + ]:        133 :                 for (i = 0; i < num_threads[j]; i++)
     239         [ +  + ]:        259 :                         rte_rcu_qsbr_thread_register(t[0],
     240                 :            :                                 (j == 2) ? (RTE_MAX_LCORE - 1) : i);
     241                 :            : 
     242         [ -  + ]:          3 :                 token = rte_rcu_qsbr_start(t[0]);
     243         [ -  + ]:          3 :                 TEST_RCU_QSBR_RETURN_IF_ERROR(
     244                 :            :                         (token != (TEST_RCU_QSBR_CNT_INIT + 1)), "QSBR Start");
     245                 :          3 :                 skip_thread_id = rte_rand() % RTE_MAX_LCORE;
     246                 :            :                 /* Update quiescent state counter */
     247         [ +  + ]:        133 :                 for (i = 0; i < num_threads[j]; i++) {
     248                 :            :                         /* Skip one update */
     249         [ +  + ]:        130 :                         if ((j == 1) && (i == skip_thread_id))
     250                 :          1 :                                 continue;
     251   [ +  +  +  - ]:        257 :                         rte_rcu_qsbr_quiescent(t[0],
     252                 :            :                                 (j == 2) ? (RTE_MAX_LCORE - 1) : i);
     253                 :            :                 }
     254                 :            : 
     255         [ +  + ]:          3 :                 if (j == 1) {
     256                 :            :                         /* Validate the updates */
     257         [ +  - ]:          1 :                         ret = rte_rcu_qsbr_check(t[0], token, false);
     258                 :          0 :                         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0),
     259                 :            :                                                 "Non-blocking QSBR check");
     260                 :            :                         /* Update the previously skipped thread */
     261         [ +  - ]:          1 :                         rte_rcu_qsbr_quiescent(t[0], skip_thread_id);
     262                 :            :                 }
     263                 :            : 
     264                 :            :                 /* Validate the updates */
     265         [ +  + ]:          3 :                 ret = rte_rcu_qsbr_check(t[0], token, false);
     266                 :          0 :                 TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0),
     267                 :            :                                                 "Non-blocking QSBR check");
     268                 :            : 
     269         [ +  + ]:        133 :                 for (i = 0; i < num_threads[j]; i++)
     270         [ +  + ]:        259 :                         rte_rcu_qsbr_thread_unregister(t[0],
     271                 :            :                                 (j == 2) ? (RTE_MAX_LCORE - 1) : i);
     272                 :            : 
     273                 :            :                 /* Check with no thread registered */
     274         [ -  + ]:          3 :                 ret = rte_rcu_qsbr_check(t[0], token, true);
     275                 :            :                 TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0),
     276                 :            :                                                 "Blocking QSBR check");
     277                 :            :         }
     278                 :            :         return 0;
     279                 :            : }
     280                 :            : 
     281                 :            : /*
     282                 :            :  * rte_rcu_qsbr_start: Ask the worker threads to report the quiescent state
     283                 :            :  * status.
     284                 :            :  */
     285                 :            : static int
     286                 :          1 : test_rcu_qsbr_start(void)
     287                 :            : {
     288                 :            :         uint64_t token;
     289                 :            :         unsigned int i;
     290                 :            : 
     291                 :            :         printf("\nTest rte_rcu_qsbr_start()\n");
     292                 :            : 
     293                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     294                 :            : 
     295         [ +  + ]:          2 :         for (i = 0; i < num_cores; i++)
     296                 :          1 :                 rte_rcu_qsbr_thread_register(t[0], enabled_core_ids[i]);
     297                 :            : 
     298         [ -  + ]:          1 :         token = rte_rcu_qsbr_start(t[0]);
     299         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR(
     300                 :            :                 (token != (TEST_RCU_QSBR_CNT_INIT + 1)), "QSBR Start");
     301                 :            :         return 0;
     302                 :            : }
     303                 :            : 
     304                 :            : static int
     305                 :          1 : test_rcu_qsbr_check_reader(void *arg)
     306                 :            : {
     307                 :            :         struct rte_rcu_qsbr *temp;
     308                 :          1 :         uint8_t read_type = (uint8_t)((uintptr_t)arg);
     309                 :            :         unsigned int i;
     310                 :            : 
     311                 :          1 :         temp = t[read_type];
     312                 :            : 
     313                 :            :         /* Update quiescent state counter */
     314         [ +  + ]:          2 :         for (i = 0; i < num_cores; i++) {
     315         [ +  - ]:          1 :                 if (i % 2 == 0)
     316         [ +  - ]:          1 :                         rte_rcu_qsbr_quiescent(temp, enabled_core_ids[i]);
     317                 :            :                 else
     318                 :          0 :                         rte_rcu_qsbr_thread_unregister(temp,
     319                 :          0 :                                                         enabled_core_ids[i]);
     320                 :            :         }
     321                 :          1 :         return 0;
     322                 :            : }
     323                 :            : 
     324                 :            : /*
     325                 :            :  * rte_rcu_qsbr_check: Checks if all the worker threads have entered the queis-
     326                 :            :  * cent state 'n' number of times. 'n' is provided in rte_rcu_qsbr_start API.
     327                 :            :  */
     328                 :            : static int
     329                 :          1 : test_rcu_qsbr_check(void)
     330                 :            : {
     331                 :            :         int ret;
     332                 :            :         unsigned int i;
     333                 :            :         uint64_t token;
     334                 :            : 
     335                 :            :         printf("\nTest rte_rcu_qsbr_check()\n");
     336                 :            : 
     337                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     338                 :            : 
     339         [ -  + ]:          1 :         token = rte_rcu_qsbr_start(t[0]);
     340         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR(
     341                 :            :                 (token != (TEST_RCU_QSBR_CNT_INIT + 1)), "QSBR Start");
     342                 :            : 
     343                 :            : 
     344         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], 0, false);
     345                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "Token = 0");
     346                 :            : 
     347         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     348                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "Blocking QSBR check");
     349                 :            : 
     350         [ +  + ]:          2 :         for (i = 0; i < num_cores; i++)
     351                 :          1 :                 rte_rcu_qsbr_thread_register(t[0], enabled_core_ids[i]);
     352                 :            : 
     353         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, false);
     354                 :            :         /* Threads are offline, hence this should pass */
     355                 :          0 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "Non-blocking QSBR check");
     356                 :            : 
     357         [ -  + ]:          1 :         token = rte_rcu_qsbr_start(t[0]);
     358         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR(
     359                 :            :                 (token != (TEST_RCU_QSBR_CNT_INIT + 2)), "QSBR Start");
     360                 :            : 
     361         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, false);
     362                 :            :         /* Threads are offline, hence this should pass */
     363                 :          0 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "Non-blocking QSBR check");
     364                 :            : 
     365         [ +  + ]:          2 :         for (i = 0; i < num_cores; i++)
     366                 :          1 :                 rte_rcu_qsbr_thread_unregister(t[0], enabled_core_ids[i]);
     367                 :            : 
     368         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     369                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "Blocking QSBR check");
     370                 :            : 
     371                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     372                 :            : 
     373         [ +  + ]:          2 :         for (i = 0; i < num_cores; i++)
     374                 :          1 :                 rte_rcu_qsbr_thread_register(t[0], enabled_core_ids[i]);
     375                 :            : 
     376         [ -  + ]:          1 :         token = rte_rcu_qsbr_start(t[0]);
     377         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR(
     378                 :            :                 (token != (TEST_RCU_QSBR_CNT_INIT + 1)), "QSBR Start");
     379                 :            : 
     380                 :          1 :         rte_eal_remote_launch(test_rcu_qsbr_check_reader, NULL,
     381                 :          1 :                                                         enabled_core_ids[0]);
     382                 :            : 
     383                 :          1 :         rte_eal_mp_wait_lcore();
     384         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     385                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret != 1), "Blocking QSBR check");
     386                 :            : 
     387                 :            :         return 0;
     388                 :            : }
     389                 :            : 
     390                 :            : static int
     391                 :          1 : test_rcu_qsbr_synchronize_reader(void *arg)
     392                 :            : {
     393                 :            :         uint32_t lcore_id = rte_lcore_id();
     394                 :            :         (void)arg;
     395                 :            : 
     396                 :            :         /* Register and become online */
     397                 :          1 :         rte_rcu_qsbr_thread_register(t[0], lcore_id);
     398                 :          1 :         rte_rcu_qsbr_thread_online(t[0], lcore_id);
     399                 :            : 
     400         [ +  + ]:      15010 :         while (!writer_done)
     401         [ +  + ]:      15009 :                 rte_rcu_qsbr_quiescent(t[0], lcore_id);
     402                 :            : 
     403                 :          1 :         rte_rcu_qsbr_thread_offline(t[0], lcore_id);
     404                 :          1 :         rte_rcu_qsbr_thread_unregister(t[0], lcore_id);
     405                 :            : 
     406                 :          1 :         return 0;
     407                 :            : }
     408                 :            : 
     409                 :            : /*
     410                 :            :  * rte_rcu_qsbr_synchronize: Wait till all the reader threads have entered
     411                 :            :  * the quiescent state.
     412                 :            :  */
     413                 :            : static int
     414                 :          1 : test_rcu_qsbr_synchronize(void)
     415                 :            : {
     416                 :            :         unsigned int i;
     417                 :            : 
     418                 :            :         printf("\nTest rte_rcu_qsbr_synchronize()\n");
     419                 :            : 
     420                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     421                 :            : 
     422                 :            :         /* Test if the API returns when there are no threads reporting
     423                 :            :          * QS on the variable.
     424                 :            :          */
     425                 :          1 :         rte_rcu_qsbr_synchronize(t[0], RTE_QSBR_THRID_INVALID);
     426                 :            : 
     427                 :            :         /* Test if the API returns when there are threads registered
     428                 :            :          * but not online.
     429                 :            :          */
     430         [ +  + ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++)
     431                 :        128 :                 rte_rcu_qsbr_thread_register(t[0], i);
     432                 :          1 :         rte_rcu_qsbr_synchronize(t[0], RTE_QSBR_THRID_INVALID);
     433                 :            : 
     434                 :            :         /* Test if the API returns when the caller is also
     435                 :            :          * reporting the QS status.
     436                 :            :          */
     437                 :          1 :         rte_rcu_qsbr_thread_online(t[0], 0);
     438                 :          1 :         rte_rcu_qsbr_synchronize(t[0], 0);
     439                 :          1 :         rte_rcu_qsbr_thread_offline(t[0], 0);
     440                 :            : 
     441                 :            :         /* Check the other boundary */
     442                 :          1 :         rte_rcu_qsbr_thread_online(t[0], RTE_MAX_LCORE - 1);
     443                 :          1 :         rte_rcu_qsbr_synchronize(t[0], RTE_MAX_LCORE - 1);
     444                 :          1 :         rte_rcu_qsbr_thread_offline(t[0], RTE_MAX_LCORE - 1);
     445                 :            : 
     446                 :            :         /* Test if the API returns after unregistering all the threads */
     447         [ +  + ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++)
     448                 :        128 :                 rte_rcu_qsbr_thread_unregister(t[0], i);
     449                 :          1 :         rte_rcu_qsbr_synchronize(t[0], RTE_QSBR_THRID_INVALID);
     450                 :            : 
     451                 :            :         /* Test if the API returns with the live threads */
     452                 :          1 :         writer_done = 0;
     453         [ +  + ]:          2 :         for (i = 0; i < num_cores; i++)
     454                 :          1 :                 rte_eal_remote_launch(test_rcu_qsbr_synchronize_reader,
     455                 :          1 :                         NULL, enabled_core_ids[i]);
     456                 :          1 :         rte_rcu_qsbr_synchronize(t[0], RTE_QSBR_THRID_INVALID);
     457                 :          1 :         rte_rcu_qsbr_synchronize(t[0], RTE_QSBR_THRID_INVALID);
     458                 :          1 :         rte_rcu_qsbr_synchronize(t[0], RTE_QSBR_THRID_INVALID);
     459                 :          1 :         rte_rcu_qsbr_synchronize(t[0], RTE_QSBR_THRID_INVALID);
     460                 :          1 :         rte_rcu_qsbr_synchronize(t[0], RTE_QSBR_THRID_INVALID);
     461                 :            : 
     462                 :          1 :         writer_done = 1;
     463                 :          1 :         rte_eal_mp_wait_lcore();
     464                 :            : 
     465                 :          1 :         return 0;
     466                 :            : }
     467                 :            : 
     468                 :            : /*
     469                 :            :  * rte_rcu_qsbr_thread_online: Add a registered reader thread, to
     470                 :            :  * the list of threads reporting their quiescent state on a QS variable.
     471                 :            :  */
     472                 :            : static int
     473                 :          1 : test_rcu_qsbr_thread_online(void)
     474                 :            : {
     475                 :            :         int i, ret;
     476                 :            :         uint64_t token;
     477                 :            : 
     478                 :            :         printf("Test rte_rcu_qsbr_thread_online()\n");
     479                 :            : 
     480                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     481                 :            : 
     482                 :            :         /* Register 2 threads to validate that only the
     483                 :            :          * online thread is waited upon.
     484                 :            :          */
     485                 :          1 :         rte_rcu_qsbr_thread_register(t[0], enabled_core_ids[0]);
     486                 :          1 :         rte_rcu_qsbr_thread_register(t[0], enabled_core_ids[1]);
     487                 :            : 
     488                 :            :         /* Use qsbr_start to verify that the thread_online API
     489                 :            :          * succeeded.
     490                 :            :          */
     491                 :          1 :         token = rte_rcu_qsbr_start(t[0]);
     492                 :            : 
     493                 :            :         /* Make the thread online */
     494                 :          1 :         rte_rcu_qsbr_thread_online(t[0], enabled_core_ids[0]);
     495                 :            : 
     496                 :            :         /* Check if the thread is online */
     497         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     498                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "thread online");
     499                 :            : 
     500                 :            :         /* Check if the online thread, can report QS */
     501         [ +  - ]:          1 :         token = rte_rcu_qsbr_start(t[0]);
     502         [ +  - ]:          1 :         rte_rcu_qsbr_quiescent(t[0], enabled_core_ids[0]);
     503         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     504                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "thread update");
     505                 :            : 
     506                 :            :         /* Make all the threads online */
     507                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     508                 :          1 :         token = rte_rcu_qsbr_start(t[0]);
     509         [ +  + ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++) {
     510                 :        128 :                 rte_rcu_qsbr_thread_register(t[0], i);
     511                 :        128 :                 rte_rcu_qsbr_thread_online(t[0], i);
     512                 :            :         }
     513                 :            :         /* Check if all the threads are online */
     514         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     515                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "thread online");
     516                 :            :         /* Check if all the online threads can report QS */
     517                 :          1 :         token = rte_rcu_qsbr_start(t[0]);
     518         [ +  + ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++)
     519         [ +  - ]:        128 :                 rte_rcu_qsbr_quiescent(t[0], i);
     520         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     521                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "thread update");
     522                 :            : 
     523                 :            :         return 0;
     524                 :            : }
     525                 :            : 
     526                 :            : /*
     527                 :            :  * rte_rcu_qsbr_thread_offline: Remove a registered reader thread, from
     528                 :            :  * the list of threads reporting their quiescent state on a QS variable.
     529                 :            :  */
     530                 :            : static int
     531                 :          1 : test_rcu_qsbr_thread_offline(void)
     532                 :            : {
     533                 :            :         int i, ret;
     534                 :            :         uint64_t token;
     535                 :            : 
     536                 :            :         printf("\nTest rte_rcu_qsbr_thread_offline()\n");
     537                 :            : 
     538                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     539                 :            : 
     540                 :          1 :         rte_rcu_qsbr_thread_register(t[0], enabled_core_ids[0]);
     541                 :            : 
     542                 :            :         /* Make the thread offline */
     543         [ +  - ]:          1 :         rte_rcu_qsbr_thread_offline(t[0], enabled_core_ids[0]);
     544                 :            : 
     545                 :            :         /* Use qsbr_start to verify that the thread_offline API
     546                 :            :          * succeeded.
     547                 :            :          */
     548         [ +  - ]:          1 :         token = rte_rcu_qsbr_start(t[0]);
     549                 :            :         /* Check if the thread is offline */
     550         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     551                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "thread offline");
     552                 :            : 
     553                 :            :         /* Bring an offline thread online and check if it can
     554                 :            :          * report QS.
     555                 :            :          */
     556                 :          1 :         rte_rcu_qsbr_thread_online(t[0], enabled_core_ids[0]);
     557                 :            :         /* Check if the online thread, can report QS */
     558         [ +  - ]:          1 :         token = rte_rcu_qsbr_start(t[0]);
     559         [ +  - ]:          1 :         rte_rcu_qsbr_quiescent(t[0], enabled_core_ids[0]);
     560         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     561                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "offline to online");
     562                 :            : 
     563                 :            :         /*
     564                 :            :          * Check a sequence of online/status/offline/status/online/status
     565                 :            :          */
     566                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     567                 :          1 :         token = rte_rcu_qsbr_start(t[0]);
     568                 :            :         /* Make the threads online */
     569         [ +  + ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++) {
     570                 :        128 :                 rte_rcu_qsbr_thread_register(t[0], i);
     571                 :        128 :                 rte_rcu_qsbr_thread_online(t[0], i);
     572                 :            :         }
     573                 :            : 
     574                 :            :         /* Check if all the threads are online */
     575         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     576                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "thread online");
     577                 :            : 
     578                 :            :         /* Check if all the online threads can report QS */
     579                 :          1 :         token = rte_rcu_qsbr_start(t[0]);
     580         [ +  + ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++)
     581         [ +  - ]:        128 :                 rte_rcu_qsbr_quiescent(t[0], i);
     582         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     583                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "report QS");
     584                 :            : 
     585                 :            :         /* Make all the threads offline */
     586         [ +  + ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++)
     587                 :        128 :                 rte_rcu_qsbr_thread_offline(t[0], i);
     588                 :            :         /* Make sure these threads are not being waited on */
     589         [ +  - ]:          1 :         token = rte_rcu_qsbr_start(t[0]);
     590         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     591                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "offline QS");
     592                 :            : 
     593                 :            :         /* Make the threads online */
     594         [ +  + ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++)
     595                 :        128 :                 rte_rcu_qsbr_thread_online(t[0], i);
     596                 :            :         /* Check if all the online threads can report QS */
     597                 :          1 :         token = rte_rcu_qsbr_start(t[0]);
     598         [ +  + ]:        129 :         for (i = 0; i < RTE_MAX_LCORE; i++)
     599         [ +  - ]:        128 :                 rte_rcu_qsbr_quiescent(t[0], i);
     600         [ +  - ]:          1 :         ret = rte_rcu_qsbr_check(t[0], token, true);
     601                 :            :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "online again");
     602                 :            : 
     603                 :            :         return 0;
     604                 :            : }
     605                 :            : 
     606                 :            : static void
     607                 :          0 : test_rcu_qsbr_free_resource1(void *p, void *e, unsigned int n)
     608                 :            : {
     609   [ #  #  #  # ]:          0 :         if (p != NULL || e != NULL || n != 1) {
     610                 :            :                 printf("%s: Test failed\n", __func__);
     611                 :          0 :                 cb_failed = 1;
     612                 :            :         }
     613                 :          0 : }
     614                 :            : 
     615                 :            : static void
     616                 :       1084 : test_rcu_qsbr_free_resource2(void *p, void *e, unsigned int n)
     617                 :            : {
     618   [ +  -  -  + ]:       1084 :         if (p != NULL || e == NULL || n != 1) {
     619                 :            :                 printf("%s: Test failed\n", __func__);
     620                 :          0 :                 cb_failed = 1;
     621                 :            :         }
     622                 :       1084 : }
     623                 :            : 
     624                 :            : /*
     625                 :            :  * rte_rcu_qsbr_dq_create: create a queue used to store the data structure
     626                 :            :  * elements that can be freed later. This queue is referred to as 'defer queue'.
     627                 :            :  */
     628                 :            : static int
     629                 :          1 : test_rcu_qsbr_dq_create(void)
     630                 :            : {
     631                 :            :         char rcu_dq_name[RTE_RCU_QSBR_DQ_NAMESIZE];
     632                 :            :         struct rte_rcu_qsbr_dq_parameters params;
     633                 :            :         struct rte_rcu_qsbr_dq *dq;
     634                 :            : 
     635                 :            :         printf("\nTest rte_rcu_qsbr_dq_create()\n");
     636                 :            : 
     637                 :            :         /* Pass invalid parameters */
     638                 :          1 :         dq = rte_rcu_qsbr_dq_create(NULL);
     639         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq != NULL), "dq create invalid params");
     640                 :            : 
     641                 :            :         memset(&params, 0, sizeof(struct rte_rcu_qsbr_dq_parameters));
     642                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     643         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq != NULL), "dq create invalid params");
     644                 :            : 
     645                 :            :         snprintf(rcu_dq_name, sizeof(rcu_dq_name), "TEST_RCU");
     646                 :          1 :         params.name = rcu_dq_name;
     647                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     648         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq != NULL), "dq create invalid params");
     649                 :            : 
     650                 :          1 :         params.free_fn = test_rcu_qsbr_free_resource1;
     651                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     652         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq != NULL), "dq create invalid params");
     653                 :            : 
     654                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     655                 :          1 :         params.v = t[0];
     656                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     657         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq != NULL), "dq create invalid params");
     658                 :            : 
     659                 :          1 :         params.size = 1;
     660                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     661         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq != NULL), "dq create invalid params");
     662                 :            : 
     663                 :          1 :         params.esize = 3;
     664                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     665         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq != NULL), "dq create invalid params");
     666                 :            : 
     667                 :          1 :         params.trigger_reclaim_limit = 0;
     668                 :          1 :         params.max_reclaim_size = 0;
     669                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     670         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq != NULL), "dq create invalid params");
     671                 :            : 
     672                 :            :         /* Pass all valid parameters */
     673                 :          1 :         params.esize = 16;
     674                 :          1 :         params.trigger_reclaim_limit = 0;
     675                 :          1 :         params.max_reclaim_size = params.size;
     676                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     677         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq == NULL), "dq create valid params");
     678                 :          1 :         rte_rcu_qsbr_dq_delete(dq);
     679                 :            : 
     680                 :          1 :         params.esize = 16;
     681                 :          1 :         params.flags = RTE_RCU_QSBR_DQ_MT_UNSAFE;
     682                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     683         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq == NULL), "dq create valid params");
     684                 :          1 :         rte_rcu_qsbr_dq_delete(dq);
     685                 :            : 
     686                 :          1 :         return 0;
     687                 :            : }
     688                 :            : 
     689                 :            : /*
     690                 :            :  * rte_rcu_qsbr_dq_enqueue: enqueue one resource to the defer queue,
     691                 :            :  * to be freed later after at least one grace period is over.
     692                 :            :  */
     693                 :            : static int
     694                 :          1 : test_rcu_qsbr_dq_enqueue(void)
     695                 :            : {
     696                 :            :         int ret;
     697                 :            :         uint64_t r;
     698                 :            :         char rcu_dq_name[RTE_RCU_QSBR_DQ_NAMESIZE];
     699                 :            :         struct rte_rcu_qsbr_dq_parameters params;
     700                 :            :         struct rte_rcu_qsbr_dq *dq;
     701                 :            : 
     702                 :            :         printf("\nTest rte_rcu_qsbr_dq_enqueue()\n");
     703                 :            : 
     704                 :            :         /* Create a queue with simple parameters */
     705                 :            :         memset(&params, 0, sizeof(struct rte_rcu_qsbr_dq_parameters));
     706                 :            :         snprintf(rcu_dq_name, sizeof(rcu_dq_name), "TEST_RCU");
     707                 :          1 :         params.name = rcu_dq_name;
     708                 :          1 :         params.free_fn = test_rcu_qsbr_free_resource1;
     709                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     710                 :          1 :         params.v = t[0];
     711                 :          1 :         params.size = 1;
     712                 :          1 :         params.esize = 16;
     713                 :          1 :         params.trigger_reclaim_limit = 0;
     714                 :          1 :         params.max_reclaim_size = params.size;
     715                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     716         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq == NULL), "dq create valid params");
     717                 :            : 
     718                 :            :         /* Pass invalid parameters */
     719                 :          1 :         ret = rte_rcu_qsbr_dq_enqueue(NULL, NULL);
     720         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "dq enqueue invalid params");
     721                 :            : 
     722                 :          1 :         ret = rte_rcu_qsbr_dq_enqueue(dq, NULL);
     723         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "dq enqueue invalid params");
     724                 :            : 
     725                 :          1 :         ret = rte_rcu_qsbr_dq_enqueue(NULL, &r);
     726         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "dq enqueue invalid params");
     727                 :            : 
     728                 :          1 :         ret = rte_rcu_qsbr_dq_delete(dq);
     729         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 1), "dq delete valid params");
     730                 :            : 
     731                 :            :         return 0;
     732                 :            : }
     733                 :            : 
     734                 :            : /*
     735                 :            :  * rte_rcu_qsbr_dq_reclaim: Reclaim resources from the defer queue.
     736                 :            :  */
     737                 :            : static int
     738                 :          1 : test_rcu_qsbr_dq_reclaim(void)
     739                 :            : {
     740                 :            :         int ret;
     741                 :            :         char rcu_dq_name[RTE_RCU_QSBR_DQ_NAMESIZE];
     742                 :            :         struct rte_rcu_qsbr_dq_parameters params;
     743                 :            :         struct rte_rcu_qsbr_dq *dq;
     744                 :            : 
     745                 :            :         printf("\nTest rte_rcu_qsbr_dq_reclaim()\n");
     746                 :            : 
     747                 :            :         /* Pass invalid parameters */
     748                 :          1 :         ret = rte_rcu_qsbr_dq_reclaim(NULL, 10, NULL, NULL, NULL);
     749         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret != 1), "dq reclaim invalid params");
     750                 :            : 
     751                 :            :         /* Pass invalid parameters */
     752                 :            :         memset(&params, 0, sizeof(struct rte_rcu_qsbr_dq_parameters));
     753                 :            :         snprintf(rcu_dq_name, sizeof(rcu_dq_name), "TEST_RCU");
     754                 :          1 :         params.name = rcu_dq_name;
     755                 :          1 :         params.free_fn = test_rcu_qsbr_free_resource1;
     756                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     757                 :          1 :         params.v = t[0];
     758                 :          1 :         params.size = 1;
     759                 :          1 :         params.esize = 3;
     760                 :          1 :         params.trigger_reclaim_limit = 0;
     761                 :          1 :         params.max_reclaim_size = params.size;
     762                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     763                 :          1 :         ret = rte_rcu_qsbr_dq_reclaim(dq, 0, NULL, NULL, NULL);
     764         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret != 1), "dq reclaim invalid params");
     765                 :            : 
     766                 :            :         return 0;
     767                 :            : }
     768                 :            : 
     769                 :            : /*
     770                 :            :  * rte_rcu_qsbr_dq_delete: Delete a defer queue.
     771                 :            :  */
     772                 :            : static int
     773                 :          1 : test_rcu_qsbr_dq_delete(void)
     774                 :            : {
     775                 :            :         int ret;
     776                 :            :         char rcu_dq_name[RTE_RCU_QSBR_DQ_NAMESIZE];
     777                 :            :         struct rte_rcu_qsbr_dq_parameters params;
     778                 :            :         struct rte_rcu_qsbr_dq *dq;
     779                 :            : 
     780                 :            :         printf("\nTest rte_rcu_qsbr_dq_delete()\n");
     781                 :            : 
     782                 :            :         /* Pass invalid parameters */
     783                 :          1 :         ret = rte_rcu_qsbr_dq_delete(NULL);
     784         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret != 0), "dq delete invalid params");
     785                 :            : 
     786                 :            :         memset(&params, 0, sizeof(struct rte_rcu_qsbr_dq_parameters));
     787                 :            :         snprintf(rcu_dq_name, sizeof(rcu_dq_name), "TEST_RCU");
     788                 :          1 :         params.name = rcu_dq_name;
     789                 :          1 :         params.free_fn = test_rcu_qsbr_free_resource1;
     790                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     791                 :          1 :         params.v = t[0];
     792                 :          1 :         params.size = 1;
     793                 :          1 :         params.esize = 16;
     794                 :          1 :         params.trigger_reclaim_limit = 0;
     795                 :          1 :         params.max_reclaim_size = params.size;
     796                 :          1 :         dq = rte_rcu_qsbr_dq_create(&params);
     797         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq == NULL), "dq create valid params");
     798                 :          1 :         ret = rte_rcu_qsbr_dq_delete(dq);
     799         [ -  + ]:          1 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret != 0), "dq delete valid params");
     800                 :            : 
     801                 :            :         return 0;
     802                 :            : }
     803                 :            : 
     804                 :            : /*
     805                 :            :  * rte_rcu_qsbr_dq_enqueue: enqueue one resource to the defer queue,
     806                 :            :  * to be freed later after at least one grace period is over.
     807                 :            :  */
     808                 :            : static int
     809                 :          4 : test_rcu_qsbr_dq_functional(int32_t size, int32_t esize, uint32_t flags)
     810                 :            : {
     811                 :            :         int i, j, ret;
     812                 :            :         char rcu_dq_name[RTE_RCU_QSBR_DQ_NAMESIZE];
     813                 :            :         struct rte_rcu_qsbr_dq_parameters params;
     814                 :            :         struct rte_rcu_qsbr_dq *dq;
     815                 :            :         uint64_t *e;
     816                 :            :         uint64_t sc = 200;
     817                 :            :         int max_entries;
     818                 :            : 
     819                 :            :         printf("\nTest rte_rcu_qsbr_dq_xxx functional tests()\n");
     820                 :            :         printf("Size = %d, esize = %d, flags = 0x%x\n", size, esize, flags);
     821                 :            : 
     822                 :          4 :         e = (uint64_t *)rte_zmalloc(NULL, esize, RTE_CACHE_LINE_SIZE);
     823         [ +  - ]:          4 :         if (e == NULL)
     824                 :            :                 return 0;
     825                 :          4 :         cb_failed = 0;
     826                 :            : 
     827                 :            :         /* Initialize the RCU variable. No threads are registered */
     828                 :          4 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     829                 :            : 
     830                 :            :         /* Create a queue with simple parameters */
     831                 :            :         memset(&params, 0, sizeof(struct rte_rcu_qsbr_dq_parameters));
     832                 :            :         snprintf(rcu_dq_name, sizeof(rcu_dq_name), "TEST_RCU");
     833                 :          4 :         params.name = rcu_dq_name;
     834                 :          4 :         params.flags = flags;
     835                 :          4 :         params.free_fn = test_rcu_qsbr_free_resource2;
     836                 :          4 :         params.v = t[0];
     837                 :          4 :         params.size = size;
     838                 :          4 :         params.esize = esize;
     839                 :          4 :         params.trigger_reclaim_limit = size >> 3;
     840         [ +  + ]:          4 :         params.max_reclaim_size = (size >> 4)?(size >> 4):1;
     841                 :          4 :         dq = rte_rcu_qsbr_dq_create(&params);
     842         [ -  + ]:          4 :         TEST_RCU_QSBR_RETURN_IF_ERROR((dq == NULL), "dq create valid params");
     843                 :            : 
     844                 :            :         /* Given the size calculate the maximum number of entries
     845                 :            :          * that can be stored on the defer queue (look at the logic used
     846                 :            :          * in capacity calculation of rte_ring).
     847                 :            :          */
     848                 :          4 :         max_entries = rte_align32pow2(size + 1) - 1;
     849                 :            :         printf("max_entries = %d\n", max_entries);
     850                 :            : 
     851                 :            :         /* Enqueue few counters starting with the value 'sc' */
     852                 :            :         /* The queue size will be rounded up to 2. The enqueue API also
     853                 :            :          * reclaims if the queue size is above certain limit. Since, there
     854                 :            :          * are no threads registered, reclamation succeeds. Hence, it should
     855                 :            :          * be possible to enqueue more than the provided queue size.
     856                 :            :          */
     857         [ +  + ]:         44 :         for (i = 0; i < 10; i++) {
     858                 :         40 :                 ret = rte_rcu_qsbr_dq_enqueue(dq, e);
     859         [ -  + ]:         40 :                 TEST_RCU_QSBR_GOTO_IF_ERROR(end, (ret != 0),
     860                 :            :                         "dq enqueue functional, i = %d", i);
     861         [ +  + ]:        240 :                 for (j = 0; j < esize/8; j++)
     862                 :        200 :                         e[j] = sc++;
     863                 :            :         }
     864                 :            : 
     865                 :            :         /* Validate that call back function did not return any error */
     866         [ -  + ]:          4 :         TEST_RCU_QSBR_GOTO_IF_ERROR(end, (cb_failed == 1), "CB failed");
     867                 :            : 
     868                 :            :         /* Register a thread on the RCU QSBR variable. Reclamation will not
     869                 :            :          * succeed. It should not be possible to enqueue more than the size
     870                 :            :          * number of resources.
     871                 :            :          */
     872                 :          4 :         rte_rcu_qsbr_thread_register(t[0], 1);
     873                 :          4 :         rte_rcu_qsbr_thread_online(t[0], 1);
     874                 :            : 
     875         [ +  + ]:        526 :         for (i = 0; i < max_entries; i++) {
     876                 :        522 :                 ret = rte_rcu_qsbr_dq_enqueue(dq, e);
     877         [ -  + ]:        522 :                 TEST_RCU_QSBR_GOTO_IF_ERROR(end, (ret != 0),
     878                 :            :                         "dq enqueue functional, max_entries = %d, i = %d",
     879                 :            :                         max_entries, i);
     880         [ +  + ]:       1660 :                 for (j = 0; j < esize/8; j++)
     881                 :       1138 :                         e[j] = sc++;
     882                 :            :         }
     883                 :            : 
     884                 :            :         /* Enqueue fails as queue is full */
     885                 :          4 :         ret = rte_rcu_qsbr_dq_enqueue(dq, e);
     886         [ -  + ]:          4 :         TEST_RCU_QSBR_GOTO_IF_ERROR(end, (ret == 0), "defer queue is not full");
     887                 :            : 
     888                 :            :         /* Delete should fail as there are elements in defer queue which
     889                 :            :          * cannot be reclaimed.
     890                 :            :          */
     891                 :          4 :         ret = rte_rcu_qsbr_dq_delete(dq);
     892         [ -  + ]:          4 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret == 0), "dq delete valid params");
     893                 :            : 
     894                 :            :         /* Report quiescent state, enqueue should succeed */
     895         [ +  - ]:          4 :         rte_rcu_qsbr_quiescent(t[0], 1);
     896         [ +  + ]:        526 :         for (i = 0; i < max_entries; i++) {
     897                 :        522 :                 ret = rte_rcu_qsbr_dq_enqueue(dq, e);
     898         [ -  + ]:        522 :                 TEST_RCU_QSBR_GOTO_IF_ERROR(end, (ret != 0),
     899                 :            :                         "dq enqueue functional");
     900         [ +  + ]:       1660 :                 for (j = 0; j < esize/8; j++)
     901                 :       1138 :                         e[j] = sc++;
     902                 :            :         }
     903                 :            : 
     904                 :            :         /* Validate that call back function did not return any error */
     905         [ -  + ]:          4 :         TEST_RCU_QSBR_GOTO_IF_ERROR(end, (cb_failed == 1), "CB failed");
     906                 :            : 
     907                 :            :         /* Queue is full */
     908                 :          4 :         ret = rte_rcu_qsbr_dq_enqueue(dq, e);
     909         [ -  + ]:          4 :         TEST_RCU_QSBR_GOTO_IF_ERROR(end, (ret == 0), "defer queue is not full");
     910                 :            : 
     911                 :            :         /* Report quiescent state, delete should succeed */
     912         [ +  - ]:          4 :         rte_rcu_qsbr_quiescent(t[0], 1);
     913                 :          4 :         ret = rte_rcu_qsbr_dq_delete(dq);
     914         [ -  + ]:          4 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret != 0), "dq delete valid params");
     915                 :            : 
     916                 :          4 :         rte_free(e);
     917                 :            : 
     918                 :            :         /* Validate that call back function did not return any error */
     919         [ -  + ]:          4 :         TEST_RCU_QSBR_RETURN_IF_ERROR((cb_failed == 1), "CB failed");
     920                 :            : 
     921                 :            :         return 0;
     922                 :            : 
     923                 :          0 : end:
     924                 :          0 :         rte_free(e);
     925                 :          0 :         ret = rte_rcu_qsbr_dq_delete(dq);
     926         [ #  # ]:          0 :         TEST_RCU_QSBR_RETURN_IF_ERROR((ret != 0), "dq delete valid params");
     927                 :            :         return -1;
     928                 :            : }
     929                 :            : 
     930                 :            : /*
     931                 :            :  * rte_rcu_qsbr_dump: Dump status of a single QS variable to a file
     932                 :            :  */
     933                 :            : static int
     934                 :          1 : test_rcu_qsbr_dump(void)
     935                 :            : {
     936                 :            :         unsigned int i;
     937                 :            : 
     938                 :            :         printf("\nTest rte_rcu_qsbr_dump()\n");
     939                 :            : 
     940                 :            :         /* Negative tests */
     941                 :          1 :         rte_rcu_qsbr_dump(NULL, t[0]);
     942                 :          1 :         rte_rcu_qsbr_dump(stdout, NULL);
     943                 :          1 :         rte_rcu_qsbr_dump(NULL, NULL);
     944                 :            : 
     945                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
     946                 :          1 :         rte_rcu_qsbr_init(t[1], RTE_MAX_LCORE);
     947                 :            : 
     948                 :            :         /* QS variable with 0 core mask */
     949                 :          1 :         rte_rcu_qsbr_dump(stdout, t[0]);
     950                 :            : 
     951                 :          1 :         rte_rcu_qsbr_thread_register(t[0], enabled_core_ids[0]);
     952                 :            : 
     953         [ -  + ]:          1 :         for (i = 1; i < num_cores; i++)
     954                 :          0 :                 rte_rcu_qsbr_thread_register(t[1], enabled_core_ids[i]);
     955                 :            : 
     956                 :          1 :         rte_rcu_qsbr_dump(stdout, t[0]);
     957                 :          1 :         rte_rcu_qsbr_dump(stdout, t[1]);
     958                 :            :         printf("\n");
     959                 :          1 :         return 0;
     960                 :            : }
     961                 :            : 
     962                 :            : static int
     963                 :          1 : test_rcu_qsbr_reader(void *arg)
     964                 :            : {
     965                 :            :         struct rte_rcu_qsbr *temp;
     966                 :            :         struct rte_hash *hash = NULL;
     967                 :            :         int i;
     968                 :            :         uint32_t lcore_id = rte_lcore_id();
     969                 :            :         struct test_rcu_thread_info *ti;
     970                 :            :         uint32_t *pdata;
     971                 :            : 
     972                 :            :         ti = (struct test_rcu_thread_info *)arg;
     973                 :          1 :         temp = t[ti->ir];
     974                 :          1 :         hash = h[ti->ih];
     975                 :            : 
     976                 :            :         do {
     977                 :          2 :                 rte_rcu_qsbr_thread_register(temp, lcore_id);
     978                 :            :                 rte_rcu_qsbr_thread_online(temp, lcore_id);
     979         [ +  + ]:      16386 :                 for (i = 0; i < TOTAL_ENTRY; i++) {
     980                 :            :                         rte_rcu_qsbr_lock(temp, lcore_id);
     981         [ +  + ]:      16384 :                         if (rte_hash_lookup_data(hash, keys+i,
     982                 :            :                                         (void **)&pdata) != -ENOENT) {
     983                 :      16379 :                                 pdata[lcore_id] = 0;
     984         [ +  + ]:   67104763 :                                 while (pdata[lcore_id] < COUNTER_VALUE)
     985                 :   67088384 :                                         pdata[lcore_id]++;
     986                 :            :                         }
     987                 :            :                         rte_rcu_qsbr_unlock(temp, lcore_id);
     988                 :            :                 }
     989                 :            :                 /* Update quiescent state counter */
     990                 :            :                 rte_rcu_qsbr_quiescent(temp, lcore_id);
     991                 :            :                 rte_rcu_qsbr_thread_offline(temp, lcore_id);
     992                 :          2 :                 rte_rcu_qsbr_thread_unregister(temp, lcore_id);
     993         [ +  + ]:          2 :         } while (!writer_done);
     994                 :            : 
     995                 :          1 :         return 0;
     996                 :            : }
     997                 :            : 
     998                 :            : static int
     999                 :          0 : test_rcu_qsbr_writer(void *arg)
    1000                 :            : {
    1001                 :            :         uint64_t token;
    1002                 :            :         int32_t i, pos, del;
    1003                 :            :         uint32_t c;
    1004                 :            :         struct rte_rcu_qsbr *temp;
    1005                 :            :         struct rte_hash *hash = NULL;
    1006                 :            :         struct test_rcu_thread_info *ti;
    1007                 :            : 
    1008                 :            :         ti = (struct test_rcu_thread_info *)arg;
    1009                 :          0 :         temp = t[ti->ir];
    1010                 :          0 :         hash = h[ti->ih];
    1011                 :            : 
    1012                 :            :         /* Delete element from the shared data structure */
    1013                 :          0 :         del = rte_lcore_id() % TOTAL_ENTRY;
    1014                 :          0 :         pos = rte_hash_del_key(hash, keys + del);
    1015         [ #  # ]:          0 :         if (pos < 0) {
    1016                 :          0 :                 printf("Delete key failed #%d\n", keys[del]);
    1017                 :          0 :                 return -1;
    1018                 :            :         }
    1019                 :            :         /* Start the quiescent state query process */
    1020                 :            :         token = rte_rcu_qsbr_start(temp);
    1021                 :            :         /* Check the quiescent state status */
    1022                 :            :         rte_rcu_qsbr_check(temp, token, true);
    1023         [ #  # ]:          0 :         for (i = 0; i < 2; i++) {
    1024                 :          0 :                 c = hash_data[ti->ih][del][ti->r_core_ids[i]];
    1025         [ #  # ]:          0 :                 if (c != COUNTER_VALUE && c != 0) {
    1026                 :            :                         printf("Reader lcore id %u did not complete = %u\t",
    1027                 :            :                                 rte_lcore_id(), c);
    1028                 :          0 :                         return -1;
    1029                 :            :                 }
    1030                 :            :         }
    1031                 :            : 
    1032         [ #  # ]:          0 :         if (rte_hash_free_key_with_position(hash, pos) < 0) {
    1033                 :          0 :                 printf("Failed to free the key #%d\n", keys[del]);
    1034                 :          0 :                 return -1;
    1035                 :            :         }
    1036                 :          0 :         rte_free(hash_data[ti->ih][del]);
    1037                 :          0 :         hash_data[ti->ih][del] = NULL;
    1038                 :            : 
    1039                 :          0 :         return 0;
    1040                 :            : }
    1041                 :            : 
    1042                 :            : static struct rte_hash *
    1043                 :          1 : init_hash(int hash_id)
    1044                 :            : {
    1045                 :            :         int i;
    1046                 :            :         struct rte_hash *h = NULL;
    1047                 :            : 
    1048                 :          1 :         sprintf(hash_name[hash_id], "hash%d", hash_id);
    1049                 :          2 :         struct rte_hash_parameters hash_params = {
    1050                 :            :                 .entries = TOTAL_ENTRY,
    1051                 :            :                 .key_len = sizeof(uint32_t),
    1052                 :            :                 .hash_func_init_val = 0,
    1053                 :          1 :                 .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                 :          1 :         h = rte_hash_create(&hash_params);
    1061         [ -  + ]:          1 :         if (h == NULL) {
    1062                 :            :                 printf("Hash create Failed\n");
    1063                 :          0 :                 return NULL;
    1064                 :            :         }
    1065                 :            : 
    1066         [ +  + ]:       8193 :         for (i = 0; i < TOTAL_ENTRY; i++) {
    1067                 :       8192 :                 hash_data[hash_id][i] =
    1068                 :       8192 :                         rte_zmalloc(NULL, sizeof(uint32_t) * RTE_MAX_LCORE, 0);
    1069         [ -  + ]:       8192 :                 if (hash_data[hash_id][i] == NULL) {
    1070                 :            :                         printf("No memory\n");
    1071                 :          0 :                         return NULL;
    1072                 :            :                 }
    1073                 :            :         }
    1074                 :          1 :         keys = rte_malloc(NULL, sizeof(uint32_t) * TOTAL_ENTRY, 0);
    1075         [ -  + ]:          1 :         if (keys == NULL) {
    1076                 :            :                 printf("No memory\n");
    1077                 :          0 :                 return NULL;
    1078                 :            :         }
    1079                 :            : 
    1080         [ +  + ]:       8193 :         for (i = 0; i < TOTAL_ENTRY; i++)
    1081                 :       8192 :                 keys[i] = i;
    1082                 :            : 
    1083         [ +  + ]:       8193 :         for (i = 0; i < TOTAL_ENTRY; i++) {
    1084         [ -  + ]:       8192 :                 if (rte_hash_add_key_data(h, keys + i,
    1085                 :       8192 :                                 (void *)((uintptr_t)hash_data[hash_id][i]))
    1086                 :            :                                 < 0) {
    1087                 :            :                         printf("Hash key add Failed #%d\n", i);
    1088                 :          0 :                         return NULL;
    1089                 :            :                 }
    1090                 :            :         }
    1091                 :            :         return h;
    1092                 :            : }
    1093                 :            : 
    1094                 :            : /*
    1095                 :            :  * Functional test:
    1096                 :            :  * Single writer, Single QS variable, simultaneous QSBR Queries
    1097                 :            :  */
    1098                 :            : static int
    1099                 :          1 : test_rcu_qsbr_sw_sv_3qs(void)
    1100                 :            : {
    1101                 :            :         uint64_t token[3];
    1102                 :            :         uint32_t c;
    1103                 :            :         int i, num_readers;
    1104                 :            :         int32_t pos[3];
    1105                 :            : 
    1106                 :          1 :         writer_done = 0;
    1107                 :            : 
    1108                 :            :         printf("Test: 1 writer, 1 QSBR variable, simultaneous QSBR queries\n");
    1109                 :            : 
    1110                 :          1 :         rte_rcu_qsbr_init(t[0], RTE_MAX_LCORE);
    1111                 :            : 
    1112                 :            :         /* Shared data structure created */
    1113                 :          1 :         h[0] = init_hash(0);
    1114         [ -  + ]:          1 :         if (h[0] == NULL) {
    1115                 :            :                 printf("Hash init failed\n");
    1116                 :          0 :                 goto error;
    1117                 :            :         }
    1118                 :            : 
    1119                 :            :         /* No need to fill the registered core IDs as the writer
    1120                 :            :          * thread is not launched.
    1121                 :            :          */
    1122                 :          1 :         thread_info[0].ir = 0;
    1123                 :          1 :         thread_info[0].ih = 0;
    1124                 :            : 
    1125                 :            :         /* Reader threads are launched */
    1126                 :            :         /* Keep the number of reader threads low to reduce
    1127                 :            :          * the execution time.
    1128                 :            :          */
    1129                 :          1 :         num_readers = num_cores < 4 ? num_cores : 4;
    1130         [ +  + ]:          2 :         for (i = 0; i < num_readers; i++)
    1131                 :          1 :                 rte_eal_remote_launch(test_rcu_qsbr_reader, &thread_info[0],
    1132                 :          1 :                                         enabled_core_ids[i]);
    1133                 :            : 
    1134                 :            :         /* Delete element from the shared data structure */
    1135                 :          1 :         pos[0] = rte_hash_del_key(h[0], keys + 0);
    1136         [ -  + ]:          1 :         if (pos[0] < 0) {
    1137                 :          0 :                 printf("Delete key failed #%d\n", keys[0]);
    1138                 :          0 :                 goto error;
    1139                 :            :         }
    1140                 :            :         /* Start the quiescent state query process */
    1141                 :          1 :         token[0] = rte_rcu_qsbr_start(t[0]);
    1142                 :            : 
    1143                 :            :         /* Delete element from the shared data structure */
    1144                 :          1 :         pos[1] = rte_hash_del_key(h[0], keys + 3);
    1145         [ -  + ]:          1 :         if (pos[1] < 0) {
    1146                 :          0 :                 printf("Delete key failed #%d\n", keys[3]);
    1147                 :          0 :                 goto error;
    1148                 :            :         }
    1149                 :            :         /* Start the quiescent state query process */
    1150                 :          1 :         token[1] = rte_rcu_qsbr_start(t[0]);
    1151                 :            : 
    1152                 :            :         /* Delete element from the shared data structure */
    1153                 :          1 :         pos[2] = rte_hash_del_key(h[0], keys + 6);
    1154         [ -  + ]:          1 :         if (pos[2] < 0) {
    1155                 :          0 :                 printf("Delete key failed #%d\n", keys[6]);
    1156                 :          0 :                 goto error;
    1157                 :            :         }
    1158                 :            :         /* Start the quiescent state query process */
    1159         [ +  - ]:          1 :         token[2] = rte_rcu_qsbr_start(t[0]);
    1160                 :            : 
    1161                 :            :         /* Check the quiescent state status */
    1162         [ +  - ]:          1 :         rte_rcu_qsbr_check(t[0], token[0], true);
    1163         [ +  + ]:          2 :         for (i = 0; i < num_readers; i++) {
    1164                 :          1 :                 c = hash_data[0][0][enabled_core_ids[i]];
    1165         [ -  + ]:          1 :                 if (c != COUNTER_VALUE && c != 0) {
    1166                 :          0 :                         printf("Reader lcore %d did not complete #0 = %d\n",
    1167                 :            :                                 enabled_core_ids[i], c);
    1168                 :          0 :                         goto error;
    1169                 :            :                 }
    1170                 :            :         }
    1171                 :            : 
    1172         [ -  + ]:          1 :         if (rte_hash_free_key_with_position(h[0], pos[0]) < 0) {
    1173                 :          0 :                 printf("Failed to free the key #%d\n", keys[0]);
    1174                 :          0 :                 goto error;
    1175                 :            :         }
    1176                 :          1 :         rte_free(hash_data[0][0]);
    1177                 :          1 :         hash_data[0][0] = NULL;
    1178                 :            : 
    1179                 :            :         /* Check the quiescent state status */
    1180         [ +  - ]:          1 :         rte_rcu_qsbr_check(t[0], token[1], true);
    1181         [ +  + ]:          2 :         for (i = 0; i < num_readers; i++) {
    1182                 :          1 :                 c = hash_data[0][3][enabled_core_ids[i]];
    1183         [ -  + ]:          1 :                 if (c != COUNTER_VALUE && c != 0) {
    1184                 :          0 :                         printf("Reader lcore %d did not complete #3 = %d\n",
    1185                 :            :                                 enabled_core_ids[i], c);
    1186                 :          0 :                         goto error;
    1187                 :            :                 }
    1188                 :            :         }
    1189                 :            : 
    1190         [ -  + ]:          1 :         if (rte_hash_free_key_with_position(h[0], pos[1]) < 0) {
    1191                 :          0 :                 printf("Failed to free the key #%d\n", keys[3]);
    1192                 :          0 :                 goto error;
    1193                 :            :         }
    1194                 :          1 :         rte_free(hash_data[0][3]);
    1195                 :          1 :         hash_data[0][3] = NULL;
    1196                 :            : 
    1197                 :            :         /* Check the quiescent state status */
    1198         [ -  + ]:          1 :         rte_rcu_qsbr_check(t[0], token[2], true);
    1199         [ +  + ]:          2 :         for (i = 0; i < num_readers; i++) {
    1200                 :          1 :                 c = hash_data[0][6][enabled_core_ids[i]];
    1201         [ -  + ]:          1 :                 if (c != COUNTER_VALUE && c != 0) {
    1202                 :          0 :                         printf("Reader lcore %d did not complete #6 = %d\n",
    1203                 :            :                                 enabled_core_ids[i], c);
    1204                 :          0 :                         goto error;
    1205                 :            :                 }
    1206                 :            :         }
    1207                 :            : 
    1208         [ -  + ]:          1 :         if (rte_hash_free_key_with_position(h[0], pos[2]) < 0) {
    1209                 :          0 :                 printf("Failed to free the key #%d\n", keys[6]);
    1210                 :          0 :                 goto error;
    1211                 :            :         }
    1212                 :          1 :         rte_free(hash_data[0][6]);
    1213                 :          1 :         hash_data[0][6] = NULL;
    1214                 :            : 
    1215                 :          1 :         writer_done = 1;
    1216                 :            : 
    1217                 :            :         /* Wait and check return value from reader threads */
    1218         [ +  + ]:          2 :         for (i = 0; i < num_readers; i++)
    1219         [ -  + ]:          1 :                 if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
    1220                 :          0 :                         goto error;
    1221                 :          1 :         rte_hash_free(h[0]);
    1222                 :          1 :         rte_free(keys);
    1223                 :            : 
    1224                 :          1 :         return 0;
    1225                 :            : 
    1226                 :          0 : error:
    1227                 :          0 :         writer_done = 1;
    1228                 :            :         /* Wait until all readers have exited */
    1229                 :          0 :         rte_eal_mp_wait_lcore();
    1230                 :            : 
    1231                 :          0 :         rte_hash_free(h[0]);
    1232                 :          0 :         rte_free(keys);
    1233         [ #  # ]:          0 :         for (i = 0; i < TOTAL_ENTRY; i++)
    1234                 :          0 :                 rte_free(hash_data[0][i]);
    1235                 :            : 
    1236                 :            :         return -1;
    1237                 :            : }
    1238                 :            : 
    1239                 :            : /*
    1240                 :            :  * Multi writer, Multiple QS variable, simultaneous QSBR queries
    1241                 :            :  */
    1242                 :            : static int
    1243                 :          1 : test_rcu_qsbr_mw_mv_mqs(void)
    1244                 :            : {
    1245                 :            :         unsigned int i, j;
    1246                 :            :         unsigned int test_cores;
    1247                 :            : 
    1248         [ +  - ]:          1 :         if (RTE_MAX_LCORE < 5 || num_cores < 4) {
    1249                 :            :                 printf("Not enough cores for %s, expecting at least 5\n",
    1250                 :            :                         __func__);
    1251                 :          1 :                 return TEST_SKIPPED;
    1252                 :            :         }
    1253                 :            : 
    1254                 :          0 :         writer_done = 0;
    1255                 :            :         test_cores = num_cores / 4;
    1256                 :            :         test_cores = test_cores * 4;
    1257                 :            : 
    1258                 :          0 :         printf("Test: %d writers, %d QSBR variable, simultaneous QSBR queries\n",
    1259                 :            :                test_cores / 2, test_cores / 4);
    1260                 :            : 
    1261         [ #  # ]:          0 :         for (i = 0; i < test_cores / 4; i++) {
    1262                 :          0 :                 j = i * 4;
    1263                 :          0 :                 rte_rcu_qsbr_init(t[i], RTE_MAX_LCORE);
    1264                 :          0 :                 h[i] = init_hash(i);
    1265         [ #  # ]:          0 :                 if (h[i] == NULL) {
    1266                 :            :                         printf("Hash init failed\n");
    1267                 :          0 :                         goto error;
    1268                 :            :                 }
    1269                 :          0 :                 thread_info[i].ir = i;
    1270                 :          0 :                 thread_info[i].ih = i;
    1271                 :          0 :                 thread_info[i].r_core_ids[0] = enabled_core_ids[j];
    1272                 :          0 :                 thread_info[i].r_core_ids[1] = enabled_core_ids[j + 1];
    1273                 :            : 
    1274                 :            :                 /* Reader threads are launched */
    1275                 :          0 :                 rte_eal_remote_launch(test_rcu_qsbr_reader,
    1276                 :          0 :                                         (void *)&thread_info[i],
    1277                 :            :                                         enabled_core_ids[j]);
    1278                 :          0 :                 rte_eal_remote_launch(test_rcu_qsbr_reader,
    1279                 :            :                                         (void *)&thread_info[i],
    1280                 :          0 :                                         enabled_core_ids[j + 1]);
    1281                 :            : 
    1282                 :            :                 /* Writer threads are launched */
    1283                 :          0 :                 rte_eal_remote_launch(test_rcu_qsbr_writer,
    1284                 :            :                                         (void *)&thread_info[i],
    1285                 :          0 :                                         enabled_core_ids[j + 2]);
    1286                 :          0 :                 rte_eal_remote_launch(test_rcu_qsbr_writer,
    1287                 :            :                                         (void *)&thread_info[i],
    1288                 :          0 :                                         enabled_core_ids[j + 3]);
    1289                 :            :         }
    1290                 :            : 
    1291                 :            :         /* Wait and check return value from writer threads */
    1292         [ #  # ]:          0 :         for (i = 0; i < test_cores / 4; i++) {
    1293                 :          0 :                 j = i * 4;
    1294         [ #  # ]:          0 :                 if (rte_eal_wait_lcore(enabled_core_ids[j + 2]) < 0)
    1295                 :          0 :                         goto error;
    1296                 :            : 
    1297         [ #  # ]:          0 :                 if (rte_eal_wait_lcore(enabled_core_ids[j + 3]) < 0)
    1298                 :          0 :                         goto error;
    1299                 :            :         }
    1300                 :          0 :         writer_done = 1;
    1301                 :            : 
    1302                 :            :         /* Wait and check return value from reader threads */
    1303         [ #  # ]:          0 :         for (i = 0; i < test_cores / 4; i++) {
    1304                 :          0 :                 j = i * 4;
    1305         [ #  # ]:          0 :                 if (rte_eal_wait_lcore(enabled_core_ids[j]) < 0)
    1306                 :          0 :                         goto error;
    1307                 :            : 
    1308         [ #  # ]:          0 :                 if (rte_eal_wait_lcore(enabled_core_ids[j + 1]) < 0)
    1309                 :          0 :                         goto error;
    1310                 :            :         }
    1311                 :            : 
    1312         [ #  # ]:          0 :         for (i = 0; i < test_cores / 4; i++)
    1313                 :          0 :                 rte_hash_free(h[i]);
    1314                 :            : 
    1315                 :          0 :         rte_free(keys);
    1316                 :            : 
    1317                 :          0 :         return 0;
    1318                 :            : 
    1319                 :          0 : error:
    1320                 :          0 :         writer_done = 1;
    1321                 :            :         /* Wait until all readers and writers have exited */
    1322                 :          0 :         rte_eal_mp_wait_lcore();
    1323                 :            : 
    1324         [ #  # ]:          0 :         for (i = 0; i < test_cores / 4; i++)
    1325                 :          0 :                 rte_hash_free(h[i]);
    1326                 :          0 :         rte_free(keys);
    1327         [ #  # ]:          0 :         for (j = 0; j < test_cores / 4; j++)
    1328         [ #  # ]:          0 :                 for (i = 0; i < TOTAL_ENTRY; i++)
    1329                 :          0 :                         rte_free(hash_data[j][i]);
    1330                 :            : 
    1331                 :            :         return -1;
    1332                 :            : }
    1333                 :            : 
    1334                 :            : static int
    1335                 :          1 : test_rcu_qsbr_main(void)
    1336                 :            : {
    1337                 :            :         uint16_t core_id;
    1338                 :            : 
    1339                 :          1 :         num_cores = 0;
    1340         [ +  + ]:          2 :         RTE_LCORE_FOREACH_WORKER(core_id) {
    1341                 :          1 :                 enabled_core_ids[num_cores] = core_id;
    1342                 :          1 :                 num_cores++;
    1343                 :            :         }
    1344                 :            : 
    1345                 :            :         /* Error-checking test cases */
    1346         [ -  + ]:          1 :         if (test_rcu_qsbr_get_memsize() < 0)
    1347                 :          0 :                 goto test_fail;
    1348                 :            : 
    1349         [ -  + ]:          1 :         if (test_rcu_qsbr_init() < 0)
    1350                 :          0 :                 goto test_fail;
    1351                 :            : 
    1352                 :          1 :         alloc_rcu();
    1353                 :            : 
    1354         [ -  + ]:          1 :         if (test_rcu_qsbr_thread_register() < 0)
    1355                 :          0 :                 goto test_fail;
    1356                 :            : 
    1357         [ -  + ]:          1 :         if (test_rcu_qsbr_thread_unregister() < 0)
    1358                 :          0 :                 goto test_fail;
    1359                 :            : 
    1360         [ -  + ]:          1 :         if (test_rcu_qsbr_start() < 0)
    1361                 :          0 :                 goto test_fail;
    1362                 :            : 
    1363         [ -  + ]:          1 :         if (test_rcu_qsbr_check() < 0)
    1364                 :          0 :                 goto test_fail;
    1365                 :            : 
    1366         [ -  + ]:          1 :         if (test_rcu_qsbr_synchronize() < 0)
    1367                 :          0 :                 goto test_fail;
    1368                 :            : 
    1369         [ -  + ]:          1 :         if (test_rcu_qsbr_dump() < 0)
    1370                 :          0 :                 goto test_fail;
    1371                 :            : 
    1372         [ -  + ]:          1 :         if (test_rcu_qsbr_thread_online() < 0)
    1373                 :          0 :                 goto test_fail;
    1374                 :            : 
    1375         [ -  + ]:          1 :         if (test_rcu_qsbr_thread_offline() < 0)
    1376                 :          0 :                 goto test_fail;
    1377                 :            : 
    1378         [ -  + ]:          1 :         if (test_rcu_qsbr_dq_create() < 0)
    1379                 :          0 :                 goto test_fail;
    1380                 :            : 
    1381         [ -  + ]:          1 :         if (test_rcu_qsbr_dq_reclaim() < 0)
    1382                 :          0 :                 goto test_fail;
    1383                 :            : 
    1384         [ -  + ]:          1 :         if (test_rcu_qsbr_dq_delete() < 0)
    1385                 :          0 :                 goto test_fail;
    1386                 :            : 
    1387         [ -  + ]:          1 :         if (test_rcu_qsbr_dq_enqueue() < 0)
    1388                 :          0 :                 goto test_fail;
    1389                 :            : 
    1390                 :            :         printf("\nFunctional tests\n");
    1391                 :            : 
    1392         [ -  + ]:          1 :         if (test_rcu_qsbr_sw_sv_3qs() < 0)
    1393                 :          0 :                 goto test_fail;
    1394                 :            : 
    1395         [ -  + ]:          1 :         if (test_rcu_qsbr_mw_mv_mqs() < 0)
    1396                 :          0 :                 goto test_fail;
    1397                 :            : 
    1398         [ -  + ]:          1 :         if (test_rcu_qsbr_dq_functional(1, 8, 0) < 0)
    1399                 :          0 :                 goto test_fail;
    1400                 :            : 
    1401         [ -  + ]:          1 :         if (test_rcu_qsbr_dq_functional(2, 8, RTE_RCU_QSBR_DQ_MT_UNSAFE) < 0)
    1402                 :          0 :                 goto test_fail;
    1403                 :            : 
    1404         [ -  + ]:          1 :         if (test_rcu_qsbr_dq_functional(303, 16, 0) < 0)
    1405                 :          0 :                 goto test_fail;
    1406                 :            : 
    1407         [ +  - ]:          1 :         if (test_rcu_qsbr_dq_functional(7, 128, RTE_RCU_QSBR_DQ_MT_UNSAFE) < 0)
    1408                 :          0 :                 goto test_fail;
    1409                 :            : 
    1410                 :            :         free_rcu();
    1411                 :            : 
    1412                 :            :         printf("\n");
    1413                 :          1 :         return 0;
    1414                 :            : 
    1415                 :            : test_fail:
    1416                 :            :         free_rcu();
    1417                 :            : 
    1418                 :            :         return -1;
    1419                 :            : }
    1420                 :            : 
    1421                 :        252 : REGISTER_FAST_TEST(rcu_qsbr_autotest, true, true, test_rcu_qsbr_main);

Generated by: LCOV version 1.14