linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] create generic alignment api (v2)
@ 2010-03-28  1:22 Mathieu Desnoyers
  2010-03-28 15:40 ` Imre Deak
  0 siblings, 1 reply; 8+ messages in thread
From: Mathieu Desnoyers @ 2010-03-28  1:22 UTC (permalink / raw)
  Cc: Russell King - ARM Linux, Alexander Shishkin, linux-arm-kernel,
	Imre Deak, Jamie Lokier, rostedt, mingo, linux-kernel

Rather than re-doing the "alignment on a type size" trick all over again at
different levels, import the "ltt_align" from LTTng into kernel.h and make this
available to everyone. Renaming to:

- offset_align
- offset_align_floor
- object_align
- object_align_floor

Changelog since v1:

- Align on the object natural alignment
    (rather than min(arch word alignment, natural alignment))

The advantage of separating the API in "object alignment" and "offset alignment"
is that it gives more freedom to play with offset alignment. Very useful to
implement a tracer ring-buffer alignment. (hint hint)

Typical users will use "object alignment", but infrastructures like tracers
which need to perform dynamic alignment will typically use "offset alignment",
because it allows to align with respect to a base rather than to pass an
absolute address.

We use "sizeof(object)" rather than "__alignof__()" object because alignof
returns "recommended" object alignment for the architecture, which can be
sub-optimal on some architectures. By ensuring alignment on the object size, we
are sure to make the right choice.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
CC: Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: Alexander Shishkin <virtuoso@slind.org>,
CC: linux-arm-kernel@lists.infradead.org
CC: Imre Deak <imre.deak@nokia.com>
CC: Jamie Lokier <jamie@shareable.org>
CC: rostedt@goodmis.org
CC: mingo@elte.hu
---
 include/linux/kernel.h |   35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Index: linux-2.6-lttng/include/linux/kernel.h
===================================================================
--- linux-2.6-lttng.orig/include/linux/kernel.h	2010-03-27 20:46:07.000000000 -0400
+++ linux-2.6-lttng/include/linux/kernel.h	2010-03-27 21:17:52.000000000 -0400
@@ -42,6 +42,41 @@ extern const char linux_proc_banner[];
 #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
 #define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
 
+/**
+ * offset_align - Calculate the offset needed to align an object on its natural
+ *                alignment towards higher addresses.
+ * @align_drift:  object offset from an "alignment"-aligned address.
+ * @alignment:    natural object alignment. Must be non-zero, power of 2.
+ *
+ * Returns the offset that must be added to align towards higher
+ * addresses.
+ */
+static inline size_t offset_align(size_t align_drift, size_t alignment)
+{
+	return (alignment - align_drift) & (alignment - 1);
+}
+
+/**
+ * offset_align_floor - Calculate the offset needed to align an object
+ *                      on its natural alignment towards lower addresses.
+ * @align_drift:  object offset from an "alignment"-aligned address.
+ * @alignment:    natural object alignment. Must be non-zero, power of 2.
+ *
+ * Returns the offset that must be substracted to align towards lower addresses.
+ */
+static inline size_t offset_align_floor(size_t align_drift, size_t alignment)
+{
+	return (align_drift - alignment) & (alignment - 1);
+}
+
+#define object_align(object)						       \
+	((typeof(object))((size_t) object + offset_align((size_t) object,      \
+			  sizeof(object))))
+
+#define object_align_floor(object)					       \
+	((typeof(object))((size_t) object - offset_align_floor((size_t) object,\
+			  sizeof(object))))
+
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 
 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH] create generic alignment api (v2)
  2010-03-28  1:22 [RFC PATCH] create generic alignment api (v2) Mathieu Desnoyers
@ 2010-03-28 15:40 ` Imre Deak
  2010-03-28 18:29   ` Mathieu Desnoyers
  2010-03-29  0:09   ` [RFC PATCH] create generic alignment api (v5) Mathieu Desnoyers
  0 siblings, 2 replies; 8+ messages in thread
From: Imre Deak @ 2010-03-28 15:40 UTC (permalink / raw)
  To: ext Mathieu Desnoyers
  Cc: Russell King - ARM Linux, Alexander Shishkin, linux-arm-kernel,
	Jamie Lokier, rostedt, mingo, linux-kernel

