VirtualBox

Ignore:
Timestamp:
Jul 21, 2010 1:39:14 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63851
Message:

IPRT/vboxdrv: We have RTTimeSystemNanoTS in ring-0 now, so use it.

Location:
trunk/src/VBox/Runtime/common/time
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/time/time.cpp

    r28800 r30961  
    257257RTDECL(PRTTIME) RTTimeExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec)
    258258{
     259    int64_t         i64Div;
     260    int32_t         i32Div;
     261    int32_t         i32Rem;
     262    unsigned        iYear;
     263    const uint16_t *paiDayOfYear;
     264    int             iMonth;
     265
    259266    AssertMsg(VALID_PTR(pTime), ("%p\n", pTime));
    260267    AssertMsg(VALID_PTR(pTimeSpec), ("%p\n", pTime));
     
    263270     * The simple stuff first.
    264271     */
    265     pTime->fFlags        = RTTIME_FLAGS_TYPE_UTC;
    266     int64_t i64Div = pTimeSpec->i64NanosecondsRelativeToUnixEpoch;
    267     int32_t i32Rem = (int32_t)(i64Div % 1000000000);
     272    pTime->fFlags = RTTIME_FLAGS_TYPE_UTC;
     273    i64Div = pTimeSpec->i64NanosecondsRelativeToUnixEpoch;
     274    i32Rem = (int32_t)(i64Div % 1000000000);
    268275    i64Div /= 1000000000;
    269276    if (i32Rem < 0)
     
    285292
    286293    /* minute */
    287     int32_t i32Div = (int32_t)i64Div;   /* 60,000,000,000 > 33bit, so 31bit suffices. */
     294    i32Div = (int32_t)i64Div;   /* 60,000,000,000 > 33bit, so 31bit suffices. */
    288295    i32Rem = i32Div % 60;
    289296    i32Div /= 60;
     
    314321     * generate a table and perform a simple two way search from the modulus 365 derived.
    315322     */
    316     unsigned iYear = OFF_YEAR_IDX_EPOCH + i32Div / 365;
     323    iYear = OFF_YEAR_IDX_EPOCH + i32Div / 365;
    317324    while (g_aoffYear[iYear + 1] <= i32Div)
    318325        iYear++;
     
    327334     * ensure that the index is matching or too small.
    328335     */
    329     const uint16_t *paiDayOfYear;
    330336    if (rtTimeIsLeapYear(pTime->i32Year))
    331337    {
     
    338344        paiDayOfYear = &g_aiDayOfYear[0];
    339345    }
    340     int iMonth = i32Div / 32;
     346    iMonth = i32Div / 32;
    341347    i32Div++;
    342348    while (paiDayOfYear[iMonth + 1] <= i32Div)
     
    370376RTDECL(PRTTIMESPEC) RTTimeImplode(PRTTIMESPEC pTimeSpec, PCRTTIME pTime)
    371377{
     378    int32_t     i32Days;
     379    uint32_t    u32Secs;
     380    int64_t     i64Nanos;
     381
    372382    /*
    373383     * Validate input.
     
    386396     * Do the conversion to nanoseconds.
    387397     */
    388     int32_t i32Days  = g_aoffYear[pTime->i32Year - OFF_YEAR_IDX_0_YEAR]
    389                      + pTime->u16YearDay - 1;
     398    i32Days  = g_aoffYear[pTime->i32Year - OFF_YEAR_IDX_0_YEAR]
     399             + pTime->u16YearDay - 1;
    390400    AssertMsgReturn(i32Days <= RTTIME_MAX_DAY && i32Days >= RTTIME_MIN_DAY, ("%RI32\n", i32Days), NULL);
    391401
    392     uint32_t u32Secs = pTime->u8Second
    393                      + pTime->u8Minute * 60
    394                      + pTime->u8Hour   * 3600;
    395     int64_t i64Nanos = (uint64_t)pTime->u32Nanosecond
    396                      + u32Secs * UINT64_C(1000000000);
     402    u32Secs = pTime->u8Second
     403             + pTime->u8Minute * 60
     404             + pTime->u8Hour   * 3600;
     405    i64Nanos = (uint64_t)pTime->u32Nanosecond
     406             + u32Secs * UINT64_C(1000000000);
    397407    AssertMsgReturn(i32Days != RTTIME_MAX_DAY || i64Nanos <= RTTIME_MAX_DAY_NANO, ("%RI64\n", i64Nanos), NULL);
    398408    AssertMsgReturn(i32Days != RTTIME_MIN_DAY || i64Nanos >= RTTIME_MIN_DAY_NANO, ("%RI64\n", i64Nanos), NULL);
     
    412422PRTTIME rtTimeNormalizeInternal(PRTTIME pTime)
    413423{
     424    unsigned    uSecond;
     425    unsigned    uMinute;
     426    unsigned    uHour;
     427    bool        fLeapYear;
     428
    414429    /*
    415430     * Fix the YearDay and Month/MonthDay.
    416431     */
    417     bool fLeapYear = rtTimeIsLeapYear(pTime->i32Year);
     432    fLeapYear = rtTimeIsLeapYear(pTime->i32Year);
    418433    if (!pTime->u16YearDay)
    419434    {
     
    469484            do
    470485            {
     486                uint16_t u16YearDay;
     487
    471488                /* If you change one, zero the other to make clear what you mean. */
    472489                AssertBreak(pTime->u8Month <= 12);
     
    474491                                                  ? g_acDaysInMonthsLeap[pTime->u8Month - 1]
    475492                                                  : g_acDaysInMonths[pTime->u8Month - 1]));
    476                 uint16_t u16YearDay = pTime->u8MonthDay - 1
    477                                     + (fLeapYear
    478                                        ? g_aiDayOfYearLeap[pTime->u8Month - 1]
    479                                        : g_aiDayOfYear[pTime->u8Month - 1]);
     493                u16YearDay = pTime->u8MonthDay - 1
     494                           + (fLeapYear
     495                              ? g_aiDayOfYearLeap[pTime->u8Month - 1]
     496                              : g_aiDayOfYear[pTime->u8Month - 1]);
    480497                AssertBreak(u16YearDay == pTime->u16YearDay);
    481498                fRecalc = false;
     
    484501        if (fRecalc)
    485502        {
     503            const uint16_t *paiDayOfYear;
     504
    486505            /* overflow adjust YearDay */
    487506            while (pTime->u16YearDay > (fLeapYear ? 366 : 365))
     
    494513
    495514            /* calc Month and MonthDay */
    496             const uint16_t *paiDayOfYear = fLeapYear
    497                                          ? &g_aiDayOfYearLeap[0]
    498                                          : &g_aiDayOfYear[0];
     515            paiDayOfYear = fLeapYear
     516                         ? &g_aiDayOfYearLeap[0]
     517                         : &g_aiDayOfYear[0];
    499518            pTime->u8Month = 1;
    500519            while (pTime->u16YearDay > paiDayOfYear[pTime->u8Month])
     
    509528     * Use unsigned int values internally to avoid overflows.
    510529     */
    511     unsigned uSecond = pTime->u8Second;
    512     unsigned uMinute = pTime->u8Minute;
    513     unsigned uHour   = pTime->u8Hour;
     530    uSecond = pTime->u8Second;
     531    uMinute = pTime->u8Minute;
     532    uHour   = pTime->u8Hour;
    514533
    515534    while (pTime->u32Nanosecond >= 1000000000)
     
    668687RTDECL(char *) RTTimeToString(PCRTTIME pTime, char *psz, size_t cb)
    669688{
     689    size_t cch;
     690
    670691    /* (Default to UTC if not specified) */
    671692    if (    (pTime->fFlags & RTTIME_FLAGS_TYPE_MASK) == RTTIME_FLAGS_TYPE_LOCAL
    672693        &&  pTime->offUTC)
    673694    {
    674         Assert(pTime->offUTC <= 840 && pTime->offUTC >= -840);
    675695        int32_t offUTCHour   = pTime->offUTC / 60;
    676696        int32_t offUTCMinute = pTime->offUTC % 60;
    677         char chSign;
     697        char    chSign;
     698        Assert(pTime->offUTC <= 840 && pTime->offUTC >= -840);
    678699        if (pTime->offUTC >= 0)
    679700            chSign = '+';
     
    684705            offUTCHour = -offUTCHour;
    685706        }
    686         size_t cch = RTStrPrintf(psz, cb,
    687                                  "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32%c%02%02",
    688                                  pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
    689                                  pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond,
    690                                  chSign, offUTCHour, offUTCMinute);
     707        cch = RTStrPrintf(psz, cb,
     708                          "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32%c%02%02",
     709                          pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
     710                          pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond,
     711                          chSign, offUTCHour, offUTCMinute);
    691712        if (    cch <= 15
    692713            ||  psz[cch - 5] != chSign)
     
    695716    else
    696717    {
    697         size_t cch = RTStrPrintf(psz, cb, "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32Z",
    698                                  pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
    699                                  pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond);
     718        cch = RTStrPrintf(psz, cb, "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32Z",
     719                          pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
     720                          pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond);
    700721        if (    cch <= 15
    701722            ||  psz[cch - 1] != 'Z')
  • trunk/src/VBox/Runtime/common/time/timesup.cpp

    r29267 r30961  
    8282static const PFNTIMENANOTSINTERNAL g_apfnWorkers[] =
    8383{
    84 #define RTTIMENANO_WORKER_DETECT        0
     84# define RTTIMENANO_WORKER_DETECT        0
    8585    rtTimeNanoTSInternalRediscover,
    86 #define RTTIMENANO_WORKER_SYNC_CPUID    1
     86# define RTTIMENANO_WORKER_SYNC_CPUID    1
    8787    RTTimeNanoTSLegacySync,
    88 #define RTTIMENANO_WORKER_ASYNC_CPUID   2
     88# define RTTIMENANO_WORKER_ASYNC_CPUID   2
    8989    RTTimeNanoTSLegacyAsync,
    90 #define RTTIMENANO_WORKER_SYNC_LFENCE   3
     90# define RTTIMENANO_WORKER_SYNC_LFENCE   3
    9191    RTTimeNanoTSLFenceSync,
    92 #define RTTIMENANO_WORKER_ASYNC_LFENCE  4
     92# define RTTIMENANO_WORKER_ASYNC_LFENCE  4
    9393    RTTimeNanoTSLFenceAsync,
    94 #define RTTIMENANO_WORKER_FALLBACK      5
     94# define RTTIMENANO_WORKER_FALLBACK      5
    9595    rtTimeNanoTSInternalFallback,
    9696};
     
    128128        return rtTimeNanoTSInternalRediscover(pData);
    129129    NOREF(pData);
    130 #if defined(IN_RING3) /** @todo Add ring-0 RTTimeSystemNanoTS to all hosts. */
     130# ifndef IN_RC
    131131    return RTTimeSystemNanoTS();
    132 #else
     132# else
    133133    return 0;
    134 #endif
     134# endif
    135135}
    136136
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