Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_thread.c
Show First 20 Lines • Show All 497 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Initialize global thread allocation resources. | * Initialize global thread allocation resources. | ||||
*/ | */ | ||||
void | void | ||||
threadinit(void) | threadinit(void) | ||||
{ | { | ||||
u_long i; | u_long i; | ||||
lwpid_t tid0; | lwpid_t tid0; | ||||
uint32_t flags; | |||||
/* | /* | ||||
* Place an upper limit on threads which can be allocated. | * Place an upper limit on threads which can be allocated. | ||||
* | * | ||||
* Note that other factors may make the de facto limit much lower. | * Note that other factors may make the de facto limit much lower. | ||||
* | * | ||||
* Platform limits are somewhat arbitrary but deemed "more than good | * Platform limits are somewhat arbitrary but deemed "more than good | ||||
* enough" for the foreseable future. | * enough" for the foreseable future. | ||||
Show All 11 Lines | #endif | ||||
/* | /* | ||||
* Handle thread0. | * Handle thread0. | ||||
*/ | */ | ||||
thread_count_inc(); | thread_count_inc(); | ||||
tid0 = tid_alloc(); | tid0 = tid_alloc(); | ||||
if (tid0 != THREAD0_TID) | if (tid0 != THREAD0_TID) | ||||
panic("tid0 %d != %d\n", tid0, THREAD0_TID); | panic("tid0 %d != %d\n", tid0, THREAD0_TID); | ||||
flags = UMA_ZONE_NOFREE; | |||||
#ifdef __aarch64__ | |||||
/* | |||||
* Force thread structures to be allocated from the direct map. | |||||
* Otherwise, superpage promotions and demotions may temporarily | |||||
* invalidate thread structure mappings. For most dynamically allocated | |||||
* structures this is not a problem, but translation faults cannot be | |||||
* handled without accessing curthread. | |||||
*/ | |||||
flags |= UMA_ZONE_CONTIG; | |||||
#endif | |||||
thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(), | thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(), | ||||
thread_ctor, thread_dtor, thread_init, thread_fini, | thread_ctor, thread_dtor, thread_init, thread_fini, | ||||
32 - 1, flags); | 32 - 1, UMA_ZONE_NOFREE); | ||||
tidhashtbl = hashinit(maxproc / 2, M_TIDHASH, &tidhash); | tidhashtbl = hashinit(maxproc / 2, M_TIDHASH, &tidhash); | ||||
tidhashlock = (tidhash + 1) / 64; | tidhashlock = (tidhash + 1) / 64; | ||||
if (tidhashlock > 0) | if (tidhashlock > 0) | ||||
tidhashlock--; | tidhashlock--; | ||||
tidhashtbl_lock = malloc(sizeof(*tidhashtbl_lock) * (tidhashlock + 1), | tidhashtbl_lock = malloc(sizeof(*tidhashtbl_lock) * (tidhashlock + 1), | ||||
M_TIDHASH, M_WAITOK | M_ZERO); | M_TIDHASH, M_WAITOK | M_ZERO); | ||||
for (i = 0; i < tidhashlock + 1; i++) | for (i = 0; i < tidhashlock + 1; i++) | ||||
rw_init(&tidhashtbl_lock[i], "tidhash"); | rw_init(&tidhashtbl_lock[i], "tidhash"); | ||||
▲ Show 20 Lines • Show All 1,242 Lines • Show Last 20 Lines |