event/sw: add new software-only eventdev driver
authorBruce Richardson <bruce.richardson@intel.com>
Thu, 30 Mar 2017 19:30:31 +0000 (20:30 +0100)
committerJerin Jacob <jerin.jacob@caviumnetworks.com>
Tue, 4 Apr 2017 17:19:51 +0000 (19:19 +0200)
This adds the minimal changes to allow a SW eventdev implementation to
be compiled, linked and created at run time. The eventdev does nothing,
but can be created via vdev on commandline, e.g.

  sudo ./x86_64-native-linuxapp-gcc/app/test --vdev=event_sw0
  ...
  PMD: Creating eventdev sw device event_sw0, numa_node=0, sched_quanta=128
  RTE>>

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
config/common_base
drivers/event/Makefile
drivers/event/sw/Makefile [new file with mode: 0644]
drivers/event/sw/rte_pmd_evdev_sw_version.map [new file with mode: 0644]
drivers/event/sw/sw_evdev.c [new file with mode: 0644]
drivers/event/sw/sw_evdev.h [new file with mode: 0644]
mk/rte.app.mk

index 45c08e1..8b724c6 100644 (file)
@@ -482,6 +482,12 @@ CONFIG_RTE_EVENT_MAX_QUEUES_PER_DEV=64
 CONFIG_RTE_LIBRTE_PMD_SKELETON_EVENTDEV=y
 CONFIG_RTE_LIBRTE_PMD_SKELETON_EVENTDEV_DEBUG=n
 
+#
+# Compile PMD for software event device
+#
+CONFIG_RTE_LIBRTE_PMD_SW_EVENTDEV=y
+CONFIG_RTE_LIBRTE_PMD_SW_EVENTDEV_DEBUG=n
+
 #
 # Compile librte_ring
 #
index f7e24c2..13e977e 100644 (file)
@@ -35,5 +35,7 @@ core-libs := librte_eal librte_eventdev
 
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_SKELETON_EVENTDEV) += skeleton
 DEPDIRS-skeleton = $(core-libs)
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_SW_EVENTDEV) += sw
+DEPDIRS-sw = $(core-libs) librte_kvargs librte_ring
 
 include $(RTE_SDK)/mk/rte.subdir.mk
