aboutsummaryrefslogtreecommitdiffstats
path: root/wintun.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-08-03 20:43:16 +0000
committerJason A. Donenfeld <Jason@zx2c4.com>2019-08-04 07:06:50 +0000
commit85a8076d08d75cd939136dc01fde4a18aeb78e70 (patch)
treef44603cba636eaf5b5f5210417389886a4f1ae89 /wintun.c
parentGetCurrentProcessToken() is Win8+, so open our own token (diff)
downloadwintun-85a8076d08d75cd939136dc01fde4a18aeb78e70.tar.xz
wintun-85a8076d08d75cd939136dc01fde4a18aeb78e70.zip
Spin less and more efficiently
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'wintun.c')
-rw-r--r--wintun.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/wintun.c b/wintun.c
index 41e1b16..9486457 100644
--- a/wintun.c
+++ b/wintun.c
@@ -402,9 +402,11 @@ _Function_class_(KSTART_ROUTINE)
static VOID
TunProcessReceiveData(_Inout_ TUN_CTX *Ctx)
{
+ KeSetPriorityThread(KeGetCurrentThread(), 1);
+
TUN_RING *Ring = Ctx->Device.Receive.Ring;
ULONG RingCapacity = Ctx->Device.Receive.Capacity;
- const ULONG SpinMax = 10000 * 50 / KeQueryTimeIncrement(); /* 50ms */
+ const ULONG SpinMax = 10000 * 20 / KeQueryTimeIncrement(); /* 20 ms */
VOID *Events[] = { &Ctx->Device.Disconnected, Ctx->Device.Receive.TailMoved };
ASSERT(RTL_NUMBER_OF(Events) <= THREAD_WAIT_OBJECTS);
@@ -431,10 +433,7 @@ TunProcessReceiveData(_Inout_ TUN_CTX *Ctx)
KeQueryTickCount(&SpinNow);
if ((ULONG64)SpinNow.QuadPart - (ULONG64)SpinStart.QuadPart >= SpinMax)
break;
-
- /* This should really call KeYieldProcessorEx(&zero), so it does the Hyper-V paravirtualization call,
- * but it's not exported. */
- YieldProcessor();
+ ZwYieldExecution();
}
if (RingHead == RingTail)
{