From patchwork Fri Apr 17 07:05:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11494253 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC0096CA for ; Fri, 17 Apr 2020 07:07:22 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8BFC21D94 for ; Fri, 17 Apr 2020 07:07:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="duQ3EvjR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8BFC21D94 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jPL4p-0001lL-K5; Fri, 17 Apr 2020 07:06:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jPL4o-0001kF-8L for xen-devel@lists.xen.org; Fri, 17 Apr 2020 07:06:14 +0000 X-Inumbo-ID: ec55d89a-8079-11ea-b4f4-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ec55d89a-8079-11ea-b4f4-bc764e2007e4; Fri, 17 Apr 2020 07:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1587107173; x=1618643173; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=l/TJTTqBsW2Qk+W7CflHlPQqQTeMk2Ziy87aPeKhtR8=; b=duQ3EvjROmJPZs0ebKxZAr14SUrLCqvIYnKFyPlv5h2q5XtksLi4d7w9 /J/mXl2gnTU/096pjxwQsz7bnPsWVNr54W6nM8R/HdHz8tMEPyCwhTbC/ nsKyRbVuRdIhIux965NZDgcCT94WccLj//B+bY0HhCbpBrA7NBak/VoS+ Q=; IronPort-SDR: QKpZsaYWvK5JQHIwh1KDXnpUuIWKPnO0byJA6yZrOwJCTUeKWStqi424LVyNyHDyZMMrwqMnk0 IiQqFmkj40gg== X-IronPort-AV: E=Sophos;i="5.72,394,1580774400"; d="scan'208";a="37631727" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 17 Apr 2020 07:06:11 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com (Postfix) with ESMTPS id 6EC1BA22CA; Fri, 17 Apr 2020 07:06:11 +0000 (UTC) Received: from EX13D05EUB002.ant.amazon.com (10.43.166.45) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 17 Apr 2020 07:05:49 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D05EUB002.ant.amazon.com (10.43.166.45) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 17 Apr 2020 07:05:48 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 17 Apr 2020 07:05:46 +0000 From: Pawel Wieczorkiewicz To: Subject: [XTF 5/6] time: Add cycles2{n,u,m}sec functions Date: Fri, 17 Apr 2020 07:05:27 +0000 Message-ID: <20200417070528.48329-6-wipawel@amazon.de> X-Mailer: git-send-email 2.16.6 In-Reply-To: <20200417070528.48329-1-wipawel@amazon.de> References: <20200417070528.48329-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: julien@xen.org, paul@xen.org, semelpaul@gmail.com, andrew.cooper3@citrix.com, Pawel Wieczorkiewicz , nmanthey@amazon.de Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" In order to easily translate CPU cycles to time values add the following helpers: - cycles2nsec() - cycles2usec() - cycles2msec() Signed-off-by: Pawel Wieczorkiewicz --- common/time.c | 17 +++++++++++++++++ include/xtf/time.h | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/common/time.c b/common/time.c index 3db1f8f..8f73243 100644 --- a/common/time.c +++ b/common/time.c @@ -162,6 +162,23 @@ void msleep(uint64_t t) mspin_sleep(t); } +unsigned long cycles2nsec(uint64_t cycles) +{ + return scale_delta(cycles, + shared_info.vcpu_info[0].time.tsc_to_system_mul, + shared_info.vcpu_info[0].time.tsc_shift); +} + +unsigned long cycles2usec(uint64_t cycles) +{ + return cycles2nsec(cycles) / 1000; +} + +unsigned long cycles2msec(uint64_t cycles) +{ + return cycles2nsec(cycles) / 1000000; +} + /* * Local variables: * mode: C diff --git a/include/xtf/time.h b/include/xtf/time.h index 07fcae5..6aa1efc 100644 --- a/include/xtf/time.h +++ b/include/xtf/time.h @@ -43,10 +43,13 @@ void msleep(uint64_t f); int gettimeofday(struct timeval *tp); - /* This returns the current epoch time */ #define NOW() current_time() +unsigned long cycles2nsec(uint64_t cycles); +unsigned long cycles2usec(uint64_t cycles); +unsigned long cycles2msec(uint64_t cycles); + #endif /* XTF_TIME_H */ /*