diff options
Diffstat (limited to 'tools/perf/util/include')
23 files changed, 236 insertions, 83 deletions
diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h new file mode 100644 index 00000000000..6789d788d49 --- /dev/null +++ b/tools/perf/util/include/asm/alternative-asm.h @@ -0,0 +1,8 @@ +#ifndef _PERF_ASM_ALTERNATIVE_ASM_H +#define _PERF_ASM_ALTERNATIVE_ASM_H + +/* Just disable it so we can build arch/x86/lib/memcpy_64.S for perf bench: */ + +#define altinstruction_entry # + +#endif diff --git a/tools/perf/util/include/asm/bug.h b/tools/perf/util/include/asm/bug.h deleted file mode 100644 index 7fcc6810adc..00000000000 --- a/tools/perf/util/include/asm/bug.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _PERF_ASM_GENERIC_BUG_H -#define _PERF_ASM_GENERIC_BUG_H - -#define __WARN_printf(arg...)	do { fprintf(stderr, arg); } while (0) - -#define WARN(condition, format...) ({		\ -	int __ret_warn_on = !!(condition);	\ -	if (unlikely(__ret_warn_on))		\ -		__WARN_printf(format);		\ -	unlikely(__ret_warn_on);		\ -}) - -#define WARN_ONCE(condition, format...)	({	\ -	static int __warned;			\ -	int __ret_warn_once = !!(condition);	\ -						\ -	if (unlikely(__ret_warn_once))		\ -		if (WARN(!__warned, format)) 	\ -			__warned = 1;		\ -	unlikely(__ret_warn_once);		\ -}) -#endif diff --git a/tools/perf/util/include/asm/byteorder.h b/tools/perf/util/include/asm/byteorder.h index b722abe3a62..2a9bdc06630 100644 --- a/tools/perf/util/include/asm/byteorder.h +++ b/tools/perf/util/include/asm/byteorder.h @@ -1,2 +1,2 @@  #include <asm/types.h> -#include "../../../../include/linux/swab.h" +#include "../../../../include/uapi/linux/swab.h" diff --git a/tools/perf/util/include/asm/cpufeature.h b/tools/perf/util/include/asm/cpufeature.h new file mode 100644 index 00000000000..acffd5e4d1d --- /dev/null +++ b/tools/perf/util/include/asm/cpufeature.h @@ -0,0 +1,9 @@ + +#ifndef PERF_CPUFEATURE_H +#define PERF_CPUFEATURE_H + +/* cpufeature.h ... dummy header file for including arch/x86/lib/memcpy_64.S */ + +#define X86_FEATURE_REP_GOOD 0 + +#endif	/* PERF_CPUFEATURE_H */ diff --git a/tools/perf/util/include/asm/dwarf2.h b/tools/perf/util/include/asm/dwarf2.h new file mode 100644 index 00000000000..afe38199e92 --- /dev/null +++ b/tools/perf/util/include/asm/dwarf2.h @@ -0,0 +1,13 @@ + +#ifndef PERF_DWARF2_H +#define PERF_DWARF2_H + +/* dwarf2.h ... dummy header file for including arch/x86/lib/mem{cpy,set}_64.S */ + +#define CFI_STARTPROC +#define CFI_ENDPROC +#define CFI_REMEMBER_STATE +#define CFI_RESTORE_STATE + +#endif	/* PERF_DWARF2_H */ + diff --git a/tools/perf/util/include/asm/hash.h b/tools/perf/util/include/asm/hash.h new file mode 100644 index 00000000000..d82b170bb21 --- /dev/null +++ b/tools/perf/util/include/asm/hash.h @@ -0,0 +1,6 @@ +#ifndef __ASM_GENERIC_HASH_H +#define __ASM_GENERIC_HASH_H + +/* Stub */ + +#endif /* __ASM_GENERIC_HASH_H */ diff --git a/tools/perf/util/include/asm/unistd_32.h b/tools/perf/util/include/asm/unistd_32.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tools/perf/util/include/asm/unistd_32.h @@ -0,0 +1 @@ + diff --git a/tools/perf/util/include/asm/unistd_64.h b/tools/perf/util/include/asm/unistd_64.h new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tools/perf/util/include/asm/unistd_64.h @@ -0,0 +1 @@ + diff --git a/tools/perf/util/include/dwarf-regs.h b/tools/perf/util/include/dwarf-regs.h index cf6727e99c4..8f149655f49 100644 --- a/tools/perf/util/include/dwarf-regs.h +++ b/tools/perf/util/include/dwarf-regs.h @@ -1,7 +1,7 @@  #ifndef _PERF_DWARF_REGS_H_  #define _PERF_DWARF_REGS_H_ -#ifdef DWARF_SUPPORT +#ifdef HAVE_DWARF_SUPPORT  const char *get_arch_regstr(unsigned int n);  #endif diff --git a/tools/perf/util/include/linux/bitmap.h b/tools/perf/util/include/linux/bitmap.h index eda4416efa0..01ffd12dc79 100644 --- a/tools/perf/util/include/linux/bitmap.h +++ b/tools/perf/util/include/linux/bitmap.h @@ -4,7 +4,12 @@  #include <string.h>  #include <linux/bitops.h> +#define DECLARE_BITMAP(name,bits) \ +	unsigned long name[BITS_TO_LONGS(bits)] +  int __bitmap_weight(const unsigned long *bitmap, int bits); +void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, +		 const unsigned long *bitmap2, int bits);  #define BITMAP_LAST_WORD_MASK(nbits)					\  (									\ @@ -32,4 +37,13 @@ static inline int bitmap_weight(const unsigned long *src, int nbits)  	return __bitmap_weight(src, nbits);  } +static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, +			     const unsigned long *src2, int nbits) +{ +	if (small_const_nbits(nbits)) +		*dst = *src1 | *src2; +	else +		__bitmap_or(dst, src1, src2, nbits); +} +  #endif /* _PERF_BITOPS_H */ diff --git a/tools/perf/util/include/linux/bitops.h b/tools/perf/util/include/linux/bitops.h index bb4ac2e0538..dadfa7e5428 100644 --- a/tools/perf/util/include/linux/bitops.h +++ b/tools/perf/util/include/linux/bitops.h @@ -2,17 +2,41 @@  #define _PERF_LINUX_BITOPS_H_  #include <linux/kernel.h> +#include <linux/compiler.h>  #include <asm/hweight.h> +#ifndef __WORDSIZE +#define __WORDSIZE (__SIZEOF_LONG__ * 8) +#endif +  #define BITS_PER_LONG __WORDSIZE  #define BITS_PER_BYTE           8  #define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) +#define BITS_TO_U64(nr)         DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64)) +#define BITS_TO_U32(nr)         DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32)) +#define BITS_TO_BYTES(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE) + +#define for_each_set_bit(bit, addr, size) \ +	for ((bit) = find_first_bit((addr), (size));		\ +	     (bit) < (size);					\ +	     (bit) = find_next_bit((addr), (size), (bit) + 1)) + +/* same as for_each_set_bit() but use bit as value to start with */ +#define for_each_set_bit_from(bit, addr, size) \ +	for ((bit) = find_next_bit((addr), (size), (bit));	\ +	     (bit) < (size);					\ +	     (bit) = find_next_bit((addr), (size), (bit) + 1))  static inline void set_bit(int nr, unsigned long *addr)  {  	addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);  } +static inline void clear_bit(int nr, unsigned long *addr) +{ +	addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG)); +} +  static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)  {  	return ((1UL << (nr % BITS_PER_LONG)) & @@ -24,4 +48,113 @@ static inline unsigned long hweight_long(unsigned long w)  	return sizeof(w) == 4 ? hweight32(w) : hweight64(w);  } +#define BITOP_WORD(nr)		((nr) / BITS_PER_LONG) + +/** + * __ffs - find first bit in word. + * @word: The word to search + * + * Undefined if no bit exists, so code should check against 0 first. + */ +static __always_inline unsigned long __ffs(unsigned long word) +{ +	int num = 0; + +#if BITS_PER_LONG == 64 +	if ((word & 0xffffffff) == 0) { +		num += 32; +		word >>= 32; +	} +#endif +	if ((word & 0xffff) == 0) { +		num += 16; +		word >>= 16; +	} +	if ((word & 0xff) == 0) { +		num += 8; +		word >>= 8; +	} +	if ((word & 0xf) == 0) { +		num += 4; +		word >>= 4; +	} +	if ((word & 0x3) == 0) { +		num += 2; +		word >>= 2; +	} +	if ((word & 0x1) == 0) +		num += 1; +	return num; +} + +typedef const unsigned long __attribute__((__may_alias__)) long_alias_t; + +/* + * Find the first set bit in a memory region. + */ +static inline unsigned long +find_first_bit(const unsigned long *addr, unsigned long size) +{ +	long_alias_t *p = (long_alias_t *) addr; +	unsigned long result = 0; +	unsigned long tmp; + +	while (size & ~(BITS_PER_LONG-1)) { +		if ((tmp = *(p++))) +			goto found; +		result += BITS_PER_LONG; +		size -= BITS_PER_LONG; +	} +	if (!size) +		return result; + +	tmp = (*p) & (~0UL >> (BITS_PER_LONG - size)); +	if (tmp == 0UL)		/* Are any bits set? */ +		return result + size;	/* Nope. */ +found: +	return result + __ffs(tmp); +} + +/* + * Find the next set bit in a memory region. + */ +static inline unsigned long +find_next_bit(const unsigned long *addr, unsigned long size, unsigned long offset) +{ +	const unsigned long *p = addr + BITOP_WORD(offset); +	unsigned long result = offset & ~(BITS_PER_LONG-1); +	unsigned long tmp; + +	if (offset >= size) +		return size; +	size -= result; +	offset %= BITS_PER_LONG; +	if (offset) { +		tmp = *(p++); +		tmp &= (~0UL << offset); +		if (size < BITS_PER_LONG) +			goto found_first; +		if (tmp) +			goto found_middle; +		size -= BITS_PER_LONG; +		result += BITS_PER_LONG; +	} +	while (size & ~(BITS_PER_LONG-1)) { +		if ((tmp = *(p++))) +			goto found_middle; +		result += BITS_PER_LONG; +		size -= BITS_PER_LONG; +	} +	if (!size) +		return result; +	tmp = *p; + +found_first: +	tmp &= (~0UL >> (BITS_PER_LONG - size)); +	if (tmp == 0UL)		/* Are any bits set? */ +		return result + size;	/* Nope. */ +found_middle: +	return result + __ffs(tmp); +} +  #endif diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h deleted file mode 100644 index 791f9dd27eb..00000000000 --- a/tools/perf/util/include/linux/compiler.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _PERF_LINUX_COMPILER_H_ -#define _PERF_LINUX_COMPILER_H_ - -#ifndef __always_inline -#define __always_inline	inline -#endif -#define __user -#define __attribute_const__ - -#define __used		__attribute__((__unused__)) - -#endif diff --git a/tools/perf/util/include/linux/const.h b/tools/perf/util/include/linux/const.h new file mode 100644 index 00000000000..c10a35e1afb --- /dev/null +++ b/tools/perf/util/include/linux/const.h @@ -0,0 +1 @@ +#include "../../../../include/uapi/linux/const.h" diff --git a/tools/perf/util/include/linux/hash.h b/tools/perf/util/include/linux/hash.h deleted file mode 100644 index 201f5739799..00000000000 --- a/tools/perf/util/include/linux/hash.h +++ /dev/null @@ -1,5 +0,0 @@ -#include "../../../../include/linux/hash.h" - -#ifndef PERF_HASH_H -#define PERF_HASH_H -#endif diff --git a/tools/perf/util/include/linux/kernel.h b/tools/perf/util/include/linux/kernel.h index 1eb804fd3fb..9844c31b7c2 100644 --- a/tools/perf/util/include/linux/kernel.h +++ b/tools/perf/util/include/linux/kernel.h @@ -8,8 +8,8 @@  #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)) +#define PERF_ALIGN(x, a)	__PERF_ALIGN_MASK(x, (typeof(x))(a)-1) +#define __PERF_ALIGN_MASK(x, mask)	(((x)+(mask))&~(mask))  #ifndef offsetof  #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) @@ -46,9 +46,22 @@  	_min1 < _min2 ? _min1 : _min2; })  #endif +#ifndef roundup +#define roundup(x, y) (                                \ +{                                                      \ +	const typeof(y) __y = y;		       \ +	(((x) + (__y - 1)) / __y) * __y;	       \ +}                                                      \ +) +#endif +  #ifndef BUG_ON +#ifdef NDEBUG +#define BUG_ON(cond) do { if (cond) {} } while (0) +#else  #define BUG_ON(cond) assert(!(cond))  #endif +#endif  /*   * Both need more care to handle endianness @@ -81,12 +94,6 @@ static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)  	return (i >= ssize) ? (ssize - 1) : i;  } -static inline unsigned long -simple_strtoul(const char *nptr, char **endptr, int base) -{ -	return strtoul(nptr, endptr, base); -} -  int eprintf(int level,  	    const char *fmt, ...) __attribute__((format(printf, 2, 3))); @@ -108,4 +115,14 @@ int eprintf(int level,  #define pr_debug3(fmt, ...) pr_debugN(3, pr_fmt(fmt), ##__VA_ARGS__)  #define pr_debug4(fmt, ...) pr_debugN(4, pr_fmt(fmt), ##__VA_ARGS__) +/* + * This looks more complex than it should be. But we need to + * get the type for the ~ right in round_down (it needs to be + * as wide as the result!), and we want to evaluate the macro + * arguments just once each. + */ +#define __round_mask(x, y) ((__typeof__(x))((y)-1)) +#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) +#define round_down(x, y) ((x) & ~__round_mask(x, y)) +  #endif diff --git a/tools/perf/util/include/linux/linkage.h b/tools/perf/util/include/linux/linkage.h new file mode 100644 index 00000000000..06387cffe12 --- /dev/null +++ b/tools/perf/util/include/linux/linkage.h @@ -0,0 +1,13 @@ + +#ifndef PERF_LINUX_LINKAGE_H_ +#define PERF_LINUX_LINKAGE_H_ + +/* linkage.h ... for including arch/x86/lib/memcpy_64.S */ + +#define ENTRY(name)				\ +	.globl name;				\ +	name: + +#define ENDPROC(name) + +#endif	/* PERF_LINUX_LINKAGE_H_ */ diff --git a/tools/perf/util/include/linux/list.h b/tools/perf/util/include/linux/list.h index f5ca26e53fb..76ddbc72634 100644 --- a/tools/perf/util/include/linux/list.h +++ b/tools/perf/util/include/linux/list.h @@ -1,3 +1,6 @@ +#include <linux/kernel.h> +#include <linux/types.h> +  #include "../../../../include/linux/list.h"  #ifndef PERF_LIST_H @@ -22,5 +25,5 @@ static inline void list_del_range(struct list_head *begin,   * @head: the head for your list.   */  #define list_for_each_from(pos, head) \ -	for (; prefetch(pos->next), pos != (head); pos = pos->next) +	for (; pos != (head); pos = pos->next)  #endif diff --git a/tools/perf/util/include/linux/module.h b/tools/perf/util/include/linux/module.h deleted file mode 100644 index b43e2dc21e0..00000000000 --- a/tools/perf/util/include/linux/module.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef PERF_LINUX_MODULE_H -#define PERF_LINUX_MODULE_H - -#define EXPORT_SYMBOL(name) - -#endif diff --git a/tools/perf/util/include/linux/prefetch.h b/tools/perf/util/include/linux/prefetch.h deleted file mode 100644 index 7841e485d8c..00000000000 --- a/tools/perf/util/include/linux/prefetch.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef PERF_LINUX_PREFETCH_H -#define PERF_LINUX_PREFETCH_H - -static inline void prefetch(void *a __attribute__((unused))) { } - -#endif diff --git a/tools/perf/util/include/linux/rbtree.h b/tools/perf/util/include/linux/rbtree.h index 7a243a14303..2a030c5af3a 100644 --- a/tools/perf/util/include/linux/rbtree.h +++ b/tools/perf/util/include/linux/rbtree.h @@ -1 +1,2 @@ +#include <stdbool.h>  #include "../../../../include/linux/rbtree.h" diff --git a/tools/perf/util/include/linux/rbtree_augmented.h b/tools/perf/util/include/linux/rbtree_augmented.h new file mode 100644 index 00000000000..9d6fcdf1788 --- /dev/null +++ b/tools/perf/util/include/linux/rbtree_augmented.h @@ -0,0 +1,2 @@ +#include <stdbool.h> +#include "../../../../include/linux/rbtree_augmented.h" diff --git a/tools/perf/util/include/linux/string.h b/tools/perf/util/include/linux/string.h index 3b2f5900276..97a80073822 100644 --- a/tools/perf/util/include/linux/string.h +++ b/tools/perf/util/include/linux/string.h @@ -1 +1,4 @@  #include <string.h> + +void *memdup(const void *src, size_t len); +int str_append(char **s, int *len, const char *a); diff --git a/tools/perf/util/include/linux/types.h b/tools/perf/util/include/linux/types.h deleted file mode 100644 index 12de3b8112f..00000000000 --- a/tools/perf/util/include/linux/types.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _PERF_LINUX_TYPES_H_ -#define _PERF_LINUX_TYPES_H_ - -#include <asm/types.h> - -#define DECLARE_BITMAP(name,bits) \ -	unsigned long name[BITS_TO_LONGS(bits)] - -struct list_head { -	struct list_head *next, *prev; -}; - -struct hlist_head { -	struct hlist_node *first; -}; - -struct hlist_node { -	struct hlist_node *next, **pprev; -}; - -#endif  | 
