| 446 | } |
| 447 | |
| 448 | static int |
| 449 | _gtaskqueue_start_threads(struct gtaskqueue **tqp, int count, int pri, |
| 450 | cpuset_t *mask, const char *name, va_list ap) |
| 451 | { |
| 452 | char ktname[MAXCOMLEN + 1]; |
| 453 | struct thread *td; |
| 454 | struct gtaskqueue *tq; |
| 455 | int i, error; |
| 456 | |
| 457 | if (count <= 0) |
| 458 | return (EINVAL); |
| 459 | |
| 460 | vsnprintf(ktname, sizeof(ktname), name, ap); |
| 461 | tq = *tqp; |
| 462 | |
| 463 | tq->tq_threads = malloc(sizeof(struct thread *) * count, M_GTASKQUEUE, |
| 464 | M_NOWAIT | M_ZERO); |
| 465 | if (tq->tq_threads == NULL) { |
| 466 | printf("%s: no memory for %s threads\n", __func__, ktname); |
| 467 | return (ENOMEM); |
| 468 | } |
| 469 | |
| 470 | for (i = 0; i < count; i++) { |
| 471 | if (count == 1) |
| 472 | error = kthread_add(gtaskqueue_thread_loop, tqp, NULL, |
| 473 | &tq->tq_threads[i], RFSTOPPED, 0, "%s", ktname); |
| 474 | else |
| 475 | error = kthread_add(gtaskqueue_thread_loop, tqp, NULL, |
| 476 | &tq->tq_threads[i], RFSTOPPED, 0, |
| 477 | "%s_%d", ktname, i); |
| 478 | if (error) { |
| 479 | /* should be ok to continue, taskqueue_free will dtrt */ |
| 480 | printf("%s: kthread_add(%s): error %d", __func__, |
| 481 | ktname, error); |
| 482 | tq->tq_threads[i] = NULL; /* paranoid */ |
| 483 | } else |
| 484 | tq->tq_tcount++; |
| 485 | } |
| 486 | for (i = 0; i < count; i++) { |
| 487 | if (tq->tq_threads[i] == NULL) |
| 488 | continue; |
| 489 | td = tq->tq_threads[i]; |
| 490 | if (mask) { |
| 491 | error = cpuset_setthread(td->td_tid, mask); |
| 492 | /* |
| 493 | * Failing to pin is rarely an actual fatal error; |
| 494 | * it'll just affect performance. |
| 495 | */ |
| 496 | if (error) |
| 497 | printf("%s: curthread=%llu: can't pin; " |
| 498 | "error=%d\n", |
| 499 | __func__, |
| 500 | (unsigned long long) td->td_tid, |
| 501 | error); |
| 502 | } |
| 503 | thread_lock(td); |
| 504 | sched_prio(td, pri); |
| 505 | sched_add(td, SRQ_BORING); |
no test coverage detected