View difference between Paste ID: mriWBiMX and Zz1psruL
SHOW: | | - or go back to the newest paste.
1
Index: host.c
2
===================================================================
3
--- host.c	(revision 12089)
4
+++ host.c	(working copy)
5
@@ -671,6 +671,7 @@
6
 	double time3 = 0;
7
 	double cl_timer = 0, sv_timer = 0;
8
 	double clframetime, deltacleantime, olddirtytime, dirtytime;
9
+	double checkconsole = 0;
10
 	double wait;
11
 	int pass1, pass2, pass3, i;
12
 	char vabuf[1024];
13
@@ -768,7 +769,10 @@
14
 		Curl_Run();
15
 
16
 		// check for commands typed to the host
17
-		Host_GetConsoleCommands();
18
+		if (realtime > checkconsole) {
19
+			Host_GetConsoleCommands();
20
+			checkconsole = realtime + 1;
21
+		}
22
 
23
 		// when a server is running we only execute console commands on server frames
24
 		// (this mainly allows frikbot .way config files to work properly by staying in sync with the server qc)
25
Index: sys_shared.c
26
===================================================================
27
--- sys_shared.c	(revision 12089)
28
+++ sys_shared.c	(working copy)
29
@@ -13,6 +13,9 @@
30
 # include <windows.h>
31
 # include <mmsystem.h> // timeGetTime
32
 # include <time.h> // localtime
33
+#ifdef __GNUC__
34
+# include <x86intrin.h> // __rdtsc
35
+#endif
36
 #ifdef _MSC_VER
37
 #pragma comment(lib, "winmm.lib")
38
 #endif
39
@@ -235,12 +238,15 @@
40
 #ifdef WIN32
41
 # define HAVE_TIMEGETTIME 1
42
 # define HAVE_QUERYPERFORMANCECOUNTER 1
43
+# define HAVE_RDTSC 1
44
 # define HAVE_Sleep 1
45
 #endif
46
 
47
+#ifndef WIN32
48
 #if defined(CLOCK_MONOTONIC) || defined(CLOCK_HIRES)
49
 # define HAVE_CLOCKGETTIME 1
50
 #endif
51
+#endif
52
 
53
 #ifndef WIN32
54
 // FIXME improve this check, manpage hints to DST_NONE
55
@@ -270,6 +276,9 @@
56
 #if HAVE_QUERYPERFORMANCECOUNTER
57
 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)"};
58
 #endif
59
+#if HAVE_RDTSC
60
+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)"};
61
+#endif
62
 #if HAVE_CLOCKGETTIME
63
 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)"};
64
 #endif
65
@@ -290,6 +299,9 @@
66
 #if HAVE_QUERYPERFORMANCECOUNTER
67
 	Cvar_RegisterVariable(&sys_usequeryperformancecounter);
68
 #endif
69
+#if HAVE_RDTSC
70
+	Cvar_RegisterVariable(&sys_usetimestampcounter);
71
+#endif
72
 #if HAVE_CLOCKGETTIME
73
 	Cvar_RegisterVariable(&sys_useclockgettime);
74
 #endif
75-
@@ -344,6 +356,34 @@
75+
@@ -344,6 +356,38 @@
76
 		}
77
 	}
78
 #endif
79
+#if HAVE_RDTSC
80
+	if (sys_usetimestampcounter.integer)
81
+	{
82
+		static double timescale;
83
+		
84
+		if (!timescale)
85
+		{
86
+			LONG success;
87
+			HKEY hKey;
88
+			DWORD regType = REG_DWORD;
89
+			DWORD regSize = sizeof(DWORD);
90
+			DWORD MHz;
91
+			success = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey);
92-
+			if (success == ERROR_SUCCESS) success = RegQueryValueEx(hKey, "~MHz", NULL, &regType, (LPBYTE)&MHz, &regSize);
92+
+			if (success == ERROR_SUCCESS)
93-
+			if (success == ERROR_SUCCESS && MHz) timescale = 1.0 / ( 1000000.0 * MHz );
93+
+			{
94
+				success = RegQueryValueEx(hKey, "~MHz", NULL, &regType, (LPBYTE)&MHz, &regSize);
95
+				if (success == ERROR_SUCCESS && MHz) timescale = 1.0 / ( 1000000.0 * MHz );
96
+				RegCloseKey(hKey);
97
+			}
98
+		}
99
+		if (timescale)
100
+		{
101
+			return timescale * __rdtsc();
102
+		}
103
+		else
104
+		{
105
+			Con_Printf("No time stamp counter frequency available\n");
106
+			// fall back to other clock sources
107
+			Cvar_SetValueQuick(&sys_usetimestampcounter, false);
108
+		}
109
+	}
110
+#endif
111
 
112
 #if HAVE_CLOCKGETTIME
113
 	if (sys_useclockgettime.integer)