diff options
author | trasz <trasz@FreeBSD.org> | 2011-03-31 19:22:11 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2011-03-31 19:22:11 +0000 |
commit | 4c83b1bba4b449bdd0b62585ba1ebe3163ef107c (patch) | |
tree | 4d811cbdd5ef5640877c96685d01fe33cad06e1e /sys/kern/kern_thr.c | |
parent | 596c078ed8b0a61497f5b46a4d05593182e0f69d (diff) | |
download | FreeBSD-src-4c83b1bba4b449bdd0b62585ba1ebe3163ef107c.zip FreeBSD-src-4c83b1bba4b449bdd0b62585ba1ebe3163ef107c.tar.gz |
Enable accounting for RACCT_NPROC and RACCT_NTHR.
Sponsored by: The FreeBSD Foundation
Reviewed by: kib (earlier version)
Diffstat (limited to 'sys/kern/kern_thr.c')
-rw-r--r-- | sys/kern/kern_thr.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c index 58c3806..7011a53 100644 --- a/sys/kern/kern_thr.c +++ b/sys/kern/kern_thr.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include <sys/priv.h> #include <sys/proc.h> #include <sys/posix4.h> +#include <sys/racct.h> #include <sys/resourcevar.h> #include <sys/rwlock.h> #include <sys/sched.h> @@ -184,10 +185,18 @@ create_thread(struct thread *td, mcontext_t *ctx, } } + PROC_LOCK(td->td_proc); + error = racct_add(p, RACCT_NTHR, 1); + PROC_UNLOCK(td->td_proc); + if (error != 0) + return (EPROCLIM); + /* Initialize our td */ newtd = thread_alloc(0); - if (newtd == NULL) - return (ENOMEM); + if (newtd == NULL) { + error = ENOMEM; + goto fail; + } /* * Try the copyout as soon as we allocate the td so we don't @@ -203,7 +212,8 @@ create_thread(struct thread *td, mcontext_t *ctx, (parent_tid != NULL && suword_lwpid(parent_tid, newtd->td_tid))) { thread_free(newtd); - return (EFAULT); + error = EFAULT; + goto fail; } bzero(&newtd->td_startzero, @@ -220,7 +230,7 @@ create_thread(struct thread *td, mcontext_t *ctx, if (error != 0) { thread_free(newtd); crfree(td->td_ucred); - return (error); + goto fail; } } else { /* Set up our machine context. */ @@ -233,7 +243,7 @@ create_thread(struct thread *td, mcontext_t *ctx, if (error != 0) { thread_free(newtd); crfree(td->td_ucred); - return (error); + goto fail; } } @@ -265,6 +275,12 @@ create_thread(struct thread *td, mcontext_t *ctx, thread_unlock(newtd); return (0); + +fail: + PROC_LOCK(p); + racct_sub(p, RACCT_NTHR, 1); + PROC_UNLOCK(p); + return (error); } int @@ -294,7 +310,10 @@ thr_exit(struct thread *td, struct thr_exit_args *uap) } rw_wlock(&tidhash_lock); + PROC_LOCK(p); + racct_sub(p, RACCT_NTHR, 1); + /* * Shutting down last thread in the proc. This will actually * call exit() in the trampoline when it returns. |