From owner-cvs-all Tue Jan 16 0:26:43 2001 Delivered-To: cvs-all@freebsd.org Received: from moby.geekhouse.net (moby.geekhouse.net [64.81.6.36]) by hub.freebsd.org (Postfix) with ESMTP id CDD8B37B6A3; Tue, 16 Jan 2001 00:26:15 -0800 (PST) Received: from laptop.baldwin.cx (john@dhcp150.geekhouse.net [192.168.1.150]) by moby.geekhouse.net (8.11.0/8.9.3) with ESMTP id f0G8Tps53757; Tue, 16 Jan 2001 00:29:51 -0800 (PST) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <200101160806.f0G86GI31855@gratis.grondar.za> Date: Tue, 16 Jan 2001 00:26:09 -0800 (PST) From: John Baldwin To: Mark Murray Subject: RE: Atomic ops (Was Re: cvs commit: src/sys/i386/include atomic. Cc: jake@FreeBSD.org, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On 16-Jan-01 Mark Murray wrote: >> > particularly if I just do a >> > >> > if (mutex_try_enter(foo, ...)) { >> > /* Harvest */ >> > : >> > mutex_exit(foo, ...); >> > } >> > >> > How much of a difference would it make if I were to use atomic ops like >> > >> > if (atomic_cmpset(foo, 0, 1)) { >> > /* harvest */ >> > : >> > foo = 0; >> > } >> >> You would have to use atomic_store_rel() here. And you would have to use >> atomic_cmpset_acq() since you are protecting something. > > Right. I'm getting a grasp of whats going on here :-) > >> Since you are doing atomic operations with memory barriers either way, I'm >> not >> sure that the mutex is that much slower, to be perfectly honest. > > OK. What I needed to know! I'll figure out an alternative logic. Which > are the "cheaper" atomic ops, and which are the ones to avoid? Anything with acq and rel memory barriers (which you will likely need unfortunately) are expensive. :-P Now, if you can pull a trick where you you had a circular buffer, and you used one atomic operation to increment the index, that would be better. The tophalf would just have to always use atomic ops when acessing the index as well. -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message