Counter Strike : Global Offensive Source Code
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.

162 lines
4.1 KiB

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