Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
[local gc] Enable eventing (#16120)
Browse files Browse the repository at this point in the history
* move GC etw enums to gcinterface.ee.h

* add GetActiveSyncBlockCount

* refactor reference to ETW::GCLog::ShouldTrackMovementForEtw()

* mov g_dwHandles to gc side

* enable FEATURE_EVENT_TRACE for gc
  • Loading branch information
davmason committed Feb 1, 2018
1 parent b11de87 commit 0bdf138
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 44 deletions.
3 changes: 0 additions & 3 deletions src/gc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Local GC meta-issue: https://github.com/dotnet/coreclr/issues/11518

# https://github.com/dotnet/coreclr/issues/11514
remove_definitions(-DFEATURE_EVENT_TRACE=1)

# https://github.com/dotnet/coreclr/issues/11517
remove_definitions(-DFEATURE_APPDOMAIN_RESOURCE_MONITORING)

Expand Down
1 change: 1 addition & 0 deletions src/gc/env/gcenv.ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class GCToEEInterface
static void SyncBlockCacheWeakPtrScan(HANDLESCANPROC scanProc, uintptr_t lp1, uintptr_t lp2);
static void SyncBlockCacheDemote(int max_gen);
static void SyncBlockCachePromotionsGranted(int max_gen);
static uint32_t GetActiveSyncBlockCount();

// Thread functions
static bool IsPreemptiveGCDisabled(Thread * pThread);
Expand Down
8 changes: 5 additions & 3 deletions src/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13231,7 +13231,7 @@ int gc_heap::try_allocate_more_space (alloc_context* acontext, size_t size,
// Unfortunately some of the ETW macros do not check whether the ETW feature is enabled.
// The ones that do are much less efficient.
#if defined(FEATURE_EVENT_TRACE)
if (EventEnabledGCAllocationTick_V3())
if (EVENT_ENABLED(GCAllocationTick_V3))
{
fire_etw_allocation_event (etw_allocation_running_amount[etw_allocation_index], gen_number, acontext->alloc_ptr);
}
Expand Down Expand Up @@ -19972,7 +19972,7 @@ void gc_heap::pin_object (uint8_t* o, uint8_t** ppObject, uint8_t* low, uint8_t*
set_pinned (o);

#ifdef FEATURE_EVENT_TRACE
if(EventEnabledPinObjectAtGCTime())
if(EVENT_ENABLED(PinObjectAtGCTime))
{
fire_etw_pin_object_event(o, ppObject);
}
Expand Down Expand Up @@ -31352,7 +31352,9 @@ void gc_heap::background_sweep()
#endif //MULTIPLE_HEAPS
{
#ifdef FEATURE_EVENT_TRACE
bgc_heap_walk_for_etw_p = ETW::GCLog::ShouldTrackMovementForEtw();
bgc_heap_walk_for_etw_p = GCEventStatus::IsEnabled(GCEventProvider_Default,
GCEventKeyword_GCHeapSurvivalAndMovement,
GCEventLevel_Information);
#endif //FEATURE_EVENT_TRACE

leave_spin_lock (&gc_lock);
Expand Down
6 changes: 6 additions & 0 deletions src/gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ class DacHeapWalker;
extern "C" uint32_t* g_gc_card_bundle_table;
#endif

#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
// Note this is not updated in a thread safe way so the value may not be accurate. We get
// it accurately in full GCs if the handle count is requested.
extern DWORD g_dwHandles;
#endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE

extern "C" uint32_t* g_gc_card_table;
extern "C" uint8_t* g_gc_lowest_address;
extern "C" uint8_t* g_gc_highest_address;
Expand Down
2 changes: 1 addition & 1 deletion src/gc/gcee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void GCHeap::UpdatePostGCCounters()
memset (g_GenerationPromotedSizes, 0, sizeof (g_GenerationPromotedSizes));

size_t total_num_gc_handles = g_dwHandles;
uint32_t total_num_sync_blocks = SyncBlockCache::GetSyncBlockCache()->GetActiveCount();
uint32_t total_num_sync_blocks = GCToEEInterface::GetActiveSyncBlockCount();

// Note this is however for perf counter only, for legacy reasons. What we showed
// in perf counters for "gen0 size" was really the gen0 budget which made
Expand Down
7 changes: 7 additions & 0 deletions src/gc/gcenv.ee.standalone.inl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ inline void GCToEEInterface::SyncBlockCachePromotionsGranted(int max_gen)
g_theGCToCLR->SyncBlockCachePromotionsGranted(max_gen);
}


inline uint32_t GCToEEInterface::GetActiveSyncBlockCount()
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->GetActiveSyncBlockCount();
}

inline bool GCToEEInterface::IsPreemptiveGCDisabled(Thread * pThread)
{
assert(g_theGCToCLR != nullptr);
Expand Down
18 changes: 18 additions & 0 deletions src/gc/gcinterface.ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
#ifndef _GCINTERFACE_EE_H_
#define _GCINTERFACE_EE_H_

enum EtwGCRootFlags
{
kEtwGCRootFlagsPinning = 0x1,
kEtwGCRootFlagsWeakRef = 0x2,
kEtwGCRootFlagsInterior = 0x4,
kEtwGCRootFlagsRefCounted = 0x8,
};

enum EtwGCRootKind
{
kEtwGCRootKindStack = 0,
kEtwGCRootKindFinalizer = 1,
kEtwGCRootKindHandle = 2,
kEtwGCRootKindOther = 3,
};

// This interface provides functions that the GC can use to fire events.
// Events fired on this interface are split into two categories: "known"
Expand Down Expand Up @@ -203,6 +218,9 @@ class IGCToCLR {
virtual
void SyncBlockCachePromotionsGranted(int max_gen) = 0;

virtual
uint32_t GetActiveSyncBlockCount() = 0;

// Queries whether or not the given thread has preemptive GC disabled.
virtual
bool IsPreemptiveGCDisabled(Thread * pThread) = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/gc/gcinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ struct ScanContext
#if defined(GC_PROFILING) || defined(FEATURE_EVENT_TRACE)
EtwGCRootKind dwEtwRootKind;
#else
int _unused3;
EtwGCRootKind _unused3;
#endif // GC_PROFILING || FEATURE_EVENT_TRACE

ScanContext()
Expand All @@ -929,9 +929,9 @@ struct ScanContext
#ifdef GC_PROFILING
pMD = NULL;
#endif //GC_PROFILING
#ifdef FEATURE_EVENT_TRACE
#if defined(GC_PROFILING) || defined(FEATURE_EVENT_TRACE)
dwEtwRootKind = kEtwGCRootKindOther;
#endif // FEATURE_EVENT_TRACE
#endif
}
};

Expand Down
12 changes: 12 additions & 0 deletions src/gc/handletable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "objecthandle.h"
#include "handletablepriv.h"

#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
DWORD g_dwHandles = 0;
#endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE

/****************************************************************************
*
* FORWARD DECLARATIONS
Expand Down Expand Up @@ -342,6 +346,10 @@ OBJECTHANDLE HndCreateHandle(HHANDLETABLE hTable, uint32_t uType, OBJECTREF obje
HandleQuickSetUserData(handle, lExtraInfo);
}

#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
g_dwHandles++;
#endif // defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)

// store the reference
HndAssignHandle(handle, object);
STRESS_LOG2(LF_GC, LL_INFO1000, "CreateHandle: %p, type=%d\n", handle, uType);
Expand Down Expand Up @@ -464,6 +472,10 @@ void HndDestroyHandle(HHANDLETABLE hTable, uint32_t uType, OBJECTHANDLE handle)

// return the handle to the table's cache
TableFreeSingleHandleToCache(pTable, uType, handle);

#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
g_dwHandles--;
#endif // defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
}


Expand Down
16 changes: 0 additions & 16 deletions src/inc/eventtracebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,6 @@ void InitializeEventTracing();
// These flags need to be defined either when FEATURE_EVENT_TRACE is enabled or the
// PROFILING_SUPPORTED is set, since they are used both by event tracing and profiling.

enum EtwGCRootFlags
{
kEtwGCRootFlagsPinning = 0x1,
kEtwGCRootFlagsWeakRef = 0x2,
kEtwGCRootFlagsInterior = 0x4,
kEtwGCRootFlagsRefCounted = 0x8,
};

enum EtwGCRootKind
{
kEtwGCRootKindStack = 0,
kEtwGCRootKindFinalizer = 1,
kEtwGCRootKindHandle = 2,
kEtwGCRootKindOther = 3,
};

enum EtwTypeFlags
{
kEtwTypeFlagsDelegate = 0x1,
Expand Down
1 change: 1 addition & 0 deletions src/vm/eetoprofinterfaceimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "eeprofinterfaces.h"
#include "shash.h"
#include "eventtracebase.h"
#include "gcinterface.h"

class SimpleRWLock;

Expand Down
12 changes: 12 additions & 0 deletions src/vm/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@ void GCToEEInterface::SyncBlockCachePromotionsGranted(int max_gen)
SyncBlockCache::GetSyncBlockCache()->GCDone(FALSE, max_gen);
}

uint32_t GCToEEInterface::GetActiveSyncBlockCount()
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
}
CONTRACTL_END;

return SyncBlockCache::GetSyncBlockCache()->GetActiveCount();
}

gc_alloc_context * GCToEEInterface::GetAllocContext(Thread * pThread)
{
WRAPPER_NO_CONTRACT;
Expand Down
1 change: 1 addition & 0 deletions src/vm/gcenv.ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GCToEEInterface : public IGCToCLR {
void SyncBlockCacheWeakPtrScan(HANDLESCANPROC scanProc, uintptr_t lp1, uintptr_t lp2);
void SyncBlockCacheDemote(int max_gen);
void SyncBlockCachePromotionsGranted(int max_gen);
uint32_t GetActiveSyncBlockCount();
bool IsPreemptiveGCDisabled(Thread * pThread);
void EnablePreemptiveGC(Thread * pThread);
void DisablePreemptiveGC(Thread * pThread);
Expand Down
8 changes: 0 additions & 8 deletions src/vm/gchandleutilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ void ValidateHandleAssignment(OBJECTHANDLE handle, OBJECTREF objRef)

void DiagHandleCreated(OBJECTHANDLE handle, OBJECTREF objRef)
{
#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
g_dwHandles++;
#endif // defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)

#ifdef GC_PROFILING
BEGIN_PIN_PROFILER(CORProfilerTrackGC());
g_profControlBlock.pProfInterface->HandleCreated((uintptr_t)handle, (ObjectID)OBJECTREF_TO_UNCHECKED_OBJECTREF(objRef));
Expand All @@ -71,8 +67,4 @@ void DiagHandleDestroyed(OBJECTHANDLE handle)
#else
UNREFERENCED_PARAMETER(handle);
#endif // GC_PROFILING

#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
g_dwHandles--;
#endif // defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
}
4 changes: 0 additions & 4 deletions src/vm/vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ GPTR_IMPL(Thread,g_pSuspensionThread);
// Global SyncBlock cache
GPTR_IMPL(SyncTableEntry,g_pSyncTable);

#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
DWORD g_dwHandles = 0;
#endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE

#ifdef STRESS_LOG
GPTR_IMPL_INIT(StressLog, g_pStressLog, &StressLog::theLog);
#endif
Expand Down
6 changes: 0 additions & 6 deletions src/vm/vars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,6 @@ GPTR_DECL(Thread,g_pSuspensionThread);
typedef DPTR(SyncTableEntry) PTR_SyncTableEntry;
GPTR_DECL(SyncTableEntry, g_pSyncTable);

#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
// Note this is not updated in a thread safe way so the value may not be accurate. We get
// it accurately in full GCs if the handle count is requested.
extern DWORD g_dwHandles;
#endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE

#ifdef FEATURE_COMINTEROP
// Global RCW cleanup list
typedef DPTR(RCWCleanupList) PTR_RCWCleanupList;
Expand Down

0 comments on commit 0bdf138

Please sign in to comment.