From owner-freebsd-arch@FreeBSD.ORG Mon Jun 16 04:13:18 2003 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 99A9E37B404; Mon, 16 Jun 2003 04:13:18 -0700 (PDT) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4BA0343FAF; Mon, 16 Jun 2003 04:13:17 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3p2/8.8.7) with ESMTP id VAA16549; Mon, 16 Jun 2003 21:13:14 +1000 Date: Mon, 16 Jun 2003 21:13:13 +1000 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Don Lewis In-Reply-To: <200306161048.h5GAmMM7048782@gw.catspoiler.org> Message-ID: <20030616205631.F28116@gamplex.bde.org> References: <200306161048.h5GAmMM7048782@gw.catspoiler.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: iedowse@maths.tcd.ie cc: freebsd-arch@FreeBSD.org Subject: Re: Message buffer and printf reentrancy patch X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jun 2003 11:13:18 -0000 On Mon, 16 Jun 2003, Don Lewis wrote: > On 16 Jun, Bruce Evans wrote: > > On Sun, 15 Jun 2003, Ian Dowse wrote: > >> >> ... > >> >> +#define MSGBUF_SEQSUB(mbp, seq1, seq2) (MSGBUF_SEQNORM(mbp, (seq1) - (seq2) > > ... > > This problem and many casts could be avoided by using unsigned types > > for most of the msgbuf fields. I forget the details of why we changed > > them back to signed. The log message for msgbuf.h 1.19 says that this > > is because we perform signed arithmetic on them. The details for this, > > can probably be handled by the macros now. > > Using unsigned types was the first thing that I thought of. I was > wondering if the reason that this wasn't done was some sort of > portability problem with the atomic operations. MSG_SEQSUB() takes differences of sequence numbers now. The differences can be negative. Though the macro could convert to a signed type, the range of sequence numbers must be limited for their differences to fit in a signed type, so the type for sequence numbers may as well be signed too. > It looks like MSGBUF_SEQNORM() could avoid the conditional code and any > questions about signed remainders if it was defined like this: > > #define MSGBUF_SEQNORM(mbp, seq) (((seq) + (mbp)->msg_seqmod) % \ > (mbp)->msg_seqmod) > > as long as msg_seqmod < INT_MAX/2. MSGBUF_SEQNORM() could be simplified > further if msg_seqmod was added by the caller (such as MSGBUF_SEQSUB()) > if the argument could be negative. Yes. The negative numbers of interest seem to be limited to at most differences of sequence numbers (or maybe differeces of indexes, which are smaller), so they are larger than -msg_seqmod. MSGBUF_SEQSUB() shouldn't add the bias, however, since it is used in contexts where we really want to see the negative values. Bruce