From d07b8c7ae8bc22a7c36c96cb3fd800aecdde6eac Mon Sep 17 00:00:00 2001 From: Echo Nolan Date: Mon, 25 Sep 2017 18:33:30 -0400 Subject: Include original process name in worker thread name (#14153) Prior to this commit, worker OS thread were renamed to "ghc_worker" when spawned. This was annoying when reading debugging messages that print the process name because it doesn't tell you *which* Haskell program is generating the message. This commit changes it to "original_process_name:w", truncating the original name to fit in the kernel buffer if neccesary. Test Plan: ./validate Reviewers: austin, bgamari, erikd, simonmar Reviewed By: bgamari Subscribers: Phyx, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D4001 --- rts/Task.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'rts/Task.c') diff --git a/rts/Task.c b/rts/Task.c index 4376148c7a..fc928d5e31 100644 --- a/rts/Task.c +++ b/rts/Task.c @@ -19,6 +19,8 @@ #include "Hash.h" #include "Trace.h" +#include + #if HAVE_SIGNAL_H #include #endif @@ -468,7 +470,26 @@ startWorkerTask (Capability *cap) ASSERT_LOCK_HELD(&cap->lock); cap->running_task = task; - r = createOSThread(&tid, "ghc_worker", (OSThreadProc*)workerStart, task); + // Set the name of the worker thread to the original process name followed by + // ":w", but only if we're on Linux where the program_invocation_short_name + // global is available. +#if defined(linux_HOST_OS) + size_t procname_len = strlen(program_invocation_short_name); + char worker_name[16]; + // The kernel only allocates 16 bytes for thread names, so we truncate if the + // original name is too long. Process names go in another table that has more + // capacity. + if (procname_len >= 13) { + strncpy(worker_name, program_invocation_short_name, 13); + strcpy(worker_name + 13, ":w"); + } else { + strcpy(worker_name, program_invocation_short_name); + strcpy(worker_name + procname_len, ":w"); + } +#else + char * worker_name = "ghc_worker"; +#endif + r = createOSThread(&tid, worker_name, (OSThreadProc*)workerStart, task); if (r != 0) { sysErrorBelch("failed to create OS thread"); stg_exit(EXIT_FAILURE); -- cgit v1.2.1 From 8dab89b4d148d322cd7ac8c374be3342ab017297 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Fri, 2 Mar 2018 11:13:14 -0500 Subject: rts: Note functions which must take all_tasks_mutex. --- rts/Task.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rts/Task.c') diff --git a/rts/Task.c b/rts/Task.c index fc928d5e31..758ae10ffc 100644 --- a/rts/Task.c +++ b/rts/Task.c @@ -199,6 +199,7 @@ freeTask (Task *task) stgFree(task); } +/* Must take all_tasks_mutex */ static Task* newTask (bool worker) { @@ -443,6 +444,7 @@ workerStart(Task *task) scheduleWorker(cap,task); } +/* N.B. must take all_tasks_mutex */ void startWorkerTask (Capability *cap) { -- cgit v1.2.1 From eb39f98891482366cf1130fe58d728b93f0dd49f Mon Sep 17 00:00:00 2001 From: Michal Terepeta Date: Sun, 13 May 2018 18:34:03 -0400 Subject: Fix a few GCC warnings GCC 8 now generates warnings for incompatible function pointer casts [-Werror=cast-function-type]. Apparently there are a few of those in rts code, which makes `./validate` unhappy (since we compile with `-Werror`) This commit tries to fix these issues by changing the functions to have the correct type (and, if necessary, moving the casts into those functions). For instance, hash/comparison function are declared (`Hash.h`) to take `StgWord` but we want to use `StgWord64[2]` in `StaticPtrTable.c`. Instead of casting the function pointers, we can cast the `StgWord` parameter to `StgWord*`. I think this should be ok since `StgWord` should be the same size as a pointer. Signed-off-by: Michal Terepeta Test Plan: ./validate Reviewers: bgamari, erikd, simonmar Reviewed By: bgamari Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4673 --- rts/Task.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'rts/Task.c') diff --git a/rts/Task.c b/rts/Task.c index 758ae10ffc..ac86311844 100644 --- a/rts/Task.c +++ b/rts/Task.c @@ -416,7 +416,7 @@ workerTaskStop (Task *task) #if defined(THREADED_RTS) -static void OSThreadProcAttr +static void* OSThreadProcAttr workerStart(Task *task) { Capability *cap; @@ -442,6 +442,8 @@ workerStart(Task *task) traceTaskCreate(task, cap); scheduleWorker(cap,task); + + return NULL; } /* N.B. must take all_tasks_mutex */ -- cgit v1.2.1