From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: rdtsc() in kvm-unit-tests on x86 Date: Mon, 10 Aug 2015 16:47:44 +0200 Message-ID: <55C8B990.7000600@redhat.com> References: <55C86898.3000003@redhat.com> <55C8ADF0.8040204@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: Christoffer Dall , KVM General , Shih-Wei Li To: Jintack Lim Return-path: Received: from mx1.redhat.com ([209.132.183.28]:44509 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753150AbbHJOrt (ORCPT ); Mon, 10 Aug 2015 10:47:49 -0400 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On 10/08/2015 16:14, Jintack Lim wrote: >> > Yes, you just use the TSC. :) However, you first have to check that the >> > TSC is consistent across CPUs. On older machines it's not, but the >> > kernel can detect it. > Thanks, Paolo. > > What would be the best way to check if TSC is consistent across CPUs? You need to have boot_cpu_has(X86_FEATURE_CONSTANT_TSC) and boot_cpu_has(X86_FEATURE_NONSTOP_TSC). However, I would just use TAI (ktime_get_clocktai). x86 KVM provides a paravirtual interface that synchronizes CLOCK_TAI with the host, and using it is the simplest way to get synchronized times between the host and the guest. Paolo > Is it synchronized in nano second (or even cpu clock cycle) resolution? > > To get synchronized tsc across the host and the guest, > just calling rdtscll() in host and guest would be enough?