Changeset: 4eccf63aa8d6 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/4eccf63aa8d6 Modified Files: cmake/monetdb-defines.cmake gdk/gdk_bbp.c gdk/gdk_logger.c gdk/gdk_system.c gdk/gdk_system.h monetdb_config.h.in sql/backends/monet5/sql_scenario.c sql/storage/store.c Branch: Aug2024 Log Message:
Merge with Dec2023 branch. diffs (250 lines): diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake --- a/cmake/monetdb-defines.cmake +++ b/cmake/monetdb-defines.cmake @@ -111,6 +111,7 @@ function(monetdb_configure_defines) cmake_push_check_state() set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") check_function_exists("pthread_kill" HAVE_PTHREAD_KILL) + check_function_exists("pthread_mutex_timedlock" HAVE_PTHREAD_MUTEX_TIMEDLOCK) check_function_exists("pthread_setname_np" HAVE_PTHREAD_SETNAME_NP) check_function_exists("pthread_sigmask" HAVE_PTHREAD_SIGMASK) cmake_pop_check_state() diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -4863,6 +4863,15 @@ BBPtmlock(void) BBPtmlockFinish(); } +static bool +BBPtrytmlock(int ms) +{ + if (!MT_lock_trytime(&GDKtmLock, ms)) + return false; + BBPtmlockFinish(); + return true; +} + void BBPtmunlock(void) { @@ -4885,28 +4894,40 @@ BBPprintinfo(void) int nr; } bats[2][2][2][2][2] = {0}; int nbats = 0; - - BBPtmlock(); + int nskip = 0; + + if (!BBPtrytmlock(1000)) { + printf("BBP is currently locked, so no BAT information\n"); + return; + } bat sz = (bat) ATOMIC_GET(&BBPsize); for (bat i = 1; i < sz; i++) { - MT_lock_set(&GDKswapLock(i)); + if (!MT_lock_trytime(&GDKswapLock(i), 1000)) { + nskip++; + continue; + } int r; if ((r = BBP_refs(i)) > 0 || BBP_lrefs(i) > 0) { BAT *b = BBP_desc(i); - nbats++; - MT_lock_set(&b->theaplock); - ATOMIC_BASE_TYPE status = BBP_status(i); - struct counters *bt = &bats[r > 0][BATdirty(b)][(status & BBPPERSISTENT) != 0][(status & BBPLOADED) != 0][(status & BBPHOT) != 0]; - bt->nr++; - if (b->theap && b->batCacheid == b->theap->parentid) { - bt->sz += HEAPmemsize(b->theap); - bt->vmsz += HEAPvmsize(b->theap); + if (!MT_lock_trytime(&b->theaplock, 1000)) { + nskip++; + b = NULL; } - if (b->tvheap && b->batCacheid == b->tvheap->parentid) { - bt->sz += HEAPmemsize(b->tvheap); - bt->vmsz += HEAPvmsize(b->tvheap); + if (b != NULL) { + nbats++; + ATOMIC_BASE_TYPE status = BBP_status(i); + struct counters *bt = &bats[r > 0][BATdirty(b)][(status & BBPPERSISTENT) != 0][(status & BBPLOADED) != 0][(status & BBPHOT) != 0]; + bt->nr++; + if (b->theap && b->batCacheid == b->theap->parentid) { + bt->sz += HEAPmemsize(b->theap); + bt->vmsz += HEAPvmsize(b->theap); + } + if (b->tvheap && b->batCacheid == b->tvheap->parentid) { + bt->sz += HEAPmemsize(b->tvheap); + bt->vmsz += HEAPvmsize(b->tvheap); + } + MT_lock_unset(&b->theaplock); } - MT_lock_unset(&b->theaplock); } MT_lock_unset(&GDKswapLock(i)); } @@ -4980,4 +5001,6 @@ BBPprintinfo(void) printf("%d bats total, %d in use, %"PRIu32" free bats in common shared list\n", sz - 1, nbats, nfree); + if (nskip > 0) + printf("%d bat slots unaccounted for because of locking\n", nskip); } diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c --- a/gdk/gdk_logger.c +++ b/gdk/gdk_logger.c @@ -1115,6 +1115,7 @@ log_create_types_file(logger *lg, const #define rotation_lock(lg) MT_lock_set(&(lg)->rotation_lock) #define rotation_unlock(lg) MT_lock_unset(&(lg)->rotation_lock) +#define rotation_trylock(lg, ms) MT_lock_trytime(&(lg)->rotation_lock, ms) static gdk_return log_open_output(logger *lg) @@ -3502,8 +3503,11 @@ log_tstart(logger *lg, bool flushnow, ul void log_printinfo(logger *lg) { + if (!rotation_trylock(lg, 1000)) { + printf("Logger is currently locked, so no logger information\n"); + return; + } printf("logger %s:\n", lg->fn); - rotation_lock(lg); printf("current log file "ULLFMT", last handled log file "ULLFMT"\n", lg->id, lg->saved_id); printf("current transaction id %d, saved transaction id %d\n", diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c --- a/gdk/gdk_system.c +++ b/gdk/gdk_system.c @@ -239,6 +239,7 @@ struct mtthread mainthread = { static pthread_mutex_t posthread_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_key_t threadkey; #define thread_lock() pthread_mutex_lock(&posthread_lock) +#define thread_lock_try() (pthread_mutex_trylock(&posthread_lock) == 0) #define thread_unlock() pthread_mutex_unlock(&posthread_lock) #define thread_self() pthread_getspecific(threadkey) #define thread_setself(self) pthread_setspecific(threadkey, self) @@ -246,6 +247,7 @@ static pthread_key_t threadkey; static CRITICAL_SECTION winthread_cs; static DWORD threadkey = TLS_OUT_OF_INDEXES; #define thread_lock() EnterCriticalSection(&winthread_cs) +#define thread_lock_try() (TryEnterCriticalSection(&winthread_cs) != 0) #define thread_unlock() LeaveCriticalSection(&winthread_cs) #define thread_self() TlsGetValue(threadkey) #define thread_setself(self) TlsSetValue(threadkey, self) @@ -290,7 +292,23 @@ void dump_threads(void) { char buf[1024]; - thread_lock(); +#if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) && defined(HAVE_CLOCK_GETTIME) + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec++; /* give it a second */ + if (pthread_mutex_timedlock(&posthread_lock, &ts) != 0) { + printf("Threads are currently locked, so no thread information\n"); + return; + } +#else + if (!thread_lock_try()) { + MT_sleep_ms(1000); + if (!thread_lock_try()) { + printf("Threads are currently locked, so no thread information\n"); + return; + } + } +#endif if (!GDK_TRACER_TEST(M_DEBUG, THRD)) printf("Threads:\n"); for (struct mtthread *t = mtthreads; t; t = t->next) { diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h --- a/gdk/gdk_system.h +++ b/gdk/gdk_system.h @@ -494,6 +494,24 @@ typedef struct MT_Lock { #define MT_lock_try(l) (pthread_mutex_trylock(&(l)->lock) == 0 && (_DBG_LOCK_LOCKER(l), true)) +#if defined(__GNUC__) && defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) && defined(HAVE_CLOCK_GETTIME) +#define MT_lock_trytime(l, ms) \ + ({ \ + struct timespec ts; \ + clock_gettime(CLOCK_REALTIME, &ts); \ + ts.tv_nsec += (ms % 1000) * 1000000; \ + if (ts.tv_nsec >= 1000000000) { \ + ts.tv_nsec -= 1000000000; \ + ts.tv_sec++; \ + } \ + ts.tv_sec += (ms / 1000); \ + int ret = pthread_mutex_timedlock(&(l)->lock, &ts); \ + if (ret == 0) \ + _DBG_LOCK_LOCKER(l); \ + ret == 0; \ + }) +#endif + #define MT_lock_set(l) \ do { \ _DBG_LOCK_COUNT_0(l); \ @@ -506,6 +524,7 @@ typedef struct MT_Lock { _DBG_LOCK_LOCKER(l); \ _DBG_LOCK_COUNT_2(l); \ } while (0) + #define MT_lock_unset(l) \ do { \ _DBG_LOCK_UNLOCKER(l); \ @@ -622,6 +641,11 @@ typedef pthread_key_t MT_TLS_t; #endif +#ifndef MT_lock_trytime +/* simplistic way to try lock with timeout: just sleep */ +#define MT_lock_trytime(l, ms) (MT_lock_try(l) || (MT_sleep_ms(ms), MT_lock_try(l))) +#endif + gdk_export gdk_return MT_alloc_tls(MT_TLS_t *newkey); gdk_export void MT_tls_set(MT_TLS_t key, void *val); gdk_export void *MT_tls_get(MT_TLS_t key); diff --git a/monetdb_config.h.in b/monetdb_config.h.in --- a/monetdb_config.h.in +++ b/monetdb_config.h.in @@ -163,6 +163,7 @@ #cmakedefine HAVE_TM_GMTOFF 1 #cmakedefine HAVE_UNAME 1 #cmakedefine HAVE_PTHREAD_KILL 1 +#cmakedefine HAVE_PTHREAD_MUTEX_TIMEDLOCK 1 #cmakedefine HAVE_PTHREAD_SETNAME_NP 1 #cmakedefine HAVE_PTHREAD_SIGMASK 1 #cmakedefine HAVE_GETOPT 1 diff --git a/sql/backends/monet5/sql_scenario.c b/sql/backends/monet5/sql_scenario.c --- a/sql/backends/monet5/sql_scenario.c +++ b/sql/backends/monet5/sql_scenario.c @@ -104,7 +104,10 @@ CLIENTprintinfo(void) char cpbuf[64]; struct tm tm; - MT_lock_set(&mal_contextLock); + if (!MT_lock_trytime(&mal_contextLock, 1000)) { + printf("Clients are currently locked, so no client information\n"); + return; + } printf("Clients:\n"); for (Client c = mal_clients; c < mal_clients + MAL_MAXCLIENTS; c++) { switch (c->mode) { diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -7494,7 +7494,10 @@ sql_trans_convert_partitions(sql_trans * void store_printinfo(sqlstore *store) { - MT_lock_set(&store->commit); + if (!MT_lock_trytime(&store->commit, 1000)) { + printf("WAL is currently locked, so no WAL information\n"); + return; + } printf("WAL:\n"); printf("SQL store oldest pending "ULLFMT"\n", store->oldest_pending); log_printinfo(store->logger); _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org