Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/kern_kthread.c
Show First 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | kproc_create(void (*func)(void *), void *arg, | ||||
va_start(ap, fmt); | va_start(ap, fmt); | ||||
vsnprintf(td->td_name, sizeof(td->td_name), fmt, ap); | vsnprintf(td->td_name, sizeof(td->td_name), fmt, ap); | ||||
va_end(ap); | va_end(ap); | ||||
#ifdef KTR | #ifdef KTR | ||||
sched_clear_tdname(td); | sched_clear_tdname(td); | ||||
#endif | #endif | ||||
/* call the processes' main()... */ | /* call the processes' main()... */ | ||||
cpu_set_fork_handler(td, func, arg); | cpu_fork_kthread_handler(td, func, arg); | ||||
/* Avoid inheriting affinity from a random parent. */ | /* Avoid inheriting affinity from a random parent. */ | ||||
cpuset_setthread(td->td_tid, cpuset_root); | cpuset_setthread(td->td_tid, cpuset_root); | ||||
thread_lock(td); | thread_lock(td); | ||||
TD_SET_CAN_RUN(td); | TD_SET_CAN_RUN(td); | ||||
sched_prio(td, PVM); | sched_prio(td, PVM); | ||||
sched_user_prio(td, PUSER); | sched_user_prio(td, PUSER); | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | kthread_add(void (*func)(void *), void *arg, struct proc *p, | ||||
bcopy(&oldtd->td_startcopy, &newtd->td_startcopy, | bcopy(&oldtd->td_startcopy, &newtd->td_startcopy, | ||||
__rangeof(struct thread, td_startcopy, td_endcopy)); | __rangeof(struct thread, td_startcopy, td_endcopy)); | ||||
/* set up arg0 for 'ps', et al */ | /* set up arg0 for 'ps', et al */ | ||||
va_start(ap, fmt); | va_start(ap, fmt); | ||||
vsnprintf(newtd->td_name, sizeof(newtd->td_name), fmt, ap); | vsnprintf(newtd->td_name, sizeof(newtd->td_name), fmt, ap); | ||||
va_end(ap); | va_end(ap); | ||||
newtd->td_proc = p; /* needed for cpu_set_upcall */ | newtd->td_proc = p; /* needed for cpu_copy_thread */ | ||||
/* might be further optimized for kthread */ | |||||
/* XXX optimise this probably? */ | cpu_copy_thread(newtd, oldtd); | ||||
/* On x86 (and probably the others too) it is way too full of junk */ | |||||
/* Needs a better name */ | |||||
cpu_set_upcall(newtd, oldtd); | |||||
/* put the designated function(arg) as the resume context */ | /* put the designated function(arg) as the resume context */ | ||||
cpu_set_fork_handler(newtd, func, arg); | cpu_fork_kthread_handler(newtd, func, arg); | ||||
newtd->td_pflags |= TDP_KTHREAD; | newtd->td_pflags |= TDP_KTHREAD; | ||||
thread_cow_get_proc(newtd, p); | thread_cow_get_proc(newtd, p); | ||||
/* this code almost the same as create_thread() in kern_thr.c */ | /* this code almost the same as create_thread() in kern_thr.c */ | ||||
p->p_flag |= P_HADTHREADS; | p->p_flag |= P_HADTHREADS; | ||||
thread_link(newtd, p); | thread_link(newtd, p); | ||||
thread_lock(oldtd); | thread_lock(oldtd); | ||||
▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines |