From patchwork Mon Jul 24 12:48:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 27152 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 [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 3977737B4; Mon, 24 Jul 2017 14:48:45 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 6E78B1F5 for ; Mon, 24 Jul 2017 14:48:43 +0200 (CEST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jul 2017 05:48:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,407,1496127600"; d="scan'208";a="130411325" Received: from silpixa00398672.ir.intel.com ([10.237.223.128]) by fmsmga005.fm.intel.com with ESMTP; 24 Jul 2017 05:48:30 -0700 From: Harry van Haaren To: dev@dpdk.org Cc: jerin.jacob@caviumnetworks.com, Harry van Haaren Date: Mon, 24 Jul 2017 13:48:20 +0100 Message-Id: <1500900500-144237-1-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] eventdev: add dev id checks to config functions 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" 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 Signed-off-by: Harry van Haaren --- 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__);