From: rostedt@goodmis.org (Steven Rostedt)
Subject: [ltt-dev] [RFC PATCH 01/20] Create generic alignment API (v8)
Date: Tue, 17 Aug 2010 21:25:26 -0400 [thread overview]
Message-ID: <1282094726.3268.2197.camel@gandalf.stny.rr.com> (raw)
In-Reply-To: <20100817232150.251244768@efficios.com>
On Tue, 2010-08-17 at 19:16 -0400, Mathieu Desnoyers wrote:
> +/*
> + * Align pointer on natural object alignment. Object size must be power of two.
> + */
Hmm, I wonder if we should add a compiler bug here too.
extern void __bug_obj_not_power_of_two(void);
({
if ((sizeof(*obj) - 1) & sizeof(*obj))
__bug_obj_not_power_of_two();
PTR_ALIGN((obj), __alignof__(*(obj)));
})
> +#define object_align(obj) PTR_ALIGN((obj), __alignof__(*(obj)))
> +#define object_align_floor(obj) PTR_ALIGN_FLOOR((obj), __alignof__(*(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);
> +}
I take it that theses functions can have variables passed to it for
alignment, thus a check wont help. Although, we could add a test for the
constant case.
-- Steve
> +
next prev parent reply other threads:[~2010-08-18 1:25 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-17 23:16 [ltt-dev] [RFC PATCH 00/20] Generic Ring Buffer Library (v2) Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 01/20] Create generic alignment API (v8) Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-18 0:00 ` Kirill A. Shutemov
2010-08-18 1:05 ` Mathieu Desnoyers
2010-08-18 1:25 ` Steven Rostedt [this message]
2010-08-18 2:09 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 02/20] Notifier atomic call chain notrace Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 03/20] Idle notifier standardization Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 04/20] Idle notifier standardization x86_32 Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 05/20] Poll : add poll_wait_set_exclusive Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 06/20] Prio_heap: heap_remove(), heap_maximum(), heap_replace() and heap_cherrypick() Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 07/20] kthread: Add kthread_kill_stop() Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 08/20] Add inline memcpy Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 09/20] x86: " Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 10/20] Trace clock - build standalone Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 11/20] Ftrace ring buffer renaming (v2) Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 12/20] Ring buffer backend Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 13/20] Ring buffer frontend Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 14/20] Ring buffer library - documentation (v2) Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 15/20] Ring buffer library - VFS operations (v2) Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 16/20] Ring buffer library - client sample Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 17/20] Ring buffer benchmark library Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 18/20] Ring buffer record iterator Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 19/20] Ring buffer library: basic API (v2) Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` [ltt-dev] [RFC PATCH 20/20] Ring buffer: benchmark simple " Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
2010-08-17 23:16 ` Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1282094726.3268.2197.camel@gandalf.stny.rr.com \
--to=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox