Skip to content
Snippets Groups Projects
Commit ed94ec26 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

try more than once to get a task before sleeping.

Former-commit-id: 458a6f26e877376b6bb0f74c835c04954c691959
parent 84a9f7fe
No related branches found
No related tags found
No related merge requests found
......@@ -662,32 +662,29 @@ struct task *scheduler_gettask ( struct scheduler *s , int qid ) {
/* Loop as long as there are tasks... */
while ( s->waiting > 0 ) {
/* Try to get a task from the suggested queue. */
if ( ( res = queue_gettask( &s->queues[qid] , qid , 0 ) ) != NULL )
return res;
/* If unsucessful, try stealing from the largest queue. */
if ( s->flags & scheduler_flag_steal ) {
int qids[ nr_queues ];
for ( k = 0 ; k < nr_queues ; k++ )
qids[k] = k;
/* int max_count = 0, max_ind = 0;
for ( k = 0 ; k < nr_queues ; k++ )
if ( k != qid && s->queues[k].count > max_count ) {
max_ind = k;
max_count = s->queues[k].count;
/* Try more than once before sleeping. */
for ( int tries = 0 ; tries < scheduler_flag_maxsteal ; tries++ ) {
/* Try to get a task from the suggested queue. */
if ( ( res = queue_gettask( &s->queues[qid] , qid , 0 ) ) != NULL )
return res;
/* If unsucessful, try stealing from the largest queue. */
if ( s->flags & scheduler_flag_steal ){
int qids[ nr_queues ];
for ( k = 0 ; k < nr_queues ; k++ )
qids[k] = k;
for ( k = 0 ; k < nr_queues ; k++ ) {
int j = k + ( rand() % (nr_queues - k) );
int temp = qids[j];
qids[j] = qids[k];
if ( temp == qid )
continue;
if ( s->queues[temp].count > 0 && ( res = queue_gettask( &s->queues[temp] , qid , 0 ) ) != NULL )
return res;
}
if ( max_count > 0 && ( res = queue_gettask( &s->queues[ max_ind ] , qid , 0 ) ) != NULL )
return res; */
for ( k = 0 ; k < nr_queues ; k++ ) {
if ( k == qid )
continue;
int j = k + ( rand() % (nr_queues - k) );
int temp = qids[j];
qids[j] = qids[k];
if ( s->queues[temp].count > 0 && ( res = queue_gettask( &s->queues[temp] , qid , 0 ) ) != NULL )
return res;
}
}
/* If we failed, take a short nap. */
......
......@@ -27,6 +27,7 @@
/* Flags . */
#define scheduler_flag_none 0
#define scheduler_flag_steal 1
#define scheduler_flag_maxsteal 2
/* Data of a scheduler. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment