From patchwork Fri Apr 23 00:31:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Zhou X-Patchwork-Id: 92042 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C1342A0A02; Fri, 23 Apr 2021 02:32:52 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F046F41DDE; Fri, 23 Apr 2021 02:32:22 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 82B9641ACA for ; Fri, 23 Apr 2021 02:32: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 6685F20B83DA; Thu, 22 Apr 2021 17:32:06 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6685F20B83DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1619137926; bh=lKaMLVidxfsfNZIthKZhlVgYTS35iQ9Y0R+kgWLO7SE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xa0Bw9r8Prd0k9g0+m27YZFHxuM4R8mkwvGQLbkkhpVZPiqj91OasQ0TH+WxSVkJS tTr0cbrtRfZz56w4g694srGPzJcGRoI/m7iuunakO2pxc3F7RXk3k7bYDq8ZFO1xHW 4EGU+qMnC9bRYldeiFYE3cAIGApjZPgDjc7L8N6M= From: Jie Zhou To: dev@dpdk.org Cc: dmitry.kozliuk@gmail.com, xiaoyun.li@intel.com, roretzla@microsoft.com, pallavi.kadam@intel.com, thomas@monjalon.net, bruce.richardson@intel.com, ferruh.yigit@intel.com, konstantin.ananyev@intel.com Date: Thu, 22 Apr 2021 17:31:55 -0700 Message-Id: <1619137920-13449-6-git-send-email-jizh@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619137920-13449-1-git-send-email-jizh@linux.microsoft.com> References: <1618874400-26819-1-git-send-email-jizh@linux.microsoft.com> <1619137920-13449-1-git-send-email-jizh@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v7 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..e21bed576 --- /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_ */