From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stable-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 6AEAAA0524
	for <public@inbox.dpdk.org>; Wed,  5 May 2021 21:12:24 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 5D3C541104;
	Wed,  5 May 2021 21:12:24 +0200 (CEST)
Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182])
 by mails.dpdk.org (Postfix) with ESMTP id C9B07410E1;
 Wed,  5 May 2021 21:12:17 +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 0C75920B800A;
 Wed,  5 May 2021 12:12:17 -0700 (PDT)
DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0C75920B800A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com;
 s=default; t=1620241937;
 bh=ZDBOm+Ks9XVnmPq8hedt8B4QABCoUGBWGUlNOPpt30I=;
 h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
 b=ljMCUH10l6PITkYcHreJX9W+/eJbC5QzRx/R2GHF+mCK2SpWBKb04vpLkfYOaHg7U
 Rz/g15lPywgfvh+NQ/90CvDGfiGTQl26FItAkkqVOfId1lDc/ZNr866oeRDazNA+sg
 DVu0K/GUSJfIEhDOBJMIXT7vFfjnakLRgKcQTs6g=
From: Jie Zhou <jizh@linux.microsoft.com>
To: dev@dpdk.org
Cc: dmitry.kozliuk@gmail.com, xiaoyun.li@intel.com, roretzla@microsoft.com,
 talshn@nvidia.com, pallavi.kadam@intel.com, thomas@monjalon.net,
 bruce.richardson@intel.com, ferruh.yigit@intel.com,
 konstantin.ananyev@intel.com, stable@dpdk.org
Date: Wed,  5 May 2021 12:12:05 -0700
Message-Id: <1620241931-28435-5-git-send-email-jizh@linux.microsoft.com>
X-Mailer: git-send-email 1.8.3.1
In-Reply-To: <1620241931-28435-1-git-send-email-jizh@linux.microsoft.com>
References: <1620236174-10676-1-git-send-email-jizh@linux.microsoft.com>
 <1620241931-28435-1-git-send-email-jizh@linux.microsoft.com>
Subject: [dpdk-stable] [PATCH v13 04/10] 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 <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
Errors-To: stable-bounces@dpdk.org
Sender: "stable" <stable-bounces@dpdk.org>

Add clock_gettime on Windows in rte_os_shim.h

Signed-off-by: Jie Zhou <jizh@microsoft.com>
Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
---
 lib/eal/windows/include/rte_os_shim.h | 38 +++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
index 3763cae62..cd1f53dfa 100644
--- a/lib/eal/windows/include/rte_os_shim.h
+++ b/lib/eal/windows/include/rte_os_shim.h
@@ -77,4 +77,42 @@ 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
+/* High-resolution timer from the CPU. */
+#define CLOCK_PROCESS_CPUTIME_ID        2
+/* Thread-specific CPU-time clock. */
+#define CLOCK_THREAD_CPUTIME_ID         3
+
+#define NS_PER_SEC 1E9
+
+typedef int clockid_t;
+
+static inline int
+rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
+{
+	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:
+		if (QueryPerformanceFrequency(&pf) == 0)
+			return -1;
+		if (QueryPerformanceCounter(&pc) == 0)
+			return -1;
+		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.30.0.vfs.0.2