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 866EEA0524; Sun, 21 Feb 2021 00:29:43 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 923AC22A262; Sun, 21 Feb 2021 00:29:24 +0100 (CET) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by mails.dpdk.org (Postfix) with ESMTP id 18CFC22A25A for ; Sun, 21 Feb 2021 00:29:22 +0100 (CET) Received: by mail-lj1-f169.google.com with SMTP id a17so44114494ljq.2 for ; Sat, 20 Feb 2021 15:29:22 -0800 (PST) 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=6HBBi46aLE4tojLHuhD1zt9K6yB/yz+Q7GFJaWnW3r4=; b=Pouv+pa1LxnK7/fkXielfPxT6/Hd4ykHLBXLIHXMmWVZySEhCSZ6RddRFJ88njPyDv u0F5yiYYPonrNsNcG5u/4iJ9QieJcqUFr5sL4Nauo+sZUPEb54i3ElcvyOR69wf20L9Z CT5Vb5sUmicwbOuy8v6EfIoj2OB5cHcPjJ2infB7X/sy2XuvWvptqoXv0PpNbHGCJSWM qo5gVJ1nO8eWf0SKBlgD7m/G5SAakA1O/f+gmoy70jSkAIFhNZ0LW60sIhRMntYCss8u W8pQ4cGgkdSF8sd6Eum+dmEIn80vGoKmKo5XOXcV5doHhY+iP+YibHRtUts5Xl61+Mtp zWLQ== 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=6HBBi46aLE4tojLHuhD1zt9K6yB/yz+Q7GFJaWnW3r4=; b=DdVZmaFLHxaE/dhcV4kKgx1rU4lm+PnACnpw7fYBQV51XJY3BnwqBHFXP4+Ea8b/Aa iMZDLSCFcbayW9lykHrxcQ1xsSoJm0w+kC0FxA6Jo6C3uZq3r5qlfaPGuXCBeaqQbhyE ibs7sGFlLCydkLuMgbScUZ57LG1OrhZu6+fyaNS2hhbo75V4Vc/2wlx/B/E+505O0FqE 02JMWha3cLQm00bUtscmyYDMkcGD8djk/H+NEWgesC8a6mu+k7JFNZNLQQQHLaR49uZF 77x2ighGuI5j9lxvPtMFtlvNzIX9A2AKJpZM32c0bivU5cnZ78OcReUel3Hr048V4+aJ 0pMw== X-Gm-Message-State: AOAM532n69SAn4wVCp8z1YStgpzSkCbEtHmcJFjLua0u4+ccnHN9N7YN q7wvOMlHLRRqUTyPZnjFZKuPYEzsWQhDeg== X-Google-Smtp-Source: ABdhPJxo7kfaKZ/A1ePEynF2YRfTPvHEewKKaKv+wArUCjuqE1u9jFWCIMHT9jIYa+rd6dz/PpP5cw== X-Received: by 2002:a05:6512:32ab:: with SMTP id q11mr9345479lfe.417.1613863761486; Sat, 20 Feb 2021 15:29:21 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id f5sm1462931ljc.8.2021.02.20.15.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Feb 2021 15:29:21 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tyler Retzlaff , Nick Connolly , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , Ray Kinsella , Neil Horman Date: Sun, 21 Feb 2021 02:29:06 +0300 Message-Id: <20210220232910.772-4-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210220232910.772-1-dmitry.kozliuk@gmail.com> References: <20210220232910.772-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 3/7] 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 --- 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 | 6 ++++++ lib/librte_eal/version.map | 3 +++ lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c index 71e0bd035..0e89a4f7d 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 e640ea185..f0c12dd79 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 474cf123f..494240b94 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 86ffeebc9..029d39dd4 100644 --- a/lib/librte_eal/unix/rte_thread.c +++ b/lib/librte_eal/unix/rte_thread.c @@ -84,3 +84,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 fce90a112..106864469 100644 --- a/lib/librte_eal/version.map +++ b/lib/librte_eal/version.map @@ -412,6 +412,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 908e726d1..957792301 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