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 BD7FA40DC7 for ; Wed, 16 Oct 2002 17:32:03 -0400 (EDT) Received: (from mail@localhost) by int-mx1.corp.redhat.com (8.11.6/8.11.6) id g9GLW3307334 for axp-list@listman.redhat.com; Wed, 16 Oct 2002 17:32:03 -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 g9GLW3f07330 for ; Wed, 16 Oct 2002 17:32:03 -0400 Received: from mailserver.iplink.net (IDENT:root@smtp.iplink.net [192.139.81.186]) by mx1.redhat.com (8.11.6/8.11.6) with SMTP id g9GLBMw18831 for ; Wed, 16 Oct 2002 17:11:22 -0400 Received: from mercutio.iplink.net ([192.139.81.54]:2437 "EHLO iplink.net") by mailserver.iplink.net with ESMTP id ; Wed, 16 Oct 2002 17:31:40 -0400 Message-ID: <3DADDA83.6040900@iplink.net> Date: Wed, 16 Oct 2002 17:30:43 -0400 From: alvin User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830 X-Accept-Language: en-us, en MIME-Version: 1.0 To: axp-list@redhat.com Subject: Re: unaligned traps question 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> <20021016142302.A25749@ellpspace.math.ualberta.ca> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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: Michal Jaegermann wrote: > 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? I just did a global search and replace. It seemed easier to make the array larger than the largest item and not worry about it > - 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)? This is true. I was looking to make the fewest changes to the way the code operated. As the number of changes increse so does the likelyhood of new bugs creeping in. > - With a correct size a "magic constant" of 8 can and should be > replaced by sizeof(raw). Hmmm. This is true. Possibly time to look at changing this code to clean it up a bit. I did not write this code originaly. Personaly I think I would have created a structure and tried to work with that. This is only one of about a hundred routines or so that do just about the same thing. > >>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? Well the software seems to work quite reliably. But on the other hand the system wedged on the weekend. -- Alvin Starr || voice: (416)785-4051 Interlink Connectivity || fax: (416)785-3668 alvin@iplink.net ||