On Sun, Mar 28, 2010 at 03:22:47AM +0200, ext Mathieu Desnoyers wrote:
>  [...]
> +/**
> + * offset_align - Calculate the offset needed to align an object on its natural
> + *                alignment towards higher addresses.
> + * @align_drift:  object offset from an "alignment"-aligned address.
> + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> + *
> + * Returns the offset that must be added to align towards higher
> + * addresses.
> + */
> +static inline size_t offset_align(size_t align_drift, size_t alignment)
> +{
> +	return (alignment - align_drift) & (alignment - 1);
> +}
> +
> +/**
> + * offset_align_floor - Calculate the offset needed to align an object
> + *                      on its natural alignment towards lower addresses.
> + * @align_drift:  object offset from an "alignment"-aligned address.
> + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> + *
> + * Returns the offset that must be substracted to align towards lower addresses.
> + */
> +static inline size_t offset_align_floor(size_t align_drift, size_t alignment)
> +{
> +	return (align_drift - alignment) & (alignment - 1);
> +}
> +
> +#define object_align(object)						       \
> +	((typeof(object))((size_t) object + offset_align((size_t) object,      \
> +			  sizeof(object))))
> +
> +#define object_align_floor(object)					       \
> +	((typeof(object))((size_t) object - offset_align_floor((size_t) object,\
> +			  sizeof(object))))
> +

Here object must be a pointer, but then sizeof(object) will result in
aligning to the arch word size not the object's natural alignment. Is
this what you intended?

