summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_resource.c
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2010-10-09 02:50:23 +0000
committerdavidxu <davidxu@FreeBSD.org>2010-10-09 02:50:23 +0000
commit55194e796cd9e8eb27d9bb4ec9f07184e390d01a (patch)
tree84ad0652e39fc58da6ca522cc6bf55a188109780 /sys/kern/kern_resource.c
parent6afff59f3c11c8f879672f8dbcb0a74bcbae79a5 (diff)
downloadFreeBSD-src-55194e796cd9e8eb27d9bb4ec9f07184e390d01a.zip
FreeBSD-src-55194e796cd9e8eb27d9bb4ec9f07184e390d01a.tar.gz
Create a global thread hash table to speed up thread lookup, use
rwlock to protect the table. In old code, thread lookup is done with process lock held, to find a thread, kernel has to iterate through process and thread list, this is quite inefficient. With this change, test shows in extreme case performance is dramatically improved. Earlier patch was reviewed by: jhb, julian
Diffstat (limited to 'sys/kern/kern_resource.c')
-rw-r--r--sys/kern/kern_resource.c36
1 files changed, 13 insertions, 23 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index ec2d6b6..09c8603 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -295,25 +295,23 @@ rtprio_thread(struct thread *td, struct rtprio_thread_args *uap)
else
cierror = 0;
- /*
- * Though lwpid is unique, only current process is supported
- * since there is no efficient way to look up a LWP yet.
- */
- p = td->td_proc;
- PROC_LOCK(p);
+ if (uap->lwpid == 0 || uap->lwpid == td->td_tid) {
+ p = td->td_proc;
+ td1 = td;
+ PROC_LOCK(p);
+ } else {
+ /* Only look up thread in current process */
+ td1 = tdfind(uap->lwpid, curproc->p_pid);
+ if (td1 == NULL)
+ return (ESRCH);
+ p = td1->td_proc;
+ }
switch (uap->function) {
case RTP_LOOKUP:
if ((error = p_cansee(td, p)))
break;
- if (uap->lwpid == 0 || uap->lwpid == td->td_tid)
- td1 = td;
- else
- td1 = thread_find(p, uap->lwpid);
- if (td1 != NULL)
- pri_to_rtp(td1, &rtp);
- else
- error = ESRCH;
+ pri_to_rtp(td1, &rtp);
PROC_UNLOCK(p);
return (copyout(&rtp, uap->rtp, sizeof(struct rtprio)));
case RTP_SET:
@@ -337,15 +335,7 @@ rtprio_thread(struct thread *td, struct rtprio_thread_args *uap)
if (error)
break;
}
-
- if (uap->lwpid == 0 || uap->lwpid == td->td_tid)
- td1 = td;
- else
- td1 = thread_find(p, uap->lwpid);
- if (td1 != NULL)
- error = rtp_to_pri(&rtp, td1);
- else
- error = ESRCH;
+ error = rtp_to_pri(&rtp, td1);
break;
default:
error = EINVAL;
OpenPOWER on IntegriCloud