From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by listman.redhat.com (Postfix) with ESMTP id 145C43FFC7 for ; Wed, 16 Oct 2002 16:23:11 -0400 (EDT) Received: (from mail@localhost) by int-mx1.corp.redhat.com (8.11.6/8.11.6) id g9GKNAW20537 for axp-list@listman.redhat.com; Wed, 16 Oct 2002 16:23:10 -0400 Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with SMTP id g9GKNAf20533 for ; Wed, 16 Oct 2002 16:23:10 -0400 Received: from ellpspace.math.ualberta.ca (ellpspace.math.ualberta.ca [129.128.207.67]) by mx1.redhat.com (8.11.6/8.11.6) with SMTP id g9GK2Tw32530 for ; Wed, 16 Oct 2002 16:02:29 -0400 Received: (from michal@localhost) by ellpspace.math.ualberta.ca (8.11.6/8.11.6) id g9GKN2s25819 for axp-list@redhat.com; Wed, 16 Oct 2002 14:23:02 -0600 Date: Wed, 16 Oct 2002 14:23:02 -0600 From: Michal Jaegermann To: axp-list@redhat.com Subject: Re: unaligned traps question Message-ID: <20021016142302.A25749@ellpspace.math.ualberta.ca> References: <01da01c273e4$d5c57320$35de2b09@Viswanadha> <3DAB7754.F6F5D8B0@voicenet.com> <02101511393604.01593@shadowfax.middleearth> <20021015104643.A19134@ellpspace.math.ualberta.ca> <3DAC5D76.3060101@iplink.net> <3DAC6EF2.BC962839@voicenet.com> <3DADACDB.8000401@iplink.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <3DADACDB.8000401@iplink.net>; from alvin@iplink.net on Wed, Oct 16, 2002 at 02:15:55PM -0400 X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0.1 Precedence: bulk Reply-To: axp-list@redhat.com List-Help: List-Post: List-Subscribe: , List-Id: Linux and Red Hat on Alpha processors List-Unsubscribe: , List-Archive: On Wed, Oct 16, 2002 at 02:15:55PM -0400, alvin wrote: > > So I have a chunk of code like this: > > int add_message_type_avp(struct buffer *buf, _u16 type) { > _u16 *raw = (_u16 *)(buf->start + buf->len); > raw[0] = htons(0x8 | MBIT); > raw[1] = htons(VENDOR_ID); > raw[2] = 0; > raw[3] = htons(type); > buf->len += 8; > return 0; > } Regardless of all other issues this is a really costly method for doing this. You may cause four kernel traps. > > I end up converting it to this: > > int add_message_type_avp(struct buffer *buf, _u16 type) { > _u16 raw[32]; > raw[0] = htons(0x8 | MBIT); > raw[1] = htons(VENDOR_ID); > raw[2] = 0; > raw[3] = htons(type); > memcpy((char *)(buf->start + buf->len), (char *)&raw,8); > buf->len += 8; > return 0; > } > > > This is not pretty but it does work. Save some code questions this is actually a correct way of coding something of that sort. Should compile to something reasonably fast too. Here are questions. - Why you are pushing on stack raw[32] while only four positions are used? - Are MBIT and VENDOR_ID really constants as suggested by a case? If yes then how about making a static initializer for first three positions in raw[4] and filling up only one cell with htons(type)? - With a correct size a "magic constant" of 8 can and should be replaced by sizeof(raw). > I spent a lot of time tracking this one down and could only come to the > conclusion that the unaligned trap handler was not working correctly. Seems like there is a potential for few other mess-ups. You really eliminated them all? Michal