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 12E88A0A02; Tue, 27 Apr 2021 22:03:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 518A0412A8; Tue, 27 Apr 2021 22:02:19 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id E90FE4003E for ; Tue, 27 Apr 2021 22:02:07 +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 871CB20B83D9; Tue, 27 Apr 2021 13:02:06 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 871CB20B83D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1619553726; bh=PGCqqLW407yBIidYjkcK9cB+DA8g7XS92cI1V+Ty+Ow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I+W2T9EWPhEY6E+seaO5dUnN2Yg+cf6dpGRz2ezAvfgAv4nRDTT21mdGaUy+jpSxU 8d5/5fMMthVvaYjtzZAuCh0IkJQb1VR/r92MKbJVfO2xJVhLCf105xKNQs+SSKCvqn +XAIO7KvRFlWG1EiXvy21pAQvKyek4V50oVsEIz4= 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, thomas@monjalon.net, bruce.richardson@intel.com, ferruh.yigit@intel.com, konstantin.ananyev@intel.com Date: Tue, 27 Apr 2021 13:01:56 -0700 Message-Id: <1619553721-5220-6-git-send-email-jizh@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619553721-5220-1-git-send-email-jizh@linux.microsoft.com> References: <1619137920-13449-1-git-send-email-jizh@linux.microsoft.com> <1619553721-5220-1-git-send-email-jizh@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v8 05/10] app/testpmd: add clock_gettime on Windows 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" Add clock_gettime for testpmd on Windows in config.h Signed-off-by: Jie Zhou Signed-off-by: Jie Zhou --- app/test-pmd/config.c | 10 ++----- app/test-pmd/config.h | 66 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 app/test-pmd/config.h diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index e189062ef..9fbf2f5f7 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -54,17 +54,10 @@ #include "testpmd.h" #include "cmdline_mtr.h" +#include "config.h" #define ETHDEV_FWVERS_LEN 32 -#ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */ -#define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW -#else -#define CLOCK_TYPE_ID CLOCK_MONOTONIC -#endif - -#define NS_PER_SEC 1E9 - static char *flowtype_to_str(uint16_t flow_type); static const struct { @@ -205,6 +198,7 @@ nic_stats_display(portid_t port_id) "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes); diff_ns = 0; + if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) { uint64_t ns; diff --git a/app/test-pmd/config.h b/app/test-pmd/config.h new file mode 100644 index 000000000..16599c9d5 --- /dev/null +++ b/app/test-pmd/config.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2021 Microsoft Corporation + */ + +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +#include + +#ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */ +#define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW +#else +#define CLOCK_TYPE_ID CLOCK_MONOTONIC +#endif + +#define NS_PER_SEC 1E9 + +#ifdef RTE_EXEC_ENV_WINDOWS + +/* 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 + +typedef int clockid_t; + +#ifndef clock_gettime +#define clock_gettime _clock_gettime +#endif + +static int +_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; + } +} + +#endif /* RTE_EXEC_ENV_WINDOWS */ + +#endif /* _CONFIG_H_ */ -- 2.30.0.vfs.0.2