From owner-freebsd-threads@FreeBSD.ORG Sat Feb 19 13:18:31 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 41E4D16A4CE; Sat, 19 Feb 2005 13:18:31 +0000 (GMT) Received: from mx.highway.ne.jp (pip7.usen.ad.jp [61.122.117.245]) by mx1.FreeBSD.org (Postfix) with ESMTP id EE82043D4C; Sat, 19 Feb 2005 13:18:29 +0000 (GMT) (envelope-from kaakun@highway.ne.jp) Received: from [219.195.104.17] (helo=[192.168.11.16]) by pop12.isp.us-com.jp with esmtp (Mail 4.20) id 1D2UVA-0004A8-Ks; Sat, 19 Feb 2005 22:18:28 +0900 Message-ID: <42173C82.7040408@highway.ne.jp> Date: Sat, 19 Feb 2005 22:17:54 +0900 From: Kazuaki Oda User-Agent: Mozilla Thunderbird 1.0 (X11/20050101) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Daniel Eischen References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------070804040805030500010306" cc: threads@freebsd.org Subject: Re: thread accounting in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Feb 2005 13:18:31 -0000 This is a multi-part message in MIME format. --------------070804040805030500010306 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Daniel Eischen wrote: >On Sat, 19 Feb 2005, Kazuaki Oda wrote: > > >>And while looking at thr_kern.c, I've had one more question. >>In kse_switchout_thread, after calling thr_accounting thread is placed >>at the tail of run queue or at the head of it according to >>thread->slice_usec. >>But in kse_check_completed, thread is just placed at the tail of run queue. >>Is there any reason why thread is not placed at the head of run queue in >>case of thread->slice_usec != -1? >> >> > >Because it already blocked and we don't want to needlessly >switch out a currently running thread that hasn't used its >quantum. > > > Blocked? I think that completed threads are *not* blocked and they are ready to run except for suspended. And, kse_check_completed could be called after calling kse_wait. In this case there is currently no running thread. The reason why I am researching libpthread is that the attached program shows -------------------- thread 00: 55666 thread 01: 1161 thread 02: 1112 thread 03: 1112 thread 04: 55494 -------------------- on xterm on my UP machine. This is a unexpected result. It seems to me that libpthread does unfair scheduling. But on SMP machine that program shows expected result and on console too... -------------------- Kazuaki Oda --------------070804040805030500010306 Content-Type: text/plain; name="thrdtest.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="thrdtest.c" #include #include #include #include #include #include #include #define NTHREADS 5 #define BUFSZ 128 void *func(void *arg); typedef struct { int id; } funcarg; int stop = 0; long counts[NTHREADS]; int main(void) { pthread_t tids[NTHREADS]; funcarg *arg; int rval; int i; for (i = 0; i < NTHREADS; i++) { if ((arg = malloc(sizeof(funcarg))) == NULL) err(1, "malloc"); arg->id = i; if ((rval = pthread_create(&tids[i], NULL, func, arg)) != 0) errc(1, rval, "pthread_create"); } sleep(10); stop = 1; for (i = 0; i < NTHREADS; i++) { if ((rval = pthread_join(tids[i], NULL)) != 0) errc(1, rval, "pthread_join"); } printf("--------------------\n"); for (i = 0; i < NTHREADS; i++) printf("thread %02d: %ld\n", i, counts[i]); printf("--------------------\n"); return 0; } void *func(void *arg) { char buf[BUFSZ]; int id; int n; id = ((funcarg *)arg)->id; free(arg); while (!stop) { counts[id]++; n = snprintf(buf, sizeof(buf), "thread %02d: countup\n", id); write(STDOUT_FILENO, buf, n); } return NULL; } --------------070804040805030500010306--