From owner-freebsd-threads@FreeBSD.ORG Sun Feb 20 15:57:07 2005 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C5EFB16A4CE for ; Sun, 20 Feb 2005 15:57:07 +0000 (GMT) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5334E43D31 for ; Sun, 20 Feb 2005 15:57:07 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) j1KFv3Gp008783; Sun, 20 Feb 2005 10:57:04 -0500 (EST) Date: Sun, 20 Feb 2005 10:57:03 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Kazuaki Oda In-Reply-To: <42187232.2060308@highway.ne.jp> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) cc: threads@freebsd.org Subject: Re: thread accounting in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Feb 2005 15:57:07 -0000 On Sun, 20 Feb 2005, Kazuaki Oda wrote: > Daniel Eischen wrote: > > >If there was no running thread before kse_wait(), then after > >kse_wait() returns and if there are completed threads, then > >either one thread completed or N threads completed. Either > >way, they are all added to the end of the run queue. But > >the run queue must have been empty to begin with, otherwise > >kse_wait() would not have been called. So it doesn't matter > >whether they are added to the head or the end of the queue. > >If one thread completes, then it will be run right away > >since it will be the only thread in the queue. If N threads > >complete (assuming they are all at the same priority) then > >the first thread pulled from the completed list will be > >run first since it will be the first thread added to the > >run queue. > > Did you try to run the program attached to my past mail? If you run it > under X11 terminal on a UP machine, you probably get a unfair result. I don't get much of a difference with and without patch at end. Depending on what your threads are blocking on, I think it can be random. with patch ---------- thread 00: 4716 thread 01: 4307 thread 02: 3631 thread 03: 3698 thread 04: 3455 without patch ------------- thread 00: 4289 thread 01: 2903 thread 02: 4352 thread 03: 3444 thread 04: 4405 -- DE Index: thread/thr_kern.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/thr_kern.c,v retrieving revision 1.116 diff -u -r1.116 thr_kern.c --- thread/thr_kern.c 18 Dec 2004 18:07:37 -0000 1.116 +++ thread/thr_kern.c 20 Feb 2005 15:36:33 -0000 @@ -1465,14 +1465,22 @@ static void kse_check_completed(struct kse *kse) { - struct pthread *thread; + TAILQ_HEAD(, pthread) completeq; + struct pthread *thread, *next; struct kse_thr_mailbox *completed; int sig; if ((completed = kse->k_kcb->kcb_kmbx.km_completed) != NULL) { + TAILQ_INIT(&completeq); kse->k_kcb->kcb_kmbx.km_completed = NULL; while (completed != NULL) { thread = completed->tm_udata; + TAILQ_INSERT_HEAD(&completeq, thread, pqe); + completed = completed->tm_next; + } + for (thread = TAILQ_FIRST(&completeq); thread != NULL; + thread = next) { + next = TAILQ_NEXT(thread, pqe); DBG_MSG("Found completed thread %p, name %s\n", thread, (thread->name == NULL) ? "none" : thread->name); @@ -1505,7 +1513,6 @@ &thread->tcb->tcb_tmbx.tm_syncsig); thread->tcb->tcb_tmbx.tm_syncsig.si_signo = 0; } - completed = completed->tm_next; } } }