diff --git a/src/scheduler.c b/src/scheduler.c index 84c6608cbdb66493b6aaa619b1b7f06f4749c412..93bcbc0f98ef10bda6793065e1e4c123989ab5c2 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -847,7 +847,7 @@ struct task *scheduler_gettask ( struct scheduler *s , int qid , struct cell *su while ( s->waiting > 0 && res == NULL ) { /* Try more than once before sleeping. */ - for ( int tries = 0 ; res == NULL && tries < scheduler_flag_maxsteal ; tries++ ) { + for ( int tries = 0 ; res == NULL && tries < scheduler_maxtries ; tries++ ) { /* Try to get a task from the suggested queue. */ if ( ( res = queue_gettask( &s->queues[qid] , qid , super , 0 ) ) != NULL ) @@ -859,7 +859,14 @@ struct task *scheduler_gettask ( struct scheduler *s , int qid , struct cell *su for ( k = 0 ; k < nr_queues ; k++ ) if ( s->queues[k].count > 0 ) qids[ count++ ] = k; - if ( count > 0 && ( res = queue_gettask( &s->queues[ qids[ rand() % count ] ] , qid , super , 0 ) ) != NULL ) + for ( k = 0 ; k < scheduler_maxsteal && count > 0 ; k++ ) { + int ind = rand() % count; + if ( ( res = queue_gettask( &s->queues[ qids[ ind ] ] , qid , super , 0 ) ) != NULL ) + break; + else + qids[ ind ] = qids[ --count ]; + } + if ( res != NULL ) break; } diff --git a/src/scheduler.h b/src/scheduler.h index b8ae07ed35967861e6228dce537ded55cb91160b..46b196f4b61e997e9e716959745ab92c8d2a43f7 100644 --- a/src/scheduler.h +++ b/src/scheduler.h @@ -22,11 +22,12 @@ #define scheduler_maxwait 3 #define scheduler_maxunlock 40 #define scheduler_dosub 1 +#define scheduler_maxsteal 10 +#define scheduler_maxtries 10 /* Flags . */ #define scheduler_flag_none 0 #define scheduler_flag_steal 1 -#define scheduler_flag_maxsteal 10 /* Data of a scheduler. */