[dpdk-dev] [PATCH v6 12/23] eventtimer: add event timer arm/cancel function definitions
Pavan Nikhilesh
pbhagavatula at caviumnetworks.com
Thu Jan 11 12:38:37 CET 2018
On Wed, Jan 10, 2018 at 06:21:03PM -0600, Erik Gabriel Carrillo wrote:
> Signed-off-by: Erik Gabriel Carrillo <erik.g.carrillo at intel.com>
> ---
> lib/Makefile | 2 +-
> lib/librte_eventdev/Makefile | 2 +-
> lib/librte_eventdev/rte_event_timer_adapter.c | 155 +++++++++++++++++++++++---
> mk/rte.app.mk | 2 +-
> 4 files changed, 141 insertions(+), 20 deletions(-)
>
> diff --git a/lib/Makefile b/lib/Makefile
> index 4c53f8c..c2bee80 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -29,7 +29,7 @@ DEPDIRS-librte_security := librte_eal librte_mempool librte_ring librte_mbuf
> DEPDIRS-librte_security += librte_ether
> DEPDIRS-librte_security += librte_cryptodev
> DIRS-$(CONFIG_RTE_LIBRTE_EVENTDEV) += librte_eventdev
> -DEPDIRS-librte_eventdev := librte_eal librte_ring librte_ether librte_hash librte_mempool
> +DEPDIRS-librte_eventdev := librte_eal librte_ring librte_ether librte_hash librte_mempool librte_timer
> DIRS-$(CONFIG_RTE_LIBRTE_VHOST) += librte_vhost
> DEPDIRS-librte_vhost := librte_eal librte_mempool librte_mbuf librte_ether
> DIRS-$(CONFIG_RTE_LIBRTE_HASH) += librte_hash
> diff --git a/lib/librte_eventdev/Makefile b/lib/librte_eventdev/Makefile
> index e68f888..6e95528 100644
> --- a/lib/librte_eventdev/Makefile
> +++ b/lib/librte_eventdev/Makefile
> @@ -13,7 +13,7 @@ LIBABIVER := 3
> # build flags
> CFLAGS += -O3
> CFLAGS += $(WERROR_FLAGS)
> -LDLIBS += -lrte_eal -lrte_ring -lrte_ethdev -lrte_hash -lrte_mempool
> +LDLIBS += -lrte_eal -lrte_ring -lrte_ethdev -lrte_hash -lrte_mempool -lrte_timer
>
> # library source files
> SRCS-y += rte_eventdev.c
> diff --git a/lib/librte_eventdev/rte_event_timer_adapter.c b/lib/librte_eventdev/rte_event_timer_adapter.c
> index a4c8012..38e52cb 100644
> --- a/lib/librte_eventdev/rte_event_timer_adapter.c
> +++ b/lib/librte_eventdev/rte_event_timer_adapter.c
> @@ -609,16 +609,91 @@ sw_event_timer_adapter_stop(const struct rte_event_timer_adapter *adapter)
> return rte_service_component_runstate_set(sw_data->service_id, 0);
> }
>
> +static __rte_always_inline void
> +swap(struct rte_event_timer **evtims, int i, int j)
> +{
> + struct rte_event_timer *tmp;
> +
> + tmp = evtims[i];
> + evtims[i] = evtims[j];
> + evtims[j] = tmp;
> +}
> +
> +static __rte_always_inline int
> +__sw_event_timer_arm_burst(const struct rte_event_timer_adapter *adapter,
> + struct rte_event_timer **evtims,
> + uint16_t nb_evtims)
> +{
> + int i, n, mark, nb_fails = 0;
> + int fails[nb_evtims];
> + struct rte_event_timer_adapter_sw_data *sw_data;
> + struct msg *msgs[nb_evtims];
> + struct rte_timer *tims[nb_evtims];
> +
> + sw_data = adapter->data->adapter_priv;
> +
> + n = rte_mempool_get_bulk(sw_data->msg_pool, (void **)msgs, nb_evtims);
> + if (n < 0) {
> + rte_errno = ENOMEM;
> + return 0;
> + }
> +
> + n = rte_mempool_get_bulk(sw_data->tim_pool, (void **)tims, nb_evtims);
> + if (n < 0) {
> + rte_errno = ENOMEM;
Need to free msg objs that were dequeued prior (Although this has a very low
chance of happening.)
As mentioned before consider having a single pool.
> + return 0;
> + }
> +
> + for (i = 0; i < nb_evtims; i++) {
> + rte_timer_init(tims[i]);
> + evtims[i]->impl_opaque[0] = (uintptr_t)tims[i];
> + evtims[i]->impl_opaque[1] = (uintptr_t)adapter;
> +
> + msgs[i]->evtim = evtims[i];
> + msgs[i]->type = MSG_TYPE_ARM;
> + }
> +
> + n = rte_ring_enqueue_burst(sw_data->msg_ring, (void **)msgs, nb_evtims,
> + NULL);
> + if (n < nb_evtims) {
> + rte_mempool_put_bulk(sw_data->msg_pool, (void **)&msgs[n],
> + nb_evtims - n);
> + rte_mempool_put_bulk(sw_data->tim_pool, (void **)&tims[n],
> + nb_evtims - n);
> + }
> +
> + for (i = 0; i < n; i++) {
> + /* Wait until state is updated */
> + while (evtims[i]->state == RTE_EVENT_TIMER_NOT_ARMED ||
> + evtims[i]->state == RTE_EVENT_TIMER_CANCELED)
> + ;
> +
> + /* Note any failures */
> + if (evtims[i]->state != RTE_EVENT_TIMER_ARMED) {
> + fails[nb_fails++] = i;
> + rte_errno = EINVAL;
> + }
> +
> + /* TODO: handle the case of consecutive arm requests; the
> + * second request can erroneously see success from the first
> + */
> + }
> +
> + /* Move the failures to the end of the array */
> + for (i = 0, mark = n - 1; i < nb_fails; i++, mark--)
> + swap(evtims, fails[i], mark);
> +
> + n = mark + 1;
> +
> + return n;
> +}
> +
> static int
> sw_event_timer_arm_burst(const struct rte_event_timer_adapter *adapter,
> struct rte_event_timer **evtims,
> uint16_t nb_evtims)
> {
> - RTE_SET_USED(adapter);
> - RTE_SET_USED(evtims);
> - RTE_SET_USED(nb_evtims);
> -
> - return 0;
> + return __sw_event_timer_arm_burst(adapter, evtims, nb_evtims);
> }
>
> static int
> @@ -626,25 +701,71 @@ sw_event_timer_cancel_burst(const struct rte_event_timer_adapter *adapter,
> struct rte_event_timer **evtims,
> uint16_t nb_evtims)
> {
> - RTE_SET_USED(adapter);
> - RTE_SET_USED(evtims);
> - RTE_SET_USED(nb_evtims);
> + int i, n, mark, nb_fails = 0;
> + int fails[nb_evtims];
> + struct msg *msg, *msgs[nb_evtims];
> + struct rte_event_timer_adapter_sw_data *sw_data;
>
> - return 0;
> +#ifdef RTE_LIBRTE_EVENTDEV_DEBUG
> + /* TODO: verify that service is running to avoid hanging if in block
> + * mode
> + */
> +#endif
> +
> + sw_data = adapter->data->adapter_priv;
> +
> + n = rte_mempool_get_bulk(sw_data->msg_pool, (void **)msgs, nb_evtims);
> + if (n < 0) {
> + rte_errno = ENOMEM;
> + return 0;
> + }
> +
> + /* Set up the messages */
> + for (i = 0; i < nb_evtims; i++) {
> + msg = msgs[i];
> + msg->type = MSG_TYPE_CANCEL;
> + msg->evtim = evtims[i];
> + }
> +
> + n = rte_ring_enqueue_burst(sw_data->msg_ring, (void **)msgs, nb_evtims,
> + NULL);
> + if (n < nb_evtims)
> + rte_mempool_put_bulk(sw_data->msg_pool, (void **)&msgs[n],
> + nb_evtims - n);
> +
> + for (i = 0; i < n; i++) {
> + /* Wait until state is updated */
> + while (evtims[i]->state == RTE_EVENT_TIMER_ARMED)
> + ;
> +
> + /* Note any failures */
> + if (evtims[i]->state != RTE_EVENT_TIMER_CANCELED) {
> + fails[nb_fails++] = i;
> + rte_errno = EINVAL;
> + }
> + }
> +
> + /* Move the failures to the end of the array */
> + for (i = 0, mark = n - 1; i < nb_fails; i++, mark--)
> + swap(evtims, fails[i], mark);
> +
> + n = mark + 1;
> +
> + return n;
> }
>
> static int
> sw_event_timer_arm_tmo_tick_burst(const struct rte_event_timer_adapter *adapter,
> - struct rte_event_timer **tims,
> - uint64_t timeout_tick,
> - uint16_t nb_tims)
> + struct rte_event_timer **evtims,
> + uint64_t timeout_ticks,
> + uint16_t nb_evtims)
> {
> - RTE_SET_USED(adapter);
> - RTE_SET_USED(tims);
> - RTE_SET_USED(timeout_tick);
> - RTE_SET_USED(nb_tims);
> + int i;
>
> - return 0;
> + for (i = 0; i < nb_evtims; i++)
> + evtims[i]->timeout_ticks = timeout_ticks;
> +
> + return __sw_event_timer_arm_burst(adapter, evtims, nb_evtims);
> }
>
> const struct rte_event_timer_adapter_ops sw_event_adapter_timer_ops = {
> diff --git a/mk/rte.app.mk b/mk/rte.app.mk
> index 6a6a745..3dd95f5 100644
> --- a/mk/rte.app.mk
> +++ b/mk/rte.app.mk
> @@ -80,7 +80,6 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_BITRATE) += -lrte_bitratestats
> _LDLIBS-$(CONFIG_RTE_LIBRTE_LATENCY_STATS) += -lrte_latencystats
> _LDLIBS-$(CONFIG_RTE_LIBRTE_POWER) += -lrte_power
>
> -_LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER) += -lrte_timer
> _LDLIBS-$(CONFIG_RTE_LIBRTE_EFD) += -lrte_efd
>
> _LDLIBS-y += --whole-archive
> @@ -96,6 +95,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_ETHER) += -lrte_ethdev
> _LDLIBS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += -lrte_cryptodev
> _LDLIBS-$(CONFIG_RTE_LIBRTE_SECURITY) += -lrte_security
> _LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV) += -lrte_eventdev
> +_LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER) += -lrte_timer
> _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += -lrte_mempool
> _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING) += -lrte_mempool_ring
> _LDLIBS-$(CONFIG_RTE_LIBRTE_RING) += -lrte_ring
> --
> 2.6.4
>
More information about the dev
mailing list