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 2483CA0546; Sun, 14 Feb 2021 03:16:34 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E161B1CC4FA; Sun, 14 Feb 2021 03:16:29 +0100 (CET) Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by mails.dpdk.org (Postfix) with ESMTP id 240921CC4DA for ; Sun, 14 Feb 2021 03:16:28 +0100 (CET) Received: by mail-lj1-f179.google.com with SMTP id k22so3058896ljg.3 for ; Sat, 13 Feb 2021 18:16:28 -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=lqHnc/gk+WRoUiAhgV7JNfW0MR5h6LzcLQ4WRFpUXBA=; b=jYsuPonK3CRNsdMmm03UvxJ/2LHo96w4GqEHYaqKDQCAzbqgiwBlJvDBFUaX4xWAvW ez0XSmFBv440+1m1479nW9rnbjowBpugZMKtxPC+yVV0o9EbRSPsa2CYZlnnQ0ZKSf+k b69AUYnqx1ZwEE3d0qwcdpw9G+8+epUqq9rRbDCaKNG3PsmLr/N+uMJf33UvkMBCCdjV 6FuAHdmfq2f8kjgmG/1QLU57R3otbUSCIZ6/MJTimh30NB9ix2x5KMbgocnf+RPeOGXM K9/BfF4vvcdczOD7JqSgqAEMronCCq1D81jNtHZeiL9iLBLXg7sQ0RgHNKX1FcQpFhYH /Lcg== 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=lqHnc/gk+WRoUiAhgV7JNfW0MR5h6LzcLQ4WRFpUXBA=; b=SN4x4knjCZQm6eRch3vCyKQCib5WgWJv70zhV/AyZxKTVxYDaL379YV/kNtawnCzTl 0eQNZ2TyaARt0cQYcoOWgDdIUvp5VZ5Z+RDQ3+XnD95Ajx22xbSRe5E5XtwmCljxV3iK kyF06Kswweb3rZtLe/N9tIPp2Pd4I4RAmU8oqwGm813HTFJzxfOSxUYiFsiMa1HzaIjS gfIlc3v6YX2WITlYdjf2DKnBlwbQvVpbF2ysoj3eTXzxEs7PD6F8Fl1LkOa1BKh+Xzg/ nVkwxGrBZHdcD5G0I7UeIqROp7iJpZhHLz5qTE3fRJmzIeQIR0ERD6h2PYyNbOTNWf6A 546g== X-Gm-Message-State: AOAM532SuSo9a7mLxa4M45qOKb9AwjfXP3w6U6BBGHadQ7qqRnxs+wlf 8kfxaJHhtrEwd65J/HyhbPJyE1SM70sNtg== X-Google-Smtp-Source: ABdhPJwRTuRvK7SzauoCN1o6qTL30P2GDIDRVm23t8YbCvjEKau7wz9bkOT8BFA2VBLYU5LzCwDidA== X-Received: by 2002:a2e:8005:: with SMTP id j5mr5666453ljg.34.1613268987424; Sat, 13 Feb 2021 18:16:27 -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 l19sm3017158lji.53.2021.02.13.18.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Feb 2021 18:16:27 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tyler Retzlaff , Mike Wells , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , Ray Kinsella , Neil Horman Date: Sun, 14 Feb 2021 05:16:11 +0300 Message-Id: <20210214021616.26970-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210214021616.26970-1-dmitry.kozliuk@gmail.com> References: <20210214012013.23165-1-dmitry.kozliuk@gmail.com> <20210214021616.26970-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 1/6] eal: add internal API for current time 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" Many PMDs use POSIX gettimeofday(). Add rte_time_get_us() function to obtain current time with microsecond precision on all platforms. Signed-off-by: Dmitry Kozlyuk --- lib/librte_eal/include/rte_time.h | 17 +++++++++++++++++ lib/librte_eal/rte_eal_exports.def | 1 + lib/librte_eal/unix/eal_unix_timer.c | 13 +++++++++++++ lib/librte_eal/version.map | 1 + lib/librte_eal/windows/eal_timer.c | 21 ++++++++++++++++++++- 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/include/rte_time.h b/lib/librte_eal/include/rte_time.h index 5ad7c8841..50fa4f889 100644 --- a/lib/librte_eal/include/rte_time.h +++ b/lib/librte_eal/include/rte_time.h @@ -8,6 +8,8 @@ #include #include +#include + #define NSEC_PER_SEC 1000000000L /** @@ -98,4 +100,19 @@ rte_ns_to_timespec(uint64_t nsec) return ts; } +/* Point of time with microsecond precision. */ +struct rte_time_us { + int64_t sec; /**< Number of whole seconds. */ + int64_t usec; /**< Fractional part of second in [0, 999999]. */ +}; + +/** + * Get current system time. + * + * @param now + * Receives current system time. + */ +__rte_internal +void rte_time_get_us(struct rte_time_us *now); + #endif /* _RTE_TIME_H_ */ diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def index 474cf123f..cb691f7bc 100644 --- a/lib/librte_eal/rte_eal_exports.def +++ b/lib/librte_eal/rte_eal_exports.def @@ -334,3 +334,4 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + rte_time_get_us diff --git a/lib/librte_eal/unix/eal_unix_timer.c b/lib/librte_eal/unix/eal_unix_timer.c index cc5015910..5612fdebe 100644 --- a/lib/librte_eal/unix/eal_unix_timer.c +++ b/lib/librte_eal/unix/eal_unix_timer.c @@ -4,7 +4,10 @@ #include +#include + #include +#include void rte_delay_us_sleep(unsigned int us) @@ -27,3 +30,13 @@ rte_delay_us_sleep(unsigned int us) ind = 1 - ind; } } + +void +rte_time_get_us(struct rte_time_us *now) +{ + struct timeval sys; + + gettimeofday(&sys, NULL); + now->sec = sys.tv_sec; + now->usec = sys.tv_usec; +} diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map index fce90a112..405bed766 100644 --- a/lib/librte_eal/version.map +++ b/lib/librte_eal/version.map @@ -421,4 +421,5 @@ INTERNAL { rte_mem_map; rte_mem_page_size; rte_mem_unmap; + rte_time_get_us; }; diff --git a/lib/librte_eal/windows/eal_timer.c b/lib/librte_eal/windows/eal_timer.c index b070cb775..a5c42106a 100644 --- a/lib/librte_eal/windows/eal_timer.c +++ b/lib/librte_eal/windows/eal_timer.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "eal_private.h" #define US_PER_SEC 1E6 @@ -85,10 +86,28 @@ get_tsc_freq(void) return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_10MHZ); } - int rte_eal_timer_init(void) { set_tsc_freq(); return 0; } + +void +rte_time_get_us(struct rte_time_us *now) +{ + /* 100ns ticks from 1601-01-01 to 1970-01-01 */ + static const uint64_t EPOCH = 116444736000000000ULL; + static const uint64_t TICKS_PER_USEC = 10; + static const uint64_t USEC_PER_SEC = 1000000; + + FILETIME ft; + uint64_t ticks, sec; + + GetSystemTimePreciseAsFileTime(&ft); + ticks = ((uint64_t)ft.dwHighDateTime << 32) | ft.dwLowDateTime; + ticks -= EPOCH; + sec = ticks / (TICKS_PER_USEC * USEC_PER_SEC); + now->sec = sec; + now->usec = ticks / TICKS_PER_USEC - sec * USEC_PER_SEC; +} -- 2.29.2