DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eventdev: add dev id checks to config functions
@ 2017-07-24 12:48 Harry van Haaren
  2017-09-04  5:20 ` Jerin Jacob
  2017-09-08 15:18 ` [dpdk-dev] [PATCH v2 0/3] eventdev: add attribute based get APIs Harry van Haaren
  0 siblings, 2 replies; 35+ messages in thread
From: Harry van Haaren @ 2017-07-24 12:48 UTC (permalink / raw)
  To: dev; +Cc: jerin.jacob, Harry van Haaren

This commit adds checks to verify the device ID is valid
to the following functions. Given that they are non-datapath,
these checks are always performed.

This commit also updates the event/octeontx test-cases to
have the correct signed-ness, as the API has changes this
change is required in order to compile.

Suggested-by: Jesse Bruni <jesse.bruni@intel.com>
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---
 lib/librte_eventdev/rte_eventdev.c | 36 +++++++++++++++++++++++++-----------
 lib/librte_eventdev/rte_eventdev.h | 36 ++++++++++++++++++------------------
 test/test/test_eventdev_octeontx.c | 32 +++++++++++++++++++-------------
 3 files changed, 62 insertions(+), 42 deletions(-)

diff --git a/lib/librte_eventdev/rte_eventdev.c b/lib/librte_eventdev/rte_eventdev.c
index bbb3805..e71f20c 100644
--- a/lib/librte_eventdev/rte_eventdev.c
+++ b/lib/librte_eventdev/rte_eventdev.c
@@ -609,21 +609,26 @@ rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
 	return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf);
 }
 
-uint8_t
+int16_t
 rte_event_queue_count(uint8_t dev_id)
 {
 	struct rte_eventdev *dev;
+	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
 	dev = &rte_eventdevs[dev_id];
 	return dev->data->nb_queues;
 }
 
-uint8_t
+int16_t
 rte_event_queue_priority(uint8_t dev_id, uint8_t queue_id)
 {
-	struct rte_eventdev *dev;
+	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
+	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
+	if (!is_valid_queue(dev, queue_id)) {
+		RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
+		return -EINVAL;
+	}
 
-	dev = &rte_eventdevs[dev_id];
 	if (dev->data->event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
 		return dev->data->queues_prio[queue_id];
 	else
@@ -743,28 +748,37 @@ rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
 	return 0;
 }
 
-uint8_t
+int16_t
 rte_event_port_dequeue_depth(uint8_t dev_id, uint8_t port_id)
 {
-	struct rte_eventdev *dev;
+	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
+	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
+	if (!is_valid_port(dev, port_id)) {
+		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
+		return -EINVAL;
+	}
 
-	dev = &rte_eventdevs[dev_id];
 	return dev->data->ports_dequeue_depth[port_id];
 }
 
-uint8_t
+int16_t
 rte_event_port_enqueue_depth(uint8_t dev_id, uint8_t port_id)
 {
-	struct rte_eventdev *dev;
+	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
+	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
+	if (!is_valid_port(dev, port_id)) {
+		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
+		return -EINVAL;
+	}
 
-	dev = &rte_eventdevs[dev_id];
 	return dev->data->ports_enqueue_depth[port_id];
 }
 
-uint8_t
+int16_t
 rte_event_port_count(uint8_t dev_id)
 {
 	struct rte_eventdev *dev;
+	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
 
 	dev = &rte_eventdevs[dev_id];
 	return dev->data->nb_ports;
diff --git a/lib/librte_eventdev/rte_eventdev.h b/lib/librte_eventdev/rte_eventdev.h
index 128bc52..204ff82 100644
--- a/lib/librte_eventdev/rte_eventdev.h
+++ b/lib/librte_eventdev/rte_eventdev.h
@@ -611,10 +611,10 @@ rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
  *
  * @param dev_id
  *   Event device identifier.
- * @return
- *   - The number of configured event queues
+ * @retval Positive The number of configured event queues
+ * @retval -EINVAL Invalid device id
  */
-uint8_t
+int16_t
 rte_event_queue_count(uint8_t dev_id);
 
 /**
@@ -624,13 +624,13 @@ rte_event_queue_count(uint8_t dev_id);
  *   Event device identifier.
  * @param queue_id
  *   Event queue identifier.
- * @return
- *   - If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then the
- *    configured priority of the event queue in
- *    [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST] range
- *    else the value RTE_EVENT_DEV_PRIORITY_NORMAL
+ * @retval Positive If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
+ *         then the configured priority of the event queue in
+ *         [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST]
+ *         range else the value RTE_EVENT_DEV_PRIORITY_NORMAL
+ * @retval -EINVAL Invalid device id or queue id
  */
-uint8_t
+int16_t
 rte_event_queue_priority(uint8_t dev_id, uint8_t queue_id);
 
 /* Event port specific APIs */
@@ -722,12 +722,12 @@ rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
  *   Event device identifier.
  * @param port_id
  *   Event port identifier.
- * @return
- *   - The number of configured dequeue queue depth
+ * @retval Positive The dequeue queue depth
+ * @retval -EINVAL Invalid device ID or port ID
  *
  * @see rte_event_dequeue_burst()
  */
-uint8_t
+int16_t
 rte_event_port_dequeue_depth(uint8_t dev_id, uint8_t port_id);
 
 /**
@@ -738,12 +738,12 @@ rte_event_port_dequeue_depth(uint8_t dev_id, uint8_t port_id);
  *   Event device identifier.
  * @param port_id
  *   Event port identifier.
- * @return
- *   - The number of configured enqueue queue depth
+ * @retval Positive The enqueue queue depth
+ * @retval -EINVAL Invalid device ID or port ID
  *
  * @see rte_event_enqueue_burst()
  */
-uint8_t
+int16_t
 rte_event_port_enqueue_depth(uint8_t dev_id, uint8_t port_id);
 
 /**
@@ -751,10 +751,10 @@ rte_event_port_enqueue_depth(uint8_t dev_id, uint8_t port_id);
  *
  * @param dev_id
  *   Event device identifier.
- * @return
- *   - The number of configured ports
+ * @retval Positive The number of configured ports
+ * @retval -EINVAL Invalid device id
  */
-uint8_t
+int16_t
 rte_event_port_count(uint8_t dev_id);
 
 /**
diff --git a/test/test/test_eventdev_octeontx.c b/test/test/test_eventdev_octeontx.c
index 774d030..6794f1f 100644
--- a/test/test/test_eventdev_octeontx.c
+++ b/test/test/test_eventdev_octeontx.c
@@ -591,7 +591,7 @@ wait_workers_to_join(int lcore, const rte_atomic32_t *count)
 static inline int
 launch_workers_and_wait(int (*master_worker)(void *),
 			int (*slave_workers)(void *), uint32_t total_events,
-			uint8_t nb_workers, uint8_t sched_type)
+			int16_t nb_workers, uint8_t sched_type)
 {
 	uint8_t port = 0;
 	int w_lcore;
@@ -651,14 +651,15 @@ static int
 test_multi_queue_enq_multi_port_deq(void)
 {
 	const unsigned int total_events = MAX_EVENTS;
-	uint8_t nr_ports;
+	int16_t nr_ports;
 	int ret;
 
 	ret = generate_random_events(total_events);
 	if (ret)
 		return TEST_FAILED;
 
-	nr_ports = RTE_MIN(rte_event_port_count(evdev), rte_lcore_count() - 1);
+	nr_ports = RTE_MIN(rte_event_port_count(evdev),
+			(int)rte_lcore_count() - 1);
 
 	if (!nr_ports) {
 		printf("%s: Not enough ports=%d or workers=%d\n", __func__,
@@ -698,7 +699,7 @@ test_queue_to_port_single_link(void)
 	}
 
 	nr_links = RTE_MIN(rte_event_port_count(evdev),
-				rte_event_queue_count(evdev));
+				(int)rte_event_queue_count(evdev));
 	const unsigned int total_events = MAX_EVENTS / nr_links;
 
 	/* Link queue x to port x and inject events to queue x through port x */
@@ -750,7 +751,8 @@ static int
 test_queue_to_port_multi_link(void)
 {
 	int ret, port0_events = 0, port1_events = 0;
-	uint8_t nr_queues, nr_ports, queue, port;
+	int16_t nr_queues, nr_ports, port;
+	uint8_t queue;
 
 	nr_queues = rte_event_queue_count(evdev);
 	nr_ports = rte_event_port_count(evdev);
@@ -854,10 +856,11 @@ test_multiport_flow_sched_type_test(uint8_t in_sched_type,
 			uint8_t out_sched_type)
 {
 	const unsigned int total_events = MAX_EVENTS;
-	uint8_t nr_ports;
+	int16_t nr_ports;
 	int ret;
 
-	nr_ports = RTE_MIN(rte_event_port_count(evdev), rte_lcore_count() - 1);
+	nr_ports = RTE_MIN(rte_event_port_count(evdev),
+			(int)rte_lcore_count() - 1);
 
 	if (!nr_ports) {
 		printf("%s: Not enough ports=%d or workers=%d\n", __func__,
@@ -1007,10 +1010,11 @@ test_multiport_queue_sched_type_test(uint8_t in_sched_type,
 			uint8_t out_sched_type)
 {
 	const unsigned int total_events = MAX_EVENTS;
-	uint8_t nr_ports;
+	int16_t nr_ports;
 	int ret;
 
-	nr_ports = RTE_MIN(rte_event_port_count(evdev), rte_lcore_count() - 1);
+	nr_ports = RTE_MIN(rte_event_port_count(evdev),
+			(int)rte_lcore_count() - 1);
 
 	if (rte_event_queue_count(evdev) < 2 ||  !nr_ports) {
 		printf("%s: Not enough queues=%d ports=%d or workers=%d\n",
@@ -1142,10 +1146,11 @@ worker_flow_based_pipeline_max_stages_rand_sched_type(void *arg)
 static int
 launch_multi_port_max_stages_random_sched_type(int (*fn)(void *))
 {
-	uint8_t nr_ports;
+	int16_t nr_ports;
 	int ret;
 
-	nr_ports = RTE_MIN(rte_event_port_count(evdev), rte_lcore_count() - 1);
+	nr_ports = RTE_MIN(rte_event_port_count(evdev),
+			(int)rte_lcore_count() - 1);
 
 	if (!nr_ports) {
 		printf("%s: Not enough ports=%d or workers=%d\n", __func__,
@@ -1288,9 +1293,10 @@ worker_ordered_flow_producer(void *arg)
 static inline int
 test_producer_consumer_ingress_order_test(int (*fn)(void *))
 {
-	uint8_t nr_ports;
+	int16_t nr_ports;
 
-	nr_ports = RTE_MIN(rte_event_port_count(evdev), rte_lcore_count() - 1);
+	nr_ports = RTE_MIN(rte_event_port_count(evdev),
+			(int)rte_lcore_count() - 1);
 
 	if (rte_lcore_count() < 3 || nr_ports < 2) {
 		printf("### Not enough cores for %s test.\n", __func__);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2017-09-21  9:57 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-24 12:48 [dpdk-dev] [PATCH] eventdev: add dev id checks to config functions Harry van Haaren
2017-09-04  5:20 ` Jerin Jacob
2017-09-06 14:45   ` Van Haaren, Harry
2017-09-06 14:57     ` Jerin Jacob
2017-09-08 15:18 ` [dpdk-dev] [PATCH v2 0/3] eventdev: add attribute based get APIs Harry van Haaren
2017-09-08 15:18   ` [dpdk-dev] [PATCH v2 1/4] eventdev: add port attribute function Harry van Haaren
2017-09-08 15:18   ` [dpdk-dev] [PATCH v2 2/4] eventdev: add dev attribute get function Harry van Haaren
2017-09-08 15:18   ` [dpdk-dev] [PATCH v2 3/4] eventdev: add queue attribute function Harry van Haaren
2017-09-08 15:18   ` [dpdk-dev] [PATCH v2 4/4] eventdev: add device started attribute Harry van Haaren
2017-09-08 15:36   ` [dpdk-dev] [PATCH v3 0/4] eventdev: add attribute based get APIs Harry van Haaren
2017-09-08 15:36     ` [dpdk-dev] [PATCH v3 1/4] eventdev: add port attribute function Harry van Haaren
2017-09-11 16:35       ` Jerin Jacob
2017-09-08 15:36     ` [dpdk-dev] [PATCH v3 2/4] eventdev: add dev attribute get function Harry van Haaren
2017-09-11 16:51       ` Jerin Jacob
2017-09-08 15:36     ` [dpdk-dev] [PATCH v3 3/4] eventdev: add queue attribute function Harry van Haaren
2017-09-11 17:36       ` Jerin Jacob
2017-09-08 15:36     ` [dpdk-dev] [PATCH v3 4/4] eventdev: add device started attribute Harry van Haaren
2017-09-11 17:52       ` Jerin Jacob
2017-09-12  8:07         ` Van Haaren, Harry
2017-09-11 16:16     ` [dpdk-dev] [PATCH v3 0/4] eventdev: add attribute based get APIs Jerin Jacob
2017-09-14 16:08     ` [dpdk-dev] [PATCH v4 " Harry van Haaren
2017-09-14 16:09       ` [dpdk-dev] [PATCH v4 1/4] eventdev: add port attribute function Harry van Haaren
2017-09-14 16:19         ` Van Haaren, Harry
2017-09-14 16:09       ` [dpdk-dev] [PATCH v4 2/4] eventdev: add dev attribute get function Harry van Haaren
2017-09-14 16:09       ` [dpdk-dev] [PATCH v4 3/4] eventdev: add queue attribute function Harry van Haaren
2017-09-14 16:09       ` [dpdk-dev] [PATCH v4 4/4] eventdev: add device started attribute Harry van Haaren
2017-09-15  6:14       ` [dpdk-dev] [PATCH v4 0/4] eventdev: add attribute based get APIs Nipun Gupta
2017-09-21  9:57         ` Jerin Jacob
2017-09-15 12:33       ` Jerin Jacob
2017-09-20 13:35       ` [dpdk-dev] [PATCH v5 0/5] Harry van Haaren
2017-09-20 13:35         ` [dpdk-dev] [PATCH v5 1/5] eventdev: add port attribute function Harry van Haaren
2017-09-20 13:36         ` [dpdk-dev] [PATCH v5 2/5] eventdev: add dev attribute get function Harry van Haaren
2017-09-20 13:36         ` [dpdk-dev] [PATCH v5 3/5] eventdev: add queue attribute function Harry van Haaren
2017-09-20 13:36         ` [dpdk-dev] [PATCH v5 4/5] eventdev: add device started attribute Harry van Haaren
2017-09-20 13:36         ` [dpdk-dev] [PATCH v5 5/5] eventdev: bump library version Harry van Haaren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).