perfcounters fixes/updates
Subsystems (4)
Linus,
Please pull the latest perfcounters-fixes-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git perfcounters-fixes-for-linus
I hope this is still fine ... most of the changes are fixes (and only affect perfcounters) and most of the diffstat is for the tooling side, but if it's too much we could trim it a bit and leave out some of the bits that are not strictly fixes:
perf_counter tools: Fix/resurrect perf top annotation in a simple interactive form perf_counter tools: Allow perf top top users to switch between weighted and individual counter display perf top: Improve interactive key handling
OTOH it's all for new-in-.31 code so it felt better to have it in.
( This isnt even all the stuff - we do have a fair amount of stuff
put aside for .32 already - but the fixes/tweaks stream is still coming in strong. I guess it's partly due to much bigger uptick in initial use and interest in perfcounters than i'd have anticipated for an August. People are supposed to be away on vacation or what. )
Thanks,
Ingo
------------------>
Arnaldo Carvalho de Melo (1):
perf report: Add debug help for the finding of symbol bugs - show the symtab origin (DSO, build-id, kernel, etc)
Brice Goglin (1):
perf stat: Fix tool option consistency: rename -S/--scale to -c/--scale
Carlos R. Mafra (1):
perf: "Longum est iter per praecepta, breve et efficax per exempla"
Frederic Weisbecker (9):
perf tools: Fix call-chain cumul hit based sub-total (fractal mode)
perf tools: callchain: Fix spurious 'perf report' warnings: ignore empty callchains
perf tools: callchain: Fix 'perf report' display to be callchain by default
perf tools: callchain: Fix sum of percentages to be 100% by displaying amount of ignored chains in fractal mode
perf_counter: Work around gcc warning by initializing tracepoint record unconditionally
perf_counter: Fix tracepoint sampling to be part of generic sampling
perf tools: callchain: Fix bad rounding of minimum rate
perf_counter: Subtract the buffer size field from the event record size
perf_counter: Zero dead bytes from ftrace raw samples size alignment
Mike Galbraith (5):
perf_counter tools: Fix/resurrect perf top annotation in a simple interactive form perf_counter tools: Allow perf top top users to switch between weighted and individual counter display perf top: Improve interactive key handling
perf top: Update man page
perf_counter tools: Fix libbfd detection for systems with libz dependency
Paul Mackerras (1):
perf_counter/powerpc: Fix oops on cpus without perf_counter hardware support
Peter Zijlstra (7):
perf_counter: Fix software counters for fast moving event sources
perf tools: Fix multi-counter stat bug caused by incorrect reading of perf.data file header perf report: Fix per task mult-counter stat reporting
perf list: Fix the output to not include tracepoints without an id
perf_counter: Fix a race on perf_counter_ctx
perf_counter: Correct PERF_SAMPLE_RAW output
perf_counter: Require CAP_SYS_ADMIN for raw tracepoint data
Pierre Habouzit (2):
perf util: Fix do_read() to fail on EOF instead of busy-looping perf record: Fix the -A UI for empty or non-existent perf.data
arch/powerpc/kernel/perf_counter.c | 8 + include/linux/perf_counter.h | 12 +- include/trace/ftrace.h | 15 +- kernel/perf_counter.c | 239 ++++++++----- tools/perf/Documentation/perf-examples.txt | 225 +++++++++++ tools/perf/Documentation/perf-stat.txt | 2 +- tools/perf/Documentation/perf-top.txt | 112 +++++- tools/perf/Makefile | 4 + tools/perf/builtin-record.c | 12 +- tools/perf/builtin-report.c | 99 +++++- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-top.c | 552 +++++++++++++++++++++++++--- tools/perf/util/callchain.c | 32 +- tools/perf/util/callchain.h | 8 +- tools/perf/util/header.c | 5 +- tools/perf/util/parse-events.c | 26 ++- tools/perf/util/parse-events.h | 1 + tools/perf/util/symbol.c | 57 +++- tools/perf/util/symbol.h | 2 + 19 files changed, 1212 insertions(+), 201 deletions(-) create mode 100644 tools/perf/Documentation/perf-examples.txt
arch/powerpc/kernel/perf_counter.c +8 -0
@@ -518,6 +518,8 @@ void hw_perf_disable(void)struct cpu_hw_counters *cpuhw;unsigned long flags; +if (!ppmu) +return ;local_irq_save (flags); cpuhw = &__get_cpu_var (cpu_hw_counters);
@@ -572,6 +574,8 @@ void hw_perf_enable(void)int n_lim;int idx; +if (!ppmu) +return ;local_irq_save (flags); cpuhw = &__get_cpu_var (cpu_hw_counters);if (!cpuhw->disabled) {
@@ -737,6 +741,8 @@ int hw_perf_group_sched_in(struct perf_counter *group_leader,long i, n, n0;struct perf_counter *sub; +if (!ppmu) +return 0 ; cpuhw = &__get_cpu_var (cpu_hw_counters); n0 = cpuhw->n_counters; n = collect_events(group_leader, ppmu->n_counter - n0,
@@ -1281,6 +1287,8 @@ void hw_perf_counter_setup(int cpu) {struct cpu_hw_counters *cpuhw = &per_cpu (cpu_hw_counters, cpu); +if (!ppmu) +return ;memset (cpuhw,0 ,sizeof (*cpuhw)); cpuhw->mmcr[0 ] =MMCR0_FC ; }
include/linux/perf_counter.h +7 -5
@@ -121,7 +121,7 @@ enum perf_counter_sample_format {PERF_SAMPLE_CPU =1U <<7 ,PERF_SAMPLE_PERIOD =1U <<8 ,PERF_SAMPLE_STREAM_ID =1U <<9 , -PERF_SAMPLE_TP_RECORD =1U <<10 , +PERF_SAMPLE_RAW =1U <<10 , PERF_SAMPLE_MAX = 1U << 11, /* non-ABI */ };
@@ -369,6 +369,8 @@ enum perf_event_type {* * { u64 nr, * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN +* { u32 size; +* char data[size];}&& PERF_SAMPLE_RAW * }; */ PERF_EVENT_SAMPLE = 9,
@@ -414,9 +416,9 @@ struct perf_callchain_entry {__u64 ip[PERF_MAX_STACK_DEPTH ]; }; -struct perf_tracepoint_record { -int size; -char *record; +struct perf_raw_record { +u32 size; +void *data; };struct task_struct ;
@@ -687,7 +689,7 @@ struct perf_sample_data {struct pt_regs *regs;u64 addr;u64 period; -void *private; +struct perf_raw_record *raw; }; extern int perf_counter_overflow(struct perf_counter *counter, int nmi,
include/trace/ftrace.h +13 -2
@@ -637,12 +637,20 @@ __attribute__((section("_ftrace_events"))) event_##call = { \* pc = preempt_count(); * * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); -* __entry_size = __data_size + sizeof(*entry); +* +* // Below we want to get the aligned size by taking into account +* // the u32 field that will later store the buffer size +* __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32), +* sizeof(u64)); +* __entry_size -= sizeof(u32); * * do { * char raw_data[__entry_size]; <- allocate our sample in the stack * struct trace_entry *ent; * +* zero dead bytes from alignment to avoid stack leak to userspace: +* +* *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; * entry = (struct ftrace_raw_<call> *)raw_data; * ent = &entry->ent; * tracing_generic_entry_update(ent, irq_flags, pc);
@@ -685,12 +693,15 @@ static void ftrace_profile_##call(proto) \ pc =preempt_count (); \ \ __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ - __entry_size = ALIGN(__data_size + sizeof(*entry), sizeof(u64));\ + __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ + sizeof(u64)); \ + __entry_size -= sizeof(u32); \ \ do { \ char raw_data[__entry_size]; \ struct trace_entry *ent; \ \ + *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \ entry = (struct ftrace_raw_##call *)raw_data; \ ent = &entry->ent; \ tracing_generic_entry_update(ent, irq_flags, pc); \
kernel/perf_counter.c +145 -94
387 lines not on this page · raw message
tools/perf/Documentation/perf-examples.txt new file +225 -0
225 lines not on this page · raw message
tools/perf/Documentation/perf-stat.txt +1 -1
@@ -40,7 +40,7 @@ OPTIONS -a:: system-wide collection --S:: +-c:: scale counter values EXAMPLES
tools/perf/Documentation/perf-top.txt +99 -13
135 lines not on this page · raw message
tools/perf/Makefile +4 -0
@@ -387,10 +387,14 @@ else has_bfd_iberty := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o /dev/null $(ALL_LDFLAGS) -lbfd -liberty > /dev/null 2>&1 && echo y") + has_bfd_iberty_z := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o /dev/null $(ALL_LDFLAGS) -lbfd -liberty -lz > /dev/null 2>&1 && echo y") + ifeq ($(has_bfd),y) EXTLIBS += -lbfd else ifeq ($(has_bfd_iberty),y) EXTLIBS += -lbfd -liberty + else ifeq ($(has_bfd_iberty_z),y) + EXTLIBS += -lbfd -liberty -lz else msg := $(warning No bfd.h/libbfd found, install binutils-dev[el] to gain symbol demangling) BASIC_CFLAGS += -DNO_DEMANGLE
tools/perf/builtin-record.c +8 -4
@@ -525,10 +525,14 @@ static int __cmd_record(int argc, const char **argv)signal (SIGCHLD , sig_handler);signal (SIGINT , sig_handler); -if (!stat (output_name, &st) && !force && !append_file) { -fprintf (stderr,"Error, output file %s exists, use -A to append or -f to overwrite.\n" , - output_name); -exit (-1 ); +if (!stat (output_name, &st) && st.st_size) { +if (!force && !append_file) { +fprintf (stderr,"Error, output file %s exists, use -A to append or -f to overwrite.\n" , + output_name); +exit (-1 ); + } + }else { + append_file =0 ; } flags =O_CREAT |O_RDWR ;
tools/perf/builtin-report.c +89 -10
200 lines not on this page · raw message
tools/perf/builtin-stat.c +1 -1
@@ -496,7 +496,7 @@ static const struct option options[] = { "stat events on existing pid"),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide,"system-wide collection from all CPUs" ), -OPT_BOOLEAN ('S' ,"scale" , &scale, +OPT_BOOLEAN ('c' ,"scale" , &scale,"scale/normalize counters" ),OPT_BOOLEAN ('v' ,"verbose" , &verbose, "be more verbose (show counter open errors, etc)"),
tools/perf/builtin-top.c +508 -44
687 lines not on this page · raw message
tools/perf/util/callchain.c +20 -12
@@ -13,6 +13,7 @@#include <stdio.h> #include <stdbool.h> #include <errno.h> +#include <math.h> #include "callchain.h"
@@ -26,10 +27,14 @@ rb_insert_callchain(struct rb_root *root, struct callchain_node *chain,struct rb_node **p = &root->rb_node;struct rb_node *parent =NULL ;struct callchain_node *rnode; +u64 chain_cumul =cumul_hits (chain);while (*p) { +u64 rnode_cumul; + parent = *p; rnode = rb_entry(parent, struct callchain_node, rb_node); + rnode_cumul =cumul_hits (rnode);switch (mode) {case CHAIN_FLAT :
@@ -40,7 +45,7 @@ rb_insert_callchain(struct rb_root *root, struct callchain_node *chain,break ;case CHAIN_GRAPH_ABS :/* Falldown */ case CHAIN_GRAPH_REL : -if (rnode->cumul_hit < chain->cumul_hit) +if (rnode_cumul < chain_cumul) p = &(*p)->rb_left;else p = &(*p)->rb_right;
@@ -87,7 +92,7 @@ static void __sort_chain_graph_abs(struct callchain_node *node,chain_for_each_child (child, node) {__sort_chain_graph_abs (child, min_hit); -if (child->cumul_hit >= min_hit) +if (cumul_hits (child) >= min_hit)rb_insert_callchain (&node->rb_root, child,CHAIN_GRAPH_ABS ); }
@@ -108,11 +113,11 @@ static void __sort_chain_graph_rel(struct callchain_node *node,u64 min_hit; node->rb_root =RB_ROOT ; - min_hit = node->cumul_hit * min_percent /100.0 ; + min_hit =ceil (node->children_hit * min_percent);chain_for_each_child (child, node) {__sort_chain_graph_rel (child, min_percent); -if (child->cumul_hit >= min_hit) +if (cumul_hits (child) >= min_hit)rb_insert_callchain (&node->rb_root, child,CHAIN_GRAPH_REL ); }
@@ -122,7 +127,7 @@ static void sort_chain_graph_rel(struct rb_root *rb_root, struct callchain_node *chain_root, u64 min_hit __used, struct callchain_param *param) { - __sort_chain_graph_rel(chain_root, param->min_percent); + __sort_chain_graph_rel(chain_root, param->min_percent / 100.0); rb_root->rb_node = chain_root->rb_root.rb_node; }
@@ -211,7 +216,8 @@ add_child(struct callchain_node *parent, struct ip_callchain *chain, new =create_child (parent, false);fill_node (new, chain, start, syms); - new->cumul_hit = new->hit =1 ; + new->children_hit =0 ; + new->hit =1 ; }/*
@@ -241,7 +247,8 @@ split_add_child(struct callchain_node *parent, struct ip_callchain *chain,/* split the hits */ new->hit = parent->hit; - new->cumul_hit = parent->cumul_hit; + new->children_hit = parent->children_hit; + parent->children_hit =cumul_hits (new); new->val_nr = parent->val_nr - idx_local; parent->val_nr = idx_local;
@@ -249,6 +256,7 @@ split_add_child(struct callchain_node *parent, struct ip_callchain *chain,if (idx_total < chain->nr) { parent->hit =0 ;add_child (parent, chain, idx_total, syms); + parent->children_hit++; }else { parent->hit =1 ; }
@@ -269,13 +277,13 @@ __append_chain_children(struct callchain_node *root, struct ip_callchain *chain,unsigned int ret =__append_chain (rnode, chain, start, syms);if (!ret) - goto cumul; + goto inc_children_hit; }/* nothing in children, add to the current node */ add_child (root, chain, start, syms); -cumul: - root->cumul_hit++; +inc_children_hit: + root->children_hit++; } static int
@@ -317,8 +325,6 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain,/* we match 100% of the path, increment the hit */ if (i - start == root->val_nr && i == chain->nr) { root->hit++; - root->cumul_hit++; -return 0 ; }
@@ -331,5 +337,7 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain,void append_chain (struct callchain_node *root,struct ip_callchain *chain,struct symbol **syms) { +if (!chain->nr) +return ;__append_chain_children (root, chain, syms,0 ); }
tools/perf/util/callchain.h +7 -1
@@ -7,6 +7,7 @@#include "symbol.h" enum chain_mode { +CHAIN_NONE ,CHAIN_FLAT ,CHAIN_GRAPH_ABS ,CHAIN_GRAPH_REL
@@ -21,7 +22,7 @@ struct callchain_node {struct rb_root rb_root;/* sorted tree of children */ unsigned int val_nr;u64 hit; -u64 cumul_hit;/* hit + hits of children */ +u64 children_hit; };struct callchain_param ;
@@ -48,6 +49,11 @@ static inline void callchain_init(struct callchain_node *node)INIT_LIST_HEAD (&node->val); } +static inline u64 cumul_hits (struct callchain_node *node) +{ +return node->hit + node->children_hit; +} +int register_callchain_param (struct callchain_param *param);void append_chain (struct callchain_node *root,struct ip_callchain *chain,struct symbol **syms);
tools/perf/util/header.c +4 -1
@@ -185,6 +185,8 @@ static void do_read(int fd, void *buf, size_t size)if (ret <0 )die ("failed to read" ); +if (ret ==0 ) +die ("failed to read: missing data" ); size -= ret; buf += ret;
@@ -213,9 +215,10 @@ struct perf_header *perf_header__read(int fd)for (i =0 ; i < nr_attrs; i++) {struct perf_header_attr *attr; -off_t tmp =lseek (fd,0 ,SEEK_CUR ); +off_t tmp;do_read (fd, &f_attr,sizeof (f_attr)); + tmp =lseek (fd,0 ,SEEK_CUR ); attr =perf_header_attr__new (&f_attr.attr);
tools/perf/util/parse-events.c +24 -2
@@ -121,13 +121,29 @@ static unsigned long hw_cache_stat[C(MAX)] = { (strcmp(sys_dirent.d_name, ".")) && \ (strcmp(sys_dirent.d_name, ".."))) +static int tp_event_has_id (struct dirent *sys_dir,struct dirent *evt_dir) +{ +char evt_path[MAXPATHLEN ]; +int fd; + +snprintf (evt_path,MAXPATHLEN ,"%s/%s/%s/id" , debugfs_path, + sys_dir->d_name, evt_dir->d_name); + fd =open (evt_path,O_RDONLY ); +if (fd <0 ) +return -EINVAL ; +close (fd); + +return 0 ; +} +#define for_each_event (sys_dirent, evt_dir, evt_dirent, evt_next, file, st) \ while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ if (snprintf(file, MAXPATHLEN, "%s/%s/%s", debugfs_path, \ sys_dirent.d_name, evt_dirent.d_name) && \ (!stat(file, &st)) && (S_ISDIR(st.st_mode)) && \ (strcmp(evt_dirent.d_name, ".")) && \ - (strcmp(evt_dirent.d_name, ".."))) + (strcmp(evt_dirent.d_name, "..")) && \ + (!tp_event_has_id(&sys_dirent, &evt_dirent)))#define MAX_EVENT_LENGTH 30
@@ -223,9 +239,15 @@ char *event_name(int counter) {u64 config = attrs[counter].config;int type = attrs[counter].type; + +return __event_name (type, config); +} + +char *__event_name (int type,u64 config) +{static char buf[32 ]; -if (attrs[counter].type ==PERF_TYPE_RAW ) { +if (type ==PERF_TYPE_RAW ) {sprintf (buf,"raw 0x%llx" , config);return buf; }
tools/perf/util/parse-events.h +1 -0
@@ -10,6 +10,7 @@ extern int nr_counters;extern struct perf_counter_attr attrs[MAX_COUNTERS ];extern char *event_name (int ctr); +extern char *__event_name (int type,u64 config);extern int parse_events (const struct option *opt,const char *str,int unset);
tools/perf/util/symbol.c +46 -11
117 lines not on this page · raw message
tools/perf/util/symbol.h +2 -0
@@ -26,6 +26,7 @@ struct dso {unsigned int sym_priv_size;unsigned char adjust_symbols;unsigned char slen_calculated; +unsigned char origin;char name[0 ]; };
@@ -49,6 +50,7 @@ int dso__load_modules(struct dso *self, symbol_filter_t filter, int verbose);int dso__load (struct dso *self,symbol_filter_t filter,int verbose);size_t dso__fprintf (struct dso *self,FILE *fp); +char dso__symtab_origin (const struct dso *self);void symbol__init (void );#endif /* _PERF_SYMBOL_ */