From patchwork Sun Feb 21 14:28:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kozlyuk X-Patchwork-Id: 88062 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AD6EEA034F; Sun, 21 Feb 2021 15:28:53 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7D11E22A2C0; Sun, 21 Feb 2021 15:28:33 +0100 (CET) Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by mails.dpdk.org (Postfix) with ESMTP id 6912522A286 for ; Sun, 21 Feb 2021 15:28:30 +0100 (CET) Received: by mail-lj1-f177.google.com with SMTP id c8so49225472ljd.12 for ; Sun, 21 Feb 2021 06:28:30 -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=/bYT2RLPUm8z74IPsM/9g/lpQLhv7IWPMlAjEQGx3V4=; b=XhEGFrcFZ8nAawRP+DEGJHNwYLJseMH7lySu9rWoK5+g60kWEVYfOJAQeMlo4eKtGX IQTxPlkkGAmhGicOxGN7NFTqLEIWyAFTNtOBKYs+utuUwAG/FGN5oaaCL/7nHs3f6Kb6 Pi5ChC1UGGC60vqe+TKBiO9c+0oMwV3WevpSChkQcfes5dxEsv/4U/n+Sh/guQby7+pH 4pQwYAq5/psvkylDzGiSpiMlPCUm2Fmhkpvk3ijwPwIINcGIDKt82FoBKWm66JXGywZK WaojUyYjGocn836ge4EZKG9wAoBr9vRjjR3KGEJICmHDfqfkdAlQS3SVNMTfcQT22MbA mpYA== 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=/bYT2RLPUm8z74IPsM/9g/lpQLhv7IWPMlAjEQGx3V4=; b=uYNPYF2Thpi+ROryN/7s1GSKxjMCFP9PwsdIrH5LiyLi7NjFLQOALmCaozASQfmd7Z ak1vAVAt56xZEdmQRa9P0H/xNmHyHVDOvdVc2Fzz1HBR1yecbbw1pAX4KGRYn9udIqV4 eZF2nd8yPsEXDBWpZ0p5B3qfQuZ3+OBNcO5RbKXcmALxYtVW6NEOF1oPd+QBfkDrRziC murNYjG1wBLGYCkSLQFFrgFhN3zne+UKZWc9ftAFhn/9A5tf5p6L/H2kthyvoU2iqY+M udsx3hUreoZocdO3eOeacz8218impjmffWksa3YaRWzFSKYlpaSV7Tos9i4xHinkc94u 9/nQ== X-Gm-Message-State: AOAM531jiThamKDzDR6vWpENr79LMqYNO/DtvXRxTRiefgM09Lg/fzzQ Oqd/1zotT28RkJ8GfCPBV+wxUC8YZQ0iuyqp X-Google-Smtp-Source: ABdhPJyqDhBfmLYsAN6x0BaB73lEOcnlpl+e8aWO5rX4XyGmj9VEwHa78g6UONqi8Sns992cydt8pQ== X-Received: by 2002:a2e:7f10:: with SMTP id a16mr6333456ljd.504.1613917709840; Sun, 21 Feb 2021 06:28:29 -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 a30sm1569885lfo.56.2021.02.21.06.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Feb 2021 06:28:29 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tal Shnaiderman , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , Ray Kinsella , Neil Horman Date: Sun, 21 Feb 2021 17:28:15 +0300 Message-Id: <20210221142819.6769-4-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210221142819.6769-1-dmitry.kozliuk@gmail.com> References: <20210221012831.14643-1-dmitry.kozliuk@gmail.com> <20210221142819.6769-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 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 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 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..91babfe88 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 fce90a112..b9240e7f8 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); +}