DPDK patches and discussions
 help / color / mirror / Atom feed
From: Moti Haimovsky <motih@mellanox.com>
To: gaetan.rivet@6wind.com, ferruh.yigit@intel.com
Cc: dev@dpdk.org, Moti Haimovsky <motih@mellanox.com>
Subject: [dpdk-dev] [PATCH v8 3/3] net/failsafe: add Rx interrupts
Date: Thu, 25 Jan 2018 18:19:32 +0200	[thread overview]
Message-ID: <1516897172-81448-4-git-send-email-motih@mellanox.com> (raw)
In-Reply-To: <1516897172-81448-1-git-send-email-motih@mellanox.com>

This patch is the last patch in the series of patches aimed
to add support for registering and waiting for Rx interrupts
in failsafe PMD. This allows applications to wait for Rx events
from the PMD using the DPDK rte_epoll subsystem.
The failsafe PMD presents to the application a facade of a single
device to be handled by the application while internally it manages
several devices on behalf of the application including packets
transmission and reception.
The Proposed failsafe Rx interrupt scheme follows this approach.
The failsafe PMD will present the application with a single set of
Rx interrupt vectors representing the failsafe Rx queues, while
internally it will serve as an interrupt proxy for its subdevices.
will allow applications to wait for Rx traffic from the failsafe
PMD by registering and waiting for Rx events from its Rx queues.
In order to support this the following is suggested:
  * Every Rx queue in the failsafe (virtual) device will be assigned
  * a Linux event file descriptor (efd) and an enable_interrupts flag.
  * The failsafe PMD will fill in its rte_intr_handle structure with
    the Rx efds assigned previously and register them with the EAL.
  * The failsafe driver will create a private epoll fd (epfd) and
  * will allocate enough space to handle all the Rx events from all its
    subdevices.
  * Acting as an application,
    for each Rx queue in each active subdevice the failsafe will:
      o Register the Rx queue with the EAL.
      o Pass the EAL the failsafe private epoll fd as the epfd to
        register the Rx queue event on.
      o Pass the EAL, as a parameter, the pointer to the failsafe Rx
        queue that handles this Rx queue.
      o Using the DPDK service callbacks, the failsafe PMD will launch
        an Rx proxy service that will Wait on the epoll fd for Rx
        events from the sub-devices.
      o For each Rx event received the proxy service will
          - Retrieve the pointer to failsafe Rx queue that handles
            this subdevice Rx queue from the user info returned by the
            EAL.
          - Trigger a failsafe Rx event on that queue by writing to
            the event fd unless interrupts are disabled for that queue.
  * The failsafe pmd will also implement the rx_queue_intr_enable
  * and rx_queue_intr_disable routines that will enable and disable Rx
    interrupts respectively on both on the failsafe and its subdevices.

Signed-off-by: Moti Haimovsky <motih@mellanox.com>
---
V8:
Modifications according to inputs from Ferruh Yigit
in reply to
1516867635-67104-4-git-send-email-motih@mellanox.com

V6:
Separated between routines' variables definition and initialization
according to guidelines from Gaetan Rivet.

V5:
Modified code and split the patch into three patches in accordance to
inputs from Gaetan Rivet in reply to
1516354344-13495-2-git-send-email-motih@mellanox.com

V4:
Fixed merge conflicts found during integration with other failsafe patches
(See cover letter).

V3:
Fixed build failures in FreeBSD10.3_64

V2:
Modifications according to inputs from Stephen Hemminger:
* Removed unneeded (void *) casting.
Fixed coding style warning.
---
 doc/guides/nics/features/failsafe.ini   |   1 +
 drivers/net/failsafe/failsafe_intr.c    | 168 ++++++++++++++++++++++++++++++++
 drivers/net/failsafe/failsafe_ops.c     |   6 ++
 drivers/net/failsafe/failsafe_private.h |  17 +++-
 4 files changed, 191 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/failsafe.ini b/doc/guides/nics/features/failsafe.ini
index a42e344..39ee579 100644
--- a/doc/guides/nics/features/failsafe.ini
+++ b/doc/guides/nics/features/failsafe.ini
@@ -6,6 +6,7 @@
 [Features]
 Link status          = Y
 Link status event    = Y
+Rx interrupt         = Y
 MTU update           = Y
 Jumbo frame          = Y
 Promiscuous mode     = Y
