Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
c20c6c25
Commit
c20c6c25
authored
8 years ago
by
Pedro Gonnet
Browse files
Options
Downloads
Patches
Plain Diff
use the threadpool only if there are enough tasks.
parent
141a31bd
No related branches found
No related tags found
1 merge request
!282
Scheduler activate root
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/scheduler.c
+50
-12
50 additions, 12 deletions
src/scheduler.c
with
50 additions
and
12 deletions
src/scheduler.c
+
50
−
12
View file @
c20c6c25
...
...
@@ -1020,15 +1020,44 @@ void scheduler_rewait_mapper(void *map_data, int num_elements,
}
}
void
scheduler_rewait_active_mapper
(
void
*
map_data
,
int
num_elements
,
void
*
extra_data
)
{
struct
scheduler
*
s
=
(
struct
scheduler
*
)
extra_data
;
const
int
*
tid
=
(
int
*
)
map_data
;
const
unsigned
int
mask
=
s
->
mask
;
const
unsigned
int
submask
=
s
->
submask
;
for
(
int
ind
=
0
;
ind
<
num_elements
;
ind
++
)
{
struct
task
*
t
=
&
s
->
tasks
[
tid
[
ind
]];
if
(
t
->
skip
||
!
((
1
<<
t
->
type
)
&
mask
)
||
!
((
1
<<
t
->
subtype
)
&
submask
))
continue
;
/* Skip sort tasks that have already been performed */
if
(
t
->
type
==
task_type_sort
&&
t
->
flags
==
0
)
{
error
(
"Empty sort task encountered."
);
}
/* Sets the waits of the dependances */
for
(
int
k
=
0
;
k
<
t
->
nr_unlock_tasks
;
k
++
)
{
struct
task
*
u
=
t
->
unlock_tasks
[
k
];
atomic_inc
(
&
u
->
wait
);
}
}
}
void
scheduler_enqueue_mapper
(
void
*
map_data
,
int
num_elements
,
void
*
extra_data
)
{
struct
scheduler
*
s
=
(
struct
scheduler
*
)
extra_data
;
const
int
*
tid
=
(
int
*
)
map_data
;
struct
task
*
tasks
=
s
->
tasks
;
const
unsigned
int
mask
=
s
->
mask
;
const
unsigned
int
submask
=
s
->
submask
;
for
(
int
ind
=
0
;
ind
<
num_elements
;
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
))
{
if
(
atomic_dec
(
&
t
->
wait
)
==
1
&&
!
t
->
skip
&&
((
1
<<
t
->
type
)
&
mask
)
&&
((
1
<<
t
->
subtype
)
&
submask
))
{
scheduler_enqueue
(
s
,
t
);
}
}
...
...
@@ -1045,13 +1074,13 @@ void scheduler_enqueue_mapper(void *map_data, int num_elements,
void
scheduler_start
(
struct
scheduler
*
s
,
unsigned
int
mask
,
unsigned
int
submask
)
{
const
ticks
tic
=
getticks
();
/* Store the masks */
s
->
mask
=
mask
;
s
->
submask
=
submask
|=
(
1
<<
task_subtype_none
);
/* Clear all the waits and times. */
message
(
"nr_tasks=%i, active_count=%i."
,
s
->
nr_tasks
,
s
->
active_count
);
for
(
int
k
=
0
;
k
<
s
->
active_count
;
k
++
)
{
struct
task
*
t
=
&
s
->
tasks
[
s
->
tid_active
[
k
]];
t
->
wait
=
1
;
...
...
@@ -1060,10 +1089,18 @@ void scheduler_start(struct scheduler *s, unsigned int mask,
if
(((
1
<<
t
->
type
)
&
mask
)
==
0
||
((
1
<<
t
->
subtype
)
&
submask
)
==
0
)
t
->
skip
=
1
;
}
/* message("clear took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit()); */
/* Re-wait the tasks. */
threadpool_map
(
s
->
threadpool
,
scheduler_rewait_mapper
,
s
->
tasks
,
s
->
nr_tasks
,
sizeof
(
struct
task
),
1000
,
s
);
if
(
s
->
active_count
>
1000
)
{
threadpool_map
(
s
->
threadpool
,
scheduler_rewait_active_mapper
,
s
->
tid_active
,
s
->
active_count
,
sizeof
(
int
),
1000
,
s
);
}
else
{
scheduler_rewait_active_mapper
(
s
->
tid_active
,
s
->
active_count
,
s
);
}
/* message("rewait took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit()); */
/* Check we have not missed an active task */
#ifdef SWIFT_DEBUG_CHECKS
...
...
@@ -1108,13 +1145,11 @@ void scheduler_start(struct scheduler *s, unsigned int mask,
#endif
/* Loop over the tasks and enqueue whoever is ready. */
for
(
int
k
=
0
;
k
<
s
->
active_count
;
k
++
)
{
struct
task
*
t
=
&
s
->
tasks
[
s
->
tid_active
[
k
]];
if
(
atomic_dec
(
&
t
->
wait
)
==
1
&&
!
t
->
skip
&&
((
1
<<
t
->
type
)
&
s
->
mask
)
&&
((
1
<<
t
->
subtype
)
&
s
->
submask
))
{
scheduler_enqueue
(
s
,
t
);
pthread_cond_signal
(
&
s
->
sleep_cond
);
}
if
(
s
->
active_count
>
1000
)
{
threadpool_map
(
s
->
threadpool
,
scheduler_enqueue_mapper
,
s
->
tid_active
,
s
->
active_count
,
sizeof
(
int
),
1000
,
s
);
}
else
{
scheduler_enqueue_mapper
(
s
->
tid_active
,
s
->
active_count
,
s
);
}
/* Clear the list of active tasks. */
...
...
@@ -1124,6 +1159,9 @@ void scheduler_start(struct scheduler *s, unsigned int mask,
pthread_mutex_lock
(
&
s
->
sleep_mutex
);
pthread_cond_broadcast
(
&
s
->
sleep_cond
);
pthread_mutex_unlock
(
&
s
->
sleep_mutex
);
message
(
"took %.3f %s."
,
clocks_from_ticks
(
getticks
()
-
tic
),
clocks_getunit
());
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment