Changeset: fc00ecc1e42f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/fc00ecc1e42f Modified Files: gdk/gdk.h monetdb5/mal/mal_runtime.c monetdb5/modules/mal/bbp.c monetdb5/modules/mal/mal_mapi.c monetdb5/modules/mal/remote.c monetdb5/optimizer/opt_mergetable.c monetdb5/optimizer/opt_remap.c sql/backends/monet5/sql.c Branch: no_type_bat Log Message:
merged with default diffs (truncated from 877 to 300 lines): diff --git a/clients/Tests/MAL-signatures-hge.test b/clients/Tests/MAL-signatures-hge.test --- a/clients/Tests/MAL-signatures-hge.test +++ b/clients/Tests/MAL-signatures-hge.test @@ -30330,11 +30330,6 @@ nil_2time_timestamp; cast to timestamp and check for overflow batcalc timestamp -pattern batcalc.timestamp(X_0:bat[:oid], X_1:int, X_2:bat[:BAT]):bat[:timestamp] -nil_2time_timestamp; -cast to timestamp and check for overflow -batcalc -timestamp pattern batcalc.timestamp(X_0:bat[:timestamp], X_1:bat[:oid], X_2:int):bat[:timestamp] timestamp_2time_timestamp; cast timestamp to timestamp and check for overflow diff --git a/clients/Tests/MAL-signatures.test b/clients/Tests/MAL-signatures.test --- a/clients/Tests/MAL-signatures.test +++ b/clients/Tests/MAL-signatures.test @@ -21555,11 +21555,6 @@ nil_2time_timestamp; cast to timestamp and check for overflow batcalc timestamp -pattern batcalc.timestamp(X_0:bat[:oid], X_1:int, X_2:bat[:BAT]):bat[:timestamp] -nil_2time_timestamp; -cast to timestamp and check for overflow -batcalc -timestamp pattern batcalc.timestamp(X_0:bat[:timestamp], X_1:bat[:oid], X_2:int):bat[:timestamp] timestamp_2time_timestamp; cast timestamp to timestamp and check for overflow diff --git a/gdk/ChangeLog b/gdk/ChangeLog --- a/gdk/ChangeLog +++ b/gdk/ChangeLog @@ -1,6 +1,11 @@ # ChangeLog file for GDK # This file is updated with Maddlog +* Thu Nov 2 2023 Sjoerd Mullender <sjo...@acm.org> +- Removed the compiled-in limit on the number of threads that can be used. + The number of threads are still limited, but the limit is dictated + solely by the operating system and the availability of enough memory. + * Thu Sep 28 2023 Sjoerd Mullender <sjo...@acm.org> - We now prevent accidental upgrades from a database without 128 bit integers to one with 128 bit integers (also known as HUGEINT) from diff --git a/gdk/gdk.h b/gdk/gdk.h --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -1971,18 +1971,7 @@ VALptr(const ValRecord *v) } } -/* - * The kernel maintains a central table of all active threads. They - * are indexed by their tid. The structure contains information on the - * input/output file descriptors, which should be set before a - * database operation is started. It ensures that output is delivered - * to the proper client. - * - * The Thread structure should be ideally made directly accessible to - * each thread. This speeds up access to tid and file descriptors. - */ -#define THREADS 1024 -#define THREADDATA 3 +#define THREADS 1024 /* maximum value for gdk_nr_threads */ typedef struct threadStruct *Thread; diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c --- a/gdk/gdk_logger.c +++ b/gdk/gdk_logger.c @@ -2773,8 +2773,7 @@ internal_log_bat(logger *lg, BAT *b, log if (b->ttype == TYPE_msk) { BATiter bi = bat_iterator(b); if (offset % 32 == 0) { - if (!mnstr_writeIntArray - (lg->current->output_log, (int *) ((char *) bi.base + offset / 32), + if (!mnstr_writeIntArray(lg->current->output_log, (int *) ((char *) bi.base + offset / 32), (size_t) ((nr + 31) / 32))) ok = GDK_FAIL; } else { diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c --- a/gdk/gdk_system.c +++ b/gdk/gdk_system.c @@ -262,36 +262,6 @@ THRhighwater(void) return false; } -static uint32_t allocated[THREADS / 32]; -static MT_Lock alloclock = MT_LOCK_INITIALIZER(alloclock); - -static MT_Id -alloc_thread(void) -{ - MT_Id mtid = 0; - MT_lock_set(&alloclock); - for (int i = 0; i < THREADS / 32; i++) { - if (allocated[i] != ~UINT32_C(0)) { - int x = candmask_lobit(~allocated[i]); - allocated[i] |= UINT32_C(1) << x; - mtid = (MT_Id) (i * 32 + x + 1); - break; - } - } - MT_lock_unset(&alloclock); - return mtid; -} - -static void -dealloc_thread(MT_Id mtid) -{ - assert(mtid > 0 && mtid <= THREADS); - mtid--; - MT_lock_set(&alloclock); - allocated[mtid / 32] &= ~(UINT32_C(1) << (mtid % 32)); - MT_lock_unset(&alloclock); -} - void dump_threads(void) { @@ -329,7 +299,6 @@ static void rm_mtthread(struct mtthread *t) { struct mtthread **pt; - MT_Id mtid = t->tid; assert(t != &mainthread); thread_lock(); @@ -340,7 +309,6 @@ rm_mtthread(struct mtthread *t) ATOMIC_DESTROY(&t->exited); free(t); thread_unlock(); - dealloc_thread(mtid); } bool @@ -375,8 +343,7 @@ MT_thread_init(void) } InitializeCriticalSection(&winthread_cs); #endif - allocated[0] = 1; - mainthread.tid = 1; + mainthread.tid = (MT_Id) &mainthread; mainthread.next = NULL; mtthreads = &mainthread; thread_initialized = true; @@ -406,11 +373,7 @@ MT_thread_register(void) if (self == NULL) return false; - if ((mtid = alloc_thread()) == 0) { - TRC_DEBUG(IO_, "Too many threads\n"); - GDKerror("too many threads\n"); - return false; - } + mtid = (MT_Id) self; *self = (struct mtthread) { .detached = false, #ifdef HAVE_PTHREAD_H @@ -824,24 +787,17 @@ MT_create_thread(MT_Id *t, void (*f) (vo TRC_CRITICAL(GDK, "Thread's name is too large\n"); return -1; } - if ((mtid = alloc_thread()) == 0) { - TRC_DEBUG(IO_, "Too many threads\n"); - GDKerror("too many threads\n"); - return -1; - } #ifdef HAVE_PTHREAD_H pthread_attr_t attr; int ret; if ((ret = pthread_attr_init(&attr)) != 0) { GDKsyserr(ret, "Cannot init pthread attr"); - dealloc_thread(mtid); return -1; } if ((ret = pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE)) != 0) { GDKsyserr(ret, "Cannot set stack size"); pthread_attr_destroy(&attr); - dealloc_thread(mtid); return -1; } #endif @@ -851,9 +807,9 @@ MT_create_thread(MT_Id *t, void (*f) (vo #ifdef HAVE_PTHREAD_H pthread_attr_destroy(&attr); #endif - dealloc_thread(mtid); return -1; } + mtid = (MT_Id) self; *self = (struct mtthread) { .func = f, @@ -867,9 +823,10 @@ MT_create_thread(MT_Id *t, void (*f) (vo strcpy_len(self->threadname, threadname, sizeof(self->threadname)); char *p; if ((p = strstr(self->threadname, "XXXX")) != NULL) { - /* overwrite XXXX with thread ID */ + /* overwrite XXXX with thread ID; bottom three bits are + * likely 0, so skip those */ char buf[5]; - snprintf(buf, 5, "%04zu", mtid % 9999); + snprintf(buf, 5, "%04zu", (mtid >> 3) % 9999); memcpy(p, buf, 4); } TRC_DEBUG(THRD, "Create thread \"%s\"\n", self->threadname); @@ -889,7 +846,6 @@ MT_create_thread(MT_Id *t, void (*f) (vo if (ret != 0) { GDKsyserr(ret, "Cannot start thread"); free(self); - dealloc_thread(mtid); return -1; } #else @@ -898,7 +854,6 @@ MT_create_thread(MT_Id *t, void (*f) (vo if (self->hdl == NULL) { GDKwinerror("Failed to create thread"); free(self); - dealloc_thread(mtid); return -1; } #endif @@ -914,13 +869,13 @@ MT_create_thread(MT_Id *t, void (*f) (vo MT_Id MT_getpid(void) { - if (!thread_initialized) - return 0; - struct mtthread *self; - self = thread_self(); - return self ? self->tid : 0; + if (!thread_initialized) + self = &mainthread; + else + self = thread_self(); + return self->tid; } void diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c --- a/monetdb5/mal/mal_profiler.c +++ b/monetdb5/mal/mal_profiler.c @@ -418,9 +418,8 @@ prepareMalEvent(Client cntxt, MalBlkPtr goto cleanup_and_exit; } } else { - if (!logadd - (&logbuf, ",\"mode\":\"%s\"", - (di.transient ? "transient" : "persistent"))) { + if (!logadd(&logbuf, ",\"mode\":\"%s\"", + (di.transient ? "transient" : "persistent"))) { BBPunfix(d->batCacheid); goto cleanup_and_exit; } @@ -514,8 +513,7 @@ prepareMalEvent(Client cntxt, MalBlkPtr if (!ok) goto cleanup_and_exit; } - if (!logadd - (&logbuf, ",\"eol\":%d", getVarEolife(mb, getArg(pci, j)))) + if (!logadd(&logbuf, ",\"eol\":%d", getVarEolife(mb, getArg(pci, j)))) goto cleanup_and_exit; // if (!logadd(&logbuf, ",\"fixed\":%d", isVarFixed(mb,getArg(pci,j)))) return NULL; if (!logadd(&logbuf, "}")) @@ -721,8 +719,6 @@ profilerEvent(MalEvent *me, NonMalEvent str openProfilerStream(Client cntxt, int m) { - int j; - #ifdef HAVE_SYS_RESOURCE_H getrusage(RUSAGE_SELF, &infoUsage); prevUsage = infoUsage; @@ -759,29 +755,6 @@ openProfilerStream(Client cntxt, int m) maleventstream = cntxt->fdout; profilerUser = cntxt->user; - // Ignore the JSON rendering mode, use compiled time version - - /* show all in progress instructions for stethoscope startup */ - /* wait a short time for instructions to finish updating their thread admin - * and then follow the locking scheme */ - - MT_sleep_ms(200); - - for (j = 0; j < THREADS; j++) { - struct MalEvent me = { - .cntxt = workingset[j].cntxt, - .mb = workingset[j].mb, - .stk = workingset[j].stk, - .pci = workingset[j].pci, - .clk = workingset[j].clock, - }; - if (me.cntxt && me.mb && me.stk && me.pci) { - /* show the event assuming the quintuple is aligned */ _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org