diff --git a/drivers/net/failsafe/failsafe_intr.c b/drivers/net/failsafe/failsafe_intr.c
index b0eacdc..f6ff04d 100644
--- a/drivers/net/failsafe/failsafe_intr.c
+++ b/drivers/net/failsafe/failsafe_intr.c
@@ -12,6 +12,14 @@
 #endif
 #include <unistd.h>
 
+#include <rte_alarm.h>
+#include <rte_config.h>
+#include <rte_errno.h>
+#include <rte_ethdev.h>
+#include <rte_interrupts.h>
+#include <rte_io.h>
+#include <rte_service_component.h>
+
 #include "failsafe_private.h"
 
 #define NUM_RX_PROXIES (FAILSAFE_MAX_ETHPORTS * RTE_MAX_RXTX_INTR_VEC_ID)
@@ -37,6 +45,162 @@
 }
 
 /**
+ * Install failsafe Rx event proxy service.
+ * The Rx event proxy is the service that listens to Rx events from the
+ * subdevices and triggers failsafe Rx events accordingly.
+ *
+ * @param priv
+ *   Pointer to failsafe private structure.
+ * @return
+ *   0 on success, negative errno value otherwise.
+ */
+static int
+fs_rx_event_proxy_routine(void *data)
+{
+	struct fs_priv *priv;
+	struct rxq *rxq;
+	struct rte_epoll_event *events;
+	uint64_t u64;
+	int i, n;
+	int rc = 0;
+
+	u64 = 1;
+	priv = data;
+	events = priv->rxp.evec;
+	n = rte_epoll_wait(priv->rxp.efd, events, NUM_RX_PROXIES, -1);
+	for (i = 0; i < n; i++) {
+		rxq = events[i].epdata.data;
+		if (rxq->enable_events && rxq->event_fd != -1) {
+			if (write(rxq->event_fd, &u64, sizeof(u64)) !=
+			    sizeof(u64)) {
+				ERROR("Failed to proxy Rx event to socket %d",
+				       rxq->event_fd);
+				rc = -EIO;
+			}
+		}
+	}
+	return rc;
+}
+
+/**
+ * Uninstall failsafe Rx event proxy service.
+ *
+ * @param priv
+ *   Pointer to failsafe private structure.
+ */
+static void
+fs_rx_event_proxy_service_uninstall(struct fs_priv *priv)
+{
+	/* Unregister the event service. */
+	switch (priv->rxp.sstate) {
+	case SS_RUNNING:
+		rte_service_map_lcore_set(priv->rxp.sid, priv->rxp.scid, 0);
+		/* fall through */
+	case SS_READY:
+		rte_service_runstate_set(priv->rxp.sid, 0);
+		rte_service_set_stats_enable(priv->rxp.sid, 0);
+		rte_service_component_runstate_set(priv->rxp.sid, 0);
+		/* fall through */
+	case SS_REGISTERED:
+		rte_service_component_unregister(priv->rxp.sid);
+		/* fall through */
+	default:
+		break;
+	}
+}
+
+/**
+ * Install the failsafe Rx event proxy service.
+ *
+ * @param priv
+ *   Pointer to failsafe private structure.
+ * @return
+ *   0 on success, negative errno value otherwise.
+ */
+static int
+fs_rx_event_proxy_service_install(struct fs_priv *priv)
+{
+	struct rte_service_spec service;
+	int32_t num_service_cores;
+	int ret = 0;
+
+	num_service_cores = rte_service_lcore_count();
+	if (num_service_cores <= 0) {
+		ERROR("Failed to install Rx interrupts, "
+		      "no service core found");
+		return -ENOTSUP;
+	}
+	/* prepare service info */
+	memset(&service, 0, sizeof(struct rte_service_spec));
+	snprintf(service.name, sizeof(service.name), "%s_Rx_service",
+		 priv->dev->data->name);
+	service.socket_id = priv->dev->data->numa_node;
+	service.callback = fs_rx_event_proxy_routine;
+	service.callback_userdata = priv;
+
+	if (priv->rxp.sstate == SS_NO_SERVICE) {
+		uint32_t service_core_list[num_service_cores];
+
+		/* get a service core to work with */
+		ret = rte_service_lcore_list(service_core_list,
+					     num_service_cores);
+		if (ret <= 0) {
+			ERROR("Failed to install Rx interrupts, "
+			      "service core list empty or corrupted");
+			return -ENOTSUP;
+		}
+		priv->rxp.scid = service_core_list[0];
+		ret = rte_service_lcore_add(priv->rxp.scid);
+		if (ret && ret != -EALREADY) {
+			ERROR("Failed adding service core");
+			return ret;
+		}
+		/* service core may be in "stopped" state, start it */
+		ret = rte_service_lcore_start(priv->rxp.scid);
+		if (ret && (ret != -EALREADY)) {
+			ERROR("Failed to install Rx interrupts, "
+			      "service core not started");
+			return ret;
+		}
+		/* register our service */
+		int32_t ret = rte_service_component_register(&service,
+							     &priv->rxp.sid);
+		if (ret) {
+			ERROR("service register() failed");
+			return -ENOEXEC;
+		}
+		priv->rxp.sstate = SS_REGISTERED;
+		/* run the service */
+		ret = rte_service_component_runstate_set(priv->rxp.sid, 1);
+		if (ret < 0) {
+			ERROR("Failed Setting component runstate\n");
+			return ret;
+		}
+		ret = rte_service_set_stats_enable(priv->rxp.sid, 1);
+		if (ret < 0) {
+			ERROR("Failed enabling stats\n");
+			return ret;
+		}
+		ret = rte_service_runstate_set(priv->rxp.sid, 1);
+		if (ret < 0) {
+			ERROR("Failed to run service\n");
+			return ret;
+		}
+		priv->rxp.sstate = SS_READY;
+		/* map the service with the service core */
+		ret = rte_service_map_lcore_set(priv->rxp.sid,
+						priv->rxp.scid, 1);
+		if (ret) {
+			ERROR("Failed to install Rx interrupts, "
+			      "could not map service core");
+			return ret;
+		}
+		priv->rxp.sstate = SS_RUNNING;
+	}
+	return 0;
+}
+
+/**
  * Install failsafe Rx event proxy subsystem.
  * This is the way the failsafe PMD generates Rx events on behalf of its
  * subdevices.
@@ -69,6 +233,9 @@
 		rc = -ENOMEM;
 		goto error;
 	}
+	rc = fs_rx_event_proxy_service_install(priv);
+	if (rc < 0)
+		goto error;
 	return 0;
 error:
 	if (priv->rxp.efd >= 0) {
@@ -222,6 +389,7 @@ void failsafe_rx_intr_uninstall_subdevice(struct sub_device *sdev)
 static void
 fs_rx_event_proxy_uninstall(struct fs_priv *priv)
 {
+	fs_rx_event_proxy_service_uninstall(priv);
 	if (priv->rxp.evec != NULL) {
 		free(priv->rxp.evec);
 		priv->rxp.evec = NULL;
diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c
index 249baea..eb781ef 100644
--- a/drivers/net/failsafe/failsafe_ops.c
+++ b/drivers/net/failsafe/failsafe_ops.c
@@ -434,6 +434,12 @@
 		rte_errno = EINVAL;
 		return -rte_errno;
 	}
+	/* Fail if proxy service is nor running. */
+	if (PRIV(dev)->rxp.sstate != SS_RUNNING) {
+		ERROR("failsafe interrupt services are not running");
+		rte_errno = EAGAIN;
+		return -rte_errno;
+	}
 	rxq->enable_events = 1;
 	FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
 		ret = rte_eth_dev_rx_intr_enable(PORT_ID(sdev), idx);
diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h
index ff78b9f..5d328ff 100644
--- a/drivers/net/failsafe/failsafe_private.h
+++ b/drivers/net/failsafe/failsafe_private.h
@@ -61,6 +61,13 @@
 
 #define DEVARGS_MAXLEN 4096
 
+enum rxp_service_state {
+	SS_NO_SERVICE = 0,
+	SS_REGISTERED,
+	SS_READY,
+	SS_RUNNING,
+};
+
 /* TYPES */
 
 struct rx_proxy {
@@ -68,6 +75,11 @@ struct rx_proxy {
 	int efd;
 	/* event vector to be used by epoll */
 	struct rte_epoll_event *evec;
+	/* rte service id */
+	uint32_t sid;
+	/* service core id */
+	uint32_t scid;
+	enum rxp_service_state sstate;
 };
 
 struct rxq {
@@ -169,7 +181,10 @@ struct fs_priv {
 	 * Rx interrupts/events proxy.
 	 * The PMD issues Rx events to the EAL on behalf of its subdevices,
 	 * it does that by registering an event-fd for each of its queues with
-	 * the EAL.
+	 * the EAL. A PMD service thread listens to all the Rx events from the
+	 * subdevices, when an Rx event is issued by a subdevice it will be
+	 * caught by this service with will trigger an Rx event in the
+	 * appropriate failsafe Rx queue.
 	 */
 	struct rx_proxy rxp;
 	unsigned int pending_alarm:1; /* An alarm is pending */
-- 
1.8.3.1

  parent reply	other threads:[~2018-01-25 16:20 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-11 12:41 [dpdk-dev] [PATCH] " Moti Haimovsky
2017-12-12  1:34 ` Stephen Hemminger
2017-12-13 13:12   ` Mordechay Haimovsky
2018-01-04 15:01 ` [dpdk-dev] [PATCH v2] " Moti Haimovsky
2018-01-17 12:54   ` [dpdk-dev] [PATCH V3] " Moti Haimovsky
2018-01-19  9:32     ` [dpdk-dev] [PATCH v4] " Moti Haimovsky
2018-01-19  9:32       ` Moti Haimovsky
2018-01-19 14:11         ` Gaëtan Rivet
2018-01-23 18:43         ` [dpdk-dev] [PATCH v5 0/3] net/failsafe: add Rx interrupts support Moti Haimovsky
2018-01-23 18:43           ` [dpdk-dev] [PATCH v5 1/3] net/failsafe: regiter as an Rx interrupt mode PMD Moti Haimovsky
2018-01-23 18:43           ` [dpdk-dev] [PATCH v5 2/3] net/failsafe: slaves Rx interrupts registration Moti Haimovsky
2018-01-24 16:12             ` [dpdk-dev] [PATCH v6 0/3] net/failsafe: add Rx interrupts support Moti Haimovsky
2018-01-24 16:12               ` [dpdk-dev] [PATCH v6 1/3] net/failsafe: register as an Rx interrupt mode PMD Moti Haimovsky
2018-01-24 16:12               ` [dpdk-dev] [PATCH v6 2/3] net/failsafe: slaves Rx interrupts registration Moti Haimovsky
2018-01-25  8:07                 ` [dpdk-dev] [PATCH v7 0/3] net/failsafe: add Rx interrupts support Moti Haimovsky
2018-01-25  8:07                   ` [dpdk-dev] [PATCH v7 1/3] net/failsafe: register as an Rx interrupt mode PMD Moti Haimovsky
2018-01-25 11:36                     ` Gaëtan Rivet
2018-01-25  8:07                   ` [dpdk-dev] [PATCH v7 2/3] net/failsafe: slaves Rx interrupts registration Moti Haimovsky
2018-01-25 11:49                     ` Gaëtan Rivet
2018-01-25  8:07                   ` [dpdk-dev] [PATCH v7 3/3] net/failsafe: add Rx interrupts Moti Haimovsky
2018-01-25 11:58                     ` Gaëtan Rivet
2018-01-25 16:19                     ` [dpdk-dev] [PATCH v8 0/3] net/failsafe: add Rx interrupts support Moti Haimovsky
2018-01-25 16:19                       ` [dpdk-dev] [PATCH v8 1/3] net/failsafe: register as an Rx interrupt mode PMD Moti Haimovsky
2018-01-25 16:19                       ` [dpdk-dev] [PATCH v8 2/3] net/failsafe: slaves Rx interrupts registration Moti Haimovsky
2018-01-25 16:19                       ` Moti Haimovsky [this message]
2018-01-25 16:53                       ` [dpdk-dev] [PATCH v8 0/3] net/failsafe: add Rx interrupts support Gaëtan Rivet
2018-01-26 18:22                         ` Ferruh Yigit
2018-01-24 16:12               ` [dpdk-dev] [PATCH v6 3/3] net/failsafe: add Rx interrupts Moti Haimovsky
2018-01-23 18:43           ` [dpdk-dev] [PATCH v5 " Moti Haimovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1516897172-81448-4-git-send-email-motih@mellanox.com \
    --to=motih@mellanox.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=gaetan.rivet@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).