Page 2 of 3
Re: Replace QPC to RDTSC Timer in games
Posted: 15 Aug 2021, 14:25
by Kaldaien
I'm not convinced this is a good idea
The reason we moved away from using RDTSC for timing is because 1) CPUs have dynamic frequency scaling and 2) each CPU core has a different RDTSC timestamp.
QPC is monotonic and the frequency is constant no matter what CPU core any timing code happens to be running on.
Re: Replace QPC to RDTSC Timer in games
Posted: 26 Dec 2021, 11:47
by pox02
i would like to update code so u guys get more game feeling by using the function QueryThreadCycleTime enjoy
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);
}
Re: Replace QPC to RDTSC Timer in games
Posted: 26 Dec 2021, 18:47
by Bobo
what exactly is this and how do you use it ?
Re: Replace QPC to RDTSC Timer in games
Posted: 27 Dec 2021, 12:12
by Aspector
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
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);
}
And how do we use it or compile it?
Re: Replace QPC to RDTSC Timer in games
Posted: 27 Dec 2021, 13:29
by AndreyRGW
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
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);
}
I compiled RDTSC with your code, but I didn't notice any changes compared to the original.
Re: Replace QPC to RDTSC Timer in games
Posted: 27 Dec 2021, 14:48
by pox02
AndreyRGW wrote: ↑27 Dec 2021, 13:29
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
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);
}
I compiled RDTSC with your code, but I didn't notice any changes compared to the original.
Try add SetProcessAffinityMask in first core see if any improvement
Code: Select all
SetProcessAffinityMask(GetCurrentProcess(), 1);
test fix overhead of QueryPerformanceCounter didnt try for long time so give any updates of it
Code: Select all
LARGE_INTEGER fq, st, ed;
QueryPerformanceFrequency(&fq);
QueryPerformanceCounter(&st);
LONGLONG begin = GetCycleCount();
Sleep(sleepTime);
QueryPerformanceCounter(&ed);
1000000 * (ed.QuadPart - st.QuadPart), fq;
LONGLONG end = GetCycleCount();
return (end - begin) * fq.QuadPart / (ed.QuadPart - st.QuadPart);
Re: Replace QPC to RDTSC Timer in games
Posted: 28 Dec 2021, 08:54
by AndreyRGW
pox02 wrote: ↑27 Dec 2021, 14:48
AndreyRGW wrote: ↑27 Dec 2021, 13:29
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
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);
}
I compiled RDTSC with your code, but I didn't notice any changes compared to the original.
Try add SetProcessAffinityMask in first core see if any improvement
Code: Select all
SetProcessAffinityMask(GetCurrentProcess(), 1);
test fix overhead of QueryPerformanceCounter didnt try for long time so give any updates of it
Code: Select all
LARGE_INTEGER fq, st, ed;
QueryPerformanceFrequency(&fq);
QueryPerformanceCounter(&st);
LONGLONG begin = GetCycleCount();
Sleep(sleepTime);
QueryPerformanceCounter(&ed);
1000000 * (ed.QuadPart - st.QuadPart), fq;
LONGLONG end = GetCycleCount();
return (end - begin) * fq.QuadPart / (ed.QuadPart - st.QuadPart);
I think it only got worse after that.
Re: Replace QPC to RDTSC Timer in games
Posted: 31 Dec 2021, 23:53
by pox02
AndreyRGW wrote: ↑28 Dec 2021, 08:54
pox02 wrote: ↑27 Dec 2021, 14:48
AndreyRGW wrote: ↑27 Dec 2021, 13:29
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
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);
}
I compiled RDTSC with your code, but I didn't notice any changes compared to the original.
Try add SetProcessAffinityMask in first core see if any improvement
Code: Select all
SetProcessAffinityMask(GetCurrentProcess(), 1);
test fix overhead of QueryPerformanceCounter didnt try for long time so give any updates of it
Code: Select all
LARGE_INTEGER fq, st, ed;
QueryPerformanceFrequency(&fq);
QueryPerformanceCounter(&st);
LONGLONG begin = GetCycleCount();
Sleep(sleepTime);
QueryPerformanceCounter(&ed);
1000000 * (ed.QuadPart - st.QuadPart), fq;
LONGLONG end = GetCycleCount();
return (end - begin) * fq.QuadPart / (ed.QuadPart - st.QuadPart);
I think it only got worse after that.
i see one last attempt
Code: Select all
LONGLONG GetFrequency(DWORD sleepTime)
{
LARGE_INTEGER fq, st, ed;
SetPriorityClass(GetCurrentThread(), REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
SetProcessPriorityBoost(GetCurrentThread(), 0);
SetThreadAffinityMask(GetCurrentThread(), 0x1);
SetProcessAffinityMask(GetCurrentProcess(), 0x0);
QueryPerformanceFrequency(&fq);
QueryPerformanceCounter(&st);
LONGLONG begin = GetCycleCount();
Sleep(sleepTime);
QueryPerformanceCounter(&ed);
LONGLONG end = GetCycleCount();
return (end - begin) * fq.QuadPart / (ed.QuadPart - st.QuadPart);
}
Re: Replace QPC to RDTSC Timer in games
Posted: 01 Jan 2022, 15:49
by AndreyRGW
pox02 wrote: ↑31 Dec 2021, 23:53
AndreyRGW wrote: ↑28 Dec 2021, 08:54
pox02 wrote: ↑27 Dec 2021, 14:48
AndreyRGW wrote: ↑27 Dec 2021, 13:29
I compiled RDTSC with your code, but I didn't notice any changes compared to the original.
Try add SetProcessAffinityMask in first core see if any improvement
Code: Select all
SetProcessAffinityMask(GetCurrentProcess(), 1);
test fix overhead of QueryPerformanceCounter didnt try for long time so give any updates of it
Code: Select all
LARGE_INTEGER fq, st, ed;
QueryPerformanceFrequency(&fq);
QueryPerformanceCounter(&st);
LONGLONG begin = GetCycleCount();
Sleep(sleepTime);
QueryPerformanceCounter(&ed);
1000000 * (ed.QuadPart - st.QuadPart), fq;
LONGLONG end = GetCycleCount();
return (end - begin) * fq.QuadPart / (ed.QuadPart - st.QuadPart);
I think it only got worse after that.
i see one last attempt
Code: Select all
LONGLONG GetFrequency(DWORD sleepTime)
{
LARGE_INTEGER fq, st, ed;
SetPriorityClass(GetCurrentThread(), REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
SetProcessPriorityBoost(GetCurrentThread(), 0);
SetThreadAffinityMask(GetCurrentThread(), 0x1);
SetProcessAffinityMask(GetCurrentProcess(), 0x0);
QueryPerformanceFrequency(&fq);
QueryPerformanceCounter(&st);
LONGLONG begin = GetCycleCount();
Sleep(sleepTime);
QueryPerformanceCounter(&ed);
LONGLONG end = GetCycleCount();
return (end - begin) * fq.QuadPart / (ed.QuadPart - st.QuadPart);
}
This version seems to work fine. Happy new year, by the way.
Re: Replace QPC to RDTSC Timer in games
Posted: 02 Jan 2022, 00:54
by pox02
wrong