diff options
author | julian <julian@FreeBSD.org> | 2002-10-24 08:46:34 +0000 |
---|---|---|
committer | julian <julian@FreeBSD.org> | 2002-10-24 08:46:34 +0000 |
commit | 842e39ccd89a966240364f58cc43ff6b5d71d7b6 (patch) | |
tree | 6801346569098e885eb0f181f11b85c5a0cd04c2 /sys/kern/kern_proc.c | |
parent | ccacc0c953194d9b5476c98b542d253c6c5af728 (diff) | |
download | FreeBSD-src-842e39ccd89a966240364f58cc43ff6b5d71d7b6.zip FreeBSD-src-842e39ccd89a966240364f58cc43ff6b5d71d7b6.tar.gz |
Move thread related code from kern_proc.c to kern_thread.c.
Add code to free KSEs and KSEGRPs on exit.
Sort KSE prototypes in proc.h.
Add the missing kse_exit() syscall.
ksetest now does not leak KSEs and KSEGRPS.
Submitted by: (parts) davidxu
Diffstat (limited to 'sys/kern/kern_proc.c')
-rw-r--r-- | sys/kern/kern_proc.c | 258 |
1 files changed, 0 insertions, 258 deletions
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 960421f..a016bba 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -44,7 +44,6 @@ #include <sys/malloc.h> #include <sys/mutex.h> #include <sys/proc.h> -#include <sys/sysproto.h> #include <sys/kse.h> #include <sys/smp.h> #include <sys/sysctl.h> @@ -233,263 +232,6 @@ proc_fini(void *mem, int size) kse_free(ke); } -/* - * KSE is linked onto the idle queue. - */ -void -kse_link(struct kse *ke, struct ksegrp *kg) -{ - struct proc *p = kg->kg_proc; - - TAILQ_INSERT_HEAD(&kg->kg_kseq, ke, ke_kglist); - kg->kg_kses++; - ke->ke_state = KES_UNQUEUED; - ke->ke_proc = p; - ke->ke_ksegrp = kg; - ke->ke_thread = NULL; - ke->ke_oncpu = NOCPU; -} - -void -ksegrp_link(struct ksegrp *kg, struct proc *p) -{ - - TAILQ_INIT(&kg->kg_threads); - TAILQ_INIT(&kg->kg_runq); /* links with td_runq */ - TAILQ_INIT(&kg->kg_slpq); /* links with td_runq */ - TAILQ_INIT(&kg->kg_kseq); /* all kses in ksegrp */ - TAILQ_INIT(&kg->kg_iq); /* idle kses in ksegrp */ - TAILQ_INIT(&kg->kg_lq); /* loan kses in ksegrp */ - kg->kg_proc = p; -/* the following counters are in the -zero- section and may not need clearing */ - kg->kg_numthreads = 0; - kg->kg_runnable = 0; - kg->kg_kses = 0; - kg->kg_idle_kses = 0; - kg->kg_loan_kses = 0; - kg->kg_runq_kses = 0; /* XXXKSE change name */ -/* link it in now that it's consistent */ - p->p_numksegrps++; - TAILQ_INSERT_HEAD(&p->p_ksegrps, kg, kg_ksegrp); -} - -/* - * for a newly created process, - * link up a the structure and its initial threads etc. - */ -void -proc_linkup(struct proc *p, struct ksegrp *kg, - struct kse *ke, struct thread *td) -{ - - TAILQ_INIT(&p->p_ksegrps); /* all ksegrps in proc */ - TAILQ_INIT(&p->p_threads); /* all threads in proc */ - TAILQ_INIT(&p->p_suspended); /* Threads suspended */ - p->p_numksegrps = 0; - p->p_numthreads = 0; - - ksegrp_link(kg, p); - kse_link(ke, kg); - thread_link(td, kg); -} - -int -kse_thr_interrupt(struct thread *td, struct kse_thr_interrupt_args *uap) -{ - - return(ENOSYS); -} - -int -kse_exit(struct thread *td, struct kse_exit_args *uap) -{ - - return(ENOSYS); -} - -int -kse_release(struct thread *td, struct kse_release_args *uap) -{ - struct proc *p; - - p = td->td_proc; - /* KSE-enabled processes only, please. */ - if (p->p_flag & P_KSES) { - PROC_LOCK(p); - mtx_lock_spin(&sched_lock); - thread_exit(); - /* NOTREACHED */ - } - return (EINVAL); -} - -/* struct kse_wakeup_args { - struct kse_mailbox *mbx; -}; */ -int -kse_wakeup(struct thread *td, struct kse_wakeup_args *uap) -{ - struct proc *p; - struct kse *ke, *ke2; - struct ksegrp *kg; - - p = td->td_proc; - /* KSE-enabled processes only, please. */ - if (!(p->p_flag & P_KSES)) - return EINVAL; - if (td->td_standin == NULL) - td->td_standin = thread_alloc(); - ke = NULL; - mtx_lock_spin(&sched_lock); - if (uap->mbx) { - FOREACH_KSEGRP_IN_PROC(p, kg) { - FOREACH_KSE_IN_GROUP(kg, ke2) { - if (ke2->ke_mailbox != uap->mbx) - continue; - if (ke2->ke_state == KES_IDLE) { - ke = ke2; - goto found; - } else { - mtx_unlock_spin(&sched_lock); - td->td_retval[0] = 0; - td->td_retval[1] = 0; - return 0; - } - } - } - } else { - kg = td->td_ksegrp; - ke = TAILQ_FIRST(&kg->kg_iq); - } - if (ke == NULL) { - mtx_unlock_spin(&sched_lock); - return ESRCH; - } -found: - thread_schedule_upcall(td, ke); - mtx_unlock_spin(&sched_lock); - td->td_retval[0] = 0; - td->td_retval[1] = 0; - return 0; -} - -/* - * No new KSEG: first call: use current KSE, don't schedule an upcall - * All other situations, do allocate a new KSE and schedule an upcall on it. - */ -/* struct kse_create_args { - struct kse_mailbox *mbx; - int newgroup; -}; */ -int -kse_create(struct thread *td, struct kse_create_args *uap) -{ - struct kse *newke; - struct kse *ke; - struct ksegrp *newkg; - struct ksegrp *kg; - struct proc *p; - struct kse_mailbox mbx; - int err; - - p = td->td_proc; - if ((err = copyin(uap->mbx, &mbx, sizeof(mbx)))) - return (err); - - p->p_flag |= P_KSES; /* easier to just set it than to test and set */ - kg = td->td_ksegrp; - if (uap->newgroup) { - /* - * If we want a new KSEGRP it doesn't matter whether - * we have already fired up KSE mode before or not. - * We put the process in KSE mode and create a new KSEGRP - * and KSE. If our KSE has not got a mailbox yet then - * that doesn't matter, just leave it that way. It will - * ensure that this thread stay BOUND. It's possible - * that the call came form a threaded library and the main - * program knows nothing of threads. - */ - newkg = ksegrp_alloc(); - bzero(&newkg->kg_startzero, RANGEOF(struct ksegrp, - kg_startzero, kg_endzero)); - bcopy(&kg->kg_startcopy, &newkg->kg_startcopy, - RANGEOF(struct ksegrp, kg_startcopy, kg_endcopy)); - newke = kse_alloc(); - } else { - /* - * Otherwise, if we have already set this KSE - * to have a mailbox, we want to make another KSE here, - * but only if there are not already the limit, which - * is 1 per CPU max. - * - * If the current KSE doesn't have a mailbox we just use it - * and give it one. - * - * Because we don't like to access - * the KSE outside of schedlock if we are UNBOUND, - * (because it can change if we are preempted by an interrupt) - * we can deduce it as having a mailbox if we are UNBOUND, - * and only need to actually look at it if we are BOUND, - * which is safe. - */ - if ((td->td_flags & TDF_UNBOUND) || td->td_kse->ke_mailbox) { -#if 0 /* while debugging */ -#ifdef SMP - if (kg->kg_kses > mp_ncpus) -#endif - return (EPROCLIM); -#endif - newke = kse_alloc(); - } else { - newke = NULL; - } - newkg = NULL; - } - if (newke) { - bzero(&newke->ke_startzero, RANGEOF(struct kse, - ke_startzero, ke_endzero)); -#if 0 - bcopy(&ke->ke_startcopy, &newke->ke_startcopy, - RANGEOF(struct kse, ke_startcopy, ke_endcopy)); -#endif - PROC_LOCK(p); - if (SIGPENDING(p)) - newke->ke_flags |= KEF_ASTPENDING; - PROC_UNLOCK(p); - /* For the first call this may not have been set */ - if (td->td_standin == NULL) { - td->td_standin = thread_alloc(); - } - mtx_lock_spin(&sched_lock); - if (newkg) - ksegrp_link(newkg, p); - else - newkg = kg; - kse_link(newke, newkg); - newke->ke_mailbox = uap->mbx; - newke->ke_upcall = mbx.km_func; - bcopy(&mbx.km_stack, &newke->ke_stack, sizeof(stack_t)); - thread_schedule_upcall(td, newke); - mtx_unlock_spin(&sched_lock); - } else { - /* - * If we didn't allocate a new KSE then the we are using - * the exisiting (BOUND) kse. - */ - ke = td->td_kse; - ke->ke_mailbox = uap->mbx; - ke->ke_upcall = mbx.km_func; - bcopy(&mbx.km_stack, &ke->ke_stack, sizeof(stack_t)); - } - /* - * Fill out the KSE-mode specific fields of the new kse. - */ - - td->td_retval[0] = 0; - td->td_retval[1] = 0; - return (0); -} - /* * Is p an inferior of the current process? */ |