From owner-svn-src-head@FreeBSD.ORG Tue Apr 24 09:05:30 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id DE073106564A for ; Tue, 24 Apr 2012 09:05:29 +0000 (UTC) (envelope-from listlog2011@gmail.com) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id BF25A8FC15 for ; Tue, 24 Apr 2012 09:05:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q3O95S0T010401 for ; Tue, 24 Apr 2012 09:05:29 GMT (envelope-from listlog2011@gmail.com) Message-ID: <4F966CD6.6030302@gmail.com> Date: Tue, 24 Apr 2012 17:05:26 +0800 From: David Xu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: svn-src-head@freebsd.org References: <201204232056.q3NKu6hU015276@svn.freebsd.org> In-Reply-To: <201204232056.q3NKu6hU015276@svn.freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: svn commit: r234616 - in head/sys: kern sys X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: davidxu@freebsd.org List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Apr 2012 09:05:30 -0000 On 2012/4/24 4:56, Konstantin Belousov wrote: > Author: kib > Date: Mon Apr 23 20:56:05 2012 > New Revision: 234616 > URL: http://svn.freebsd.org/changeset/base/234616 > > Log: > Allow for the process information sysctls to accept a thread id in addition > to the process id. It follows the ptrace(2) interface and allows debugging > libraries to use thread ids directly, without slow and verbose conversion > of thread id into pid. > > The PGET_NOTID flag is provided to allow a specific sysctl to disallow > this behaviour. All current callers of pget(9) have useful semantic to > operate on tid and do not need this flag. > > Reviewed by: jhb, trocini > MFC after: 1 week > > Modified: > head/sys/kern/kern_proc.c > head/sys/sys/proc.h > > Modified: head/sys/kern/kern_proc.c > ============================================================================== > --- head/sys/kern/kern_proc.c Mon Apr 23 20:53:50 2012 (r234615) > +++ head/sys/kern/kern_proc.c Mon Apr 23 20:56:05 2012 (r234616) > @@ -309,6 +309,30 @@ pfind(pid) > return (p); > } > > +static struct proc * > +pfind_tid(pid_t tid) > +{ > + struct proc *p; > + struct thread *td; > + > + sx_slock(&allproc_lock); > + FOREACH_PROC_IN_SYSTEM(p) { > + PROC_LOCK(p); > + if (p->p_state == PRS_NEW) { > + PROC_UNLOCK(p); > + continue; > + } > + FOREACH_THREAD_IN_PROC(p, td) { > + if (td->td_tid == tid) > + goto found; > + } > + PROC_UNLOCK(p); > + } > +found: > + sx_sunlock(&allproc_lock); > + return (p); > +} > + There is a tdfind(tid, pid) function which is faster in kern_thread.c, is it not good enough or is there any problem I don't see ? :( > /* > * Locate a process group by number. > * The caller must hold proctree_lock. > @@ -339,7 +363,12 @@ pget(pid_t pid, int flags, struct proc * > struct proc *p; > int error; > > - p = pfind(pid); > + if (pid<= PID_MAX) > + p = pfind(pid); > + else if ((flags& PGET_NOTID) == 0) > + p = pfind_tid(pid); > + else > + p = NULL; > if (p == NULL) > return (ESRCH); > if ((flags& PGET_CANSEE) != 0) { > > Modified: head/sys/sys/proc.h > ============================================================================== > --- head/sys/sys/proc.h Mon Apr 23 20:53:50 2012 (r234615) > +++ head/sys/sys/proc.h Mon Apr 23 20:56:05 2012 (r234616) > @@ -840,6 +840,7 @@ struct proc *zpfind(pid_t); /* Find zom > #define PGET_ISCURRENT 0x00008 /* Check that the found process is current. */ > #define PGET_NOTWEXIT 0x00010 /* Check that the process is not in P_WEXIT. */ > #define PGET_NOTINEXEC 0x00020 /* Check that the process is not in P_INEXEC. */ > +#define PGET_NOTID 0x00040 /* Do not assume tid if pid> PID_MAX. */ > > #define PGET_WANTREAD (PGET_HOLD | PGET_CANDEBUG | PGET_NOTWEXIT) > > _______________________________________________ > svn-src-head@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/svn-src-head > To unsubscribe, send any mail to "svn-src-head-unsubscribe@freebsd.org" >