--Imre


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH] create generic alignment api (v2)
  2010-03-28 15:40 ` Imre Deak
@ 2010-03-28 18:29   ` Mathieu Desnoyers
  2010-03-29  0:09   ` [RFC PATCH] create generic alignment api (v5) Mathieu Desnoyers
  1 sibling, 0 replies; 8+ messages in thread
From: Mathieu Desnoyers @ 2010-03-28 18:29 UTC (permalink / raw)
  To: Imre Deak
  Cc: Russell King - ARM Linux, Alexander Shishkin, linux-arm-kernel,
	Jamie Lokier, rostedt, mingo, linux-kernel

* Imre Deak (imre.deak@nokia.com) wrote:
> On Sun, Mar 28, 2010 at 03:22:47AM +0200, ext Mathieu Desnoyers wrote:
> >  [...]
> > +/**
> > + * offset_align - Calculate the offset needed to align an object on its natural
> > + *                alignment towards higher addresses.
> > + * @align_drift:  object offset from an "alignment"-aligned address.
> > + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> > + *
> > + * Returns the offset that must be added to align towards higher
> > + * addresses.
> > + */
> > +static inline size_t offset_align(size_t align_drift, size_t alignment)
> > +{
> > +	return (alignment - align_drift) & (alignment - 1);
> > +}
> > +
> > +/**
> > + * offset_align_floor - Calculate the offset needed to align an object
> > + *                      on its natural alignment towards lower addresses.
> > + * @align_drift:  object offset from an "alignment"-aligned address.
> > + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> > + *
> > + * Returns the offset that must be substracted to align towards lower addresses.
> > + */
> > +static inline size_t offset_align_floor(size_t align_drift, size_t alignment)
> > +{
> > +	return (align_drift - alignment) & (alignment - 1);
> > +}
> > +
> > +#define object_align(object)						       \
> > +	((typeof(object))((size_t) object + offset_align((size_t) object,      \
> > +			  sizeof(object))))
> > +
> > +#define object_align_floor(object)					       \
> > +	((typeof(object))((size_t) object - offset_align_floor((size_t) object,\
> > +			  sizeof(object))))
> > +
> 
> Here object must be a pointer, but then sizeof(object) will result in
> aligning to the arch word size not the object's natural alignment. Is
> this what you intended?

Nope, should be sizeof(*object). Good catch. I did the object_align*() macros
specifically as "helper" functions for your needs.

I'll repost a v3.

Thanks,

Mathieu

> 
> --Imre
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RFC PATCH] create generic alignment api (v5)
  2010-03-28 15:40 ` Imre Deak
  2010-03-28 18:29   ` Mathieu Desnoyers
@ 2010-03-29  0:09   ` Mathieu Desnoyers
  2010-05-01 18:35     ` Alexander Shishkin
  1 sibling, 1 reply; 8+ messages in thread
From: Mathieu Desnoyers @ 2010-03-29  0:09 UTC (permalink / raw)
  To: Imre Deak
  Cc: Russell King - ARM Linux, Alexander Shishkin, linux-arm-kernel,
	Jamie Lokier, rostedt, mingo, linux-kernel

Rather than re-doing the "alignment on a type size" trick all over again at
different levels, import the "ltt_align" from LTTng into kernel.h and make this
available to everyone. Renaming to:

- object_align()
- object_align_floor()
- offset_align()
- offset_align_floor()

Changelog since v4:
- add missing ( ) around parameters within object_align() and
  object_align_floor().
- More coding style cleanups to ALIGN() (checkpatch.pl is happy now).

Changelog since v3:
- optimize object_align*() so fewer instructions are needed for alignment of
  addresses known dynamically. Use the (already existing) "ALIGN()", and create
  the "ALIGN_FLOOR()" macro.
- While we are there, let's clean up the ALIGN() macros wrt coding style. e.g.
  missing parenthesis around the first use of the "x" parameter in ALIGN().

Changelog since v2:
- Fix object_align*(): should use object size alignment, not pointer alignment.

Changelog since v1:
- Align on the object natural alignment
    (rather than min(arch word alignment, natural alignment))

The advantage of separating the API in "object alignment" and "offset alignment"
is that it gives more freedom to play with offset alignment. Very useful to
implement a tracer ring-buffer alignment. (hint hint)

Typical users will use "object alignment", but infrastructures like tracers
which need to perform alignment of statically known base+offsets will typically
use "offset alignment", because it allows to align with respect to a base rather
than to pass an absolute address.

We use "sizeof(object)" rather than "__alignof__()" object because alignof
returns "recommended" object alignment for the architecture, which can be
sub-optimal on some architectures. By ensuring alignment on the object size, we
are sure to make the right choice.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
CC: Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: Alexander Shishkin <virtuoso@slind.org>,
CC: linux-arm-kernel@lists.infradead.org
CC: Imre Deak <imre.deak@nokia.com>
CC: Jamie Lokier <jamie@shareable.org>
CC: rostedt@goodmis.org
CC: mingo@elte.hu
---
 include/linux/kernel.h |   45 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 4 deletions(-)

Index: linux-2.6-lttng/include/linux/kernel.h
===================================================================
--- linux-2.6-lttng.orig/include/linux/kernel.h	2010-03-27 20:46:07.000000000 -0400
+++ linux-2.6-lttng/include/linux/kernel.h	2010-03-28 20:06:27.000000000 -0400
@@ -37,10 +37,47 @@ extern const char linux_proc_banner[];
 
 #define STACK_MAGIC	0xdeadbeef
 
-#define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
-#define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
-#define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
-#define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
+#define ALIGN(x, a)		__ALIGN_MASK((x), (typeof(x)) (a) - 1)
+#define __ALIGN_MASK(x, mask)	(((x) + (mask)) & ~(mask))
+#define PTR_ALIGN(p, a)		((typeof(p)) ALIGN((unsigned long) (p), (a)))
+#define ALIGN_FLOOR(x, a)	__ALIGN_FLOOR_MASK((x), (typeof(x)) (a) - 1)
+#define __ALIGN_FLOOR_MASK(x, mask)	((x) & ~(mask))
+#define PTR_ALIGN_FLOOR(p, a) \
+			((typeof(p)) ALIGN_FLOOR((unsigned long) (p), (a)))
+#define IS_ALIGNED(x, a)	(((x) & ((typeof(x)) (a) - 1)) == 0)
+
+/*
+ * Align pointer on natural object alignment. Object size must be power of two.
+ */
+#define object_align(obj)	PTR_ALIGN((obj), sizeof(*(obj)))
+#define object_align_floor(obj)	PTR_ALIGN_FLOOR((obj), sizeof(*(obj)))
+
+/**
+ * offset_align - Calculate the offset needed to align an object on its natural
+ *                alignment towards higher addresses.
+ * @align_drift:  object offset from an "alignment"-aligned address.
+ * @alignment:    natural object alignment. Must be non-zero, power of 2.
+ *
+ * Returns the offset that must be added to align towards higher
+ * addresses.
+ */
+static inline size_t offset_align(size_t align_drift, size_t alignment)
+{
+	return (alignment - align_drift) & (alignment - 1);
+}
+
+/**
+ * offset_align_floor - Calculate the offset needed to align an object
+ *                      on its natural alignment towards lower addresses.
+ * @align_drift:  object offset from an "alignment"-aligned address.
+ * @alignment:    natural object alignment. Must be non-zero, power of 2.
+ *
+ * Returns the offset that must be substracted to align towards lower addresses.
+ */
+static inline size_t offset_align_floor(size_t align_drift, size_t alignment)
+{
+	return (align_drift - alignment) & (alignment - 1);
+}
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH] create generic alignment api (v5)
  2010-03-29  0:09   ` [RFC PATCH] create generic alignment api (v5) Mathieu Desnoyers
@ 2010-05-01 18:35     ` Alexander Shishkin
  2010-05-01 19:10       ` Mathieu Desnoyers
  0 siblings, 1 reply; 8+ messages in thread
From: Alexander Shishkin @ 2010-05-01 18:35 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: Imre Deak, Russell King - ARM Linux, linux-arm-kernel,
	Jamie Lokier, rostedt, mingo, linux-kernel

On Sun, Mar 28, 2010 at 08:09:00 -0400, Mathieu Desnoyers wrote:
> Rather than re-doing the "alignment on a type size" trick all over again at
> different levels, import the "ltt_align" from LTTng into kernel.h and make this
> available to everyone. Renaming to:
> 
> - object_align()
> - object_align_floor()
> - offset_align()
> - offset_align_floor()

Do you plan to have this integrated to the mainline? I'd like to use one of
these in my next version of the __xchg patch. So, do you need any help or
feedback or whatnot with this one?

> Changelog since v4:
> - add missing ( ) around parameters within object_align() and
>   object_align_floor().
> - More coding style cleanups to ALIGN() (checkpatch.pl is happy now).
> 
> Changelog since v3:
> - optimize object_align*() so fewer instructions are needed for alignment of
>   addresses known dynamically. Use the (already existing) "ALIGN()", and create
>   the "ALIGN_FLOOR()" macro.
> - While we are there, let's clean up the ALIGN() macros wrt coding style. e.g.
>   missing parenthesis around the first use of the "x" parameter in ALIGN().
> 
> Changelog since v2:
> - Fix object_align*(): should use object size alignment, not pointer alignment.
> 
> Changelog since v1:
> - Align on the object natural alignment
>     (rather than min(arch word alignment, natural alignment))
> 
> The advantage of separating the API in "object alignment" and "offset alignment"
> is that it gives more freedom to play with offset alignment. Very useful to
> implement a tracer ring-buffer alignment. (hint hint)
> 
> Typical users will use "object alignment", but infrastructures like tracers
> which need to perform alignment of statically known base+offsets will typically
> use "offset alignment", because it allows to align with respect to a base rather
> than to pass an absolute address.
> 
> We use "sizeof(object)" rather than "__alignof__()" object because alignof
> returns "recommended" object alignment for the architecture, which can be
> sub-optimal on some architectures. By ensuring alignment on the object size, we
> are sure to make the right choice.
> 
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> CC: Russell King - ARM Linux <linux@arm.linux.org.uk>
> Cc: Alexander Shishkin <virtuoso@slind.org>,
> CC: linux-arm-kernel@lists.infradead.org
> CC: Imre Deak <imre.deak@nokia.com>
> CC: Jamie Lokier <jamie@shareable.org>
> CC: rostedt@goodmis.org
> CC: mingo@elte.hu

Acked-by: Alexander Shishkin <virtuoso@slind.org>

