From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 55F3FBB81 for ; Wed, 8 Mar 2006 23:09:59 +0100 (CET) Received: from cenn.mc.mpls.visi.com (cenn.mc.mpls.visi.com [208.42.156.9]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k28M9wWC004663 for ; Wed, 8 Mar 2006 23:09:58 +0100 Received: from [192.168.42.2] (bhurt.dsl.visi.com [208.42.141.66]) by cenn.mc.mpls.visi.com (Postfix) with ESMTP id A178A8209; Wed, 8 Mar 2006 16:09:57 -0600 (CST) Date: Wed, 8 Mar 2006 16:11:04 -0600 (CST) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: skaller Cc: William Lovas , caml-list@yquem.inria.fr Subject: Re: [Caml-list] STM support in OCaml In-Reply-To: <1141855594.23909.63.camel@budgie.wigram> Message-ID: References: <440DB255.1030701@asfandyar.cjb.net> <1141751708.20944.355.camel@budgie.wigram> <440DD982.8080800@asfandyar.cjb.net> <1141779125.20944.405.camel@budgie.wigram> <20060308193633.GA5460@coruscant.stwing.upenn.edu> <1141855594.23909.63.camel@budgie.wigram> MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1771605653-1141855046=:9569" Content-ID: X-Miltered: at concorde with ID 440F5636.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 rdtsc:01 afaik:01 interprocess:01 threads:01 roof:98 wrote:01 caml-list:01 slower:01 inline:01 kernel:01 kernel:01 caches:01 caches:01 exists:01 X-Attachments: type="TEXT/X-CSRC" name="lock.c" name="lock.c" X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-1771605653-1141855046=:9569 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; FORMAT=flowed Content-ID: On Thu, 9 Mar 2006, skaller wrote: > Ahem. Now try that on an AMDx2 (dual core). The cost goes through > the roof if one process has a thread on each core. Because each > core has its own cache and both caches have to be flushed/ > synchronised. And those caches are BIG! Love to. Wanna buy me the box? :-} Seriously- my code is attached, if someone wants to run it on other boxes and post the results, feel free. It's GNU-C/x86 specific, as I'm using GNU C's inline assembler and the rdtsc instruction to get accurate cycle counts. As to the cache comment: the whole caches don't have to be flushed, just the line the mutex is on. Which makes it approximately the cost of a cache miss- that's a good approximation of the cost of getting an uncontended lock. > > I have no idea if Linux, for example, running SMP kernel, > is smart enough to know if a mutex is shared between two > processing units or not: AFAIK Linux doesn't support > interprocess mutex. Windows does. Be interesting to > compare. It doesn't look like the mutex software is even going into the kernel. I don't think the Linux kernel even knows the mutex *exists*, let alone what threads are competing for it. On the x86, at least, lock instructions are not priveledged. > > As mentioned before the only data I have at the moment > is a two thread counter increment experiment on a dual > CPU G5 box, where the speed up from 2 CPUs vs 1 was > a factor of 15 .. times SLOWER. If you're ping-ponging a cache line between two CPUs (and the AMD dual cores count as two CPUs), then I can easily beleive that. So? Brian --8323328-1771605653-1141855046=:9569 Content-Type: TEXT/X-CSRC; CHARSET=US-ASCII; NAME=lock.c Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: ATTACHMENT; FILENAME=lock.c I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8cHRocmVhZC5oPg0KI2lu Y2x1ZGUgPHNlbWFwaG9yZS5oPg0KDQojaWYgIWRlZmluZWQoX19HTlVDX18p ICYmICFkZWZpbmVkKF9faTM4Nl9fKQ0KI2Vycm9yIFRoaXMgY29kZSBvbmx5 IHdvcmtzIHdpdGggR0NDL2kzODYuDQojZW5kaWYNCg0KLyogVGhlIHJlYXNv biB0aGlzIG9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