34#include <sys/cpuset.h>
35#include <sys/kthread.h>
39#include <sys/resourcevar.h>
40#include <sys/rwlock.h>
41#include <sys/signalvar.h>
42#include <sys/sysent.h>
44#include <sys/umtxvar.h>
45#include <sys/unistd.h>
50#include <vm/vm_extern.h>
52#include <machine/stdarg.h>
64 const struct kproc_desc *kp = udata;
68 kp->global_procpp, 0, 0,
"%s", kp->arg0);
70 panic(
"kproc_start: %s: error %d", kp->arg0, error);
85 struct proc **newpp,
int flags,
int pages,
const char *fmt, ...)
94 panic(
"kproc_create called too soon");
96 bzero(&fr,
sizeof(fr));
97 fr.fr_flags = RFMEM | RFFDG | RFPROC | RFSTOPPED |
flags;
98 fr.fr_flags2 = FR2_KPROC;
101 error =
fork1(&thread0, &fr);
111 vsnprintf(p2->p_comm,
sizeof(p2->p_comm), fmt, ap);
113 td = FIRST_THREAD_IN_PROC(p2);
115 vsnprintf(td->td_name,
sizeof(td->td_name), fmt, ap);
118 sched_clear_tdname(td);
120 TSTHREAD(td, td->td_name);
122 if (PMC_SYSTEM_SAMPLING_ACTIVE()) {
123 PMC_CALL_HOOK_UNLOCKED(td, PMC_FN_PROC_CREATE_LOG, p2);
124 PMC_CALL_HOOK_UNLOCKED(td, PMC_FN_THR_CREATE_LOG, NULL);
129 cpu_fork_kthread_handler(td, func, arg);
139 if (!(
flags & RFSTOPPED))
187 if ((p->p_flag & P_KPROC) == 0) {
191 SIGADDSET(p->p_siglist, SIGSTOP);
193 return msleep(&p->p_siglist, &p->p_mtx, PPAUSE | PDROP,
"suspkp", timo);
204 if ((p->p_flag & P_KPROC) == 0) {
208 SIGDELSET(p->p_siglist, SIGSTOP);
218 while (SIGISMEMBER(p->p_siglist, SIGSTOP)) {
220 msleep(&p->p_siglist, &p->p_mtx, PPAUSE,
"kpsusp", 0);
235 const struct kthread_desc *kp = udata;
238 error =
kthread_add((
void (*)(
void *))kp->func, NULL,
239 NULL, kp->global_threadpp, 0, 0,
"%s", kp->arg0);
241 panic(
"kthread_start: %s: error %d", kp->arg0, error);
256 struct thread **newtdp,
int flags,
int pages,
const char *fmt, ...)
259 struct thread *newtd, *oldtd;
262 panic(
"kthread_add called too soon");
274 oldtd = FIRST_THREAD_IN_PROC(p);
276 bzero(&newtd->td_startzero,
277 __rangeof(
struct thread, td_startzero, td_endzero));
278 bcopy(&oldtd->td_startcopy, &newtd->td_startcopy,
279 __rangeof(
struct thread, td_startcopy, td_endcopy));
283 vsnprintf(newtd->td_name,
sizeof(newtd->td_name), fmt, ap);
286 TSTHREAD(newtd, newtd->td_name);
289 newtd->td_pflags |= TDP_KTHREAD;
292 cpu_copy_thread(newtd, oldtd);
295 cpu_fork_kthread_handler(newtd, func, arg);
300 p->p_flag |= P_HADTHREADS;
305 TD_SET_CAN_RUN(newtd);
306 thread_unlock(oldtd);
314 if (PMC_SYSTEM_SAMPLING_ACTIVE())
315 PMC_CALL_HOOK_UNLOCKED(td, PMC_FN_THR_CREATE_LOG, NULL);
318 if (!(
flags & RFSTOPPED)) {
337 if (PMC_SYSTEM_SAMPLING_ACTIVE())
338 PMC_CALL_HOOK_UNLOCKED(td, PMC_FN_THR_EXIT_LOG, NULL);
348 if (p->p_numthreads == 1) {
353 if (p->p_sysent->sv_ontdexit != NULL)
354 p->p_sysent->sv_ontdexit(td);
379 if ((td->td_pflags & TDP_KTHREAD) == 0)
389 td->td_flags |= TDF_KTH_SUSP;
391 return (msleep(&td->td_flags, &p->p_mtx, PPAUSE | PDROP,
"suspkt",
410 if ((td->td_pflags & TDP_KTHREAD) == 0)
415 td->td_flags &= ~TDF_KTH_SUSP;
435 if ((td->td_pflags & TDP_KTHREAD) == 0)
436 panic(
"%s: curthread is not a valid kthread", __func__);
444 if ((td->td_flags & TDF_KTH_SUSP) == 0)
447 while ((td->td_flags & TDF_KTH_SUSP) != 0) {
449 msleep(&td->td_flags, &p->p_mtx, PPAUSE,
"ktsusp", 0);
456 struct proc **procptr,
struct thread **tdptr,
457 int flags,
int pages,
const char *procname,
const char *fmt, ...)
464 if (*procptr == NULL) {
466 procptr,
flags, pages,
"%s", procname);
469 td = FIRST_THREAD_IN_PROC(*procptr);
473 vsnprintf(td->td_name,
sizeof(td->td_name), fmt, ap);
476 sched_clear_tdname(td);
void cpuset_kernthread(struct thread *td)
void exit1(struct thread *td, int rval, int signo)
void proc_reparent(struct proc *child, struct proc *parent, bool set_oppid)
int fork1(struct thread *td, struct fork_req *fr)
int kproc_resume(struct proc *p)
int kproc_create(void(*func)(void *), void *arg, struct proc **newpp, int flags, int pages, const char *fmt,...)
void kproc_exit(int ecode)
void kproc_suspend_check(struct proc *p)
void kthread_suspend_check(void)
void kthread_start(const void *udata)
int kproc_suspend(struct proc *p, int timo)
void kproc_start(const void *udata)
int kthread_suspend(struct thread *td, int timo)
int kthread_resume(struct thread *td)
int kproc_kthread_add(void(*func)(void *), void *arg, struct proc **procptr, struct thread **tdptr, int flags, int pages, const char *procname, const char *fmt,...)
int kthread_add(void(*func)(void *), void *arg, struct proc *p, struct thread **newtdp, int flags, int pages, const char *fmt,...)
struct sx __exclusive_cache_line proctree_lock
void panic(const char *fmt,...)
void tdsigcleanup(struct thread *td)
void wakeup(const void *ident)
void tidhash_add(struct thread *td)
void thread_cow_get_proc(struct thread *newtd, struct proc *p)
void tidhash_remove(struct thread *td)
void thread_link(struct thread *td, struct proc *p)
struct thread * thread_alloc(int pages)
void umtx_thread_exit(struct thread *td)
void sched_fork_thread(struct thread *td, struct thread *childtd)
void sched_prio(struct thread *td, u_char prio)
void sched_add(struct thread *td, int flags)
void sched_user_prio(struct thread *td, u_char prio)
int vsnprintf(char *str, size_t size, const char *format, va_list ap)