From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gage.eads@intel.com>
Received: from mga07.intel.com (mga07.intel.com [134.134.136.100])
 by dpdk.org (Postfix) with ESMTP id 2D94F69C5
 for <dev@dpdk.org>; Fri, 10 Feb 2017 22:03:00 +0100 (CET)
Received: from fmsmga003.fm.intel.com ([10.253.24.29])
 by orsmga105.jf.intel.com with ESMTP; 10 Feb 2017 13:02:59 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.35,142,1484035200"; d="scan'208";a="819463265"
Received: from txasoft-yocto.an.intel.com (HELO txasoft-yocto.an.intel.com.)
 ([10.123.72.111])
 by FMSMGA003.fm.intel.com with ESMTP; 10 Feb 2017 13:02:58 -0800
From: Gage Eads <gage.eads@intel.com>
To: dev@dpdk.org
Cc: jerin.jacob@caviumnetworks.com, bruce.richardson@intel.com,
 hemant.agrawal@nxp.com, harry.van.haaren@intel.com, nipun.gupta@nxp.com
Date: Fri, 10 Feb 2017 15:02:21 -0600
Message-Id: <1486760541-12568-1-git-send-email-gage.eads@intel.com>
X-Mailer: git-send-email 2.7.4
Subject: [dpdk-dev] [PATCH] eventdev: Add rte_errno return values to the
	enqueue and dequeue functions
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Fri, 10 Feb 2017 21:03:01 -0000

This change allows user software to differentiate between an invalid argument
(such as an invalid queue_id or sched_type in an enqueued event) and
backpressure from the event device.

The port and device ID checks are placed in RTE_LIBRTE_EVENTDEV_DEBUG header
guards to avoid the performance hit in non-debug execution.

Signed-off-by: Gage Eads <gage.eads@intel.com>
---
 lib/librte_eventdev/rte_eventdev.h | 42 +++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eventdev/rte_eventdev.h b/lib/librte_eventdev/rte_eventdev.h
index c2f9310..ef21205 100644
--- a/lib/librte_eventdev/rte_eventdev.h
+++ b/lib/librte_eventdev/rte_eventdev.h
@@ -245,6 +245,7 @@ extern "C" {
 
 #include <rte_common.h>
 #include <rte_memory.h>
+#include <rte_errno.h>
 
 struct rte_mbuf; /* we just use mbuf pointers; no need to include rte_mbuf.h */
 
@@ -1116,9 +1117,14 @@ rte_event_schedule(uint8_t dev_id)
  *   The number of event objects actually enqueued on the event device. The
  *   return value can be less than the value of the *nb_events* parameter when
  *   the event devices queue is full or if invalid parameters are specified in a
- *   *rte_event*. If return value is less than *nb_events*, the remaining events
- *   at the end of ev[] are not consumed,and the caller has to take care of them
- *
+ *   *rte_event*. If the return value is less than *nb_events*, the remaining
+ *   events at the end of ev[] are not consumed and the caller has to take care
+ *   of them, and rte_errno is set accordingly. Possible errno values include:
+ *   -(-EINVAL) The port ID is invalid, device ID is invalid, an event's queue
+ *              ID is invalid, or an event's sched type doesn't match the
+ *              capabilities of the destination queue.
+ *   -(-ENOSPC) The event port was backpressured and unable to enqueue
+ *              one or more events.
  * @see rte_event_port_enqueue_depth()
  */
 static inline uint16_t
@@ -1127,6 +1133,21 @@ rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
 {
 	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
 
+	rte_errno = 0;
+#ifdef RTE_LIBRTE_EVENTDEV_DEBUG
+	if (rte_eventdevs[dev_id].attached == RTE_EVENTDEV_DETACHED) {
+		RTE_EDEV_LOG_DEBUG("Invalid dev_id=%d\n", dev_id);
+		rte_errno = -EINVAL;
+		return 0;
+	}
+
+	if (port_id >= dev->data->nb_ports) {
+		RTE_EDEV_LOG_DEBUG("Invalid port_id=%d\n", port_id);
+		rte_errno = -EINVAL;
+		return 0;
+	}
+#endif
+
 	/*
 	 * Allow zero cost non burst mode routine invocation if application
 	 * requests nb_events as const one
@@ -1235,6 +1256,21 @@ rte_event_dequeue_burst(uint8_t dev_id, uint8_t port_id, struct rte_event ev[],
 {
 	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
 
+#ifdef RTE_LIBRTE_EVENTDEV_DEBUG
+	rte_errno = 0;
+	if (rte_eventdevs[dev_id].attached == RTE_EVENTDEV_DETACHED) {
+		RTE_EDEV_LOG_DEBUG("Invalid dev_id=%d\n", dev_id);
+		rte_errno = -EINVAL;
+		return 0;
+	}
+
+	if (port_id >= dev->data->nb_ports) {
+		RTE_EDEV_LOG_DEBUG("Invalid port_id=%d\n", port_id);
+		rte_errno = -EINVAL;
+		return 0;
+	}
+#endif
+
 	/*
 	 * Allow zero cost non burst mode routine invocation if application
 	 * requests nb_events as const one
-- 
2.7.4