diff options
author | Duncan Coutts <duncan@well-typed.com> | 2012-07-03 19:18:46 +0100 |
---|---|---|
committer | Mikolaj Konarski <mikolaj@well-typed.com> | 2012-07-07 00:28:19 +0200 |
commit | 647ae1cfbb5ea3e2d3b1541c2bc12ea5db321134 (patch) | |
tree | 9f40458a21ee74661b95ae43c0c61bc5e3a8e08f /includes | |
parent | 01386d383fa535a16ccf6117adaffdd38af703ca (diff) | |
download | haskell-647ae1cfbb5ea3e2d3b1541c2bc12ea5db321134.tar.gz |
New functions to get kernel thread Id + serialisable task Id
On most platforms the userspace thread type (e.g. pthread_t) and kernel
thread id are different. Normally we don't care about kernel thread Ids,
but some system tools for tracing/profiling etc report kernel ids.
For example Solaris and OSX's DTrace and Linux's perf tool report kernel
thread ids. To be able to match these up with RTS's OSThread we need a
way to get at the kernel thread, so we add a new function for to do just
that (the implementation is system-dependent).
Additionally, strictly speaking the OSThreadId type, used as task ids,
is not a serialisable representation. On unix OSThreadId is a typedef for
pthread_t, but pthread_t is not guaranteed to be a numeric type.
Indeed on some systems pthread_t is a pointer and in principle it
could be a structure type. So we add another new function to get a
serialisable representation of an OSThreadId. This is only for use
in log files. We use the function to serialise an id of a task,
with the extra feature that it works in non-threaded builds
by always returning 1.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/rts/OSThreads.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/includes/rts/OSThreads.h b/includes/rts/OSThreads.h index cf72e1de69..260aac15a8 100644 --- a/includes/rts/OSThreads.h +++ b/includes/rts/OSThreads.h @@ -15,7 +15,7 @@ #ifndef RTS_OSTHREADS_H #define RTS_OSTHREADS_H -#if defined(THREADED_RTS) /* to the end */ +#if defined(THREADED_RTS) /* to near the end */ #if defined(HAVE_PTHREAD_H) && !defined(mingw32_HOST_OS) @@ -222,6 +222,29 @@ int forkOS_createThread ( HsStablePtr entry ); // Returns the number of processor cores in the machine // nat getNumberOfProcessors (void); -#endif + +// +// Support for getting at the kernel thread Id for tracing/profiling. +// +// This stuff is optional and only used for tracing/profiling purposes, to +// match up thread ids recorded by other tools. For example, on Linux and OSX +// the pthread_t type is not the same as the kernel thread id, and system +// profiling tools like Linux perf, and OSX's DTrace use the kernel thread Id. +// So if we want to match up RTS tasks with kernel threads recorded by these +// tools then we need to know the kernel thread Id, and this must be a separate +// type from the OSThreadId. +// +// If the feature cannot be supported on an OS, it is OK to always return 0. +// In particular it would almost certaily be meaningless on systems not using +// a 1:1 threading model. + +// We use a common serialisable representation on all OSs +// This is ok for Windows, OSX and Linux. +typedef StgWord64 KernelThreadId; + +// Get the current kernel thread id +KernelThreadId kernelThreadId (void); + +#endif /* CMINUSMINUS */ #endif /* RTS_OSTHREADS_H */ |