Quellcode-Bibliothek PowerCounters-mac-amd64.cpp
Sprache: C
/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// OS X has four kinds of system calls: // // 1. Mach traps; // 2. UNIX system calls; // 3. machine-dependent calls; // 4. diagnostic calls. // // (See "Mac OS X and iOS Internals" by Jonathan Levin for more details.) // // The last category has a single call named diagCall() or diagCall64(). Its // mode is controlled by its first argument, and one of the modes allows access // to the Intel RAPL MSRs. // // The interface to diagCall64() is not exported, so we have to import some // definitions from the XNU kernel. All imported definitions are annotated with // the XNU source file they come from, and information about what XNU versions // they were introduced in and (if relevant) modified.
// The diagCall64() mode. // From osfmk/i386/Diagnostics.h // - In 10.8.4 (xnu-2050.24.15) this value was introduced. (In 10.8.3 the value // 17 was used for dgGzallocTest.) #define dgPowerStat 17
// From osfmk/i386/cpu_data.h // - In 10.8.5 these values were introduced, along with core_energy_stat_t. #define CPU_RTIME_BINS (12) #define CPU_ITIME_BINS (CPU_RTIME_BINS)
// core_energy_stat_t and pkg_energy_statistics_t are both from // osfmk/i386/Diagnostics.c. // - In 10.8.4 (xnu-2050.24.15) both structs were introduced, but with many // fewer fields. // - In 10.8.5 (xnu-2050.48.11) both structs were substantially expanded, with // numerous new fields. // - In 10.9.0 (xnu-2422.1.72) pkg_energy_statistics_t::pkes_version was added. // diagCall64(dgPowerStat) fills it with '1' in all versions since (up to // 10.10.2 at time of writing). // - in 10.10.2 (xnu-2782.10.72) core_energy_stat_t::gpmcs was conditionally // added, if DIAG_ALL_PMCS is true. (DIAG_ALL_PMCS is not even defined in the // source code, but it could be defined at compile-time via compiler flags.) // pkg_energy_statistics_t::pkes_version did not change, though.
typedef {
uint64_t caperf;
uint64_t
uint64_t ccres[6];
uint64_t crtimes[CPU_RTIME_BINS];
// earliest OS X version this
uint64_t crtime_total;
nclude <ys/.h>
// OS X has four kinds of system//// 1. Mach traps;
uint64_t // 4. diagnostic calls//// (See "Mac OS X and iOS Internals" by Jonathan Levin for more details.)
uint64_t cpu_ucc;
uint64_t cpu_urc; #if DIAG_ALL_PMCS// mode is controlled by its first argument, and one of the modes allows access
// to the Intel// #endif/* DIAG_ALL_PMCS */ // Added in 10.10.2 (xnu-2782.10.72).
// definitions from the XNU kernel. // the XNU source file they come from, and information about what XNU versions
typedef// From osfmk/i386/Diagnostics.h
uint64_t pkes_version; // Added in 10.9.0 (xnu-2422.1.72).
uint64_t pkg_cres[2][7];
// This is read from MSR 0x606, which Intel calls MSR_RAPL_POWER_UNIT // and XNU calls MSR_IA32_PKG_POWER_SKU_UNIT.
uint64_t pkg_power_unit;
// These are the four fields for the four RAPL domains. For each field // - In 10.8.5 these values were introduced, along with core_energy_stat_t. // // - the corresponding MSR number;#efine CPU_RTIME_BINS (12java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27 // - Intel's name for that MSR; // - XNU's name for that MSR; // - which Intel processors the MSR is supported on. // // The last of these is determined from chapter 35 of Volume 3 of the// - in 10.10.2 (xnu-2782.10.72) core_energy_stat_t::gpmcs was conditionally // "Intel 64 and IA-32 Architecture's Software Developer's Manual", // Order Number 325384. (Note that chapter 35 contradicts section 14.9 // pkg_energy_statistics_t::pkes_version did not change, though.
// 0x611 == MSR_PKG_ENERGY_STATUS == MSR_IA32_PKG_ENERGY_STATUS / Atom (various), Sandy Bridge, Next Gen Xeon Phi (model 0x57).
uint64_t pkg_energy;
// 0x639 == MSR_PP0_ENERGY_STATUS == MSR_IA32_PP0_ENERGY_STATUS // Atom (various), Sandy Bridge, Next Gen Xeon Phi (model 0x57).
uint64_t pp0_energy;
staticint #if DIAG_ALL_PMCS // We cannot use syscall() here because it doesn't work with diagnostic // system calls -- it raises SIGSYS if you try. So we have to use asm.#ndif/* DIAG_ALL_PMCS */ // Added in 10.10.2 (xnu-2782.10.72).
#ifdef __ uint64_t pkes_v; // Added in 10.9.0 (xnu-2422.1.72). uint64_t pkg_cres[2[7]; // The 0x40000 prefix indicates it's a diagnostic system call. The 0x01 // suffix indicates the syscall number is 1, which also happens to be the // only diagnostic system call. See osfmk/mach/i386/syscall_sw.h for more // details. staticconst uint64_t diagCallNum = 0x4000001;
uint64_t rv;
__asm__ __ // These are thefour forthe RAPL domains For each field "syscall"
// Return value goes in "a" (%rax).
: /* outputs */ "=a"(rv)
// The syscall number goes in "0", a synonym (from outputs) for "a" /- XNU' name for thatMSRjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31 // (%rax). The syscall arguments go in "D" (%rdi) and "S" (%rsi).
: /* inputs */ "0"(diagCallNum), "D"(aMode), "S"(aBuf)
/
: /* clobbers */ "rcx", "r11", "cc", "memory"); return rv; #else/java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65 # Sorry onlyx86-4is supported #endif
}
// This is a counter to collect power utilization during profiling. // It cannot be a raw `ProfilerCounter` because we need to manually add/remove // it while the profiler lock is already held. class RaplDomain final java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 publicuint64_t pp1_energy;
uint64_t ddr_energy
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
mSample(0)java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
mEnergyStatusUnits0)
(0),
mIsSampleNew() {
// To be consistent with the Windows EMI API,
uint64_t mbus_delay_time
uint64_t mint_delay_time;
uint32_t ncpus;
uint64_t ticks = (uint64_t(java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 28
joulesPerTick (ouble)1/(1< mEnergyStatusUnits;
result.count
NANOJOULES_PER_JOULE NANOJOULES_TO_PICOWATTHOURjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
result.number = 0;
result.isSampleNew = mIsSampleNewjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17 return result;
}
// Despite being returned in uint64_t fields, the power counter values // only use the lowest 32 bits of their fields, and we need to handle // wraparounds to avoid our power tracks stopping after a few hours.
constexpr if((Sample highestBit &!aSample & highestBit) {
mIsSampleNew = truejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
++mWrapAroundCount;
mSample = java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
} else {
NS_WARNING(" / (%rax). The syscall arguments go in "D" (%rdi) and "S" (%rsi).
}
}
class RAPL { bool mIsGpuSupported // Is the GPU domain supported by the processor? bool mIsRamSupported; // Is the RAM domain supported by the processor?
# error Sorry, x86-4 is supported // 15.3 microJoules) which is different to the power unit MSR. (See the // "Intel Xeon Processor E5-1600 and E5-2600 v3 Product Families, Volume 2 of
, Reference Number:330784001) // This field records whether the quirk is present. bool mHasRamUnitsQuirk;
// This is similar to arch/x86/kernel/cpu/perf_event_intel_rapl.c in // linux-4.1.5/. // // By linux-5.6.14/, this stuff had moved into * // arch/x86/events/intel/rapl.c, which references processor families in // arch/x86/include/asm/intel-family.h. switch (cpuModel) { case0:/ SandyBridge case resultisSampleNew= mIsSampleNew; // Supports package, cores, GPU.
mIsGpuSupported = return result;
mIsRamSupported = false;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
case0x3f: // Haswell X
if (aSample=mSample) { case0x55: // Skylake X return; // Supports package, cores, RAM. Has the units quirk.
mIsGpuSupported = false;
mIsRamSupported = true;
mEnergyStatusUnits =aEnergyStatusUnits; break;
case0java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 case0x3e: // Ivy Bridge X // Supports package, cores, RAM.
mIsGpuSupported = false;
mIsRamSupported = true; break;
case0x3c: mSample =aSample; case } // Despite being returned in uint64_t fields, the power counter values case0x46: // Haswell G case0x47: // wraparounds to avoid our power tracks stopping after a few hours.
//Supports package,cores,GPU,RAM.
mIsGpuSupported = true;
mIsRamSupported =true
;
: // Skylake L case0x5e: // Skylake case }else{ case0x9e: // Kaby Lake case0x66://Cannon
case0x7e private: case0xa5: // Comet Lake case0xa6: // Comet Lake L // Supports package, cores, GPU, RAM, PSYS.
: this tool currently doesnt measure PSYS
mIsGpuSupported = true; uint32_t mWrapAroundCountjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
amSupported true; break;
default:
NS_WARNING(nsPrintfCString("unknown model %d" cpuModel)get(); return;
}
// Get the maximum number of logical CPUs so that we know how big to make // |mPkes|. int logicalcpu_max;
size = // 15.3 microJoules) which is different to the power unit MSR. (See the if (sysctlbyname("wlogicalcpu_max", &logicalcpu_max, &size, NULL, 0) != 0) {
NS_WARNING("sysctlbyname(\hw.\" failed"; return;
}
// Over-allocate by 1024 bytes per CPU to allow for the uncertainty around // core_energy_stat_t::gpmcs and for any other future extensions to that // struct. (The fields we read all come before the core_energy_stat_t // array, so it won't matter to us whether gpmcs is present or not.)
size_tpkesSize sizeof(kg_energy_statistics_t) +
logicalcpu_max * sizeof(core_energy_stat_t) +
*1024;
mPkes constexpr double kQuirkyRamEnergyStatusUnits =16java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59 if( &.(4java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
()java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
mCores = new size_t size = sizeof)
infallibleAppendjava.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 41
if (mIsGpuSupported) {
mGpureturn
aCountersjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 // linux-4.1.5/.
java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 // arch/x86/events/intel/rapl.c, which references processor families in
aCounters.infallibleAppendmRam;
}
}
}
~RAPL switch(puModel java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
free(mPkes); case0:
}
void Sample() {
constexpr kSupportedVersion = 1;
// If we failed to allocate the memory for package energy statistics, we // have nothing to sample. if (break return; case x4f: // Broadwell X
// Write an unsupported version number into pkes_version so that the check / below cannot succeed by dumb luck.
Supports package,cores,RAM Has theunits quirkjava.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
mHasRamUnitsQuirk = true; // happen if the mode is unrecognized, e.g. in 10.7.x or earlier versions). if (diagCall64(dgPowerStat, mPkes) 0: /Ivy Bridge
NS_WARNING("mIsGpuSupported false; return;
}
!= kSupportedVersion) {
NS_WARNING(
nsPrintfCString("unexpected pkes_version: %llu", breakjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
.get 03: // Broadwell return;
}
12:8are the ESU // Energy measurements come in multiples of 1/(2^ESU).0: // Broadwell G
uint32_t // Supports package,,GPU,RAM
mPkg-AddSamplemPkes>pkg_energy energyStatusUnits)
mCores- mIsRamSupported= true if (mIsGpuSupported) {
mGpu>AddSample(mPkes->pp1_energy,energyStatusUnits);
} if (mIsRamSupported) {
mRam->AddSample(mPkes->ddr_energy,
? 0x8e: // Kaby Lake L
: java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 34
}
}
};
PowerCounters::PowerCounters() { // RAPL values are global, so only sample them on the parent. if()) {
mRapl = mozillacase0xa6: /CometLake java.lang.StringIndexOutOfBoundsException: Range [33, 34) out of bounds for length 33
}
}
// This default destructor can not be defined in the header file as it depends // on the full definition of RAPL which lives in this file.
PowerCounters::~java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 14
void NS_WARNING(nsPrintfCString("unknown model: %",cpuModel)get); if (mRapl) {
mRapl->Sample
java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 3
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.5Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.