Changeset 11326 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Aug 11, 2008 11:01:01 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstTSC.cpp
r8245 r11326 34 34 #include <iprt/runtime.h> 35 35 36 36 37 /******************************************************************************* 37 38 * Structures and Typedefs * … … 40 41 { 41 42 /** The TSC. */ 42 uint64_t volatile TSC; 43 uint64_t volatile TSC; 43 44 /** The APIC ID. */ 44 45 uint8_t volatile u8ApicId; … … 51 52 } TSCDATA, *PTSCDATA; 52 53 54 53 55 /******************************************************************************* 54 56 * Global Variables * … … 59 61 static volatile uint32_t g_cReady; 60 62 /** The variable the CPUs are spinning on. 61 * 0: Spin. 62 * 1: Go ahead. 63 * 2: You're too late, back to square one. */ 63 * 0: Spin. 64 * 1: Go ahead. 65 * 2: You're too late, back to square one. */ 64 66 static volatile uint32_t g_u32Go; 65 67 /** The number of CPUs that managed to read the TSC. */ … … 79 81 80 82 /** 81 * Thread function for catching the other cpus. 82 * 83 * Thread function for catching the other cpus. 84 * 83 85 * @returns VINF_SUCCESS (we don't care). 84 86 * @param Thread The thread handle. … … 110 112 const uint64_t TSC1 = ASMReadTSC(); 111 113 const uint32_t u32Go = g_u32Go; 112 if (u32Go == 0) 114 if (u32Go == 0) 113 115 continue; 114 116 … … 122 124 const uint8_t ApicId4 = ASMGetApicId(); 123 125 124 if ( ApicId1 == ApicId2 126 if ( ApicId1 == ApicId2 125 127 && ApicId1 == ApicId3 126 128 && ApicId1 == ApicId4 … … 146 148 } 147 149 } 148 150 149 151 return VINF_SUCCESS; 150 152 } … … 158 160 * This is only relevant to on SMP systems. 159 161 */ 160 const unsigned cCpus = RT SystemProcessorGetCount();161 if (cCpus <= 1) 162 const unsigned cCpus = RTMpGetOnlineCount(); 163 if (cCpus <= 1) 162 164 { 163 165 RTPrintf("tstTSC: SKIPPED - Only relevant on SMP systems\n"); … … 170 172 static TSCDATA s_aData[254]; 171 173 uint32_t i; 172 if (cCpus > RT_ELEMENTS(s_aData)) 174 if (cCpus > RT_ELEMENTS(s_aData)) 173 175 { 174 176 RTPrintf("tstTSC: FAILED - too many CPUs (%u)\n", cCpus); … … 254 256 } 255 257 256 /* 258 /* 257 259 * Flip the "go" switch and do our readings. 258 260 * We give the other threads the slack it takes to two extra TSC and APIC ID reads. … … 273 275 274 276 /* Compose our own result. */ 275 if ( ApicId1 == ApicId2 277 if ( ApicId1 == ApicId2 276 278 && ApicId1 == ApicId3 277 279 && ApicId1 == ApicId4 … … 339 341 RTPrintf("%2d %02x %RX64\n", 0, s_aData[0].u8ApicId, s_aData[0].TSC); 340 342 for (i = 1; i < cCpus; i++) 341 RTPrintf("%2d %02x %RX64 %s%lld\n", i, s_aData[i].u8ApicId, s_aData[i].TSC, 343 RTPrintf("%2d %02x %RX64 %s%lld\n", i, s_aData[i].u8ApicId, s_aData[i].TSC, 342 344 s_aData[i].TSC > s_aData[0].TSC ? "+" : "", s_aData[i].TSC - s_aData[0].TSC); 343 345 RTPrintf("(Needed %u attempt%s.)\n", cTries + 1, cTries ? "s" : "");
Note:
See TracChangeset
for help on using the changeset viewer.