add tsc discussion
[lttv.git] / ltt / branches / poly / doc / developer / tsc.txt
CommitLineData
fe5ba1d0 1
2*************************************************************
3AMD
4http://lkml.org/lkml/2005/11/4/173
5http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/26094.PDF
6http://developer.amd.com/article_print.jsp?id=92 (RH)
7
8[7] AMD's 7th generation processors return a CPUID base
9 family value of '7'. These include AMD Athlon, AthlonXP,
10 AthlonMP, and Duron.
11
12[8] AMD's 8th generation processors return an effective
13 CPUID family of '0x0F'. These include AMD Opteron,
14 Athlon64, and Turion.
15
16
17before 7th gen : ok
187th gen:
19 P-state (performance state) change
20 sol : disable powernow
21 STPCLK-Throttling (temperature) : only done on UP, ok
228th gen :
23 P-state change
24 dual-core : locked-step
25 SMP : may drift
26 sol : disable powernow
27 SMP, dual core : C1-clock ramping (halt) (power state : C-state)
28 sol : idle=poll or disable C1-ramping
29 STPCLK-Throttling (temperature) :
30 single processor dual-core ok
31 SMP : NOT ok (rare)
32
33
34Until TSC becomes invariant, AMD recommends that operating
35system developers avoid TSC as a fast timer source on
36affected systems. (AMD recommends that the operating system
37should favor these time sources in a prioritized manner:
38HPET first, then ACPI PM Timer, then PIT.) The following
39pseudo-code shows one way of determining when to use TSC:
40
41 use_AMD_TSC() { // returns TRUE if ok to use TSC
42 if (CPUID.base_family < 0xf) {
43 // TSC drift doesn't exist on 7th Gen or less
44 // However, OS still needs to consider effects
45 // of P-state changes on TSC
46 return TRUE;
47 } else if (CPUID.AdvPowerMgmtInfo.TscInvariant) {
48 // Invariant TSC on 8th Gen or newer, use it
49 // (assume all cores have invariant TSC)
50 return TRUE;
51 } else if ((number_processors == 1)&&(number_cores == 1)){
52 // OK to use TSC on uni-processor-uni-core
53 // However, OS still needs to consider effects
54 // of P-state changes on TSC
55 return TRUE;
56 } else if ( (number_processors == 1) &&
57 (CPUID.effective_family == 0x0f) &&
58 !C1_ramp_8gen ){
59 // Use TSC on 8th Gen uni-proc with C1_ramp off
60 // However, OS still needs to consider effects
61 // of P-state changes on TSC
62 return TRUE;
63 } else {
64 return FALSE;
65 }
66 }
67 C1_ramp_8gen() {
68 // Check if C1-Clock ramping enabled in PMM7.CpuLowPwrEnh
69 // On 8th-Generation cores only. Assume BIOS has setup
70 // all Northbridges equivalently.
71 return (1 & read_pci_byte(bus=0,dev=0x18,fcn=3,offset=0x87));
72 }
73
74
75When an operating system can not avoid using TSC in the
76short-term, the operating system will need to either
77re-synchronize the TSC of the halted core when exiting halt
78or disable C1-clock ramping. The pseudo-code for disabling
79C1-clock ramping follows:
80
81 if ( !use_AMD_TSC() &&
82 (CPUID.effective_family == 0x0f) &&
83 C1_ramp_8gen() ){
84 for (i=0; i < number_processors; ++i){
85 // Do for all NorthBridges in platform
86 tmp = read_pci_byte(bus=0,dev=0x18+i,fcn=3,offset=0x87);
87 tmp &= 0xFC; // clears pmm7[1:0]
88 write_pci_byte(bus=0,dev=0x18+i,fcn=3,offset=0x87,tmp)
89 }
90 }
91
92
93Future TSC Directions and Solutions
94===================================
95Future AMD processors will provide a TSC that is P-state and
96C-State invariant and unaffected by STPCLK-throttling. This
97will make the TSC immune to drift. Because using the TSC
98for fast timer APIs is a desirable feature that helps
99performance, AMD has defined a CPUID feature bit that
100software can test to determine if the TSC is
101invariant. Issuing a CPUID instruction with an %eax register
102value of 0x8000_0007, on a processor whose base family is
1030xF, returns "Advanced Power Management Information" in the
104%eax, %ebx, %ecx, and %edx registers. Bit 8 of the return
105%edx is the "TscInvariant" feature flag which is set when
106TSC is P-state, C-state, and STPCLK-throttling invariant; it
107is clear otherwise.
108
109The rate of the invariant TSC is implementation-dependent
110and will likely *not* be the frequency of the processor
111core; however, its period should be short enough such that
112it is not possible for two back-to-back rdtsc instructions
113to return the same value. Software which is trying to
114measure actual processor frequency or cycle-performance
115should use Performance Event 76h, CPU Clocks not Halted,
116rather than the TSC to count CPU cycles.
117
118
119
120*************************************************************
121Intel
122
123Pentium M
124 family [06H], models [09H, 0DH]
125 SOL : disable speedstep
126Pentium 4 processors, Intel Xeon
127 family [0FH], models [00H, 01H, or 02H]
128 SOL : disable speedstep
129
130Other : ok
131
132http://download.intel.com/design/Xeon/specupdt/30675712.pdf
133http://forum.rightmark.org/post.cgi?id=print:6:269&user=%20Dmitri%20Besedin&color=1
134http://bochs.sourceforge.net/techspec/24161821.pdf cpuid
135
136cpuz
137AFAIK this problem only concerns Prescott CPUs, but I bet future production will
138also use the same rule.
139
140Well, from what Intel states in one of their docs (Intel(R) Pentium(R) M
141Processor on 90 nm Process with 2-MB L2 Cache, Specification Update, Document
142No. 302209-010 (http://www.intel.com/design/mobile/specupdt/302209.htm) ), your
143supposition is true:
144
145
146Article V. For Pentium M processors (family [06H], models [09H, 0DH]); for
147Pentium 4 processors, Intel Xeon processors (family [0FH], models [00H, 01H, or
14802H]); and for P6 family processors: the timestamp counter increments with every
149internal processor clock cycle. The internal processor clock cycle is determined
150by the current core-clock to bus-clock ratio. Intel(R) SpeedStep(R) technology
151transitions may also impact the processor clock.
152
153Article VI. For Pentium 4 processors, Intel Xeon processors (family [0FH],
154models [03H and higher]): the time-stamp counter increments at a constant rate.
155That rate may be set by the maximum core-clock to bus-clock ratio of the
156processor or may be set by the frequency at which the processor is booted. The
157specific processor configuration determines the behavior. Constant TSC behavior
158ensures that the duration of each clock tick is uniform and supports the use of
159the TSC as a wall clock timer even if the processor core changes frequency. This
160is the architectural behavior moving forward.
161
162
163It's a pity they call this sucking TSC behavior an "architectural behavior
164moving forward"
165
166
167
168*************************************************************
169HPET
170
171http://www.intel.com/hardwaredesign/hpetspec_1.pdf
172
173
174
175
This page took 0.042691 seconds and 4 git commands to generate.