/[pcsx2_0.9.7]/trunk/common/src/x86emitter/WinCpuDetect.cpp
ViewVC logotype

Contents of /trunk/common/src/x86emitter/WinCpuDetect.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 6 months ago) by william
File size: 3295 byte(s)
re-commit (had local access denied errors when committing)
1 /* Cpudetection lib
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16
17 #include "PrecompiledHeader.h"
18 #include "cpudetect_internal.h"
19
20 void x86capabilities::CountLogicalCores()
21 {
22 DWORD vProcessCPUs;
23 DWORD vSystemCPUs;
24
25 LogicalCores = 1;
26
27 if( !GetProcessAffinityMask (GetCurrentProcess (),
28 &vProcessCPUs, &vSystemCPUs) ) return;
29
30 uint CPUs = 0;
31 DWORD bit;
32
33 for (bit = 1; bit != 0; bit <<= 1)
34 {
35 if (vSystemCPUs & bit)
36 CPUs++;
37 }
38
39 LogicalCores = CPUs;
40 }
41
42 bool _test_instruction( void* pfnCall )
43 {
44 __try {
45 u128 regsave;
46 ((void (__fastcall *)(void*))pfnCall)( &regsave );
47 }
48 __except(EXCEPTION_EXECUTE_HANDLER) { return false; }
49
50 return true;
51 }
52
53 bool CanEmitShit()
54 {
55 // Under Windows, pre 0.9.6 versions of PCSX2 may not initialize the TLS
56 // register (FS register), so plugins (DLLs) using our x86emitter in multithreaded
57 // mode will just crash/fail if it tries to do the instruction set tests.
58
59 #if x86EMIT_MULTITHREADED
60 static __threadlocal int tls_failcheck;
61 __try { tls_failcheck = 1; }
62 __except(EXCEPTION_EXECUTE_HANDLER) { return false; }
63 #endif
64
65 return true;
66 }
67
68 bool CanTestInstructionSets()
69 {
70 return CanEmitShit();
71 }
72
73 SingleCoreAffinity::SingleCoreAffinity()
74 {
75 s_threadId = NULL;
76 s_oldmask = ERROR_INVALID_PARAMETER;
77
78 DWORD_PTR availProcCpus, availSysCpus;
79 if( !GetProcessAffinityMask( GetCurrentProcess(), &availProcCpus, &availSysCpus ) ) return;
80
81 int i;
82 for( i=0; i<32; ++i )
83 {
84 if( availProcCpus & (1<<i) ) break;
85 }
86
87 s_threadId = GetCurrentThread();
88 s_oldmask = SetThreadAffinityMask( s_threadId, (1UL<<i) );
89
90 if( s_oldmask == ERROR_INVALID_PARAMETER )
91 {
92 Console.Warning(
93 "CpuDetect: SetThreadAffinityMask failed...\n"
94 "\tSystem Affinity : 0x%08x"
95 "\tProcess Affinity: 0x%08x"
96 "\tAttempted Thread Affinity CPU: i",
97 availProcCpus, availSysCpus, i
98 );
99 }
100
101 Sleep( 2 );
102
103 // Sleep Explained: I arbitrarily pick Core 0 to lock to for running the CPU test. This
104 // means that the current thread will need to be switched to Core 0 if it's currently
105 // scheduled on a difference cpu/core. However, Windows does not necessarily perform
106 // that scheduling immediately upon the call to SetThreadAffinityMask (seems dependent
107 // on version: XP does, Win7 does not). So by issuing a Sleep here we give Win7 time
108 // to issue a timeslice and move our thread to Core 0. Without this, it tends to move
109 // the thread during the cpuSpeed test instead, causing totally wacky results.
110 };
111
112 SingleCoreAffinity::~SingleCoreAffinity() throw()
113 {
114 if( s_oldmask != ERROR_INVALID_PARAMETER )
115 SetThreadAffinityMask( s_threadId, s_oldmask );
116 }
117
118 void SetSingleAffinity()
119 {
120
121 }
122
123 void RestoreAffinity()
124 {
125 }

  ViewVC Help
Powered by ViewVC 1.1.22