Changeset 9444 in vbox for trunk/src/VBox/Runtime/r0drv
- Timestamp:
- Jun 5, 2008 6:08:17 PM (17 years ago)
- Location:
- trunk/src/VBox/Runtime/r0drv
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/freebsd/timer-r0drv-freebsd.c
r9352 r9444 97 97 * Validate flags. 98 98 */ 99 if (!RTTIMER_FLAGS_ IS_VALID(fFlags))99 if (!RTTIMER_FLAGS_ARE_VALID(fFlags)) 100 100 return VERR_INVALID_PARAMETER; 101 101 if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC) … … 214 214 if ( pTimer->iCpu == RTTIMER_FLAGS_CPU_MASK 215 215 || (u_int)pTimer->iCpu == curcpu) 216 pTimer->pfnTimer(pTimer, pTimer->pvUser );216 pTimer->pfnTimer(pTimer, pTimer->pvUser, pTimer->iTick); 217 217 } 218 218 … … 223 223 224 224 /* calculate and set the next timeout */ 225 pTimer->iTick++; 225 226 if (!pTimer->u64NanoInterval) 226 227 { … … 232 233 struct timeval tv; 233 234 const uint64_t u64NanoTS = RTTimeNanoTS(); 234 pTimer->iTick++;235 235 pTimer->u64NextTS = pTimer->u64StartTS + pTimer->iTick * pTimer->u64NanoInterval; 236 236 if (pTimer->u64NextTS < u64NanoTS) … … 245 245 if ( !pTimer->fSpecificCpu 246 246 || pTimer->iCpu == curcpu) 247 pTimer->pfnTimer(pTimer, pTimer->pvUser );247 pTimer->pfnTimer(pTimer, pTimer->pvUser, pTimer->iTick); 248 248 else 249 249 smp_rendezvous(NULL, rtTimerFreeBSDIpiAction, NULL, pvTimer); -
trunk/src/VBox/Runtime/r0drv/linux/timer-r0drv-linux.c
r9372 r9444 46 46 #include "internal/magics.h" 47 47 48 #if !defined(RT_USE_LINUX_HRTIMER) && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) /* ?? */ 48 #if !defined(RT_USE_LINUX_HRTIMER) \ 49 && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) \ 50 && 0 /* disabled because it somehow sucks. */ 49 51 # define RT_USE_LINUX_HRTIMER 50 52 #endif … … 193 195 194 196 197 #ifndef RT_USE_LINUX_HRTIMER 198 /** 199 * Converts a nano second interval to jiffies. 200 * 201 * @returns Jiffies. 202 * @param cNanoSecs Nanoseconds. 203 */ 204 DECLINLINE(unsigned long) rtTimerLnxNanoToJiffies(uint64_t cNanoSecs) 205 { 206 /* this can be made even better... */ 207 if (cNanoSecs > (uint64_t)TICK_NSEC * MAX_JIFFY_OFFSET) 208 return MAX_JIFFY_OFFSET; 209 #if ARCH_BITS == 32 210 if (RT_LIKELY(cNanoSecs <= UINT32_MAX)) 211 return ((uint32_t)cNanoSecs + (TICK_NSEC-1)) / TICK_NSEC; 212 #endif 213 return (cNanoSecs + (TICK_NSEC-1)) / TICK_NSEC; 214 } 215 #endif 216 217 195 218 /** 196 219 * Starts a sub-timer (RTTimerStart). … … 206 229 */ 207 230 uint64_t u64NextTS = u64Now + u64First; 208 pSubTimer->u64StartTS = u64N ow;231 pSubTimer->u64StartTS = u64NextTS; 209 232 pSubTimer->u64NextTS = u64NextTS; 233 pSubTimer->iTick = 0; 210 234 211 235 #ifdef RT_USE_LINUX_HRTIMER … … 221 245 #else 222 246 { 223 uint64_t cJiffies = !u64First ? 0 : u64First / TICK_NSEC; 224 if (cJiffies > MAX_JIFFY_OFFSET) 225 cJiffies = MAX_JIFFY_OFFSET; 247 unsigned long cJiffies = !u64First ? 0 : rtTimerLnxNanoToJiffies(u64First); 226 248 mod_timer(&pSubTimer->LnxTimer, jiffies + cJiffies); 227 249 } … … 280 302 * For the specific cpu case, we're just ignoring timer migration for now... (bad) 281 303 */ 282 if ( pTimer->fSuspended304 if ( ASMAtomicUoReadBool(&pTimer->fSuspended) 283 305 #ifdef CONFIG_SMP 284 306 || ( pTimer->fAllCpus … … 306 328 #endif 307 329 308 pTimer->pfnTimer(pTimer, pTimer->pvUser );330 pTimer->pfnTimer(pTimer, pTimer->pvUser, ++pSubTimer->iTick); 309 331 } 310 332 else … … 318 340 */ 319 341 const uint64_t u64NanoTS = RTTimeNanoTS(); 320 #if 0 /* this needs to be tested before it's enabled. */ 321 if ( pSubTimer->iTick == 0 322 && pTimer->u64NanoInterval < u64NanoTS) 323 pSubTimer->u64StartTS = pSubTimer->u64FirstTS = u64NanoTS - 1000; /* ugly */ 324 #endif 325 pSubTimer->iTick++; 342 const uint64_t iTick = ++pSubTimer->iTick; 343 #ifdef RT_USE_LINUX_HRTIMER 344 if (iTick == 1) 345 pSubTimer->u64StartTS = u64NanoTS; 346 #endif 326 347 pSubTimer->u64NextTS = pSubTimer->u64StartTS 327 + pSubTimer->iTick * pTimer->u64NanoInterval;348 + iTick * pTimer->u64NanoInterval; 328 349 if (pSubTimer->u64NextTS < u64NanoTS) 329 350 pSubTimer->u64NextTS = u64NanoTS + RTTimerGetSystemGranularity() / 2; … … 341 362 { 342 363 uint64_t offDelta = pSubTimer->u64NextTS - u64NanoTS; 343 uint64_t cJiffies = offDelta / TICK_NSEC; /* (We end up doing 64-bit div here which ever way we go.) */ 344 if (cJiffies > MAX_JIFFY_OFFSET) 345 cJiffies = MAX_JIFFY_OFFSET; 346 else if (cJiffies == 0) 347 cJiffies = 1; 364 unsigned long cJiffies = rtTimerLnxNanoToJiffies(offDelta); 348 365 mod_timer(&pSubTimer->LnxTimer, jiffies + cJiffies); 349 366 } … … 353 370 * Run the timer. 354 371 */ 355 pTimer->pfnTimer(pTimer, pTimer->pvUser );372 pTimer->pfnTimer(pTimer, pTimer->pvUser, iTick); 356 373 } 357 374 … … 512 529 513 530 /* 514 * We have to be kind of careful here as we might RTTimerStop (and RTTimerDestroy),515 * thus the paranoia.531 * We have to be kind of careful here as we might be racing RTTimerStop 532 * (and/or RTTimerDestroy, thus the paranoia. 516 533 */ 517 534 hSpinlock = pTimer->hSpinlock; … … 522 539 RTSpinlockAcquire(hSpinlock, &Tmp); 523 540 524 if ( ! pTimer->fSuspended541 if ( !ASMAtomicUoReadBool(&pTimer->fSuspended) 525 542 && pTimer->u32Magic == RTTIMER_MAGIC) 526 543 { … … 564 581 565 582 /* Is it active? */ 566 if ( ! pTimer->fSuspended567 && !pTimer->u32Magic == RTTIMER_MAGIC)583 if ( !ASMAtomicUoReadBool(&pTimer->fSuspended) 584 && pTimer->u32Magic == RTTIMER_MAGIC) 568 585 { 569 586 switch (enmEvent) … … 578 595 RTTIMERLINUXSTARTONCPUARGS Args; 579 596 Args.u64Now = RTTimeNanoTS(); 580 Args.u64First = pTimer->u64NanoInterval;597 Args.u64First = 0; 581 598 582 599 if (RTMpCpuId() == idCpu) … … 644 661 AssertReturn(pTimer->u32Magic == RTTIMER_MAGIC, VERR_INVALID_HANDLE); 645 662 646 if (! pTimer->fSuspended)663 if (!ASMAtomicUoReadBool(&pTimer->fSuspended)) 647 664 return VERR_TIMER_ACTIVE; 648 665 649 666 Args.u64First = u64First; 650 667 #ifdef CONFIG_SMP 668 /* 669 * Omnit timer? 670 */ 651 671 if (pTimer->fAllCpus) 652 672 return rtTimerLnxStartAll(pTimer, &Args); … … 654 674 655 675 /* 656 * This is pretty straight forwards.676 * Simple timer - Pretty straight forward. 657 677 */ 658 678 Args.u64Now = RTTimeNanoTS(); … … 686 706 AssertReturn(pTimer->u32Magic == RTTIMER_MAGIC, VERR_INVALID_HANDLE); 687 707 688 if ( pTimer->fSuspended)708 if (ASMAtomicUoReadBool(&pTimer->fSuspended)) 689 709 return VERR_TIMER_SUSPENDED; 690 710 691 711 #ifdef CONFIG_SMP 712 /* 713 * Omni timer? 714 */ 692 715 if (pTimer->fAllCpus) 693 716 return rtTimerLnxStopAll(pTimer); … … 695 718 696 719 /* 697 * Cancel the timer.698 */ 699 ASMAtomicWriteBool(&pTimer->fSuspended, true); /* just to be on the safe side. */720 * Simple timer. 721 */ 722 ASMAtomicWriteBool(&pTimer->fSuspended, true); 700 723 rtTimerLnxSetState(&pTimer->aSubTimers[0].enmState, RTTIMERLNXSTATE_STOPPING); 701 724 rtTimerLnxStopSubTimer(&pTimer->aSubTimers[0]); … … 732 755 * Stop the timer if it's running. 733 756 */ 734 if (!ASMAtomicUoReadBool(&pTimer->fSuspended)) /* serious paranoia */757 if (!ASMAtomicUoReadBool(&pTimer->fSuspended)) 735 758 RTTimerStop(pTimer); 736 759 … … 759 782 * Validate flags. 760 783 */ 761 if (!RTTIMER_FLAGS_ IS_VALID(fFlags))784 if (!RTTIMER_FLAGS_ARE_VALID(fFlags)) 762 785 return VERR_INVALID_PARAMETER; 763 786 if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC) … … 811 834 #else 812 835 init_timer(&pTimer->aSubTimers[iCpu].LnxTimer); 813 pTimer->aSubTimers[iCpu].LnxTimer.data = (unsigned long) pTimer;836 pTimer->aSubTimers[iCpu].LnxTimer.data = (unsigned long)&pTimer->aSubTimers[iCpu]; 814 837 pTimer->aSubTimers[iCpu].LnxTimer.function = rtTimerLinuxCallback; 815 838 pTimer->aSubTimers[iCpu].LnxTimer.expires = jiffies; -
trunk/src/VBox/Runtime/r0drv/os2/timer-r0drv-os2.cpp
r9416 r9444 319 319 { 320 320 pTimer->fDone = true; 321 pTimer->iTick++; 321 322 322 323 /* calculate the next timeout */ … … 334 335 void *pvUser = pTimer->pvUser; 335 336 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 336 pfnTimer(pTimer, pvUser );337 pfnTimer(pTimer, pvUser, pTimer->iTick); 337 338 338 339 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp); -
trunk/src/VBox/Runtime/r0drv/solaris/timer-r0drv-solaris.c
r8245 r9444 64 64 /** The CPU it must run on if fSpecificCpu is set. */ 65 65 uint8_t iCpu; 66 /** The current timer tick (since last timer start). */ 67 uint64_t iTick; 66 68 /** The Solaris cyclic structure. */ 67 69 cyc_handler_t CyclicInfo; … … 91 93 * Validate flags. 92 94 */ 93 if (!RTTIMER_FLAGS_ IS_VALID(fFlags))95 if (!RTTIMER_FLAGS_ARE_VALID(fFlags)) 94 96 return VERR_INVALID_PARAMETER; 95 97 if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC) 96 98 /** @todo implement && (fFlags & RTTIMER_FLAGS_CPU_ALL) != RTTIMER_FLAGS_CPU_ALL*/) 97 99 return VERR_NOT_SUPPORTED; 98 100 99 101 /* 100 102 * Allocate and initialize the timer handle. … … 108 110 pTimer->fSpecificCpu = !!(fFlags & RTTIMER_FLAGS_CPU_SPECIFIC); 109 111 pTimer->iCpu = fFlags & RTTIMER_FLAGS_CPU_MASK; 112 pTimer->iTick = 0; 110 113 pTimer->CyclicInfo.cyh_func = rtTimerSolarisCallback; 111 114 pTimer->CyclicInfo.cyh_level = CY_LOCK_LEVEL; … … 167 170 168 171 pTimer->fSuspended = false; 172 pTimer->iTick = 0; 169 173 timerSpec.cyt_when = u64First; 170 174 timerSpec.cyt_interval = pTimer->u64NanoInterval == 0 ? u64First : pTimer->u64NanoInterval; 171 175 172 176 mutex_enter(&cpu_lock); 173 177 pTimer->CyclicID = cyclic_add(&pTimer->CyclicInfo, &timerSpec); … … 190 194 pTimer->fSuspended = true; 191 195 rtTimerSolarisStop(pTimer); 192 196 193 197 return VINF_SUCCESS; 194 198 } … … 209 213 210 214 /* Callback user defined callback function */ 211 pTimer->pfnTimer(pTimer, pTimer->pvUser );215 pTimer->pfnTimer(pTimer, pTimer->pvUser, ++pTimer->iTick); 212 216 } 213 217 -
trunk/src/VBox/Runtime/r0drv/solaris/vbi/timer-r0drv-solaris.c
r9176 r9444 65 65 uint8_t iCpu; 66 66 /** The Solaris timer handle. */ 67 void *handle; 67 void *handle; 68 /** The user callback. */ 69 PFNRTTIMER pfnTimer; 70 /** The current tick count. */ 71 uint64_t iTick; 72 68 73 } RTTIMER; 69 74 70 75 76 /** 77 * Callback wrapper for adding the new iTick argument. 78 * 79 * @param pTimer The timer. 80 * @param pvUser The user argument. 81 */ 82 static void rtTimerSolarisCallbackWrapper(PRTTIMER pTimer, void *pvUser) 83 { 84 pTimer->pfnTimer(pTimer, pvUser, ++pTimer->iTick); 85 } 86 87 88 89 71 90 RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, unsigned fFlags, PFNRTTIMER pfnTimer, void *pvUser) 72 91 { … … 76 95 * Validate flags. 77 96 */ 78 if (!RTTIMER_FLAGS_ IS_VALID(fFlags))97 if (!RTTIMER_FLAGS_ARE_VALID(fFlags)) 79 98 return VERR_INVALID_PARAMETER; 80 99 if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC) … … 93 112 pTimer->fSpecificCpu = !!(fFlags & RTTIMER_FLAGS_CPU_SPECIFIC); 94 113 pTimer->iCpu = fFlags & RTTIMER_FLAGS_CPU_MASK; 95 pTimer->handle = vbi_timer_create(pfnTimer, pTimer, pvUser, u64NanoInterval); 114 pTimer->handle = vbi_timer_create(rtTimerSolarisCallbackWrapper, pTimer, pvUser, u64NanoInterval); 115 pTimer->pfnTimer = pfnTimer; 116 pTimer->iTick = 0; 96 117 97 118 *ppTimer = pTimer;
Note:
See TracChangeset
for help on using the changeset viewer.