> ---
>  include/linux/kernel.h |   45 +++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 41 insertions(+), 4 deletions(-)
> 
> Index: linux-2.6-lttng/include/linux/kernel.h
> ===================================================================
> --- linux-2.6-lttng.orig/include/linux/kernel.h	2010-03-27 20:46:07.000000000 -0400
> +++ linux-2.6-lttng/include/linux/kernel.h	2010-03-28 20:06:27.000000000 -0400
> @@ -37,10 +37,47 @@ extern const char linux_proc_banner[];
>  
>  #define STACK_MAGIC	0xdeadbeef
>  
> -#define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
> -#define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
> -#define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
> -#define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
> +#define ALIGN(x, a)		__ALIGN_MASK((x), (typeof(x)) (a) - 1)
> +#define __ALIGN_MASK(x, mask)	(((x) + (mask)) & ~(mask))
> +#define PTR_ALIGN(p, a)		((typeof(p)) ALIGN((unsigned long) (p), (a)))
> +#define ALIGN_FLOOR(x, a)	__ALIGN_FLOOR_MASK((x), (typeof(x)) (a) - 1)
> +#define __ALIGN_FLOOR_MASK(x, mask)	((x) & ~(mask))
> +#define PTR_ALIGN_FLOOR(p, a) \
> +			((typeof(p)) ALIGN_FLOOR((unsigned long) (p), (a)))
> +#define IS_ALIGNED(x, a)	(((x) & ((typeof(x)) (a) - 1)) == 0)
> +
> +/*
> + * Align pointer on natural object alignment. Object size must be power of two.
> + */
> +#define object_align(obj)	PTR_ALIGN((obj), sizeof(*(obj)))
> +#define object_align_floor(obj)	PTR_ALIGN_FLOOR((obj), sizeof(*(obj)))
> +
> +/**
> + * offset_align - Calculate the offset needed to align an object on its natural
> + *                alignment towards higher addresses.
> + * @align_drift:  object offset from an "alignment"-aligned address.
> + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> + *
> + * Returns the offset that must be added to align towards higher
> + * addresses.
> + */
> +static inline size_t offset_align(size_t align_drift, size_t alignment)
> +{
> +	return (alignment - align_drift) & (alignment - 1);
> +}
> +
> +/**
> + * offset_align_floor - Calculate the offset needed to align an object
> + *                      on its natural alignment towards lower addresses.
> + * @align_drift:  object offset from an "alignment"-aligned address.
> + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> + *
> + * Returns the offset that must be substracted to align towards lower addresses.
> + */
> +static inline size_t offset_align_floor(size_t align_drift, size_t alignment)
> +{
> +	return (align_drift - alignment) & (alignment - 1);
> +}
>  
>  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
>  
> 
> -- 
> Mathieu Desnoyers
> Operating System Efficiency R&D Consultant
> EfficiOS Inc.
> http://www.efficios.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH] create generic alignment api (v5)
  2010-05-01 18:35     ` Alexander Shishkin
@ 2010-05-01 19:10       ` Mathieu Desnoyers
  2010-05-01 19:29         ` Alexander Shishkin
  0 siblings, 1 reply; 8+ messages in thread
From: Mathieu Desnoyers @ 2010-05-01 19:10 UTC (permalink / raw)
  To: Imre Deak, Russell King - ARM Linux, linux-arm-kernel,
	Jamie Lokier, rostedt, mingo, linux-kernel

* Alexander Shishkin (virtuoso@slind.org) wrote:
> On Sun, Mar 28, 2010 at 08:09:00 -0400, Mathieu Desnoyers wrote:
> > Rather than re-doing the "alignment on a type size" trick all over again at
> > different levels, import the "ltt_align" from LTTng into kernel.h and make this
> > available to everyone. Renaming to:
> > 
> > - object_align()
> > - object_align_floor()
> > - offset_align()
> > - offset_align_floor()
> 
> Do you plan to have this integrated to the mainline? I'd like to use one of
> these in my next version of the __xchg patch. So, do you need any help or
> feedback or whatnot with this one?

Given that no one seems to oppose to this patch, I think I'll just re-submit it
as-is for real this time.

Thanks,

Mathieu

> 
> > Changelog since v4:
> > - add missing ( ) around parameters within object_align() and
> >   object_align_floor().
> > - More coding style cleanups to ALIGN() (checkpatch.pl is happy now).
> > 
> > Changelog since v3:
> > - optimize object_align*() so fewer instructions are needed for alignment of
> >   addresses known dynamically. Use the (already existing) "ALIGN()", and create
> >   the "ALIGN_FLOOR()" macro.
> > - While we are there, let's clean up the ALIGN() macros wrt coding style. e.g.
> >   missing parenthesis around the first use of the "x" parameter in ALIGN().
> > 
> > Changelog since v2:
> > - Fix object_align*(): should use object size alignment, not pointer alignment.
> > 
> > Changelog since v1:
> > - Align on the object natural alignment
> >     (rather than min(arch word alignment, natural alignment))
> > 
> > The advantage of separating the API in "object alignment" and "offset alignment"
> > is that it gives more freedom to play with offset alignment. Very useful to
> > implement a tracer ring-buffer alignment. (hint hint)
> > 
> > Typical users will use "object alignment", but infrastructures like tracers
> > which need to perform alignment of statically known base+offsets will typically
> > use "offset alignment", because it allows to align with respect to a base rather
> > than to pass an absolute address.
> > 
> > We use "sizeof(object)" rather than "__alignof__()" object because alignof
> > returns "recommended" object alignment for the architecture, which can be
> > sub-optimal on some architectures. By ensuring alignment on the object size, we
> > are sure to make the right choice.
> > 
> > Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> > CC: Russell King - ARM Linux <linux@arm.linux.org.uk>
> > Cc: Alexander Shishkin <virtuoso@slind.org>,
> > CC: linux-arm-kernel@lists.infradead.org
> > CC: Imre Deak <imre.deak@nokia.com>
> > CC: Jamie Lokier <jamie@shareable.org>
> > CC: rostedt@goodmis.org
> > CC: mingo@elte.hu
> 
> Acked-by: Alexander Shishkin <virtuoso@slind.org>
> 
> > ---
> >  include/linux/kernel.h |   45 +++++++++++++++++++++++++++++++++++++++++----
> >  1 file changed, 41 insertions(+), 4 deletions(-)
> > 
> > Index: linux-2.6-lttng/include/linux/kernel.h
> > ===================================================================
> > --- linux-2.6-lttng.orig/include/linux/kernel.h	2010-03-27 20:46:07.000000000 -0400
> > +++ linux-2.6-lttng/include/linux/kernel.h	2010-03-28 20:06:27.000000000 -0400
> > @@ -37,10 +37,47 @@ extern const char linux_proc_banner[];
> >  
> >  #define STACK_MAGIC	0xdeadbeef
> >  
> > -#define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
> > -#define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
> > -#define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
> > -#define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
> > +#define ALIGN(x, a)		__ALIGN_MASK((x), (typeof(x)) (a) - 1)
> > +#define __ALIGN_MASK(x, mask)	(((x) + (mask)) & ~(mask))
> > +#define PTR_ALIGN(p, a)		((typeof(p)) ALIGN((unsigned long) (p), (a)))
> > +#define ALIGN_FLOOR(x, a)	__ALIGN_FLOOR_MASK((x), (typeof(x)) (a) - 1)
> > +#define __ALIGN_FLOOR_MASK(x, mask)	((x) & ~(mask))
> > +#define PTR_ALIGN_FLOOR(p, a) \
> > +			((typeof(p)) ALIGN_FLOOR((unsigned long) (p), (a)))
> > +#define IS_ALIGNED(x, a)	(((x) & ((typeof(x)) (a) - 1)) == 0)
> > +
> > +/*
> > + * Align pointer on natural object alignment. Object size must be power of two.
> > + */
> > +#define object_align(obj)	PTR_ALIGN((obj), sizeof(*(obj)))
> > +#define object_align_floor(obj)	PTR_ALIGN_FLOOR((obj), sizeof(*(obj)))
> > +
> > +/**
> > + * offset_align - Calculate the offset needed to align an object on its natural
> > + *                alignment towards higher addresses.
> > + * @align_drift:  object offset from an "alignment"-aligned address.
> > + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> > + *
> > + * Returns the offset that must be added to align towards higher
> > + * addresses.
> > + */
> > +static inline size_t offset_align(size_t align_drift, size_t alignment)
> > +{
> > +	return (alignment - align_drift) & (alignment - 1);
> > +}
> > +
> > +/**
> > + * offset_align_floor - Calculate the offset needed to align an object
> > + *                      on its natural alignment towards lower addresses.
> > + * @align_drift:  object offset from an "alignment"-aligned address.
> > + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> > + *
> > + * Returns the offset that must be substracted to align towards lower addresses.
> > + */
> > +static inline size_t offset_align_floor(size_t align_drift, size_t alignment)
> > +{
> > +	return (align_drift - alignment) & (alignment - 1);
> > +}
> >  
> >  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
> >  
> > 
> > -- 
> > Mathieu Desnoyers
> > Operating System Efficiency R&D Consultant
> > EfficiOS Inc.
> > http://www.efficios.com

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH] create generic alignment api (v5)
  2010-05-01 19:10       ` Mathieu Desnoyers
