From 4d27c8ba6fcd78f65497d9c9784b558a581b470b Mon Sep 17 00:00:00 2001 From: Pedro Gonnet <gonnet@google.com> Date: Tue, 25 Oct 2016 21:41:05 +0200 Subject: [PATCH] clear the task wait/tic/toc only when needed, not explicitly in scheduler_start. --- src/scheduler.c | 23 ++++++++++------------- src/scheduler.h | 1 + 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/scheduler.c b/src/scheduler.c index 84626a19f1..a11b026146 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1034,8 +1034,15 @@ void scheduler_rewait_active_mapper(void *map_data, int num_elements, for (int ind = 0; ind < num_elements; ind++) { struct task *t = &s->tasks[tid[ind]]; - if (t->skip || !((1 << t->type) & mask) || !((1 << t->subtype) & submask)) + /* Ignore masked-out tasks. */ + if (t->skip || !((1 << t->type) & mask) || !((1 << t->subtype) & submask)) { + t->skip = 1; continue; + } + + /* Increment the task's own wait counter for the enqueueing. */ + atomic_inc(&t->wait); + t->tic = t->toc = 0; /* Skip sort tasks that have already been performed */ if (t->type == task_type_sort && t->flags == 0) { @@ -1083,18 +1090,6 @@ void scheduler_start(struct scheduler *s, unsigned int mask, s->mask = mask; s->submask = submask |= (1 << task_subtype_none); - /* Clear all the waits and times. */ - for (int k = 0; k < s->active_count; k++) { - struct task *t = &s->tasks[s->tid_active[k]]; - t->wait = 1; - t->tic = 0; - t->toc = 0; - if (((1 << t->type) & mask) == 0 || ((1 << t->subtype) & submask) == 0) - t->skip = 1; - } - /* message("clear took %.3f %s.", clocks_from_ticks(getticks() - tic), - clocks_getunit()); */ - /* Re-wait the tasks. */ if (s->active_count > 1000) { threadpool_map(s->threadpool, scheduler_rewait_active_mapper, s->tid_active, @@ -1296,6 +1291,8 @@ struct task *scheduler_done(struct scheduler *s, struct task *t) { they are ready. */ for (int k = 0; k < t->nr_unlock_tasks; k++) { struct task *t2 = t->unlock_tasks[k]; + if (t2->skip || !((1 << t2->type) & s->mask) || !((1 << t2->subtype) & s->submask)) + continue; const int res = atomic_dec(&t2->wait); if (res < 1) { diff --git a/src/scheduler.h b/src/scheduler.h index 22c83ae3c5..00d67a280b 100644 --- a/src/scheduler.h +++ b/src/scheduler.h @@ -121,6 +121,7 @@ struct scheduler { __attribute__((always_inline)) INLINE static void scheduler_activate( struct scheduler *s, struct task *t) { if (atomic_cas(&t->skip, 1, 0)) { + t->wait = 0; int ind = atomic_inc(&s->active_count); s->tid_active[ind] = t - s->tasks; } -- GitLab