From f7268ba2e0c22d216cdf78710c2e3b655d10bea0 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet <gonnet@google.com> Date: Tue, 21 Jun 2016 21:36:46 +0200 Subject: [PATCH] enqueue the tasks in topological order, make sure we get live ones faster. --- src/scheduler.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/scheduler.c b/src/scheduler.c index c89872f059..c0a9f5cb15 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1012,9 +1012,10 @@ void scheduler_rewait_mapper(void *map_data, int num_elements, void scheduler_enqueue_mapper(void *map_data, int num_elements, void *extra_data) { struct scheduler *s = (struct scheduler *)extra_data; - struct task *tasks = (struct task *)map_data; + const int *tid = (int *)map_data; + struct task *tasks = s->tasks; for (int ind = 0; ind < num_elements; ind++) { - struct task *t = &tasks[ind]; + struct task *t = &tasks[tid[ind]]; if (atomic_dec(&t->wait) == 1 && !t->skip && ((1 << t->type) & s->mask) && ((1 << t->subtype) & s->submask)) { scheduler_enqueue(s, t); @@ -1051,8 +1052,8 @@ void scheduler_start(struct scheduler *s, unsigned int mask, sizeof(struct task), 1000, s); /* Loop over the tasks and enqueue whoever is ready. */ - threadpool_map(s->threadpool, scheduler_enqueue_mapper, s->tasks, s->nr_tasks, - sizeof(struct task), 1000, s); + threadpool_map(s->threadpool, scheduler_enqueue_mapper, s->tasks_ind, s->nr_tasks, + sizeof(int), 1000, s); /* To be safe, fire of one last sleep_cond in a safe way. */ pthread_mutex_lock(&s->sleep_mutex); -- GitLab