From owner-freebsd-current Wed Mar 29 19:57:27 2000 Delivered-To: freebsd-current@freebsd.org Received: from khavrinen.lcs.mit.edu (khavrinen.lcs.mit.edu [18.24.4.193]) by hub.freebsd.org (Postfix) with ESMTP id 3F72537BB45; Wed, 29 Mar 2000 19:57:24 -0800 (PST) (envelope-from wollman@khavrinen.lcs.mit.edu) Received: (from wollman@localhost) by khavrinen.lcs.mit.edu (8.9.3/8.9.3) id WAA89938; Wed, 29 Mar 2000 22:57:21 -0500 (EST) (envelope-from wollman) Date: Wed, 29 Mar 2000 22:57:21 -0500 (EST) From: Garrett Wollman Message-Id: <200003300357.WAA89938@khavrinen.lcs.mit.edu> To: Alfred Perlstein Cc: Mike Smith , Matthew Dillon , freebsd-current@FreeBSD.ORG Subject: Using packed structs to gain cheap SMP primatives In-Reply-To: <20000329192526.U21029@fw.wintelcom.net> References: <200003300033.QAA07919@mass.cdrom.com> <200003300038.QAA08006@mass.cdrom.com> <20000329192526.U21029@fw.wintelcom.net> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG < said: > What do you guys think about that? Am I totally missing something > that makes the Linux way right/ok? (no locking on a 64bit struct) Generally, it's better to design an optimistic or non-blocking algorithm rather than twisting data structures to fit some pre-conceived machine model just to allow atomic updates. Most architectures provide either an atomic compare-exchange instruction, or a ``load linked'' instruction, which is what you need in order to make this work. For example, there are good non-blocking algorithms for maintaining a queue given either LL or compare-exchange of 2*sizeof(pointer). Unfortunately, this requires strict queue semantics, which few parts of FreeBSD are designed to make use of. I've had as a background task for a while now the creation of a non-blocking equivalent to queue(3), with as much functionality as is possible to achieve while still maintaining the non-blocking behavior. (If you were ever wondering why it was that struct socket and struct inpcb had grown version numbers: it is for similar reasons. If I were only smart enough to figure out how, I would have made all socket and pcb accesses non-blocking.) -GAWollman -- Garrett A. Wollman | O Siem / We are all family / O Siem / We're all the same wollman@lcs.mit.edu | O Siem / The fires of freedom Opinions not those of| Dance in the burning flame MIT, LCS, CRS, or NSA| - Susan Aglukark and Chad Irschick To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message