lkml.org 
[lkml]   [2012]   [Mar]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRe: [RFC patch] spindep: add cross cache lines checking
    Date
    On Wednesday 07 March 2012, Alex Shi wrote:

    > Understand. thx. So is the following checking that your wanted?
    > ===
    > diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h
    > index bc2994e..64828a3 100644
    > --- a/include/linux/rwlock.h
    > +++ b/include/linux/rwlock.h
    > @@ -21,10 +21,12 @@
    > do { \
    > static struct lock_class_key __key; \
    > \
    > + BUILD_BUG_ON(__alignof__(lock) == 1); \
    > __rwlock_init((lock), #lock, &__key); \
    > } while (0)
    > #else
    > # define rwlock_init(lock) \
    > + BUILD_BUG_ON(__alignof__(lock) == 1); \
    > do { *(lock) = __RW_LOCK_UNLOCKED(lock); } while (0)
    > #endif

    I think the check should be (__alignof__(lock) < __alignof__(rwlock_t)),
    otherwise it will still pass when you have structure with attribute((packed,aligned(2)))

    > 1, it is alignof bug for default gcc on my fc15 and Ubuntu 11.10 etc?
    >
    > struct sub {
    > int raw_lock;
    > char a;
    > };
    > struct foo {
    > struct sub z;
    > int slk;
    > char y;
    > }__attribute__((packed));
    >
    > struct foo f1;
    >
    > __alignof__(f1.z.raw_lock) is 4, but its address actually can align on
    > one byte.

    That looks like correct behavior, because the alignment of raw_lock inside of
    struct sub is still 4. But it does mean that there can be cases where the
    compile-time check is not sufficient, so we might want the run-time check
    as well, at least under some config option.

    Arnd


    \
     
     \ /
      Last update: 2012-03-07 12:57    [W:0.022 / U:0.192 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site