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