diff --git a/drivers/event/sw/Makefile b/drivers/event/sw/Makefile
new file mode 100644 (file)
index 0000000..49b013a
--- /dev/null
@@ -0,0 +1,59 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# library name
+LIB = librte_pmd_sw_event.a
+
+# build flags
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+# for older GCC versions, allow us to initialize an event using
+# designated initializers.
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+ifeq ($(shell test $(GCC_VERSION) -le 50 && echo 1), 1)
+CFLAGS += -Wno-missing-field-initializers
+endif
+endif
+
+# library version
+LIBABIVER := 1
+
+# versioning export map
+EXPORT_MAP := rte_pmd_evdev_sw_version.map
+
+# library source files
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_SW_EVENTDEV) += sw_evdev.c
+
+# export include files
+SYMLINK-y-include +=
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/drivers/event/sw/rte_pmd_evdev_sw_version.map b/drivers/event/sw/rte_pmd_evdev_sw_version.map
new file mode 100644 (file)
index 0000000..5352e7e
--- /dev/null
@@ -0,0 +1,3 @@
+DPDK_17.05 {
+       local: *;
+};
diff --git a/drivers/event/sw/sw_evdev.c b/drivers/event/sw/sw_evdev.c
new file mode 100644 (file)
index 0000000..46401f8
--- /dev/null
@@ -0,0 +1,177 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+#include <rte_vdev.h>
+#include <rte_memzone.h>
+#include <rte_kvargs.h>
+#include <rte_ring.h>
+
+#include "sw_evdev.h"
+
+#define EVENTDEV_NAME_SW_PMD event_sw
+#define NUMA_NODE_ARG "numa_node"
+#define SCHED_QUANTA_ARG "sched_quanta"
+#define CREDIT_QUANTA_ARG "credit_quanta"
+
+static int
+assign_numa_node(const char *key __rte_unused, const char *value, void *opaque)
+{
+       int *socket_id = opaque;
+       *socket_id = atoi(value);
+       if (*socket_id >= RTE_MAX_NUMA_NODES)
+               return -1;
+       return 0;
+}
+
+static int
+set_sched_quanta(const char *key __rte_unused, const char *value, void *opaque)
+{
+       int *quanta = opaque;
+       *quanta = atoi(value);
+       if (*quanta < 0 || *quanta >= 4096)
+               return -1;
+       return 0;
+}
+
+static int
+set_credit_quanta(const char *key __rte_unused, const char *value, void *opaque)
+{
+       int *credit = opaque;
+       *credit = atoi(value);
+       if (*credit < 0 || *credit >= 128)
+               return -1;
+       return 0;
+}
+
+static int
+sw_probe(const char *name, const char *params)
+{
+       static const struct rte_eventdev_ops evdev_sw_ops = {
+       };
+
+       static const char *const args[] = {
+               NUMA_NODE_ARG,
+               SCHED_QUANTA_ARG,
+               CREDIT_QUANTA_ARG,
+               NULL
+       };
+       struct rte_eventdev *dev;
+       struct sw_evdev *sw;
+       int socket_id = rte_socket_id();
+       int sched_quanta  = SW_DEFAULT_SCHED_QUANTA;
+       int credit_quanta = SW_DEFAULT_CREDIT_QUANTA;
+
+       if (params != NULL && params[0] != '\0') {
+               struct rte_kvargs *kvlist = rte_kvargs_parse(params, args);
+
+               if (!kvlist) {
+                       SW_LOG_INFO(
+                               "Ignoring unsupported parameters when creating device '%s'\n",
+                               name);
+               } else {
+                       int ret = rte_kvargs_process(kvlist, NUMA_NODE_ARG,
+                                       assign_numa_node, &socket_id);
+                       if (ret != 0) {
+                               SW_LOG_ERR(
+                                       "%s: Error parsing numa node parameter",
+                                       name);
+                               rte_kvargs_free(kvlist);
+                               return ret;
+                       }
+
+                       ret = rte_kvargs_process(kvlist, SCHED_QUANTA_ARG,
+                                       set_sched_quanta, &sched_quanta);
+                       if (ret != 0) {
+                               SW_LOG_ERR(
+                                       "%s: Error parsing sched quanta parameter",
+                                       name);
+                               rte_kvargs_free(kvlist);
+                               return ret;
+                       }
+
+                       ret = rte_kvargs_process(kvlist, CREDIT_QUANTA_ARG,
+                                       set_credit_quanta, &credit_quanta);
+                       if (ret != 0) {
+                               SW_LOG_ERR(
+                                       "%s: Error parsing credit quanta parameter",
+                                       name);
+                               rte_kvargs_free(kvlist);
+                               return ret;
+                       }
+
+                       rte_kvargs_free(kvlist);
+               }
+       }
+
+       SW_LOG_INFO(
+                       "Creating eventdev sw device %s, numa_node=%d, sched_quanta=%d, credit_quanta=%d\n",
+                       name, socket_id, sched_quanta, credit_quanta);
+
+       dev = rte_event_pmd_vdev_init(name,
+                       sizeof(struct sw_evdev), socket_id);
+       if (dev == NULL) {
+               SW_LOG_ERR("eventdev vdev init() failed");
+               return -EFAULT;
+       }
+       dev->dev_ops = &evdev_sw_ops;
+
+       sw = dev->data->dev_private;
+       sw->data = dev->data;
+
+       /* copy values passed from vdev command line to instance */
+       sw->credit_update_quanta = credit_quanta;
+       sw->sched_quanta = sched_quanta;
+
+       return 0;
+}
+
+static int
+sw_remove(const char *name)
+{
+       if (name == NULL)
+               return -EINVAL;
+
+       SW_LOG_INFO("Closing eventdev sw device %s\n", name);
+
+       return rte_event_pmd_vdev_uninit(name);
+}
+
+static struct rte_vdev_driver evdev_sw_pmd_drv = {
+       .probe = sw_probe,
+       .remove = sw_remove
+};
+
+RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_SW_PMD, evdev_sw_pmd_drv);
+RTE_PMD_REGISTER_PARAM_STRING(event_sw, NUMA_NODE_ARG "=<int> "
+               SCHED_QUANTA_ARG "=<int>" CREDIT_QUANTA_ARG "=<int>");
diff --git a/drivers/event/sw/sw_evdev.h b/drivers/event/sw/sw_evdev.h
new file mode 100644 (file)
index 0000000..ab315d4
--- /dev/null
@@ -0,0 +1,148 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SW_EVDEV_H_
+#define _SW_EVDEV_H_
+
+#include <rte_eventdev.h>
+#include <rte_eventdev_pmd.h>
+
+#define SW_DEFAULT_CREDIT_QUANTA 32
+#define SW_DEFAULT_SCHED_QUANTA 128
+#define SW_QID_NUM_FIDS 16384
+#define SW_IQS_MAX 4
+#define SW_Q_PRIORITY_MAX 255
+#define SW_PORTS_MAX 64
+#define MAX_SW_CONS_Q_DEPTH 128
+#define SW_INFLIGHT_EVENTS_TOTAL 4096
+/* allow for lots of over-provisioning */
+#define MAX_SW_PROD_Q_DEPTH 4096
+#define SW_FRAGMENTS_MAX 16
+
+#define EVENTDEV_NAME_SW_PMD event_sw
+#define SW_PMD_NAME RTE_STR(event_sw)
+
+#ifdef RTE_LIBRTE_PMD_EVDEV_SW_DEBUG
+#define SW_LOG_INFO(fmt, args...) \
+       RTE_LOG(INFO, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
+                       SW_PMD_NAME, \
+                       __func__, __LINE__, ## args)
+
+#define SW_LOG_DBG(fmt, args...) \
+       RTE_LOG(DEBUG, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
+                       SW_PMD_NAME, \
+                       __func__, __LINE__, ## args)
+#else
+#define SW_LOG_INFO(fmt, args...)
+#define SW_LOG_DBG(fmt, args...)
+#endif
+
+#define SW_LOG_ERR(fmt, args...) \
+       RTE_LOG(ERR, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
+                       SW_PMD_NAME, \
+                       __func__, __LINE__, ## args)
+
+/* Records basic event stats at a given point. Used in port and qid structs */
+struct sw_point_stats {
+       uint64_t rx_pkts;
+       uint64_t rx_dropped;
+       uint64_t tx_pkts;
+};
+
+/* structure used to track what port a flow (FID) is pinned to */
+struct sw_fid_t {
+       /* which CQ this FID is currently pinned to */
+       int32_t cq;
+       /* number of packets gone to the CQ with this FID */
+       uint32_t pcount;
+};
+
+struct reorder_buffer_entry {
+       uint16_t num_fragments;         /**< Number of packet fragments */
+       uint16_t fragment_index;        /**< Points to the oldest valid frag */
+       uint8_t ready;                  /**< Entry is ready to be reordered */
+       struct rte_event fragments[SW_FRAGMENTS_MAX];
+};
+
+struct sw_qid {
+       /* set when the QID has been initialized */
+       uint8_t initialized;
+       /* The type of this QID */
+       int8_t type;
+       /* Integer ID representing the queue. This is used in history lists,
+        * to identify the stage of processing.
+        */
+       uint32_t id;
+       struct sw_point_stats stats;
+
+       /* Internal priority rings for packets */
+       struct iq_ring *iq[SW_IQS_MAX];
+       uint32_t iq_pkt_mask; /* A mask to indicate packets in an IQ */
+       uint64_t iq_pkt_count[SW_IQS_MAX];
+
+       /* Information on what CQs are polling this IQ */
+       uint32_t cq_num_mapped_cqs;
+       uint32_t cq_next_tx; /* cq to write next (non-atomic) packet */
+       uint32_t cq_map[SW_PORTS_MAX];
+
+       /* Track flow ids for atomic load balancing */
+       struct sw_fid_t fids[SW_QID_NUM_FIDS];
+
+       /* Track packet order for reordering when needed */
+       struct reorder_buffer_entry *reorder_buffer; /*< pkts await reorder */
+       struct rte_ring *reorder_buffer_freelist; /* available reorder slots */
+       uint32_t reorder_buffer_index; /* oldest valid reorder buffer entry */
+       uint32_t window_size;          /* Used to wrap reorder_buffer_index */
+
+       uint8_t priority;
+};
+
+struct sw_evdev {
+       struct rte_eventdev_data *data;
+
+       int32_t sched_quanta;
+       uint32_t credit_update_quanta;
+};
+
+static inline struct sw_evdev *
+sw_pmd_priv(const struct rte_eventdev *eventdev)
+{
+       return eventdev->data->dev_private;
+}
+
+static inline const struct sw_evdev *
+sw_pmd_priv_const(const struct rte_eventdev *eventdev)
+{
+       return eventdev->data->dev_private;
+}
+
+#endif /* _SW_EVDEV_H_ */
index 9c06a8e..4f8f8b9 100644 (file)
@@ -158,6 +158,7 @@ endif # CONFIG_RTE_LIBRTE_CRYPTODEV
 
 ifeq ($(CONFIG_RTE_LIBRTE_EVENTDEV),y)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_SKELETON_EVENTDEV) += -lrte_pmd_skeleton_event
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_SW_EVENTDEV) += -lrte_pmd_sw_event
 endif # CONFIG_RTE_LIBRTE_EVENTDEV
 
 endif # !CONFIG_RTE_BUILD_SHARED_LIBS