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 A3B9BA0548; Sun, 4 Apr 2021 01:41:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A970C140E1D; Sun, 4 Apr 2021 01:41:40 +0200 (CEST) Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by mails.dpdk.org (Postfix) with ESMTP id 0E25840041 for ; Sun, 4 Apr 2021 01:41:39 +0200 (CEST) Received: by mail-lf1-f52.google.com with SMTP id d12so12392645lfv.11 for ; Sat, 03 Apr 2021 16:41:39 -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=ppuA1LCctO+2AmWw7urwHxYJl6hzdyHkeK6KilKLXjI=; b=Y7dExYmSiGfTdJB/uXd9f9AKRomrfr0iIvqvZ/6CIlQUx/+qFBpGVAk+acPDgUeMku 1PWE0ONGHRRoqXJaAQA6R/F+Q0On3+v6KIn9kYokOnBJ4Revhoop1I+Dx25EKNhHd/Bl ZetRkIqDcnGe5PgYR3/dm4veJpTq9XPxkiSv1dC7+6s5SNgA85xLwQfqQb3rPrVrsrri /6Wu4iUmkIx+TocHPSUrNlMyoy74+OPL0Qj+qtJk22dD0vxMvgQSHxuyPYqS/5T2Go4s 8blePUhZO+f9j8kcl1vE/Kk4gMKkm7qXwo7JvwMkXwPkfaKBGJAcwXPkNc8eeE3gfq0B lU+A== 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=ppuA1LCctO+2AmWw7urwHxYJl6hzdyHkeK6KilKLXjI=; b=plU4wfgNINpgPnGcnNY2VsvWqCmLb5Lt/u4PWUliz8x5HUF8bSOUhrVyIMUsBa9gZI V+MH7nYFnB+BMJmRUZ1vmH8qbGzilXJWaXJxBGFJvigTSpmxgZopUH8i4AeN4DkjOWFG AL0wQPcJ44fTF2UtpckzjKgPhzC5bgi9lSowqa52CbmMgWMXqBJrpBCor735FZh0GJ2r LQW8nLy7rcqG2Z4mI6+53Uq/jRpujgTBD2sIkrLr0okDwCkdMQ9MSDlEtiuQB215aj0V zIm6hSBi/+ZWYYidMdKVFSq8gN4LJPipNv4pWT8jgBwsZH6GKlRMi4PjR1IDC88Hd3cs O9WQ== X-Gm-Message-State: AOAM531qNxDYYkIAQAkSXiy/32LUgi4FKjddO19uh3Qn96epoJz4Buer bWGkITmyuEsHzZjFLA0I+NMKgwUZcECUvQse X-Google-Smtp-Source: ABdhPJw/UMLKjSQ10BUR/SkS21zOVYffxq7r43lLD/O5NRJMPJnhnC6QIuI77mw/4+ay+Ar/uYkpEw== X-Received: by 2002:a19:c309:: with SMTP id t9mr12669058lff.348.1617493298411; Sat, 03 Apr 2021 16:41:38 -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 f23sm1374927lja.43.2021.04.03.16.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Apr 2021 16:41:38 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tyler Retzlaff , Jie Zhou , Nick Connolly , Dmitry Kozlyuk , Khoa To , Ray Kinsella , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , Neil Horman Date: Sun, 4 Apr 2021 02:41:25 +0300 Message-Id: <20210403234129.20296-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210403234129.20296-1-dmitry.kozliuk@gmail.com> References: <20210320130525.16452-1-dmitry.kozliuk@gmail.com> <20210403234129.20296-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v7 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 Acked-by: Ray Kinsella --- 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 | 1 + lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 34 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 8be8ed8f36..450d72a2fc 100644 --- a/lib/librte_eal/include/rte_thread.h +++ b/lib/librte_eal/include/rte_thread.h @@ -119,6 +119,17 @@ int rte_thread_value_set(rte_thread_key key, const void *value); __rte_experimental void *rte_thread_value_get(rte_thread_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 c320077547..300c86eb3f 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 c72d619ec1..a7130b5870 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 @@ -90,3 +92,9 @@ rte_thread_value_get(rte_thread_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 e23745ae6e..cd35b67a9a 100644 --- a/lib/librte_eal/version.map +++ b/lib/librte_eal/version.map @@ -413,6 +413,7 @@ EXPERIMENTAL { # added in 21.05 rte_thread_key_create; rte_thread_key_delete; + rte_thread_sleep; rte_thread_value_get; rte_thread_value_set; rte_version_minor; 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.3