From owner-freebsd-current@FreeBSD.ORG Tue Oct 5 12:35:39 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A0E7A1065670 for ; Tue, 5 Oct 2010 12:35:39 +0000 (UTC) (envelope-from onwahe@gmail.com) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 354E58FC1B for ; Tue, 5 Oct 2010 12:35:38 +0000 (UTC) Received: by wyb29 with SMTP id 29so5546975wyb.13 for ; Tue, 05 Oct 2010 05:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=PAxsJsl0MS4DjjmEfLYSl68m6hneDt7wjcHyl+GIL6E=; b=Djttq2CYI+pbzG8DioTpFXyOg0T+NyH72ILFwZ1x/7ejLTWBN9aiNKonNXYxdd2/fJ W9kjmY249ivd2TFbMYRZ7yn5731EesdeDu21EQWoqPktVL1N11jUGDZ2nvtOjge71V8J 4yElxrNB5aOIfz1xAKAhZoDnqK2d4g8FC8HXw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=W9KEupI+0v21+HI3BqaiW54YB3hCm+NwrTSq32z5ipcS7aOjNLli3lwlFtigxjiuW6 BG9foZK9e8U/1zHC4IBnEo0G2SAxglLsOALrQMdNSWEpaxQETUYC9j5xNiMD+4muiSXs LI/5ORKgWEJfJAO6g6rAfmk/s1Ef6TAcuAUlk= MIME-Version: 1.0 Received: by 10.216.150.195 with SMTP id z45mr975028wej.63.1286282138049; Tue, 05 Oct 2010 05:35:38 -0700 (PDT) Received: by 10.216.172.210 with HTTP; Tue, 5 Oct 2010 05:35:38 -0700 (PDT) In-Reply-To: References: Date: Tue, 5 Oct 2010 14:35:38 +0200 Message-ID: From: Svatopluk Kraus To: Matthew Fleming Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-current@freebsd.org Subject: Re: CACHE_LINE_SIZE too small, so struct vpglocks size alignment doesn't work X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Oct 2010 12:35:39 -0000 On Fri, Oct 1, 2010 at 4:01 PM, Matthew Fleming wrote: > On Fri, Oct 1, 2010 at 1:00 PM, Svatopluk Kraus wrote: >> Hallo, >> >> =A0a size of 'struct vpglocks' is padded to CACHE_LINE_SIZE size in >> 'sys/vm/vm_page.h' >> header file. I work on a 'coldfire' port where CACHE_LINE_SIZE is 16 byt= es and >> sizeof(struct mtx) is 20 bytes thus size alignment doesn't work. >> >> =A0I solved it somehow, but I like to learn how to solve it in spirit >> of FreeBSD. >> There are a couple of possibilities: >> >> A1. Do nothing for small CACHE_LINE_SIZE. >> A2. Pad to multiple of CACHE_LINE_SIZE. >> >> B1. use #if with CACHE_LINE_SIZE >> B2. use #if with __coldfire__ >> >> When I use B1 solution I need to known sizeof(struct mtx) value in >> preprocessing time. >> So, is it correct to use something like 'assym.s' magic >> (sys/i386/i386/genassym.c) >> in MI code? Or has someone another suggestion? > > What about padding to CACHE_LINE_SIZE - (sizeof(struct vpglocks) & > (CACHE_LINE_SIZE-1)) ? > > Some compilers will complain about 0-sized arrays, but gcc isn't one of t= hem. > > Cheers, > matthew Thanks for your nice suggestion. Probably, CACHE_LINE_SIZE size is a multiple of 2 at all times, so your solution is applicable. BTW, I use gcc 4.5.1 and when a structure is aligned to a value, then a sizeof of the structure is padded to the value too implicitly. So no explicit padding is needed. Cheers, Svata