Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: host.c
- ===================================================================
- --- host.c (revision 12089)
- +++ host.c (working copy)
- @@ -671,6 +671,7 @@
- double time3 = 0;
- double cl_timer = 0, sv_timer = 0;
- double clframetime, deltacleantime, olddirtytime, dirtytime;
- + double checkconsole = 0;
- double wait;
- int pass1, pass2, pass3, i;
- char vabuf[1024];
- @@ -768,7 +769,10 @@
- Curl_Run();
- // check for commands typed to the host
- - Host_GetConsoleCommands();
- + if (realtime > checkconsole) {
- + Host_GetConsoleCommands();
- + checkconsole = realtime + 1;
- + }
- // when a server is running we only execute console commands on server frames
- // (this mainly allows frikbot .way config files to work properly by staying in sync with the server qc)
- Index: sys_shared.c
- ===================================================================
- --- sys_shared.c (revision 12089)
- +++ sys_shared.c (working copy)
- @@ -13,6 +13,9 @@
- # include <windows.h>
- # include <mmsystem.h> // timeGetTime
- # include <time.h> // localtime
- +#ifdef __GNUC__
- +# include <x86intrin.h> // __rdtsc
- +#endif
- #ifdef _MSC_VER
- #pragma comment(lib, "winmm.lib")
- #endif
- @@ -235,12 +238,15 @@
- #ifdef WIN32
- # define HAVE_TIMEGETTIME 1
- # define HAVE_QUERYPERFORMANCECOUNTER 1
- +# define HAVE_RDTSC 1
- # define HAVE_Sleep 1
- #endif
- +#ifndef WIN32
- #if defined(CLOCK_MONOTONIC) || defined(CLOCK_HIRES)
- # define HAVE_CLOCKGETTIME 1
- #endif
- +#endif
- #ifndef WIN32
- // FIXME improve this check, manpage hints to DST_NONE
- @@ -270,6 +276,9 @@
- #if HAVE_QUERYPERFORMANCECOUNTER
- static cvar_t sys_usequeryperformancecounter = {CVAR_SAVE, "sys_usequeryperformancecounter", "0", "use windows QueryPerformanceCounter timer (which has issues on multicore/multiprocessor machines and processors which are designed to conserve power) for timing rather than timeGetTime function (which has issues on some motherboards)"};
- #endif
- +#if HAVE_RDTSC
- +static cvar_t sys_usetimestampcounter = {CVAR_SAVE, "sys_usetimestampcounter", "0", "use RDTSC processor instruction (which has issues on multicore/multiprocessor machines and processors which are designed to conserve power) for timing rather than timeGetTime function (which has issues on some motherboards)"};
- +#endif
- #if HAVE_CLOCKGETTIME
- static cvar_t sys_useclockgettime = {CVAR_SAVE, "sys_useclockgettime", "1", "use POSIX clock_gettime function (not adjusted by NTP on some older Linux kernels) for timing rather than gettimeofday (which has issues if the system time is stepped by ntpdate, or apparently on some Xen installations)"};
- #endif
- @@ -290,6 +299,9 @@
- #if HAVE_QUERYPERFORMANCECOUNTER
- Cvar_RegisterVariable(&sys_usequeryperformancecounter);
- #endif
- +#if HAVE_RDTSC
- + Cvar_RegisterVariable(&sys_usetimestampcounter);
- +#endif
- #if HAVE_CLOCKGETTIME
- Cvar_RegisterVariable(&sys_useclockgettime);
- #endif
- @@ -344,6 +356,38 @@
- }
- }
- #endif
- +#if HAVE_RDTSC
- + if (sys_usetimestampcounter.integer)
- + {
- + static double timescale;
- +
- + if (!timescale)
- + {
- + LONG success;
- + HKEY hKey;
- + DWORD regType = REG_DWORD;
- + DWORD regSize = sizeof(DWORD);
- + DWORD MHz;
- + success = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey);
- + if (success == ERROR_SUCCESS)
- + {
- + success = RegQueryValueEx(hKey, "~MHz", NULL, ®Type, (LPBYTE)&MHz, ®Size);
- + if (success == ERROR_SUCCESS && MHz) timescale = 1.0 / ( 1000000.0 * MHz );
- + RegCloseKey(hKey);
- + }
- + }
- + if (timescale)
- + {
- + return timescale * __rdtsc();
- + }
- + else
- + {
- + Con_Printf("No time stamp counter frequency available\n");
- + // fall back to other clock sources
- + Cvar_SetValueQuick(&sys_usetimestampcounter, false);
- + }
- + }
- +#endif
- #if HAVE_CLOCKGETTIME
- if (sys_useclockgettime.integer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement