Changeset: 9ba65893fd6a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9ba65893fd6a
Modified Files:
clients/Tests/exports.stable.out
monetdb5/mal/mal_pipelines.c
monetdb5/mal/mal_pipelines.h
monetdb5/modules/mal/pipeline.c
monetdb5/modules/mal/pipeline.h
sql/backends/monet5/copy.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_statement.c
sql/backends/monet5/vaults/parquet/pqc_filemetadata.c
sql/backends/monet5/vaults/parquet/pqc_filemetadata.h
Branch: pp_hashjoin
Log Message:
reimplemented synchronisation, ie always use condition variables now
diffs (truncated from 455 to 300 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -900,8 +900,6 @@ const char copy_fromRef[];
const char corrRef[];
const char countRef[];
const char count_no_nilRef[];
-void counter_next(Sink *s);
-void counter_wait(Sink *s, int nr, Pipeline *p);
int cpyConstant(MalBlkPtr mb, VarPtr vr);
str createException(enum malexception, const char *, _In_z_
_Printf_format_string_ const char *, ...) __attribute__((__malloc__))
__attribute__((__format__(__printf__, 3, 4)))
__attribute__((__returns_nonnull__));
str createMalException(MalBlkPtr, int, enum malexception, _In_z_
_Printf_format_string_ const char *, ...) __attribute__((__malloc__))
__attribute__((__format__(__printf__, 4, 5)))
__attribute__((__returns_nonnull__));
@@ -1154,6 +1152,8 @@ const char packRef[];
const char parametersRef[];
const char passRef[];
const char percent_rankRef[];
+int pipeline_get_token(Pipeline *p, int channel, int id, bool *done);
+int pipeline_pass_token(Pipeline *p, int channel, int id);
const char pipelinesRef[];
const char plusRef[];
const char predicateRef[];
diff --git a/monetdb5/mal/mal_pipelines.c b/monetdb5/mal/mal_pipelines.c
--- a/monetdb5/mal/mal_pipelines.c
+++ b/monetdb5/mal/mal_pipelines.c
@@ -182,16 +182,6 @@ thread_runoncpu(int cpu)
}
#endif
-static int
-PIPELINEnext_counter(Pipeline *p)
-{
- MT_lock_set(&p->p->l);
- int n = (int) p->p->master_counter++;
- //p->p->counters[p->wid] = n;
- MT_lock_unset(&p->p->l);
- return n;
-}
-
static void
PIPELINEworker(void *T)
{
@@ -222,15 +212,15 @@ PIPELINEworker(void *T)
*p = (Pipeline) {
.p = s,
.wid = (int) ATOMIC_INC(&s->workers),
+ .tseqnr = 0,
.seqnr = -1,
.wls = NULL,
};
MT_thread_setdata(p);
- stk->stk[s->mb->stmt[s->start]->argv[1]].val.ival =
PIPELINEnext_counter(p);
+ stk->stk[s->mb->stmt[s->start]->argv[1]].val.ival = -1;
stk->stk[s->mb->stmt[s->start]->argv[2]].val.pval = p;
/* the maxparts (arg 3) is generated ie constant value
on the stack */
str error = runMALsequence(s->cntxt, s->mb, s->start+1,
s->stop, stk, 0, 0);
- //PIPELINEclear_counter(p);
if (error) {
MT_lock_set(&p->p->l);
/* only collect one error (from one thread,
needed for stable testing) */
@@ -273,7 +263,7 @@ PIPELINESinitialize(void)
workers[i].q = q_create(256, name);
if (first) /* only initialize once
*/
ATOMIC_PTR_INIT(&workers[i].cntxt, NULL);
- snprintf(name, sizeof(name), "PIPELINEworker%d", i);
+ snprintf(name, sizeof(name), "PPworker%d", i);
if (MT_create_thread(&workers[i].id, PIPELINEworker, (void *)
&workers[i], MT_THR_JOINABLE, name) < 0) {
workers[i].flag = IDLE;
} else {
@@ -322,8 +312,8 @@ runMALpipelines(Client cntxt, MalBlkPtr
snprintf(name, sizeof(name), "PIPELINE%d", cntxt->idx);
MT_sema_init(&s->s, 0, name);
MT_lock_init(&s->l, name);
- //for (size_t i = 0; i < sizeof(s->counters) / sizeof(s->counters[0]);
i++)
- //s->counters[i] = -1;
+ for(int i = 0; i<8; i++) /* pass any token to the first worker */
+ s->channel[i] = 0;
MT_cond_init(&s->cond, "pipeline-workers");
/* somehow get number of workers from statement/barrier */
for (int i = 0; i < s->nr_workers; i++)
@@ -395,12 +385,22 @@ stopMALpipelines(void)
MT_lock_unset(&pipelineLock);
}
-/*
-static void
-PIPELINEclear_counter(Pipeline *p)
+int
+pipeline_pass_token(Pipeline *p, int channel, int id)
{
MT_lock_set(&p->p->l);
- p->p->counters[p->wid] = -1;
+ p->p->channel[channel] = (id+1) % p->p->nr_workers;
+ MT_cond_broadcast(&p->p->cond); /* deblock all workers */
MT_lock_unset(&p->p->l);
+ return p->p->error?-1:0;
}
-*/
+
+int
+pipeline_get_token(Pipeline *p, int channel, int id, bool *done)
+{
+ MT_lock_set(&p->p->l);
+ while (p->p->channel[channel] != (id % p->p->nr_workers) &&
!p->p->error && !(*done))
+ MT_cond_wait(&p->p->cond, &p->p->l);
+ MT_lock_unset(&p->p->l);
+ return p->p->error?-1:0;
+}
diff --git a/monetdb5/mal/mal_pipelines.h b/monetdb5/mal/mal_pipelines.h
--- a/monetdb5/mal/mal_pipelines.h
+++ b/monetdb5/mal/mal_pipelines.h
@@ -26,9 +26,10 @@ typedef struct Pipelines {
MT_Cond cond; /* condition variable for full worker synchronisation
and worker execution order */
int maxparts;
int nr_workers;
+ int seqnr;
ATOMIC_TYPE workers;
ATOMIC_TYPE master_counter;
- //int counters[THREADS];
+ int channel[8]; /* sinks use 8, 7 etc, sources 0, 1 etc */
int status;
bat sink;
} Pipelines;
@@ -36,6 +37,7 @@ typedef struct Pipelines {
typedef struct Pipeline {
Pipelines *p; /* the shared pipelines */
int wid; /* worker id [ 0 .. nr_workers ] */
+ int tseqnr; /* multi sources pipelines aggregated seqnr (for
previous sources) */
int seqnr; /* needed to keep things align/ordered */
void *wls; /* worker local storage */
} Pipeline;
@@ -43,5 +45,10 @@ typedef struct Pipeline {
mal_export str runMALpipelines(Client cntxt, MalBlkPtr mb, int startpc, int
stoppc, int maxparts, bat sink, MalStkPtr stk);
//mal_export int PIPELINEnext_counter(Pipeline *p);
//mal_export void PIPELINEclear_counter(Pipeline *p);
+//
+
+mal_export int pipeline_pass_token(Pipeline *p, int channel, int id); /* pass
the token to the worker id+1 */
+mal_export int pipeline_get_token(Pipeline *p, int channel, int id, bool
*done); /* wait for token addressed to id, done flag could change and
+
ends
waiting */
#endif /* _MAL_PIPELINES_H*/
diff --git a/monetdb5/modules/mal/pipeline.c b/monetdb5/modules/mal/pipeline.c
--- a/monetdb5/modules/mal/pipeline.c
+++ b/monetdb5/modules/mal/pipeline.c
@@ -147,13 +147,16 @@ sync_counter_done(pp_counter *c, int wid
if (!c->cur)
c->cur = (int*)GDKzalloc(sizeof(int) * nr_workers);
cur = c->current++;
- if (cur >= c->nr)
+ if (cur >= c->nr) {
res = 1;
+ p->tseqnr += c->nr;
+ }
if (res && c->scnt != nr_workers && !p->p->error) {
c->scnt++;
- if (c->scnt != nr_workers)
- MT_cond_wait(&p->p->cond, &p->p->l);
- else
+ if (c->scnt != nr_workers) {
+ while (c->scnt != p->p->nr_workers && !p->p->error)
+ MT_cond_wait(&p->p->cond, &p->p->l);
+ } else
MT_cond_broadcast(&p->p->cond);
assert(c->scnt == nr_workers || p->p->error);
}
@@ -174,8 +177,11 @@ counter_done(pp_counter *c, int wid, int
if (!c->cur)
c->cur = (int*)GDKzalloc(sizeof(int) * nr_workers);
cur = c->current++;
- if (cur >= c->nr)
+ if (cur >= c->nr) {
res = 1;
+ Pipeline *p = MT_thread_getdata();
+ p->tseqnr += c->nr;
+ }
MT_lock_unset(&c->l);
assert(c->cur);
c->cur[wid] = cur;
@@ -208,17 +214,22 @@ PPcounter_get(Client cntxt, MalBlkPtr mb
MT_lock_set(&p->p->l);
if (c->scnt != (int)p->p->nr_workers) {
c->scnt++;
- if (c->scnt != p->p->nr_workers)
- MT_cond_wait(&p->p->cond, &p->p->l);
- else
+ if (c->scnt != p->p->nr_workers) {
+ while (c->scnt != p->p->nr_workers &&
!p->p->error)
+ MT_cond_wait(&p->p->cond, &p->p->l);
+ } else
MT_cond_broadcast(&p->p->cond);
}
- assert(c->scnt == (int)p->p->nr_workers);
+ assert(p->p->error || c->scnt == (int)p->p->nr_workers);
MT_lock_unset(&p->p->l);
}
if (!c->cur)
c->s.done(c, p->wid, p->p->nr_workers, false);
*cur = c->cur[p->wid];
+ if (*cur >= c->nr)
+ p->seqnr = -2;
+ else
+ p->seqnr = p->tseqnr + *cur;
BBPunfix(b->batCacheid);
return MAL_SUCCEED;
}
@@ -291,27 +302,6 @@ PPcounter(Client cntxt, MalBlkPtr mb, Ma
return MAL_SUCCEED;
}
-void
-counter_wait(Sink *s, int nr, Pipeline *p)
-{
- pp_counter *c = (pp_counter*)s;
- assert(s->type == COUNTER_SINK);
-
- while (c->current < nr && !ATOMIC_PTR_GET(&p->p->error))
- sleep_ns(10);
-}
-
-void
-counter_next(Sink *s)
-{
- pp_counter *c = (pp_counter*)s;
- assert(s->type == COUNTER_SINK);
-
- MT_lock_set(&c->l);
- c->current++;
- MT_lock_unset(&c->l);
-}
-
static str
PPdone(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
diff --git a/monetdb5/modules/mal/pipeline.h b/monetdb5/modules/mal/pipeline.h
--- a/monetdb5/modules/mal/pipeline.h
+++ b/monetdb5/modules/mal/pipeline.h
@@ -33,7 +33,4 @@
extern int BATupgrade(BAT *r, BAT *b, bool locked);
extern void BATswap_heaps(BAT *u, BAT *b, Pipeline *p);
-mal_export void counter_wait(Sink *s, int nr, Pipeline *p);
-mal_export void counter_next(Sink *s);
-
#endif /*_PIPELINE_H_*/
diff --git a/sql/backends/monet5/copy.c b/sql/backends/monet5/copy.c
--- a/sql/backends/monet5/copy.c
+++ b/sql/backends/monet5/copy.c
@@ -493,34 +493,6 @@ end:
return msg;
}
-static void
-sleep_ns( int ns)
-{
-#ifdef NATIVE_WIN32
- if (ns < 1000000)
- ns = 1;
- else
- ns /= 1000000;
- Sleep(ns);
-#else
-#ifdef HAVE_NANOSLEEP
- struct timespec ts;
-
- ts.tv_sec = (time_t) 0;
- ts.tv_nsec = ns;
- while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
- ;
-#else
- struct timeval tv;
-
- tv.tv_sec = 0;
- tv.tv_usec = ((ns+999)/1000);
- (void) select(0, NULL, NULL, NULL, &tv);
-#endif
-#endif
-}
-
-
static str
COPYsplitlines(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
@@ -575,8 +547,8 @@ COPYsplitlines(Client cntxt, MalBlkPtr m
if ((r->done) || r->error)
p->p->master_counter = (p->p->nr_workers*-2);
- while (!r->done && !r->error && ATOMIC_GET(&r->seqnr) !=
r->bs->seq[p->wid])
- sleep_ns(1);
+ if (!r->done && !r->error)
+ (void)pipeline_get_token(p, 0, p->wid, &r->done);
if (!r->done)
p->seqnr = (int)r->bs->seq[p->wid];
@@ -594,7 +566,10 @@ COPYsplitlines(Client cntxt, MalBlkPtr m
r->error = true;
bailout("copy.splitlines", SQLSTATE(42000)
"unterminated line at end of file while jumping");
}
- ATOMIC_INC(&r->seqnr);
+ }
+ if (r->can_jump) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]