summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsam <sam@FreeBSD.org>2006-05-24 22:11:07 +0000
committersam <sam@FreeBSD.org>2006-05-24 22:11:07 +0000
commitebcbe046b9de0cd9b1ee9874be24aef9ed6699c6 (patch)
tree554379d93fa4cbb010cdddcd7b1db69dfefb18c4
parent726780d475390e3ee689390193445ae26af8043a (diff)
downloadFreeBSD-src-ebcbe046b9de0cd9b1ee9874be24aef9ed6699c6.zip
FreeBSD-src-ebcbe046b9de0cd9b1ee9874be24aef9ed6699c6.tar.gz
When starting up threads in taskqueue_start_threads create them
stopped before adjusting their priority and setting them on the run q so they cannot race for resources (pointed out by njl). While here add a console printf on thread create fails; otherwise noone may notice (e.g. return value is always 0 and caller has no way to verify). Reviewed by: jhb, scottl MFC after: 2 weeks
-rw-r--r--sys/kern/subr_taskqueue.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c
index bd17515..f39f5d1 100644
--- a/sys/kern/subr_taskqueue.c
+++ b/sys/kern/subr_taskqueue.c
@@ -315,6 +315,7 @@ taskqueue_start_threads(struct taskqueue **tqp, int count, int pri,
{
va_list ap;
struct taskqueue *tq;
+ struct thread *td;
char ktname[MAXCOMLEN];
int i, error;
@@ -336,21 +337,27 @@ taskqueue_start_threads(struct taskqueue **tqp, int count, int pri,
for (i = 0; i < count; i++) {
if (count == 1)
error = kthread_create(taskqueue_thread_loop, tqp,
- &tq->tq_pproc[i], 0, 0, ktname);
+ &tq->tq_pproc[i], RFSTOPPED, 0, ktname);
else
error = kthread_create(taskqueue_thread_loop, tqp,
- &tq->tq_pproc[i], 0, 0, "%s_%d", ktname, i);
- if (error == 0) {
- mtx_lock_spin(&sched_lock);
- sched_prio(FIRST_THREAD_IN_PROC(tq->tq_pproc[i]), pri);
- mtx_unlock_spin(&sched_lock);
- tq->tq_pcount++;
- } else {
+ &tq->tq_pproc[i], RFSTOPPED, 0, "%s_%d", ktname, i);
+ if (error) {
/* should be ok to continue, taskqueue_free will dtrt */
printf("%s: kthread_create(%s): error %d",
__func__, ktname, error);
- }
+ tq->tq_pproc[i] = NULL; /* paranoid */
+ } else
+ tq->tq_pcount++;
+ }
+ mtx_lock_spin(&sched_lock);
+ for (i = 0; i < count; i++) {
+ if (tq->tq_pproc[i] == NULL)
+ continue;
+ td = FIRST_THREAD_IN_PROC(tq->tq_pproc[i]);
+ sched_prio(td, pri);
+ setrunqueue(td, SRQ_BORING);
}
+ mtx_unlock_spin(&sched_lock);
return (0);
}
OpenPOWER on IntegriCloud