Changeset: 2b1939405e38 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/2b1939405e38 Modified Files: cmake/monetdb-defines.cmake gdk/gdk_system.c monetdb5/mal/mal_dataflow.c monetdb_config.h.in Branch: default Log Message:
Merge with Dec2023 branch. diffs (193 lines): diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake --- a/cmake/monetdb-defines.cmake +++ b/cmake/monetdb-defines.cmake @@ -85,6 +85,7 @@ function(monetdb_configure_defines) check_symbol_exists("getopt_long" "getopt.h" HAVE_GETOPT_LONG) cmake_pop_check_state() check_function_exists("getrlimit" HAVE_GETRLIMIT) + check_function_exists("gettid" HAVE_GETTID) check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY) check_function_exists("getuid" HAVE_GETUID) check_symbol_exists("gmtime_r" "time.h" HAVE_GMTIME_R) diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c --- a/gdk/gdk_system.c +++ b/gdk/gdk_system.c @@ -52,6 +52,8 @@ #include "mutils.h" +static ATOMIC_TYPE GDKthreadid = ATOMIC_VAR_INIT(1); + #ifdef LOCK_STATS ATOMIC_TYPE GDKlockcnt = ATOMIC_VAR_INIT(0); @@ -218,6 +220,9 @@ static struct mtthread { HANDLE hdl; DWORD wtid; #endif +#ifdef HAVE_GETTID + pid_t lwptid; +#endif MT_Id tid; uintptr_t sp; char *errbuf; @@ -227,6 +232,7 @@ struct mtthread mainthread = { .threadname = "main thread", .exited = ATOMIC_VAR_INIT(0), .refs = 1, + .tid = 1, }; #ifdef HAVE_PTHREAD_H static pthread_mutex_t posthread_lock = PTHREAD_MUTEX_INITIALIZER; @@ -285,9 +291,22 @@ dump_threads(void) MT_Cond *cn = t->condwait; struct mtthread *jn = t->joinwait; int pos = snprintf(buf, sizeof(buf), - "%s, tid %zu, %"PRIu32" free bats, waiting for %s%s, working on %.200s", + "%s, tid %zu, " +#ifdef HAVE_PTHREAD_H + "Thread 0x%lx, " +#endif +#ifdef HAVE_GETTID + "LWP %ld, " +#endif + "%"PRIu32" free bats, waiting for %s%s, working on %.200s", t->threadname, t->tid, +#ifdef HAVE_PTHREAD_H + (long) t->hdl, +#endif +#ifdef HAVE_GETTID + (long) t->lwptid, +#endif t->freebats.nfreebats, lk ? "lock " : sm ? "semaphore " : cn ? "condvar " : jn ? "thread " : "", lk ? lk->name : sm ? sm->name : cn ? cn->name : jn ? jn->threadname : "nothing", @@ -329,6 +348,9 @@ MT_thread_init(void) { if (thread_initialized) return true; +#ifdef HAVE_GETTID + mainthread.lwptid = gettid(); +#endif #ifdef HAVE_PTHREAD_H int ret; @@ -356,7 +378,6 @@ MT_thread_init(void) } InitializeCriticalSection(&winthread_cs); #endif - mainthread.tid = (MT_Id) &mainthread; mainthread.next = NULL; mtthreads = &mainthread; thread_initialized = true; @@ -365,8 +386,6 @@ MT_thread_init(void) bool MT_thread_register(void) { - MT_Id mtid; - assert(thread_initialized); if (!thread_initialized) return false; @@ -386,7 +405,6 @@ MT_thread_register(void) if (self == NULL) return false; - mtid = (MT_Id) self; *self = (struct mtthread) { .detached = false, #ifdef HAVE_PTHREAD_H @@ -395,7 +413,7 @@ MT_thread_register(void) .wtid = GetCurrentThreadId(), #endif .refs = 1, - .tid = mtid, + .tid = (MT_Id) ATOMIC_INC(&GDKthreadid), .exited = ATOMIC_VAR_INIT(0), }; snprintf(self->threadname, sizeof(self->threadname), "foreign %zu", self->tid); @@ -735,6 +753,9 @@ thread_starter(void *arg) struct mtthread *self = (struct mtthread *) arg; void *data = self->data; +#ifdef HAVE_GETTID + self->lwptid = gettid(); +#endif #ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_SETNAME_NP /* name can be at most 16 chars including \0 */ @@ -848,7 +869,6 @@ int MT_create_thread(MT_Id *t, void (*f) (void *), void *arg, enum MT_thr_detach d, const char *threadname) { struct mtthread *self; - MT_Id mtid; assert(thread_initialized); join_threads(); @@ -882,7 +902,6 @@ MT_create_thread(MT_Id *t, void (*f) (vo #endif return -1; } - mtid = (MT_Id) self; *self = (struct mtthread) { .func = f, @@ -890,7 +909,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo .waiting = false, .detached = (d == MT_THR_DETACHED), .refs = 1, - .tid = mtid, + .tid = (MT_Id) ATOMIC_INC(&GDKthreadid), .exited = ATOMIC_VAR_INIT(0), }; MT_lock_set(&thread_init_lock); @@ -926,7 +945,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo /* overwrite XXXX with thread ID; bottom three bits are * likely 0, so skip those */ char buf[5]; - snprintf(buf, 5, "%04zu", (mtid >> 3) % 9999); + snprintf(buf, 5, "%04zu", self->tid % 9999); memcpy(p, buf, 4); } TRC_DEBUG(THRD, "Create thread \"%s\"\n", self->threadname); @@ -960,7 +979,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo } #endif /* must not fail after this: the thread has been started */ - *t = mtid; + *t = self->tid; thread_lock(); self->next = mtthreads; mtthreads = self; diff --git a/monetdb5/mal/mal_dataflow.c b/monetdb5/mal/mal_dataflow.c --- a/monetdb5/mal/mal_dataflow.c +++ b/monetdb5/mal/mal_dataflow.c @@ -278,7 +278,7 @@ DFLOWworker(void *T) while (1) { MT_thread_set_qry_ctx(NULL); if (fnxt == 0) { - MT_thread_setworking(NULL); + MT_thread_setworking("waiting for work"); cntxt = ATOMIC_PTR_GET(&t->cntxt); fe = q_dequeue(todo, cntxt); if (fe == NULL) { @@ -428,6 +428,7 @@ DFLOWworker(void *T) t->next = free_workers; free_workers = t; MT_lock_unset(&dataflowLock); + MT_thread_setworking("idle, waiting for new client"); MT_sema_down(&t->s); if (GDKexiting() || ATOMIC_GET(&exiting)) break; diff --git a/monetdb_config.h.in b/monetdb_config.h.in --- a/monetdb_config.h.in +++ b/monetdb_config.h.in @@ -122,6 +122,7 @@ #cmakedefine HAVE_DIRENT_H 1 #cmakedefine HAVE_SYS_SOCKET_H 1 +#cmakedefine HAVE_GETTID 1 #cmakedefine HAVE_GETTIMEOFDAY 1 #cmakedefine HAVE_SYS_STAT_H 1 #cmakedefine HAVE_FDATASYNC 1 _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org