Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp125428imn; Wed, 3 Aug 2022 22:57:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR55leGNFtzKpLW9iu6qh3VtFkkRXEAG+pf3HIbtKvYIqPwHxIZRsxJLjOwoTTlxYUqWA6CP X-Received: by 2002:a05:6402:2714:b0:43d:ca4f:d2a2 with SMTP id y20-20020a056402271400b0043dca4fd2a2mr360041edd.185.1659592674338; Wed, 03 Aug 2022 22:57:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659592674; cv=none; d=google.com; s=arc-20160816; b=I/ygdjDhLbwsKg6UGcrTJzuRHhTUtmpjnu1Vi01xffrOhdDzcN8XohJMaGa9Itn+7C sxvYUFJdU+ovbGGmMBSwoam57S69r6CIwRDoUEqshwrBp9dbe7x+yIIYPlFvkM3qQcpr xI9hrTX/x5qoSSxHOqMDQCa2fTs2xSwGmv9G473HLgn8x5Puk7qZf+cyE/ayMHIdeTMq abaq9W4MiZm9el8cedshJdXG/U7PB/ZvxtbRlx5NExDqS+S4hPj85TjcmBgWGK5SVAYh sT2dg8wWr0WeUZKV11C+qbfa8b4xgaGFmM2Q+2sbwghlEuA8Xz325F0oPEqBG47Fa5A2 ShMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zyqJcx8NJZ2pzOZJNSCkEdlDqpxyU6u6BZd0w25XTag=; b=bzKXZrB1uu3gdU3OtelWsE1BCdginKXAgeHNdOFHHVsONcvBreYZ9qVwm9DaCuae2z FGmVGNTS2uOF5oKIrI3IazajyhwkUN87WKVUa3CjuuDjLbZzlfabB8UXgC6zsprIgBga ELv4WRHbq3f9OXbx1gJXZqPTqBtxesah0aq9QV+uM5OwSaGghkSnaH1DpEgFV5+P4189 37FvMoT8lIpqXhUKEEJbDXLa9ASSZDh/sc/C4CG7II/QNsx64hLaqYF1TEkg62pyvhx7 Jr2116lH6Mqc6Ik8N6+T6aPPyXQXkH9TvNwUz16b3vkKnL9NTanODX14HCTJAu+xLMyR ttLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mnyKPNY0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m20-20020a170906581400b007156fe1aa6asi15936814ejq.650.2022.08.03.22.57.29; Wed, 03 Aug 2022 22:57:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mnyKPNY0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238989AbiHDFwv (ORCPT + 99 others); Thu, 4 Aug 2022 01:52:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238937AbiHDFwu (ORCPT ); Thu, 4 Aug 2022 01:52:50 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92502606AA for ; Wed, 3 Aug 2022 22:52:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659592369; x=1691128369; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WWJ2nxf8DmAoNTiMy7J5Jl0UJtHRXxyUfURlVtvvZ/k=; b=mnyKPNY0FV6A8xNkGOn9cl5rAJ4EoN0SOXQ5WZN278Kxn95kpL7rVbUr UXqUH4ZrroxD8H7TTsqnkzfsfKCtgPpwfYlXESSyzaFESME3sctHoBuys uJ2CBHCYAcVL+ZrvV5h1isu2zelkonp4C8A+MEGfaFuxfW7oAr4t6EnGw S4BEM8+SyFfENZqYRMzTUs4qeg9qaQXFyS/gdEqe411FwRWiy2fcgFh0u VIE2cY0h68A66sTvRNQe6Ze9zgqvMJPudFFN9mtz/PcZTPkuKICsz/uX+ RXk9XF/Ha9Nmabeus47nU8JhOfowLCVyf5SEtc5xWHiZcY56O+rLrJij2 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10428"; a="287407994" X-IronPort-AV: E=Sophos;i="5.93,214,1654585200"; d="scan'208";a="287407994" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2022 22:52:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,214,1654585200"; d="scan'208";a="553592910" Received: from louislifei-optiplex-7090.sh.intel.com ([10.239.146.218]) by orsmga003.jf.intel.com with ESMTP; 03 Aug 2022 22:52:46 -0700 From: Fei Li To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, yu1.wang@intel.com, conghui.chen@intel.com, fei1.li@intel.com Subject: [PATCH] x86/acrn: Set up timekeeping Date: Thu, 4 Aug 2022 13:59:03 +0800 Message-Id: <20220804055903.365211-1-fei1.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ACRN Hypervisor reports timing information via CPUID leaf 0x40000010. Get the TSC and CPU frequency via CPUID leaf 0x40000010 and set the kernel values accordingly. Signed-off-by: Fei Li Reviewed-by: Conghui --- arch/x86/include/asm/acrn.h | 14 ++++++++++++++ arch/x86/kernel/cpu/acrn.c | 3 +++ 2 files changed, 17 insertions(+) diff --git a/arch/x86/include/asm/acrn.h b/arch/x86/include/asm/acrn.h index e003a01b7c67..1dd14381bcb6 100644 --- a/arch/x86/include/asm/acrn.h +++ b/arch/x86/include/asm/acrn.h @@ -10,6 +10,15 @@ /* Bit 0 indicates whether guest VM is privileged */ #define ACRN_FEATURE_PRIVILEGED_VM BIT(0) +/* + * Timing Information. + * This leaf returns the current TSC frequency in kHz. + * + * EAX: (Virtual) TSC frequency in kHz. + * EBX, ECX, EDX: RESERVED (reserved fields are set to zero). + */ +#define ACRN_CPUID_TIMING_INFO 0x40000010 + void acrn_setup_intr_handler(void (*handler)(void)); void acrn_remove_intr_handler(void); @@ -21,6 +30,11 @@ static inline u32 acrn_cpuid_base(void) return 0; } +static inline unsigned long acrn_get_tsc_khz(void) +{ + return cpuid_eax(ACRN_CPUID_TIMING_INFO); +} + /* * Hypercalls for ACRN * diff --git a/arch/x86/kernel/cpu/acrn.c b/arch/x86/kernel/cpu/acrn.c index 23f5f27b5a02..485441b7f030 100644 --- a/arch/x86/kernel/cpu/acrn.c +++ b/arch/x86/kernel/cpu/acrn.c @@ -28,6 +28,9 @@ static void __init acrn_init_platform(void) { /* Setup the IDT for ACRN hypervisor callback */ alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_acrn_hv_callback); + + x86_platform.calibrate_tsc = acrn_get_tsc_khz; + x86_platform.calibrate_cpu = acrn_get_tsc_khz; } static bool acrn_x2apic_available(void) base-commit: e0dccc3b76fb35bb257b4118367a883073d7390e -- 2.34.1