Commit 43c7d555 authored by Duncan Coutts's avatar Duncan Coutts

Add capability sets to the tracing/events system

We trace the creation and shutdown of capabilities. All the capabilities
in the process are assigned to one capabilitiy set of OS-process type.

This is a second version of the patch. Includes work by Spencer Janssen.
parent c4f9b989
...@@ -253,6 +253,8 @@ initCapability( Capability *cap, nat i ) ...@@ -253,6 +253,8 @@ initCapability( Capability *cap, nat i )
cap->transaction_tokens = 0; cap->transaction_tokens = 0;
cap->context_switch = 0; cap->context_switch = 0;
cap->pinned_object_block = NULL; cap->pinned_object_block = NULL;
traceCapsetAssignCap(CAPSET_OSPROCESS_DEFAULT, i);
} }
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
...@@ -266,6 +268,10 @@ initCapability( Capability *cap, nat i ) ...@@ -266,6 +268,10 @@ initCapability( Capability *cap, nat i )
void void
initCapabilities( void ) initCapabilities( void )
{ {
/* Declare a single capability set representing the process.
Each capability will get added to this capset. */
traceCapsetCreate(CAPSET_OSPROCESS_DEFAULT, CapsetTypeOsProcess);
#if defined(THREADED_RTS) #if defined(THREADED_RTS)
nat i; nat i;
...@@ -717,7 +723,9 @@ tryGrabCapability (Capability *cap, Task *task) ...@@ -717,7 +723,9 @@ tryGrabCapability (Capability *cap, Task *task)
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
void void
shutdownCapability (Capability *cap USED_IF_THREADS, Task *task USED_IF_THREADS, rtsBool safe USED_IF_THREADS) shutdownCapability (Capability *cap,
Task *task USED_IF_THREADS,
rtsBool safe USED_IF_THREADS)
{ {
#if defined(THREADED_RTS) #if defined(THREADED_RTS)
nat i; nat i;
...@@ -813,6 +821,8 @@ shutdownCapability (Capability *cap USED_IF_THREADS, Task *task USED_IF_THREADS, ...@@ -813,6 +821,8 @@ shutdownCapability (Capability *cap USED_IF_THREADS, Task *task USED_IF_THREADS,
// closeMutex(&cap->lock); // closeMutex(&cap->lock);
#endif /* THREADED_RTS */ #endif /* THREADED_RTS */
traceCapsetRemoveCap(CAPSET_OSPROCESS_DEFAULT, cap->no);
} }
void void
...@@ -823,6 +833,7 @@ shutdownCapabilities(Task *task, rtsBool safe) ...@@ -823,6 +833,7 @@ shutdownCapabilities(Task *task, rtsBool safe)
ASSERT(task->incall->tso == NULL); ASSERT(task->incall->tso == NULL);
shutdownCapability(&capabilities[i], task, safe); shutdownCapability(&capabilities[i], task, safe);
} }
traceCapsetDelete(CAPSET_OSPROCESS_DEFAULT);
} }
static void static void
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
* typedef uint16_t EventCapNo; * typedef uint16_t EventCapNo;
* typedef uint16_t EventPayloadSize; // variable-size events * typedef uint16_t EventPayloadSize; // variable-size events
* typedef uint16_t EventThreadStatus; * typedef uint16_t EventThreadStatus;
* typedef uint32_t EventCapsetID;
* typedef uint16_t EventCapsetType; // types for EVENT_CAPSET_CREATE
*/ */
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
...@@ -60,5 +62,9 @@ provider HaskellEvent { ...@@ -60,5 +62,9 @@ provider HaskellEvent {
probe gc__idle (EventCapNo); probe gc__idle (EventCapNo);
probe gc__work (EventCapNo); probe gc__work (EventCapNo);
probe gc__done (EventCapNo); probe gc__done (EventCapNo);
probe capset__create(EventCapsetID, EventCapsetType);
probe capset__delete(EventCapsetID);
probe capset__assign__cap(EventCapsetID, EventCapNo);
probe capset__remove__cap(EventCapsetID, EventCapNo);
}; };
...@@ -251,6 +251,39 @@ void traceSchedEvent_ (Capability *cap, EventTypeNum tag, ...@@ -251,6 +251,39 @@ void traceSchedEvent_ (Capability *cap, EventTypeNum tag,
} }
} }
void traceCapsetModify_ (EventTypeNum tag,
CapsetID capset,
StgWord32 other)
{
#ifdef DEBUG
if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
ACQUIRE_LOCK(&trace_utx);
tracePreface();
switch (tag) {
case EVENT_CAPSET_CREATE: // (capset, capset_type)
debugBelch("created capset %d of type %d\n", capset, other);
break;
case EVENT_CAPSET_DELETE: // (capset)
debugBelch("deleted capset %d\n", capset);
break;
case EVENT_CAPSET_ASSIGN_CAP: // (capset, capno)
debugBelch("assigned cap %d to capset %d\n", other, capset);
break;
case EVENT_CAPSET_REMOVE_CAP: // (capset, capno)
debugBelch("removed cap %d from capset %d\n", other, capset);
break;
}
RELEASE_LOCK(&trace_utx);
} else
#endif
{
if (eventlog_enabled) {
postCapsetModifyEvent(tag, capset, other);
}
}
}
void traceEvent_ (Capability *cap, EventTypeNum tag) void traceEvent_ (Capability *cap, EventTypeNum tag)
{ {
#ifdef DEBUG #ifdef DEBUG
......
...@@ -31,6 +31,13 @@ void resetTracing (void); ...@@ -31,6 +31,13 @@ void resetTracing (void);
#endif /* TRACING */ #endif /* TRACING */
typedef StgWord32 CapsetID;
typedef StgWord16 CapsetType;
enum CapsetType { CapsetTypeCustom = CAPSET_TYPE_CUSTOM,
CapsetTypeOsProcess = CAPSET_TYPE_OSPROCESS,
CapsetTypeClockdomain = CAPSET_TYPE_CLOCKDOMAIN };
#define CAPSET_OSPROCESS_DEFAULT 0
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Message classes // Message classes
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -162,6 +169,19 @@ void traceThreadStatus_ (StgTSO *tso); ...@@ -162,6 +169,19 @@ void traceThreadStatus_ (StgTSO *tso);
void traceEventStartup_ (int n_caps); void traceEventStartup_ (int n_caps);
/*
* Events for describing capability sets in the eventlog
*
* Note: unlike other events, these are not conditional on TRACE_sched or
* similar because they are not "real" events themselves but provide
* information and context for other "real" events. Other events depend on
* the capset info events so for simplicity, rather than working out if
* they're necessary we always emit them. They should be very low volume.
*/
void traceCapsetModify_ (EventTypeNum tag,
CapsetID capset,
StgWord32 other);
#else /* !TRACING */ #else /* !TRACING */
#define traceSchedEvent(cap, tag, tso, other) /* nothing */ #define traceSchedEvent(cap, tag, tso, other) /* nothing */
...@@ -173,6 +193,7 @@ void traceEventStartup_ (int n_caps); ...@@ -173,6 +193,7 @@ void traceEventStartup_ (int n_caps);
#define debugTraceCap(class, cap, str, ...) /* nothing */ #define debugTraceCap(class, cap, str, ...) /* nothing */
#define traceThreadStatus(class, tso) /* nothing */ #define traceThreadStatus(class, tso) /* nothing */
#define traceEventStartup_(n_caps) /* nothing */ #define traceEventStartup_(n_caps) /* nothing */
#define traceCapsetModify_(tag, capset, other) /* nothing */
#endif /* TRACING */ #endif /* TRACING */
...@@ -229,6 +250,14 @@ void dtraceUserMsgWrapper(Capability *cap, char *msg); ...@@ -229,6 +250,14 @@ void dtraceUserMsgWrapper(Capability *cap, char *msg);
HASKELLEVENT_GC_WORK(cap) HASKELLEVENT_GC_WORK(cap)
#define dtraceGcDone(cap) \ #define dtraceGcDone(cap) \
HASKELLEVENT_GC_DONE(cap) HASKELLEVENT_GC_DONE(cap)
#define dtraceCapsetCreate(capset, capset_type) \
HASKELLEVENT_CAPSET_CREATE(capset, capset_type)
#define dtraceCapsetDelete(capset) \
HASKELLEVENT_CAPSET_DELETE(capset)
#define dtraceCapsetAssignCap(capset, capno) \
HASKELLEVENT_CAPSET_ASSIGN_CAP(capset, capno)
#define dtraceCapsetRemoveCap(capset, capno) \
HASKELLEVENT_CAPSET_REMOVE_CAP(capset, capno)
#else /* !defined(DTRACE) */ #else /* !defined(DTRACE) */
...@@ -251,6 +280,10 @@ void dtraceUserMsgWrapper(Capability *cap, char *msg); ...@@ -251,6 +280,10 @@ void dtraceUserMsgWrapper(Capability *cap, char *msg);
#define dtraceGcIdle(cap) /* nothing */ #define dtraceGcIdle(cap) /* nothing */
#define dtraceGcWork(cap) /* nothing */ #define dtraceGcWork(cap) /* nothing */
#define dtraceGcDone(cap) /* nothing */ #define dtraceGcDone(cap) /* nothing */
#define dtraceCapsetCreate(capset, capset_type) /* nothing */
#define dtraceCapsetDelete(capset) /* nothing */
#define dtraceCapsetAssignCap(capset, capno) /* nothing */
#define dtraceCapsetRemoveCap(capset, capno) /* nothing */
#endif #endif
...@@ -409,6 +442,33 @@ INLINE_HEADER void traceEventGcDone(Capability *cap STG_UNUSED) ...@@ -409,6 +442,33 @@ INLINE_HEADER void traceEventGcDone(Capability *cap STG_UNUSED)
dtraceGcDone((EventCapNo)cap->no); dtraceGcDone((EventCapNo)cap->no);
} }
INLINE_HEADER void traceCapsetCreate(CapsetID capset STG_UNUSED,
CapsetType capset_type STG_UNUSED)
{
traceCapsetModify_(EVENT_CAPSET_CREATE, capset, capset_type);
dtraceCapsetCreate(capset, capset_type);
}
INLINE_HEADER void traceCapsetDelete(CapsetID capset STG_UNUSED)
{
traceCapsetModify_(EVENT_CAPSET_DELETE, capset, 0);
dtraceCapsetDelete(capset);
}
INLINE_HEADER void traceCapsetAssignCap(CapsetID capset STG_UNUSED,
nat capno STG_UNUSED)
{
traceCapsetModify_(EVENT_CAPSET_ASSIGN_CAP, capset, capno);
dtraceCapsetAssignCap(capset, capno);
}
INLINE_HEADER void traceCapsetRemoveCap(CapsetID capset STG_UNUSED,
nat capno STG_UNUSED)
{
traceCapsetModify_(EVENT_CAPSET_REMOVE_CAP, capset, capno);
dtraceCapsetRemoveCap(capset, capno);
}
#include "EndPrivate.h" #include "EndPrivate.h"
#endif /* TRACE_H */ #endif /* TRACE_H */
...@@ -75,7 +75,11 @@ char *EventDesc[] = { ...@@ -75,7 +75,11 @@ char *EventDesc[] = {
[EVENT_GC_IDLE] = "GC idle", [EVENT_GC_IDLE] = "GC idle",
[EVENT_GC_WORK] = "GC working", [EVENT_GC_WORK] = "GC working",
[EVENT_GC_DONE] = "GC done", [EVENT_GC_DONE] = "GC done",
[EVENT_BLOCK_MARKER] = "Block marker" [EVENT_BLOCK_MARKER] = "Block marker",
[EVENT_CAPSET_CREATE] = "Create capability set",
[EVENT_CAPSET_DELETE] = "Delete capability set",
[EVENT_CAPSET_ASSIGN_CAP] = "Add capability to capability set",
[EVENT_CAPSET_REMOVE_CAP] = "Remove capability from capability set"
}; };
// Event type. // Event type.
...@@ -146,6 +150,12 @@ static inline void postThreadID(EventsBuf *eb, EventThreadID id) ...@@ -146,6 +150,12 @@ static inline void postThreadID(EventsBuf *eb, EventThreadID id)
static inline void postCapNo(EventsBuf *eb, EventCapNo no) static inline void postCapNo(EventsBuf *eb, EventCapNo no)
{ postWord16(eb,no); } { postWord16(eb,no); }
static inline void postCapsetID(EventsBuf *eb, EventCapsetID id)
{ postWord32(eb,id); }
static inline void postCapsetType(EventsBuf *eb, EventCapsetType type)
{ postWord16(eb,type); }
static inline void postPayloadSize(EventsBuf *eb, EventPayloadSize size) static inline void postPayloadSize(EventsBuf *eb, EventPayloadSize size)
{ postWord16(eb,size); } { postWord16(eb,size); }
...@@ -259,6 +269,21 @@ initEventLogging(void) ...@@ -259,6 +269,21 @@ initEventLogging(void)
eventTypes[t].size = sizeof(EventCapNo); eventTypes[t].size = sizeof(EventCapNo);
break; break;
case EVENT_CAPSET_CREATE: // (capset, capset_type)
eventTypes[t].size =
sizeof(EventCapsetID) + sizeof(EventCapsetType);
break;
case EVENT_CAPSET_DELETE: // (capset)
eventTypes[t].size = sizeof(EventCapsetID);
break;
case EVENT_CAPSET_ASSIGN_CAP: // (capset, cap)
case EVENT_CAPSET_REMOVE_CAP:
eventTypes[t].size =
sizeof(EventCapsetID) + sizeof(EventCapNo);
break;
case EVENT_SHUTDOWN: // (cap) case EVENT_SHUTDOWN: // (cap)
case EVENT_REQUEST_SEQ_GC: // (cap) case EVENT_REQUEST_SEQ_GC: // (cap)
case EVENT_REQUEST_PAR_GC: // (cap) case EVENT_REQUEST_PAR_GC: // (cap)
...@@ -439,6 +464,45 @@ postSchedEvent (Capability *cap, ...@@ -439,6 +464,45 @@ postSchedEvent (Capability *cap,
} }
} }
void postCapsetModifyEvent (EventTypeNum tag,
EventCapsetID capset,
StgWord32 other)
{
ACQUIRE_LOCK(&eventBufMutex);
if (!hasRoomForEvent(&eventBuf, tag)) {
// Flush event buffer to make room for new event.
printAndClearEventBuf(&eventBuf);
}
postEventHeader(&eventBuf, tag);
postCapsetID(&eventBuf, capset);
switch (tag) {
case EVENT_CAPSET_CREATE: // (capset, capset_type)
{
postCapsetType(&eventBuf, other /* capset_type */);
break;
}
case EVENT_CAPSET_DELETE: // (capset)
{
break;
}
case EVENT_CAPSET_ASSIGN_CAP: // (capset, capno)
case EVENT_CAPSET_REMOVE_CAP: // (capset, capno)
{
postCapNo(&eventBuf, other /* capno */);
break;
}
default:
barf("postCapsetModifyEvent: unknown event tag %d", tag);
}
RELEASE_LOCK(&eventBufMutex);
}
void void
postEvent (Capability *cap, EventTypeNum tag) postEvent (Capability *cap, EventTypeNum tag)
{ {
......
...@@ -47,6 +47,13 @@ void postCapMsg(Capability *cap, char *msg, va_list ap); ...@@ -47,6 +47,13 @@ void postCapMsg(Capability *cap, char *msg, va_list ap);
void postEventStartup(EventCapNo n_caps); void postEventStartup(EventCapNo n_caps);
/*
* Post a capability set modification event
*/
void postCapsetModifyEvent (EventTypeNum tag,
EventCapsetID capset,
StgWord32 other);
#else /* !TRACING */ #else /* !TRACING */
INLINE_HEADER void postSchedEvent (Capability *cap STG_UNUSED, INLINE_HEADER void postSchedEvent (Capability *cap STG_UNUSED,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment