Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba25bac1e0 | ||
|
|
0ff0d40dda | ||
|
|
8f3d9f4bb5 | ||
|
|
56b7374fc4 |
No files matched your search
+9
-179
@@ -116,13 +116,7 @@
|
||||
*/
|
||||
#define LOCKED_PAGE_SLACK 10000
|
||||
|
||||
static struct {
|
||||
Atomic_uint64 uptimeBase;
|
||||
VersionedAtomic version;
|
||||
uint64 monotimeBase;
|
||||
unsigned long jiffiesBase;
|
||||
struct timer_list timer;
|
||||
} uptimeState;
|
||||
u64 uptime_base;
|
||||
|
||||
/*
|
||||
* First Page Locking strategy
|
||||
@@ -190,17 +184,6 @@ static unsigned long compat_totalram_pages(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
|
||||
static void do_gettimeofday(struct timeval *tv)
|
||||
{
|
||||
struct timespec64 now;
|
||||
|
||||
ktime_get_real_ts64(&now);
|
||||
tv->tv_sec = now.tv_sec;
|
||||
tv->tv_usec = now.tv_nsec / 1000;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0) && defined(VERIFY_WRITE)
|
||||
#define write_access_ok(addr, size) access_ok(VERIFY_WRITE, addr, size)
|
||||
#else
|
||||
@@ -1619,143 +1602,6 @@ HostIF_WaitForFreePages(unsigned int timeoutMs) // IN:
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
* HostIFReadUptimeWork --
|
||||
*
|
||||
* Reads the current uptime. The uptime is based on getimeofday,
|
||||
* which provides the needed high resolution. However, we don't
|
||||
* want uptime to be warped by e.g. calls to settimeofday. So, we
|
||||
* use a jiffies based monotonic clock to sanity check the uptime.
|
||||
* If the uptime is more than one second from the monotonic time,
|
||||
* we assume that the time of day has been set, and recalculate the
|
||||
* uptime base to get uptime back on track with monotonic time. On
|
||||
* the other hand, we do expect jiffies based monotonic time and
|
||||
* timeofday to have small drift (due to NTP rate correction, etc).
|
||||
* We handle this by rebasing the jiffies based monotonic clock
|
||||
* every second (see HostIFUptimeResyncMono).
|
||||
*
|
||||
* Results:
|
||||
* The uptime, in units of UPTIME_FREQ. Also returns the jiffies
|
||||
* value that was used in the monotonic time calculation.
|
||||
*
|
||||
* Side effects:
|
||||
* May reset the uptime base in the case gettimeofday warp was
|
||||
* detected.
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static uint64
|
||||
HostIFReadUptimeWork(unsigned long *j) // OUT: current jiffies
|
||||
{
|
||||
struct timeval tv;
|
||||
uint64 monotime, uptime, upBase, monoBase;
|
||||
int64 diff;
|
||||
uint32 version;
|
||||
unsigned long jifs, jifBase;
|
||||
unsigned int attempts = 0;
|
||||
|
||||
retry:
|
||||
do {
|
||||
version = VersionedAtomic_BeginTryRead(&uptimeState.version);
|
||||
jifs = jiffies;
|
||||
jifBase = uptimeState.jiffiesBase;
|
||||
monoBase = uptimeState.monotimeBase;
|
||||
} while (!VersionedAtomic_EndTryRead(&uptimeState.version, version));
|
||||
|
||||
do_gettimeofday(&tv);
|
||||
upBase = Atomic_Read64(&uptimeState.uptimeBase);
|
||||
|
||||
monotime = (uint64)(jifs - jifBase) * (UPTIME_FREQ / HZ);
|
||||
monotime += monoBase;
|
||||
|
||||
uptime = tv.tv_usec * (UPTIME_FREQ / 1000000) + tv.tv_sec * UPTIME_FREQ;
|
||||
uptime += upBase;
|
||||
|
||||
/*
|
||||
* Use the jiffies based monotonic time to sanity check gettimeofday.
|
||||
* If they differ by more than one second, assume the time of day has
|
||||
* been warped, and use the jiffies time to undo (most of) the warp.
|
||||
*/
|
||||
|
||||
diff = uptime - monotime;
|
||||
if (UNLIKELY(diff < -UPTIME_FREQ || diff > UPTIME_FREQ)) {
|
||||
/* Compute a new uptimeBase to get uptime back on track. */
|
||||
uint64 newUpBase = monotime - (uptime - upBase);
|
||||
|
||||
attempts++;
|
||||
if (!Atomic_CMPXCHG64(&uptimeState.uptimeBase, upBase, newUpBase) &&
|
||||
attempts < 5) {
|
||||
/* Another thread updated uptimeBase. Recalculate uptime. */
|
||||
goto retry;
|
||||
}
|
||||
uptime = monotime;
|
||||
|
||||
Log("%s: detected settimeofday: fixed uptimeBase old %"FMT64"u "
|
||||
"new %"FMT64"u attempts %u\n", __func__,
|
||||
upBase, newUpBase, attempts);
|
||||
}
|
||||
*j = jifs;
|
||||
|
||||
return uptime;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
* HostIFUptimeResyncMono --
|
||||
*
|
||||
* Timer that fires ever second to resynchronize the jiffies based
|
||||
* monotonic time with the uptime.
|
||||
*
|
||||
* Results:
|
||||
* None
|
||||
*
|
||||
* Side effects:
|
||||
* Resets the monotonic time bases so that jiffies based monotonic
|
||||
* time does not drift from gettimeofday over the long term.
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void
|
||||
HostIFUptimeResyncMono(struct timer_list *timer) // IN: ignored
|
||||
{
|
||||
unsigned long jifs;
|
||||
uintptr_t flags;
|
||||
|
||||
/*
|
||||
* Read the uptime and the corresponding jiffies value. This will
|
||||
* also correct the uptime (which is based on time of day) if needed
|
||||
* before we rebase monotonic time (which is based on jiffies).
|
||||
*/
|
||||
|
||||
uint64 uptime = HostIFReadUptimeWork(&jifs);
|
||||
|
||||
/*
|
||||
* Every second, recalculate monoBase and jiffiesBase to squash small
|
||||
* drift between gettimeofday and jiffies. Also, this prevents
|
||||
* (jiffies - jiffiesBase) wrap on 32-bits.
|
||||
*/
|
||||
|
||||
SAVE_FLAGS(flags);
|
||||
CLEAR_INTERRUPTS();
|
||||
VersionedAtomic_BeginWrite(&uptimeState.version);
|
||||
|
||||
uptimeState.monotimeBase = uptime;
|
||||
uptimeState.jiffiesBase = jifs;
|
||||
|
||||
VersionedAtomic_EndWrite(&uptimeState.version);
|
||||
RESTORE_FLAGS(flags);
|
||||
|
||||
/* Reschedule this timer to expire in one second. */
|
||||
mod_timer(&uptimeState.timer, jifs + HZ);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
@@ -1767,8 +1613,7 @@ HostIFUptimeResyncMono(struct timer_list *timer) // IN: ignored
|
||||
* None
|
||||
*
|
||||
* Side effects:
|
||||
* Sets the initial values for the uptime state, and schedules
|
||||
* the uptime timer.
|
||||
* Sets the initial value for the uptime base.
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1776,22 +1621,7 @@ HostIFUptimeResyncMono(struct timer_list *timer) // IN: ignored
|
||||
void
|
||||
HostIF_InitUptime(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
uptimeState.jiffiesBase = jiffies;
|
||||
do_gettimeofday(&tv);
|
||||
Atomic_Write64(&uptimeState.uptimeBase,
|
||||
-(tv.tv_usec * (UPTIME_FREQ / 1000000) +
|
||||
tv.tv_sec * UPTIME_FREQ));
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0) && !defined(timer_setup)
|
||||
init_timer(&uptimeState.timer);
|
||||
uptimeState.timer.function = (void *)HostIFUptimeResyncMono;
|
||||
uptimeState.timer.data = (unsigned long)&uptimeState.timer;
|
||||
#else
|
||||
timer_setup(&uptimeState.timer, HostIFUptimeResyncMono, 0);
|
||||
#endif
|
||||
mod_timer(&uptimeState.timer, jiffies + HZ);
|
||||
uptime_base = ktime_get_ns();
|
||||
}
|
||||
|
||||
|
||||
@@ -1800,13 +1630,13 @@ HostIF_InitUptime(void)
|
||||
*
|
||||
* HostIF_CleanupUptime --
|
||||
*
|
||||
* Cleanup uptime state, called at module unloading time.
|
||||
* No-op, left for backward compatibility.
|
||||
*
|
||||
* Results:
|
||||
* None
|
||||
*
|
||||
* Side effects:
|
||||
* Deschedule the uptime timer.
|
||||
* None
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1814,7 +1644,6 @@ HostIF_InitUptime(void)
|
||||
void
|
||||
HostIF_CleanupUptime(void)
|
||||
{
|
||||
del_timer_sync(&uptimeState.timer);
|
||||
}
|
||||
|
||||
|
||||
@@ -1838,9 +1667,10 @@ HostIF_CleanupUptime(void)
|
||||
uint64
|
||||
HostIF_ReadUptime(void)
|
||||
{
|
||||
unsigned long jifs;
|
||||
u64 tm;
|
||||
|
||||
return HostIFReadUptimeWork(&jifs);
|
||||
tm = ktime_get_ns();
|
||||
return (tm - uptime_base) / (NSEC_PER_SEC / UPTIME_FREQ);
|
||||
}
|
||||
|
||||
|
||||
@@ -2217,7 +2047,7 @@ SetVMAPICAddr(VMDriver *vm, // IN/OUT: driver state
|
||||
volatile void *hostapic;
|
||||
|
||||
ASSERT_ON_COMPILE(APICR_SIZE <= PAGE_SIZE);
|
||||
hostapic = (volatile void *) ioremap_nocache(ma, PAGE_SIZE);
|
||||
hostapic = (volatile void *) ioremap(ma, PAGE_SIZE);
|
||||
if (hostapic) {
|
||||
if ((APIC_VERSIONREG(hostapic) & 0xF0) == 0x10) {
|
||||
vm->hostAPIC.base = (volatile uint32 (*)[4]) hostapic;
|
||||
|
||||
+6
-7
@@ -66,7 +66,7 @@
|
||||
#endif
|
||||
|
||||
#if LOGLEVEL >= 4
|
||||
static struct timeval vnetTime;
|
||||
static u64 vnetTime;
|
||||
#endif
|
||||
|
||||
typedef struct VNetBridge VNetBridge;
|
||||
@@ -693,7 +693,7 @@ VNetBridgeReceiveFromVNet(VNetJack *this, // IN: jack
|
||||
|
||||
netif_rx_ni(clone);
|
||||
# if LOGLEVEL >= 4
|
||||
do_gettimeofday(&vnetTime);
|
||||
vnetTime = ktime_get_ns();
|
||||
# endif
|
||||
}
|
||||
}
|
||||
@@ -1490,12 +1490,11 @@ VNetBridgeReceiveFromDev(struct sk_buff *skb, // IN: packet to receive
|
||||
|
||||
# if LOGLEVEL >= 4
|
||||
{
|
||||
struct timeval now;
|
||||
do_gettimeofday(&now);
|
||||
u64 now;
|
||||
|
||||
now = ktime_get_ns();
|
||||
LOG(3, (KERN_DEBUG "bridge-%s: time %d\n",
|
||||
bridge->name,
|
||||
(int)((now.tv_sec * 1000000 + now.tv_usec)
|
||||
- (vnetTime.tv_sec * 1000000 + vnetTime.tv_usec))));
|
||||
bridge->name, (int)((now - vnetTime) / NSEC_PER_USEC)));
|
||||
}
|
||||
# endif
|
||||
|
||||
|
||||
@@ -161,6 +161,14 @@ VNetProcOpen(struct inode *inode, // IN:
|
||||
}
|
||||
|
||||
/* Our procfs callbacks. We only need to specialize open. */
|
||||
#ifdef DEFINE_PROC_SHOW_ATTRIBUTE
|
||||
static const struct proc_ops fops = {
|
||||
.proc_open = VNetProcOpen,
|
||||
.proc_read = seq_read,
|
||||
.proc_lseek = seq_lseek,
|
||||
.proc_release = single_release,
|
||||
};
|
||||
#else
|
||||
static struct file_operations fops = {
|
||||
.open = VNetProcOpen,
|
||||
.read = seq_read,
|
||||
@@ -168,6 +176,7 @@ static struct file_operations fops = {
|
||||
.release = single_release,
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Reference in new issue
Block a user