Date: Thu, 21 Apr 2005 07:25:49 GMT From: David Xu <davidxu@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 75658 for review Message-ID: <200504210725.j3L7Pnen087212@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=75658 Change 75658 by davidxu@davidxu_celeron on 2005/04/21 07:24:56 rename thr_create2 to thr_new. merge most code in thr_new and thr_create. Affected files ... .. //depot/projects/davidxu_thread/src/sys/kern/init_sysent.c#9 edit .. //depot/projects/davidxu_thread/src/sys/kern/kern_thr.c#17 edit .. //depot/projects/davidxu_thread/src/sys/kern/syscalls.c#9 edit .. //depot/projects/davidxu_thread/src/sys/kern/syscalls.master#9 edit .. //depot/projects/davidxu_thread/src/sys/sys/syscall.h#8 edit .. //depot/projects/davidxu_thread/src/sys/sys/syscall.mk#8 edit .. //depot/projects/davidxu_thread/src/sys/sys/sysproto.h#8 edit .. //depot/projects/davidxu_thread/src/sys/sys/thr.h#8 edit Differences ... ==== //depot/projects/davidxu_thread/src/sys/kern/init_sysent.c#9 (text+ko) ==== @@ -483,5 +483,5 @@ { SYF_MPSAFE | AS(setaudit_addr_args), (sy_call_t *)lkmressys }, /* 452 = setaudit_addr */ { SYF_MPSAFE | AS(auditctl_args), (sy_call_t *)lkmressys }, /* 453 = auditctl */ { SYF_MPSAFE | AS(_umtx_op_args), (sy_call_t *)_umtx_op }, /* 454 = _umtx_op */ - { SYF_MPSAFE | AS(thr_create2_args), (sy_call_t *)thr_create2 }, /* 455 = thr_create2 */ + { SYF_MPSAFE | AS(thr_new_args), (sy_call_t *)thr_new }, /* 455 = thr_new */ }; ==== //depot/projects/davidxu_thread/src/sys/kern/kern_thr.c#17 (text+ko) ==== @@ -57,6 +57,13 @@ SYSCTL_INT(_kern_threads, OID_AUTO, thr_concurrency, CTLFLAG_RW, &thr_concurrency, 0, "a concurrency value if not default"); +static int create_thread(struct thread *td, mcontext_t *ctx, + void (*start_func)(void *), void *arg, + char *stack_base, size_t stack_size, + char *tls_base, + long *child_tid, long *parent_tid, + int flags); + /* * System call interface. */ @@ -64,128 +71,42 @@ thr_create(struct thread *td, struct thr_create_args *uap) /* ucontext_t *ctx, long *id, int flags */ { - struct thread *newtd; ucontext_t ctx; - long id; int error; - struct ksegrp *kg, *newkg; - struct proc *p; - int scope_sys, linkkg; - p = td->td_proc; - kg = td->td_ksegrp; if ((error = copyin(uap->ctx, &ctx, sizeof(ctx)))) return (error); - /* Have race condition but it is cheap. */ - if ((p->p_numksegrps >= max_groups_per_proc) || - (p->p_numthreads >= max_threads_per_proc)) { - return (EPROCLIM); - } + error = create_thread(td, &ctx.uc_mcontext, NULL, NULL, + NULL, 0, NULL, uap->id, NULL, uap->flags); + return (error); +} - scope_sys = (uap->flags & THR_SYSTEM_SCOPE) != 0; - if (thr_scope == 1) - scope_sys = 0; - else if (thr_scope == 2) - scope_sys = 1; +int +thr_new(struct thread *td, struct thr_new_args *uap) + /* struct thr_param * */ +{ + struct thr_param param; + int error; - /* Initialize our td and new ksegrp.. */ - newtd = thread_alloc(); - - /* - * Try the copyout as soon as we allocate the td so we don't have to - * tear things down in a failure case below. - */ - id = newtd->td_tid; - if ((error = copyout(&id, uap->id, sizeof(long)))) { - thread_free(newtd); + if (uap->param_size != sizeof(param)) + return (EINVAL); + if ((error = copyin(uap->param, ¶m, sizeof(param)))) return (error); - } - bzero(&newtd->td_startzero, - __rangeof(struct thread, td_startzero, td_endzero)); - bcopy(&td->td_startcopy, &newtd->td_startcopy, - __rangeof(struct thread, td_startcopy, td_endcopy)); - newtd->td_proc = td->td_proc; - newtd->td_ucred = crhold(td->td_ucred); - - /* Set up our machine context. */ - cpu_set_upcall(newtd, td); - error = set_mcontext(newtd, &ctx.uc_mcontext); - if (error != 0) { - thread_free(newtd); - crfree(td->td_ucred); - goto out; - } - - if ((td->td_proc->p_flag & P_HADTHREADS) == 0) { - p->p_procscopegrp = kg; - mtx_lock_spin(&sched_lock); - sched_set_concurrency(kg, - thr_concurrency ? thr_concurrency : (2*mp_ncpus)); - mtx_unlock_spin(&sched_lock); - } - - linkkg = 0; - if (scope_sys) { - linkkg = 1; - 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)); - sched_init_concurrency(newkg); - PROC_LOCK(td->td_proc); - } else { -retry: - PROC_LOCK(td->td_proc); - if ((newkg = p->p_procscopegrp) == NULL) { - PROC_UNLOCK(p); - 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)); - PROC_LOCK(p); - if (p->p_procscopegrp == NULL) { - p->p_procscopegrp = newkg; - sched_init_concurrency(newkg); - sched_set_concurrency(newkg, - thr_concurrency ? thr_concurrency : (2*mp_ncpus)); - linkkg = 1; - } else { - PROC_UNLOCK(p); - ksegrp_free(newkg); - goto retry; - } - } - } - - td->td_proc->p_flag |= P_HADTHREADS; - newtd->td_sigmask = td->td_sigmask; - mtx_lock_spin(&sched_lock); - if (linkkg) - ksegrp_link(newkg, p); - thread_link(newtd, newkg); - PROC_UNLOCK(p); - - /* let the scheduler know about these things. */ - if (linkkg) - sched_fork_ksegrp(td, newkg); - sched_fork_thread(td, newtd); - TD_SET_CAN_RUN(newtd); - if ((uap->flags & THR_SUSPENDED) == 0) - setrunqueue(newtd, SRQ_BORING); - mtx_unlock_spin(&sched_lock); - -out: + error = create_thread(td, NULL, param.start_func, param.arg, + param.stack_base, param.stack_size, param.tls_base, + param.child_tid, param.parent_tid, param.flags); return (error); } -int -thr_create2(struct thread *td, struct thr_create2_args *uap) - /* struct thr_param * */ +static int +create_thread(struct thread *td, mcontext_t *ctx, + void (*start_func)(void *), void *arg, + char *stack_base, size_t stack_size, + char *tls_base, + long *child_tid, long *parent_tid, + int flags) { - struct thr_param param; stack_t stack; struct thread *newtd; struct ksegrp *kg, *newkg; @@ -193,12 +114,9 @@ long id; int error, scope_sys, linkkg; + error = 0; p = td->td_proc; kg = td->td_ksegrp; - if (uap->param_size != sizeof(param)) - return (EINVAL); - if ((error = copyin(uap->param, ¶m, sizeof(param)))) - return (error); /* Have race condition but it is cheap. */ if ((p->p_numksegrps >= max_groups_per_proc) || @@ -207,7 +125,7 @@ } /* Check PTHREAD_SCOPE_SYSTEM */ - scope_sys = (param.flags & THR_SYSTEM_SCOPE) != 0; + scope_sys = (flags & THR_SYSTEM_SCOPE) != 0; /* sysctl overrides user's flag */ if (thr_scope == 1) @@ -228,9 +146,11 @@ * memory is freed before parent thread can access it. */ id = newtd->td_tid; - if ((error = copyout(&id, param.child_tid, sizeof(long))) || - (error = copyout(&id, param.parent_tid, sizeof(long)))) { - thread_free(newtd); + if ((child_tid != NULL && + (error = copyout(&id, child_tid, sizeof(long)))) || + (parent_tid != NULL && + (error = copyout(&id, parent_tid, sizeof(long))))) { + thread_free(newtd); return (error); } bzero(&newtd->td_startzero, @@ -240,15 +160,25 @@ newtd->td_proc = td->td_proc; newtd->td_ucred = crhold(td->td_ucred); - /* Set up our machine context. */ - stack.ss_sp = param.stack_base; - stack.ss_size = param.stack_size; - /* Fork user context from current thread. */ cpu_set_upcall(newtd, td); - /* Set upcall address to user thread entry function. */ - cpu_set_upcall_kse(newtd, param.start_func, param.arg, &stack); - /* Setup user TLS address and TLS pointer register. */ - cpu_set_user_tls(newtd, param.tls_base); + + if (ctx != NULL) { /* old way to set user context */ + error = set_mcontext(newtd, ctx); + if (error != 0) { + thread_free(newtd); + crfree(td->td_ucred); + return (error); + } + } else { + /* Set up our machine context. */ + stack.ss_sp = stack_base; + stack.ss_size = stack_size; + /* Set upcall address to user thread entry function. */ + cpu_set_upcall_kse(newtd, start_func, arg, &stack); + /* Setup user TLS address and TLS pointer register. */ + cpu_set_user_tls(newtd, tls_base); + } + if ((td->td_proc->p_flag & P_HADTHREADS) == 0) { /* Treat initial thread as it has PTHREAD_SCOPE_PROCESS. */ p->p_procscopegrp = kg; @@ -310,7 +240,7 @@ sched_fork_ksegrp(td, newkg); sched_fork_thread(td, newtd); TD_SET_CAN_RUN(newtd); - if ((param.flags & THR_SUSPENDED) == 0) + if ((flags & THR_SUSPENDED) == 0) setrunqueue(newtd, SRQ_BORING); mtx_unlock_spin(&sched_lock); ==== //depot/projects/davidxu_thread/src/sys/kern/syscalls.c#9 (text+ko) ==== @@ -462,5 +462,5 @@ "setaudit_addr", /* 452 = setaudit_addr */ "auditctl", /* 453 = auditctl */ "_umtx_op", /* 454 = _umtx_op */ - "thr_create2", /* 455 = thr_create2 */ + "thr_new", /* 455 = thr_new */ }; ==== //depot/projects/davidxu_thread/src/sys/kern/syscalls.master#9 (text+ko) ==== @@ -645,7 +645,7 @@ 453 MNOSTD { int auditctl(int cmd, char *path); } 454 MSTD { int _umtx_op(struct umtx *umtx, int op, long id, void *uaddr,\ void *uaddr2); } -455 MSTD { int thr_create2(struct thr_param *param, int param_size); } +455 MSTD { int thr_new(struct thr_param *param, int param_size); } ; Please copy any additions and changes to the following compatability tables: ; sys/compat/freebsd32/syscalls.master ==== //depot/projects/davidxu_thread/src/sys/sys/syscall.h#8 (text+ko) ==== @@ -368,5 +368,5 @@ #define SYS_setaudit_addr 452 #define SYS_auditctl 453 #define SYS__umtx_op 454 -#define SYS_thr_create2 455 +#define SYS_thr_new 455 #define SYS_MAXSYSCALL 456 ==== //depot/projects/davidxu_thread/src/sys/sys/syscall.mk#8 (text+ko) ==== @@ -310,4 +310,4 @@ setaudit_addr.o \ auditctl.o \ _umtx_op.o \ - thr_create2.o + thr_new.o ==== //depot/projects/davidxu_thread/src/sys/sys/sysproto.h#8 (text+ko) ==== @@ -1349,7 +1349,7 @@ char uaddr_l_[PADL_(void *)]; void * uaddr; char uaddr_r_[PADR_(void *)]; char uaddr2_l_[PADL_(void *)]; void * uaddr2; char uaddr2_r_[PADR_(void *)]; }; -struct thr_create2_args { +struct thr_new_args { char param_l_[PADL_(struct thr_param *)]; struct thr_param * param; char param_r_[PADR_(struct thr_param *)]; char param_size_l_[PADL_(int)]; int param_size; char param_size_r_[PADR_(int)]; }; @@ -1659,7 +1659,7 @@ int setaudit_addr(struct thread *, struct setaudit_addr_args *); int auditctl(struct thread *, struct auditctl_args *); int _umtx_op(struct thread *, struct _umtx_op_args *); -int thr_create2(struct thread *, struct thr_create2_args *); +int thr_new(struct thread *, struct thr_new_args *); #ifdef COMPAT_43 ==== //depot/projects/davidxu_thread/src/sys/sys/thr.h#8 (text+ko) ==== @@ -55,7 +55,7 @@ #ifndef _KERNEL int thr_create(ucontext_t *ctx, long *id, int flags); -int thr_create2(struct thr_param *param, int param_size); +int thr_new(struct thr_param *param, int param_size); int thr_self(long *id); void thr_exit(long *state); int thr_kill(long id, int sig);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200504210725.j3L7Pnen087212>