Replace QPC to RDTSC Timer in games

Everything about latency. Tips, testing methods, mouse lag, display lag, game engine lag, network lag, whole input lag chain, VSYNC OFF vs VSYNC ON, and more! Input Lag Articles on Blur Busters.
pox02
Posts: 262
Joined: 28 Sep 2018, 06:04

Re: Replace QPC to RDTSC Timer in games

Post by pox02 » 09 Jan 2022, 09:47

my final fix for rdtsc

To prevent this the programmer must serialize the the instruction queue. This can be done by inserting a serializing instruction like CPUID instruction before the RDTSC instruction

Code: Select all

.code
  GetCycleCount proc
    cpuid
    rdtsc
    ret
  GetCycleCount endp
end
Last edited by pox02 on 10 Jan 2022, 12:36, edited 1 time in total.
monitors xg258q aw2518hf 27GK750F-B pg248q xg240r lg w2363d-pf xb270hu XL2546 XL2546K NXG252R

Ilim
Posts: 7
Joined: 21 Oct 2020, 16:31

Re: Replace QPC to RDTSC Timer in games

Post by Ilim » 10 Jan 2022, 12:01

how to use it, tell me, otherwise I don't understand programming

pox02
Posts: 262
Joined: 28 Sep 2018, 06:04

Re: Replace QPC to RDTSC Timer in games

Post by pox02 » 11 Jan 2022, 10:04

i would like to avoid SetProcessAffinityMask/ SetThreadAffinityMask and change freq more for much more stable rdtsc i suggest use processhacker taskmgr process lasso and disable core 0 there much better

Code: Select all

LONGLONG GetFrequency(DWORD sleepTime)
{
    LARGE_INTEGER fq, st, ed;
    QueryPerformanceFrequency(&fq);
    QueryPerformanceCounter(&st);
    LONGLONG begin = GetCycleCount();
    Sleep(sleepTime);
    QueryPerformanceCounter(&ed);
    LONGLONG usec = (ed.QuadPart % st.QuadPart) * 1000000 / fq.QuadPart;
    LONGLONG end = GetCycleCount();
    return (end - usec - begin) * fq.QuadPart / (ed.QuadPart - st.QuadPart);
}
monitors xg258q aw2518hf 27GK750F-B pg248q xg240r lg w2363d-pf xb270hu XL2546 XL2546K NXG252R

pox02
Posts: 262
Joined: 28 Sep 2018, 06:04

Re: Replace QPC to RDTSC Timer in games

Post by pox02 » 13 Jan 2022, 16:52

My Final update of RDTSC is using RDTSCP which more efficiently now we back to use SetThreadAffinityMask in core 0 since without its can cause drift time and loops in cores reduce the freq to 1 microsecond more efficiently Enjoy the best timer :D

RDTSC + CPUID (in reverse order, here) to flush the pipeline, and incurred up to a 60x overhead (!) on a Virtual Machine (my working environment) due to hypercalls and whatnot. This is both with and without HW Virtualization enabled.

Most recently I've come across the RDTSCP* instruction, which seems to do what RDTSC+CPUID did, but more efficiently as it's a newer instruction - only a 1.5x-2x overhead, relatively.


i update here so u guys can compile it https://github.com/Zcytxcbyz/DLLHighResolutionTimer
monitors xg258q aw2518hf 27GK750F-B pg248q xg240r lg w2363d-pf xb270hu XL2546 XL2546K NXG252R

Plznoinputlag
Posts: 75
Joined: 03 Nov 2021, 11:13

Re: Replace QPC to RDTSC Timer in games

Post by Plznoinputlag » 13 Jan 2022, 17:06

pox02 wrote:
13 Jan 2022, 16:52
My Final update of RDTSC is using RDTSCP which more efficiently now we back to use SetThreadAffinityMask in core 0 since without its can cause drift time and loops in cores reduce the freq to 1 microsecond more efficiently Enjoy the best timer :D

RDTSC + CPUID (in reverse order, here) to flush the pipeline, and incurred up to a 60x overhead (!) on a Virtual Machine (my working environment) due to hypercalls and whatnot. This is both with and without HW Virtualization enabled.

Most recently I've come across the RDTSCP* instruction, which seems to do what RDTSC+CPUID did, but more efficiently as it's a newer instruction - only a 1.5x-2x overhead, relatively.


i update here so u guys can compile it https://github.com/Zcytxcbyz/DLLHighResolutionTimer
but u cant use this in online games useles thing

uzbek
Posts: 1
Joined: 27 Aug 2022, 19:25

Re: Replace QPC to RDTSC Timer in games

Post by uzbek » 27 Aug 2022, 19:28

pox02 wrote:
26 Dec 2021, 11:47
i would like to update code so u guys get more game feeling by using the function QueryThreadCycleTime enjoy :D

Code: Select all

LONGLONG GetFrequency(DWORD sleepTime)
{
    LARGE_INTEGER fq, st, ed;
    QueryPerformanceFrequency(&fq);
    QueryPerformanceCounter(&st);
    QueryThreadCycleTime(GetCurrentThread(), &st);
    LONGLONG begin = GetCycleCount();
    Sleep(sleepTime);
    QueryPerformanceCounter(&ed);
    QueryThreadCycleTime(GetCurrentThread(), &ed);
    LONGLONG end = GetCycleCount();
    return (end - begin) * fq.QuadPart / (ed.QuadPart - st.QuadPart);
}

hi how i can use it?

User avatar
Cyanide_
Posts: 104
Joined: 04 Jul 2022, 14:16

Re: Replace QPC to RDTSC Timer in games

Post by Cyanide_ » 28 Aug 2022, 23:30

Plznoinputlag wrote:
13 Jan 2022, 17:06
but u cant use this in online games useles thing
And he posted it on Overclock electricity issue forum, like some DLL would help vs electricity caused "input lag/delay" lmao

Post Reply