From patchwork Mon Mar 23 13:36:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Norbert Manthey X-Patchwork-Id: 11452983 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 8BE881392 for ; Mon, 23 Mar 2020 13:39:44 +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 66F5720735 for ; Mon, 23 Mar 2020 13:39:44 +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="qpZfeq0n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66F5720735 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 1jGNHe-0000cb-Nv; Mon, 23 Mar 2020 13:38:26 +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 1jGNHc-0000cD-Pa for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 13:38:24 +0000 X-Inumbo-ID: 91471062-6d0b-11ea-82d5-12813bfff9fa Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 91471062-6d0b-11ea-82d5-12813bfff9fa; Mon, 23 Mar 2020 13:38:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1584970704; x=1616506704; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=z/DoFgB6ZCcaWgWbVny7toMvgGDC5SXUHgrw+cdeKno=; b=qpZfeq0nB/hYgLAD7UuBZAMVULcUnKlGgL/vhFqS70daTXgvafyggFZe DQcE+kJqwoQA+VkPf8UIvDliczwVVdEUCqeqVckOylkvwP4l549lUEfBq jNmsQwooJPX1QL68r/HN0muVVwd3pGAozzClUWjV0bLcCjtoo1OGI7jaZ Q=; IronPort-SDR: 41ky9xrDQqUFQg0UYXLck/YPsU/jruoM5vqOnjMMom1EQPdEy8f/g8AO1hd8rQ+srvwV6ysPjM aaksbrhqtzSQ== X-IronPort-AV: E=Sophos;i="5.72,296,1580774400"; d="scan'208";a="34295816" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-67b371d8.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 23 Mar 2020 13:38:22 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1a-67b371d8.us-east-1.amazon.com (Postfix) with ESMTPS id 9574DA299B; Mon, 23 Mar 2020 13:38:21 +0000 (UTC) Received: from EX13D05EUC001.ant.amazon.com (10.43.164.118) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Mon, 23 Mar 2020 13:38:21 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D05EUC001.ant.amazon.com (10.43.164.118) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Mar 2020 13:38:19 +0000 Received: from u6fc700a6f3c650.ant.amazon.com (10.95.138.2) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Mon, 23 Mar 2020 13:38:16 +0000 From: Norbert Manthey To: Andrew Cooper , Date: Mon, 23 Mar 2020 14:36:58 +0100 Message-ID: <20200323133701.21728-2-nmanthey@amazon.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323133701.21728-1-nmanthey@amazon.de> References: <20200323133701.21728-1-nmanthey@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH XTF benchmark v1 1/4] categories: add benchmark 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: Pawel Wieczorkiewicz , Norbert Manthey Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" As XTF allows to write tests that interact with the hypervisor, we would like to use this capability to implement micro benchmarks, so that we can measure the performance impact of modifications to the hypervisor. This change introduces a category benchmark, which can be used as container for tests of this kind. Signed-off-by: Norbert Manthey --- build/common.mk | 2 +- xtf-runner | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/common.mk b/build/common.mk --- a/build/common.mk +++ b/build/common.mk @@ -1,4 +1,4 @@ -ALL_CATEGORIES := special functional xsa utility in-development +ALL_CATEGORIES := special functional xsa utility in-development benchmark ALL_ENVIRONMENTS := pv64 pv32pae hvm64 hvm32pae hvm32pse hvm32 diff --git a/xtf-runner b/xtf-runner --- a/xtf-runner +++ b/xtf-runner @@ -43,7 +43,7 @@ def exit_code(state): # All test categories default_categories = set(("functional", "xsa")) -non_default_categories = set(("special", "utility", "in-development")) +non_default_categories = set(("special", "utility", "in-development", "benchmark")) all_categories = default_categories | non_default_categories # All test environments From patchwork Mon Mar 23 13:36:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Norbert Manthey X-Patchwork-Id: 11452987 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 7F1421392 for ; Mon, 23 Mar 2020 13:39:57 +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 5024F20735 for ; Mon, 23 Mar 2020 13:39:57 +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="MD3WKLdV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5024F20735 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 1jGNHm-0000dz-0q; Mon, 23 Mar 2020 13:38:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jGNHl-0000dk-9T for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 13:38:33 +0000 X-Inumbo-ID: 963e5526-6d0b-11ea-92cf-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 963e5526-6d0b-11ea-92cf-bc764e2007e4; Mon, 23 Mar 2020 13:38:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1584970713; x=1616506713; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=MdOyL29AYTHsWMpNZ5/kM3iG2cT5KMAOOZ0LlLh7nN8=; b=MD3WKLdVZZoFVtzQkmvCsiA1/AxlZ1q9eu71b7JKhqhqcOnFJ89u0pPr fpspt5L5GeA+R37Cyc/t0gFw1rJuWZP3v3MPghcYZ+3WCiKdUilmpxj0y hC+rdasFEQ6UqaaSOJ40EPEi1lM2H28CrH5g8jzf9tbWEpt1wSwGb68SI k=; IronPort-SDR: yoaByQ4Z2ZqPmySFmxd59FTnLMwQ1g7RhnX45omRipqKZe2zOc68wXStVgJpGi8wbFQ2BUqpj7 yRiWTR8teDrA== X-IronPort-AV: E=Sophos;i="5.72,296,1580774400"; d="scan'208";a="32897681" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 23 Mar 2020 13:38:31 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com (Postfix) with ESMTPS id DEE14A1889; Mon, 23 Mar 2020 13:38:29 +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.1236.3; Mon, 23 Mar 2020 13:38:29 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D05EUB003.ant.amazon.com (10.43.166.253) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Mar 2020 13:38:28 +0000 Received: from u6fc700a6f3c650.ant.amazon.com (10.95.138.2) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Mon, 23 Mar 2020 13:38:25 +0000 From: Norbert Manthey To: Andrew Cooper , Date: Mon, 23 Mar 2020 14:36:59 +0100 Message-ID: <20200323133701.21728-3-nmanthey@amazon.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323133701.21728-1-nmanthey@amazon.de> References: <20200323133701.21728-1-nmanthey@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH XTF benchmark v1 2/4] time: add stubs 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: Pawel Wieczorkiewicz , Paul Semel , Norbert Manthey Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" To measure how long a certain interaction takes, we need time primitives. This commit introduces these primitives, so that future tests can use the gettimeofday function to retrieve the current time. Signed-off-by: Paul Semel Signed-off-by: Norbert Manthey --- build/files.mk | 1 + common/time.c | 203 +++++++++++++++++++++++++++++++++++++++++++++ include/xtf/time.h | 66 +++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 common/time.c create mode 100644 include/xtf/time.h diff --git a/build/files.mk b/build/files.mk --- 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 --- /dev/null +++ b/common/time.c @@ -0,0 +1,203 @@ +#include +#include +#include +#include + +/* This function was taken from mini-os source code [tag xen-RELEASE-4.11.1] + **************************************************************************** + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge + * (C) 2002-2003 - Keir Fraser - University of Cambridge + * (C) 2005 - Grzegorz Milos - Intel Research Cambridge + * (C) 2006 - Robert Kaiser - FH Wiesbaden + **************************************************************************** + * + * File: time.c + * Author: Rolf Neugebauer and Keir Fraser + * Changes: Grzegorz Milos + * + * Description: Simple time and timer functions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +/* 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; +} + +/* 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); +} + +/* 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; +} + +#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 + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/xtf/time.h b/include/xtf/time.h new file mode 100644 --- /dev/null +++ b/include/xtf/time.h @@ -0,0 +1,66 @@ +/** + * @file include/xtf/time.h + * + * Time management + */ +#ifndef XTF_TIME_H +# define XTF_TIME_H + +#include + +static inline uint64_t rdtscp (void) { + unsigned int low, high; + asm volatile ("rdtscp" : "=a" (low), "=d" (high) :: "ecx"); + return ((uint64_t) high << 32) | low; +} + +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); + +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 */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Mon Mar 23 13:37:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Norbert Manthey X-Patchwork-Id: 11452989 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 DDAA21667 for ; Mon, 23 Mar 2020 13:40:26 +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 B7F5820735 for ; Mon, 23 Mar 2020 13:40:26 +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="iem70URK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B7F5820735 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 1jGNI5-0000if-B7; Mon, 23 Mar 2020 13:38:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jGNI3-0000iD-Vn for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 13:38:52 +0000 X-Inumbo-ID: a1b85a8c-6d0b-11ea-a6c1-bc764e2007e4 Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a1b85a8c-6d0b-11ea-a6c1-bc764e2007e4; Mon, 23 Mar 2020 13:38:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1584970731; x=1616506731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=z8dz4h3mXSy6ZGzFUZMYSMXvNQuf3lLok71VJ3FGFcY=; b=iem70URKFdKotb6tO9x7kVxrh1HB1WydP99qTU+NrVzheg5IyNkTtN5I aSTQtuFOg4Nmn37ymwi3SHa/VheZ9R/5LdVg8M4SzPz1Kx/3M0cRf7zUS R+hQqRLfV1/Ce+dvyA9P0TXOpJJrjgxuv+QHegkeN5pLl0a5Nay6mhm9E 0=; IronPort-SDR: EROhmyWDUx4u3ocGRSjK9aiuFqfgYKmlV7Dc3n43iYLwwMMAws6EKWk623Utqsx8KWG/wGHwcc CB/a75aD9tXg== X-IronPort-AV: E=Sophos;i="5.72,296,1580774400"; d="scan'208";a="23770896" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-2c665b5d.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 23 Mar 2020 13:38:39 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-2c665b5d.us-east-1.amazon.com (Postfix) with ESMTPS id 833F2A21A8; Mon, 23 Mar 2020 13:38:39 +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.1236.3; Mon, 23 Mar 2020 13:38:39 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D05EUB003.ant.amazon.com (10.43.166.253) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Mar 2020 13:38:38 +0000 Received: from u6fc700a6f3c650.ant.amazon.com (10.95.138.2) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Mon, 23 Mar 2020 13:38:35 +0000 From: Norbert Manthey To: Andrew Cooper , Date: Mon, 23 Mar 2020 14:37:00 +0100 Message-ID: <20200323133701.21728-4-nmanthey@amazon.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323133701.21728-1-nmanthey@amazon.de> References: <20200323133701.21728-1-nmanthey@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH XTF benchmark v1 3/4] time: provide measurement template 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: Pawel Wieczorkiewicz , Norbert Manthey Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The added function measure_performance allows to measure the run time of a function, by computing the average time it takes to call that function a given number of retries. The measured total time is returned in nano seconds. Furthermore, the value is printed via printk in a fixed format, to allow processing the output further. This format is, where average-time provides ns with ps granularity: perf test_name ns Signed-off-by: Norbert Manthey --- common/time.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++ include/xtf/time.h | 15 +++++++++ 2 files changed, 91 insertions(+) diff --git a/common/time.c b/common/time.c --- a/common/time.c +++ b/common/time.c @@ -192,6 +192,82 @@ 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 measure_performance(const char* test_name, + const char* function_name, + function_under_test_t call, + unsigned long measure_seconds, + unsigned long callibration_calls, + int print_times) +{ + unsigned long start, end; // time stamps for before and after the execution + unsigned long calibration_ns, total_measured_ns, avg_ns, avg_ps_fraction; + unsigned long counter; + unsigned long measure_calls; + int rc = 0; + + + /* Calibrate by measuring time for given amount of callibration calls*/ + printk("Calibrate %s by calling %lu times\n", function_name, + callibration_calls); + start = rdtscp(); + for(counter = 0; counter < callibration_calls; ++ counter) + { + rc = call(); + } + end = rdtscp(); + + /* Calculate the total number in nano seconds */ + calibration_ns = cycles2nsec(end - start); + + /* Calculate number of calls for about measure_seconds based on + (callibration_calls / calibration_ns) equals + (measure_calls / (measure_seconds * 1000 * 1000 * 1000)) */ + measure_calls = ((measure_seconds * 1000UL * 1000UL * 1000UL) + / calibration_ns) * callibration_calls; + + printk("Measure %s by calling %lu times\n", function_name, measure_calls); + + /* Perform all calls, measure start and end time */ + start = rdtscp(); + for(counter = 0; counter < measure_calls; ++ counter) + { + rc = call(); + } + end = rdtscp(); + + /* Calculate the total number in nano seconds */ + total_measured_ns = cycles2nsec(end - start); + avg_ns = total_measured_ns / measure_calls; + avg_ps_fraction = (total_measured_ns / (measure_calls/1000)) % 1000; + + if(print_times) + { + /* Show the result of the last query */ + printk("%s's last return value: %d\n", function_name, rc); + + /* Print average time and total time */ + printk("Avg %s call time: avg: %ld.%s%ld ns total: %ld ns\n", + function_name, avg_ns, + avg_ps_fraction < 10 ? "00" : (avg_ps_fraction < 100 ? "0" : ""), + avg_ps_fraction, total_measured_ns); + + /* Print performance value */ + printk("perf %s %ld.%s%ld ns\n", test_name, avg_ns, + avg_ps_fraction < 10 ? "00" : (avg_ps_fraction < 100 ? "0" : ""), + avg_ps_fraction); + } + + /* Return average run time in pico seconds */ + return avg_ns * 1000 + avg_ps_fraction; +} + /* * Local variables: * mode: C diff --git a/include/xtf/time.h b/include/xtf/time.h --- a/include/xtf/time.h +++ b/include/xtf/time.h @@ -53,6 +53,21 @@ int gettimeofday(struct timeval *tp); /* This returns the current epoch time */ #define NOW() current_time() +unsigned long cycles2nsec(uint64_t cycles); + +/* Signature of a function to be called for measurement */ +typedef int (*function_under_test_t)(void); + +/* Measure the time it takes to call the passed function. Measure for a given + amount of time after calibrating for a given amount of calls. Returns the + average run time of the measure call in pico seconds. */ +unsigned long measure_performance(const char* test_name, + const char* function_name, + function_under_test_t call, + unsigned long measure_seconds, + unsigned long callibration_calls, + int print_times); + #endif /* XTF_TIME_H */ /* From patchwork Mon Mar 23 13:37:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Norbert Manthey X-Patchwork-Id: 11452991 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 AAD001392 for ; Mon, 23 Mar 2020 13:40:34 +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 86C6720735 for ; Mon, 23 Mar 2020 13:40:34 +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="hvaQEC0O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86C6720735 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 1jGNIE-0000lj-OA; Mon, 23 Mar 2020 13:39:02 +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 1jGNID-0000lX-MM for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 13:39:01 +0000 X-Inumbo-ID: a781059a-6d0b-11ea-82d5-12813bfff9fa Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a781059a-6d0b-11ea-82d5-12813bfff9fa; Mon, 23 Mar 2020 13:39:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1584970741; x=1616506741; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=mIn+She3Up5TtWgnP2Z/bljW0ooT4ae9labqk5XxODU=; b=hvaQEC0OqDDGiulkxgC5KVoNaNYq6LuU0qc0+hXU8i5iUnZGOzdwy0UK +3APWe0gJQkszHLbRDPIQjLJ9LV97M3Xf8hGHlCiHeZYbGNKQPi7lrAjq U/ykWeF8w7vIw/d2pZjVtm21kVRsuC6UrDQ0Umpk/ow73HVfY7/xhdOLo 4=; IronPort-SDR: 3JOhp+xvPSr+nI2Xri7IoAMRy2rJmkDSzvasn5YMH2Ddmucw/UceVOq6eUPCzOwsYo1gyuOuNi PrTMPGmR3yqQ== X-IronPort-AV: E=Sophos;i="5.72,296,1580774400"; d="scan'208";a="22498450" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-303d0b0e.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 23 Mar 2020 13:38:49 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-303d0b0e.us-east-1.amazon.com (Postfix) with ESMTPS id 3894AA060F; Mon, 23 Mar 2020 13:38:48 +0000 (UTC) Received: from EX13D05EUB004.ant.amazon.com (10.43.166.115) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Mon, 23 Mar 2020 13:38:48 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D05EUB004.ant.amazon.com (10.43.166.115) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Mar 2020 13:38:47 +0000 Received: from u6fc700a6f3c650.ant.amazon.com (10.95.138.2) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Mon, 23 Mar 2020 13:38:44 +0000 From: Norbert Manthey To: Andrew Cooper , Date: Mon, 23 Mar 2020 14:37:01 +0100 Message-ID: <20200323133701.21728-5-nmanthey@amazon.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323133701.21728-1-nmanthey@amazon.de> References: <20200323133701.21728-1-nmanthey@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH XTF benchmark v1 4/4] perf: measure MMUEXT_MARK_SUPER test 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: Pawel Wieczorkiewicz , Norbert Manthey Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" A first simple test is to call a hypercall in a tight loop. To measure implementation aspects of the hypervisor, we picked a hypercall that is not implemented and hence results in a no-op, namely the hypercall mmuext_op with the command MMUEXT_MARK_SUPER. The test calibrates the execution time for 1000 calls to the hypercall, and next calculates the number of calls to take about 5 minutes. Signed-off-by: Norbert Manthey Reviewed-by: Bjoern Doebel --- tests/perf-PV-MMUEXT_MARK_SUPER-noop/Makefile | 9 +++ tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c | 80 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 tests/perf-PV-MMUEXT_MARK_SUPER-noop/Makefile create mode 100644 tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c diff --git a/tests/perf-PV-MMUEXT_MARK_SUPER-noop/Makefile b/tests/perf-PV-MMUEXT_MARK_SUPER-noop/Makefile new file mode 100644 --- /dev/null +++ b/tests/perf-PV-MMUEXT_MARK_SUPER-noop/Makefile @@ -0,0 +1,9 @@ +include $(ROOT)/build/common.mk + +NAME := perf-PV-MMUEXT_MARK_SUPER-noop +CATEGORY := benchmark +TEST-ENVS := pv64 + +obj-perenv += main.o + +include $(ROOT)/build/gen.mk diff --git a/tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c b/tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c new file mode 100644 --- /dev/null +++ b/tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c @@ -0,0 +1,80 @@ +/** + * Copyright (C) Amazon.com, Inc. or its affiliates. + * Author: Norbert Manthey + * + * @file tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c + * @ref test-perf-PV-MMUEXT_MARK_SUPER-noop + * + * @page perf-PV-MMUEXT_MARK_SUPER-noop + * + * This test runs the hypercall mmuext_op with the command MMUEXT_MARK_SUPER in + * a tight loop, and measures how much time it takes for all loops. Finally, the + * test prints this time. + * + * Since this is a performance test, the actual value is furthermore printed + * using the predefined pattern on a separate line. The reported value + * represents the time it takes to run the mmuext_op hypercall in nano seconds. + * The average is calculated by running the call for about 5 minutes. + * + * perf + * + * @see tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c + */ + +/* To improve precision of the measurement, try to run the hypercall for this + amount of seconds. As the time per call can be different for test machines, + we measure the time for the below number of calls, and estimate the number of + calls to perform accordingly. */ +#define MEASUREMENT_SECONDS 300 + +/* This number of calls to the function under test will be used to estimate how + many times we need to call the function to measure for about 5 minutes. */ +#define CALIBRATION_CALLS 1000 + +#include +#include + +const char test_title[] = "Test perf-MMUEXT_MARK_SUPER"; + +/* Use a global struct to avoid local variables in call_MMUEXT_MARK_SUPER */ +mmuext_op_t op = +{ + .cmd = MMUEXT_MARK_SUPER, + .arg1.mfn = 1, +}; + +/* Schedule a no-op hypercall */ +int call_MMUEXT_MARK_SUPER(void) +{ + return hypercall_mmuext_op(&op, 1, NULL, DOMID_SELF); +} + +void test_main(void) +{ + int rc = 0; + + /* Test whether the hypercall is implemented as expected */ + rc = call_MMUEXT_MARK_SUPER(); + if(rc != -EOPNOTSUPP && rc != -EINVAL && rc != -ENOSYS) + return xtf_error("Unexpected MMUEXT_MARK_SUPER, rc %d\n", rc); + + /* Measuring average execution time for given function, and print stats */ + measure_performance(test_title, + "mmuext_op(MMUEXT_MARK_SUPER, ...)", + call_MMUEXT_MARK_SUPER, + MEASUREMENT_SECONDS, + CALIBRATION_CALLS, + 1); + + return xtf_success("Success: performed MMUEXT_MARK_SUPER hypercall with expected result\n"); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */