Date: Sun, 20 Feb 2005 20:19:14 +0900 From: Kazuaki Oda <kaakun@highway.ne.jp> To: Daniel Eischen <deischen@freebsd.org> Cc: threads@freebsd.org Subject: Re: thread accounting in libpthread Message-ID: <42187232.2060308@highway.ne.jp> In-Reply-To: <Pine.GSO.4.43.0502191404330.22284-100000@sea.ntplx.net> References: <Pine.GSO.4.43.0502191404330.22284-100000@sea.ntplx.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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 traced the program, and so I have noticed that the program repeats the following operations: thread 00 is switched in thread 00 outputs many lines thread 00 is blocked in the kernel thread 01 is switched in thread 01 outputs 1 line thread 01 is blocked in the kernel thread 02 is switched in thread 02 outputs 1 line thread 02 is blocked in the kernel thread 03 is switched in thread 03 outputs 1 line thread 03 is blocked in the kernel thread 04 is switched in thread 04 outputs 1 line thread 04 is blocked in the kernel kse_wait() is called because there is no thread ready to run we return from kse_wait(), and kse_check_completed() is called we add thread 04 to the tail of run queue we add thread 03 to the tail of run queue we add thread 02 to the tail of run queue we add thread 01 to the tail of run queue we add thread 00 to the tail of run queue we return from kse_check_completed() thread 04 is switched in thread 04 outputs many lines thread 04 is blocked in the kernel thread 03 is switched in thread 03 outputs 1 line thread 03 is blocked in the kernel thread 02 is switched in thread 02 outputs 1 line thread 02 is blocked in the kernel thread 01 is switched in thread 01 outputs 1 line thread 01 is blocked in the kernel thread 00 is switched in thread 00 outputs 1 line thread 00 is blocked in the kernel kse_wait() is called because there is no thread ready to run we return from kse_wait(), and kse_check_completed() is called we add thread 00 to the tail of run queue we add thread 01 to the tail of run queue we add thread 02 to the tail of run queue we add thread 03 to the tail of run queue we add thread 04 to the tail of run queue we return from kse_check_completed() Because the program repeats the above operations, I get a result: -------------------- thread 00: 55666 thread 01: 1161 thread 02: 1112 thread 03: 1112 thread 04: 55494 -------------------- Is this a expected result? At least this is not for me. It seems unfair. As we just add completed threads to the tail of run queue in the order which kernel returns, thread 00 and thread 04 get much time slice... -------------------- Kazuaki Oda
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?42187232.2060308>