1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/profiler/IntelPowerGadget.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,150 @@ 1.4 +/* 1.5 + * Copyright 2013, Intel Corporation 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + * 1.19 + * Author: Joe Olivas <joseph.k.olivas@intel.com> 1.20 + */ 1.21 + 1.22 +#ifndef profiler_IntelPowerGadget_h 1.23 +#define profiler_IntelPowerGadget_h 1.24 + 1.25 +#ifdef _MSC_VER 1.26 +typedef __int32 int32_t; 1.27 +typedef unsigned __int32 uint32_t; 1.28 +typedef __int64 int64_t; 1.29 +typedef unsigned __int64 uint64_t; 1.30 +#else 1.31 +#include <stdint.h> 1.32 +#endif 1.33 +#include "prlink.h" 1.34 + 1.35 +typedef int (*IPGInitialize) (); 1.36 +typedef int (*IPGGetNumNodes) (int *nNodes); 1.37 +typedef int (*IPGGetNumMsrs) (int *nMsr); 1.38 +typedef int (*IPGGetMsrName) (int iMsr, wchar_t *szName); 1.39 +typedef int (*IPGGetMsrFunc) (int iMsr, int *pFuncID); 1.40 +typedef int (*IPGReadMSR) (int iNode, unsigned int address, uint64_t *value); 1.41 +typedef int (*IPGWriteMSR) (int iNode, unsigned int address, uint64_t value); 1.42 +typedef int (*IPGGetIAFrequency) (int iNode, int *freqInMHz); 1.43 +typedef int (*IPGGetTDP) (int iNode, double *TDP); 1.44 +typedef int (*IPGGetMaxTemperature) (int iNode, int *degreeC); 1.45 +typedef int (*IPGGetThresholds) (int iNode, int *degree1C, int *degree2C); 1.46 +typedef int (*IPGGetTemperature) (int iNode, int *degreeC); 1.47 +typedef int (*IPGReadSample) (); 1.48 +typedef int (*IPGGetSysTime) (void *pSysTime); 1.49 +typedef int (*IPGGetRDTSC) (uint64_t *pTSC); 1.50 +typedef int (*IPGGetTimeInterval) (double *pOffset); 1.51 +typedef int (*IPGGetBaseFrequency) (int iNode, double *pBaseFrequency); 1.52 +typedef int (*IPGGetPowerData) (int iNode, int iMSR, double *pResult, int *nResult); 1.53 +typedef int (*IPGStartLog) (wchar_t *szFileName); 1.54 +typedef int (*IPGStopLog) (); 1.55 + 1.56 +#if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) 1.57 +#define PG_LIBRARY_NAME "EnergyLib64" 1.58 +#else 1.59 +#define PG_LIBRARY_NAME "EnergyLib32" 1.60 +#endif 1.61 + 1.62 + 1.63 +class IntelPowerGadget 1.64 +{ 1.65 +public: 1.66 + 1.67 + IntelPowerGadget(); 1.68 + ~IntelPowerGadget(); 1.69 + 1.70 + // Fails if initialization is incomplete 1.71 + bool Init(); 1.72 + 1.73 + // Returns the number of packages on the system 1.74 + int GetNumberNodes(); 1.75 + 1.76 + // Returns the number of MSRs being tracked 1.77 + int GetNumberMsrs(); 1.78 + 1.79 + // Given a node, returns the temperature 1.80 + int GetCPUFrequency(int); 1.81 + 1.82 + // Returns the TDP of the given node 1.83 + double GetTdp(int); 1.84 + 1.85 + // Returns the maximum temperature for the given node 1.86 + int GetMaxTemp(int); 1.87 + 1.88 + // Returns the current temperature in degrees C 1.89 + // of the given node 1.90 + int GetTemp(int); 1.91 + 1.92 + // Takes a sample of data. Must be called before 1.93 + // any current data is retrieved. 1.94 + int TakeSample(); 1.95 + 1.96 + // Gets the timestamp of the most recent sample 1.97 + uint64_t GetRdtsc(); 1.98 + 1.99 + // returns number of seconds between the last 1.100 + // two samples 1.101 + double GetInterval(); 1.102 + 1.103 + // Returns the base frequency for the given node 1.104 + double GetCPUBaseFrequency(int node); 1.105 + 1.106 + // Returns the combined package power for all 1.107 + // packages on the system for the last sample. 1.108 + double GetTotalPackagePowerInWatts(); 1.109 + double GetPackagePowerInWatts(int node); 1.110 + 1.111 + // Returns the combined CPU power for all 1.112 + // packages on the system for the last sample. 1.113 + // If the reading is not available, returns 0.0 1.114 + double GetTotalCPUPowerInWatts(); 1.115 + double GetCPUPowerInWatts(int node); 1.116 + 1.117 + // Returns the combined GPU power for all 1.118 + // packages on the system for the last sample. 1.119 + // If the reading is not available, returns 0.0 1.120 + double GetTotalGPUPowerInWatts(); 1.121 + double GetGPUPowerInWatts(int node); 1.122 + 1.123 +private: 1.124 + 1.125 + PRLibrary *libpowergadget; 1.126 + IPGInitialize Initialize; 1.127 + IPGGetNumNodes GetNumNodes; 1.128 + IPGGetNumMsrs GetNumMsrs; 1.129 + IPGGetMsrName GetMsrName; 1.130 + IPGGetMsrFunc GetMsrFunc; 1.131 + IPGReadMSR ReadMSR; 1.132 + IPGWriteMSR WriteMSR; 1.133 + IPGGetIAFrequency GetIAFrequency; 1.134 + IPGGetTDP GetTDP; 1.135 + IPGGetMaxTemperature GetMaxTemperature; 1.136 + IPGGetThresholds GetThresholds; 1.137 + IPGGetTemperature GetTemperature; 1.138 + IPGReadSample ReadSample; 1.139 + IPGGetSysTime GetSysTime; 1.140 + IPGGetRDTSC GetRDTSC; 1.141 + IPGGetTimeInterval GetTimeInterval; 1.142 + IPGGetBaseFrequency GetBaseFrequency; 1.143 + IPGGetPowerData GetPowerData; 1.144 + IPGStartLog StartLog; 1.145 + IPGStopLog StopLog; 1.146 + 1.147 + int packageMSR; 1.148 + int cpuMSR; 1.149 + int freqMSR; 1.150 + int tempMSR; 1.151 +}; 1.152 + 1.153 +#endif // profiler_IntelPowerGadget_h