From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 324C4A0C45 for ; Thu, 10 Jun 2021 14:06:54 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2C8AA410E9; Thu, 10 Jun 2021 14:06:54 +0200 (CEST) Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by mails.dpdk.org (Postfix) with ESMTP id C0ADD4069B for ; Thu, 10 Jun 2021 14:06:52 +0200 (CEST) Received: from 2.general.paelzer.uk.vpn ([10.172.196.173] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lrJSR-0008O2-KM; Thu, 10 Jun 2021 12:06:47 +0000 From: Christian Ehrhardt To: Chengwen Feng Cc: Min Hu , =?UTF-8?q?Morten=20Br=C3=B8rup?= , dpdk stable Date: Thu, 10 Jun 2021 14:05:53 +0200 Message-Id: <20210610120641.885862-5-christian.ehrhardt@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610120641.885862-1-christian.ehrhardt@canonical.com> References: <20210610120641.885862-1-christian.ehrhardt@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'ipc: use monotonic clock' has been queued to stable release 19.11.9 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to stable release 19.11.9 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 06/12/21. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/cpaelzer/dpdk-stable-queue This queued commit can be viewed at: https://github.com/cpaelzer/dpdk-stable-queue/commit/0bc04a9e43521816b2c8bda20127c958bb79454f Thanks. Christian Ehrhardt --- >From 0bc04a9e43521816b2c8bda20127c958bb79454f Mon Sep 17 00:00:00 2001 From: Chengwen Feng Date: Tue, 11 May 2021 18:41:23 +0800 Subject: [PATCH] ipc: use monotonic clock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ upstream commit cc994d3922b7cd464d84fbef110dd65348e0a0da ] Currently, the mp uses gettimeofday() API to get the time, and used as timeout parameter. But the time which gets from gettimeofday() API isn't monotonically increasing. The process may fail if the system time is changed. This fixes it by using clock_gettime() API with monotonic attribution. Fixes: 783b6e54971d ("eal: add synchronous multi-process communication") Fixes: f05e26051c15 ("eal: add IPC asynchronous request") Signed-off-by: Chengwen Feng Signed-off-by: Min Hu (Connor) Acked-by: Morten Brørup --- lib/librte_eal/common/eal_common_proc.c | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c index 13ae2b915e..922569f3f5 100644 --- a/lib/librte_eal/common/eal_common_proc.c +++ b/lib/librte_eal/common/eal_common_proc.c @@ -483,14 +483,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); @@ -884,6 +881,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; @@ -892,7 +890,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) { @@ -955,8 +955,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; RTE_LOG(DEBUG, EAL, "request: %s\n", req->name); @@ -973,15 +972,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) { @@ -1055,7 +1054,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; @@ -1070,7 +1069,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; @@ -1092,9 +1091,9 @@ rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts, end = ¶m->end; reply = ¶m->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; -- 2.31.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2021-06-10 14:04:58.336059988 +0200 +++ 0005-ipc-use-monotonic-clock.patch 2021-06-10 14:04:57.998024139 +0200 @@ -1 +1 @@ -From cc994d3922b7cd464d84fbef110dd65348e0a0da Mon Sep 17 00:00:00 2001 +From 0bc04a9e43521816b2c8bda20127c958bb79454f Mon Sep 17 00:00:00 2001 @@ -8,0 +9,2 @@ +[ upstream commit cc994d3922b7cd464d84fbef110dd65348e0a0da ] + @@ -19 +20,0 @@ -Cc: stable@dpdk.org @@ -25 +26 @@ - lib/eal/common/eal_common_proc.c | 27 +++++++++++++-------------- + lib/librte_eal/common/eal_common_proc.c | 27 ++++++++++++------------- @@ -28,5 +29,5 @@ -diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c -index 6d1af3c0e7..dc4a2efa82 100644 ---- a/lib/eal/common/eal_common_proc.c -+++ b/lib/eal/common/eal_common_proc.c -@@ -490,14 +490,11 @@ async_reply_handle_thread_unsafe(void *arg) +diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c +index 13ae2b915e..922569f3f5 100644 +--- a/lib/librte_eal/common/eal_common_proc.c ++++ b/lib/librte_eal/common/eal_common_proc.c +@@ -483,14 +483,11 @@ async_reply_handle_thread_unsafe(void *arg) @@ -48 +49 @@ -@@ -896,6 +893,7 @@ mp_request_sync(const char *dst, struct rte_mp_msg *req, +@@ -884,6 +881,7 @@ mp_request_sync(const char *dst, struct rte_mp_msg *req, @@ -56 +57 @@ -@@ -904,7 +902,9 @@ mp_request_sync(const char *dst, struct rte_mp_msg *req, +@@ -892,7 +890,9 @@ mp_request_sync(const char *dst, struct rte_mp_msg *req, @@ -67 +68 @@ -@@ -967,8 +967,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply, +@@ -955,8 +955,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply, @@ -74,2 +74,0 @@ - const struct internal_config *internal_conf = - eal_get_internal_configuration(); @@ -77 +76,3 @@ -@@ -987,15 +986,15 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply, + RTE_LOG(DEBUG, EAL, "request: %s\n", req->name); + +@@ -973,15 +972,15 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply, @@ -96 +97 @@ -@@ -1069,7 +1068,7 @@ rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts, +@@ -1055,7 +1054,7 @@ rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts, @@ -104,2 +105,2 @@ - const struct internal_config *internal_conf = -@@ -1086,7 +1085,7 @@ rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts, + +@@ -1070,7 +1069,7 @@ rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts, @@ -114 +115 @@ -@@ -1108,9 +1107,9 @@ rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts, +@@ -1092,9 +1091,9 @@ rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts,