LCOV - code coverage report
Current view: top level - app/test-eventdev - test_atomic_common.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 17 0.0 %
Date: 2025-04-03 19:37:06 Functions: 0 2 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                 :            : #ifndef _TEST_ATOMIC_COMMON_H
       6                 :            : #define _TEST_ATOMIC_COMMON_H
       7                 :            : 
       8                 :            : #include <stdio.h>
       9                 :            : #include <stdbool.h>
      10                 :            : 
      11                 :            : #include <rte_eventdev.h>
      12                 :            : 
      13                 :            : #include "evt_common.h"
      14                 :            : #include "evt_options.h"
      15                 :            : #include "evt_test.h"
      16                 :            : 
      17                 :            : #include "test_order_common.h"
      18                 :            : 
      19                 :            : #define IDLE_TIMEOUT 1
      20                 :            : 
      21                 :            : static inline uint32_t
      22                 :            : get_lock_idx(int stage, flow_id_t flow, uint32_t nb_flows)
      23                 :            : {
      24                 :          0 :         return (stage * nb_flows) + flow;
      25                 :            : }
      26                 :            : 
      27                 :            : static inline bool
      28                 :            : atomic_spinlock_trylock(rte_spinlock_t atomic_locks[],
      29                 :            :                 uint32_t stage,
      30                 :            :                 uint32_t flow,
      31                 :            :                 uint32_t nb_flows)
      32                 :            : {
      33                 :          0 :         return rte_spinlock_trylock(&atomic_locks[get_lock_idx(stage, flow, nb_flows)]);
      34                 :            : }
      35                 :            : 
      36                 :            : static inline void
      37                 :            : atomic_spinlock_unlock(rte_spinlock_t atomic_locks[],
      38                 :            :                 uint32_t stage,
      39                 :            :                 uint32_t flow,
      40                 :            :                 uint32_t nb_flows)
      41                 :            : {
      42                 :          0 :         rte_spinlock_unlock(&atomic_locks[get_lock_idx(stage, flow, nb_flows)]);
      43                 :            : }
      44                 :            : 
      45                 :            : static inline void
      46                 :          0 : atomic_lock_verify(rte_spinlock_t atomic_locks[],
      47                 :            :                 uint32_t stage,
      48                 :            :                 uint32_t flow,
      49                 :            :                 uint32_t nb_flows,
      50                 :            :                 struct test_order *const t,
      51                 :            :                 uint32_t port)
      52                 :            : {
      53                 :          0 :         if (!atomic_spinlock_trylock(atomic_locks, stage, flow, nb_flows)) {
      54                 :            : 
      55                 :          0 :                 evt_err("q=%u, flow=%x atomicity error: port %u tried to take held spinlock %p",
      56                 :            :                                 stage, flow, port,
      57                 :            :                                 &atomic_locks[get_lock_idx(stage, flow, nb_flows)]);
      58                 :          0 :                 t->err = true;
      59                 :            :         }
      60                 :          0 : }
      61                 :            : 
      62                 :            : static inline rte_spinlock_t *
      63                 :          0 : atomic_init_locks(uint32_t nb_stages, uint32_t nb_flows)
      64                 :            : {
      65                 :          0 :         const uint32_t num_locks = nb_stages * nb_flows;
      66                 :            : 
      67                 :          0 :         rte_spinlock_t *atomic_locks = rte_calloc(NULL, num_locks, sizeof(rte_spinlock_t), 0);
      68                 :            : 
      69                 :          0 :         if (atomic_locks == NULL)
      70                 :          0 :                 evt_err("Unable to allocate memory for spinlocks.");
      71                 :            : 
      72                 :          0 :         for (uint32_t i = 0; i < num_locks; i++)
      73                 :          0 :                 rte_spinlock_init(&atomic_locks[i]);
      74                 :            : 
      75                 :          0 :         return atomic_locks;
      76                 :            : }
      77                 :            : 
      78                 :            : static inline flow_id_t *
      79                 :            : order_mbuf_flow_id(struct test_order *t, struct rte_mbuf *mbuf)
      80                 :            : {
      81                 :          0 :         return RTE_MBUF_DYNFIELD(mbuf, t->flow_id_dynfield_offset, flow_id_t *);
      82                 :            : }
      83                 :            : 
      84                 :            : int atomic_launch_lcores(struct evt_test *test, struct evt_options *opt,
      85                 :            :                 int (*worker)(void *));
      86                 :            : 
      87                 :            : #endif

Generated by: LCOV version 1.14