Changeset 2064


Ignore:
Timestamp:
Jun 23, 2005, 8:02:57 AM (20 years ago)
Author:
bird
Message:

Changed the bootime algorithm.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/misc/sysctl_os2.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2063 r2064  
    3939#include <sys/time.h>
    4040#include <InnoTekLIBC/FastInfoBlocks.h>
     41#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_MISC
     42#include <InnoTekLIBC/logstrict.h>
    4143#define _KERNEL
    4244#include <sys/sysctl.h>
     
    5557    if (!tv.tv_sec)
    5658    {
     59        /*
     60         * Use the highres timer to estimate the wrap-arounds.
     61         * Then use that with the millisecond timer to get a
     62         * stable number.
     63         */
     64        unsigned cWraps = 0;
    5765        union
    5866        {
     
    6270        ULONG ul;
    6371        FS_VAR_SAVE_LOAD();
    64 
    65         /* Try the highres timer first. */
    6672        if (   !DosTmrQueryFreq(&ul)
    6773            && !DosTmrQueryTime(&u.qw))
    6874        {
    69             gettimeofday(&tv, NULL);
    70             tv.tv_sec -= u.ull / ul;
    7175            long double lrd = u.ull;
    72             lrd *= 1000000;
     76            lrd *= 1000;
    7377            lrd /= ul;
    74             ul = (ULONG)lrd;
    75             tv.tv_usec -= ul % 1000000;
    76         }
    77         else
    78         {
    79             /* Use the millisecond counter. */
    80             gettimeofday(&tv, NULL);
    81             ul = fibGetMsCount();
    82             unsigned u = (ul % 1000) * 1000;
    83             tv.tv_usec -= u;
    84             tv.tv_sec -= ul / 1000;
     78            unsigned long long ull = 0x100000000ULL;
     79            cWraps = lrd / ull;
    8580        }
    8681        FS_RESTORE();
    87         if (tv.tv_usec < 0)
     82
     83        gettimeofday(&tv, NULL);
     84        gettimeofday(&tv, NULL);
     85        ul = fibGetMsCount();
     86        unsigned cSecs = (ul % 1000) * 1000;
     87        tv.tv_usec -= cSecs;
     88        tv.tv_sec -= ul / 1000;
     89        for (;;)
    8890        {
    89             tv.tv_sec--;
    90             tv.tv_usec += 1000000;
     91            if (tv.tv_usec < 0)
     92            {
     93                tv.tv_sec--;
     94                tv.tv_usec += 1000000;
     95            }
     96            if (cWraps-- <= 0)
     97                break;
     98            tv.tv_sec  -= 4294967;
     99            tv.tv_usec -= 296000;
    91100        }
     101        LIBC_ASSERT(tv.tv_sec > 0);
     102        LIBC_ASSERT(tv.tv_usec >= 0 && tv.tv_usec < 1000000);
    92103    }
    93104
Note: See TracChangeset for help on using the changeset viewer.