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 744FFA0547; Wed, 21 Apr 2021 21:34:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6D38C41BCC; Wed, 21 Apr 2021 21:34:05 +0200 (CEST) Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by mails.dpdk.org (Postfix) with ESMTP id 14A4540150 for ; Wed, 21 Apr 2021 21:34:02 +0200 (CEST) Received: by mail-lj1-f173.google.com with SMTP id b38so7887526ljf.5 for ; Wed, 21 Apr 2021 12:34:02 -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=5TrRgNXn07+vs9PigbWwgzuvJQb2lLLUjH2bBucmSw0=; b=gtd12NcQVnZDGx+xQMZBMP0DtvFfRBINy1YzYNUUDBE4KMMpfUhvs6+Yb72oQl1jf4 ZfRUHDKLpV2HIoYS8RepvDSPBjIlvSY2GKWLZofvQxmt2aa6N+SoLX7TEYCG6SyKxkk0 h+Bmv8MQ2ahLXkC38xOx7GP+3PDZusu8H3hn2SD7yypUpE0k1dQV6H30Y9ip9FKRqJ18 WAhmP8NUVNjXyPa19nxhWCQSSs1yAZleHYwUB+Ol6sw1WgrT78GTB9Ri+OIEXsHWt4Pc FnXTLOke2i/B8KbBQe1J26N3nz4Od9wSPVIHGkVAmyxuFZhDKs/IymGgSTCrEEzZkExO os3g== 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=5TrRgNXn07+vs9PigbWwgzuvJQb2lLLUjH2bBucmSw0=; b=s2oa4hIYqT1CgdZkk6MoP2XjSdyfjkmYJtithaZTdMeXKOoNu/+PRfbUPJydXGEAoG IWeIuIHodVm92LjOPT3GwQD8bgBd/wzt3Z84eHSmFSzWAfdPosZqfujdR7uKyJb+M8P6 vAp9gtbv5/Jax1mWQo9p8bxvhh5wtcsJ20wQq02LRqeqlGMLI8LukBHNxoJVeyTYM4rm 4XE7WZBwiWbc4/eKtlKXDBbmI8F5R33nzHOqnEJCcOtH6/0gaMh0brK8AQW61U0OQnK8 HgHiP1dk/t63HHZEM1DgLWHKw4kVKn5A5YF6wQvNMKs1aQ/MekSALGU6REtbdpChj7d2 nIsg== X-Gm-Message-State: AOAM532X0GO3q/18Ph9GwqVqqP/S6CiTcXrLCsZkH20FgkyB0zdgnCyF neq9yIq3KsAnPJpb8exkWcIwJLh+CJmorg== X-Google-Smtp-Source: ABdhPJwzLcsI0bJpIf4p4aQ3KSZ7msQlXtgS1w/v00L9KKoP7C2d9eD8GmFkD+Imwt7IgjP0dYBEag== X-Received: by 2002:a05:651c:1029:: with SMTP id w9mr16473597ljm.379.1619033641396; Wed, 21 Apr 2021 12:34:01 -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 p11sm47588lfg.126.2021.04.21.12.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 12:34:01 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , Jie Zhou , Nick Connolly , Bruce Richardson , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Wed, 21 Apr 2021 22:33:49 +0300 Message-Id: <20210421193351.1909-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210421193351.1909-1-dmitry.kozliuk@gmail.com> References: <20210415221055.1575-1-dmitry.kozliuk@gmail.com> <20210421193351.1909-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v5 1/3] eal: add timespec_get shim 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" C11 timespec_get() is not provided on some platforms: * MinGW-w64 does not currently implement it [1]. * FreeBSD 11 with Clang 10.0.0 does not provide it. Add internal shims to Windows and FreeBSD EALs. For Windows, it can be removed after [1] is fixed. [1]: https://sourceforge.net/p/mingw-w64/mailman/message/37224689/ Signed-off-by: Dmitry Kozlyuk Acked-by: Jie Zhou Acked-by: Nick Connolly --- lib/eal/freebsd/include/rte_os_shim.h | 17 ++++++++++++++ lib/eal/windows/include/rte_os_shim.h | 32 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/eal/freebsd/include/rte_os_shim.h b/lib/eal/freebsd/include/rte_os_shim.h index 1e85229ca9..10b51b802f 100644 --- a/lib/eal/freebsd/include/rte_os_shim.h +++ b/lib/eal/freebsd/include/rte_os_shim.h @@ -3,6 +3,8 @@ #ifndef _RTE_OS_SHIM_ #define _RTE_OS_SHIM_ +#include + #include /** @@ -11,4 +13,19 @@ * Provides semi-standard OS facilities by convenient names. */ +#ifndef TIME_UTC + +#define TIME_UTC 1 + +static inline int +rte_timespec_get(struct timespec *now, int base) +{ + if (base != TIME_UTC || clock_gettime(CLOCK_REALTIME, now) < 0) + return 0; + return base; +} + +#define timespec_get(ts, base) rte_timespec_get(ts, base) + +#endif /* !defined TIME_UTC */ #endif /* _RTE_OS_SHIM_ */ diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h index f40fb62d1d..e50895fd83 100644 --- a/lib/eal/windows/include/rte_os_shim.h +++ b/lib/eal/windows/include/rte_os_shim.h @@ -3,7 +3,10 @@ #ifndef _RTE_OS_SHIM_ #define _RTE_OS_SHIM_ +#include + #include +#include /** * @file @@ -33,4 +36,33 @@ #define IPPROTO_SCTP 132 #endif +#ifdef RTE_TOOLCHAIN_GCC + +#define TIME_UTC 1 + +static inline int +rte_timespec_get(struct timespec *now, int base) +{ + /* 100ns ticks from 1601-01-01 to 1970-01-01 */ + static const uint64_t EPOCH = 116444736000000000ULL; + static const uint64_t TICKS_PER_SEC = 10000000; + static const uint64_t NS_PER_TICK = 100; + + FILETIME ft; + uint64_t ticks; + + if (base != TIME_UTC) + return 0; + + GetSystemTimePreciseAsFileTime(&ft); + ticks = ((uint64_t)ft.dwHighDateTime << 32) | ft.dwLowDateTime; + ticks -= EPOCH; + now->tv_sec = ticks / TICKS_PER_SEC; + now->tv_nsec = (ticks - now->tv_sec * TICKS_PER_SEC) * NS_PER_TICK; + return base; +} + +#define timespec_get(ts, base) rte_timespec_get(ts, base) + +#endif /* RTE_TOOLCHAIN_GCC */ #endif /* _RTE_OS_SHIM_ */ -- 2.29.3