@ 2010-05-01 19:29         ` Alexander Shishkin
  2010-05-01 19:45           ` Mathieu Desnoyers
  0 siblings, 1 reply; 8+ messages in thread
From: Alexander Shishkin @ 2010-05-01 19:29 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: Imre Deak, Russell King - ARM Linux, linux-arm-kernel,
	Jamie Lokier, rostedt, mingo, linux-kernel

On Sat, May 01, 2010 at 03:10:45 -0400, Mathieu Desnoyers wrote:
> * Alexander Shishkin (virtuoso@slind.org) wrote:
> > On Sun, Mar 28, 2010 at 08:09:00 -0400, Mathieu Desnoyers wrote:
> > > Rather than re-doing the "alignment on a type size" trick all over again at
> > > different levels, import the "ltt_align" from LTTng into kernel.h and make this
> > > available to everyone. Renaming to:
> > > 
> > > - object_align()
> > > - object_align_floor()
> > > - offset_align()
> > > - offset_align_floor()
> > 
> > Do you plan to have this integrated to the mainline? I'd like to use one of
> > these in my next version of the __xchg patch. So, do you need any help or
> > feedback or whatnot with this one?
> 
> Given that no one seems to oppose to this patch, I think I'll just re-submit it
> as-is for real this time.

Sorry, a short explanation: it has to be a separate header file in order to be of
use to me, since I need those in system.h, which gets included implicitly through
bitops.h earlier in kernel.h.

