From 4bca770ede796a1ef7af9c983166d5608d9ccfaf Mon Sep 17 00:00:00 2001 From: Anton Blanchard Date: Mon, 17 Jan 2011 16:17:42 +1100 Subject: [PATCH 1/3] powerpc: perf: Fix frequency calculation for overflowing counters When profiling a benchmark that is almost 100% userspace, I noticed some wildly inaccurate profiles that showed almost all time spent in the kernel. Closer examination shows we were programming a tiny number of cycles into the PMU after each overflow (about ~200 away from the next overflow). This gets us stuck in a loop which we eventually break out of by throttling the PMU (there are regular throttle/unthrottle events in the log). It looks like we aren't setting event->hw.last_period to something same and the frequency to period calculations in perf are going haywire. With the following patch we find the correct period after a few interrupts and stay there. I also see no more throttle events. Signed-off-by: Anton Blanchard Acked-by: Benjamin Herrenschmidt Cc: linuxppc-dev@lists.ozlabs.org Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Arnaldo Carvalho de Melo LKML-Reference: <20110117161742.5feb3761@kryten> Signed-off-by: Ingo Molnar --- arch/powerpc/kernel/perf_event.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/powerpc/kernel/perf_event.c b/arch/powerpc/kernel/perf_event.c index 567480705789..ab6f6beadb57 100644 --- a/arch/powerpc/kernel/perf_event.c +++ b/arch/powerpc/kernel/perf_event.c @@ -1212,6 +1212,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val, if (left <= 0) left = period; record = 1; + event->hw.last_period = event->hw.sample_period; } if (left < 0x80000000LL) val = 0x80000000LL - left; From dd9a9ad5e1e94894433110ccbf492ed60d75ffcb Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Mon, 17 Jan 2011 14:25:06 -0200 Subject: [PATCH 2/3] perf tools: Fix handling of wildcards in tracepoint event selectors It wasn't accounting the ':' when consuming bytes in the the event selector string, so parse_events() would fail in this test: if (!(*str == 0 || *str == ',' || isspace(*str))) return -1; as *str would be pointing to '*', the last character in the '-e' arg in: $ perf record -q -a -D -e sched:sched_* | perf script -i - -s perf-script.py Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Mike Galbraith Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Tom Zanussi LKML-Reference: Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 5cb6f4bde905..1f4cfe5d32fc 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -555,7 +555,7 @@ static enum event_result parse_tracepoint_event(const char **strp, if (evt_length >= MAX_EVENT_LENGTH) return EVT_FAILED; if (strpbrk(evt_name, "*?")) { - *strp += strlen(sys_name) + evt_length; + *strp += strlen(sys_name) + evt_length + 1; /* 1 == the ':' */ return parse_multiple_tracepoint_event(sys_name, evt_name, flags); } else { From ad7f4e3f7b966ac09c8f98dbc5024813a1685775 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Mon, 17 Jan 2011 18:28:13 -0200 Subject: [PATCH 3/3] perf tools: Fix tracepoint id to string perf.data header table It was broken by f006d25 that passed just the event name, not the complete sys:event that it expected to open the /sys/.../sys/sys:event/id file to get the id. Fix it by moving it to after parse_events in cmd_record, as at that point we can just traverse the evsel_list and use evsel->attr.config + event_name(evsel) instead of re-opening the /id file. Reported-by: Franck Bui-Huu Cc: Franck Bui-Huu Cc: Frederic Weisbecker Cc: Han Pingtian Cc: Ingo Molnar Cc: Mike Galbraith Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Tom Zanussi LKML-Reference: <20110117202801.GG2085@ghostprotocols.net> Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-record.c | 2 ++ tools/perf/util/parse-events.c | 29 ----------------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index df6064ad9bf2..fcd29e8af29f 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -936,6 +936,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) list_for_each_entry(pos, &evsel_list, node) { if (perf_evsel__alloc_fd(pos, cpus->nr, threads->nr) < 0) goto out_free_fd; + if (perf_header__push_event(pos->attr.config, event_name(pos))) + goto out_free_fd; } event_array = malloc((sizeof(struct pollfd) * MAX_NR_CPUS * MAX_COUNTERS * threads->nr)); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 1f4cfe5d32fc..bc2732ee23eb 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -490,32 +490,6 @@ parse_multiple_tracepoint_event(char *sys_name, const char *evt_exp, return EVT_HANDLED_ALL; } -static int store_event_type(const char *orgname) -{ - char filename[PATH_MAX], *c; - FILE *file; - int id, n; - - sprintf(filename, "%s/", debugfs_path); - strncat(filename, orgname, strlen(orgname)); - strcat(filename, "/id"); - - c = strchr(filename, ':'); - if (c) - *c = '/'; - - file = fopen(filename, "r"); - if (!file) - return 0; - n = fscanf(file, "%i", &id); - fclose(file); - if (n < 1) { - pr_err("cannot store event ID\n"); - return -EINVAL; - } - return perf_header__push_event(id, orgname); -} - static enum event_result parse_tracepoint_event(const char **strp, struct perf_event_attr *attr) { @@ -559,9 +533,6 @@ static enum event_result parse_tracepoint_event(const char **strp, return parse_multiple_tracepoint_event(sys_name, evt_name, flags); } else { - if (store_event_type(evt_name) < 0) - return EVT_FAILED; - return parse_single_tracepoint_event(sys_name, evt_name, evt_length, attr, strp); }