Skip to contentSkip to conversation

perfcounters updates

GIT PULL Ingo Molnar 1 participant 1 message Jun 30, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Linus,

Would you still be willing to pull the latest perfcounters git tree? It is at:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git perfcounters-fixes-for-linus

I kept the tree strictly within perfcounter file boundaries, so it shouldnt affect anything else - and perfcounters is a new subsystem so this shouldnt cause regressions.

The scope and size of the changes is beyond what we'd allow for a pre-existing subsystem, hence the RFC. There's a lot of interest, feedback, fixes and activities so it would be nice to have this upstream. All additions to the syscall are ABI compatible, as usual.

Thanks,

Ingo

------------------>
Arnaldo Carvalho de Melo (4):

      perf_counter tools: Adjust only prelinked symbol's addresses
      perf report: Add --dsos parameter
      perf report: Add --comms parameter
      perf report: Add --symbols parameter

Frederic Weisbecker (3):
perf record: Fix unhandled io return value perf_counter tools: Prepare a small callchain framework perf report: Print sorted callchains per histogram entries

Ingo Molnar (7):
perf_counter tools: Fix vmlinux fallback when running on a different kernel perf report: Fix help text typo
perf_counter tools: Add CREDITS file for Git contributors perf_counter tools: Remove dead code
perf stat: Add -n/--null option to run without counters
perf stat: Fix multi-run stats
perf stat: Use percentages for scaling output

Jaswinder Singh Rajput (12):
perf_counter, x8: Fix L1-data-Cache-Store-Referencees for AMD
perf_counter tools: Define separate declarations for H/W and S/W events perf_counter tools: Introduce alias member in event_symbol
perf_counter tools: Set alias for page-faults
perf stat: Fix command option / manpage
perf stat: Fix verbose for perf stat
perf stat: Remove dead code
perf_counter tools: Check for valid cache operations
perf_counter tools: Shorten names for events
perf_counter tools: Add alias for 'l1d' and 'l1i'
perf stat: Improve output
perf stat: Micro-optimize the code: memcpy is only required if no event is selected and !null_run

Johannes Weiner (1):
perf record: Fix filemap pathname parsing in /proc/pid/maps

Paul Mackerras (2):
perf_counter tools: Reduce perf stat measurement overhead/skew
perf_counter: Provide a way to enable counters on exec

Peter Zijlstra (15):
perf report: Output more symbol related debug data perf_counter tools: Handle overlapping MMAP events
perf_counter: Optimize perf_swcounter_event()
perf_counter: Push inherit into perf_counter_alloc()
perf_counter: Optimize perf_counter_alloc()'s inherit case perf_counter tools: Rework the file format
perf_counter: Split the mmap control page in two parts
perf_counter: Add scale information to the mmap control page perf_counter, x86: Add mmap counter read support
perf_counter: Add PERF_EVENT_READ
perf_counter: Implement more accurate per task statistics
perf_counter: Rework the sample ABI
perf-report: Add modes for inherited stats and no-samples
perf-report: Add bare minimum PERF_EVENT_READ parsing
perf_counter: Complete counter swap

Roel Kluin (1):
perf_counter tools: Fix strbuf_fread() error path handling

Yinghai Lu (1):
perf_counter, x86: Update x86_pmu after WARN()

Yong Wang (1):
perf_counter, x86: Set global control MSR correctly

 arch/powerpc/include/asm/perf_counter.h  |    2 +
 arch/x86/include/asm/perf_counter.h      |    3 +
 arch/x86/kernel/cpu/perf_counter.c       |   22 +--
 include/linux/perf_counter.h             |   46 ++++-
 kernel/perf_counter.c                    |  320 +++++++++++++++++++++++++-----
 tools/perf/CREDITS                       |   30 +++
 tools/perf/Documentation/perf-report.txt |   14 ++-
 tools/perf/Documentation/perf-stat.txt   |    6 +-
 tools/perf/Makefile                      |    6 +-
 tools/perf/builtin-annotate.c            |    8 +-
 tools/perf/builtin-record.c              |  127 ++++++++----
 tools/perf/builtin-report.c              |  236 ++++++++++++++++++----
 tools/perf/builtin-stat.c                |  171 ++++++++++-------
 tools/perf/builtin-top.c                 |   11 +-
 tools/perf/perf.h                        |    9 +-
 tools/perf/util/callchain.c              |  174 ++++++++++++++++
 tools/perf/util/callchain.h              |   33 +++
 tools/perf/util/header.c                 |  242 ++++++++++++++++++++++
 tools/perf/util/header.h                 |   37 ++++
 tools/perf/util/help.c                   |   15 --
 tools/perf/util/pager.c                  |    5 +-
 tools/perf/util/parse-events.c           |  153 ++++++++++-----
 tools/perf/util/run-command.c            |   95 +---------
 tools/perf/util/run-command.h            |    5 -
 tools/perf/util/strbuf.c                 |    2 +-
 tools/perf/util/string.h                 |    2 +-
 tools/perf/util/strlist.c                |  184 +++++++++++++++++
 tools/perf/util/strlist.h                |   32 +++
 tools/perf/util/symbol.c                 |   16 ++-
 tools/perf/util/symbol.h                 |    5 +-
 tools/perf/{ => util}/types.h            |    0
 tools/perf/util/util.h                   |   15 --
 32 files changed, 1604 insertions(+), 422 deletions(-)
 create mode 100644 tools/perf/CREDITS
 create mode 100644 tools/perf/util/callchain.c
 create mode 100644 tools/perf/util/callchain.h
 create mode 100644 tools/perf/util/header.c
 create mode 100644 tools/perf/util/header.h
 create mode 100644 tools/perf/util/strlist.c
 create mode 100644 tools/perf/util/strlist.h
 rename tools/perf/{ => util}/types.h (100%)
arch/powerpc/include/asm/perf_counter.h +2 -0
index 8ccd4e1..0ea0639 100644
@@ -61,6 +61,8 @@ struct pt_regs;
 extern unsigned long perf_misc_flags(struct pt_regs *regs);
 extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
 
+#define PERF_COUNTER_INDEX_OFFSET	1
+
 /*
  * Only override the default definitions in include/linux/perf_counter.h
  * if we have hardware PMU support.
arch/x86/include/asm/perf_counter.h +3 -0
index 5fb33e1..fa64e40 100644
@@ -87,6 +87,9 @@ union cpuid10_edx {
 #ifdef CONFIG_PERF_COUNTERS
 extern void init_hw_perf_counters(void);
 extern void perf_counters_lapic_init(void);
+
+#define PERF_COUNTER_INDEX_OFFSET			0
+
 #else
 static inline void init_hw_perf_counters(void)		{ }
 static inline void perf_counters_lapic_init(void)	{ }
arch/x86/kernel/cpu/perf_counter.c +10 -12
index 76dfef2..d4cf4ce 100644
@@ -401,7 +401,7 @@ static const u64 amd_hw_cache_event_ids
 		[ C(RESULT_MISS)   ] = 0x0041, /* Data Cache Misses          */
 	},
 	[ C(OP_WRITE) ] = {
-		[ C(RESULT_ACCESS) ] = 0x0042, /* Data Cache Refills from L2 */
+		[ C(RESULT_ACCESS) ] = 0x0142, /* Data Cache Refills :system */
 		[ C(RESULT_MISS)   ] = 0,
 	},
 	[ C(OP_PREFETCH) ] = {
@@ -912,6 +912,8 @@ x86_perf_counter_set_period(struct perf_counter *counter,
 	err = checking_wrmsrl(hwc->counter_base + idx,
 			     (u64)(-left) & x86_pmu.counter_mask);
 
+	perf_counter_update_userpage(counter);
+
 	return ret;
 }
 
@@ -969,13 +971,6 @@ fixed_mode_idx(struct perf_counter *counter, struct hw_perf_counter *hwc)
 	if (!x86_pmu.num_counters_fixed)
 		return -1;
 
-	/*
-	 * Quirk, IA32_FIXED_CTRs do not work on current Atom processors:
-	 */
-	if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
-					boot_cpu_data.x86_model == 28)
-		return -1;
-
 	event = hwc->config & ARCH_PERFMON_EVENT_MASK;
 
 	if (unlikely(event == x86_pmu.event_map(PERF_COUNT_HW_INSTRUCTIONS)))
