* stopped by H/W. Without carefully handling of TSC/APIC stop issues,
* deep C state can't work correctly.
*/
- /* placeholder for preparing TSC stop */
-
+ /* preparing TSC stop */
+ cstate_save_tsc();
/* placeholder for preparing APIC stop */
/* Invoke C3 */
/* placeholder for recovering APIC */
- /* placeholder for recovering TSC */
+ /* recovering TSC */
+ cstate_restore_tsc();
/* Get end time (ticks) */
t2 = inl(pmtmr_ioport);
struct cpu_time {
u64 local_tsc_stamp;
+ u64 cstate_tsc_stamp;
s_time_t stime_local_stamp;
s_time_t stime_master_stamp;
struct time_scale tsc_scale;
+ u32 cstate_plt_count_stamp;
struct timer calibration_timer;
};
static DEFINE_PER_CPU(struct cpu_time, cpu_time);
+static u8 tsc_invariant=0; /* TSC is invariant upon C state entry */
+
/*
* We simulate a 32-bit platform timer from the 16-bit PIT ch2 counter.
* Otherwise overflow happens too quickly (~50ms) for us to guarantee that
freq_string(pts->frequency), pts->name);
}
+void cstate_save_tsc(void)
+{
+ struct cpu_time *t = &this_cpu(cpu_time);
+
+ if (!tsc_invariant){
+ t->cstate_plt_count_stamp = plt_src.read_counter();
+ rdtscll(t->cstate_tsc_stamp);
+ }
+}
+
+void cstate_restore_tsc(void)
+{
+ struct cpu_time *t;
+ u32 plt_count_delta;
+ u64 tsc_delta;
+
+ if (!tsc_invariant){
+ t = &this_cpu(cpu_time);
+
+ /* if platform counter overflow happens, interrupt will bring CPU from
+ C state to working state, so the platform counter won't wrap the
+ cstate_plt_count_stamp, and the 32 bit unsigned platform counter
+ is enough for delta calculation
+ */
+ plt_count_delta =
+ (plt_src.read_counter() - t->cstate_plt_count_stamp) & plt_mask;
+ tsc_delta = scale_delta(plt_count_delta, &plt_scale)*cpu_khz/1000000UL;
+ wrmsrl(MSR_IA32_TSC, t->cstate_tsc_stamp + tsc_delta);
+ }
+}
/***************************************************************************
* CMOS Timer functions
stime_platform_stamp = 0;
init_platform_timer();
+ /* check if TSC is invariant during deep C state
+ this is a new feature introduced by Nehalem*/
+ if ( cpuid_edx(0x80000007) & (1U<<8) )
+ tsc_invariant = 1;
+
local_irq_enable();
return 0;