/** ************************************************************************* ** ** Copyright (C) 2008 Heinz van Saanen ** ** This file is part of the function viewer Zhu3D. ** ** This file may be used under the terms of the GNU General Public ** License version 3 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ****************************************************************************/ #ifndef _CPUINFO_H_ #define _CPUINFO_H_ /** Timer stuff */ #include "timers.h" #include "tsc.h" /** Include stuff for misc OS's */ #if defined(Q_WS_MAC) #include #include #include #elif defined(Q_WS_WIN) #include #elif (defined(Q_OS_LINUX) || defined(sgi)) #include #endif /** Counting cores, checking frequency and endianess */ class CPUINFO { public: CPUINFO() {} ~CPUINFO() {} /** Returns core-number on success, 0 otherwise */ static int cores() { int tmp=0; /** Apple Mac OS */ #if defined(Q_WS_MAC) int mib[2]={ CTL_HW, HW_NCPUINFO }; int cpus; size_t size=sizeof(cpus); if(0==sysctl(mib, 2, &cpus, &size, NULL, 0)) tmp=cpus; /** Microsoft Windows */ #elif defined(Q_WS_WIN) SYSTEM_INFO si; GetSystemInfo(&si); tmp=si.dwNumberOfProcessors; /** Linux/Unix */ #elif defined(Q_OS_LINUX) #if defined(_SC_NPROCESSORS_ONLN) tmp=sysconf(_SC_NPROCESSORS_ONLN); #endif /** SGI/Irix */ #elif defined(sgi) #if defined(_SC_NPROC_ONLN) tmp=sysconf(_SC_NPROC_ONLN); #endif #endif return tmp; } /** Returns frequency in MHz units. Average some 50 ms measurements */ static double MHz() { double tmp=0.0; TIMERS tim; TSC tsc; tsc.start(); tim.uwait(50000); tmp+=tsc.stop(); tsc.start(); tim.uwait(50000); tmp+=tsc.stop(); tsc.start(); tim.uwait(50000); tmp+=tsc.stop(); return (tmp*0.00002)/3.0; } /** Check out endinaness dynamically */ static bool isBigEndian() { unsigned int i=1; unsigned char *pt = (unsigned char *) &i; if(pt[0]) return false; return true; } }; /** _CPUINFO_H_ */ #endif