@@ -1041,6 +1036,8 @@ try_generic:
 	x86_perf_counter_set_period(counter, hwc, idx);
 	x86_pmu.enable(hwc, idx);
 
+	perf_counter_update_userpage(counter);
+
 	return 0;
 }
 
@@ -1133,6 +1130,8 @@ static void x86_pmu_disable(struct perf_counter *counter)
 	x86_perf_counter_update(counter, hwc, idx);
 	cpuc->counters[idx] = NULL;
 	clear_bit(idx, cpuc->used_mask);
+
+	perf_counter_update_userpage(counter);
 }
 
 /*
@@ -1428,8 +1427,6 @@ static int intel_pmu_init(void)
 	 */
 	x86_pmu.num_counters_fixed	= max((int)edx.split.num_counters_fixed, 3);
 
-	rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, x86_pmu.intel_ctrl);
-
 	/*
 	 * Install the hw-cache-events table:
 	 */
@@ -1499,21 +1496,22 @@ void __init init_hw_perf_counters(void)
 	pr_cont("%s PMU driver.\n", x86_pmu.name);
 
 	if (x86_pmu.num_counters > X86_PMC_MAX_GENERIC) {
-		x86_pmu.num_counters = X86_PMC_MAX_GENERIC;
 		WARN(1, KERN_ERR "hw perf counters %d > max(%d), clipping!",
 		     x86_pmu.num_counters, X86_PMC_MAX_GENERIC);
+		x86_pmu.num_counters = X86_PMC_MAX_GENERIC;
 	}
 	perf_counter_mask = (1 << x86_pmu.num_counters) - 1;
 	perf_max_counters = x86_pmu.num_counters;
 
 	if (x86_pmu.num_counters_fixed > X86_PMC_MAX_FIXED) {
-		x86_pmu.num_counters_fixed = X86_PMC_MAX_FIXED;
 		WARN(1, KERN_ERR "hw perf counters fixed %d > max(%d), clipping!",
 		     x86_pmu.num_counters_fixed, X86_PMC_MAX_FIXED);
+		x86_pmu.num_counters_fixed = X86_PMC_MAX_FIXED;
 	}
 
 	perf_counter_mask |=
 		((1LL << x86_pmu.num_counters_fixed)-1) << X86_PMC_IDX_FIXED;
+	x86_pmu.intel_ctrl = perf_counter_mask;
 
 	perf_counters_lapic_init();
 	register_die_notifier(&perf_counter_nmi_notifier);
include/linux/perf_counter.h +39 -7

96 lines not on this page · raw message

kernel/perf_counter.c +271 -49

534 lines not on this page · raw message

tools/perf/CREDITS new file +30 -0
new file mode 100644
index 0000000..c2ddcb3
@@ -0,0 +1,30 @@
+Most of the infrastructure that 'perf' uses here has been reused
+from the Git project, as of version:
+
+    66996ec: Sync with 1.6.2.4
+
+Here is an (incomplete!) list of main contributors to those files
+in util/* and elsewhere:
+
+ Alex Riesen
+ Christian Couder
+ Dmitry Potapov
+ Jeff King
+ Johannes Schindelin
+ Johannes Sixt
+ Junio C Hamano
+ Linus Torvalds
+ Matthias Kestenholz
+ Michal Ostrowski
+ Miklos Vajna
+ Petr Baudis
+ Pierre Habouzit
+ René Scharfe
+ Samuel Tardieu
+ Shawn O. Pearce
+ Steffen Prohaska
+ Steve Haslam
+
+Thanks guys!
+
+The full history of the files can be found in the upstream Git commits.
tools/perf/Documentation/perf-report.txt +13 -1
index 52d3fc6..8aa3f8c 100644
@@ -13,13 +13,25 @@ SYNOPSIS
 DESCRIPTION
 -----------
 This command displays the performance counter profile information recorded
-via perf report.
+via perf record.
 
 OPTIONS
 -------
 -i::
 --input=::
         Input file name. (default: perf.data)
+-d::
+--dsos=::
+	Only consider symbols in these dsos. CSV that understands
+	file://filename entries.
+-C::
+--comms=::
+	Only consider symbols in these comms. CSV that understands
+	file://filename entries.
+-S::
+--symbols=::
+	Only consider these symbols. CSV that understands
+	file://filename entries.
 
 SEE ALSO
 --------
tools/perf/Documentation/perf-stat.txt +3 -3
index c368a72..0d74346 100644
@@ -8,8 +8,8 @@ perf-stat - Run a command and gather performance counter statistics
 SYNOPSIS
 --------
 [verse]
-'perf stat' [-e <EVENT> | --event=EVENT] [-l] [-a] <command>
-'perf stat' [-e <EVENT> | --event=EVENT] [-l] [-a] -- <command> [<options>]
+'perf stat' [-e <EVENT> | --event=EVENT] [-S] [-a] <command>
+'perf stat' [-e <EVENT> | --event=EVENT] [-S] [-a] -- <command> [<options>]
 
 DESCRIPTION
 -----------
@@ -40,7 +40,7 @@ OPTIONS
 -a::
         system-wide collection
 
--l::
+-S::
         scale counter values
 
 EXAMPLES
tools/perf/Makefile +5 -1
index 36d7eef..9c6d0ae 100644
@@ -290,7 +290,7 @@ LIB_FILE=libperf.a
 
 LIB_H += ../../include/linux/perf_counter.h
 LIB_H += perf.h
-LIB_H += types.h
+LIB_H += util/types.h
 LIB_H += util/list.h
 LIB_H += util/rbtree.h
 LIB_H += util/levenshtein.h
@@ -301,6 +301,7 @@ LIB_H += util/util.h
 LIB_H += util/help.h
 LIB_H += util/strbuf.h
 LIB_H += util/string.h
+LIB_H += util/strlist.h
 LIB_H += util/run-command.h
 LIB_H += util/sigchain.h
 LIB_H += util/symbol.h
@@ -322,12 +323,15 @@ LIB_OBJS += util/run-command.o
 LIB_OBJS += util/quote.o
 LIB_OBJS += util/strbuf.o
 LIB_OBJS += util/string.o
+LIB_OBJS += util/strlist.o
 LIB_OBJS += util/usage.o
 LIB_OBJS += util/wrapper.o
 LIB_OBJS += util/sigchain.o
 LIB_OBJS += util/symbol.o
 LIB_OBJS += util/color.o
 LIB_OBJS += util/pager.o
+LIB_OBJS += util/header.o
+LIB_OBJS += util/callchain.o
 
 BUILTIN_OBJS += builtin-annotate.o
 BUILTIN_OBJS += builtin-help.o
tools/perf/builtin-annotate.c +4 -4
index 7e58e3a..722c0f5 100644
@@ -855,7 +855,7 @@ static unsigned long total = 0,
 		     total_unknown = 0;
 
 static int
-process_overflow_event(event_t *event, unsigned long offset, unsigned long head)
+process_sample_event(event_t *event, unsigned long offset, unsigned long head)
 {
 	char level;
 	int show = 0;
@@ -1013,10 +1013,10 @@ process_period_event(event_t *event, unsigned long offset, unsigned long head)
 static int
 process_event(event_t *event, unsigned long offset, unsigned long head)
 {
-	if (event->header.misc & PERF_EVENT_MISC_OVERFLOW)
-		return process_overflow_event(event, offset, head);
-
 	switch (event->header.type) {
+	case PERF_EVENT_SAMPLE:
+		return process_sample_event(event, offset, head);
+
 	case PERF_EVENT_MMAP:
 		return process_mmap_event(event, offset, head);
 
tools/perf/builtin-record.c +87 -40

240 lines not on this page · raw message

tools/perf/builtin-report.c +197 -39

453 lines not on this page · raw message

tools/perf/builtin-stat.c +102 -69

301 lines not on this page · raw message

tools/perf/builtin-top.c +6 -5
index 5352b5e..cf0d21f 100644
@@ -392,11 +392,11 @@ static void record_ip(u64 ip, int counter)
 	samples--;
 }
 
-static void process_event(u64 ip, int counter)
+static void process_event(u64 ip, int counter, int user)
 {
 	samples++;
 
-	if (ip < min_ip || ip > max_ip) {
+	if (user) {
 		userspace_samples++;
 		return;
 	}
@@ -509,9 +509,10 @@ static void mmap_read_counter(struct mmap_data *md)
 
 		old += size;
 
-		if (event->header.misc & PERF_EVENT_MISC_OVERFLOW) {
-			if (event->header.type & PERF_SAMPLE_IP)
-				process_event(event->ip.ip, md->counter);
+		if (event->header.type == PERF_EVENT_SAMPLE) {
+			int user =
+	(event->header.misc & PERF_EVENT_MISC_CPUMODE_MASK) == PERF_EVENT_MISC_USER;
+			process_event(event->ip.ip, md->counter, user);
 		}
 	}
 
tools/perf/perf.h +4 -5
index bccb529..a49842b 100644
@@ -19,7 +19,7 @@
 #include <sys/syscall.h>
 
 #include "../../include/linux/perf_counter.h"
-#include "types.h"
+#include "util/types.h"
 
 /*
  * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
@@ -66,10 +66,9 @@ sys_perf_counter_open(struct perf_counter_attr *attr,
 #define MAX_COUNTERS			256
 #define MAX_NR_CPUS			256
 
-struct perf_file_header {
-	u64	version;
-	u64	sample_type;
-	u64	data_size;
+struct ip_callchain {
+	u64 nr;
+	u64 ips[0];
 };
 
 #endif
tools/perf/util/callchain.c new file +174 -0

174 lines not on this page · raw message

tools/perf/util/callchain.h new file +33 -0
new file mode 100644
index 0000000..fa1cd2f
@@ -0,0 +1,33 @@
+#ifndef __PERF_CALLCHAIN_H
+#define __PERF_CALLCHAIN_H
+
+#include "../perf.h"
+#include "list.h"
+#include "rbtree.h"
+
+
+struct callchain_node {
+	struct callchain_node	*parent;
+	struct list_head	brothers;
+	struct list_head 	children;
+	struct list_head 	val;
+	struct rb_node		rb_node;
+	int			val_nr;
+	int			hit;
+};
+
+struct callchain_list {
+	unsigned long		ip;
+	struct list_head	list;
+};
+
+static inline void callchain_init(struct callchain_node *node)
+{
+	INIT_LIST_HEAD(&node->brothers);
+	INIT_LIST_HEAD(&node->children);
+	INIT_LIST_HEAD(&node->val);
+}
+
+void append_chain(struct callchain_node *root, struct ip_callchain *chain);
+void sort_chain_to_rbtree(struct rb_root *rb_root, struct callchain_node *node);
+#endif
tools/perf/util/header.c new file +242 -0

242 lines not on this page · raw message

tools/perf/util/header.h new file +37 -0
new file mode 100644
index 0000000..b5ef53a
@@ -0,0 +1,37 @@
+#ifndef _PERF_HEADER_H
+#define _PERF_HEADER_H
+
+#include "../../../include/linux/perf_counter.h"
+#include <sys/types.h>
+#include "types.h"
+
+struct perf_header_attr {
+	struct perf_counter_attr attr;
+	int ids, size;
+	u64 *id;
+	off_t id_offset;
+};
+
+struct perf_header {
+	int frozen;
+	int attrs, size;
+	struct perf_header_attr **attr;
+	off_t attr_offset;
+	u64 data_offset;
+	u64 data_size;
+};
+
+struct perf_header *perf_header__read(int fd);
+void perf_header__write(struct perf_header *self, int fd);
+
+void perf_header__add_attr(struct perf_header *self,
+			   struct perf_header_attr *attr);
+
+struct perf_header_attr *
+perf_header_attr__new(struct perf_counter_attr *attr);
+void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
+
+
+struct perf_header *perf_header__new(void);
+
+#endif /* _PERF_HEADER_H */
tools/perf/util/help.c +0 -15
index 6653f7d..17a00e0 100644
@@ -126,21 +126,6 @@ static int is_executable(const char *name)
 	    !S_ISREG(st.st_mode))
 		return 0;
 
-#ifdef __MINGW32__
-	/* cannot trust the executable bit, peek into the file instead */
-	char buf[3] = { 0 };
-	int n;
-	int fd = open(name, O_RDONLY);
-	st.st_mode &= ~S_IXUSR;
-	if (fd >= 0) {
-		n = read(fd, buf, 2);
-		if (n == 2)
-			/* DOS executables start with "MZ" */
-			if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
-				st.st_mode |= S_IXUSR;
-		close(fd);
-	}
-#endif
 	return st.st_mode & S_IXUSR;
 }
 
tools/perf/util/pager.c +1 -4
index a28bcca..1915de2 100644
@@ -9,7 +9,6 @@
 
 static int spawned_pager;
 
-#ifndef __MINGW32__
 static void pager_preexec(void)
 {
 	/*
@@ -24,7 +23,6 @@ static void pager_preexec(void)
 
 	setenv("LESS", "FRSX", 0);
 }
-#endif
 
 static const char *pager_argv[] = { "sh", "-c", NULL, NULL };
 static struct child_process pager_process;
@@ -70,9 +68,8 @@ void setup_pager(void)
 	pager_argv[2] = pager;
 	pager_process.argv = pager_argv;
 	pager_process.in = -1;
-#ifndef __MINGW32__
 	pager_process.preexec_cb = pager_preexec;
-#endif
+
 	if (start_command(&pager_process))
 		return;
 
tools/perf/util/parse-events.c +105 -48

230 lines not on this page · raw message

tools/perf/util/run-command.c +2 -93

134 lines not on this page · raw message

tools/perf/util/run-command.h +0 -5
index 328289f..cc1837d 100644
@@ -79,12 +79,7 @@ struct async {
 	int (*proc)(int fd, void *data);
 	void *data;
 	int out;	/* caller reads from here and closes it */
-#ifndef __MINGW32__
 	pid_t pid;
-#else
-	HANDLE tid;
-	int fd_for_proc;
-#endif
 };
 
 int start_async(struct async *async);
tools/perf/util/strbuf.c +1 -1
index eaba093..464e7ca 100644
@@ -259,7 +259,7 @@ size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f)
 	res = fread(sb->buf + sb->len, 1, size, f);
 	if (res > 0)
 		strbuf_setlen(sb, sb->len + res);
-	else if (res < 0 && oldalloc == 0)
+	else if (oldalloc == 0)
 		strbuf_release(sb);
 	return res;
 }
tools/perf/util/string.h +1 -1
index 37b0325..3dca2f6 100644
@@ -1,7 +1,7 @@
 #ifndef _PERF_STRING_H_
 #define _PERF_STRING_H_
 
-#include "../types.h"
+#include "types.h"
 
 int hex2u64(const char *ptr, u64 *val);
 
tools/perf/util/strlist.c new file +184 -0

184 lines not on this page · raw message

tools/perf/util/strlist.h new file +32 -0
new file mode 100644
index 0000000..2fb117f
@@ -0,0 +1,32 @@
+#ifndef STRLIST_H_
+#define STRLIST_H_
+
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

tools/perf/util/symbol.c +13 -3
index 86e1437..78c2efd 100644

Lines of this file are not shown. View the raw message.

tools/perf/util/symbol.h +3 -2
index ea332e5..2c48ace 100644

Lines of this file are not shown. View the raw message.

tools/perf/util/types.h renamed from tools/perf/types.h +0 -0
similarity index 100%
rename from tools/perf/types.h
rename to tools/perf/util/types.h
tools/perf/util/util.h +0 -15
index b8cfed7..b4be607 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.