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 454B1A0524; Sat, 20 Mar 2021 12:27:53 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3A1BF141083; Sat, 20 Mar 2021 12:27:49 +0100 (CET) Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by mails.dpdk.org (Postfix) with ESMTP id E7EDE40395 for ; Sat, 20 Mar 2021 12:27:45 +0100 (CET) Received: by mail-lf1-f50.google.com with SMTP id b14so775563lfv.8 for ; Sat, 20 Mar 2021 04:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JBT1Rj/rGIpw7yQP4AzTZEy/VLjUIgWO1rGD1EycJ+g=; b=lM0B8AaL/Jhy1CVLllCj50hZ+eO/bmSBCYgYRaDAN3IrMu/h1oWHrORDaptYqOOnDY eUF7c5csUu98p+ln0TBKkkRT7UpXngF8ebyhY+Y9b5ftIEecYW24MiULTfPDewlsUt+7 p3xX64Zw2jH5D1+SKn4oxREKUl5/ydcm5qB8EVVpfaxiQIatGhxhbbuOirT5iFbYDMoC JYdgTCScvDsfgR7Gtyt0bIWtHOteXN78aCoC73Xk+QcFbPvZTFTAevZjRLqHc+0DZH5q OTzD3QoiR3ZL9pTR2fV1L8hvSHm80b4MlstXWJPvGThzUmRrCTeyyCYjAZN3FqQNS5wo szXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JBT1Rj/rGIpw7yQP4AzTZEy/VLjUIgWO1rGD1EycJ+g=; b=RO8/Y7hkhDIu8tfCjw8AK8JVra6zqSaD7ldoROWLt7BFC64FP7tfCqK9G4gaihIMrC sCOggdaqu9wUQZRbw5l30wiV3dL4eM2dGilKWny4jnc/l988+Yu8SGaU6QJtpaYhhMeH XO2DTTzQtzNmJi0z4FrmBuHjb57VZtY9fY2T44XDcPRx3MPrIXZ8V1ZL1dEhOqEWXW0J ZuRPEWSjeS2/1uG6+dQy/MQTRpLXayshDFXB6y+oAKx9uvYp5Sp+IAcdPTcf5IzzTij/ xc6/3qSaKDBQSIYRYou+He0yed59o+68Ghht1WtieNnjZj2mSM0Kp08blFlg5JM7yu5F GPHA== X-Gm-Message-State: AOAM532ssBIlrFgag1PxGTgAsd8nmq/5r75tID9SW79myhSVx9rGJDg/ j+oXh6kyYLE2hu5ZiRG1zZaFy1DL390qcS70 X-Google-Smtp-Source: ABdhPJyjAaXrXCvx9Wi+noOAron2brwTyRa6TLaU+NgWv0hsb9KTB+tjSGLBHEkJoDgy5iIf1Mc7VQ== X-Received: by 2002:a19:3f08:: with SMTP id m8mr3594563lfa.275.1616239665268; Sat, 20 Mar 2021 04:27:45 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id v26sm913976lfe.276.2021.03.20.04.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 04:27:44 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tyler Retzlaff , Jie Zhou , Dmitry Kozlyuk , Khoa To , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , Ray Kinsella , Neil Horman Date: Sat, 20 Mar 2021 14:27:29 +0300 Message-Id: <20210320112733.13160-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210320112733.13160-1-dmitry.kozliuk@gmail.com> References: <20210306000500.8698-1-dmitry.kozliuk@gmail.com> <20210320112733.13160-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v5 1/5] eal: add sleep API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" POSIX sleep(3) is missing from Windows. Add generic rte_thread_sleep() to suspend current OS thread. Signed-off-by: Dmitry Kozlyuk Acked-by: Khoa To --- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 10 +++++++++- lib/librte_eal/version.map | 3 +++ lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c index 71e0bd035a..0e89a4f7df 100644 --- a/lib/librte_eal/common/eal_common_timer.c +++ b/lib/librte_eal/common/eal_common_timer.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "eal_private.h" #include "eal_memcfg.h" @@ -47,9 +48,9 @@ estimate_tsc_freq(void) #define CYC_PER_10MHZ 1E7 RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly" " - clock timings may be less accurate.\n"); - /* assume that the sleep(1) will sleep for 1 second */ + /* assume that the rte_thread_sleep(1) will sleep for 1 second */ uint64_t start = rte_rdtsc(); - sleep(1); + rte_thread_sleep(1); /* Round up to 10Mhz. 1E7 ~ 10Mhz */ return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ); } diff --git a/lib/librte_eal/include/rte_thread.h b/lib/librte_eal/include/rte_thread.h index e640ea1857..f0c12dd79d 100644 --- a/lib/librte_eal/include/rte_thread.h +++ b/lib/librte_eal/include/rte_thread.h @@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value); __rte_experimental void *rte_thread_tls_value_get(rte_tls_key key); +/** + * Suspend current OS thread for the specified time, yielding CPU to scheduler. + * + * @param sec + * Number of seconds to sleep. The system may return control later, + * but not earlier. Zero value always yields the CPU, but control may be + * returned immediately. + */ +__rte_experimental +void rte_thread_sleep(unsigned int sec); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def index 474cf123fa..494240b940 100644 --- a/lib/librte_eal/rte_eal_exports.def +++ b/lib/librte_eal/rte_eal_exports.def @@ -334,3 +334,5 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + + rte_thread_sleep diff --git a/lib/librte_eal/unix/rte_thread.c b/lib/librte_eal/unix/rte_thread.c index 86ffeebc95..91babfe887 100644 --- a/lib/librte_eal/unix/rte_thread.c +++ b/lib/librte_eal/unix/rte_thread.c @@ -3,10 +3,12 @@ */ #include -#include #include #include +#include +#include + #include #include #include @@ -84,3 +86,9 @@ rte_thread_tls_value_get(rte_tls_key key) } return pthread_getspecific(key->thread_index); } + +void +rte_thread_sleep(unsigned int sec) +{ + sleep(sec); +} diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map index 756c60ed1d..823c6639ec 100644 --- a/lib/librte_eal/version.map +++ b/lib/librte_eal/version.map @@ -419,6 +419,9 @@ EXPERIMENTAL { rte_thread_tls_key_delete; rte_thread_tls_value_get; rte_thread_tls_value_set; + + # added in 21.05 + rte_thread_sleep; }; INTERNAL { diff --git a/lib/librte_eal/windows/eal_thread.c b/lib/librte_eal/windows/eal_thread.c index 9c3f6d69fd..c84e67009c 100644 --- a/lib/librte_eal/windows/eal_thread.c +++ b/lib/librte_eal/windows/eal_thread.c @@ -11,9 +11,10 @@ #include #include #include -#include +#include #include "eal_private.h" +#include "eal_thread.h" #include "eal_windows.h" /* @@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name) /* This is a stub, not the expected result */ return 0; } + +void +rte_thread_sleep(unsigned int sec) +{ + return Sleep(MS_PER_S * sec); +} -- 2.29.2