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 D2E6FA0C41; Fri, 16 Apr 2021 19:35:47 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D7AD1161C17; Fri, 16 Apr 2021 19:35:17 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 1815A161B97 for ; Fri, 16 Apr 2021 19:35:09 +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 1F79620B83DA; Fri, 16 Apr 2021 10:35:08 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1F79620B83DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1618594508; bh=/bC+3qlIlUwUJ8PiJG5xk4uIUmrvk3zJWuqRf34MwMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bpMpHPjO2pZKM9eTqnCiVvJs/8fvhZ+Nw+gpR8iLEQ1MUfrlgY5NXd8D+WYdn1D31 Cp++3zxvt0WIogWOpcj6r2BOCJA7su7yt4hjIqVYLL3QrQFuffd8YxEI1bdsTJ8b5N 7W+gULk/IrMY/iQo3V/ilQMLzfAg7NxqwFpEKmlk= 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 Date: Fri, 16 Apr 2021 10:34:57 -0700 Message-Id: <1618594501-23795-6-git-send-email-jizh@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1618594501-23795-1-git-send-email-jizh@linux.microsoft.com> References: <1618334363-15147-1-git-send-email-jizh@linux.microsoft.com> <1618594501-23795-1-git-send-email-jizh@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v4 5/9] app/testpmd: add clock_gettime_monotonic 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_monotonic for testpmd on Windows Signed-off-by: Jie Zhou Signed-off-by: Jie Zhou --- app/test-pmd/config.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index ef0b9784d..018b75381 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -63,6 +63,12 @@ #define NS_PER_SEC 1E9 +#ifdef RTE_EXEC_ENV_WINDOWS +#define _clock_gettime_monotonic(cur_time) clock_gettime_monotonic(&cur_time); +#else +#define _clock_gettime_monotonic(cur_time) clock_gettime(CLOCK_TYPE_ID, &cur_time); +#endif + static char *flowtype_to_str(uint16_t flow_type); static const struct { @@ -170,6 +176,27 @@ print_ethaddr(const char *name, struct rte_ether_addr *eth_addr) printf("%s%s", name, buf); } +#ifdef RTE_EXEC_ENV_WINDOWS +static int +clock_gettime_monotonic(struct timespec *tp) +{ + LARGE_INTEGER pf, pc; + LONGLONG nsec; + + 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; +} +#endif + void nic_stats_display(portid_t port_id) { @@ -186,6 +213,8 @@ nic_stats_display(portid_t port_id) static const char *nic_stats_border = "########################"; + int ret; + if (port_id_is_invalid(port_id, ENABLED_WARN)) { print_valid_ports(); return; @@ -202,7 +231,9 @@ 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) { + + ret = _clock_gettime_monotonic(cur_time); + if (ret == 0) { uint64_t ns; ns = cur_time.tv_sec * NS_PER_SEC; -- 2.30.0.vfs.0.2