Home | History | Annotate | Download | only in power_gadget
      1 // Copyright (c) 2014, Intel Corporation
      2 // All rights reserved.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions are
      6 // met:
      7 //
      8 //     * Redistributions of source code must retain the above copyright
      9 // notice, this list of conditions and the following disclaimer.
     10 //     * Redistributions in binary form must reproduce the above
     11 // copyright notice, this list of conditions and the following disclaimer
     12 // in the documentation and/or other materials provided with the
     13 // distribution.
     14 //     * Neither the name of Intel Corporation nor the names of its
     15 // contributors may be used to endorse or promote products derived from
     16 // this software without specific prior written permission.
     17 //
     18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 
     30 #include <Windows.h>
     31 #include <string>
     32 
     33 using namespace std;
     34 
     35 typedef bool (*IPGInitialize) ();
     36 typedef bool (*IPGGetNumNodes) (int *nNodes);
     37 typedef bool (*IPGGetNumMsrs) (int *nMsr);
     38 typedef bool (*IPGGetMsrName) (int iMsr, wchar_t *szName);
     39 typedef bool (*IPGGetMsrFunc) (int iMsr, int *funcID);
     40 typedef bool (*IPGGetIAFrequency) (int iNode, int *freqInMHz);
     41 typedef bool (*IPGGetTDP) (int iNode, double *TDP);
     42 typedef bool (*IPGGetMaxTemperature) (int iNode, int *degreeC);
     43 typedef bool (*IPGGetTemperature) (int iNode, int *degreeC);
     44 typedef bool (*IPGReadSample) ();
     45 typedef bool (*IPGGetSysTime) (SYSTEMTIME *pSysTime);
     46 typedef bool (*IPGGetRDTSC) (UINT64 *TSC);
     47 typedef bool (*IPGGetTimeInterval) (double *offset);
     48 typedef bool (*IPGGetBaseFrequency) (int iNode, double *baseFrequency);
     49 typedef bool (*IPGGetPowerData) (int iNode, int iMSR, double *result, int *nResult);
     50 typedef bool (*IPGStartLog) (wchar_t *szFileName);
     51 typedef bool (*IPGStopLog) ();
     52 
     53 class CIntelPowerGadgetLib
     54 {
     55 public:
     56 	CIntelPowerGadgetLib(void);
     57 	~CIntelPowerGadgetLib(void);
     58 
     59 	bool IntelEnergyLibInitialize(void);
     60 	bool GetNumNodes(int * nNodes);
     61 	bool GetNumMsrs(int *nMsrs);
     62 	bool GetMsrName(int iMsr, wchar_t *szName);
     63 	bool GetMsrFunc(int iMsr, int *funcID);
     64 	bool GetIAFrequency(int iNode, int *freqInMHz);
     65 	bool GetTDP(int iNode, double *TDP);
     66 	bool GetMaxTemperature(int iNode, int *degreeC);
     67 	bool GetTemperature(int iNode, int *degreeC);
     68 	bool ReadSample();
     69 	bool GetSysTime(SYSTEMTIME *sysTime);
     70 	bool GetRDTSC(UINT64 *TSC);
     71 	bool GetTimeInterval(double *offset);
     72 	bool GetBaseFrequency(int iNode, double *baseFrequency);
     73 	bool GetPowerData(int iNode, int iMSR, double *results, int *nResult);
     74 	bool StartLog(wchar_t *szFilename);
     75 	bool StopLog();
     76 	string GetLastError();
     77 
     78 private:
     79 	IPGInitialize pInitialize;
     80 	IPGGetNumNodes pGetNumNodes;
     81 	IPGGetNumMsrs pGetNumMsrs;
     82 	IPGGetMsrName pGetMsrName;
     83 	IPGGetMsrFunc pGetMsrFunc;
     84 	IPGGetIAFrequency pGetIAFrequency;
     85 	IPGGetTDP pGetTDP;
     86 	IPGGetMaxTemperature pGetMaxTemperature;
     87 	IPGGetTemperature pGetTemperature;
     88 	IPGReadSample pReadSample;
     89 	IPGGetSysTime pGetSysTime;
     90 	IPGGetRDTSC pGetRDTSC;
     91 	IPGGetTimeInterval pGetTimeInterval;
     92 	IPGGetBaseFrequency pGetBaseFrequency;
     93 	IPGGetPowerData pGetPowerData;
     94 	IPGStartLog pStartLog;
     95 	IPGStopLog pStopLog;
     96 };
     97 
     98