From owner-svn-src-user@FreeBSD.ORG Wed Oct 24 15:45:16 2012 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A04C91DF; Wed, 24 Oct 2012 15:45:16 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx1.freebsd.org (Postfix) with ESMTP id 042B68FC0C; Wed, 24 Oct 2012 15:45:14 +0000 (UTC) Received: by mail-vc0-f182.google.com with SMTP id fw7so846523vcb.13 for ; Wed, 24 Oct 2012 08:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=vL7Lrkz7oVfGCA8+LQCphDGrBZ/OUled68MCmM1Vqmc=; b=mJKD1627upnDJyz1lHQgal+UEM13Cd/sbj/bOCKDpIw46d7HUqklaro6hcgbvoCWoq fl5Nhg9OZO2rq7/lTMyHZvepVIQhPqt8MRuE5HO+y1lLYjsBDdAwTliyfgCQxlgQkAsV i/TmFlCqca9QmH5bKsIKUSmIovrkDizQ1Sno7D0NcxmW3CW3zq1RtvWQN8Be0K/8xmd3 SlxyAVDfPQf6oNt1s6Mouo3rrg4GdVy36ozlNcNAmI1l9RIhDaw1KLYC3j9DRt6HcT/T t+eTMNG0LBic/mld5vdl5xuDsU9dNVPRmXRpj9DgEqZvrTHp/OPP1qWC9pbSow1ORWK6 17ow== MIME-Version: 1.0 Received: by 10.52.176.168 with SMTP id cj8mr22519528vdc.72.1351093507646; Wed, 24 Oct 2012 08:45:07 -0700 (PDT) Sender: asmrookie@gmail.com Received: by 10.220.150.197 with HTTP; Wed, 24 Oct 2012 08:45:07 -0700 (PDT) In-Reply-To: <20121024154302.GH70741@FreeBSD.org> References: <201210221418.q9MEINkr026751@svn.freebsd.org> <201210241136.06154.jhb@freebsd.org> <20121024154302.GH70741@FreeBSD.org> Date: Wed, 24 Oct 2012 16:45:07 +0100 X-Google-Sender-Auth: _HTegseU8NuhruHXnBPusAoYlfI Message-ID: Subject: Re: svn commit: r241889 - in user/andre/tcp_workqueue/sys: arm/arm cddl/compat/opensolaris/kern cddl/contrib/opensolaris/uts/common/dtrace cddl/contrib/opensolaris/uts/common/fs/zfs ddb dev/acpica dev/... From: Attilio Rao To: Gleb Smirnoff Content-Type: text/plain; charset=UTF-8 Cc: mdf@freebsd.org, src-committers@freebsd.org, Andre Oppermann , John Baldwin , svn-src-user@freebsd.org, Bruce Evans X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: attilio@FreeBSD.org List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Oct 2012 15:45:16 -0000 On Wed, Oct 24, 2012 at 4:43 PM, Gleb Smirnoff wrote: > On Wed, Oct 24, 2012 at 11:36:06AM -0400, John Baldwin wrote: > J> On Wednesday, October 24, 2012 11:24:22 am Attilio Rao wrote: > J> > On Wed, Oct 24, 2012 at 4:09 PM, Attilio Rao wrote: > J> > > On Wed, Oct 24, 2012 at 3:45 PM, John Baldwin wrote: > J> > >> On Wednesday, October 24, 2012 10:34:34 am Attilio Rao wrote: > J> > >>> On Wed, Oct 24, 2012 at 3:05 PM, John Baldwin wrote: > J> > >>> > On Tuesday, October 23, 2012 7:20:04 pm Andre Oppermann wrote: > J> > >>> >> On 24.10.2012 00:15, mdf@FreeBSD.org wrote: > J> > >>> >> > On Tue, Oct 23, 2012 at 7:41 AM, Andre Oppermann > J> > >> wrote: > J> > >>> >> >> Struct mtx and MTX_SYSINIT always occur as pair next to each other. > J> > >>> >> > > J> > >>> >> > That doesn't matter. Language basics like variable definitions should > J> > >>> >> > not be obscured by macros. It either takes longer to figure out what > J> > >>> >> > a variable is (because one needs to look up the definition of the > J> > >>> >> > macro) or makes it almost impossible (because now e.g. cscope doesn't > J> > >>> >> > know this is a variable definition. > J> > >>> >> > J> > >>> >> Sigh, cscope doesn't expand macros? > J> > >>> >> > J> > >>> >> Is there a way to do the cache line alignment in a sane way without > J> > >>> >> littering __aligned(CACHE_LINE_SIZE) all over the place? > J> > >>> > > J> > >>> > I was hoping to do something with an anonymous union or some such like: > J> > >>> > > J> > >>> > union mtx_aligned { > J> > >>> > struct mtx; > J> > >>> > char[roundup2(sizeof(struct mtx), CACHE_LINE_SIZE)]; > J> > >>> > } > J> > >>> > > J> > >>> > I don't know if there is a useful way to define an 'aligned mutex' type > J> > >>> > that will transparently map to a 'struct mtx', e.g.: > J> > >>> > > J> > >>> > typedef struct mtx __aligned(CACHE_LINE_SIZE) aligned_mtx_t; > J> > >>> > J> > >>> Unfortunately that doesn't work as I've verified with alc@ few months ago. > J> > >>> The __aligned() attribute only works with structures definition, not > J> > >>> objects declaration. > J> > >> > J> > >> Are you saying that the typedef doesn't (I expect it doesn't), or that this > J> > >> doesn't: > J> > >> > J> > >> struct mtx foo __aligned(CACHE_LINE_SIZE); > J> > > > J> > > I meant to say that such notation won't address the padding issue > J> > > which is as import as the alignment. Infact, for sensitive locks, > J> > > having just an aligned object is not really useful if the cacheline > J> > > gets shared. > J> > > In the end you will need to use explicit padding or use __aligned in > J> > > the struct definition, which cannot be used as a general pattern. > J> > > J> > The quickest way I see this can be made general is to have a specific > J> > struct defined in sys/_mutex.h like that > J> > > J> > struct mtx_unshare { > J> > struct mtx lock; > J> > char _pad[CACHE_LINE_SIZE - sizeof(struct mtx)]; > J> > } __aligned(CACHE_LINE_SIZE); > J> > J> I think instead you want my union above that uses roundup2 in case a lock > J> eats up multiple cache lines: > J> > J> union mtx_foo { > J> struct mtx lock; > J> char junk[roundup2(sizeof(struct mtx), CACHE_LINE_SIZE)]; > J> } __aligned_CACHE_LINE_SIZE; > J> > J> > then let mtx_* functions to accept void ptrs and cast them to struct > J> > mtx as long as the functions enter. > J> > J> Eh, that removes all compile time type checks. That seems very dubious to me. > > I think that we should first get benchmarking results, and only then try > to evolve an API for cache aligned mutexes. > > As an option we can allocate mutexes from cache aligned uma zone dynamically, > to avoid all these syntax acrobatics. There are several objections to this. Quicker that came to my mind: - Some locks needs to be ready before UMA subsystem is setup - On arches where the KVA is already scarce (i386, powerpc, etc.) this is going to be completely overkill Attilio -- Peace can only be achieved by understanding - A. Einstein