On 11-Jan-18 4:07 AM, Jianfeng Tan wrote:
---
  lib/librte_eal/common/eal_common_proc.c | 144 +++++++++++++++++++++++++++++---
  lib/librte_eal/common/include/rte_eal.h |  73 +++++++++++++++-
  lib/librte_eal/rte_eal_version.map      |   2 +
  3 files changed, 206 insertions(+), 13 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_proc.c 
b/lib/librte_eal/common/eal_common_proc.c
index 70519cc..f194a52 100644
--- a/lib/librte_eal/common/eal_common_proc.c
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -32,6 +32,7 @@
  static int mp_fd = -1;
  static char *mp_sec_sockets[MAX_SECONDARY_PROCS];
  static pthread_mutex_t mp_mutex_action = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t mp_mutex_request = PTHREAD_MUTEX_INITIALIZER;
struct action_entry {
        TAILQ_ENTRY(action_entry) next;      /**< Next attached action entry */
@@ -49,6 +50,10 @@ static struct action_entry_list action_entry_list =
struct mp_msghdr {
        char action_name[MAX_ACTION_NAME_LEN];
+#define MP_MSG 0 /* Share message with peers, will not block */
+#define MP_REQ 1 /* Request for information, Will block for a reply */
+#define MP_REP 2 /* Reply to previously-received request */

nitpicking, but... response instead of reply?

+       int type;
        int fds_num;
        int len_params;
        char params[0];
@@ -138,7 +143,8 @@ rte_eal_mp_action_unregister(const char *name)
  }
static int
-read_msg(int fd, char *buf, int buflen, int *fds, int fds_num)
+read_msg(int fd, char *buf, int buflen,
+        int *fds, int fds_num, struct sockaddr_un *s)

<snip>

+       return mp_send(action_name, params, len_params,
+                       fds, fds_num, MP_MSG, NULL);
+}
+
+int
+rte_eal_mp_request(const char *action_name,
+                  void *params,
+                  int len_p,
+                  int fds[],
+                  int fds_in,
+                  int fds_out)

name == NULL? name too long?

+{
+       int i, j;
+       int sockfd;
+       int nprocs;
+       int ret = 0;
+       struct mp_msghdr *req;
+       struct timeval tv;
+       char buf[MAX_MSG_LENGTH];
+       struct mp_msghdr *hdr;
+
+       RTE_LOG(DEBUG, EAL, "request: %s\n", action_name);
+
+       if (fds_in > SCM_MAX_FD || fds_out > SCM_MAX_FD) {
+               RTE_LOG(ERR, EAL, "Cannot send more than %d FDs\n", SCM_MAX_FD);
+               rte_errno = -E2BIG;

(this also applies to previous patches) you set rte_errno to -EINVAL in format_msg when message with parameters is too big - should that be setting -E2BIG as well? Also, maybe not set rte_errno in multiple places, and put all parameter checking (or at least errno setting) in rte_eal_mp_* functions?

+               return 0;
+       }
+
+       req = format_msg(action_name, params, len_p, fds_in, MP_REQ);
+       if (req == NULL)
+               return 0;
+
+       if ((sockfd = open_unix_fd(0)) < 0) {
+               free(req);
+               return 0;
+       }
+
+       tv.tv_sec = 5;  /* 5 Secs Timeout */
+       tv.tv_usec = 0;
+       if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO,
+                       (const void *)&tv, sizeof(struct timeval)) < 0)
+               RTE_LOG(INFO, EAL, "Failed to set recv timeout\n");
+
+       /* Only allow one req at a time */
+       pthread_mutex_lock(&mp_mutex_request);
+
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+               nprocs = 0;
+               for (i = 0; i < MAX_SECONDARY_PROCS; ++i)

What follows is a bit confusing, some comments explaining what happens and maybe more informative variable names would've been helpful.

+                       if (!mp_sec_sockets[i]) {
+                               j = i;
+                               nprocs++;
+                       }
+
+               if (nprocs > 1) {
+                       RTE_LOG(ERR, EAL,
+                               "multi secondary processes not supported\n");
+                       goto free_and_ret;
+               }
+

<snip>


--
Thanks,
Anatoly

Reply via email to