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 4A69CA0A0C for ; Tue, 29 Jun 2021 22:50:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2FADB41221; Tue, 29 Jun 2021 22:50:33 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 06313411F4; Tue, 29 Jun 2021 22:50:27 +0200 (CEST) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 517FD20B83DE; Tue, 29 Jun 2021 13:50:26 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 517FD20B83DE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1624999826; bh=YZxPzszlEGhbeIWXbKTngU0KhpQPAujwg0XLJU5DKG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nTDVr+lxWQIa4FII6rAP4/oJ6yrhjrjdJMn3nChXnfgiYwU50KKKNw42RKGL33g+R HZY/dlsHvASVNXriplUGIrI83rPNy+BSzjlgFxeisGW+qF9YBLGPTeyAEFwhdn6Abp ESVMWf+AHy5iIr6EGzMJY/E4IS/KWhQRssy1/yIQ= From: Jie Zhou To: dev@dpdk.org Cc: dmitry.kozliuk@gmail.com, xiaoyun.li@intel.com, roretzla@microsoft.com, talshn@nvidia.com, pallavi.kadam@intel.com, andrew.rybchenko@oktetlabs.ru, thomas@monjalon.net, bruce.richardson@intel.com, ferruh.yigit@intel.com, konstantin.ananyev@intel.com, stable@dpdk.org Date: Tue, 29 Jun 2021 13:50:17 -0700 Message-Id: <1624999822-16149-5-git-send-email-jizh@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1624999822-16149-1-git-send-email-jizh@linux.microsoft.com> References: <1624998226-12220-1-git-send-email-jizh@linux.microsoft.com> <1624999822-16149-1-git-send-email-jizh@linux.microsoft.com> Subject: [dpdk-stable] [PATCH v16 4/9] eal/Windows: add clock_gettime on Windows X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Add clock_gettime on Windows in rte_os_shim.h Signed-off-by: Jie Zhou Acked-by: Dmitry Kozlyuk --- lib/eal/windows/include/rte_os_shim.h | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h index 824d9748ba..33619745ab 100644 --- a/lib/eal/windows/include/rte_os_shim.h +++ b/lib/eal/windows/include/rte_os_shim.h @@ -77,4 +77,37 @@ rte_timespec_get(struct timespec *now, int base) #endif /* RTE_TOOLCHAIN_GCC */ +/* Identifier for system-wide realtime clock. */ +#define CLOCK_REALTIME 0 +/* Monotonic system-wide clock. */ +#define CLOCK_MONOTONIC 1 + +typedef int clockid_t; + +static inline int +rte_clock_gettime(clockid_t clock_id, struct timespec *tp) +{ + const int NS_PER_SEC = 1E9; + LARGE_INTEGER pf, pc; + LONGLONG nsec; + + switch (clock_id) { + case CLOCK_REALTIME: + if (timespec_get(tp, TIME_UTC) != TIME_UTC) + return -1; + return 0; + case CLOCK_MONOTONIC: + QueryPerformanceFrequency(&pf); + QueryPerformanceCounter(&pc); + + nsec = pc.QuadPart * NS_PER_SEC / pf.QuadPart; + tp->tv_sec = nsec / NS_PER_SEC; + tp->tv_nsec = nsec - tp->tv_sec * NS_PER_SEC; + return 0; + default: + return -1; + } +} +#define clock_gettime(clock_id, tp) rte_clock_gettime(clock_id, tp) + #endif /* _RTE_OS_SHIM_ */ -- 2.31.0.vfs.0.1