From owner-freebsd-threads@FreeBSD.ORG Thu Dec 30 07:47:53 2004 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 22D6A16A4CE for ; Thu, 30 Dec 2004 07:47:53 +0000 (GMT) Received: from silver.he.iki.fi (helenius.fi [193.64.42.241]) by mx1.FreeBSD.org (Postfix) with ESMTP id BD3BD43D2D for ; Thu, 30 Dec 2004 07:47:51 +0000 (GMT) (envelope-from pete@he.iki.fi) Received: from [193.64.42.134] (h86.vuokselantie10.fi [193.64.42.134]) by silver.he.iki.fi (8.13.1/8.11.4) with ESMTP id iBU7lms8041110; Thu, 30 Dec 2004 09:47:49 +0200 (EET) (envelope-from pete@he.iki.fi) Message-ID: <41D3B2A6.4090307@he.iki.fi> Date: Thu, 30 Dec 2004 09:47:50 +0200 From: Petri Helenius User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Damian Cieslicki References: <20041230024706.94879.qmail@web52401.mail.yahoo.com> In-Reply-To: <20041230024706.94879.qmail@web52401.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-threads@freebsd.org Subject: Re: Thread time spikes 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: Thu, 30 Dec 2004 07:47:53 -0000 Damian Cieslicki wrote: >Hi folks, > >I just wonder about the time behavior of this simple >threaded program: > > How many CPUs on the box? Pete > >#include /* threading */ >#include /* printf */ >#include /* exit */ > >#define MILLION 1000000L >#define THOUSAND 1000L > > >/* prototypes */ >void * doit(void *arg); > > >/* >************************************************************************* >*/ > >int main (int argc, char **argv){ > > long duration1; > pthread_t pthread_id; > struct timespec tv1start, tv1end; > > > clock_gettime(CLOCK_REALTIME, &tv1start); // real > > /* thread ... */ > pthread_create(&pthread_id, NULL, doit, NULL); > pthread_join(pthread_id, NULL); > > /* vs function call */ > // doit(NULL); > > clock_gettime(CLOCK_REALTIME, &tv1end); > > duration1 = MILLION*(tv1end.tv_sec - >tv1start.tv_sec) + > (tv1end.tv_nsec - tv1start.tv_nsec)/THOUSAND; > > > printf("%ld\n", duration1); > > > exit(0); >} > > >/* >************************************************************************* >*/ > > >void* doit(void *arg){ > > int k; > > k=42; /* heavy computation */ > > return(NULL); > >} > >/* >************************************************************************* >*/ > > >compiler options: gcc -D_THREAD_SAFE -g -Wall >-pthread threadspikes.c >-o threadspikes > >os: freebsd 5.2, generic kernel > >hw: Pentium III 500 Mhz. > >load: no real computation, just the standard daemons >and x window are >running. > > > >Why does the threaded program take each 10th time much >longer?: Why I get these "time spikes" ? > >359 >392 >365 >379 >374 >2474 >370 >363 >365 >376 >364 >364 >397 >378 >393 >389 >370 >365 >3221 >366 >377 > > > >replacing the thread with a function call reduces the >number of spikes >drastically but they still do occur (even more >drastically): > >: >3 >3 >3 >3 >3 >3 >3 >19021 > > >I assume there is a global re-scheduling after >pthread_create and sometimes a totally different >process (like sendmail) gets chosen. But even >nice -n -n19 doesn't help. > >Is there a way to get deterministic results? > > > > >