From patchwork Fri Apr 17 07:05:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11494259 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 0BF5613B2 for ; Fri, 17 Apr 2020 07:07:33 +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 DDC51221EC for ; Fri, 17 Apr 2020 07:07:32 +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="ptbhjimg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDC51221EC 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 1jPL4c-0001gF-EY; Fri, 17 Apr 2020 07:06:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jPL4b-0001g5-9W for xen-devel@lists.xen.org; Fri, 17 Apr 2020 07:06:01 +0000 X-Inumbo-ID: e2279250-8079-11ea-9e09-bc764e2007e4 Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e2279250-8079-11ea-9e09-bc764e2007e4; Fri, 17 Apr 2020 07:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1587107156; x=1618643156; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=FGq21dZDqlyAQXJxV2xTF6vsjs2rXeIGTVUXZZqRLdA=; b=ptbhjimgkFbgqPndDPQ8IHF1jFoLh7ooko+wBKsclEHQr+yHTPPJ50rN 2L/csHrXyzFBcE16TaKDOb31eBXmmKS2QkhJni3UnlqNli044tuP4dDSZ HbX+ir3UBBf1VGyblaqdU5gzrtwhAcwNLSMtw0R0fdLBTlD9nxBXrGDOC U=; IronPort-SDR: rjJzvLVqtRl3y398/t9DcG0j2Zl+/QEbvLLjmG61nbiR07845Oq27V1MnQL0HXGPPxmBq1ysn2 LVWhC2MEWvZw== X-IronPort-AV: E=Sophos;i="5.72,394,1580774400"; d="scan'208";a="26253747" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 17 Apr 2020 07:05:43 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com (Postfix) with ESMTPS id BD700A225C; Fri, 17 Apr 2020 07:05:42 +0000 (UTC) Received: from EX13D02EUC002.ant.amazon.com (10.43.164.14) 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:42 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D02EUC002.ant.amazon.com (10.43.164.14) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 17 Apr 2020 07:05:41 +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:39 +0000 From: Pawel Wieczorkiewicz To: Subject: [XTF 1/6] time: introduce time managment in xtf Date: Fri, 17 Apr 2020 07:05:23 +0000 Message-ID: <20200417070528.48329-2-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" From: Paul Semel This commit introduces basic time management functionality. For synchronization purpose, we do really want to be able to "control" time. Add since_boot_time() that gets the time in nanoseconds from the moment the VM has booted. Signed-off-by: Paul Semel Signed-off-by: Pawel Wieczorkiewicz --- build/files.mk | 1 + common/time.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/xtf/lib.h | 18 ++++++++++++ include/xtf/time.h | 28 ++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 common/time.c create mode 100644 include/xtf/time.h diff --git a/build/files.mk b/build/files.mk index dfa27e4..6286317 100644 --- a/build/files.mk +++ b/build/files.mk @@ -16,6 +16,7 @@ obj-perarch += $(ROOT)/common/libc/vsnprintf.o obj-perarch += $(ROOT)/common/report.o obj-perarch += $(ROOT)/common/setup.o obj-perarch += $(ROOT)/common/xenbus.o +obj-perarch += $(ROOT)/common/time.o obj-perenv += $(ROOT)/arch/x86/decode.o obj-perenv += $(ROOT)/arch/x86/desc.o diff --git a/common/time.c b/common/time.c new file mode 100644 index 0000000..b9a6531 --- /dev/null +++ b/common/time.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include + +/* This function was taken from mini-os source code */ +/* It returns ((delta << shift) * mul_frac) >> 32 */ +static inline uint64_t scale_delta(uint64_t delta, uint32_t mul_frac, int shift) +{ + uint64_t product; +#ifdef __i386__ + uint32_t tmp1, tmp2; +#endif + + if ( shift < 0 ) + delta >>= -shift; + else + delta <<= shift; + +#ifdef __i386__ + __asm__ ( + "mul %5 ; " + "mov %4,%%eax ; " + "mov %%edx,%4 ; " + "mul %5 ; " + "add %4,%%eax ; " + "xor %5,%5 ; " + "adc %5,%%edx ; " + : "=A" (product), "=r" (tmp1), "=r" (tmp2) + : "a" ((uint32_t)delta), "1" ((uint32_t)(delta >> 32)), "2" (mul_frac) ); +#else + __asm__ ( + "mul %%rdx ; shrd $32,%%rdx,%%rax" + : "=a" (product) : "0" (delta), "d" ((uint64_t)mul_frac) ); +#endif + + return product; +} + + +#if defined(__i386__) +uint32_t since_boot_time(void) +#else +uint64_t since_boot_time(void) +#endif +{ + unsigned long old_tsc, tsc; +#if defined(__i386__) + uint32_t system_time; +#else + uint64_t system_time; +#endif + uint32_t ver1, ver2; + + do { + do { + ver1 = shared_info.vcpu_info[0].time.version; + smp_rmb(); + } while ( (ver1 & 1) == 1 ); + + system_time = shared_info.vcpu_info[0].time.system_time; + old_tsc = shared_info.vcpu_info[0].time.tsc_timestamp; + + smp_rmb(); + tsc = rdtscp(); + ver2 = ACCESS_ONCE(shared_info.vcpu_info[0].time.version); + smp_rmb(); + } while ( ver1 != ver2 ); + + system_time += scale_delta(tsc - old_tsc, + shared_info.vcpu_info[0].time.tsc_to_system_mul, + shared_info.vcpu_info[0].time.tsc_shift); + + return system_time; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/xtf/lib.h b/include/xtf/lib.h index 3348464..c3eb10c 100644 --- a/include/xtf/lib.h +++ b/include/xtf/lib.h @@ -54,6 +54,24 @@ void __noreturn panic(const char *fmt, ...) __printf(1, 2); #define ROUNDUP(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#ifdef __GCC_ASM_FLAG_OUTPUTS__ +# define ASM_FLAG_OUT(yes, no) yes +#else +# define ASM_FLAG_OUT(yes, no) no +#endif + +static inline uint64_t rdtsc (void) { + unsigned int low, high; + asm volatile ("rdtsc" : "=a" (low), "=d" (high)); + return ((uint64_t) high << 32) | low; +} + +static inline uint64_t rdtscp (void) { + unsigned int low, high; + asm volatile ("rdtscp" : "=a" (low), "=d" (high) :: "ecx"); + return ((uint64_t) high << 32) | low; +} + void heapsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *), void (*swap)(void *, void *)); diff --git a/include/xtf/time.h b/include/xtf/time.h new file mode 100644 index 0000000..e30d109 --- /dev/null +++ b/include/xtf/time.h @@ -0,0 +1,28 @@ +/** + * @file include/xtf/time.h + * + * Time management + */ +#ifndef XTF_TIME_H +# define XTF_TIME_H + +#include + +#if defined(__i386__) +/* Time from boot in nanoseconds */ +uint32_t since_boot_time(void); +#else +uint64_t since_boot_time(void); +#endif + +#endif /* XTF_TIME_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Fri Apr 17 07:05:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11494263 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 F1B7892C for ; Fri, 17 Apr 2020 07:07:39 +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 CDE7421D94 for ; Fri, 17 Apr 2020 07:07:39 +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="RVeUGLlL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CDE7421D94 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 1jPL4f-0001hG-Nq; Fri, 17 Apr 2020 07:06:05 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jPL4d-0001gm-LW for xen-devel@lists.xen.org; Fri, 17 Apr 2020 07:06:03 +0000 X-Inumbo-ID: e5f79132-8079-11ea-8c80-12813bfff9fa Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e5f79132-8079-11ea-8c80-12813bfff9fa; Fri, 17 Apr 2020 07:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1587107163; x=1618643163; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=UuhJUamVQd+VEFaxWjDQUrzLutylPKzCdCKci7sTFY8=; b=RVeUGLlLP/pEJaD+6PIWi9VAiqzAIz51ndh15kpZWTZhAx4WPy4OgyUd pIdzHyjqqIksfm6Fq/VNl6o87ppQwPX95c7Nc+tCSIoncgYmL0WdLG+lM 69oBytPRP6BbDccQCZsFOz4gtXBc2DfWL7cWT0A8HXBBEyrKoGcJEFgLB o=; IronPort-SDR: HZXgY8bJmz2svV7iz58h+viVh4a+y8Y07WG7YaoCHAnuPRqDVveBIiijfZOwfer/Kr6DcblnPV uVcoYzSMTUfQ== X-IronPort-AV: E=Sophos;i="5.72,394,1580774400"; d="scan'208";a="27348876" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-87a10be6.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 17 Apr 2020 07:05:45 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-87a10be6.us-west-2.amazon.com (Postfix) with ESMTPS id 6C582A24B7; Fri, 17 Apr 2020 07:05:44 +0000 (UTC) Received: from EX13D02EUB002.ant.amazon.com (10.43.166.170) 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:44 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D02EUB002.ant.amazon.com (10.43.166.170) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 17 Apr 2020 07:05:43 +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:41 +0000 From: Pawel Wieczorkiewicz To: Subject: [XTF 2/6] time: add current_time() function to time management Date: Fri, 17 Apr 2020 07:05:24 +0000 Message-ID: <20200417070528.48329-3-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: semelpaul@gmail.com, andrew.cooper3@citrix.com, julien@xen.org, nmanthey@amazon.de, paul@xen.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Paul Semel This function returns the "epoch" time. Signed-off-by: Paul Semel --- common/time.c | 16 ++++++++++++++++ include/xtf/time.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/common/time.c b/common/time.c index b9a6531..7decd07 100644 --- a/common/time.c +++ b/common/time.c @@ -74,6 +74,22 @@ uint64_t since_boot_time(void) return system_time; } +/* This function return the epoch time (number of seconds elapsed + * since Juanary 1, 1970) */ +#if defined(__i386__) +uint32_t current_time(void) +#else +uint64_t current_time(void) +#endif +{ +#if defined(__i386__) + uint32_t seconds = shared_info.wc_sec; +#else + uint64_t seconds = ((uint64_t)shared_info.wc_sec_hi << 32) | shared_info.wc_sec; +#endif + return seconds + (since_boot_time() / 1000000000); +} + /* * Local variables: * mode: C diff --git a/include/xtf/time.h b/include/xtf/time.h index e30d109..52da27a 100644 --- a/include/xtf/time.h +++ b/include/xtf/time.h @@ -11,8 +11,12 @@ #if defined(__i386__) /* Time from boot in nanoseconds */ uint32_t since_boot_time(void); + +uint32_t current_time(void); #else uint64_t since_boot_time(void); + +uint64_t current_time(void); #endif #endif /* XTF_TIME_H */ From patchwork Fri Apr 17 07:05:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11494243 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 911C56CA for ; Fri, 17 Apr 2020 07:06:25 +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 6E918221F7 for ; Fri, 17 Apr 2020 07:06:25 +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="IHlDk+s/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E918221F7 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 1jPL4j-0001iU-1G; Fri, 17 Apr 2020 07:06:09 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jPL4i-0001iJ-LZ for xen-devel@lists.xen.org; Fri, 17 Apr 2020 07:06:08 +0000 X-Inumbo-ID: e6d588fd-8079-11ea-8c80-12813bfff9fa Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e6d588fd-8079-11ea-8c80-12813bfff9fa; Fri, 17 Apr 2020 07:06:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1587107165; x=1618643165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=493GNuIf5KbW+Y/729Kw1IKQ8Uqsew/NWiY7HpkG1hg=; b=IHlDk+s/fHSacLfqJM1ZyUhysyyzv1zhiljbsKiX5C+T2+uj7ZiuIcX5 yxeXjz8iSBpDQ8fSLqfmzhOB4LA/ZsYxkVFbhKY6VAu3DDi2GTIgQ+yEH DPt7St+azVfn42SSIKa+jI8awMzMSBhoQf+cJgd6uxycHhsb6Jv/gGGp3 c=; IronPort-SDR: bB/uFZXPLRh/pPukLbf1/QJKMR4TloS6qG2sZfxHgYCMOuZ1ys2ILsDEwcKqcvWmqOjiZ+9jNp Mmn+b03wsatw== X-IronPort-AV: E=Sophos;i="5.72,394,1580774400"; d="scan'208";a="26002075" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 17 Apr 2020 07:05:47 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com (Postfix) with ESMTPS id 32E3AA24C6; Fri, 17 Apr 2020 07:05:46 +0000 (UTC) Received: from EX13D02EUB001.ant.amazon.com (10.43.166.150) 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:45 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D02EUB001.ant.amazon.com (10.43.166.150) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 17 Apr 2020 07:05:44 +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:43 +0000 From: Pawel Wieczorkiewicz To: Subject: [XTF 3/6] time: add gettimeofday() function to time managment Date: Fri, 17 Apr 2020 07:05:25 +0000 Message-ID: <20200417070528.48329-4-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 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: semelpaul@gmail.com, andrew.cooper3@citrix.com, julien@xen.org, nmanthey@amazon.de, paul@xen.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Paul Semel Signed-off-by: Paul Semel --- common/time.c | 14 ++++++++++++++ include/xtf/time.h | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/common/time.c b/common/time.c index 7decd07..fffae1c 100644 --- a/common/time.c +++ b/common/time.c @@ -90,6 +90,20 @@ uint64_t current_time(void) return seconds + (since_boot_time() / 1000000000); } +/* The POSIX gettimeofday syscall normally takes a second argument, which is + * the timezone (struct timezone). However, it sould be NULL because linux + * doesn't use it anymore. So we need for us to add it in this function + */ +int gettimeofday(struct timeval *tp) +{ + if (!tp) + return -1; + + tp->sec = current_time(); + tp->nsec = shared_info.wc_nsec + (since_boot_time() % 1000000000); + return 0; +} + /* * Local variables: * mode: C diff --git a/include/xtf/time.h b/include/xtf/time.h index 52da27a..e312465 100644 --- a/include/xtf/time.h +++ b/include/xtf/time.h @@ -8,6 +8,16 @@ #include +struct timeval { +#if !defined(__i386__) + uint64_t sec; + uint64_t nsec; +#else + uint32_t sec; + uint32_t nsec; +#endif +}; + #if defined(__i386__) /* Time from boot in nanoseconds */ uint32_t since_boot_time(void); @@ -19,6 +29,8 @@ uint64_t since_boot_time(void); uint64_t current_time(void); #endif +int gettimeofday(struct timeval *tp); + #endif /* XTF_TIME_H */ /* From patchwork Fri Apr 17 07:05:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11494257 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 E335D92C for ; Fri, 17 Apr 2020 07:07:32 +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 BF72121D94 for ; Fri, 17 Apr 2020 07:07:32 +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="jdNkq8/P" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BF72121D94 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 1jPL4o-0001kI-AL; Fri, 17 Apr 2020 07:06:14 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jPL4n-0001k1-Lv for xen-devel@lists.xen.org; Fri, 17 Apr 2020 07:06:13 +0000 X-Inumbo-ID: ec349702-8079-11ea-8c80-12813bfff9fa Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ec349702-8079-11ea-8c80-12813bfff9fa; 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=7z65Bh4Xe0Ehypmwl+K1UUIrCedT+0ZwsHnvKnpUKuo=; b=jdNkq8/P4tIwHc5HqNoq+VfI1uWhFxRffAs6Ba7AhvzPK1ytQe+yBWgi ICbexPFXPs9z3GE8NnLehUerGuXb+G4el+d8/sPIkexqyJPm+VnAZBUAZ +pXl2V2wcaEZ63EgbJEgrKhNvZjPo71nPyFvDEGDaCP432F6wsw5IQ22X I=; IronPort-SDR: ipOWzI3Pz3DD/dajzMiIsbaMbBaQAyA9/mhsuH+7SPxo01uOIPjsRIZkiZbCQteofQXlvabn86 jdhLw+mSKaPw== X-IronPort-AV: E=Sophos;i="5.72,394,1580774400"; d="scan'208";a="27348926" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-baacba05.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 17 Apr 2020 07:06:13 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-baacba05.us-west-2.amazon.com (Postfix) with ESMTPS id B58B1A056D; Fri, 17 Apr 2020 07:06:11 +0000 (UTC) Received: from EX13D02EUC004.ant.amazon.com (10.43.164.117) 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:47 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D02EUC004.ant.amazon.com (10.43.164.117) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 17 Apr 2020 07:05:46 +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:45 +0000 From: Pawel Wieczorkiewicz To: Subject: [XTF 4/6] time: Add helper functions and macros to time management Date: Fri, 17 Apr 2020 07:05:26 +0000 Message-ID: <20200417070528.48329-5-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: semelpaul@gmail.com, andrew.cooper3@citrix.com, julien@xen.org, nmanthey@amazon.de, paul@xen.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Paul Semel Add the following helper functions: - nspin_sleep() - spin_sleep() - mspin_sleep() Add the following helper macros: - sleep() - msleep() - NOW() Signed-off-by: Paul Semel --- common/time.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/xtf/time.h | 16 +++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/common/time.c b/common/time.c index fffae1c..3db1f8f 100644 --- a/common/time.c +++ b/common/time.c @@ -104,6 +104,64 @@ int gettimeofday(struct timeval *tp) return 0; } +#if defined(__i386__) +static inline void nspin_sleep(uint32_t t) +#else +static inline void nspin_sleep(uint64_t t) +#endif +{ + unsigned long end = since_boot_time() + t; + + while ( since_boot_time() < end ) + asm volatile ( "pause" ); +} + +#if defined(__i386__) +static inline void spin_sleep(uint32_t t) +#else +static inline void spin_sleep(uint64_t t) +#endif +{ +#if defined(__i386__) + uint32_t nsec = t * 1000000000; +#else + uint64_t nsec = t * 1000000000ul; +#endif + nspin_sleep(nsec); +} + +#if defined(__i386__) +static inline void mspin_sleep(uint32_t t) +#else +static inline void mspin_sleep(uint64_t t) +#endif +{ +#if defined(__i386__) + uint32_t nsec = t * 1000000; +#else + uint64_t nsec = t * 1000000ul; +#endif + nspin_sleep(nsec); +} + +#if defined(__i386__) +void sleep(uint32_t t) +#else +void sleep(uint64_t t) +#endif +{ + spin_sleep(t); +} + +#if defined(__i386__) +void msleep(uint32_t t) +#else +void msleep(uint64_t t) +#endif +{ + mspin_sleep(t); +} + /* * Local variables: * mode: C diff --git a/include/xtf/time.h b/include/xtf/time.h index e312465..07fcae5 100644 --- a/include/xtf/time.h +++ b/include/xtf/time.h @@ -23,14 +23,30 @@ struct timeval { uint32_t since_boot_time(void); uint32_t current_time(void); + +/* This function takes seconds in parameter */ +void sleep(uint32_t f); + +/* Be careful, this function takes milliseconds in parameter, + * not microseconds ! + */ +void msleep(uint32_t f); #else uint64_t since_boot_time(void); uint64_t current_time(void); + +void sleep(uint64_t f); + +void msleep(uint64_t f); #endif int gettimeofday(struct timeval *tp); + +/* This returns the current epoch time */ +#define NOW() current_time() + #endif /* XTF_TIME_H */ /* 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 */ /* From patchwork Fri Apr 17 07:05:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11494265 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 1F9B313B2 for ; Fri, 17 Apr 2020 07:07:40 +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 F11E1221EC for ; Fri, 17 Apr 2020 07:07:39 +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="Iq05JnjD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F11E1221EC 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 1jPL51-0001s1-4f; Fri, 17 Apr 2020 07:06:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jPL4z-0001rQ-Vh for xen-devel@lists.xen.org; Fri, 17 Apr 2020 07:06:25 +0000 X-Inumbo-ID: f3b57adc-8079-11ea-b4f4-bc764e2007e4 Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f3b57adc-8079-11ea-b4f4-bc764e2007e4; Fri, 17 Apr 2020 07:06:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1587107186; x=1618643186; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=ohM0/A02cQtDxZuWCKtvIr8AsH7i7i/rmvBHra8TnjM=; b=Iq05JnjD0Ksap+A2CMLoa+a+aCdMiyQJ+jkfyeB/osDnSD/mhRK2v8F7 lj1DVW6W239jFO/I1i+8YuBLqeuDoH5kTqn3qWR0aSL2YiPXJbgGvSSBz KtRx/0LMcJ0dGICKMoXZ0vlnHUHSgzcLuDhEbOgbLk5labBs50RpMQhnW Q=; IronPort-SDR: /gCX9Bs9KaV8s7+165BhnxqcrciZ2hP71u0dos2O8eUjPUQxjrJmVL3fhlouF8tIIOa5de3rZq 8Ltkwv+SMVhg== X-IronPort-AV: E=Sophos;i="5.72,394,1580774400"; d="scan'208";a="25912318" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 17 Apr 2020 07:06:14 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com (Postfix) with ESMTPS id D57D3A2747; Fri, 17 Apr 2020 07:06:11 +0000 (UTC) Received: from EX13D05EUB003.ant.amazon.com (10.43.166.253) 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:51 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D05EUB003.ant.amazon.com (10.43.166.253) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 17 Apr 2020 07:05:50 +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:48 +0000 From: Pawel Wieczorkiewicz To: Subject: [XTF 6/6] event_channels: Add EVTCHNOP_bind_vcpu hypercall support Date: Fri, 17 Apr 2020 07:05:28 +0000 Message-ID: <20200417070528.48329-7-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" Signed-off-by: Pawel Wieczorkiewicz --- include/xen/event_channel.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/xen/event_channel.h b/include/xen/event_channel.h index 62ee95a..6253b89 100644 --- a/include/xen/event_channel.h +++ b/include/xen/event_channel.h @@ -2,6 +2,7 @@ #define XEN_PUBLIC_EVENT_CHANNEL_H #define EVTCHNOP_send 4 +#define EVTCHNOP_bind_vcpu 8 #define EVTCHNOP_init_control 11 #define EVTCHNOP_expand_array 12 @@ -22,6 +23,12 @@ struct evtchn_expand_array { uint64_t array_gfn; }; +struct evtchn_bind_vcpu { + /* IN parameters. */ + evtchn_port_t port; + uint32_t vcpu; +}; + #endif /* XEN_PUBLIC_EVENT_CHANNEL_H */ /*