Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Oct 2012 16:32:47 +0100
From:      Attilio Rao <attilio@freebsd.org>
To:        Andre Oppermann <andre@freebsd.org>
Cc:        mdf@freebsd.org, src-committers@freebsd.org, Bruce Evans <brde@optusnet.com.au>, John Baldwin <jhb@freebsd.org>, svn-src-user@freebsd.org
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/...
Message-ID:  <CAJ-FndArcGtgPtX4Vdp9EOBoWy=KZ1G5AgGE3-wGMfj%2B0U5iTg@mail.gmail.com>
In-Reply-To: <5088098D.9070206@freebsd.org>
References:  <201210221418.q9MEINkr026751@svn.freebsd.org> <201210241005.38977.jhb@freebsd.org> <CAJ-FndBENEuyaH%2B2Q%2Bigj39tdGmsHh=3arL-Cb2GP3i9WSr_hQ@mail.gmail.com> <201210241045.39211.jhb@freebsd.org> <CAJ-FndC=zV%2BHN1wr_CnSEY93VHT--w9cYPMhH8P53y%2BLvBSO7g@mail.gmail.com> <5088098D.9070206@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Oct 24, 2012 at 4:30 PM, Andre Oppermann <andre@freebsd.org> wrote:
> On 24.10.2012 17:09, Attilio Rao wrote:
>>
>> On Wed, Oct 24, 2012 at 3:45 PM, John Baldwin <jhb@freebsd.org> wrote:
>>>
>>> On Wednesday, October 24, 2012 10:34:34 am Attilio Rao wrote:
>>>>
>>>> On Wed, Oct 24, 2012 at 3:05 PM, John Baldwin <jhb@freebsd.org> wrote:
>>>>>
>>>>> On Tuesday, October 23, 2012 7:20:04 pm Andre Oppermann wrote:
>>>>>>
>>>>>> On 24.10.2012 00:15, mdf@FreeBSD.org wrote:
>>>>>>>
>>>>>>> On Tue, Oct 23, 2012 at 7:41 AM, Andre Oppermann <andre@freebsd.org>
>>>
>>> wrote:
>>>>>>>>
>>>>>>>> Struct mtx and MTX_SYSINIT always occur as pair next to each other.
>>>>>>>
>>>>>>>
>>>>>>> That doesn't matter.  Language basics like variable definitions
>>>>>>> should
>>>>>>> not be obscured by macros.  It either takes longer to figure out what
>>>>>>> a variable is (because one needs to look up the definition of the
>>>>>>> macro) or makes it almost impossible (because now e.g. cscope doesn't
>>>>>>> know this is a variable definition.
>>>>>>
>>>>>>
>>>>>> Sigh, cscope doesn't expand macros?
>>>>>>
>>>>>> Is there a way to do the cache line alignment in a sane way without
>>>>>> littering __aligned(CACHE_LINE_SIZE) all over the place?
>>>>>
>>>>>
>>>>> I was hoping to do something with an anonymous union or some such like:
>>>>>
>>>>> union mtx_aligned {
>>>>>          struct mtx;
>>>>>          char[roundup2(sizeof(struct mtx), CACHE_LINE_SIZE)];
>>>>> }
>>>>>
>>>>> I don't know if there is a useful way to define an 'aligned mutex' type
>>>>> that will transparently map to a 'struct mtx', e.g.:
>>>>>
>>>>> typedef struct mtx __aligned(CACHE_LINE_SIZE) aligned_mtx_t;
>>>>
>>>>
>>>> Unfortunately that doesn't work as I've verified with alc@ few months
>>>> ago.
>>>> The __aligned() attribute only works with structures definition, not
>>>> objects declaration.
>>>
>>>
>>> Are you saying that the typedef doesn't (I expect it doesn't), or that
>>> this
>>> doesn't:
>>>
>>> struct mtx foo __aligned(CACHE_LINE_SIZE);
>>
>>
>> I meant to say that such notation won't address the padding issue
>> which is as import as the alignment. Infact, for sensitive locks,
>> having just an aligned object is not really useful if the cacheline
>> gets shared.
>
>
> As far as I understand __aligned() not only aligns the start of the
> object but also ensures that is padded on a multiple of the alignment
> after the object.  So explicit padding after it is not necessary.

As I said it only works if you specify it in the struct definition,
otherwise it doesn't work.
You can try it yourself.

Attilio


-- 
Peace can only be achieved by understanding - A. Einstein



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ-FndArcGtgPtX4Vdp9EOBoWy=KZ1G5AgGE3-wGMfj%2B0U5iTg>