VirtualBox

Ignore:
Timestamp:
Oct 8, 2008 6:33:59 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
37593
Message:

vboxadd-timesync: added (disabled) code for using adjusting the guest time with adjtime()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/daemon/vboxadd_timesync.c

    r10554 r13101  
    9090    for (;;)
    9191    {
    92         c = getopt_long(argc, argv, "", options, NULL);
     92        c = getopt_long(argc, argv, "i:dh", options, NULL);
    9393        if (c == -1)
    9494            break;
     
    151151            if (VBOX_SUCCESS(req.header.rc))
    152152            {
    153                 /** Set the system time.
    154                  *  @@todo r=frank: This is too choppy. Adapt time smoother and try
    155                  *                  to prevent negative time differences. */
     153                /* Adapt time smoothly and try to prevent negative time differences. */
     154                uint64_t u64Now;
     155                int64_t  i64Diff;
     156                int64_t  i64AbsDiff;
    156157                struct timeval tv;
    157                 tv.tv_sec  =  req.time / (uint64_t)1000;
    158                 tv.tv_usec = (req.time % (uint64_t)1000) * 1000;
    159                 settimeofday(&tv, NULL);
     158
     159                gettimeofday(&tv, NULL);
     160#if 0
     161                u64Now     = (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000;
     162                i64Diff    = (int64_t)(req.time - u64Now);
     163                i64AbsDiff = i64Diff < 0 ? -i64Diff : i64Diff;
     164
     165                if (i64AbsDiff < 300000)
     166                {
     167                    /* difference less than 5 minutes => smoothly adapt the guest time */
     168                    int32_t i32Diff = (int32_t)i64Diff;
     169                    int32_t i32Sec, i32Micro;
     170                    struct timeval delta;
     171
     172                    i32Sec   = i32Diff / 1000;
     173                    i32Micro = (i32Diff % 1000) * 1000;
     174
     175                    if (i32Micro < 0)
     176                        i32Micro = -i32Micro;
     177                    delta.tv_sec  = i32Sec;
     178                    delta.tv_usec = i32Micro;
     179
     180                    /* adjtime on Linux adjusts the time about 5 ms per 10 seconds, even
     181                     * for very huge differences */
     182                    adjtime(&delta, NULL);
     183                }
     184                else
     185#endif
     186                {
     187                    /* difference more than 5 minutes => set the time with all consequences */
     188                    tv.tv_sec  =  req.time / (uint64_t)1000;
     189                    tv.tv_usec = (req.time % (uint64_t)1000) * 1000;
     190                    settimeofday(&tv, NULL);
     191                }
    160192            }
    161193            else
    162             {
    163194                printf("Error querying host time! header.rc = %d\n", req.header.rc);
    164             }
    165195        }
    166196        else
    167         {
    168197            printf("Error performing VMM request! errno = %d\n", errno);
    169         }
    170             /* wait for the next run */
     198
     199        /* wait for the next run */
    171200        safe_sleep(secInterval);
    172201
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