Skip to content
Snippets Groups Projects
Commit 676e5761 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'scheduler_activate_root' into 'master'

Scheduler activate root

Re-set the task waits on activation, saves a loop over the tasks in `scheduler_start`.

See merge request !282
parents d8b52883 58857257
No related branches found
No related tags found
1 merge request!282Scheduler activate root
...@@ -996,13 +996,18 @@ void scheduler_reweight(struct scheduler *s, int verbose) { ...@@ -996,13 +996,18 @@ void scheduler_reweight(struct scheduler *s, int verbose) {
void scheduler_rewait_mapper(void *map_data, int num_elements, void scheduler_rewait_mapper(void *map_data, int num_elements,
void *extra_data) { void *extra_data) {
struct task *tasks = (struct task *)map_data; struct scheduler *s = (struct scheduler *)extra_data;
const int *tid = (int *)map_data;
for (int ind = 0; ind < num_elements; ind++) { for (int ind = 0; ind < num_elements; ind++) {
struct task *t = &tasks[ind]; struct task *t = &s->tasks[tid[ind]];
/* Ignore skipped tasks. */
if (t->skip) continue; if (t->skip) continue;
/* Increment the task's own wait counter for the enqueueing. */
atomic_inc(&t->wait);
/* Skip sort tasks that have already been performed */ /* Skip sort tasks that have already been performed */
if (t->type == task_type_sort && t->flags == 0) { if (t->type == task_type_sort && t->flags == 0) {
error("Empty sort task encountered."); error("Empty sort task encountered.");
...@@ -1037,12 +1042,13 @@ void scheduler_enqueue_mapper(void *map_data, int num_elements, ...@@ -1037,12 +1042,13 @@ void scheduler_enqueue_mapper(void *map_data, int num_elements,
*/ */
void scheduler_start(struct scheduler *s) { void scheduler_start(struct scheduler *s) {
/* Clear all the waits. */
for (int k = 0; k < s->nr_tasks; k++) s->tasks[k].wait = 1;
/* Re-wait the tasks. */ /* Re-wait the tasks. */
threadpool_map(s->threadpool, scheduler_rewait_mapper, s->tasks, s->nr_tasks, if (s->active_count > 1000) {
sizeof(struct task), 1000, NULL); threadpool_map(s->threadpool, scheduler_rewait_mapper, s->tid_active,
s->active_count, sizeof(int), 1000, s);
} else {
scheduler_rewait_mapper(s->tid_active, s->active_count, s);
}
/* Check we have not missed an active task */ /* Check we have not missed an active task */
#ifdef SWIFT_DEBUG_CHECKS #ifdef SWIFT_DEBUG_CHECKS
...@@ -1091,12 +1097,11 @@ void scheduler_start(struct scheduler *s) { ...@@ -1091,12 +1097,11 @@ void scheduler_start(struct scheduler *s) {
#endif #endif
/* Loop over the tasks and enqueue whoever is ready. */ /* Loop over the tasks and enqueue whoever is ready. */
for (int k = 0; k < s->active_count; k++) { if (s->active_count > 1000) {
struct task *t = &s->tasks[s->tid_active[k]]; threadpool_map(s->threadpool, scheduler_enqueue_mapper, s->tid_active,
if (atomic_dec(&t->wait) == 1 && !t->skip) { s->active_count, sizeof(int), 1000, s);
scheduler_enqueue(s, t); } else {
pthread_cond_signal(&s->sleep_cond); scheduler_enqueue_mapper(s->tid_active, s->active_count, s);
}
} }
/* Clear the list of active tasks. */ /* Clear the list of active tasks. */
...@@ -1232,6 +1237,7 @@ struct task *scheduler_done(struct scheduler *s, struct task *t) { ...@@ -1232,6 +1237,7 @@ struct task *scheduler_done(struct scheduler *s, struct task *t) {
they are ready. */ they are ready. */
for (int k = 0; k < t->nr_unlock_tasks; k++) { for (int k = 0; k < t->nr_unlock_tasks; k++) {
struct task *t2 = t->unlock_tasks[k]; struct task *t2 = t->unlock_tasks[k];
if (t2->skip) continue;
const int res = atomic_dec(&t2->wait); const int res = atomic_dec(&t2->wait);
if (res < 1) { if (res < 1) {
......
...@@ -114,6 +114,7 @@ struct scheduler { ...@@ -114,6 +114,7 @@ struct scheduler {
__attribute__((always_inline)) INLINE static void scheduler_activate( __attribute__((always_inline)) INLINE static void scheduler_activate(
struct scheduler *s, struct task *t) { struct scheduler *s, struct task *t) {
if (atomic_cas(&t->skip, 1, 0)) { if (atomic_cas(&t->skip, 1, 0)) {
t->wait = 0;
int ind = atomic_inc(&s->active_count); int ind = atomic_inc(&s->active_count);
s->tid_active[ind] = t - s->tasks; s->tid_active[ind] = t - s->tasks;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment