|
@@ -1,6 +1,16 @@
|
|
|
#ifndef PERF_LINUX_KERNEL_H_
|
|
|
#define PERF_LINUX_KERNEL_H_
|
|
|
|
|
|
+#include <stdarg.h>
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <assert.h>
|
|
|
+
|
|
|
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
|
|
+
|
|
|
+#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
|
|
|
+#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
|
|
|
+
|
|
|
#ifndef offsetof
|
|
|
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
|
|
#endif
|
|
@@ -26,4 +36,53 @@
|
|
|
_max1 > _max2 ? _max1 : _max2; })
|
|
|
#endif
|
|
|
|
|
|
+#ifndef min
|
|
|
+#define min(x, y) ({ \
|
|
|
+ typeof(x) _min1 = (x); \
|
|
|
+ typeof(y) _min2 = (y); \
|
|
|
+ (void) (&_min1 == &_min2); \
|
|
|
+ _min1 < _min2 ? _min1 : _min2; })
|
|
|
+#endif
|
|
|
+
|
|
|
+#ifndef BUG_ON
|
|
|
+#define BUG_ON(cond) assert(!(cond))
|
|
|
+#endif
|
|
|
+
|
|
|
+/*
|
|
|
+ * Both need more care to handle endianness
|
|
|
+ * (Don't use bitmap_copy_le() for now)
|
|
|
+ */
|
|
|
+#define cpu_to_le64(x) (x)
|
|
|
+#define cpu_to_le32(x) (x)
|
|
|
+
|
|
|
+static inline int
|
|
|
+vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ ssize_t ssize = size;
|
|
|
+
|
|
|
+ i = vsnprintf(buf, size, fmt, args);
|
|
|
+
|
|
|
+ return (i >= ssize) ? (ssize - 1) : i;
|
|
|
+}
|
|
|
+
|
|
|
+static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
|
|
|
+{
|
|
|
+ va_list args;
|
|
|
+ ssize_t ssize = size;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ va_start(args, fmt);
|
|
|
+ i = vsnprintf(buf, size, fmt, args);
|
|
|
+ va_end(args);
|
|
|
+
|
|
|
+ return (i >= ssize) ? (ssize - 1) : i;
|
|
|
+}
|
|
|
+
|
|
|
+static inline unsigned long
|
|
|
+simple_strtoul(const char *nptr, char **endptr, int base)
|
|
|
+{
|
|
|
+ return strtoul(nptr, endptr, base);
|
|
|
+}
|
|
|
+
|
|
|
#endif
|