diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /tier0/pmc360.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'tier0/pmc360.cpp')
| -rw-r--r-- | tier0/pmc360.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tier0/pmc360.cpp b/tier0/pmc360.cpp new file mode 100644 index 0000000..0d18441 --- /dev/null +++ b/tier0/pmc360.cpp @@ -0,0 +1,88 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Inner workings of Performance Monitor Counters on the xbox 360; +// they let vprof track L2 dcache misses, LHS, etc. +// +//=============================================================================// + +#include "pch_tier0.h" + +#ifndef _X360 +#error pmc360.cpp must only be compiled for XBOX360! +#else + +#include "tier0/platform.h" +#include "tier0/vprof.h" +#include <pmcpbsetup.h> +#include "tier0/dbg.h" +#include "pmc360.h" + +#include "tier0/memdbgon.h" + +static bool s_bInitialized = false; + +CPMCData::CPMCData() +{ +} + +void CPMCData::InitializeOnceProgramWide( void ) +{ +#if !defined( _CERT ) + // Select a set of sixteen counters + DmPMCInstallAndStart( PMC_SETUP_FLUSHREASONS_PB0T0 ); + // Reset the Performance Monitor Counters in preparation for a new sampling run. + DmPMCResetCounters(); +#endif + s_bInitialized = true; +} + +bool CPMCData::IsInitialized() +{ + return s_bInitialized; +} + +void CPMCData::Start() +{ +#if !defined( _CERT ) + // stop the stopwatches, save off the counter, start them again. + DmPMCStop(); + + PMCState pmcstate; + // Get the counters. + DmPMCGetCounters( &pmcstate ); + + // in the default state as set up by InitializeOnceProgramWide, + // counters 9 and 6 are L2 misses and LHS respectively + m_OnStart.L2CacheMiss = pmcstate.pmc[9]; + m_OnStart.LHS = pmcstate.pmc[6]; + + DmPMCStart(); +#endif +} + +void CPMCData::End() +{ +#if !defined( _CERT ) + DmPMCStop(); + + // get end-state counters + PMCState pmcstate; + // Get the counters. + DmPMCGetCounters( &pmcstate ); + + // in the default state as set up by InitializeOnceProgramWide, + // counters 9 and 6 are l2 misses and LHS respectively + const uint64 &endL2 = pmcstate.pmc[9]; + const uint64 &endLHS = pmcstate.pmc[6]; + + // compute delta between end and start. Because these are + // unsigned nums, even in overflow this still works out + // correctly under modular arithmetic. + m_Delta.L2CacheMiss = endL2 - m_OnStart.L2CacheMiss; + m_Delta.LHS = endLHS - m_OnStart.LHS; + + DmPMCStart(); +#endif +} + +#endif |