perf/core improvements and fixes
Subsystems (2)
Arnaldo Carvalho de Melo
maintainerPATCH 1/15 perf jit: Add missing curly braces
In reply to Arnaldo Carvalho de MeloFrom: Dan Carpenter <[email protected]>
It doesn't change the runtime behavior, but my static checker complains that curly braces were intended.
--- tools/perf/jvmti/jvmti_agent.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/jvmti/jvmti_agent.c +2 -1
@@ -491,10 +491,11 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,if (sret !=1 ) goto error; } -if (padding_count) +if (padding_count) { sret =fwrite_unlocked (pad_bytes, padding_count,1 , fp);if (sret !=1 ) goto error; + }funlockfile (fp);return 0 ;
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 2/15 perf jit: Remove some no-op error handling
In reply to Arnaldo Carvalho de MeloFrom: Dan Carpenter <[email protected]>
The 'info.e_machine' struct member is an uint16_t so 'm' is never less than zero. It looks like this was maybe left over code from earlier versions so I've just removed it.
--- tools/perf/jvmti/jvmti_agent.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
tools/perf/jvmti/jvmti_agent.c +1 -6
@@ -59,7 +59,6 @@ static int get_e_machine(struct jitheader *hdr)ssize_t sret;char id[16 ];int fd, ret =-1 ; -int m =-1 ;struct {uint16_t e_type;uint16_t e_machine;
@@ -81,11 +80,7 @@ static int get_e_machine(struct jitheader *hdr)if (sret !=sizeof (info)) goto error; - m = info.e_machine; -if (m <0 ) - m =0 ;/* ELF EM_NONE */ - - hdr->elf_mach = m; + hdr->elf_mach = info.e_machine; ret =0 ; error:close (fd);
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 3/15 perf tools: Add missing linux/compiler.h include to perf-sys.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
It uses the likely/unlikely macros, so need to include <linux/compiler.h>.
--- tools/perf/perf-sys.h | 1 + 1 file changed, 1 insertion(+)
tools/perf/perf-sys.h +1 -0
@@ -5,6 +5,7 @@#include <sys/types.h> #include <sys/syscall.h> #include <linux/types.h> +#include <linux/compiler.h> #include <linux/perf_event.h> #include <asm/barrier.h>
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 4/15 perf tools: Remove tools/perf/util/include/asm/byteorder.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Not used anymore. This also stops include linux/swab.h directly from the kernel sources, remove that reference from the MANIFEST.
--- tools/perf/MANIFEST | 2 -- tools/perf/util/include/asm/byteorder.h | 2 -- 2 files changed, 4 deletions(-) delete mode 100644 tools/perf/util/include/asm/byteorder.h
tools/perf/MANIFEST +0 -2
@@ -84,10 +84,8 @@ include/asm-generic/bitops/__fls.h include/asm-generic/bitops/fls.h include/linux/list.h include/linux/hash.h -include/linux/swab.h arch/*/include/asm/unistd*.h arch/*/include/uapi/asm/unistd*.h tools/arch/*/include/uapi/asm/perf_regs.h include/linux/poison.h include/uapi/linux/const.h -include/uapi/linux/swab.h
tools/perf/util/include/asm/byteorder.h deleted +0 -2
@@ -1,2 +0,0 @@ -#include <asm/types.h> -#include "../../../../include/uapi/linux/swab.h"
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 12/15 perf probe: Warn unmatched function filter correctly
In reply to Arnaldo Carvalho de MeloFrom: Masami Hiramatsu <[email protected]>
Warn unmatched function filter correctly instead of warning "symbol-loading error", since that can be a filter issue.
Quoted 1 line
From the technical point of view, this adds a filter chech in
map__load
and if there is a filter, it returns -2 (filter-out), instead of -1 (error), and perf-probe checks it and change message.
E.g. without this fix:
# perf probe -F rt_sp* no symbols found in [kernel.kallsyms], maybe install a debug package? Failed to load symbols in kernel
With this fix:
# perf probe -F rt_sp*
no symbols passed the given filter.
Failed to find symbols matched to "rt_sp*"
Error: Failed to show functions.--- tools/perf/util/map.c | 3 +++ tools/perf/util/probe-event.c | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
tools/perf/util/map.c +3 -0
@@ -312,6 +312,9 @@ int map__load(struct map *map, symbol_filter_t filter)pr_warning ("%.*s was updated (is prelink enabled?). " "Restart the long running apps that use it!\n" , (int )real_len, name); + }else if (filter) { +pr_warning ("no symbols passed the given filter.\n" ); +return -2 ;/* Empty but maybe by the filter */ }else {pr_warning ("no symbols found in %s, maybe install " "a debug package?\n" , name);
tools/perf/util/probe-event.c +10 -2
@@ -3312,8 +3312,16 @@ int show_available_funcs(const char *target, struct strfilter *_filter,/* Load symbols with given filter */ available_func_filter = _filter; -if (map__load (map, filter_available_functions)) { -pr_err ("Failed to load symbols in %s\n" , (target) ? :"kernel" ); + ret =map__load (map, filter_available_functions); +if (ret) { +if (ret ==-2 ) { +char *str =strfilter__string (_filter); +pr_err ("Failed to find symbols matched to \"%s\"\n" , + str); +free (str); + }else +pr_err ("Failed to load symbols in %s\n" , + (target) ? :"kernel" ); goto end; }if (!dso__sorted_by_name (map->dso, map->type))
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 7/15 tools: Copy the bitops files accessed from the kernel and check for drift
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
copy some more kernel files accessed from tools/, check for drift.
--- tools/include/asm-generic/bitops/__fls.h | 44 +++++++++++++++++++++++- tools/include/asm-generic/bitops/arch_hweight.h | 26 +++++++++++++- tools/include/asm-generic/bitops/const_hweight.h | 44 +++++++++++++++++++++++- tools/include/asm-generic/bitops/fls.h | 42 +++++++++++++++++++++- tools/include/asm-generic/bitops/fls64.h | 37 +++++++++++++++++++- tools/perf/MANIFEST | 5 --- tools/perf/Makefile.perf | 15 ++++++++ 7 files changed, 203 insertions(+), 10 deletions(-)
tools/include/asm-generic/bitops/__fls.h +43 -1
@@ -1 +1,43 @@ -#include "../../../../include/asm-generic/bitops/__fls.h" +#ifndef _ASM_GENERIC_BITOPS___FLS_H_ +#define _ASM_GENERIC_BITOPS___FLS_H_ + +#include <asm/types.h> + +/** +* __fls - find last (most-significant) set bit in a long word +* @word: the word to search +* +* Undefined if no set bit exists, so code should check against 0 first. +*/ +static __always_inline unsigned long __fls (unsigned long word) +{ +int num =BITS_PER_LONG -1 ; + +#if BITS_PER_LONG ==64 +if (!(word & (~0ul <<32 ))) { + num -=32 ; + word <<=32 ; + } +#endif +if (!(word & (~0ul << (BITS_PER_LONG -16 )))) { + num -=16 ; + word <<=16 ; + } +if (!(word & (~0ul << (BITS_PER_LONG -8 )))) { + num -=8 ; + word <<=8 ; + } +if (!(word & (~0ul << (BITS_PER_LONG -4 )))) { + num -=4 ; + word <<=4 ; + } +if (!(word & (~0ul << (BITS_PER_LONG -2 )))) { + num -=2 ; + word <<=2 ; + } +if (!(word & (~0ul << (BITS_PER_LONG -1 )))) + num -=1 ; +return num; +} + +#endif /* _ASM_GENERIC_BITOPS___FLS_H_ */
tools/include/asm-generic/bitops/arch_hweight.h +25 -1
@@ -1 +1,25 @@ -#include "../../../../include/asm-generic/bitops/arch_hweight.h" +#ifndef _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_ +#define _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_ + +#include <asm/types.h> + +static inline unsigned int __arch_hweight32 (unsigned int w) +{ +return __sw_hweight32 (w); +} + +static inline unsigned int __arch_hweight16 (unsigned int w) +{ +return __sw_hweight16 (w); +} + +static inline unsigned int __arch_hweight8 (unsigned int w) +{ +return __sw_hweight8 (w); +} + +static inline unsigned long __arch_hweight64 (__u64 w) +{ +return __sw_hweight64 (w); +} +#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */
tools/include/asm-generic/bitops/const_hweight.h +43 -1
44 lines not on this page · raw message
tools/include/asm-generic/bitops/fls.h +41 -1
42 lines not on this page · raw message
tools/include/asm-generic/bitops/fls64.h +36 -1
@@ -1 +1,36 @@ -#include "../../../../include/asm-generic/bitops/fls64.h" +#ifndef _ASM_GENERIC_BITOPS_FLS64_H_ +#define _ASM_GENERIC_BITOPS_FLS64_H_ + +#include <asm/types.h> + +/** +* fls64 - find last set bit in a 64-bit word +* @x: the word to search +* +* This is defined in a similar way as the libc and compiler builtin +* ffsll, but returns the position of the most significant set bit. +* +* fls64(value) returns 0 if value is 0 or the position of the last +* set bit if value is nonzero. The last (most significant) bit is +* at position 64. +*/ +#if BITS_PER_LONG ==32 +static __always_inline int fls64(__u64 x) +{ +__u32 h = x >>32 ; +if (h) +return fls (h) +32 ; +return fls (x); +} +#elif BITS_PER_LONG ==64 +static __always_inline int fls64(__u64 x) +{ +if (x ==0 ) +return 0 ; +return __fls (x) +1 ; +} +#else +#error BITS_PER_LONG not 32 or 64 +#endif + +#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */
tools/perf/MANIFEST +0 -5
@@ -77,11 +77,6 @@ tools/include/linux/stringify.h tools/include/linux/types.h tools/include/linux/err.h tools/include/linux/bitmap.h -include/asm-generic/bitops/arch_hweight.h -include/asm-generic/bitops/const_hweight.h -include/asm-generic/bitops/fls64.h -include/asm-generic/bitops/__fls.h -include/asm-generic/bitops/fls.h include/linux/list.h include/linux/hash.h tools/arch/*/include/uapi/asm/perf_regs.h
tools/perf/Makefile.perf +15 -0
@@ -411,6 +411,21 @@ $(PERF_IN): prepare FORCE @(test -f ../../arch/arm64/include/uapi/asm/kvm.h && ( \ (diff -B ../arch/arm64/include/uapi/asm/kvm.h ../../arch/arm64/include/uapi/asm/kvm.h >/dev/null) \ || echo "Warning: tools/arch/arm64/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true + @(test -f ../../include/asm-generic/bitops/arch_hweight.h && ( \ + (diff -B ../include/asm-generic/bitops/arch_hweight.h ../../include/asm-generic/bitops/arch_hweight.h >/dev/null) \ + || echo "Warning: tools/include/asm-generic/bitops/arch_hweight.h differs from kernel" >&2 )) || true + @(test -f ../../include/asm-generic/bitops/const_hweight.h && ( \ + (diff -B ../include/asm-generic/bitops/const_hweight.h ../../include/asm-generic/bitops/const_hweight.h >/dev/null) \ + || echo "Warning: tools/include/asm-generic/bitops/const_hweight.h differs from kernel" >&2 )) || true + @(test -f ../../include/asm-generic/bitops/__fls.h && ( \ + (diff -B ../include/asm-generic/bitops/__fls.h ../../include/asm-generic/bitops/__fls.h >/dev/null) \ + || echo "Warning: tools/include/asm-generic/bitops/__fls.h differs from kernel" >&2 )) || true + @(test -f ../../include/asm-generic/bitops/fls.h && ( \ + (diff -B ../include/asm-generic/bitops/fls.h ../../include/asm-generic/bitops/fls.h >/dev/null) \ + || echo "Warning: tools/include/asm-generic/bitops/fls.h differs from kernel" >&2 )) || true + @(test -f ../../include/asm-generic/bitops/fls64.h && ( \ + (diff -B ../include/asm-generic/bitops/fls64.h ../../include/asm-generic/bitops/fls64.h >/dev/null) \ + || echo "Warning: tools/include/asm-generic/bitops/fls64.h differs from kernel" >&2 )) || true $(Q)$(MAKE) $(build)=perf $(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(LIBTRACEEVENT_DYNAMIC_LIST)
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 13/15 perf script python: Fix string vs byte array resolving
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Jirka reported that python code returns all arrays as strings. This makes impossible to get all items for byte array tracepoint field containing 0x00 value item.
Fixing this by scanning full length of the array and returning it as PyByteArray object in case non printable byte is found.
--- .../util/scripting-engines/trace-event-python.c | 39 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-)
tools/perf/util/scripting-engines/trace-event-python.c +33 -6
@@ -386,6 +386,21 @@ exit:return pylist; } +static int is_printable_array (char *p,unsigned int len) +{ +unsigned int i; + +if (!p || !len || p[len -1 ] !=0 ) +return 0 ; + + len--; + +for (i =0 ; i < len; i++) { +if (!isprint (p[i]) && !isspace (p[i])) +return 0 ; + } +return 1 ; +} static void python_process_tracepoint(struct perf_sample *sample, struct perf_evsel *evsel,
@@ -457,14 +472,26 @@ static void python_process_tracepoint(struct perf_sample *sample,pydict_set_item_string_decref (dict,"common_callchain" , callchain); }for (field = event->format.fields; field; field = field->next) { -if (field->flags &FIELD_IS_STRING ) { -int offset; +unsigned int offset, len; +unsigned long long val; + +if (field->flags &FIELD_IS_ARRAY ) { + offset = field->offset; + len = field->size;if (field->flags &FIELD_IS_DYNAMIC ) { - offset = *(int *)(data + field->offset); + val =pevent_read_number (scripting_context->pevent, + data + offset, len); + offset = val; + len = offset >>16 ; offset &=0xffff ; - }else - offset = field->offset; - obj =PyString_FromString ((char *)data + offset); + } +if (field->flags &FIELD_IS_STRING && +is_printable_array (data + offset, len)) { + obj =PyString_FromString ((char *) data + offset); + }else { + obj =PyByteArray_FromStringAndSize ((const char *) data + offset, len); + field->flags &= ~FIELD_IS_STRING ; + } }else {/* FIELD_IS_NUMERIC */ obj =get_field_numeric_entry (event, field, data); }
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 5/15 perf tools: Remove tools/perf/util/include/linux/const.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Not used anymore, remove one more file referencing kernel sources, i.e. outside of tools/
--- tools/perf/MANIFEST | 1 - tools/perf/util/include/linux/const.h | 1 - 2 files changed, 2 deletions(-) delete mode 100644 tools/perf/util/include/linux/const.h
tools/perf/MANIFEST +0 -1
@@ -88,4 +88,3 @@ arch/*/include/asm/unistd*.h arch/*/include/uapi/asm/unistd*.h tools/arch/*/include/uapi/asm/perf_regs.h include/linux/poison.h -include/uapi/linux/const.h
tools/perf/util/include/linux/const.h deleted +0 -1
@@ -1 +0,0 @@ -#include "../../../../include/uapi/linux/const.h"
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 8/15 perf tools: Remove include/linux/list.h from perf's MANIFEST
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
It hasn't been used since we made tools/ self sufficiente wrt list.h.
--- tools/perf/MANIFEST | 1 - 1 file changed, 1 deletion(-)
tools/perf/MANIFEST +0 -1
@@ -77,7 +77,6 @@ tools/include/linux/stringify.h tools/include/linux/types.h tools/include/linux/err.h tools/include/linux/bitmap.h -include/linux/list.h include/linux/hash.h tools/arch/*/include/uapi/asm/perf_regs.h include/linux/poison.h
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 6/15 Remove: kernel unistd*h files from perf's MANIFEST, not used
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No need to copy it to a detached tarball as they aren't used anymore
--- tools/perf/MANIFEST | 2 -- 1 file changed, 2 deletions(-)
tools/perf/MANIFEST +0 -2
@@ -84,7 +84,5 @@ include/asm-generic/bitops/__fls.h include/asm-generic/bitops/fls.h include/linux/list.h include/linux/hash.h -arch/*/include/asm/unistd*.h -arch/*/include/uapi/asm/unistd*.h tools/arch/*/include/uapi/asm/perf_regs.h include/linux/poison.h
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 9/15 tools: Copy linux/{hash,poison}.h and check for drift
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
We were also using this directly from the kernel sources, the two last cases, fix it.
--- tools/include/linux/hash.h | 105 +++++++++++++++++++++++++++++++++++++++++-- tools/include/linux/poison.h | 91 ++++++++++++++++++++++++++++++++++++- tools/perf/MANIFEST | 2 - tools/perf/Makefile.perf | 3 ++ 4 files changed, 195 insertions(+), 6 deletions(-)
tools/include/linux/hash.h +102 -3
@@ -1,5 +1,104 @@ -#include "../../../include/linux/hash.h" +#ifndef _LINUX_HASH_H +#define _LINUX_HASH_H +/* Fast hashing routine for ints, longs and pointers. +(C) 2002 Nadia Yvette Chambers, IBM */ -#ifndef _TOOLS_LINUX_HASH_H -#define _TOOLS_LINUX_HASH_H +#include <asm/types.h> +#include <linux/compiler.h> + +/* +* The "GOLDEN_RATIO_PRIME" is used in ifs/btrfs/brtfs_inode.h and +* fs/inode.c. It's not actually prime any more (the previous primes +* were actively bad for hashing), but the name remains. +*/ +#if BITS_PER_LONG ==32 +#define GOLDEN_RATIO_PRIME GOLDEN_RATIO_32 +#define hash_long (val, bits) hash_32(val, bits) +#elif BITS_PER_LONG ==64 +#define hash_long (val, bits) hash_64(val, bits) +#define GOLDEN_RATIO_PRIME GOLDEN_RATIO_64 +#else +#error Wordsize not 32 or 64 +#endif + +/* +* This hash multiplies the input by a large odd number and takes the +* high bits. Since multiplication propagates changes to the most +* significant end only, it is essential that the high bits of the +* product be used for the hash value. +* +* Chuck Lever verified the effectiveness of this technique: +* http://www.citi.umich.edu/techreports/reports/citi-tr-00-1.pdf +* +* Although a random odd number will do, it turns out that the golden +* ratio phi = (sqrt(5)-1)/2, or its negative, has particularly nice +* properties. (See Knuth vol 3, section 6.4, exercise 9.) +* +* These are the negative, (1 - phi) = phi**2 = (3 - sqrt(5))/2, +* which is very slightly easier to multiply by and makes no +* difference to the hash distribution. +*/ +#define GOLDEN_RATIO_32 0x61C88647 +#define GOLDEN_RATIO_64 0x61C8864680B583EBull + +#ifdef CONFIG_HAVE_ARCH_HASH +/* This header may use the GOLDEN_RATIO_xx constants */ +#include <asm/hash.h> +#endif + +/* +* The _generic versions exist only so lib/test_hash.c can compare +* the arch-optimized versions with the generic. +* +* Note that if you change these, any <asm/hash.h> that aren't updated +* to match need to have their HAVE_ARCH_* define values updated so the +* self-test will not false-positive. +*/ +#ifndef HAVE_ARCH__HASH_32 +#define __hash_32 __hash_32_generic +#endif +static inline u32 __hash_32_generic (u32 val) +{ +return val *GOLDEN_RATIO_32 ; +} + +#ifndef HAVE_ARCH_HASH_32 +#define hash_32 hash_32_generic#endif +static inline u32 hash_32_generic (u32 val,unsigned int bits) +{ +/* High bits are more random, so use them. */ +return __hash_32 (val) >> (32 - bits); +} + +#ifndef HAVE_ARCH_HASH_64 +#define hash_64 hash_64_generic +#endif +static __always_inline u32 hash_64_generic(u64 val, unsigned int bits) +{ +#if BITS_PER_LONG ==64 +/* 64x64-bit multiply is efficient on all 64-bit processors */ +return val *GOLDEN_RATIO_64 >> (64 - bits); +#else +/* Hash 64 bits using only 32x32-bit multiply. */ +return hash_32 ((u32 )val ^__hash_32 (val >>32 ), bits); +#endif +} + +static inline u32 hash_ptr (const void *ptr,unsigned int bits) +{ +return hash_long ((unsigned long )ptr, bits); +} + +/* This really should be called fold32_ptr; it does no hashing to speak of. */ +static inline u32 hash32_ptr (const void *ptr) +{ +unsigned long val = (unsigned long )ptr; + +#if BITS_PER_LONG ==64 + val ^= (val >>32 ); +#endif +return (u32 )val; +} + +#endif /* _LINUX_HASH_H */
tools/include/linux/poison.h +90 -1
91 lines not on this page · raw message
tools/perf/MANIFEST +0 -2
@@ -77,6 +77,4 @@ tools/include/linux/stringify.h tools/include/linux/types.h tools/include/linux/err.h tools/include/linux/bitmap.h -include/linux/hash.h tools/arch/*/include/uapi/asm/perf_regs.h -include/linux/poison.h
tools/perf/Makefile.perf +3 -0
@@ -351,6 +351,9 @@ $(PERF_IN): prepare FORCE @(test -f ../../include/uapi/linux/perf_event.h && ( \ (diff -B ../include/uapi/linux/perf_event.h ../../include/uapi/linux/perf_event.h >/dev/null) \ || echo "Warning: tools/include/uapi/linux/perf_event.h differs from kernel" >&2 )) || true + @(test -f ../../include/linux/hash.h && ( \ + (diff -B ../include/linux/hash.h ../../include/linux/hash.h >/dev/null) \ + || echo "Warning: tools/include/linux/hash.h differs from kernel" >&2 )) || true @(test -f ../../include/uapi/linux/hw_breakpoint.h && ( \ (diff -B ../include/uapi/linux/hw_breakpoint.h ../../include/uapi/linux/hw_breakpoint.h >/dev/null) \ || echo "Warning: tools/include/uapi/linux/hw_breakpoint.h differs from kernel" >&2 )) || true
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 15/15 perf tests: Add is_printable_array test
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add automated test for is_printable_array function.
--- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 ++++ tools/perf/tests/is_printable_array.c | 36 +++++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + 4 files changed, 42 insertions(+) create mode 100644 tools/perf/tests/is_printable_array.c
tools/perf/tests/Build +1 -0
@@ -40,6 +40,7 @@ perf-y += event_update.o perf-y += event-times.o perf-y += backward-ring-buffer.o perf-y += sdt.o +perf-y += is_printable_array.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir)
tools/perf/tests/builtin-test.c +4 -0
@@ -222,6 +222,10 @@ static struct test generic_tests[] = { .func = test__sdt_event, }, { + .desc = "Test is_printable_array function", + .func = test__is_printable_array, + }, + { .func = NULL, }, };
tools/perf/tests/is_printable_array.c new file +36 -0
@@ -0,0 +1,36 @@ +#include <linux/compiler.h> +#include "tests.h" +#include "debug.h" +#include "util.h" + +int test__is_printable_array (int subtest__maybe_unused ) +{ +char buf1[] = {'k' ,'r' ,4 ,'v' ,'a' ,0 }; +char buf2[] = {'k' ,'r' ,'a' ,'v' ,4 ,0 }; +struct { +char *buf; +unsigned int len; +int ret; + } t[] = { + { (char *)"krava" ,sizeof ("krava" ),1 }, + { (char *)"krava" ,sizeof ("krava" ) -1 ,0 }, + { (char *)"" ,sizeof ("" ),1 }, + { (char *)"" ,0 ,0 }, + {NULL ,0 ,0 }, + { buf1,sizeof (buf1),0 }, + { buf2,sizeof (buf2),0 }, + }; +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (t); i++) { +int ret; + + ret =is_printable_array ((char *) t[i].buf, t[i].len); +if (ret != t[i].ret) { +pr_err ("failed: test %u\n" , i); +return TEST_FAIL ; + } + } + +return TEST_OK ; +}
tools/perf/tests/tests.h +1 -0
@@ -89,6 +89,7 @@ int test__event_times(int subtest);int test__backward_ring_buffer (int subtest);int test__cpu_map_print (int subtest);int test__sdt_event (int subtest); +int test__is_printable_array (int subtest);#if defined(__arm__) || defined(__aarch64__)#ifdef HAVE_DWARF_UNWIND_SUPPORT
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 14/15 perf tools: Make is_printable_array global
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
It's used from 2 objects in perf, so it's better to keep just one copy.
--- tools/perf/util/python.c | 12 ------------ tools/perf/util/scripting-engines/trace-event-python.c | 16 ---------------- tools/perf/util/util.c | 16 ++++++++++++++++ tools/perf/util/util.h | 1 + 4 files changed, 17 insertions(+), 28 deletions(-)
tools/perf/util/python.c +0 -12
@@ -295,18 +295,6 @@ static bool is_tracepoint(struct pyrf_event *pevent)return pevent->evsel->attr.type ==PERF_TYPE_TRACEPOINT ; } -static int is_printable_array (char *p,unsigned int len) -{ -unsigned int i; - -for (i =0 ; i < len; i++) { -if (!isprint (p[i]) && !isspace (p[i])) -return 0 ; - } - -return 1 ; -} -static PyObject *tracepoint_field (struct pyrf_event *pe,struct format_field *field) {
tools/perf/util/scripting-engines/trace-event-python.c +0 -16
@@ -386,22 +386,6 @@ exit:return pylist; } -static int is_printable_array (char *p,unsigned int len) -{ -unsigned int i; - -if (!p || !len || p[len -1 ] !=0 ) -return 0 ; - - len--; - -for (i =0 ; i < len; i++) { -if (!isprint (p[i]) && !isspace (p[i])) -return 0 ; - } -return 1 ; -} -static void python_process_tracepoint (struct perf_sample *sample,struct perf_evsel *evsel,struct addr_location *al)
tools/perf/util/util.c +16 -0
@@ -746,3 +746,19 @@ void print_binary(unsigned char *data, size_t len, }printer (BINARY_PRINT_DATA_END ,-1 , extra); } + +int is_printable_array (char *p,unsigned int len) +{ +unsigned int i; + +if (!p || !len || p[len -1 ] !=0 ) +return 0 ; + + len--; + +for (i =0 ; i < len; i++) { +if (!isprint (p[i]) && !isspace (p[i])) +return 0 ; + } +return 1 ; +}
tools/perf/util/util.h +1 -0
@@ -364,4 +364,5 @@ void print_binary(unsigned char *data, size_t len,extern int sched_getcpu (void );#endif +int is_printable_array (char *p,unsigned int len);#endif /* GIT_COMPAT_UTIL_H */
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 11/15 perf cpu_map: Add more helpers
In reply to Arnaldo Carvalho de MeloFrom: Mark Rutland <[email protected]>
In some cases it's necessry to figure out the map-local index of a given Linux logical CPU ID. Add a new helper, cpu_map__idx, to acquire this. As the logic is largely the same as the existing cpu_map__has, this is rewritten in terms of the new helper.
At the same time, add the inverse operation, cpu_map__cpu, which yields the logical CPU id for a map-local index. While this can be performed manually, wrapping this in a helper can make code more legible.
--- tools/perf/util/cpumap.c | 14 ++++++++++++-- tools/perf/util/cpumap.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-)
tools/perf/util/cpumap.c +12 -2
@@ -589,14 +589,24 @@ int cpu__setup_cpunode_map(void)bool cpu_map__has (struct cpu_map *cpus,int cpu) { +return cpu_map__idx (cpus, cpu) !=-1 ; +} + +int cpu_map__idx (struct cpu_map *cpus,int cpu) +{int i;for (i =0 ; i < cpus->nr; ++i) {if (cpus->map[i] == cpu) -return true; +return i; } -return false; +return -1 ; +} + +int cpu_map__cpu (struct cpu_map *cpus,int idx) +{ +return cpus->map[idx]; }size_t cpu_map__snprint (struct cpu_map *map,char *buf,size_t size)
tools/perf/util/cpumap.h +2 -0
@@ -68,5 +68,7 @@ int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,int (*f)(struct cpu_map *map,int cpu,void *data), void *data); +int cpu_map__cpu (struct cpu_map *cpus,int idx);bool cpu_map__has (struct cpu_map *cpus,int cpu); +int cpu_map__idx (struct cpu_map *cpus,int cpu);#endif /* __PERF_CPUMAP_H */
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerFrom: Arnaldo Carvalho de Melo <[email protected]>
Hi Ingo,
Please consider pulling,
- Arnaldo
Build stats:
[root@jouet 5]# perf stat dm
alpine:3.4: Ok
android-ndk:r12b: Ok
centos:5: Ok
centos:6: Ok
centos:7: Ok
debian:7: Ok
debian:8: Ok
debian:experimental: Ok
fedora:21: Ok
fedora:22: Ok
fedora:23: Ok
fedora:24: Ok
fedora:rawhide: Ok
mageia:5: Ok
opensuse:13.2: Ok
opensuse:42.1: Ok
ubuntu:14.04.4: Ok
ubuntu:15.10: Ok
ubuntu:16.04: Ok
ubuntu:16.04-x-armhf: Ok
Performance counter stats for 'dm':
1896.227285 task-clock (msec) # 0.002 CPUs utilized
76,145 context-switches # 0.040 M/sec
9,323 cpu-migrations # 0.005 M/sec
53,894 page-faults # 0.028 M/sec
5,497,625,679 cycles # 2.899 GHz
5,110,226,458 instructions # 0.93 insn per cycle
950,036,839 branches # 501.014 M/sec
16,978,253 branch-misses # 1.79% of all branches 767.910393301 seconds time elapsed
[root@jouet 5]#
The following changes since commit 09211e2530ab4905ec16edecc27022d6b247419d:
Merge tag 'perf-core-for-mingo-20160715' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2016-07-16 22:36:42 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo-20160718
for you to fetch changes up to 988dd774dcbd9151c2a643fc7284c5c3c4d0adb7:
perf tests: Add is_printable_array test (2016-07-18 19:50:35 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
User visible:
- Properly report when a function wildcard produces no matches in 'perf probe' (Masami Hiramatsu)
- Balance opening and reading events in 'perf stat', which could cause it to get stuck trying to close invalid file descriptors (Mark Rutland)
Infrastructure:
- Copy more headers from the kernel, this time for headers that were just including the contents of its kernel counterparts, should help resolving the problems with linux-next, where some uapi related patches seem to be breaking tools/object/ build.
Some more combing will be done, but at least it is possible to build perf out of tree, via a detached tarball (make help | grep perf) without including kernel files in its MANIFEST (Arnaldo Carvalho de Melo)
- Fix smatch found errors that were not causing problems, but are mistakes nonetheless (Dan Carpenter)
- Fix string vs byte array resolving in the python script code (Jiri Olsa)
----------------------------------------------------------------
Arnaldo Carvalho de Melo (7):
perf tools: Add missing linux/compiler.h include to perf-sys.h perf tools: Remove tools/perf/util/include/asm/byteorder.h perf tools: Remove tools/perf/util/include/linux/const.h
Remove: kernel unistd*h files from perf's MANIFEST, not used
tools: Copy the bitops files accessed from the kernel and check for drift perf tools: Remove include/linux/list.h from perf's MANIFEST
tools: Copy linux/{hash,poison}.h and check for drift
Dan Carpenter (2):
perf jit: Add missing curly braces
perf jit: Remove some no-op error handling
Jiri Olsa (3):
perf script python: Fix string vs byte array resolving perf tools: Make is_printable_array global perf tests: Add is_printable_array test
Mark Rutland (2):
perf stat: Balance opening and reading events perf cpu_map: Add more helpers
Masami Hiramatsu (1):
perf probe: Warn unmatched function filter correctly
tools/include/asm-generic/bitops/__fls.h | 44 ++++++++- tools/include/asm-generic/bitops/arch_hweight.h | 26 ++++- tools/include/asm-generic/bitops/const_hweight.h | 44 ++++++++- tools/include/asm-generic/bitops/fls.h | 42 ++++++++- tools/include/asm-generic/bitops/fls64.h | 37 +++++++- tools/include/linux/hash.h | 105 ++++++++++++++++++++- tools/include/linux/poison.h | 91 +++++++++++++++++- tools/perf/MANIFEST | 13 --- tools/perf/Makefile.perf | 18 ++++ tools/perf/builtin-stat.c | 8 +- tools/perf/jvmti/jvmti_agent.c | 10 +- tools/perf/perf-sys.h | 1 + tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/is_printable_array.c | 36 +++++++ tools/perf/tests/tests.h | 1 + tools/perf/util/cpumap.c | 14 ++- tools/perf/util/cpumap.h | 2 + tools/perf/util/include/asm/byteorder.h | 2 - tools/perf/util/include/linux/const.h | 1 - tools/perf/util/map.c | 3 + tools/perf/util/probe-event.c | 12 ++- tools/perf/util/python.c | 12 --- .../util/scripting-engines/trace-event-python.c | 25 +++-- tools/perf/util/util.c | 16 ++++ tools/perf/util/util.h | 1 + 26 files changed, 512 insertions(+), 57 deletions(-) create mode 100644 tools/perf/tests/is_printable_array.c delete mode 100644 tools/perf/util/include/asm/byteorder.h delete mode 100644 tools/perf/util/include/linux/const.h
Arnaldo Carvalho de Melo
maintainerPATCH 10/15 perf stat: Balance opening and reading events
From: Mark Rutland <[email protected]>
In create_perf_stat_counter, when a target CPU has not been provided, we call __perf_evsel__open with empty_cpu_map, and open a single FD per thread. However, in read_counter we assume that we opened events for the product of threads and CPUs described in the evsel's cpu_map.
Thus, if an evsel has a cpu_map with more than one entry, we will attempt to access FDs that we didn't open. This could result in a number of problems (e.g. blocking while reading from STDIN if the fd memory happened to be initialised to zero).
This is problematic for systems were a logical CPU PMU covers some arbitrary subset of CPUs. The cpu_map of any evsel for that PMU will be initialised based on the cpumask exposed through sysfs, even if the user requests per-thread events.
--- tools/perf/builtin-stat.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/builtin-stat.c +6 -2
@@ -290,8 +290,12 @@ perf_evsel__write_stat_event(struct perf_evsel *counter, u32 cpu, u32 thread,static int read_counter (struct perf_evsel *counter) {int nthreads =thread_map__nr (evsel_list->threads); -int ncpus =perf_evsel__nr_cpus (counter); -int cpu, thread; +int ncpus, cpu, thread; + +if (target__has_cpu (&target)) + ncpus =perf_evsel__nr_cpus (counter); +else + ncpus =1 ;if (!counter->supported)return -ENOENT ;
Signature · 1 line
2.7.4
Quoted 136 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
Hi Ingo,
Please consider pulling,
- Arnaldo
Build stats:
[root@jouet 5]# perf stat dm
alpine:3.4: Ok
android-ndk:r12b: Ok
centos:5: Ok
centos:6: Ok
centos:7: Ok
debian:7: Ok
debian:8: Ok
debian:experimental: Ok
fedora:21: Ok
fedora:22: Ok
fedora:23: Ok
fedora:24: Ok
fedora:rawhide: Ok
mageia:5: Ok
opensuse:13.2: Ok
opensuse:42.1: Ok
ubuntu:14.04.4: Ok
ubuntu:15.10: Ok
ubuntu:16.04: Ok
ubuntu:16.04-x-armhf: OkPerformance counter stats for 'dm':
1896.227285 task-clock (msec) # 0.002 CPUs utilized 76,145 context-switches # 0.040 M/sec 9,323 cpu-migrations # 0.005 M/sec 53,894 page-faults # 0.028 M/sec 5,497,625,679 cycles # 2.899 GHz 5,110,226,458 instructions # 0.93 insn per cycle 950,036,839 branches # 501.014 M/sec 16,978,253 branch-misses # 1.79% of all branches767.910393301 seconds time elapsed[root@jouet 5]#
The following changes since commit
09211e2530ab4905ec16edecc27022d6b247419d:Merge tag 'perf-core-for-mingo-20160715' of
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linuxinto perf/core (2016-07-16 22:36:42 +0200)are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-core-for-mingo-20160718for you to fetch changes up to
988dd774dcbd9151c2a643fc7284c5c3c4d0adb7:perf tests: Add
is_printable_arraytest (2016-07-18 19:50:35 -0300)----------------------------------------------------------------
perf/core improvements and fixes:User visible:
- Properly report when a function wildcard produces no matches in 'perf probe' (Masami Hiramatsu)
- Balance opening and reading events in 'perf stat', which could cause it to get stuck trying to close invalid file descriptors (Mark Rutland)
Infrastructure:
- Copy more headers from the kernel, this time for headers that were just including the contents of its kernel counterparts, should help resolving the problems with linux-next, where some uapi related patches seem to be breaking
tools/object/build.Some more combing will be done, but at least it is possible to build perf out of tree, via a detached tarball (make help | grep perf) without including kernel files in its MANIFEST (Arnaldo Carvalho de Melo)
- Fix smatch found errors that were not causing problems, but are mistakes nonetheless (Dan Carpenter)
- Fix string vs byte array resolving in the python script code (Jiri Olsa)
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Arnaldo Carvalho de Melo (7):
perf tools: Add missinglinux/compiler.hinclude toperf-sys.hperf tools: Removetools/perf/util/include/asm/byteorder.hperf tools: Removetools/perf/util/include/linux/const.h
Remove: kernel unistd*h files from perf's MANIFEST, not used
tools: Copy the bitops files accessed from the kernel and check for drift perf tools: Removeinclude/linux/list.hfrom perf's MANIFEST
tools: Copylinux/{hash,poison}.hand check for driftDan Carpenter (2):
perf jit: Add missing curly braces
perf jit: Remove some no-op error handlingJiri Olsa (3):
perf script python: Fix string vs byte array resolving perf tools: Makeis_printable_arrayglobal perf tests: Addis_printable_arraytestMark Rutland (2):
perf stat: Balance opening and reading events perfcpu_map: Add more helpersMasami Hiramatsu (1):
perf probe: Warn unmatched function filter correctlytools/include/asm-generic/bitops/__fls.h | 44 ++++++++- tools/include/asm-generic/bitops/arch_hweight.h | 26 ++++- tools/include/asm-generic/bitops/const_hweight.h | 44 ++++++++- tools/include/asm-generic/bitops/fls.h | 42 ++++++++- tools/include/asm-generic/bitops/fls64.h | 37 +++++++- tools/include/linux/hash.h | 105 ++++++++++++++++++++- tools/include/linux/poison.h | 91 +++++++++++++++++- tools/perf/MANIFEST | 13 --- tools/perf/Makefile.perf | 18 ++++ tools/perf/builtin-stat.c | 8 +- tools/perf/jvmti/jvmti_agent.c | 10 +- tools/perf/perf-sys.h | 1 + tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/is_printable_array.c | 36 +++++++ tools/perf/tests/tests.h | 1 + tools/perf/util/cpumap.c | 14 ++- tools/perf/util/cpumap.h | 2 + tools/perf/util/include/asm/byteorder.h | 2 - tools/perf/util/include/linux/const.h | 1 - tools/perf/util/map.c | 3 + tools/perf/util/probe-event.c | 12 ++-
Quoted 8 lines
tools/perf/util/python.c | 12 --- .../util/scripting-engines/trace-event-python.c | 25 +++-- tools/perf/util/util.c | 16 ++++ tools/perf/util/util.h | 1 + 26 files changed, 512 insertions(+), 57 deletions(-) create mode 100644 tools/perf/tests/is_printable_array.c delete mode 100644 tools/perf/util/include/asm/byteorder.h delete mode 100644 tools/perf/util/include/linux/const.h
Pulled, thanks a lot Arnaldo!
Ingo
Re: [PATCH 13/15] perf script python: Fix string vs byte array resolving
In reply to Arnaldo Carvalho de MeloQuoted 35 lines · On Mon, 18 Jul 2016 20:33:16 -0300 Arnaldo Carvalho de Melo <[email protected]>…
From: Jiri Olsa <[email protected]>
Jirka reported that python code returns all arrays as strings. This makes impossible to get all items for byte array tracepoint field containing
0x00value item.Fixing this by scanning full length of the array and returning it as PyByteArray object in case non printable byte is found.
Signed-off-by Jiri Olsa <[email protected]>Reported-and-Tested-by Jiri Pirko <[email protected]>Cc David Ahern <[email protected]>Cc Namhyung Kim <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Steven Rostedt <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- .../util/scripting-engines/trace-event-python.c | 39 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-)tools/perf/util/scripting-engines/trace-event-python.c +6
-0@@ -386,6 +386,21 @@ exit:return pylist; } +static int is_printable_array (char *p,unsigned int len) +{ +unsigned int i; + +if (!p || !len || p[len -1 ] !=0 ) +return 0 ;
tools/perf/util/scripting-engines/trace-event-python.c exit: · line 404
Quoted 10 lines
tools/perf/util/scripting-engines/trace-event-python.c +9
-0+ + len--; + +for (i =0 ; i < len; i++) { +if (!isprint (p[i]) && !isspace (p[i])) +return 0 ; + } +return 1 ; +}
Darn, I never got to add my Reviewed-by tag, as I had lots of comments on this function. Oh well, that's what happens when you go off to volcanoes.
-- Steve