From: Dan Magenheimer Subject: [PATCH] minor cleanup of code that writes to TSC Date: Mon, 21 Sep 2009 10:09:44 -0700 (PDT) Message-ID: <452509ba-dce7-47b9-8082-96355dd43beb@default> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "Xen-Devel (E-mail)" List-Id: xen-devel@lists.xenproject.org While working on TSC-handling code, I missed an important piece of code that writes to TSC because it does it differently than other pieces of code. Fix that, and also cleanup a bit to avoid hardcoded constants and use wrmsrl instead of wrmsr plus handwritten 64-bit dismembering code. Signed-off-by: Dan Magenheimer diff -r 72d130772f36 xen/arch/x86/smpboot.c --- a/xen/arch/x86/smpboot.c=09Wed Sep 16 09:30:41 2009 +0100 +++ b/xen/arch/x86/smpboot.c=09Mon Sep 21 11:03:24 2009 -0600 @@ -223,7 +223,7 @@ static void __init synchronize_tsc_bp (v =09=09 * We clear the TSC in the last loop: =09=09 */ =09=09if (i =3D=3D NR_LOOPS-1) -=09=09=09write_tsc(0, 0); +=09=09=09write_tsc(0L); =20 =09=09/* =09=09 * Wait for all APs to leave the synchronization point: @@ -293,7 +293,7 @@ static void __init synchronize_tsc_ap (v =20 =09=09rdtscll(tsc_values[smp_processor_id()]); =09=09if (i =3D=3D NR_LOOPS-1) -=09=09=09write_tsc(0, 0); +=09=09=09write_tsc(0L); =20 =09=09atomic_inc(&tsc_count_stop); =09=09while (atomic_read(&tsc_count_stop) !=3D num_booting_cpus()) mb(); diff -r 72d130772f36 xen/arch/x86/time.c --- a/xen/arch/x86/time.c=09Wed Sep 16 09:30:41 2009 +0100 +++ b/xen/arch/x86/time.c=09Mon Sep 21 11:03:24 2009 -0600 @@ -699,7 +699,7 @@ void cstate_restore_tsc(void) struct cpu_time *t =3D &this_cpu(cpu_time); struct time_scale sys_to_tsc =3D scale_reciprocal(t->tsc_scale); s_time_t stime_delta; - u64 tsc_delta; + u64 new_tsc; =20 if ( boot_cpu_has(X86_FEATURE_NOSTOP_TSC) ) return; @@ -708,9 +708,9 @@ void cstate_restore_tsc(void) if ( stime_delta < 0 ) stime_delta =3D 0; =20 - tsc_delta =3D scale_delta(stime_delta, &sys_to_tsc); + new_tsc =3D t->local_tsc_stamp + scale_delta(stime_delta, &sys_to_tsc)= ; =20 - wrmsrl(MSR_IA32_TSC, t->local_tsc_stamp + tsc_delta); + write_tsc(new_tsc); } =20 /*************************************************************************= ** @@ -1126,8 +1126,7 @@ static void time_calibration_tsc_rendezv atomic_inc(&r->semaphore); =20 if ( i =3D=3D 0 ) - write_tsc((u32)r->master_tsc_stamp, - (u32)(r->master_tsc_stamp >> 32)); + write_tsc(r->master_tsc_stamp); =20 while ( atomic_read(&r->semaphore) !=3D (2*total_cpus - 1) ) mb(); @@ -1140,8 +1139,7 @@ static void time_calibration_tsc_rendezv mb(); =20 if ( i =3D=3D 0 ) - write_tsc((u32)r->master_tsc_stamp, - (u32)(r->master_tsc_stamp >> 32)); + write_tsc(r->master_tsc_stamp); =20 atomic_inc(&r->semaphore); while ( atomic_read(&r->semaphore) > total_cpus ) diff -r 72d130772f36 xen/include/asm-x86/msr.h --- a/xen/include/asm-x86/msr.h=09Wed Sep 16 09:30:41 2009 +0100 +++ b/xen/include/asm-x86/msr.h=09Mon Sep 21 11:03:24 2009 -0600 @@ -82,7 +82,7 @@ static inline void wrmsrl(unsigned int m } while(0) #endif =20 -#define write_tsc(val1,val2) wrmsr(0x10, val1, val2) +#define write_tsc(val) wrmsrl(MSR_IA32_TSC, val) =20 #define rdpmc(counter,low,high) \ __asm__ __volatile__("rdpmc" \