common/sfc_efx/base: add API to get mport ID by selector
[dpdk.git] / lib / eal / common / eal_common_proc.c
index 6d1af3c..ebd0f66 100644 (file)
@@ -35,6 +35,7 @@
 #include "eal_internal_cfg.h"
 
 static int mp_fd = -1;
+static pthread_t mp_handle_tid;
 static char mp_filter[PATH_MAX];   /* Filter for secondary process sockets */
 static char mp_dir_path[PATH_MAX]; /* The directory path for all mp sockets */
 static pthread_mutex_t mp_mutex_action = PTHREAD_MUTEX_INITIALIZER;
@@ -383,7 +384,7 @@ mp_handle(void *arg __rte_unused)
        struct mp_msg_internal msg;
        struct sockaddr_un sa;
 
-       while (1) {
+       while (mp_fd >= 0) {
                if (read_msg(&msg, &sa) == 0)
                        process_msg(&msg, &sa);
        }
@@ -490,14 +491,11 @@ async_reply_handle_thread_unsafe(void *arg)
        struct pending_request *req = (struct pending_request *)arg;
        enum async_action action;
        struct timespec ts_now;
-       struct timeval now;
 
-       if (gettimeofday(&now, NULL) < 0) {
+       if (clock_gettime(CLOCK_MONOTONIC, &ts_now) < 0) {
                RTE_LOG(ERR, EAL, "Cannot get current time\n");
                goto no_trigger;
        }
-       ts_now.tv_nsec = now.tv_usec * 1000;
-       ts_now.tv_sec = now.tv_sec;
 
        action = process_async_request(req, &ts_now);
 
@@ -570,14 +568,11 @@ open_socket_fd(void)
 }
 
 static void
-close_socket_fd(void)
+close_socket_fd(int fd)
 {
        char path[PATH_MAX];
 
-       if (mp_fd < 0)
-               return;
-
-       close(mp_fd);
+       close(fd);
        create_socket_path(peer_name, path, sizeof(path));
        unlink(path);
 }
@@ -587,7 +582,6 @@ rte_mp_channel_init(void)
 {
        char path[PATH_MAX];
        int dir_fd;
-       pthread_t mp_handle_tid;
        const struct internal_config *internal_conf =
                eal_get_internal_configuration();
 
@@ -648,7 +642,16 @@ rte_mp_channel_init(void)
 void
 rte_mp_channel_cleanup(void)
 {
-       close_socket_fd();
+       int fd;
+
+       if (mp_fd < 0)
+               return;
+
+       fd = mp_fd;
+       mp_fd = -1;
+       pthread_cancel(mp_handle_tid);
+       pthread_join(mp_handle_tid, NULL);
+       close_socket_fd(fd);
 }
 
 /**
@@ -896,6 +899,7 @@ mp_request_sync(const char *dst, struct rte_mp_msg *req,
               struct rte_mp_reply *reply, const struct timespec *ts)
 {
        int ret;
+       pthread_condattr_t attr;
        struct rte_mp_msg msg, *tmp;
        struct pending_request pending_req, *exist;
 
@@ -904,7 +908,9 @@ mp_request_sync(const char *dst, struct rte_mp_msg *req,
        strlcpy(pending_req.dst, dst, sizeof(pending_req.dst));
        pending_req.request = req;
        pending_req.reply = &msg;
-       pthread_cond_init(&pending_req.sync.cond, NULL);
+       pthread_condattr_init(&attr);
+       pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
+       pthread_cond_init(&pending_req.sync.cond, &attr);
 
        exist = find_pending_request(dst, req->name);
        if (exist) {
@@ -967,8 +973,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
        int dir_fd, ret = -1;
        DIR *mp_dir;
        struct dirent *ent;
-       struct timeval now;
-       struct timespec end;
+       struct timespec now, end;
        const struct internal_config *internal_conf =
                eal_get_internal_configuration();
 
@@ -987,15 +992,15 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
                return -1;
        }
 
-       if (gettimeofday(&now, NULL) < 0) {
+       if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) {
                RTE_LOG(ERR, EAL, "Failed to get current time\n");
                rte_errno = errno;
                goto end;
        }
 
-       end.tv_nsec = (now.tv_usec * 1000 + ts->tv_nsec) % 1000000000;
+       end.tv_nsec = (now.tv_nsec + ts->tv_nsec) % 1000000000;
        end.tv_sec = now.tv_sec + ts->tv_sec +
-                       (now.tv_usec * 1000 + ts->tv_nsec) / 1000000000;
+                       (now.tv_nsec + ts->tv_nsec) / 1000000000;
 
        /* for secondary process, send request to the primary process only */
        if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
@@ -1069,7 +1074,7 @@ rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts,
        int dir_fd, ret = 0;
        DIR *mp_dir;
        struct dirent *ent;
-       struct timeval now;
+       struct timespec now;
        struct timespec *end;
        bool dummy_used = false;
        const struct internal_config *internal_conf =
@@ -1086,7 +1091,7 @@ rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts,
                return -1;
        }
 
-       if (gettimeofday(&now, NULL) < 0) {
+       if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) {
                RTE_LOG(ERR, EAL, "Failed to get current time\n");
                rte_errno = errno;
                return -1;
@@ -1108,9 +1113,9 @@ rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts,
        end = &param->end;
        reply = &param->user_reply;
 
-       end->tv_nsec = (now.tv_usec * 1000 + ts->tv_nsec) % 1000000000;
+       end->tv_nsec = (now.tv_nsec + ts->tv_nsec) % 1000000000;
        end->tv_sec = now.tv_sec + ts->tv_sec +
-                       (now.tv_usec * 1000 + ts->tv_nsec) / 1000000000;
+                       (now.tv_nsec + ts->tv_nsec) / 1000000000;
        reply->nb_sent = 0;
        reply->nb_received = 0;
        reply->msgs = NULL;