So I took the liberty to hack up a v6 of this patch.

Regards,
--
Alex

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH] create generic alignment api (v5)
  2010-05-01 19:29         ` Alexander Shishkin
@ 2010-05-01 19:45           ` Mathieu Desnoyers
  0 siblings, 0 replies; 8+ messages in thread
From: Mathieu Desnoyers @ 2010-05-01 19:45 UTC (permalink / raw)
  To: Imre Deak, Russell King - ARM Linux, linux-arm-kernel,
	Jamie Lokier, rostedt, mingo, linux-kernel

* Alexander Shishkin (virtuoso@slind.org) wrote:
> On Sat, May 01, 2010 at 03:10:45 -0400, Mathieu Desnoyers wrote:
> > * Alexander Shishkin (virtuoso@slind.org) wrote:
> > > On Sun, Mar 28, 2010 at 08:09:00 -0400, Mathieu Desnoyers wrote:
> > > > Rather than re-doing the "alignment on a type size" trick all over again at
> > > > different levels, import the "ltt_align" from LTTng into kernel.h and make this
> > > > available to everyone. Renaming to:
> > > > 
> > > > - object_align()
> > > > - object_align_floor()
> > > > - offset_align()
> > > > - offset_align_floor()
> > > 
> > > Do you plan to have this integrated to the mainline? I'd like to use one of
> > > these in my next version of the __xchg patch. So, do you need any help or
> > > feedback or whatnot with this one?
> > 
> > Given that no one seems to oppose to this patch, I think I'll just re-submit it
> > as-is for real this time.
> 
> Sorry, a short explanation: it has to be a separate header file in order to be of
> use to me, since I need those in system.h, which gets included implicitly through
> bitops.h earlier in kernel.h.
> 
> So I took the liberty to hack up a v6 of this patch.

Yep, I'm ok with this change.

Thanks,

Mathieu

> 
> Regards,
> --
> Alex

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-05-01 19:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-28  1:22 [RFC PATCH] create generic alignment api (v2) Mathieu Desnoyers
2010-03-28 15:40 ` Imre Deak
2010-03-28 18:29   ` Mathieu Desnoyers
2010-03-29  0:09   ` [RFC PATCH] create generic alignment api (v5) Mathieu Desnoyers
2010-05-01 18:35     ` Alexander Shishkin
2010-05-01 19:10       ` Mathieu Desnoyers
2010-05-01 19:29         ` Alexander Shishkin
2010-05-01 19:45           ` Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).