Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
61e7f193
Commit
61e7f193
authored
Jun 22, 2013
by
Pedro Gonnet
Browse files
implement strategy to sleep if tasks are rare.
Former-commit-id: 544f802833b16e3ecf9e399e2f8a4d02579ef817
parent
8f62de2c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/scheduler.c
View file @
61e7f193
...
...
@@ -25,6 +25,7 @@
#include
<stdlib.h>
#include
<string.h>
#include
<math.h>
#include
<pthread.h>
/* Local headers. */
#include
"error.h"
...
...
@@ -627,7 +628,10 @@ void scheduler_done ( struct scheduler *s , struct task *t ) {
}
/* Task definitely done. */
pthread_mutex_lock
(
&
s
->
sleep_mutex
);
atomic_dec
(
&
s
->
waiting
);
pthread_cond_broadcast
(
&
s
->
sleep_cond
);
pthread_mutex_unlock
(
&
s
->
sleep_mutex
);
}
...
...
@@ -664,6 +668,12 @@ struct task *scheduler_gettask ( struct scheduler *s , int qid ) {
if
(
max_count
>
0
&&
(
res
=
queue_gettask
(
&
s
->
queues
[
max_ind
]
,
qid
,
0
)
)
!=
NULL
)
return
res
;
}
/* If we failed, take a short nap. */
pthread_mutex_lock
(
&
s
->
sleep_mutex
);
if
(
s
->
waiting
>
0
)
pthread_cond_wait
(
&
s
->
sleep_cond
,
&
s
->
sleep_mutex
);
pthread_mutex_unlock
(
&
s
->
sleep_mutex
);
}
...
...
@@ -696,6 +706,11 @@ void scheduler_init ( struct scheduler *s , struct space *space , int nr_queues
for
(
k
=
0
;
k
<
nr_queues
;
k
++
)
queue_init
(
&
s
->
queues
[
k
]
,
NULL
);
/* Init the sleep mutex and cond. */
if
(
pthread_cond_init
(
&
s
->
sleep_cond
,
NULL
)
!=
0
||
pthread_mutex_init
(
&
s
->
sleep_mutex
,
NULL
)
!=
0
)
error
(
"Failed to initialize sleep barrier."
);
/* Set the scheduler variables. */
s
->
nr_queues
=
nr_queues
;
s
->
flags
=
flags
;
...
...
src/scheduler.h
View file @
61e7f193
...
...
@@ -56,6 +56,10 @@ struct scheduler {
/* Lock for this scheduler. */
lock_type
lock
;
/* Waiting queue. */
pthread_mutex_t
sleep_mutex
;
pthread_cond_t
sleep_cond
;
/* The space associated with this scheduler. */
struct
space
*
space
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment