From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JbJYH-0002MU-I4 for qemu-devel@nongnu.org; Mon, 17 Mar 2008 13:55:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JbJYB-0002KH-W8 for qemu-devel@nongnu.org; Mon, 17 Mar 2008 13:55:13 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JbJYB-0002KE-O8 for qemu-devel@nongnu.org; Mon, 17 Mar 2008 13:55:07 -0400 Received: from ug-out-1314.google.com ([66.249.92.169]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JbJYA-00039G-Q7 for qemu-devel@nongnu.org; Mon, 17 Mar 2008 13:55:07 -0400 Received: by ug-out-1314.google.com with SMTP id m2so666548uge.4 for ; Mon, 17 Mar 2008 10:55:05 -0700 (PDT) Message-ID: <5d6222a80803171055g260d6742u72c82876403758c6@mail.gmail.com> Date: Mon, 17 Mar 2008 14:55:03 -0300 From: "Glauber Costa" Subject: Re: [Qemu-devel] [PATCH] use a thread id variable In-Reply-To: <47D3F9AF.2030408@codefidence.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <12047472711034-git-send-email-gcosta@redhat.com> <12047472772114-git-send-email-gcosta@redhat.com> <47D3AD53.6030809@codefidence.com> <20080309115826.GA8077@shareable.org> <47D3F9AF.2030408@codefidence.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gilad Ben-Yossef Cc: kvm-devel@lists.sourceforge.net, chrisw@sous-sol.org, qemu-devel@nongnu.org, Glauber Costa On Sun, Mar 9, 2008 at 11:52 AM, Gilad Ben-Yossef wrote: > Jamie Lokier wrote: > > Gilad Ben-Yossef wrote: > >> Glauber Costa wrote: > >>> This patch introduces a "thread_id" variable to CPUState. > >>> It's duty will be to hold the process, or more generally, thread > >>> id of the current executing cpu > >>> > >>> env->nb_watchpoints = 0; > >>> +#ifdef __WIN32 > >>> + env->thread_id = GetCurrentProcessId(); > >>> +#else > >>> + env->thread_id = getpid(); > >>> +#endif > >>> *penv = env; > >> hmm... maybe I'm missing something, but in Linux at least I think you > >> would prefer this to be gettid() rather then getpid as each CPU has it's > >> own thread, not a different process. > > > > On most platforms, getpid() returns the same value for all threads, so > > it's not useful as a thread id. > > Of course it does - this what POSIX says it should do (Linux 2.4 in > compliance not withstanding). Which is why I suggested to use on Linux > the non standard gettid() rather then getpid > > > > > On Linux, it depends which version of threads. The old package, > > LinuxThreads, has different getpid() for each thread. The current one, > > NPTL, has them all the same. > > > LinuxThreads behavior is wrong according to the POSIX standard. Of > course, nothing else was possible with 2.4 kernels, so this is not an > error on LinuxThreads coders part. > > > > > What you're supposed to do with pthreads in general is use pthread_self(). > > Unfortunately, AFAIK the opaque handle that pthread_self() returns is > not quite meaningless outside of the process whereas what the non > standard gettid() returns can actually be used to identify a thread from > "outside" the process, like the shell. > Identifying a thread from the outside world is _exactly_ my intent here, so pthread_self won't do. I can easily write a wrapper to gettid() and use it. It would make the kvm specific patch not-necessary, which is good. The reason I used getpid in the first place, is that all raw qemu cpus are in the same process anyway. It's up to you, guys. -- Glauber Costa. "Free as in Freedom" http://glommer.net "The less confident you are, the more serious you have to act."