00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined SOCPUDEVICE_H
00024 #define SOCPUDEVICE_H
00025
00026 #include <Inventor/devices/SoDevice.h>
00027
00028 #include <Inventor/STL/vector>
00029 #include <Inventor/STL/string>
00030 #include <Inventor/STL/map>
00031
00032 #include <Inventor/threads/SbThreadMutex.h>
00033
00034 #include <Inventor/SbString.h>
00035 #include <Inventor/errors/SoDebugError.h>
00036
00053 class SoCpuDevice : public SoDevice
00054 {
00055 friend class SoDevice;
00056
00057
00058
00059 public:
00060
00066 virtual SbString getDeviceName() const;
00067
00071 enum ProcessorArchitecture
00072 {
00073 X86_64,
00074 X86_32,
00075 IA64,
00076 PPC_32,
00077 PPC_64,
00078 UNKNOWN
00079 };
00080
00082 virtual unsigned long long getTotalMemory() const;
00083
00087 virtual unsigned long long getAvailableMemory() const;
00088
00093 virtual SbString getDriverVersion() const { return SbString("0.0"); };
00094
00096 ProcessorArchitecture getArchitecture() const;
00097
00099 bool isActive() const;
00100
00102 bool hasMMX() const;
00103
00105 bool hasSSE() const;
00106
00108 int getSSELevel() const;
00109
00116 virtual unsigned int getLogicalUnits() const;
00117
00126 unsigned int getCacheSize( int cacheLevel ) const;
00127
00133 static SoCpuDevice* getDevice( int index = 0 );
00134
00138 static unsigned int getDevicesCount();
00139
00141 static SoCpuDevice* findFirstAvailableDevice();
00142
00146 static void initClass();
00147
00151 static void exitClass();
00152
00156 friend std::ostream& operator << ( std::ostream& os, const SoCpuDevice& dev )
00157 {
00158 unsigned long long allocatedMem, freeMem;
00159 dev.getMemoryInfo( allocatedMem, freeMem );
00160
00161 return os << "[CPU name]: " << dev.m_name.toLatin1() << "\n" << \
00162 "[RAM Size]: " << (dev.m_totalMemory)/(1024*1024) << "MB" << "\n" <<
00163 "[Available RAM size]: " << freeMem /(1024*1024) << "MB" << "\n" <<
00164 "[Cores number]: " << dev.m_coresCount << "\n" << \
00165 "[L1 cache size]: " << dev.m_cacheSize[0]/1024 << "KB\n" << \
00166 "[L2 cache size]: " << dev.m_cacheSize[1]/1024 << "KB\n" << \
00167 "[L3 cache size]: " << dev.m_cacheSize[2]/1024 << "KB\n" << \
00168 "[MMX]: " << (dev.m_hasMMX?"available":"not available") << "\n" << \
00169 "[SSE level]: " << dev.m_sseLevel;
00170 }
00171
00172
00173
00174 private:
00175 static unsigned int s_sse_alignement;
00176
00177
00178 virtual unsigned long long getProcessMemory() const;
00179
00180
00181 virtual unsigned long long getPeakProcessMemory() const;
00182
00183 private:
00184
00188 SoCpuDevice();
00189
00193 virtual ~SoCpuDevice();
00194
00196 static bool findFirstDeviceFunc( SoDevice* device );
00197
00199 static bool findDevicesCount( SoDevice* device );
00200
00201
00202
00203 private:
00204 void getMemoryInfo( unsigned long long& allocatedMem, unsigned long long& freeMem ) const;
00205
00206 typedef std::map<std::string, unsigned long long> MemInfoMap;
00207
00209 static void fetchMemInfos( MemInfoMap& memInfo );
00210
00215 static bool getTotalAndFreeMem( unsigned long long& totalMem, unsigned long long& freeMem );
00216
00218 unsigned long long m_totalMemory;
00219
00220
00221 SbString m_name;
00222
00224 ProcessorArchitecture m_architecture;
00225
00227 bool m_isActive;
00228
00230 bool m_hasMMX;
00231
00233 bool m_hasSSE;
00234
00236 int m_sseLevel;
00237
00239 unsigned int m_coresCount;
00240
00242 unsigned int m_cacheSize[3];
00243
00245 static SbThreadMutex s_initThreadMutex;
00246
00248 static unsigned int s_processorsCount;
00249
00251 static int s_initRefCount;
00252 };
00253
00254
00255
00256 inline unsigned long long
00257 SoCpuDevice::getTotalMemory() const
00258 {
00259 return m_totalMemory;
00260 }
00261
00262
00263 inline SoCpuDevice::ProcessorArchitecture
00264 SoCpuDevice::getArchitecture() const
00265 {
00266 return m_architecture;
00267 }
00268
00269
00270
00271 inline bool
00272 SoCpuDevice::isActive() const
00273 {
00274 return m_isActive;
00275 }
00276
00277
00278
00279 inline bool
00280 SoCpuDevice::hasSSE() const
00281 {
00282 return m_hasSSE;
00283 }
00284
00285
00286
00287 inline int
00288 SoCpuDevice::getSSELevel() const
00289 {
00290 return m_sseLevel;
00291 }
00292
00293
00294 inline bool
00295 SoCpuDevice::hasMMX() const
00296 {
00297 return m_hasMMX;
00298 }
00299
00300
00301
00302
00303 #endif // SOCPUDEVICE_H
00304
00305