michael@0: /* michael@0: * Copyright 2013, Intel Corporation michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: * michael@0: * Author: Joe Olivas michael@0: */ michael@0: michael@0: #ifndef profiler_IntelPowerGadget_h michael@0: #define profiler_IntelPowerGadget_h michael@0: michael@0: #ifdef _MSC_VER michael@0: typedef __int32 int32_t; michael@0: typedef unsigned __int32 uint32_t; michael@0: typedef __int64 int64_t; michael@0: typedef unsigned __int64 uint64_t; michael@0: #else michael@0: #include michael@0: #endif michael@0: #include "prlink.h" michael@0: michael@0: typedef int (*IPGInitialize) (); michael@0: typedef int (*IPGGetNumNodes) (int *nNodes); michael@0: typedef int (*IPGGetNumMsrs) (int *nMsr); michael@0: typedef int (*IPGGetMsrName) (int iMsr, wchar_t *szName); michael@0: typedef int (*IPGGetMsrFunc) (int iMsr, int *pFuncID); michael@0: typedef int (*IPGReadMSR) (int iNode, unsigned int address, uint64_t *value); michael@0: typedef int (*IPGWriteMSR) (int iNode, unsigned int address, uint64_t value); michael@0: typedef int (*IPGGetIAFrequency) (int iNode, int *freqInMHz); michael@0: typedef int (*IPGGetTDP) (int iNode, double *TDP); michael@0: typedef int (*IPGGetMaxTemperature) (int iNode, int *degreeC); michael@0: typedef int (*IPGGetThresholds) (int iNode, int *degree1C, int *degree2C); michael@0: typedef int (*IPGGetTemperature) (int iNode, int *degreeC); michael@0: typedef int (*IPGReadSample) (); michael@0: typedef int (*IPGGetSysTime) (void *pSysTime); michael@0: typedef int (*IPGGetRDTSC) (uint64_t *pTSC); michael@0: typedef int (*IPGGetTimeInterval) (double *pOffset); michael@0: typedef int (*IPGGetBaseFrequency) (int iNode, double *pBaseFrequency); michael@0: typedef int (*IPGGetPowerData) (int iNode, int iMSR, double *pResult, int *nResult); michael@0: typedef int (*IPGStartLog) (wchar_t *szFileName); michael@0: typedef int (*IPGStopLog) (); michael@0: michael@0: #if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) michael@0: #define PG_LIBRARY_NAME "EnergyLib64" michael@0: #else michael@0: #define PG_LIBRARY_NAME "EnergyLib32" michael@0: #endif michael@0: michael@0: michael@0: class IntelPowerGadget michael@0: { michael@0: public: michael@0: michael@0: IntelPowerGadget(); michael@0: ~IntelPowerGadget(); michael@0: michael@0: // Fails if initialization is incomplete michael@0: bool Init(); michael@0: michael@0: // Returns the number of packages on the system michael@0: int GetNumberNodes(); michael@0: michael@0: // Returns the number of MSRs being tracked michael@0: int GetNumberMsrs(); michael@0: michael@0: // Given a node, returns the temperature michael@0: int GetCPUFrequency(int); michael@0: michael@0: // Returns the TDP of the given node michael@0: double GetTdp(int); michael@0: michael@0: // Returns the maximum temperature for the given node michael@0: int GetMaxTemp(int); michael@0: michael@0: // Returns the current temperature in degrees C michael@0: // of the given node michael@0: int GetTemp(int); michael@0: michael@0: // Takes a sample of data. Must be called before michael@0: // any current data is retrieved. michael@0: int TakeSample(); michael@0: michael@0: // Gets the timestamp of the most recent sample michael@0: uint64_t GetRdtsc(); michael@0: michael@0: // returns number of seconds between the last michael@0: // two samples michael@0: double GetInterval(); michael@0: michael@0: // Returns the base frequency for the given node michael@0: double GetCPUBaseFrequency(int node); michael@0: michael@0: // Returns the combined package power for all michael@0: // packages on the system for the last sample. michael@0: double GetTotalPackagePowerInWatts(); michael@0: double GetPackagePowerInWatts(int node); michael@0: michael@0: // Returns the combined CPU power for all michael@0: // packages on the system for the last sample. michael@0: // If the reading is not available, returns 0.0 michael@0: double GetTotalCPUPowerInWatts(); michael@0: double GetCPUPowerInWatts(int node); michael@0: michael@0: // Returns the combined GPU power for all michael@0: // packages on the system for the last sample. michael@0: // If the reading is not available, returns 0.0 michael@0: double GetTotalGPUPowerInWatts(); michael@0: double GetGPUPowerInWatts(int node); michael@0: michael@0: private: michael@0: michael@0: PRLibrary *libpowergadget; michael@0: IPGInitialize Initialize; michael@0: IPGGetNumNodes GetNumNodes; michael@0: IPGGetNumMsrs GetNumMsrs; michael@0: IPGGetMsrName GetMsrName; michael@0: IPGGetMsrFunc GetMsrFunc; michael@0: IPGReadMSR ReadMSR; michael@0: IPGWriteMSR WriteMSR; michael@0: IPGGetIAFrequency GetIAFrequency; michael@0: IPGGetTDP GetTDP; michael@0: IPGGetMaxTemperature GetMaxTemperature; michael@0: IPGGetThresholds GetThresholds; michael@0: IPGGetTemperature GetTemperature; michael@0: IPGReadSample ReadSample; michael@0: IPGGetSysTime GetSysTime; michael@0: IPGGetRDTSC GetRDTSC; michael@0: IPGGetTimeInterval GetTimeInterval; michael@0: IPGGetBaseFrequency GetBaseFrequency; michael@0: IPGGetPowerData GetPowerData; michael@0: IPGStartLog StartLog; michael@0: IPGStopLog StopLog; michael@0: michael@0: int packageMSR; michael@0: int cpuMSR; michael@0: int freqMSR; michael@0: int tempMSR; michael@0: }; michael@0: michael@0: #endif // profiler_IntelPowerGadget_h