tools/profiler/IntelPowerGadget.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 * Copyright 2013, Intel Corporation
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 *
michael@0 16 * Author: Joe Olivas <joseph.k.olivas@intel.com>
michael@0 17 */
michael@0 18
michael@0 19 #ifndef profiler_IntelPowerGadget_h
michael@0 20 #define profiler_IntelPowerGadget_h
michael@0 21
michael@0 22 #ifdef _MSC_VER
michael@0 23 typedef __int32 int32_t;
michael@0 24 typedef unsigned __int32 uint32_t;
michael@0 25 typedef __int64 int64_t;
michael@0 26 typedef unsigned __int64 uint64_t;
michael@0 27 #else
michael@0 28 #include <stdint.h>
michael@0 29 #endif
michael@0 30 #include "prlink.h"
michael@0 31
michael@0 32 typedef int (*IPGInitialize) ();
michael@0 33 typedef int (*IPGGetNumNodes) (int *nNodes);
michael@0 34 typedef int (*IPGGetNumMsrs) (int *nMsr);
michael@0 35 typedef int (*IPGGetMsrName) (int iMsr, wchar_t *szName);
michael@0 36 typedef int (*IPGGetMsrFunc) (int iMsr, int *pFuncID);
michael@0 37 typedef int (*IPGReadMSR) (int iNode, unsigned int address, uint64_t *value);
michael@0 38 typedef int (*IPGWriteMSR) (int iNode, unsigned int address, uint64_t value);
michael@0 39 typedef int (*IPGGetIAFrequency) (int iNode, int *freqInMHz);
michael@0 40 typedef int (*IPGGetTDP) (int iNode, double *TDP);
michael@0 41 typedef int (*IPGGetMaxTemperature) (int iNode, int *degreeC);
michael@0 42 typedef int (*IPGGetThresholds) (int iNode, int *degree1C, int *degree2C);
michael@0 43 typedef int (*IPGGetTemperature) (int iNode, int *degreeC);
michael@0 44 typedef int (*IPGReadSample) ();
michael@0 45 typedef int (*IPGGetSysTime) (void *pSysTime);
michael@0 46 typedef int (*IPGGetRDTSC) (uint64_t *pTSC);
michael@0 47 typedef int (*IPGGetTimeInterval) (double *pOffset);
michael@0 48 typedef int (*IPGGetBaseFrequency) (int iNode, double *pBaseFrequency);
michael@0 49 typedef int (*IPGGetPowerData) (int iNode, int iMSR, double *pResult, int *nResult);
michael@0 50 typedef int (*IPGStartLog) (wchar_t *szFileName);
michael@0 51 typedef int (*IPGStopLog) ();
michael@0 52
michael@0 53 #if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
michael@0 54 #define PG_LIBRARY_NAME "EnergyLib64"
michael@0 55 #else
michael@0 56 #define PG_LIBRARY_NAME "EnergyLib32"
michael@0 57 #endif
michael@0 58
michael@0 59
michael@0 60 class IntelPowerGadget
michael@0 61 {
michael@0 62 public:
michael@0 63
michael@0 64 IntelPowerGadget();
michael@0 65 ~IntelPowerGadget();
michael@0 66
michael@0 67 // Fails if initialization is incomplete
michael@0 68 bool Init();
michael@0 69
michael@0 70 // Returns the number of packages on the system
michael@0 71 int GetNumberNodes();
michael@0 72
michael@0 73 // Returns the number of MSRs being tracked
michael@0 74 int GetNumberMsrs();
michael@0 75
michael@0 76 // Given a node, returns the temperature
michael@0 77 int GetCPUFrequency(int);
michael@0 78
michael@0 79 // Returns the TDP of the given node
michael@0 80 double GetTdp(int);
michael@0 81
michael@0 82 // Returns the maximum temperature for the given node
michael@0 83 int GetMaxTemp(int);
michael@0 84
michael@0 85 // Returns the current temperature in degrees C
michael@0 86 // of the given node
michael@0 87 int GetTemp(int);
michael@0 88
michael@0 89 // Takes a sample of data. Must be called before
michael@0 90 // any current data is retrieved.
michael@0 91 int TakeSample();
michael@0 92
michael@0 93 // Gets the timestamp of the most recent sample
michael@0 94 uint64_t GetRdtsc();
michael@0 95
michael@0 96 // returns number of seconds between the last
michael@0 97 // two samples
michael@0 98 double GetInterval();
michael@0 99
michael@0 100 // Returns the base frequency for the given node
michael@0 101 double GetCPUBaseFrequency(int node);
michael@0 102
michael@0 103 // Returns the combined package power for all
michael@0 104 // packages on the system for the last sample.
michael@0 105 double GetTotalPackagePowerInWatts();
michael@0 106 double GetPackagePowerInWatts(int node);
michael@0 107
michael@0 108 // Returns the combined CPU power for all
michael@0 109 // packages on the system for the last sample.
michael@0 110 // If the reading is not available, returns 0.0
michael@0 111 double GetTotalCPUPowerInWatts();
michael@0 112 double GetCPUPowerInWatts(int node);
michael@0 113
michael@0 114 // Returns the combined GPU power for all
michael@0 115 // packages on the system for the last sample.
michael@0 116 // If the reading is not available, returns 0.0
michael@0 117 double GetTotalGPUPowerInWatts();
michael@0 118 double GetGPUPowerInWatts(int node);
michael@0 119
michael@0 120 private:
michael@0 121
michael@0 122 PRLibrary *libpowergadget;
michael@0 123 IPGInitialize Initialize;
michael@0 124 IPGGetNumNodes GetNumNodes;
michael@0 125 IPGGetNumMsrs GetNumMsrs;
michael@0 126 IPGGetMsrName GetMsrName;
michael@0 127 IPGGetMsrFunc GetMsrFunc;
michael@0 128 IPGReadMSR ReadMSR;
michael@0 129 IPGWriteMSR WriteMSR;
michael@0 130 IPGGetIAFrequency GetIAFrequency;
michael@0 131 IPGGetTDP GetTDP;
michael@0 132 IPGGetMaxTemperature GetMaxTemperature;
michael@0 133 IPGGetThresholds GetThresholds;
michael@0 134 IPGGetTemperature GetTemperature;
michael@0 135 IPGReadSample ReadSample;
michael@0 136 IPGGetSysTime GetSysTime;
michael@0 137 IPGGetRDTSC GetRDTSC;
michael@0 138 IPGGetTimeInterval GetTimeInterval;
michael@0 139 IPGGetBaseFrequency GetBaseFrequency;
michael@0 140 IPGGetPowerData GetPowerData;
michael@0 141 IPGStartLog StartLog;
michael@0 142 IPGStopLog StopLog;
michael@0 143
michael@0 144 int packageMSR;
michael@0 145 int cpuMSR;
michael@0 146 int freqMSR;
michael@0 147 int tempMSR;
michael@0 148 };
michael@0 149
michael@0 150 #endif // profiler_IntelPowerGadget_h

mercurial