VirtualBox

Ignore:
Timestamp:
Dec 16, 2009 1:44:58 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56075
Message:

Runtime/r0drv/timer-linux: make the hrtimer code work, requires Linux 2.6.28+ now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/linux/timer-r0drv-linux.c

    r24181 r25427  
    4848#include "internal/magics.h"
    4949
     50/* We use the API of Linux 2.6.28+ (hrtimer_add_expires_ns()) */
    5051#if !defined(RT_USE_LINUX_HRTIMER) \
    51     && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) \
    52     && 0 /* disabled because it somehow sucks. */
     52    && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28) \
     53    && 0 /* currently disabled */
    5354# define RT_USE_LINUX_HRTIMER
    5455#endif
     
    5657/* This check must match the ktime usage in rtTimeGetSystemNanoTS() / time-r0drv-linux.c. */
    5758#if defined(RT_USE_LINUX_HRTIMER) \
    58  && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
    59 # error "RT_USE_LINUX_HRTIMER requires 2.6.16 or later, sorry."
     59 && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
     60# error "RT_USE_LINUX_HRTIMER requires 2.6.28 or later, sorry."
    6061#endif
    6162
     
    99100#else
    100101    struct timer_list       LnxTimer;
    101 #endif
    102102    /** The start of the current run (ns).
    103103     * This is used to calculate when the timer ought to fire the next time. */
     
    106106     * This is used to calculate when the timer ought to fire the next time. */
    107107    uint64_t                u64NextTS;
     108#endif
    108109    /** The current tick number (since u64StartTS). */
    109110    uint64_t                iTick;
     
    250251    if (cNanoSecs > (uint64_t)TICK_NSEC * MAX_JIFFY_OFFSET)
    251252        return MAX_JIFFY_OFFSET;
    252 #if ARCH_BITS == 32
     253# if ARCH_BITS == 32
    253254    if (RT_LIKELY(cNanoSecs <= UINT32_MAX))
    254255        return ((uint32_t)cNanoSecs + (TICK_NSEC-1)) / TICK_NSEC;
    255 #endif
     256# endif
    256257    return (cNanoSecs + (TICK_NSEC-1)) / TICK_NSEC;
    257258}
    258 #endif
     259#endif /* ! RT_USE_LINUX_HRTIMER */
    259260
    260261
     
    272273     */
    273274    uint64_t u64NextTS = u64Now + u64First;
     275#ifndef RT_USE_LINUX_HRTIMER
    274276    pSubTimer->u64StartTS = u64NextTS;
    275277    pSubTimer->u64NextTS = u64NextTS;
     278#endif
     279
    276280    pSubTimer->iTick = 0;
    277281
     
    368372    else
    369373    {
     374        const uint64_t iTick = ++pSubTimer->iTick;
     375
     376#ifdef RT_USE_LINUX_HRTIMER
     377        hrtimer_add_expires_ns(&pSubTimer->LnxTimer, pTimer->u64NanoInterval);
     378        rc = HRTIMER_RESTART;
     379#else
     380        const uint64_t u64NanoTS = RTTimeNanoTS();
     381
    370382        /*
    371383         * Interval timer, calculate the next timeout and re-arm it.
     
    375387         * This may of course backfire with highres timers...
    376388         */
    377         const uint64_t u64NanoTS = RTTimeNanoTS();
    378         const uint64_t iTick = ++pSubTimer->iTick;
    379 
    380389        if (RT_UNLIKELY(iTick == 1))
    381390        {
    382 #ifdef RT_USE_LINUX_HRTIMER
    383             pSubTimer->u64StartTS = pSubTimer->u64NextTS = u64NanoTS;//rtTimerLnxKtToNano(pSubTimer->LnxTimer.base->softirq_time);
    384 #else
    385391            pSubTimer->u64StartTS = pSubTimer->u64NextTS = u64NanoTS;
    386392            pSubTimer->ulNextJiffies = jiffies;
    387 #endif
    388393        }
    389394
    390395        pSubTimer->u64NextTS += pTimer->u64NanoInterval;
    391 
    392 #ifdef RT_USE_LINUX_HRTIMER
    393         while (pSubTimer->u64NextTS < u64NanoTS)
    394             pSubTimer->u64NextTS += pTimer->u64NanoInterval;
    395 
    396         pSubTimer->LnxTimer.expires = rtTimerLnxNanoToKt(pSubTimer->u64NextTS);
    397         rc = HRTIMER_RESTART;
    398 #else
    399396        if (pTimer->cJiffies)
    400397        {
     
    896893        pTimer->aSubTimers[iCpu].LnxTimer.function = rtTimerLinuxCallback;
    897894        pTimer->aSubTimers[iCpu].LnxTimer.expires  = jiffies;
    898 #endif
    899895        pTimer->aSubTimers[iCpu].u64StartTS = 0;
    900896        pTimer->aSubTimers[iCpu].u64NextTS = 0;
     897#endif
    901898        pTimer->aSubTimers[iCpu].iTick = 0;
    902899        pTimer->aSubTimers[iCpu].pParent = pTimer;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette