Changeset 87766 in vbox for trunk/src/VBox/VMM/VMMAll
- Timestamp:
- Feb 16, 2021 2:27:43 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 142820
- Location:
- trunk/src/VBox/VMM/VMMAll
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp
r87361 r87766 2335 2335 VMCPU_ASSERT_EMT(pVCpu); 2336 2336 uint64_t const cTicksToNext = uTimer << cShift; 2337 return TMTimerSetRelative(pVCpu-> cpum.s.CTX_SUFF(pNestedVmxPreemptTimer), cTicksToNext, pu64EntryTick);2337 return TMTimerSetRelative(pVCpu->CTX_SUFF(pVM), pVCpu->cpum.s.hNestedVmxPreemptTimer, cTicksToNext, pu64EntryTick); 2338 2338 } 2339 2339 … … 2353 2353 /* 2354 2354 * CPUM gets initialized before TM, so we defer creation of timers till CPUMR3InitCompleted(). 2355 * However, we still get called during CPUMR3Init() and hence we need to check if we 2355 * However, we still get called during CPUMR3Init() and hence we need to check if we have 2356 2356 * a valid timer object before trying to stop it. 2357 2357 */ 2358 PTMTIMER pTimer = pVCpu->cpum.s.CTX_SUFF(pNestedVmxPreemptTimer); 2359 if (!pTimer) 2360 return VERR_NOT_FOUND; 2361 2362 int rc = TMTimerLock(pTimer, VERR_IGNORED); 2363 if (rc == VINF_SUCCESS) 2364 { 2365 if (TMTimerIsActive(pTimer)) 2366 TMTimerStop(pTimer); 2367 TMTimerUnlock(pTimer); 2368 } 2358 int rc; 2359 TMTIMERHANDLE hTimer = pVCpu->cpum.s.hNestedVmxPreemptTimer; 2360 if (hTimer != NIL_TMTIMERHANDLE) 2361 { 2362 PVMCC pVM = pVCpu->CTX_SUFF(pVM); 2363 rc = TMTimerLock(pVM, hTimer, VERR_IGNORED); 2364 if (rc == VINF_SUCCESS) 2365 { 2366 if (TMTimerIsActive(pVM, hTimer)) 2367 TMTimerStop(pVM, hTimer); 2368 TMTimerUnlock(pVM, hTimer); 2369 } 2370 } 2371 else 2372 rc = VERR_NOT_FOUND; 2369 2373 return rc; 2370 2374 } -
trunk/src/VBox/VMM/VMMAll/GIMAllHv.cpp
r82968 r87766 509 509 VMM_INT_DECL(void) gimHvStartStimer(PVMCPUCC pVCpu, PCGIMHVSTIMER pHvStimer) 510 510 { 511 PTMTIMER pTimer = pHvStimer->CTX_SUFF(pTimer); 512 Assert(TMTimerIsLockOwner(pTimer)); 511 PVMCC pVM = pVCpu->CTX_SUFF(pVM); 512 TMTIMERHANDLE hTimer = pHvStimer->hTimer; 513 Assert(TMTimerIsLockOwner(pVM, hTimer)); 513 514 514 515 uint64_t const uTimerCount = pHvStimer->uStimerCountMsr; … … 520 521 if (MSR_GIM_HV_STIMER_IS_PERIODIC(pHvStimer->uStimerConfigMsr)) 521 522 { 522 TMTimerSetNano(p Timer, uTimerCountNS);523 TMTimerSetNano(pVM, hTimer, uTimerCountNS); 523 524 LogFlow(("GIM%u: HyperV: Started relative periodic STIMER%u with uTimerCountNS=%RU64\n", pVCpu->idCpu, 524 525 pHvStimer->idxStimer, uTimerCountNS)); … … 532 533 { 533 534 uint64_t const uRelativeNS = uTimerCountNS - uCurRefTimeNS; 534 TMTimerSetNano(p Timer, uRelativeNS);535 TMTimerSetNano(pVM, hTimer, uRelativeNS); 535 536 LogFlow(("GIM%u: HyperV: Started one-shot relative STIMER%u with uRelativeNS=%RU64\n", pVCpu->idCpu, 536 537 pHvStimer->idxStimer, uRelativeNS)); … … 554 555 { 555 556 VMCPU_ASSERT_EMT_OR_NOT_RUNNING(pVCpu); 556 RT_NOREF(pVCpu); 557 558 PTMTIMER pTimer = pHvStimer->CTX_SUFF(pTimer); 559 Assert(TMTimerIsLockOwner(pTimer)); 560 RT_NOREF(pTimer); 561 562 if (TMTimerIsActive(pHvStimer->CTX_SUFF(pTimer))) 563 TMTimerStop(pHvStimer->CTX_SUFF(pTimer)); 557 PVMCC pVM = pVCpu->CTX_SUFF(pVM); 558 559 TMTIMERHANDLE hTimer = pHvStimer->hTimer; 560 Assert(TMTimerIsLockOwner(pVM, hTimer)); 561 562 if (TMTimerIsActive(pVM, hTimer)) 563 TMTimerStop(pVM, hTimer); 564 564 } 565 565 … … 757 757 { 758 758 NOREF(pRange); 759 PVM 759 PVMCC pVM = pVCpu->CTX_SUFF(pVM); 760 760 PGIMHV pHv = &pVM->gim.s.u.Hv; 761 761 … … 1153 1153 Assert(idxStimer < RT_ELEMENTS(pHvCpu->aStimers)); 1154 1154 PGIMHVSTIMER pHvStimer = &pHvCpu->aStimers[idxStimer]; 1155 PTMTIMER pTimer = pHvStimer->CTX_SUFF(pTimer);1156 1155 1157 1156 /* Lock to prevent concurrent access from the timer callback. */ 1158 int rc = TMTimerLock(p Timer, VERR_IGNORED);1157 int rc = TMTimerLock(pVM, pHvStimer->hTimer, VERR_IGNORED); 1159 1158 if (rc == VINF_SUCCESS) 1160 1159 { … … 1176 1175 if (!MSR_GIM_HV_STIMER_IS_AUTO_ENABLED(uRawValue)) 1177 1176 { 1178 if (!TMTimerIsActive(p HvStimer->CTX_SUFF(pTimer)))1177 if (!TMTimerIsActive(pVM, pHvStimer->hTimer)) 1179 1178 { 1180 1179 gimHvStartStimer(pVCpu, pHvStimer); … … 1197 1196 } 1198 1197 1199 TMTimerUnlock(p Timer);1198 TMTimerUnlock(pVM, pHvStimer->hTimer); 1200 1199 } 1201 1200 return rc; … … 1239 1238 if (MSR_GIM_HV_STIMER_IS_AUTO_ENABLED(pHvStimer->uStimerConfigMsr)) 1240 1239 { 1241 PTMTIMER pTimer = pHvStimer->CTX_SUFF(pTimer); 1242 int rc = TMTimerLock(pTimer, rcBusy); 1240 int rc = TMTimerLock(pVM, pHvStimer->hTimer, rcBusy); 1243 1241 if (rc == VINF_SUCCESS) 1244 1242 { 1245 1243 pHvStimer->uStimerCountMsr = uRawValue; 1246 1244 gimHvStartStimer(pVCpu, pHvStimer); 1247 TMTimerUnlock(p Timer);1245 TMTimerUnlock(pVM, pHvStimer->hTimer); 1248 1246 Log(("GIM%u: HyperV: Set STIMER_COUNT%u=%RU64 %RU64 msec, auto-started timer\n", pVCpu->idCpu, idxStimer, 1249 1247 uRawValue, (uRawValue * 100) / RT_NS_1MS_64)); -
trunk/src/VBox/VMM/VMMAll/PDMAllQueue.cpp
r82968 r87766 111 111 #endif 112 112 113 if ( !pQueue->pTimer)113 if (pQueue->hTimer == NIL_TMTIMERHANDLE) 114 114 pdmQueueSetFF(pQueue); 115 115 STAM_REL_COUNTER_INC(&pQueue->StatInsert); -
trunk/src/VBox/VMM/VMMAll/TMAll.cpp
r87764 r87766 1102 1102 1103 1103 /** 1104 * Gets the host context ring-3 pointer of the timer.1105 *1106 * @returns HC R3 pointer.1107 * @param pTimer Timer handle as returned by one of the create functions.1108 */1109 VMMDECL(PTMTIMERR3) TMTimerR3Ptr(PTMTIMER pTimer)1110 {1111 #ifdef IN_RING01112 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0);1113 #endif1114 return (PTMTIMERR3)MMHyperCCToR3(pTimer->CTX_SUFF(pVM), pTimer);1115 }1116 1117 1118 /**1119 * Gets the host context ring-0 pointer of the timer.1120 *1121 * @returns HC R0 pointer.1122 * @param pTimer Timer handle as returned by one of the create functions.1123 */1124 VMMDECL(PTMTIMERR0) TMTimerR0Ptr(PTMTIMER pTimer)1125 {1126 #ifdef IN_RING01127 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0);1128 #endif1129 return (PTMTIMERR0)MMHyperCCToR0(pTimer->CTX_SUFF(pVM), pTimer);1130 }1131 1132 1133 /**1134 * Gets the RC pointer of the timer.1135 *1136 * @returns RC pointer.1137 * @param pTimer Timer handle as returned by one of the create functions.1138 */1139 VMMDECL(PTMTIMERRC) TMTimerRCPtr(PTMTIMER pTimer)1140 {1141 #ifdef IN_RING01142 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0);1143 #endif1144 return (PTMTIMERRC)MMHyperCCToRC(pTimer->CTX_SUFF(pVM), pTimer);1145 }1146 1147 1148 /**1149 1104 * Locks the timer clock. 1150 1105 * 1151 1106 * @returns VINF_SUCCESS on success, @a rcBusy if busy, and VERR_NOT_SUPPORTED 1152 1107 * if the clock does not have a lock. 1153 * @param p Timer The timer which clock lock we wish to take.1154 * @param rcBusy What to return in ring-0 and raw-mode context1155 * if the lock is busy. Pass VINF_SUCCESS to1156 * acquired the critical section thru a ring-31157 1108 * @param pVM The cross context VM structure. 1109 * @param hTimer Timer handle as returned by one of the create functions. 1110 * @param rcBusy What to return in ring-0 and raw-mode context if the 1111 * lock is busy. Pass VINF_SUCCESS to acquired the 1112 * critical section thru a ring-3 call if necessary. 1158 1113 * 1159 1114 * @remarks Currently only supported on timers using the virtual sync clock. 1160 1115 */ 1161 VMMDECL(int) TMTimerLock(PTMTIMER pTimer, int rcBusy) 1162 { 1163 #ifdef IN_RING0 1164 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 1165 #endif 1116 VMMDECL(int) TMTimerLock(PVMCC pVM, TMTIMERHANDLE hTimer, int rcBusy) 1117 { 1118 PTMTIMER pTimer; 1119 TMTIMER_HANDLE_TO_PTR_RETURN(pVM, hTimer, pTimer); 1166 1120 AssertPtr(pTimer); 1167 1121 AssertReturn(pTimer->enmClock == TMCLOCK_VIRTUAL_SYNC, VERR_NOT_SUPPORTED); 1168 return PDMCritSectEnter(&p Timer->CTX_SUFF(pVM)->tm.s.VirtualSyncLock, rcBusy);1122 return PDMCritSectEnter(&pVM->tm.s.VirtualSyncLock, rcBusy); 1169 1123 } 1170 1124 … … 1173 1127 * Unlocks a timer clock locked by TMTimerLock. 1174 1128 * 1175 * @param pTimer The timer which clock to unlock. 1176 */ 1177 VMMDECL(void) TMTimerUnlock(PTMTIMER pTimer) 1178 { 1179 #ifdef IN_RING0 1180 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 1181 #endif 1182 AssertPtr(pTimer); 1129 * @param pVM The cross context VM structure. 1130 * @param hTimer Timer handle as returned by one of the create functions. 1131 */ 1132 VMMDECL(void) TMTimerUnlock(PVMCC pVM, TMTIMERHANDLE hTimer) 1133 { 1134 PTMTIMER pTimer; 1135 TMTIMER_HANDLE_TO_PTR_RETURN_VOID(pVM, hTimer, pTimer); 1183 1136 AssertReturnVoid(pTimer->enmClock == TMCLOCK_VIRTUAL_SYNC); 1184 PDMCritSectLeave(&p Timer->CTX_SUFF(pVM)->tm.s.VirtualSyncLock);1137 PDMCritSectLeave(&pVM->tm.s.VirtualSyncLock); 1185 1138 } 1186 1139 … … 1190 1143 * 1191 1144 * @returns @c true if its the owner, @c false if not. 1192 * @param p Timer The timer handle.1193 * /1194 VMMDECL(bool) TMTimerIsLockOwner(PTMTIMER pTimer) 1195 { 1196 #ifdef IN_RING0 1197 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0);1198 #endif 1145 * @param pVM The cross context VM structure. 1146 * @param hTimer Timer handle as returned by one of the create functions. 1147 */ 1148 VMMDECL(bool) TMTimerIsLockOwner(PVMCC pVM, TMTIMERHANDLE hTimer) 1149 { 1150 PTMTIMER pTimer; 1151 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, false, pTimer); 1199 1152 AssertPtr(pTimer); 1200 1153 AssertReturn(pTimer->enmClock == TMCLOCK_VIRTUAL_SYNC, false); 1201 return PDMCritSectIsOwner(&p Timer->CTX_SUFF(pVM)->tm.s.VirtualSyncLock);1154 return PDMCritSectIsOwner(&pVM->tm.s.VirtualSyncLock); 1202 1155 } 1203 1156 … … 1319 1272 * 1320 1273 * @returns VBox status code. 1321 * @param pTimer Timer handle as returned by one of the create functions. 1322 * @param u64Expire New expire time. 1323 */ 1324 VMMDECL(int) TMTimerSet(PTMTIMER pTimer, uint64_t u64Expire) 1325 { 1326 #ifdef IN_RING0 1327 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 1328 #endif 1329 PVMCC pVM = pTimer->CTX_SUFF(pVM); 1274 * @param pVM The cross context VM structure. 1275 * @param hTimer Timer handle as returned by one of the create functions. 1276 * @param u64Expire New expire time. 1277 */ 1278 VMMDECL(int) TMTimerSet(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t u64Expire) 1279 { 1280 PTMTIMER pTimer; 1281 TMTIMER_HANDLE_TO_PTR_RETURN(pVM, hTimer, pTimer); 1330 1282 STAM_COUNTER_INC(&pTimer->StatSetAbsolute); 1331 1283 … … 1627 1579 * 1628 1580 * @returns VBox status code. 1629 * @param pTimer Timer handle as returned by one of the create functions. 1581 * @param pVM The cross context VM structure. 1582 * @param hTimer Timer handle as returned by one of the create functions. 1630 1583 * @param cTicksToNext Clock ticks until the next time expiration. 1631 1584 * @param pu64Now Where to return the current time stamp used. 1632 1585 * Optional. 1633 1586 */ 1634 VMMDECL(int) TMTimerSetRelative(PTMTIMER pTimer, uint64_t cTicksToNext, uint64_t *pu64Now) 1635 { 1636 #ifdef IN_RING0 1637 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 1638 #endif 1639 PVMCC pVM = pTimer->CTX_SUFF(pVM); 1587 static int tmTimerSetRelative(PVMCC pVM, PTMTIMER pTimer, uint64_t cTicksToNext, uint64_t *pu64Now) 1588 { 1640 1589 STAM_COUNTER_INC(&pTimer->StatSetRelative); 1641 1590 … … 1849 1798 1850 1799 /** 1800 * Arm a timer with a expire time relative to the current time. 1801 * 1802 * @returns VBox status code. 1803 * @param pVM The cross context VM structure. 1804 * @param hTimer Timer handle as returned by one of the create functions. 1805 * @param cTicksToNext Clock ticks until the next time expiration. 1806 * @param pu64Now Where to return the current time stamp used. 1807 * Optional. 1808 */ 1809 VMMDECL(int) TMTimerSetRelative(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicksToNext, uint64_t *pu64Now) 1810 { 1811 PTMTIMER pTimer; 1812 TMTIMER_HANDLE_TO_PTR_RETURN(pVM, hTimer, pTimer); 1813 return tmTimerSetRelative(pVM, pTimer, cTicksToNext, pu64Now); 1814 } 1815 1816 1817 /** 1851 1818 * Drops a hint about the frequency of the timer. 1852 1819 * … … 1855 1822 * 1856 1823 * @returns VBox status code. 1857 * @param p Timer Timer handle as returned by one of the create1858 * 1859 * @param uHzHint 1824 * @param pVM The cross context VM structure. 1825 * @param hTimer Timer handle as returned by one of the create functions. 1826 * @param uHzHint The frequency hint. Pass 0 to clear the hint. 1860 1827 * 1861 1828 * @remarks We're using an integer hertz value here since anything above 1 HZ … … 1863 1830 * range where it makes sense is >= 100 HZ. 1864 1831 */ 1865 VMMDECL(int) TMTimerSetFrequencyHint(PTMTIMER pTimer, uint32_t uHzHint) 1866 { 1867 #ifdef IN_RING0 1868 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 1869 #endif 1832 VMMDECL(int) TMTimerSetFrequencyHint(PVMCC pVM, TMTIMERHANDLE hTimer, uint32_t uHzHint) 1833 { 1834 PTMTIMER pTimer; 1835 TMTIMER_HANDLE_TO_PTR_RETURN(pVM, hTimer, pTimer); 1870 1836 TMTIMER_ASSERT_CRITSECT(pTimer); 1871 1837 … … 1873 1839 pTimer->uHzHint = uHzHint; 1874 1840 1875 PVM pVM = pTimer->CTX_SUFF(pVM);1876 1841 uint32_t const uMaxHzHint = pVM->tm.s.uMaxHzHint; 1877 1842 if ( uHzHint > uMaxHzHint … … 1959 1924 * 1960 1925 * @returns VBox status code. 1961 * @param pTimer Timer handle as returned by one of the create functions. 1962 */ 1963 VMMDECL(int) TMTimerStop(PTMTIMER pTimer) 1964 { 1965 #ifdef IN_RING0 1966 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 1967 #endif 1968 PVMCC pVM = pTimer->CTX_SUFF(pVM); 1926 * @param pVM The cross context VM structure. 1927 * @param hTimer Timer handle as returned by one of the create functions. 1928 */ 1929 VMMDECL(int) TMTimerStop(PVMCC pVM, TMTIMERHANDLE hTimer) 1930 { 1931 PTMTIMER pTimer; 1932 TMTIMER_HANDLE_TO_PTR_RETURN(pVM, hTimer, pTimer); 1969 1933 STAM_COUNTER_INC(&pTimer->StatStop); 1970 1934 … … 2070 2034 * 2071 2035 * @returns Current clock time. 2072 * @param pTimer Timer handle as returned by one of the create functions. 2073 */ 2074 VMMDECL(uint64_t) TMTimerGet(PTMTIMER pTimer) 2075 { 2076 #ifdef IN_RING0 2077 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 2078 #endif 2079 PVMCC pVM = pTimer->CTX_SUFF(pVM); 2036 * @param pVM The cross context VM structure. 2037 * @param hTimer Timer handle as returned by one of the create functions. 2038 */ 2039 VMMDECL(uint64_t) TMTimerGet(PVMCC pVM, TMTIMERHANDLE hTimer) 2040 { 2041 PTMTIMER pTimer; 2042 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, UINT64_MAX, pTimer); 2080 2043 STAM_COUNTER_INC(&pTimer->StatGet); 2081 2044 … … 2106 2069 * 2107 2070 * @returns Clock frequency (as Hz of course). 2108 * @param p Timer Timer handle as returned by one of the create functions.2109 * /2110 VMMDECL(uint64_t) TMTimerGetFreq(PTMTIMER pTimer) 2111 { 2112 #ifdef IN_RING0 2113 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0);2114 #endif 2071 * @param pVM The cross context VM structure. 2072 * @param hTimer Timer handle as returned by one of the create functions. 2073 */ 2074 VMMDECL(uint64_t) TMTimerGetFreq(PVMCC pVM, TMTIMERHANDLE hTimer) 2075 { 2076 PTMTIMER pTimer; 2077 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, 0, pTimer); 2115 2078 switch (pTimer->enmClock) 2116 2079 { … … 2134 2097 * 2135 2098 * @returns Expire time of the timer. 2136 * @param p Timer Timer handle as returned by one of the create functions.2137 * /2138 VMMDECL(uint64_t) TMTimerGetExpire(PTMTIMER pTimer) 2139 { 2140 #ifdef IN_RING0 2141 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0);2142 #endif 2099 * @param pVM The cross context VM structure. 2100 * @param hTimer Timer handle as returned by one of the create functions. 2101 */ 2102 VMMDECL(uint64_t) TMTimerGetExpire(PVMCC pVM, TMTIMERHANDLE hTimer) 2103 { 2104 PTMTIMER pTimer; 2105 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, UINT64_MAX, pTimer); 2143 2106 TMTIMER_ASSERT_CRITSECT(pTimer); 2144 2107 int cRetries = 1000; … … 2155 2118 Log2(("TMTimerGetExpire: returns ~0 (pTimer=%p:{.enmState=%s, .pszDesc='%s'})\n", 2156 2119 pTimer, tmTimerState(pTimer->enmState), R3STRING(pTimer->pszDesc))); 2157 return ~(uint64_t)0;2120 return UINT64_MAX; 2158 2121 2159 2122 case TMTIMERSTATE_ACTIVE: … … 2180 2143 Log2(("TMTimerGetExpire: returns ~0 (pTimer=%p:{.enmState=%s, .pszDesc='%s'})\n", 2181 2144 pTimer, tmTimerState(pTimer->enmState), R3STRING(pTimer->pszDesc))); 2182 return ~(uint64_t)0;2145 return UINT64_MAX; 2183 2146 default: 2184 2147 AssertMsgFailed(("Unknown timer state %d (%s)\n", enmState, R3STRING(pTimer->pszDesc))); 2185 return ~(uint64_t)0;2148 return UINT64_MAX; 2186 2149 } 2187 2150 } while (cRetries-- > 0); … … 2190 2153 Log2(("TMTimerGetExpire: returns ~0 (pTimer=%p:{.enmState=%s, .pszDesc='%s'})\n", 2191 2154 pTimer, tmTimerState(pTimer->enmState), R3STRING(pTimer->pszDesc))); 2192 return ~(uint64_t)0;2155 return UINT64_MAX; 2193 2156 } 2194 2157 … … 2199 2162 * @returns True if active. 2200 2163 * @returns False if not active. 2201 * @param p Timer Timer handle as returned by one of the create functions.2202 * /2203 VMMDECL(bool) TMTimerIsActive(PTMTIMER pTimer) 2204 { 2205 #ifdef IN_RING0 2206 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0);2207 #endif 2164 * @param pVM The cross context VM structure. 2165 * @param hTimer Timer handle as returned by one of the create functions. 2166 */ 2167 VMMDECL(bool) TMTimerIsActive(PVMCC pVM, TMTIMERHANDLE hTimer) 2168 { 2169 PTMTIMER pTimer; 2170 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, false, pTimer); 2208 2171 TMTIMERSTATE enmState = pTimer->enmState; 2209 2172 switch (enmState) … … 2250 2213 * 2251 2214 * @returns VBox status code. 2252 * @param pTimer Timer handle as returned by one of the create functions. 2215 * @param pVM The cross context VM structure. 2216 * @param hTimer Timer handle as returned by one of the create functions. 2253 2217 * @param cMilliesToNext Number of milliseconds to the next tick. 2254 2218 */ 2255 VMMDECL(int) TMTimerSetMillies(PTMTIMER pTimer, uint32_t cMilliesToNext) 2256 { 2219 VMMDECL(int) TMTimerSetMillies(PVMCC pVM, TMTIMERHANDLE hTimer, uint32_t cMilliesToNext) 2220 { 2221 PTMTIMER pTimer; 2222 TMTIMER_HANDLE_TO_PTR_RETURN(pVM, hTimer, pTimer); 2257 2223 switch (pTimer->enmClock) 2258 2224 { 2259 2225 case TMCLOCK_VIRTUAL: 2260 2226 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000); 2261 return TMTimerSetRelative(pTimer, cMilliesToNext * UINT64_C(1000000), NULL);2227 return tmTimerSetRelative(pVM, pTimer, cMilliesToNext * UINT64_C(1000000), NULL); 2262 2228 2263 2229 case TMCLOCK_VIRTUAL_SYNC: 2264 2230 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000); 2265 return TMTimerSetRelative(pTimer, cMilliesToNext * UINT64_C(1000000), NULL);2231 return tmTimerSetRelative(pVM, pTimer, cMilliesToNext * UINT64_C(1000000), NULL); 2266 2232 2267 2233 case TMCLOCK_REAL: 2268 2234 AssertCompile(TMCLOCK_FREQ_REAL == 1000); 2269 return TMTimerSetRelative(pTimer, cMilliesToNext, NULL);2235 return tmTimerSetRelative(pVM, pTimer, cMilliesToNext, NULL); 2270 2236 2271 2237 default: … … 2280 2246 * 2281 2247 * @returns VBox status code. 2282 * @param pTimer Timer handle as returned by one of the create functions. 2248 * @param pVM The cross context VM structure. 2249 * @param hTimer Timer handle as returned by one of the create functions. 2283 2250 * @param cMicrosToNext Number of microseconds to the next tick. 2284 2251 */ 2285 VMMDECL(int) TMTimerSetMicro(PTMTIMER pTimer, uint64_t cMicrosToNext) 2286 { 2252 VMMDECL(int) TMTimerSetMicro(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cMicrosToNext) 2253 { 2254 PTMTIMER pTimer; 2255 TMTIMER_HANDLE_TO_PTR_RETURN(pVM, hTimer, pTimer); 2287 2256 switch (pTimer->enmClock) 2288 2257 { 2289 2258 case TMCLOCK_VIRTUAL: 2290 2259 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000); 2291 return TMTimerSetRelative(pTimer, cMicrosToNext * 1000, NULL);2260 return tmTimerSetRelative(pVM, pTimer, cMicrosToNext * 1000, NULL); 2292 2261 2293 2262 case TMCLOCK_VIRTUAL_SYNC: 2294 2263 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000); 2295 return TMTimerSetRelative(pTimer, cMicrosToNext * 1000, NULL);2264 return tmTimerSetRelative(pVM, pTimer, cMicrosToNext * 1000, NULL); 2296 2265 2297 2266 case TMCLOCK_REAL: 2298 2267 AssertCompile(TMCLOCK_FREQ_REAL == 1000); 2299 return TMTimerSetRelative(pTimer, cMicrosToNext / 1000, NULL);2268 return tmTimerSetRelative(pVM, pTimer, cMicrosToNext / 1000, NULL); 2300 2269 2301 2270 default: … … 2310 2279 * 2311 2280 * @returns VBox status code. 2312 * @param pTimer Timer handle as returned by one of the create functions. 2281 * @param pVM The cross context VM structure. 2282 * @param hTimer Timer handle as returned by one of the create functions. 2313 2283 * @param cNanosToNext Number of nanoseconds to the next tick. 2314 2284 */ 2315 VMMDECL(int) TMTimerSetNano(PTMTIMER pTimer, uint64_t cNanosToNext) 2316 { 2285 VMMDECL(int) TMTimerSetNano(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cNanosToNext) 2286 { 2287 PTMTIMER pTimer; 2288 TMTIMER_HANDLE_TO_PTR_RETURN(pVM, hTimer, pTimer); 2317 2289 switch (pTimer->enmClock) 2318 2290 { 2319 2291 case TMCLOCK_VIRTUAL: 2320 2292 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000); 2321 return TMTimerSetRelative(pTimer, cNanosToNext, NULL);2293 return tmTimerSetRelative(pVM, pTimer, cNanosToNext, NULL); 2322 2294 2323 2295 case TMCLOCK_VIRTUAL_SYNC: 2324 2296 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000); 2325 return TMTimerSetRelative(pTimer, cNanosToNext, NULL);2297 return tmTimerSetRelative(pVM, pTimer, cNanosToNext, NULL); 2326 2298 2327 2299 case TMCLOCK_REAL: 2328 2300 AssertCompile(TMCLOCK_FREQ_REAL == 1000); 2329 return TMTimerSetRelative(pTimer, cNanosToNext / 1000000, NULL);2301 return tmTimerSetRelative(pVM, pTimer, cNanosToNext / 1000000, NULL); 2330 2302 2331 2303 default: … … 2340 2312 * 2341 2313 * @returns The timer clock as nanoseconds. 2342 * @param pTimer Timer handle as returned by one of the create functions. 2343 */ 2344 VMMDECL(uint64_t) TMTimerGetNano(PTMTIMER pTimer) 2345 { 2346 return TMTimerToNano(pTimer, TMTimerGet(pTimer)); 2314 * @param pVM The cross context VM structure. 2315 * @param hTimer Timer handle as returned by one of the create functions. 2316 */ 2317 VMMDECL(uint64_t) TMTimerGetNano(PVMCC pVM, TMTIMERHANDLE hTimer) 2318 { 2319 return TMTimerToNano(pVM, hTimer, TMTimerGet(pVM, hTimer)); 2347 2320 } 2348 2321 … … 2352 2325 * 2353 2326 * @returns The timer clock as microseconds. 2354 * @param pTimer Timer handle as returned by one of the create functions. 2355 */ 2356 VMMDECL(uint64_t) TMTimerGetMicro(PTMTIMER pTimer) 2357 { 2358 return TMTimerToMicro(pTimer, TMTimerGet(pTimer)); 2327 * @param pVM The cross context VM structure. 2328 * @param hTimer Timer handle as returned by one of the create functions. 2329 */ 2330 VMMDECL(uint64_t) TMTimerGetMicro(PVMCC pVM, TMTIMERHANDLE hTimer) 2331 { 2332 return TMTimerToMicro(pVM, hTimer, TMTimerGet(pVM, hTimer)); 2359 2333 } 2360 2334 … … 2364 2338 * 2365 2339 * @returns The timer clock as milliseconds. 2366 * @param pTimer Timer handle as returned by one of the create functions. 2367 */ 2368 VMMDECL(uint64_t) TMTimerGetMilli(PTMTIMER pTimer) 2369 { 2370 return TMTimerToMilli(pTimer, TMTimerGet(pTimer)); 2340 * @param pVM The cross context VM structure. 2341 * @param hTimer Timer handle as returned by one of the create functions. 2342 */ 2343 VMMDECL(uint64_t) TMTimerGetMilli(PVMCC pVM, TMTIMERHANDLE hTimer) 2344 { 2345 return TMTimerToMilli(pVM, hTimer, TMTimerGet(pVM, hTimer)); 2371 2346 } 2372 2347 … … 2376 2351 * 2377 2352 * @returns nanoseconds. 2378 * @param pTimer Timer handle as returned by one of the create functions. 2379 * @param u64Ticks The clock ticks. 2353 * @param pVM The cross context VM structure. 2354 * @param hTimer Timer handle as returned by one of the create functions. 2355 * @param cTicks The clock ticks. 2380 2356 * @remark There could be rounding errors here. We just do a simple integer divide 2381 2357 * without any adjustments. 2382 2358 */ 2383 VMMDECL(uint64_t) TMTimerToNano(PTMTIMER pTimer, uint64_t u64Ticks) 2384 { 2385 #ifdef IN_RING0 2386 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 2387 #endif 2359 VMMDECL(uint64_t) TMTimerToNano(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicks) 2360 { 2361 PTMTIMER pTimer; 2362 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, 0, pTimer); 2388 2363 switch (pTimer->enmClock) 2389 2364 { … … 2391 2366 case TMCLOCK_VIRTUAL_SYNC: 2392 2367 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000); 2393 return u64Ticks;2368 return cTicks; 2394 2369 2395 2370 case TMCLOCK_REAL: 2396 2371 AssertCompile(TMCLOCK_FREQ_REAL == 1000); 2397 return u64Ticks * 1000000;2372 return cTicks * 1000000; 2398 2373 2399 2374 default: … … 2408 2383 * 2409 2384 * @returns microseconds. 2410 * @param pTimer Timer handle as returned by one of the create functions. 2411 * @param u64Ticks The clock ticks. 2385 * @param pVM The cross context VM structure. 2386 * @param hTimer Timer handle as returned by one of the create functions. 2387 * @param cTicks The clock ticks. 2412 2388 * @remark There could be rounding errors here. We just do a simple integer divide 2413 2389 * without any adjustments. 2414 2390 */ 2415 VMMDECL(uint64_t) TMTimerToMicro(PTMTIMER pTimer, uint64_t u64Ticks) 2416 { 2417 #ifdef IN_RING0 2418 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 2419 #endif 2391 VMMDECL(uint64_t) TMTimerToMicro(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicks) 2392 { 2393 PTMTIMER pTimer; 2394 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, 0, pTimer); 2420 2395 switch (pTimer->enmClock) 2421 2396 { … … 2423 2398 case TMCLOCK_VIRTUAL_SYNC: 2424 2399 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000); 2425 return u64Ticks / 1000;2400 return cTicks / 1000; 2426 2401 2427 2402 case TMCLOCK_REAL: 2428 2403 AssertCompile(TMCLOCK_FREQ_REAL == 1000); 2429 return u64Ticks * 1000;2404 return cTicks * 1000; 2430 2405 2431 2406 default: … … 2440 2415 * 2441 2416 * @returns milliseconds. 2442 * @param pTimer Timer handle as returned by one of the create functions. 2443 * @param u64Ticks The clock ticks. 2417 * @param pVM The cross context VM structure. 2418 * @param hTimer Timer handle as returned by one of the create functions. 2419 * @param cTicks The clock ticks. 2444 2420 * @remark There could be rounding errors here. We just do a simple integer divide 2445 2421 * without any adjustments. 2446 2422 */ 2447 VMMDECL(uint64_t) TMTimerToMilli(PTMTIMER pTimer, uint64_t u64Ticks) 2448 { 2449 #ifdef IN_RING0 2450 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 2451 #endif 2423 VMMDECL(uint64_t) TMTimerToMilli(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicks) 2424 { 2425 PTMTIMER pTimer; 2426 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, 0, pTimer); 2452 2427 switch (pTimer->enmClock) 2453 2428 { … … 2455 2430 case TMCLOCK_VIRTUAL_SYNC: 2456 2431 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000); 2457 return u64Ticks / 1000000;2432 return cTicks / 1000000; 2458 2433 2459 2434 case TMCLOCK_REAL: 2460 2435 AssertCompile(TMCLOCK_FREQ_REAL == 1000); 2461 return u64Ticks;2436 return cTicks; 2462 2437 2463 2438 default: … … 2472 2447 * 2473 2448 * @returns timer clock ticks. 2474 * @param pTimer Timer handle as returned by one of the create functions. 2475 * @param cNanoSecs The nanosecond value ticks to convert. 2449 * @param pVM The cross context VM structure. 2450 * @param hTimer Timer handle as returned by one of the create functions. 2451 * @param cNanoSecs The nanosecond value ticks to convert. 2476 2452 * @remark There could be rounding and overflow errors here. 2477 2453 */ 2478 VMMDECL(uint64_t) TMTimerFromNano(PTMTIMER pTimer, uint64_t cNanoSecs) 2479 { 2480 #ifdef IN_RING0 2481 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 2482 #endif 2454 VMMDECL(uint64_t) TMTimerFromNano(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cNanoSecs) 2455 { 2456 PTMTIMER pTimer; 2457 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, 0, pTimer); 2483 2458 switch (pTimer->enmClock) 2484 2459 { … … 2503 2478 * 2504 2479 * @returns timer clock ticks. 2505 * @param pTimer Timer handle as returned by one of the create functions. 2506 * @param cMicroSecs The microsecond value ticks to convert. 2480 * @param pVM The cross context VM structure. 2481 * @param hTimer Timer handle as returned by one of the create functions. 2482 * @param cMicroSecs The microsecond value ticks to convert. 2507 2483 * @remark There could be rounding and overflow errors here. 2508 2484 */ 2509 VMMDECL(uint64_t) TMTimerFromMicro(PTMTIMER pTimer, uint64_t cMicroSecs) 2510 { 2511 #ifdef IN_RING0 2512 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 2513 #endif 2485 VMMDECL(uint64_t) TMTimerFromMicro(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cMicroSecs) 2486 { 2487 PTMTIMER pTimer; 2488 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, 0, pTimer); 2514 2489 switch (pTimer->enmClock) 2515 2490 { … … 2534 2509 * 2535 2510 * @returns timer clock ticks. 2536 * @param pVM 2537 * @param pTimerTimer handle as returned by one of the create functions.2538 * @param cMilliSecs 2511 * @param pVM The cross context VM structure. 2512 * @param hTimer Timer handle as returned by one of the create functions. 2513 * @param cMilliSecs The millisecond value ticks to convert. 2539 2514 * @remark There could be rounding and overflow errors here. 2540 2515 */ 2541 VMMDECL(uint64_t) TMTimerFromMilli(PVMCC pVM, PTMTIMER pTimer, uint64_t cMilliSecs) 2542 { 2543 RT_NOREF(pVM); 2544 Assert(pVM == pTimer->CTX_SUFF(pVM)); 2545 #ifdef IN_RING0 2546 Assert(pTimer->fFlags & TMTIMER_FLAGS_RING0); 2547 #endif 2516 VMMDECL(uint64_t) TMTimerFromMilli(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cMilliSecs) 2517 { 2518 PTMTIMER pTimer; 2519 TMTIMER_HANDLE_TO_PTR_RETURN_EX(pVM, hTimer, 0, pTimer); 2548 2520 switch (pTimer->enmClock) 2549 2521 {
Note:
See TracChangeset
for help on using the changeset viewer.