LCOV - code coverage report
Current view: top level - app/test-eventdev - test_atomic_atq.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 89 0.0 %
Date: 2025-04-03 19:37:06 Functions: 0 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2025 Ericsson AB
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <unistd.h>
       7                 :            : 
       8                 :            : #include "test_atomic_common.h"
       9                 :            : 
      10                 :            : #define NB_QUEUES 1
      11                 :            : #define NB_STAGES 2
      12                 :            : 
      13                 :            : static rte_spinlock_t *atomic_locks;
      14                 :            : 
      15                 :            : static inline void
      16                 :          0 : atomic_atq_process_stage_0(struct test_order *const t,
      17                 :            :                 struct rte_event *const ev,
      18                 :            :                 uint32_t nb_flows,
      19                 :            :                 uint32_t port)
      20                 :            : {
      21                 :          0 :         const uint32_t flow = *order_mbuf_flow_id(t, ev->mbuf);
      22                 :            : 
      23                 :          0 :         atomic_lock_verify(atomic_locks, 0, flow, nb_flows, t, port);
      24                 :            : 
      25                 :          0 :         ev->sub_event_type = 1;
      26                 :          0 :         ev->op = RTE_EVENT_OP_FORWARD;
      27                 :          0 :         ev->sched_type = RTE_SCHED_TYPE_ATOMIC;
      28                 :          0 :         ev->event_type = RTE_EVENT_TYPE_CPU;
      29                 :            : 
      30                 :          0 :         atomic_spinlock_unlock(atomic_locks, 0, flow, nb_flows);
      31                 :          0 : }
      32                 :            : 
      33                 :            : static inline void
      34                 :          0 : atomic_atq_process_stage_1(struct test_order *const t,
      35                 :            :                 struct rte_event *const ev,
      36                 :            :                 uint32_t nb_flows,
      37                 :            :                 uint32_t *const expected_flow_seq,
      38                 :            :                 RTE_ATOMIC(uint64_t) * const outstand_pkts,
      39                 :            :                 uint32_t port)
      40                 :            : {
      41                 :          0 :         const uint32_t flow = *order_mbuf_flow_id(t, ev->mbuf);
      42                 :          0 :         const uint32_t seq = *order_mbuf_seqn(t, ev->mbuf);
      43                 :            : 
      44                 :          0 :         atomic_lock_verify(atomic_locks, 1, flow, nb_flows, t, port);
      45                 :            : 
      46                 :            :         /* compare the seqn against expected value */
      47                 :          0 :         if (seq != expected_flow_seq[flow]) {
      48                 :          0 :                 evt_err("flow=%x seqn mismatch got=%x expected=%x", flow, seq,
      49                 :            :                                 expected_flow_seq[flow]);
      50                 :          0 :                 t->err = true;
      51                 :            :         }
      52                 :            : 
      53                 :          0 :         expected_flow_seq[flow]++;
      54                 :          0 :         rte_pktmbuf_free(ev->mbuf);
      55                 :            : 
      56                 :          0 :         rte_atomic_fetch_sub_explicit(outstand_pkts, 1, rte_memory_order_relaxed);
      57                 :            : 
      58                 :          0 :         ev->op = RTE_EVENT_OP_RELEASE;
      59                 :            : 
      60                 :          0 :         atomic_spinlock_unlock(atomic_locks, 1, flow, nb_flows);
      61                 :          0 : }
      62                 :            : 
      63                 :            : static int
      64                 :          0 : atomic_atq_worker_burst(void *arg, bool flow_id_cap, uint32_t max_burst)
      65                 :            : {
      66                 :          0 :         ORDER_WORKER_INIT;
      67                 :            :         struct rte_event ev[BURST_SIZE];
      68                 :            :         uint16_t i;
      69                 :            : 
      70                 :          0 :         while (t->err == false) {
      71                 :            : 
      72                 :          0 :                 uint16_t const nb_rx = rte_event_dequeue_burst(dev_id, port, ev, max_burst, 0);
      73                 :            : 
      74                 :          0 :                 if (nb_rx == 0) {
      75                 :          0 :                         if (rte_atomic_load_explicit(outstand_pkts, rte_memory_order_relaxed) <= 0)
      76                 :            :                                 break;
      77                 :            :                         rte_pause();
      78                 :          0 :                         continue;
      79                 :            :                 }
      80                 :            : 
      81                 :          0 :                 for (i = 0; i < nb_rx; i++) {
      82                 :          0 :                         if (!flow_id_cap)
      83                 :          0 :                                 order_flow_id_copy_from_mbuf(t, &ev[i]);
      84                 :            : 
      85                 :          0 :                         switch (ev[i].sub_event_type) {
      86                 :          0 :                         case 0:
      87                 :          0 :                                 atomic_atq_process_stage_0(t, &ev[i], nb_flows, port);
      88                 :          0 :                                 break;
      89                 :          0 :                         case 1:
      90                 :          0 :                                 atomic_atq_process_stage_1(t, &ev[i], nb_flows, expected_flow_seq,
      91                 :            :                                                 outstand_pkts, port);
      92                 :          0 :                                 break;
      93                 :          0 :                         default:
      94                 :            :                                 order_process_stage_invalid(t, &ev[i]);
      95                 :            :                                 break;
      96                 :            :                         }
      97                 :            :                 }
      98                 :            : 
      99                 :            :                 uint16_t total_enq = 0;
     100                 :            : 
     101                 :            :                 do {
     102                 :          0 :                         total_enq += rte_event_enqueue_burst(
     103                 :          0 :                                         dev_id, port, ev + total_enq, nb_rx - total_enq);
     104                 :          0 :                 } while (total_enq < nb_rx);
     105                 :            :         }
     106                 :            : 
     107                 :          0 :         return 0;
     108                 :            : }
     109                 :            : 
     110                 :            : static int
     111                 :          0 : worker_wrapper(void *arg)
     112                 :            : {
     113                 :            :         struct worker_data *w = arg;
     114                 :          0 :         int max_burst = evt_has_burst_mode(w->dev_id) ? BURST_SIZE : 1;
     115                 :          0 :         const bool flow_id_cap = evt_has_flow_id(w->dev_id);
     116                 :            : 
     117                 :          0 :         return atomic_atq_worker_burst(arg, flow_id_cap, max_burst);
     118                 :            : }
     119                 :            : 
     120                 :            : static int
     121                 :          0 : atomic_atq_launch_lcores(struct evt_test *test, struct evt_options *opt)
     122                 :            : {
     123                 :          0 :         int ret = atomic_launch_lcores(test, opt, worker_wrapper);
     124                 :          0 :         rte_free(atomic_locks);
     125                 :          0 :         return ret;
     126                 :            : }
     127                 :            : 
     128                 :            : static int
     129                 :          0 : atomic_atq_eventdev_setup(struct evt_test *test, struct evt_options *opt)
     130                 :            : {
     131                 :            :         int ret;
     132                 :            : 
     133                 :          0 :         const uint8_t nb_workers = evt_nr_active_lcores(opt->wlcores);
     134                 :            :         /* number of active worker cores + 1 producer */
     135                 :          0 :         const uint8_t nb_ports = nb_workers + 1;
     136                 :            : 
     137                 :          0 :         ret = evt_configure_eventdev(opt, NB_QUEUES, nb_ports);
     138                 :          0 :         if (ret) {
     139                 :          0 :                 evt_err("failed to configure eventdev %d", opt->dev_id);
     140                 :          0 :                 return ret;
     141                 :            :         }
     142                 :            : 
     143                 :            :         /* q0 all types queue configuration */
     144                 :          0 :         struct rte_event_queue_conf q0_conf = {
     145                 :            :                         .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
     146                 :            :                         .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES,
     147                 :          0 :                         .nb_atomic_flows = opt->nb_flows,
     148                 :            :                         .nb_atomic_order_sequences = opt->nb_flows,
     149                 :            :         };
     150                 :          0 :         ret = rte_event_queue_setup(opt->dev_id, 0, &q0_conf);
     151                 :          0 :         if (ret) {
     152                 :          0 :                 evt_err("failed to setup queue0 eventdev %d", opt->dev_id);
     153                 :          0 :                 return ret;
     154                 :            :         }
     155                 :            : 
     156                 :            :         /* setup one port per worker, linking to all queues */
     157                 :          0 :         ret = order_event_dev_port_setup(test, opt, nb_workers, NB_QUEUES);
     158                 :          0 :         if (ret)
     159                 :            :                 return ret;
     160                 :            : 
     161                 :          0 :         if (!evt_has_distributed_sched(opt->dev_id)) {
     162                 :            :                 uint32_t service_id;
     163                 :          0 :                 rte_event_dev_service_id_get(opt->dev_id, &service_id);
     164                 :          0 :                 ret = evt_service_setup(service_id);
     165                 :          0 :                 if (ret) {
     166                 :          0 :                         evt_err("No service lcore found to run event dev.");
     167                 :          0 :                         return ret;
     168                 :            :                 }
     169                 :            :         }
     170                 :            : 
     171                 :          0 :         ret = rte_event_dev_start(opt->dev_id);
     172                 :          0 :         if (ret) {
     173                 :          0 :                 evt_err("failed to start eventdev %d", opt->dev_id);
     174                 :          0 :                 return ret;
     175                 :            :         }
     176                 :            : 
     177                 :          0 :         atomic_locks = atomic_init_locks(NB_STAGES, opt->nb_flows);
     178                 :            : 
     179                 :          0 :         return 0;
     180                 :            : }
     181                 :            : 
     182                 :            : static void
     183                 :          0 : atomic_atq_opt_dump(struct evt_options *opt)
     184                 :            : {
     185                 :          0 :         order_opt_dump(opt);
     186                 :            :         evt_dump("nb_evdev_queues", "%d", NB_QUEUES);
     187                 :          0 : }
     188                 :            : 
     189                 :            : static bool
     190                 :          0 : atomic_atq_capability_check(struct evt_options *opt)
     191                 :            : {
     192                 :            :         struct rte_event_dev_info dev_info;
     193                 :            : 
     194                 :          0 :         rte_event_dev_info_get(opt->dev_id, &dev_info);
     195                 :          0 :         if (dev_info.max_event_queues < NB_QUEUES ||
     196                 :          0 :                         dev_info.max_event_ports < order_nb_event_ports(opt)) {
     197                 :          0 :                 evt_err("not enough eventdev queues=%d/%d or ports=%d/%d", NB_QUEUES,
     198                 :            :                                 dev_info.max_event_queues, order_nb_event_ports(opt),
     199                 :            :                                 dev_info.max_event_ports);
     200                 :          0 :                 return false;
     201                 :            :         }
     202                 :            : 
     203                 :            :         return true;
     204                 :            : }
     205                 :            : 
     206                 :            : static const struct evt_test_ops atomic_atq = {
     207                 :            :         .cap_check        = atomic_atq_capability_check,
     208                 :            :         .opt_check        = order_opt_check,
     209                 :            :         .opt_dump         = atomic_atq_opt_dump,
     210                 :            :         .test_setup       = order_test_setup,
     211                 :            :         .mempool_setup    = order_mempool_setup,
     212                 :            :         .eventdev_setup   = atomic_atq_eventdev_setup,
     213                 :            :         .launch_lcores    = atomic_atq_launch_lcores,
     214                 :            :         .eventdev_destroy = order_eventdev_destroy,
     215                 :            :         .mempool_destroy  = order_mempool_destroy,
     216                 :            :         .test_result      = order_test_result,
     217                 :            :         .test_destroy     = order_test_destroy,
     218                 :            : };
     219                 :            : 
     220                 :          0 : EVT_TEST_REGISTER(atomic_atq);

Generated by: LCOV version 1.14