Path: blob/master/tools/perf/util/include/linux/kernel.h
10825 views
#ifndef PERF_LINUX_KERNEL_H_1#define PERF_LINUX_KERNEL_H_23#include <stdarg.h>4#include <stdio.h>5#include <stdlib.h>6#include <assert.h>78#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))910#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)11#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))1213#ifndef offsetof14#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)15#endif1617#ifndef container_of18/**19* container_of - cast a member of a structure out to the containing structure20* @ptr: the pointer to the member.21* @type: the type of the container struct this is embedded in.22* @member: the name of the member within the struct.23*24*/25#define container_of(ptr, type, member) ({ \26const typeof(((type *)0)->member) * __mptr = (ptr); \27(type *)((char *)__mptr - offsetof(type, member)); })28#endif2930#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))3132#ifndef max33#define max(x, y) ({ \34typeof(x) _max1 = (x); \35typeof(y) _max2 = (y); \36(void) (&_max1 == &_max2); \37_max1 > _max2 ? _max1 : _max2; })38#endif3940#ifndef min41#define min(x, y) ({ \42typeof(x) _min1 = (x); \43typeof(y) _min2 = (y); \44(void) (&_min1 == &_min2); \45_min1 < _min2 ? _min1 : _min2; })46#endif4748#ifndef BUG_ON49#define BUG_ON(cond) assert(!(cond))50#endif5152/*53* Both need more care to handle endianness54* (Don't use bitmap_copy_le() for now)55*/56#define cpu_to_le64(x) (x)57#define cpu_to_le32(x) (x)5859static inline int60vscnprintf(char *buf, size_t size, const char *fmt, va_list args)61{62int i;63ssize_t ssize = size;6465i = vsnprintf(buf, size, fmt, args);6667return (i >= ssize) ? (ssize - 1) : i;68}6970static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)71{72va_list args;73ssize_t ssize = size;74int i;7576va_start(args, fmt);77i = vsnprintf(buf, size, fmt, args);78va_end(args);7980return (i >= ssize) ? (ssize - 1) : i;81}8283static inline unsigned long84simple_strtoul(const char *nptr, char **endptr, int base)85{86return strtoul(nptr, endptr, base);87}8889int eprintf(int level,90const char *fmt, ...) __attribute__((format(printf, 2, 3)));9192#ifndef pr_fmt93#define pr_fmt(fmt) fmt94#endif9596#define pr_err(fmt, ...) \97eprintf(0, pr_fmt(fmt), ##__VA_ARGS__)98#define pr_warning(fmt, ...) \99eprintf(0, pr_fmt(fmt), ##__VA_ARGS__)100#define pr_info(fmt, ...) \101eprintf(0, pr_fmt(fmt), ##__VA_ARGS__)102#define pr_debug(fmt, ...) \103eprintf(1, pr_fmt(fmt), ##__VA_ARGS__)104#define pr_debugN(n, fmt, ...) \105eprintf(n, pr_fmt(fmt), ##__VA_ARGS__)106#define pr_debug2(fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)107#define pr_debug3(fmt, ...) pr_debugN(3, pr_fmt(fmt), ##__VA_ARGS__)108#define pr_debug4(fmt, ...) pr_debugN(4, pr_fmt(fmt), ##__VA_ARGS__)109110#endif111112113