MCPcopy Create free account
hub / github.com/F-Stack/f-stack / _gtaskqueue_start_threads

Function _gtaskqueue_start_threads

freebsd/kern/subr_gtaskqueue.c:448–509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446}
447
448static 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);

Callers 1

gtaskqueue_start_threadsFunction · 0.85

Calls 7

vsnprintfFunction · 0.85
mallocFunction · 0.85
cpuset_setthreadFunction · 0.85
printfFunction · 0.70
kthread_addFunction · 0.70
sched_prioFunction · 0.70
sched_addFunction · 0.70

Tested by

no test coverage detected