From 9ea221b05140529725c33ef6478b1aca02c2bc05 Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Thu, 12 Sep 2024 17:26:18 +0300 Subject: [PATCH] linux-dpdk: event: use linux-gen event code Use platform agnostic code from linux-generic. Signed-off-by: Matias Elo --- platform/linux-dpdk/Makefile.am | 3 +- platform/linux-dpdk/odp_event.c | 228 ------------------------ platform/linux-dpdk/odp_event_offsets.c | 23 +++ 3 files changed, 25 insertions(+), 229 deletions(-) delete mode 100644 platform/linux-dpdk/odp_event.c create mode 100644 platform/linux-dpdk/odp_event_offsets.c diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 4543830bc..b1e635ad1 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -210,7 +210,8 @@ __LIB__libodp_dpdk_la_SOURCES = \ odp_dma.c \ odp_crypto.c \ odp_errno.c \ - odp_event.c \ + ../linux-generic/odp_event.c \ + odp_event_offsets.c \ ../linux-generic/odp_event_validation.c \ ../linux-generic/odp_hash_crc_gen.c \ odp_init.c \ diff --git a/platform/linux-dpdk/odp_event.c b/platform/linux-dpdk/odp_event.c deleted file mode 100644 index 5af5681a9..000000000 --- a/platform/linux-dpdk/odp_event.c +++ /dev/null @@ -1,228 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2015-2018 Linaro Limited - * Copyright (c) 2020-2024 Nokia - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -/* Inlined API functions */ -#include -#include -#include -#include - -#include - -#include - -/* Fill in event header field offsets for inline functions */ -const _odp_event_inline_offset_t -_odp_event_inline_offset ODP_ALIGNED_CACHE = { - .event_type = offsetof(_odp_event_hdr_t, hdr.event_type), - .base_data = offsetof(_odp_event_hdr_t, mb.buf_addr), - .subtype = offsetof(_odp_event_hdr_t, hdr.subtype), - .flow_id = offsetof(_odp_event_hdr_t, hdr.flow_id), - .pool = offsetof(_odp_event_hdr_t, hdr.pool), - .buf_len = offsetof(_odp_event_hdr_t, mb.buf_len) -}; - -#include - -void odp_event_free(odp_event_t event) -{ - switch (odp_event_type(event)) { - case ODP_EVENT_BUFFER: - _odp_buffer_validate(odp_buffer_from_event(event), _ODP_EV_EVENT_FREE); - odp_buffer_free(odp_buffer_from_event(event)); - break; - case ODP_EVENT_PACKET: - _odp_packet_validate(odp_packet_from_event(event), _ODP_EV_EVENT_FREE); - odp_packet_free(odp_packet_from_event(event)); - break; - case ODP_EVENT_PACKET_VECTOR: - _odp_packet_vector_free_full(odp_packet_vector_from_event(event)); - break; - case ODP_EVENT_TIMEOUT: - odp_timeout_free(odp_timeout_from_event(event)); - break; - case ODP_EVENT_IPSEC_STATUS: - _odp_ipsec_status_free(_odp_ipsec_status_from_event(event)); - break; - case ODP_EVENT_PACKET_TX_COMPL: - odp_packet_tx_compl_free(odp_packet_tx_compl_from_event(event)); - break; - case ODP_EVENT_DMA_COMPL: - odp_dma_compl_free(odp_dma_compl_from_event(event)); - break; - case ODP_EVENT_ML_COMPL: - odp_ml_compl_free(odp_ml_compl_from_event(event)); - break; - default: - _ODP_ABORT("Invalid event type: %d\n", odp_event_type(event)); - } -} - -static inline void packet_vector_free_full_multi(const odp_packet_vector_t pktv[], int num) -{ - for (int i = 0; i < num; i++) - _odp_packet_vector_free_full(pktv[i]); -} - -static inline void ipsec_status_free_multi(const ipsec_status_t status[], int num) -{ - for (int i = 0; i < num; i++) - _odp_ipsec_status_free(status[i]); -} - -static inline void packet_tx_compl_free_multi(const odp_packet_tx_compl_t tx_compl[], int num) -{ - for (int i = 0; i < num; i++) - odp_packet_tx_compl_free(tx_compl[i]); -} - -static inline void dma_compl_free_multi(const odp_dma_compl_t dma_compl[], int num) -{ - for (int i = 0; i < num; i++) - odp_dma_compl_free(dma_compl[i]); -} - -static inline void ml_compl_free_multi(const odp_ml_compl_t ml_compl[], int num) -{ - for (int i = 0; i < num; i++) - odp_ml_compl_free(ml_compl[i]); -} - -static inline void event_free_multi(const odp_event_t event[], int num, odp_event_type_t type, - _odp_ev_id_t id) -{ - switch (type) { - case ODP_EVENT_BUFFER: - _odp_buffer_validate_multi((odp_buffer_t *)(uintptr_t)event, num, id); - odp_buffer_free_multi((odp_buffer_t *)(uintptr_t)event, num); - break; - case ODP_EVENT_PACKET: - _odp_packet_validate_multi((odp_packet_t *)(uintptr_t)event, num, id); - odp_packet_free_multi((odp_packet_t *)(uintptr_t)event, num); - break; - case ODP_EVENT_PACKET_VECTOR: - packet_vector_free_full_multi((odp_packet_vector_t *)(uintptr_t)event, num); - break; - case ODP_EVENT_TIMEOUT: - odp_timeout_free_multi((odp_timeout_t *)(uintptr_t)event, num); - break; - case ODP_EVENT_IPSEC_STATUS: - ipsec_status_free_multi((ipsec_status_t *)(uintptr_t)event, num); - break; - case ODP_EVENT_PACKET_TX_COMPL: - packet_tx_compl_free_multi((odp_packet_tx_compl_t *)(uintptr_t)event, num); - break; - case ODP_EVENT_DMA_COMPL: - dma_compl_free_multi((odp_dma_compl_t *)(uintptr_t)event, num); - break; - case ODP_EVENT_ML_COMPL: - ml_compl_free_multi((odp_ml_compl_t *)(uintptr_t)event, num); - break; - default: - _ODP_ABORT("Invalid event type: %d\n", type); - } -} - -void odp_event_free_multi(const odp_event_t event[], int num) -{ - const odp_event_t *burst_start; - odp_event_type_t burst_type; - int burst_size; - - if (odp_unlikely(num <= 0)) - return; - - burst_type = odp_event_type(event[0]); - burst_start = &event[0]; - burst_size = 1; - - for (int i = 1; i < num; i++) { - const odp_event_type_t cur_type = odp_event_type(event[i]); - - if (cur_type == burst_type) { - burst_size++; - continue; - } - - event_free_multi(burst_start, burst_size, burst_type, _ODP_EV_EVENT_FREE_MULTI); - - burst_type = cur_type; - burst_start = &event[i]; - burst_size = 1; - } - - event_free_multi(burst_start, burst_size, burst_type, _ODP_EV_EVENT_FREE_MULTI); -} - -void odp_event_free_sp(const odp_event_t event[], int num) -{ - if (odp_unlikely(num <= 0)) - return; - - if (ODP_DEBUG) { - const odp_pool_t pool = _odp_event_pool(event[0]); - - for (int i = 1; i < num; i++) - _ODP_ASSERT(_odp_event_pool(event[i]) == pool); - } - - event_free_multi(event, num, odp_event_type(event[0]), _ODP_EV_EVENT_FREE_SP); -} - -uint64_t odp_event_to_u64(odp_event_t hdl) -{ - return _odp_pri(hdl); -} - -int odp_event_is_valid(odp_event_t event) -{ - if (event == ODP_EVENT_INVALID) - return 0; - - if (_odp_event_is_valid(event) == 0) - return 0; - - switch (odp_event_type(event)) { - case ODP_EVENT_BUFFER: - return !_odp_buffer_validate(odp_buffer_from_event(event), _ODP_EV_EVENT_IS_VALID); - case ODP_EVENT_PACKET: - return !_odp_packet_validate(odp_packet_from_event(event), _ODP_EV_EVENT_IS_VALID); - case ODP_EVENT_TIMEOUT: - /* Fall through */ - case ODP_EVENT_IPSEC_STATUS: - /* Fall through */ - case ODP_EVENT_PACKET_VECTOR: - /* Fall through */ - case ODP_EVENT_DMA_COMPL: - /* Fall through */ - case ODP_EVENT_ML_COMPL: - /* Fall through */ - case ODP_EVENT_PACKET_TX_COMPL: - break; - default: - return 0; - } - - return 1; -} diff --git a/platform/linux-dpdk/odp_event_offsets.c b/platform/linux-dpdk/odp_event_offsets.c new file mode 100644 index 000000000..41d52f019 --- /dev/null +++ b/platform/linux-dpdk/odp_event_offsets.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2015-2018 Linaro Limited + * Copyright (c) 2020-2024 Nokia + */ + +#include + +#include + +#include + +/* Fill in event header field offsets for inline functions */ +const _odp_event_inline_offset_t +_odp_event_inline_offset ODP_ALIGNED_CACHE = { + .event_type = offsetof(_odp_event_hdr_t, hdr.event_type), + .base_data = offsetof(_odp_event_hdr_t, mb.buf_addr), + .subtype = offsetof(_odp_event_hdr_t, hdr.subtype), + .flow_id = offsetof(_odp_event_hdr_t, hdr.flow_id), + .pool = offsetof(_odp_event_hdr_t, hdr.pool), + .buf_len = offsetof(_odp_event_hdr_t, mb.buf_len) +}; + +#include