From patchwork Fri Aug 27 05:49:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 136651 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o7R5nZfn002744 for ; Fri, 27 Aug 2010 05:49:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752914Ab0H0Ftd (ORCPT ); Fri, 27 Aug 2010 01:49:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38125 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752461Ab0H0Ftd (ORCPT ); Fri, 27 Aug 2010 01:49:33 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7R5nWY0023481 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 27 Aug 2010 01:49:32 -0400 Received: from [127.0.1.1] (dhcp-65-37.nay.redhat.com [10.66.65.37]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7R5nUY5031436; Fri, 27 Aug 2010 01:49:30 -0400 Subject: [PATCH kvm-unit-test 3/6] Export tsc related helpers To: mtosatti@redhat.com, avi@redhat.com, kvm@vger.kernel.org From: Jason Wang Cc: glommer@redhat.com Date: Fri, 27 Aug 2010 13:49:29 +0800 Message-ID: <20100827054928.7409.84735.stgit@FreeLancer> In-Reply-To: <20100827054733.7409.63882.stgit@FreeLancer> References: <20100827054733.7409.63882.stgit@FreeLancer> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 27 Aug 2010 05:49:35 +0000 (UTC) diff --git a/lib/x86/processor.h b/lib/x86/processor.h index 67d7ca5..c348808 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -258,4 +258,26 @@ static inline void sti(void) asm volatile ("sti"); } +static inline unsigned long long rdtsc() +{ + long long r; + +#ifdef __x86_64__ + unsigned a, d; + + asm volatile ("rdtsc" : "=a"(a), "=d"(d)); + r = a | ((long long)d << 32); +#else + asm volatile ("rdtsc" : "=A"(r)); +#endif + return r; +} + +static inline void wrtsc(u64 tsc) +{ + unsigned a = tsc, d = tsc >> 32; + + asm volatile("wrmsr" : : "a"(a), "d"(d), "c"(0x10)); +} + #endif diff --git a/x86/tsc.c b/x86/tsc.c index 394a9c6..58f332d 100644 --- a/x86/tsc.c +++ b/x86/tsc.c @@ -1,19 +1,5 @@ #include "libcflat.h" - -u64 rdtsc(void) -{ - unsigned a, d; - - asm volatile("rdtsc" : "=a"(a), "=d"(d)); - return a | (u64)d << 32; -} - -void wrtsc(u64 tsc) -{ - unsigned a = tsc, d = tsc >> 32; - - asm volatile("wrmsr" : : "a"(a), "d"(d), "c"(0x10)); -} +#include "processor.h" void test_wrtsc(u64 t1) { diff --git a/x86/vmexit.c b/x86/vmexit.c index 84c384d..551083d 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -3,21 +3,6 @@ #include "smp.h" #include "processor.h" -static inline unsigned long long rdtsc() -{ - long long r; - -#ifdef __x86_64__ - unsigned a, d; - - asm volatile ("rdtsc" : "=a"(a), "=d"(d)); - r = a | ((long long)d << 32); -#else - asm volatile ("rdtsc" : "=A"(r)); -#endif - return r; -} - static unsigned int inl(unsigned short port) { unsigned int val;