Skip to content

Commit 2fb7e8a

Browse files
committed
Add a mechanism to reset the default task spawn order
Add `qthread_reset_target_shep()`, which resets the shepherd that tasks created with `NO_SHEPHERD` get spawned to. This is useful in Chapel for cases where we want to use the default spawn location, but get good NUMA affinity between data parallel loops sepreated by some other task spawn. Just using the `qthread_fork_to` API would disable future stealing, so this is a mechanism to get tasks in consecutive data parallel loops to spawn to the same shepherds without preventing stealing. This was originally done in chapel-lang/chapel 12868, which includes some perf results. At the time I expected we'd update our shim to use `qthread_fork_to`, but had not considered the work-stealing implications at the time.
1 parent dc880eb commit 2fb7e8a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/qthread/qthread.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ int qthread_spawn(qthread_f f,
333333
/* This is a function to move a thread from one shepherd to another. */
334334
int qthread_migrate_to(const qthread_shepherd_id_t shepherd);
335335

336+
/* Resets the default shepherd spawn order for tasks that use NO_SHEPHERD */
337+
void qthread_reset_target_shep(void);
338+
336339
/* This function sets the debug level if debugging has been enabled */
337340
int qthread_debuglevel(int);
338341

src/qthread.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,19 @@ int API_FUNC qthread_migrate_to(const qthread_shepherd_id_t shepherd)
30003000
}
30013001
} /*}}} */
30023002

3003+
void API_FUNC qthread_reset_target_shep(void) {
3004+
assert(qthread_library_initialized);
3005+
qthread_t *me = qthread_internal_self();
3006+
3007+
if (me) {
3008+
assert(me->rdata);
3009+
me->rdata->shepherd_ptr->sched_shepherd = 0;
3010+
} else {
3011+
qlib->sched_shepherd = 0;
3012+
MACHINE_FENCE;
3013+
}
3014+
}
3015+
30033016

30043017
/* These are just accessor functions */
30053018
unsigned int API_FUNC qthread_id(void)

0 commit comments

Comments
 (0)