102ec2955SJerin Jacob /* 202ec2955SJerin Jacob * BSD LICENSE 302ec2955SJerin Jacob * 43abcd29fSJerin Jacob * Copyright (C) Cavium, Inc 2017. 502ec2955SJerin Jacob * 602ec2955SJerin Jacob * Redistribution and use in source and binary forms, with or without 702ec2955SJerin Jacob * modification, are permitted provided that the following conditions 802ec2955SJerin Jacob * are met: 902ec2955SJerin Jacob * 1002ec2955SJerin Jacob * * Redistributions of source code must retain the above copyright 1102ec2955SJerin Jacob * notice, this list of conditions and the following disclaimer. 1202ec2955SJerin Jacob * * Redistributions in binary form must reproduce the above copyright 1302ec2955SJerin Jacob * notice, this list of conditions and the following disclaimer in 1402ec2955SJerin Jacob * the documentation and/or other materials provided with the 1502ec2955SJerin Jacob * distribution. 163abcd29fSJerin Jacob * * Neither the name of Cavium, Inc nor the names of its 1702ec2955SJerin Jacob * contributors may be used to endorse or promote products derived 1802ec2955SJerin Jacob * from this software without specific prior written permission. 1902ec2955SJerin Jacob * 2002ec2955SJerin Jacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2102ec2955SJerin Jacob * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2202ec2955SJerin Jacob * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2302ec2955SJerin Jacob * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2402ec2955SJerin Jacob * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2502ec2955SJerin Jacob * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2602ec2955SJerin Jacob * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2702ec2955SJerin Jacob * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2802ec2955SJerin Jacob * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2902ec2955SJerin Jacob * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3002ec2955SJerin Jacob * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3102ec2955SJerin Jacob */ 3202ec2955SJerin Jacob 3302ec2955SJerin Jacob #include <stdio.h> 3402ec2955SJerin Jacob #include <unistd.h> 3502ec2955SJerin Jacob 3602ec2955SJerin Jacob #include "test_order_common.h" 3702ec2955SJerin Jacob 3802ec2955SJerin Jacob /* See http://dpdk.org/doc/guides/tools/testeventdev.html for test details */ 3902ec2955SJerin Jacob 404d04346fSJerin Jacob static inline __attribute__((always_inline)) void 414d04346fSJerin Jacob order_queue_process_stage_0(struct rte_event *const ev) 424d04346fSJerin Jacob { 434d04346fSJerin Jacob ev->queue_id = 1; /* q1 atomic queue */ 444d04346fSJerin Jacob ev->op = RTE_EVENT_OP_FORWARD; 454d04346fSJerin Jacob ev->sched_type = RTE_SCHED_TYPE_ATOMIC; 464d04346fSJerin Jacob ev->event_type = RTE_EVENT_TYPE_CPU; 474d04346fSJerin Jacob } 484d04346fSJerin Jacob 494d04346fSJerin Jacob static int 504d04346fSJerin Jacob order_queue_worker(void *arg) 514d04346fSJerin Jacob { 524d04346fSJerin Jacob ORDER_WORKER_INIT; 534d04346fSJerin Jacob struct rte_event ev; 544d04346fSJerin Jacob 554d04346fSJerin Jacob while (t->err == false) { 564d04346fSJerin Jacob uint16_t event = rte_event_dequeue_burst(dev_id, port, 574d04346fSJerin Jacob &ev, 1, 0); 584d04346fSJerin Jacob if (!event) { 594d04346fSJerin Jacob if (rte_atomic64_read(outstand_pkts) <= 0) 604d04346fSJerin Jacob break; 614d04346fSJerin Jacob rte_pause(); 624d04346fSJerin Jacob continue; 634d04346fSJerin Jacob } 644d04346fSJerin Jacob 654d04346fSJerin Jacob if (ev.queue_id == 0) { /* from ordered queue */ 664d04346fSJerin Jacob order_queue_process_stage_0(&ev); 674d04346fSJerin Jacob while (rte_event_enqueue_burst(dev_id, port, &ev, 1) 684d04346fSJerin Jacob != 1) 694d04346fSJerin Jacob rte_pause(); 704d04346fSJerin Jacob } else if (ev.queue_id == 1) { /* from atomic queue */ 714d04346fSJerin Jacob order_process_stage_1(t, &ev, nb_flows, 724d04346fSJerin Jacob expected_flow_seq, outstand_pkts); 734d04346fSJerin Jacob } else { 744d04346fSJerin Jacob order_process_stage_invalid(t, &ev); 754d04346fSJerin Jacob } 764d04346fSJerin Jacob } 774d04346fSJerin Jacob return 0; 784d04346fSJerin Jacob } 794d04346fSJerin Jacob 804d04346fSJerin Jacob static int 814d04346fSJerin Jacob order_queue_worker_burst(void *arg) 824d04346fSJerin Jacob { 834d04346fSJerin Jacob ORDER_WORKER_INIT; 844d04346fSJerin Jacob struct rte_event ev[BURST_SIZE]; 854d04346fSJerin Jacob uint16_t i; 864d04346fSJerin Jacob 874d04346fSJerin Jacob while (t->err == false) { 884d04346fSJerin Jacob uint16_t const nb_rx = rte_event_dequeue_burst(dev_id, port, ev, 894d04346fSJerin Jacob BURST_SIZE, 0); 904d04346fSJerin Jacob 914d04346fSJerin Jacob if (nb_rx == 0) { 924d04346fSJerin Jacob if (rte_atomic64_read(outstand_pkts) <= 0) 934d04346fSJerin Jacob break; 944d04346fSJerin Jacob rte_pause(); 954d04346fSJerin Jacob continue; 964d04346fSJerin Jacob } 974d04346fSJerin Jacob 984d04346fSJerin Jacob for (i = 0; i < nb_rx; i++) { 994d04346fSJerin Jacob if (ev[i].queue_id == 0) { /* from ordered queue */ 1004d04346fSJerin Jacob order_queue_process_stage_0(&ev[i]); 1014d04346fSJerin Jacob } else if (ev[i].queue_id == 1) {/* from atomic queue */ 1024d04346fSJerin Jacob order_process_stage_1(t, &ev[i], nb_flows, 1034d04346fSJerin Jacob expected_flow_seq, outstand_pkts); 1044d04346fSJerin Jacob ev[i].op = RTE_EVENT_OP_RELEASE; 1054d04346fSJerin Jacob } else { 1064d04346fSJerin Jacob order_process_stage_invalid(t, &ev[i]); 1074d04346fSJerin Jacob } 1084d04346fSJerin Jacob } 1094d04346fSJerin Jacob 1104d04346fSJerin Jacob uint16_t enq; 1114d04346fSJerin Jacob 1124d04346fSJerin Jacob enq = rte_event_enqueue_burst(dev_id, port, ev, nb_rx); 1134d04346fSJerin Jacob while (enq < nb_rx) { 1144d04346fSJerin Jacob enq += rte_event_enqueue_burst(dev_id, port, 1154d04346fSJerin Jacob ev + enq, nb_rx - enq); 1164d04346fSJerin Jacob } 1174d04346fSJerin Jacob } 1184d04346fSJerin Jacob return 0; 1194d04346fSJerin Jacob } 1204d04346fSJerin Jacob 1214d04346fSJerin Jacob static int 1224d04346fSJerin Jacob worker_wrapper(void *arg) 1234d04346fSJerin Jacob { 1244d04346fSJerin Jacob struct worker_data *w = arg; 1254d04346fSJerin Jacob const bool burst = evt_has_burst_mode(w->dev_id); 1264d04346fSJerin Jacob 1274d04346fSJerin Jacob if (burst) 1284d04346fSJerin Jacob return order_queue_worker_burst(arg); 1294d04346fSJerin Jacob else 1304d04346fSJerin Jacob return order_queue_worker(arg); 1314d04346fSJerin Jacob } 1324d04346fSJerin Jacob 1334d04346fSJerin Jacob static int 1344d04346fSJerin Jacob order_queue_launch_lcores(struct evt_test *test, struct evt_options *opt) 1354d04346fSJerin Jacob { 1364d04346fSJerin Jacob return order_launch_lcores(test, opt, worker_wrapper); 1374d04346fSJerin Jacob } 1384d04346fSJerin Jacob 13902ec2955SJerin Jacob #define NB_QUEUES 2 14002ec2955SJerin Jacob static int 14102ec2955SJerin Jacob order_queue_eventdev_setup(struct evt_test *test, struct evt_options *opt) 14202ec2955SJerin Jacob { 14302ec2955SJerin Jacob int ret; 14402ec2955SJerin Jacob 14502ec2955SJerin Jacob const uint8_t nb_workers = evt_nr_active_lcores(opt->wlcores); 14602ec2955SJerin Jacob /* number of active worker cores + 1 producer */ 14702ec2955SJerin Jacob const uint8_t nb_ports = nb_workers + 1; 14802ec2955SJerin Jacob 14902ec2955SJerin Jacob const struct rte_event_dev_config config = { 15002ec2955SJerin Jacob .nb_event_queues = NB_QUEUES,/* q0 ordered, q1 atomic */ 15102ec2955SJerin Jacob .nb_event_ports = nb_ports, 15202ec2955SJerin Jacob .nb_events_limit = 4096, 15302ec2955SJerin Jacob .nb_event_queue_flows = opt->nb_flows, 15402ec2955SJerin Jacob .nb_event_port_dequeue_depth = 128, 15502ec2955SJerin Jacob .nb_event_port_enqueue_depth = 128, 15602ec2955SJerin Jacob }; 15702ec2955SJerin Jacob 15802ec2955SJerin Jacob ret = rte_event_dev_configure(opt->dev_id, &config); 15902ec2955SJerin Jacob if (ret) { 16002ec2955SJerin Jacob evt_err("failed to configure eventdev %d", opt->dev_id); 16102ec2955SJerin Jacob return ret; 16202ec2955SJerin Jacob } 16302ec2955SJerin Jacob 16402ec2955SJerin Jacob /* q0 (ordered queue) configuration */ 16502ec2955SJerin Jacob struct rte_event_queue_conf q0_ordered_conf = { 16602ec2955SJerin Jacob .priority = RTE_EVENT_DEV_PRIORITY_NORMAL, 167*13370a38SPavan Nikhilesh .schedule_type = RTE_SCHED_TYPE_ORDERED, 16802ec2955SJerin Jacob .nb_atomic_flows = opt->nb_flows, 16902ec2955SJerin Jacob .nb_atomic_order_sequences = opt->nb_flows, 17002ec2955SJerin Jacob }; 17102ec2955SJerin Jacob ret = rte_event_queue_setup(opt->dev_id, 0, &q0_ordered_conf); 17202ec2955SJerin Jacob if (ret) { 17302ec2955SJerin Jacob evt_err("failed to setup queue0 eventdev %d", opt->dev_id); 17402ec2955SJerin Jacob return ret; 17502ec2955SJerin Jacob } 17602ec2955SJerin Jacob 17702ec2955SJerin Jacob /* q1 (atomic queue) configuration */ 17802ec2955SJerin Jacob struct rte_event_queue_conf q1_atomic_conf = { 17902ec2955SJerin Jacob .priority = RTE_EVENT_DEV_PRIORITY_NORMAL, 180*13370a38SPavan Nikhilesh .schedule_type = RTE_SCHED_TYPE_ATOMIC, 18102ec2955SJerin Jacob .nb_atomic_flows = opt->nb_flows, 18202ec2955SJerin Jacob .nb_atomic_order_sequences = opt->nb_flows, 18302ec2955SJerin Jacob }; 18402ec2955SJerin Jacob ret = rte_event_queue_setup(opt->dev_id, 1, &q1_atomic_conf); 18502ec2955SJerin Jacob if (ret) { 18602ec2955SJerin Jacob evt_err("failed to setup queue1 eventdev %d", opt->dev_id); 18702ec2955SJerin Jacob return ret; 18802ec2955SJerin Jacob } 18902ec2955SJerin Jacob 19002ec2955SJerin Jacob /* setup one port per worker, linking to all queues */ 19102ec2955SJerin Jacob ret = order_event_dev_port_setup(test, opt, nb_workers, NB_QUEUES); 19202ec2955SJerin Jacob if (ret) 19302ec2955SJerin Jacob return ret; 19402ec2955SJerin Jacob 19502ec2955SJerin Jacob ret = rte_event_dev_start(opt->dev_id); 19602ec2955SJerin Jacob if (ret) { 19702ec2955SJerin Jacob evt_err("failed to start eventdev %d", opt->dev_id); 19802ec2955SJerin Jacob return ret; 19902ec2955SJerin Jacob } 20002ec2955SJerin Jacob 20102ec2955SJerin Jacob return 0; 20202ec2955SJerin Jacob } 20302ec2955SJerin Jacob 20402ec2955SJerin Jacob static void 20502ec2955SJerin Jacob order_queue_opt_dump(struct evt_options *opt) 20602ec2955SJerin Jacob { 20702ec2955SJerin Jacob order_opt_dump(opt); 20802ec2955SJerin Jacob evt_dump("nb_evdev_queues", "%d", NB_QUEUES); 20902ec2955SJerin Jacob } 21002ec2955SJerin Jacob 21102ec2955SJerin Jacob static bool 21202ec2955SJerin Jacob order_queue_capability_check(struct evt_options *opt) 21302ec2955SJerin Jacob { 21402ec2955SJerin Jacob struct rte_event_dev_info dev_info; 21502ec2955SJerin Jacob 21602ec2955SJerin Jacob rte_event_dev_info_get(opt->dev_id, &dev_info); 21702ec2955SJerin Jacob if (dev_info.max_event_queues < NB_QUEUES || dev_info.max_event_ports < 21802ec2955SJerin Jacob order_nb_event_ports(opt)) { 21902ec2955SJerin Jacob evt_err("not enough eventdev queues=%d/%d or ports=%d/%d", 22002ec2955SJerin Jacob NB_QUEUES, dev_info.max_event_queues, 22102ec2955SJerin Jacob order_nb_event_ports(opt), dev_info.max_event_ports); 22202ec2955SJerin Jacob return false; 22302ec2955SJerin Jacob } 22402ec2955SJerin Jacob 22502ec2955SJerin Jacob return true; 22602ec2955SJerin Jacob } 22702ec2955SJerin Jacob 22802ec2955SJerin Jacob static const struct evt_test_ops order_queue = { 22902ec2955SJerin Jacob .cap_check = order_queue_capability_check, 23002ec2955SJerin Jacob .opt_check = order_opt_check, 23102ec2955SJerin Jacob .opt_dump = order_queue_opt_dump, 23202ec2955SJerin Jacob .test_setup = order_test_setup, 23302ec2955SJerin Jacob .mempool_setup = order_mempool_setup, 23402ec2955SJerin Jacob .eventdev_setup = order_queue_eventdev_setup, 2354d04346fSJerin Jacob .launch_lcores = order_queue_launch_lcores, 23602ec2955SJerin Jacob .eventdev_destroy = order_eventdev_destroy, 23702ec2955SJerin Jacob .mempool_destroy = order_mempool_destroy, 23802ec2955SJerin Jacob .test_result = order_test_result, 23902ec2955SJerin Jacob .test_destroy = order_test_destroy, 24002ec2955SJerin Jacob }; 24102ec2955SJerin Jacob 24202ec2955SJerin Jacob EVT_TEST_REGISTER(order_queue); 243