From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <jianfeng.tan@intel.com>
Received: from mga11.intel.com (mga11.intel.com [192.55.52.93])
 by dpdk.org (Postfix) with ESMTP id 4B55C7CA9
 for <dev@dpdk.org>; Thu, 19 Apr 2018 17:05:29 +0200 (CEST)
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga003.jf.intel.com ([10.7.209.27])
 by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 19 Apr 2018 08:01:45 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.48,469,1517904000"; d="scan'208";a="44534173"
Received: from dpdk06.sh.intel.com ([10.67.110.196])
 by orsmga003.jf.intel.com with ESMTP; 19 Apr 2018 08:01:44 -0700
From: Jianfeng Tan <jianfeng.tan@intel.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, anatoly.burakov@intel.com,
 Jianfeng Tan <jianfeng.tan@intel.com>
Date: Thu, 19 Apr 2018 15:03:36 +0000
Message-Id: <1524150216-3407-9-git-send-email-jianfeng.tan@intel.com>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1524150216-3407-1-git-send-email-jianfeng.tan@intel.com>
References: <1524150216-3407-1-git-send-email-jianfeng.tan@intel.com>
Subject: [dpdk-dev] [RFC 8/8] ipc: remove IPC thread for message read
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 19 Apr 2018 15:05:29 -0000

As discussed here, http://dpdk.org/dev/patchwork/patch/36579/,
we remove IPC thread, rte_mp_handle, in this patch.

Previously, to handle requests from peer(s), or replies for a
request (sync or async) by itself, thread rte_mp_handle will
blockly readmsg on the unix socket for incoming messages.
Now, we change to make use of the IPC event callback mechanism
(added in previous patch); in other words, we merge this into
interrupt thread.

Cc: Anatoly Burakov <anatoly.burakov@intel.com>

Suggested-by: Thomas Monjalon <thomas@monjalon.net>
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 lib/librte_eal/common/eal_common_proc.c | 38 ++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
index 4cb460e..1f102ce 100644
--- a/lib/librte_eal/common/eal_common_proc.c
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -25,6 +25,7 @@
 #include <rte_cycles.h>
 #include <rte_eal.h>
 #include <rte_errno.h>
+#include <rte_interrupts.h>
 #include <rte_lcore.h>
 #include <rte_log.h>
 #include <rte_tailq.h>
@@ -101,6 +102,8 @@ static struct {
 	/**< used in async requests only */
 };
 
+static struct rte_intr_handle ipc_intr_handle;
+
 static void async_reply_handle(void *arg);
 
 /* forward declarations */
@@ -339,18 +342,18 @@ process_msg(struct mp_msg_internal *m, struct sockaddr_un *s)
 	}
 }
 
-static void *
+static void
 mp_handle(void *arg __rte_unused)
 {
 	struct mp_msg_internal msg;
 	struct sockaddr_un sa;
 
 	while (1) {
-		if (read_msg(&msg, &sa) == 0)
-			process_msg(&msg, &sa);
-	}
+		if (read_msg(&msg, &sa) < 0)
+			break;
 
-	return NULL;
+		process_msg(&msg, &sa);
+	}
 }
 
 static int
@@ -548,10 +551,8 @@ unlink_sockets(const char *filter)
 int
 rte_mp_channel_init(void)
 {
-	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 	char path[PATH_MAX];
 	int dir_fd;
-	pthread_t mp_handle_tid;
 
 	/* create filter path */
 	create_socket_path("*", path, sizeof(path));
@@ -579,32 +580,31 @@ rte_mp_channel_init(void)
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
 			unlink_sockets(mp_filter)) {
 		RTE_LOG(ERR, EAL, "failed to unlink mp sockets\n");
-		close(dir_fd);
-		return -1;
+		goto res;
 	}
 
 	if (open_socket_fd() < 0) {
-		close(dir_fd);
-		return -1;
+		mp_fd = -1;
+		goto res;
 	}
 
-	if (pthread_create(&mp_handle_tid, NULL, mp_handle, NULL) < 0) {
-		RTE_LOG(ERR, EAL, "failed to create mp thead: %s\n",
+	ipc_intr_handle.fd = mp_fd;
+	ipc_intr_handle.type = RTE_INTR_HANDLE_IPC;
+
+	if (rte_intr_callback_register(&ipc_intr_handle,
+					mp_handle, NULL) < 0) {
+                RTE_LOG(ERR, EAL, "failed to register IPC callback: %s\n",
 			strerror(errno));
 		close(mp_fd);
 		mp_fd = -1;
-		return -1;
 	}
 
-	/* try best to set thread name */
-	snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "rte_mp_handle");
-	rte_thread_setname(mp_handle_tid, thread_name);
-
+res:
 	/* unlock the directory */
 	flock(dir_fd, LOCK_UN);
 	close(dir_fd);
 
-	return 0;
+	return (mp_fd < 0) ? -1 : 0;
 }
 
 /**
-- 
2.7.4