Improve Windows sleep accuracy from 15ms to 15µs

This commit is contained in:
Justine Tunney 2024-12-06 23:00:07 -08:00
parent b40140e6c5
commit b490e23d63
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
16 changed files with 189 additions and 67 deletions

View file

@ -751,6 +751,7 @@ imp 'NtQuerySecurityObject' NtQuerySecurityObject ntdll 5
imp 'NtQuerySymbolicLinkObject' NtQuerySymbolicLinkObject ntdll 3
imp 'NtQuerySystemInformation' NtQuerySystemInformation ntdll 4
imp 'NtQuerySystemTime' NtQuerySystemTime ntdll 1
imp 'NtQueryTimerResolution' NtQueryTimerResolution ntdll 3
imp 'NtQueryValueKey' NtQueryValueKey ntdll 6
imp 'NtQueryVirtualMemory' NtQueryVirtualMemory ntdll 6
imp 'NtQueryVolumeInformationFile' NtQueryVolumeInformationFile ntdll 5
@ -767,6 +768,7 @@ imp 'NtSetInformationFile' NtSetInformationFile ntdll 5
imp 'NtSetInformationThread' NtSetInformationThread ntdll 4
imp 'NtSetIntervalProfile' NtSetIntervalProfile ntdll 2
imp 'NtSetTimer' NtSetTimer ntdll 7
imp 'NtSetTimerResolution' NtSetTimerResolution ntdll 3
imp 'NtSetValueKey' NtSetValueKey ntdll 6
imp 'NtSignalAndWaitForSingleObject' NtSignalAndWaitForSingleObject ntdll 4
imp 'NtStartProfile' NtStartProfile ntdll 1

View file

@ -224,6 +224,16 @@ NtStatus RtlUnlockHeap(int64_t heap);
NtStatus RtlGetProcessHeaps(uint32_t count, void **out_Heaps);
NtStatus RtlWalkHeap(int64_t heap, void *out_Info);
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § new technology » beyond the pale » i am the time lorde
*/
NtStatus NtSetTimerResolution(uint32_t DesiredResolution, bool32 SetResolution,
uint32_t *out_CurrentResolution);
NtStatus NtQueryTimerResolution(uint32_t *out_MinimumResolution,
uint32_t *out_MaximumResolution,
uint32_t *out_CurrentResolution);
#if ShouldUseMsabiAttribute()
#include "libc/nt/thunk/ntdll.inc"
#endif /* ShouldUseMsabiAttribute() */

View file

@ -0,0 +1,18 @@
#include "libc/nt/ntdllimport.h"
.ntimp NtQueryTimerResolution,NtQueryTimerResolution
.text.windows
.ftrace1
NtQueryTimerResolution:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov __imp_NtQueryTimerResolution(%rip),%rax
jmp __sysv2nt
#elif defined(__aarch64__)
mov x0,#0
ret
#endif
.endfn NtQueryTimerResolution,globl
.previous

View file

@ -0,0 +1,18 @@
#include "libc/nt/ntdllimport.h"
.ntimp NtSetTimerResolution,NtSetTimerResolution
.text.windows
.ftrace1
NtSetTimerResolution:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov __imp_NtSetTimerResolution(%rip),%rax
jmp __sysv2nt
#elif defined(__aarch64__)
mov x0,#0
ret
#endif
.endfn NtSetTimerResolution,globl
.previous