From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA18834; Mon, 28 Jun 2004 17:08:07 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA18823 for ; Mon, 28 Jun 2004 17:08:06 +0200 (MET DST) Received: from yquem.inria.fr (yquem.inria.fr [128.93.8.37]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i5SF85EV019763; Mon, 28 Jun 2004 17:08:05 +0200 Received: by yquem.inria.fr (Postfix, from userid 18180) id 93BB8BC3A; Mon, 28 Jun 2004 17:08:05 +0200 (CEST) Date: Mon, 28 Jun 2004 17:08:05 +0200 From: Xavier Leroy To: Christophe Raffalli Cc: caml-list Subject: Re: [Caml-list] Thread and kernel 2.6 pb still there in CVS Message-ID: <20040628150805.GC7353@yquem.inria.fr> References: <20040624194603.2A91010EF06@clark.cs.brown.edu> <1088158825.1941.113.camel@pelican.wigram> <20040625110748.GB2707@bourg.inria.fr> <1088166608.1941.120.camel@pelican.wigram> <40DC38D3.4010009@univ-savoie.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <40DC38D3.4010009@univ-savoie.fr> User-Agent: Mutt/1.3.28i X-Miltered: at nez-perce with ID 40E03455.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 vouillon's:01 bug:01 bug:01 andrieu:01 kernels:01 posix:01 inter-thread:01 threads:01 mandrake:01 threads:01 sched:01 kernels:01 sched:01 posix:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I tried to submit a change in vouillon's entry in the bug tracking > system (classed as not a bug because can not reproduce), but as I am not > sure it worked, So I also post this here You should be grateful to Olivier Andrieu, who actually cared to submit a bug report along with useful info on 2.6 kernels. > In the latest CVS of ocaml there is still the periodic call Thread.yield > (through a sigalarm) in thread_posix.ml Yes, and that is necessary to get preemptive scheduling. Without this periodic Thread.yield, a thread that performs no I/O and no inter-thread communications would prevent all other Caml threads from running at all. > This implies that a threaded OCaml program ON A LINUX KERNEL 2.6 (at > least 2.6.3 on Mandrake 10, but probaby all 2.6) gets very little CPU > when another process is running (the usual figure is 10% CPU for the > threaded OCaml program against 90% for another program) Thread.yield does three things: - release the global Caml mutex, giving other Caml threads a chance to grab it and run; - call sched_yield() to suggest the kernel scheduler that now is a good time to schedule another thread; - re-acquire the global Caml mutex before returning to the caller. The 2.6 Linux kernels changed the behavior of sched_yield() in a way that causes the unfairness you observed. Other threaded applications are affected, including Open Office (!). My belief is that it's really a bug in 2.6 kernels and that the new behavior of sched_yield(), while technically conformant to the POSIX specs, lowers the quality of implementation quite a lot. (I seem to remember from my LinuxThreads development days that this isn't the first time the kernel developers broke sched_yield(), then realized their error.) The question I'm currently investigating is whether the call to sched_yield() can be omitted, as it's just a scheduling hint. Initial experiments suggested that this would hurt fairness (in Caml thread scheduling) quite a lot on all platforms other than Linux 2.6. More careful experiments that I'm currently conducting suggest that it might not be so bad. One can also play games where sched_yield() isn't called if there are no other Caml threads waiting for the global Caml mutex. In summary, a solution will eventually be found, but please be patient, and submit a bug report next time. - Xavier Leroy ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners