From patchwork Thu Jan 11 00:21:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Carrillo, Erik G" X-Patchwork-Id: 33536 X-Patchwork-Delegate: jerinj@marvell.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C0D451B252; Thu, 11 Jan 2018 01:21:51 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 8F6811B1E0 for ; Thu, 11 Jan 2018 01:21:42 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jan 2018 16:21:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,342,1511856000"; d="scan'208";a="192627459" Received: from txasoft-yocto.an.intel.com (HELO txasoft-yocto.an.intel.com.) ([10.123.72.111]) by orsmga005.jf.intel.com with ESMTP; 10 Jan 2018 16:21:41 -0800 From: Erik Gabriel Carrillo To: pbhagavatula@caviumnetworks.com Cc: dev@dpdk.org, jerin.jacob@caviumnetworks.com, nipun.gupta@nxp.com, hemant.agrawal@nxp.com Date: Wed, 10 Jan 2018 18:21:03 -0600 Message-Id: <1515630074-29020-13-git-send-email-erik.g.carrillo@intel.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1515630074-29020-1-git-send-email-erik.g.carrillo@intel.com> References: <1512158458-22661-1-git-send-email-erik.g.carrillo@intel.com> <1515630074-29020-1-git-send-email-erik.g.carrillo@intel.com> Subject: [dpdk-dev] [PATCH v6 12/23] eventtimer: add event timer arm/cancel function definitions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Signed-off-by: Erik Gabriel Carrillo --- 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; + 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