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 DFB91A0524; Sat, 20 Mar 2021 14:06:06 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A4A4E1410A7; Sat, 20 Mar 2021 14:05:53 +0100 (CET) Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by mails.dpdk.org (Postfix) with ESMTP id 795074067A for ; Sat, 20 Mar 2021 14:05:50 +0100 (CET) Received: by mail-lf1-f54.google.com with SMTP id 75so14239755lfa.2 for ; Sat, 20 Mar 2021 06:05:50 -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=sMD8/jEHhJjSShrF3NYEM+OecTUns5X1WpDa+HI4auI=; b=oMv08dVJrSATTVml9H8xv5J5ExGRP2+rp2ZmxG7Wir2NLeRQ+ccFeno964j5aLsNew sH3pLK6mq0Amj399Tg+SQjxo2rcz4+AAkDgTItuhUFZrhMCd4pky5zsLWR4UgJZU+3Jf HhAWQQ+9/bQkDh31GFzj0xJSZrCALKACzw4ETUhwujtgNVyQRMYIkGGVhzA5j2b2aJ+9 RJjpoQD/qZ1CuklkNyudhaNvdsZ1/fGkaP9foCwvVSGIYrCuKKi/MzP7qyMMrwifH6Xu CPVuHhZCzSb4/DzmbN9GFBrF9ZjPcO44IMYiFTzvfqYvZ2ltHVJiZyCVb1I2M9UlyG91 Q/Yg== 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=sMD8/jEHhJjSShrF3NYEM+OecTUns5X1WpDa+HI4auI=; b=F3tDJR83Bvt+qkmZyGeeaLWNUh8Y+PAZHGHOUhMDKOIhqnlwCO3RNn2r/+VdnZl9YR /nC9rB1xnqVvIsOe7qREHqZuwvGNeuKpdOVVH+SlR2yuP3k6lal6kF7wYAQ9kQWaPoeA PIiqGoGJGLbX8sDEcR7+LrsV39LYTNnZhuDUSN/DMBEj5vUb6nCllP4U52HwLKsDhW1F WRsdeKnpElsvzYpBvY2kHnYvFGomjia3XxeU8CUSiaCO8LVpZp86QfEeGYWUoKuZAoNC ZONPtaiwJlj/d6+JugOfVhxDnJshr1cDB1Ggja1dUwvhx8jM16JTVLS7xvYViJ9ZPpqQ iMcA== X-Gm-Message-State: AOAM530wbLcqYp4akytIc1xNRqTi9SeLg/4JYfT2FRJqyA60tRpVnEL0 V8JPYpefg6/pfc60nTwDvc+/2Kl28lasWphk X-Google-Smtp-Source: ABdhPJwvE6oV8VzbSBVDSKEwCSDy5Ddzyn6FQJvZyl3LbAaWe7PBKD2bUJoqN15qzDx8PBsNlWrxgA== X-Received: by 2002:a19:f50d:: with SMTP id j13mr3756355lfb.545.1616245548351; Sat, 20 Mar 2021 06:05:48 -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 r66sm929610lff.93.2021.03.20.06.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 06:05:47 -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 16:05:21 +0300 Message-Id: <20210320130525.16452-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210320130525.16452-1-dmitry.kozliuk@gmail.com> References: <20210320112733.13160-1-dmitry.kozliuk@gmail.com> <20210320130525.16452-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v6 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 | 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 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 48a2b55d57..da527f41bf 100644 --- a/lib/librte_eal/version.map +++ b/lib/librte_eal/version.map @@ -415,6 +415,7 @@ EXPERIMENTAL { rte_thread_tls_value_set; # added in 21.05 + rte_thread_sleep; rte_version_minor; rte_version_month; rte_version_prefix; 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