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