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

Function threadinit

freebsd/kern/kern_thread.c:486–545  ·  view source on GitHub ↗

* Initialize global thread allocation resources. */

Source from the content-addressed store, hash-verified

484 * Initialize global thread allocation resources.
485 */
486void
487threadinit(void)
488{
489 u_long i;
490 lwpid_t tid0;
491 uint32_t flags;
492
493 /*
494 * Place an upper limit on threads which can be allocated.
495 *
496 * Note that other factors may make the de facto limit much lower.
497 *
498 * Platform limits are somewhat arbitrary but deemed "more than good
499 * enough" for the foreseable future.
500 */
501 if (maxthread == 0) {
502#ifdef _LP64
503 maxthread = MIN(maxproc * max_threads_per_proc, 1000000);
504#else
505 maxthread = MIN(maxproc * max_threads_per_proc, 100000);
506#endif
507 }
508
509 mtx_init(&tid_lock, "TID lock", NULL, MTX_DEF);
510 tid_bitmap = bit_alloc(maxthread, M_TIDHASH, M_WAITOK);
511 /*
512 * Handle thread0.
513 */
514 thread_count_inc();
515 tid0 = tid_alloc();
516 if (tid0 != THREAD0_TID)
517 panic("tid0 %d != %d\n", tid0, THREAD0_TID);
518
519 flags = UMA_ZONE_NOFREE;
520#ifdef __aarch64__
521 /*
522 * Force thread structures to be allocated from the direct map.
523 * Otherwise, superpage promotions and demotions may temporarily
524 * invalidate thread structure mappings. For most dynamically allocated
525 * structures this is not a problem, but translation faults cannot be
526 * handled without accessing curthread.
527 */
528 flags |= UMA_ZONE_CONTIG;
529#endif
530 thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(),
531 thread_ctor, thread_dtor, thread_init, thread_fini,
532 32 - 1, flags);
533 tidhashtbl = hashinit(maxproc / 2, M_TIDHASH, &tidhash);
534 tidhashlock = (tidhash + 1) / 64;
535 if (tidhashlock > 0)
536 tidhashlock--;
537 tidhashtbl_lock = malloc(sizeof(*tidhashtbl_lock) * (tidhashlock + 1),
538 M_TIDHASH, M_WAITOK | M_ZERO);
539 for (i = 0; i < tidhashlock + 1; i++)
540 rw_init(&tidhashtbl_lock[i], "tidhash");
541
542 TASK_INIT(&thread_reap_task, 0, thread_reap_task_cb, NULL);
543 callout_init(&thread_reap_callout, 1);

Callers 2

proc0_initFunction · 0.85
proc0_initFunction · 0.85

Calls 11

mtx_initFunction · 0.85
bit_allocFunction · 0.85
thread_count_incFunction · 0.85
tid_allocFunction · 0.85
uma_zcreateFunction · 0.85
mallocFunction · 0.85
rw_initFunction · 0.85
panicFunction · 0.70
sched_sizeof_threadFunction · 0.70
hashinitFunction · 0.70
callout_initFunction · 0.70

Tested by

no test coverage detected