From patchwork Thu Sep 9 01:38:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12482193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9725C433EF for ; Thu, 9 Sep 2021 01:42:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 9578A610E8 for ; Thu, 9 Sep 2021 01:42:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9578A610E8 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1eYJ7HWfkV5h2I/kcdTzefoQ8adhRSW3MpEFgwQeQz8=; b=WYffXVm9mJb8qlZ0Tk3Z78Qh+U tMuXUujiDRIot9StTpVKRpvpdD+uGA2RJR+OLdExeIXiQZQD6EOGxlaplHuv+r7B8fxk7qg+Gx1ug IXi9F3fCxy9TCYrA6z6WMqIEanitfDlKbbEGrjrxRcsLToicvY1JuJRcCjxAuGRHThxZtjEc2s+iX OjLCUDU5Zuzf9GR1Yjj3alkpdEtY76ggiA7At8Zlu4JDpA4Map3sCd3mUE8y7rRVDqRnImdwdzRLc 4AT+Ci0c38fIKB/XWdxw9U4YKERjIZbx+YSX/PKrIxDVQSQ+eVz2HlFnvdLAocAX7ifJLoY3mPluP /aqMGQVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mO93Q-007wBP-JD; Thu, 09 Sep 2021 01:40:41 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mO91Z-007vOS-Ir for linux-arm-kernel@lists.infradead.org; Thu, 09 Sep 2021 01:38:46 +0000 Received: by mail-pj1-x104a.google.com with SMTP id a12-20020a17090aa50cb0290178fef5c227so225157pjq.1 for ; Wed, 08 Sep 2021 18:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=hjRX/HftaWd94e+jvOSEuHmijk3nZocmEtVUiH9mvr8=; b=DNT8H+P/i3+0pP+A8ae3zx+/69e/d6GKxdp5tnytAlBYxL1bysblA3Z96zvM7faRnp MiPxYxeza9JLHN0GpF4GmSXez3T0p4LoZRVFrVHQYzEr0LcPVUlKEELrUiWxD6I0A9Wm taOxz6ZoahTr8qdnhqB/tnCUY5TNl9VfVe5mDKpPeuQeDd5EQckZgFf63OfLJ5Pvjd0e IM/ym6YPja6fesLQKlJwdRY5BdXDUXU7h6AVrtoCG6Pmgk0KHvtPv9klWAhie36Uqena wWc0B+bDczYGE1Sq2/AfitLnfQKqzh5MeXwN4J65tKUXEmoCgUXw+E0W60fmyDJKwhst rOzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=hjRX/HftaWd94e+jvOSEuHmijk3nZocmEtVUiH9mvr8=; b=bN8/B29IxENMTdqWDTtWUHeRdK0EFUfV2PbOKWmKNxpR4SducK0ussrnBF+rOO8/R9 3w4THAuAaFQdy+/FkUASeGi1qK70p/ZtDqslafpKeb7ykYhwFR4mCAHGIqi/5lHg8Out sOH8KfMyuIE/KYOKZQAVgWrt69+24p2kpVJBPDen7NeunHPvAzZEc3C/wXd9cYv1Mzrd MFhulSDFe2uP7oSHiFRQ/OCsVamwRnnDn25dMFbG+Vwstb19fY2bQ/HCyH9/v/b1X6an g8589LOLMtoEIm5k7dvkzKaXrk3ymB7oxtnPKERAhNMI0C9S4/X7PUfbBtCWYvOuXQYx +PkA== X-Gm-Message-State: AOAM530353D7AQa1DDglKeQrlV03Upztr0oaGZ+VfJR5yjNkSDkS1xlN kNrgsuPjX4nyOkegFUPdz8h17k3L7EEy X-Google-Smtp-Source: ABdhPJyDh2cPwprGNDmaMLhS9RKCSqm8CaY83z9TCFAffNsjqNFL2DJ5xQrC3RTO9+d6S+9VLvSevr3OyarG X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:902:a415:b029:129:5342:eab7 with SMTP id p21-20020a170902a415b02901295342eab7mr420693plq.26.1631151521851; Wed, 08 Sep 2021 18:38:41 -0700 (PDT) Date: Thu, 9 Sep 2021 01:38:07 +0000 In-Reply-To: <20210909013818.1191270-1-rananta@google.com> Message-Id: <20210909013818.1191270-8-rananta@google.com> Mime-Version: 1.0 References: <20210909013818.1191270-1-rananta@google.com> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog Subject: [PATCH v4 07/18] KVM: arm64: selftests: Add basic support to generate delays From: Raghavendra Rao Ananta To: Paolo Bonzini , Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210908_183845_672018_EFBCE419 X-CRM114-Status: GOOD ( 12.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add udelay() support to generate a delay in the guest. The routines are derived and simplified from kernel's arch/arm64/lib/delay.c. Signed-off-by: Raghavendra Rao Ananta Reviewed-by: Andrew Jones Reviewed-by: Oliver Upton --- .../selftests/kvm/include/aarch64/delay.h | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/aarch64/delay.h diff --git a/tools/testing/selftests/kvm/include/aarch64/delay.h b/tools/testing/selftests/kvm/include/aarch64/delay.h new file mode 100644 index 000000000000..329e4f5079ea --- /dev/null +++ b/tools/testing/selftests/kvm/include/aarch64/delay.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * ARM simple delay routines + */ + +#ifndef SELFTEST_KVM_ARM_DELAY_H +#define SELFTEST_KVM_ARM_DELAY_H + +#include "arch_timer.h" + +static inline void __delay(uint64_t cycles) +{ + enum arch_timer timer = VIRTUAL; + uint64_t start = timer_get_cntct(timer); + + while ((timer_get_cntct(timer) - start) < cycles) + cpu_relax(); +} + +static inline void udelay(unsigned long usec) +{ + __delay(usec_to_cycles(usec)); +} + +#endif /* SELFTEST_KVM_ARM_DELAY_H */