Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "pch_tier0.h"
  7. #define WINDOWS_LEAN_AND_MEAN
  8. #include <windows.h>
  9. #pragma warning( disable : 4530 ) // warning: exception handler -GX option
  10. #include "tier0/platform.h"
  11. #include "tier0/vprof.h"
  12. #include "tier0/pmelib.h"
  13. #include "tier0/l2cache.h"
  14. #include "tier0/dbg.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Initialization
  17. //-----------------------------------------------------------------------------
  18. void InitPME( void )
  19. {
  20. bool bInit = false;
  21. PME *pPME = PME::Instance();
  22. if ( pPME )
  23. {
  24. if ( pPME->GetVendor() != INTEL )
  25. return;
  26. if ( pPME->GetProcessorFamily() != PENTIUM4_FAMILY )
  27. return;
  28. pPME->SetProcessPriority( ProcessPriorityHigh );
  29. bInit = true;
  30. DevMsg( 1, _T("PME Initialized.\n") );
  31. }
  32. else
  33. {
  34. DevMsg( 1, _T("PME Uninitialized.\n") );
  35. }
  36. g_VProfCurrentProfile.PMEInitialized( bInit );
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose: Shutdown
  40. //-----------------------------------------------------------------------------
  41. void ShutdownPME( void )
  42. {
  43. PME *pPME = PME::Instance();
  44. if ( pPME )
  45. {
  46. pPME->SetProcessPriority( ProcessPriorityNormal );
  47. }
  48. g_VProfCurrentProfile.PMEInitialized( false );
  49. }
  50. //=============================================================================
  51. //
  52. // CL2Cache Code.
  53. //
  54. static int s_nCreateCount = 0;
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. //-----------------------------------------------------------------------------
  58. CL2Cache::CL2Cache()
  59. {
  60. m_nID = s_nCreateCount++;
  61. m_pL2CacheEvent = new P4Event_BSQ_cache_reference;
  62. m_iL2CacheMissCount = 0;
  63. m_i64Start = 0;
  64. m_i64End = 0;
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. CL2Cache::~CL2Cache()
  70. {
  71. if ( m_pL2CacheEvent )
  72. {
  73. delete m_pL2CacheEvent;
  74. m_pL2CacheEvent = NULL;
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose:
  79. //-----------------------------------------------------------------------------
  80. void CL2Cache::Start( void )
  81. {
  82. if ( m_pL2CacheEvent )
  83. {
  84. // Set this up to check for L2 cache misses.
  85. m_pL2CacheEvent->eventMask->RD_2ndL_MISS = 1;
  86. // Set the event mask and set the capture mode.
  87. // m_pL2CacheEvent->SetCaptureMode( USR_Only );
  88. m_pL2CacheEvent->SetCaptureMode( OS_and_USR );
  89. // That's it, now sw capture events
  90. m_pL2CacheEvent->StopCounter();
  91. m_pL2CacheEvent->ClearCounter();
  92. m_pL2CacheEvent->StartCounter();
  93. m_i64Start = m_pL2CacheEvent->ReadCounter();
  94. }
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose:
  98. //-----------------------------------------------------------------------------
  99. void CL2Cache::End( void )
  100. {
  101. if ( m_pL2CacheEvent )
  102. {
  103. // Stop the counter and find the delta.
  104. m_i64End = m_pL2CacheEvent->ReadCounter();
  105. int64 i64Delta = m_i64End - m_i64Start;
  106. m_pL2CacheEvent->StopCounter();
  107. // Save the delta for later query.
  108. m_iL2CacheMissCount = ( int )i64Delta;
  109. }
  110. }
  111. #pragma warning( default : 4530 )
  112. #ifdef DBGFLAG_VALIDATE
  113. //-----------------------------------------------------------------------------
  114. // Purpose: Ensure that all of our internal structures are consistent, and
  115. // account for all memory that we've allocated.
  116. // Input: validator - Our global validator object
  117. // pchName - Our name (typically a member var in our container)
  118. //-----------------------------------------------------------------------------
  119. void CL2Cache::Validate( CValidator &validator, tchar *pchName )
  120. {
  121. validator.Push( _T("CL2Cache"), this, pchName );
  122. validator.ClaimMemory( m_pL2CacheEvent );
  123. validator.Pop( );
  124. }
  125. #endif // DBGFLAG_VALIDATE