From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [lttng-dev] [PATCH 05/20] lttng: offset alignment header
Date: Mon, 28 Nov 2011 07:42:12 -0500 [thread overview]
Message-ID: <1322484147-30598-6-git-send-email-mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <1322484147-30598-1-git-send-email-mathieu.desnoyers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
---
drivers/staging/lttng/lib/align.h | 61 +++++++++++++++++++++++++++++++++++++
1 files changed, 61 insertions(+), 0 deletions(-)
create mode 100644 drivers/staging/lttng/lib/align.h
diff --git a/drivers/staging/lttng/lib/align.h b/drivers/staging/lttng/lib/align.h
new file mode 100644
index 0000000..0b86100
--- /dev/null
+++ b/drivers/staging/lttng/lib/align.h
@@ -0,0 +1,61 @@
+#ifndef _LTTNG_ALIGN_H
+#define _LTTNG_ALIGN_H
+
+/*
+ * lib/align.h
+ *
+ * (C) Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#ifdef __KERNEL__
+
+#include <linux/types.h>
+#include "bug.h"
+
+#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))
+
+/*
+ * Align pointer on natural object alignment.
+ */
+#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.
+ */
+#define offset_align(align_drift, alignment) \
+ ({ \
+ BUILD_RUNTIME_BUG_ON((alignment) == 0 \
+ || ((alignment) & ((alignment) - 1))); \
+ (((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.
+ */
+#define offset_align_floor(align_drift, alignment) \
+ ({ \
+ BUILD_RUNTIME_BUG_ON((alignment) == 0 \
+ || ((alignment) & ((alignment) - 1))); \
+ (((align_drift) - (alignment)) & ((alignment) - 1); \
+ })
+
+#endif /* __KERNEL__ */
+
+#endif
--
1.7.2.5
next prev parent reply other threads:[~2011-11-28 12:42 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-28 12:42 [lttng-dev] LTTng driver submission for staging (2nd attempt) Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 01/20] lttng lib: lttng priority heap Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 02/20] lttng lib: ring buffer Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 03/20] lttng lib: portable bitfield read/write header Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 04/20] lttng: BUILD_RUNTIME_BUG_ON Mathieu Desnoyers
2011-11-28 12:42 ` Mathieu Desnoyers [this message]
2011-11-28 12:42 ` [lttng-dev] [PATCH 06/20] lttng libs: add Makefile Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 07/20] lttng wrappers Mathieu Desnoyers
2011-11-29 1:04 ` Greg KH
2011-11-29 2:22 ` Mathieu Desnoyers
2011-11-30 6:23 ` Greg KH
2011-11-28 12:42 ` [lttng-dev] [PATCH 08/20] lttng instrumentation: tracepoint events Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 09/20] lttng: syscall instrumentation Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 10/20] lttng: lib ring buffer clients Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 11/20] lttng: tracer control and core structures Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 12/20] lttng: dynamically selectable context information Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 13/20] lttng: timing calibration feature Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 14/20] lttng: debugfs and procfs ABI Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 15/20] lttng: Add documentation and TODO files Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 16/20] lttng: add system call instrumentation probe Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 17/20] lttng: probe callbacks Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 18/20] lttng: toplevel Makefile and Kconfig Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 19/20] staging: add LTTng to build Mathieu Desnoyers
2011-11-28 12:42 ` [lttng-dev] [PATCH 20/20] Add LTTng entry to MAINTAINERS file Mathieu Desnoyers
2011-11-29 1:07 ` [lttng-dev] LTTng driver submission for staging (2nd attempt) Greg KH
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=1322484147-30598-6-git-send-email-mathieu.desnoyers@efficios.com \
--to=mathieu.desnoyers@efficios.com \
/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