Date: Sun, 20 Feb 2005 10:57:03 -0500 (EST) From: Daniel Eischen <deischen@freebsd.org> To: Kazuaki Oda <kaakun@highway.ne.jp> Cc: threads@freebsd.org Subject: Re: thread accounting in libpthread Message-ID: <Pine.GSO.4.43.0502201054060.26607-100000@sea.ntplx.net> In-Reply-To: <42187232.2060308@highway.ne.jp>
next in thread | previous in thread | raw e-mail | index | archive | help
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; } } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.43.0502201054060.26607-100000>