All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff
@ 2010-05-02 22:58 Arnaldo Carvalho de Melo
  2010-05-02 22:58 ` [PATCH 1/5] perf tools: Don't use code surrounded by __KERNEL__ Arnaldo Carvalho de Melo
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-05-02 22:58 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, H. Peter Anvin,
	Frédéric Weisbecker, Mike Galbraith, Paul Mackerras,
	Peter Zijlstra, Tom Zanussi

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Hi Ingo,

	Please consider pulling from:

	git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 perf

- Arnaldo

Arnaldo Carvalho de Melo (3):
  perf tools: Don't use code surrounded by __KERNEL__
  perf record: Don't exit in live mode when no tracepoints are enabled
  perf inject: Refactor read_buildid function

Tom Zanussi (2):
  perf/live: don't synthesize build ids at the end of a live mode trace
  perf: add perf-inject builtin

 tools/perf/Makefile                    |   17 +--
 tools/perf/builtin-annotate.c          |    2 +-
 tools/perf/builtin-buildid-list.c      |    2 +-
 tools/perf/builtin-diff.c              |    4 +-
 tools/perf/builtin-inject.c            |  228 ++++++++++++++++++++++++++++++++
 tools/perf/builtin-kmem.c              |    2 +-
 tools/perf/builtin-lock.c              |    2 +-
 tools/perf/builtin-record.c            |   24 ++--
 tools/perf/builtin-report.c            |    2 +-
 tools/perf/builtin-sched.c             |    2 +-
 tools/perf/builtin-timechart.c         |    2 +-
 tools/perf/builtin-top.c               |    2 +-
 tools/perf/builtin-trace.c             |    2 +-
 tools/perf/builtin.h                   |    1 +
 tools/perf/perf.c                      |    1 +
 tools/perf/util/bitmap.c               |   21 +++
 tools/perf/util/header.c               |   96 ++++----------
 tools/perf/util/header.h               |    2 -
 tools/perf/util/hweight.c              |   31 +++++
 tools/perf/util/include/asm/bitops.h   |   18 ---
 tools/perf/util/include/asm/hweight.h  |    8 +
 tools/perf/util/include/linux/bitmap.h |   38 +++++-
 tools/perf/util/include/linux/bitops.h |   20 ++--
 tools/perf/util/session.c              |    3 +-
 tools/perf/util/session.h              |    3 +-
 tools/perf/util/trace-event-read.c     |   19 +++-
 tools/perf/util/trace-event.h          |    2 +-
 27 files changed, 407 insertions(+), 147 deletions(-)
 create mode 100644 tools/perf/builtin-inject.c
 create mode 100644 tools/perf/util/bitmap.c
 create mode 100644 tools/perf/util/hweight.c
 delete mode 100644 tools/perf/util/include/asm/bitops.h
 create mode 100644 tools/perf/util/include/asm/hweight.h


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/5] perf tools: Don't use code surrounded by __KERNEL__
  2010-05-02 22:58 [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Arnaldo Carvalho de Melo
@ 2010-05-02 22:58 ` Arnaldo Carvalho de Melo
  2010-05-02 22:58 ` [PATCH 2/5] perf/live: don't synthesize build ids at the end of a live mode trace Arnaldo Carvalho de Melo
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-05-02 22:58 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo,
	Frédéric Weisbecker, Mike Galbraith, Paul Mackerras,
	Peter Zijlstra

From: Arnaldo Carvalho de Melo <acme@redhat.com>

We need to refactor code to be explicitely shared by the kernel and at
least the tools/ userspace programs, so, till we do that, copy the bare
minimum bitmap/bitops code needed by tools/perf.

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile                    |   16 +------------
 tools/perf/util/bitmap.c               |   21 +++++++++++++++++
 tools/perf/util/hweight.c              |   31 ++++++++++++++++++++++++++
 tools/perf/util/include/asm/bitops.h   |   18 ---------------
 tools/perf/util/include/asm/hweight.h  |    8 ++++++
 tools/perf/util/include/linux/bitmap.h |   38 +++++++++++++++++++++++++++++--
 tools/perf/util/include/linux/bitops.h |   20 +++++++---------
 7 files changed, 105 insertions(+), 47 deletions(-)
 create mode 100644 tools/perf/util/bitmap.c
 create mode 100644 tools/perf/util/hweight.c
 delete mode 100644 tools/perf/util/include/asm/bitops.h
 create mode 100644 tools/perf/util/include/asm/hweight.h

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 739c441..c5ac0a9 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -377,9 +377,9 @@ LIB_H += util/include/linux/rbtree.h
 LIB_H += util/include/linux/string.h
 LIB_H += util/include/linux/types.h
 LIB_H += util/include/asm/asm-offsets.h
-LIB_H += util/include/asm/bitops.h
 LIB_H += util/include/asm/bug.h
 LIB_H += util/include/asm/byteorder.h
+LIB_H += util/include/asm/hweight.h
 LIB_H += util/include/asm/swab.h
 LIB_H += util/include/asm/system.h
 LIB_H += util/include/asm/uaccess.h
@@ -435,7 +435,6 @@ LIB_OBJS += $(OUTPUT)util/path.o
 LIB_OBJS += $(OUTPUT)util/rbtree.o
 LIB_OBJS += $(OUTPUT)util/bitmap.o
 LIB_OBJS += $(OUTPUT)util/hweight.o
-LIB_OBJS += $(OUTPUT)util/find_next_bit.o
 LIB_OBJS += $(OUTPUT)util/run-command.o
 LIB_OBJS += $(OUTPUT)util/quote.o
 LIB_OBJS += $(OUTPUT)util/strbuf.o
@@ -948,19 +947,6 @@ $(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
-# some perf warning policies can't fit to lib/bitmap.c, eg: it warns about variable shadowing
-# from <string.h> that comes from kernel headers wrapping.
-KBITMAP_FLAGS=`echo $(ALL_CFLAGS) | sed s/-Wshadow// | sed s/-Wswitch-default// | sed s/-Wextra//`
-
-$(OUTPUT)util/bitmap.o: ../../lib/bitmap.c $(OUTPUT)PERF-CFLAGS
-	$(QUIET_CC)$(CC) -o $@ -c $(KBITMAP_FLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
-
-$(OUTPUT)util/hweight.o: ../../lib/hweight.c $(OUTPUT)PERF-CFLAGS
-	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
-
-$(OUTPUT)util/find_next_bit.o: ../../lib/find_next_bit.c $(OUTPUT)PERF-CFLAGS
-	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
-
 $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
diff --git a/tools/perf/util/bitmap.c b/tools/perf/util/bitmap.c
new file mode 100644
index 0000000..5e230ac
--- /dev/null
+++ b/tools/perf/util/bitmap.c
@@ -0,0 +1,21 @@
+/*
+ * From lib/bitmap.c
+ * Helper functions for bitmap.h.
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
+ */
+#include <linux/bitmap.h>
+
+int __bitmap_weight(const unsigned long *bitmap, int bits)
+{
+	int k, w = 0, lim = bits/BITS_PER_LONG;
+
+	for (k = 0; k < lim; k++)
+		w += hweight_long(bitmap[k]);
+
+	if (bits % BITS_PER_LONG)
+		w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
+
+	return w;
+}
diff --git a/tools/perf/util/hweight.c b/tools/perf/util/hweight.c
new file mode 100644
index 0000000..5c1d0d0
--- /dev/null
+++ b/tools/perf/util/hweight.c
@@ -0,0 +1,31 @@
+#include <linux/bitops.h>
+
+/**
+ * hweightN - returns the hamming weight of a N-bit word
+ * @x: the word to weigh
+ *
+ * The Hamming Weight of a number is the total number of bits set in it.
+ */
+
+unsigned int hweight32(unsigned int w)
+{
+	unsigned int res = w - ((w >> 1) & 0x55555555);
+	res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
+	res = (res + (res >> 4)) & 0x0F0F0F0F;
+	res = res + (res >> 8);
+	return (res + (res >> 16)) & 0x000000FF;
+}
+
+unsigned long hweight64(__u64 w)
+{
+#if BITS_PER_LONG == 32
+	return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
+#elif BITS_PER_LONG == 64
+	__u64 res = w - ((w >> 1) & 0x5555555555555555ul);
+	res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
+	res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
+	res = res + (res >> 8);
+	res = res + (res >> 16);
+	return (res + (res >> 32)) & 0x00000000000000FFul;
+#endif
+}
diff --git a/tools/perf/util/include/asm/bitops.h b/tools/perf/util/include/asm/bitops.h
deleted file mode 100644
index 58e9817..0000000
--- a/tools/perf/util/include/asm/bitops.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef _PERF_ASM_BITOPS_H_
-#define _PERF_ASM_BITOPS_H_
-
-#include <sys/types.h>
-#include "../../types.h"
-#include <linux/compiler.h>
-
-/* CHECKME: Not sure both always match */
-#define BITS_PER_LONG	__WORDSIZE
-
-#include "../../../../include/asm-generic/bitops/__fls.h"
-#include "../../../../include/asm-generic/bitops/fls.h"
-#include "../../../../include/asm-generic/bitops/fls64.h"
-#include "../../../../include/asm-generic/bitops/__ffs.h"
-#include "../../../../include/asm-generic/bitops/ffz.h"
-#include "../../../../include/asm-generic/bitops/hweight.h"
-
-#endif
diff --git a/tools/perf/util/include/asm/hweight.h b/tools/perf/util/include/asm/hweight.h
new file mode 100644
index 0000000..36cf26d
--- /dev/null
+++ b/tools/perf/util/include/asm/hweight.h
@@ -0,0 +1,8 @@
+#ifndef PERF_HWEIGHT_H
+#define PERF_HWEIGHT_H
+
+#include <linux/types.h>
+unsigned int hweight32(unsigned int w);
+unsigned long hweight64(__u64 w);
+
+#endif /* PERF_HWEIGHT_H */
diff --git a/tools/perf/util/include/linux/bitmap.h b/tools/perf/util/include/linux/bitmap.h
index 9450763..eda4416 100644
--- a/tools/perf/util/include/linux/bitmap.h
+++ b/tools/perf/util/include/linux/bitmap.h
@@ -1,3 +1,35 @@
-#include "../../../../include/linux/bitmap.h"
-#include "../../../../include/asm-generic/bitops/find.h"
-#include <linux/errno.h>
+#ifndef _PERF_BITOPS_H
+#define _PERF_BITOPS_H
+
+#include <string.h>
+#include <linux/bitops.h>
+
+int __bitmap_weight(const unsigned long *bitmap, int bits);
+
+#define BITMAP_LAST_WORD_MASK(nbits)					\
+(									\
+	((nbits) % BITS_PER_LONG) ?					\
+		(1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL		\
+)
+
+#define small_const_nbits(nbits) \
+	(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
+
+static inline void bitmap_zero(unsigned long *dst, int nbits)
+{
+	if (small_const_nbits(nbits))
+		*dst = 0UL;
+	else {
+		int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
+		memset(dst, 0, len);
+	}
+}
+
+static inline int bitmap_weight(const unsigned long *src, int nbits)
+{
+	if (small_const_nbits(nbits))
+		return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
+	return __bitmap_weight(src, nbits);
+}
+
+#endif /* _PERF_BITOPS_H */
diff --git a/tools/perf/util/include/linux/bitops.h b/tools/perf/util/include/linux/bitops.h
index 8d63116..bb4ac2e 100644
--- a/tools/perf/util/include/linux/bitops.h
+++ b/tools/perf/util/include/linux/bitops.h
@@ -1,13 +1,12 @@
 #ifndef _PERF_LINUX_BITOPS_H_
 #define _PERF_LINUX_BITOPS_H_
 
-#define __KERNEL__
+#include <linux/kernel.h>
+#include <asm/hweight.h>
 
-#define CONFIG_GENERIC_FIND_NEXT_BIT
-#define CONFIG_GENERIC_FIND_FIRST_BIT
-#include "../../../../include/linux/bitops.h"
-
-#undef __KERNEL__
+#define BITS_PER_LONG __WORDSIZE
+#define BITS_PER_BYTE           8
+#define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 
 static inline void set_bit(int nr, unsigned long *addr)
 {
@@ -20,10 +19,9 @@ static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
 		(((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
 }
 
-unsigned long generic_find_next_zero_le_bit(const unsigned long *addr, unsigned
-		long size, unsigned long offset);
-
-unsigned long generic_find_next_le_bit(const unsigned long *addr, unsigned
-		long size, unsigned long offset);
+static inline unsigned long hweight_long(unsigned long w)
+{
+	return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
+}
 
 #endif
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/5] perf/live: don't synthesize build ids at the end of a live mode trace
  2010-05-02 22:58 [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Arnaldo Carvalho de Melo
  2010-05-02 22:58 ` [PATCH 1/5] perf tools: Don't use code surrounded by __KERNEL__ Arnaldo Carvalho de Melo
@ 2010-05-02 22:58 ` Arnaldo Carvalho de Melo
  2010-05-02 22:59 ` [PATCH 3/5] perf: add perf-inject builtin Arnaldo Carvalho de Melo
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-05-02 22:58 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Tom Zanussi, Frédéric Weisbecker,
	Ingo Molnar, Steven Rostedt, Arnaldo Carvalho de Melo

From: Tom Zanussi <tzanussi@gmail.com>

It doesn't really make sense to record the build ids at the end of a
live mode session - live mode samples need that information during the
trace rather than at the end.

Leave event__synthesize_build_id() in place, however; we'll still be
using that to synthesize build ids in a more timely fashion in a
future patch.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1272696080-16435-2-git-send-email-tzanussi@gmail.com>
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-record.c |    7 -----
 tools/perf/util/header.c    |   61 -------------------------------------------
 tools/perf/util/header.h    |    2 -
 3 files changed, 0 insertions(+), 70 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 83b308a..1a73796 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -446,13 +446,6 @@ static void atexit_header(void)
 
 		process_buildids();
 		perf_header__write(&session->header, output, true);
-	} else {
-		int err;
-
-		err = event__synthesize_build_ids(process_synthesized_event,
-						  session);
-		if (err < 0)
-			pr_err("Couldn't synthesize build ids.\n");
 	}
 }
 
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 6227dc4..2d1d97e 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1136,67 +1136,6 @@ int event__synthesize_build_id(struct dso *pos, u16 misc,
 	return err;
 }
 
-static int __event_synthesize_build_ids(struct list_head *head, u16 misc,
-					event__handler_t process,
-					struct machine *machine,
-					struct perf_session *session)
-{
-	struct dso *pos;
-
-	dsos__for_each_with_build_id(pos, head) {
-		int err;
-		if (!pos->hit)
-			continue;
-
-		err = event__synthesize_build_id(pos, misc, process,
-						 machine, session);
-		if (err < 0)
-			return err;
-	}
-
-	return 0;
-}
-
-int event__synthesize_build_ids(event__handler_t process,
-				struct perf_session *session)
-{
-	int err = 0;
-	u16 kmisc, umisc;
-	struct machine *pos;
-	struct rb_node *nd;
-
-	if (!dsos__read_build_ids(&session->header, true))
-		return 0;
-
-	for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
-		pos = rb_entry(nd, struct machine, rb_node);
-		if (machine__is_host(pos)) {
-			kmisc = PERF_RECORD_MISC_KERNEL;
-			umisc = PERF_RECORD_MISC_USER;
-		} else {
-			kmisc = PERF_RECORD_MISC_GUEST_KERNEL;
-			umisc = PERF_RECORD_MISC_GUEST_USER;
-		}
-
-		err = __event_synthesize_build_ids(&pos->kernel_dsos, kmisc,
-						   process, pos, session);
-		if (err == 0)
-			err = __event_synthesize_build_ids(&pos->user_dsos, umisc,
-							   process, pos, session);
-		if (err)
-			break;
-	}
-
-	if (err < 0) {
-		pr_debug("failed to synthesize build ids\n");
-		return err;
-	}
-
-	dsos__cache_build_ids(&session->header);
-
-	return 0;
-}
-
 int event__process_build_id(event_t *self,
 			    struct perf_session *session)
 {
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index f39443d..402ac24 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -122,8 +122,6 @@ int event__synthesize_build_id(struct dso *pos, u16 misc,
 			       event__handler_t process,
 			       struct machine *machine,
 			       struct perf_session *session);
-int event__synthesize_build_ids(event__handler_t process,
-				struct perf_session *session);
 int event__process_build_id(event_t *self, struct perf_session *session);
 
 #endif /* __PERF_HEADER_H */
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/5] perf: add perf-inject builtin
  2010-05-02 22:58 [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Arnaldo Carvalho de Melo
  2010-05-02 22:58 ` [PATCH 1/5] perf tools: Don't use code surrounded by __KERNEL__ Arnaldo Carvalho de Melo
  2010-05-02 22:58 ` [PATCH 2/5] perf/live: don't synthesize build ids at the end of a live mode trace Arnaldo Carvalho de Melo
@ 2010-05-02 22:59 ` Arnaldo Carvalho de Melo
  2010-05-02 22:59 ` [PATCH 4/5] perf record: Don't exit in live mode when no tracepoints are enabled Arnaldo Carvalho de Melo
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-05-02 22:59 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Tom Zanussi, Ingo Molnar, Steven Rostedt,
	Frédéric Weisbecker, Arnaldo Carvalho de Melo

From: Tom Zanussi <tzanussi@gmail.com>

Currently, perf 'live mode' writes build-ids at the end of the
session, which isn't actually useful for processing live mode events.

What would be better would be to have the build-ids sent before any of
the samples that reference them, which can be done by processing the
event stream and retrieving the build-ids on the first hit.  Doing
that in perf-record itself, however, is off-limits.

This patch introduces perf-inject, which does the same job while
leaving perf-record untouched.  Normal mode perf still records the
build-ids at the end of the session as it should, but for live mode,
perf-inject can be injected in between the record and report steps
e.g.:

perf record -o - ./hackbench 10 | perf inject -v -b | perf report -v -i -

perf-inject reads a perf-record event stream and repipes it to stdout.
At any point the processing code can inject other events into the
event stream - in this case build-ids (-b option) are read and
injected as needed into the event stream.

Build-ids are just the first user of perf-inject - potentially
anything that needs userspace processing to augment the trace stream
with additional information could make use of this facility.

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
LKML-Reference: <1272696080-16435-3-git-send-email-tzanussi@gmail.com>
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile                |    1 +
 tools/perf/builtin-annotate.c      |    2 +-
 tools/perf/builtin-buildid-list.c  |    2 +-
 tools/perf/builtin-diff.c          |    4 +-
 tools/perf/builtin-inject.c        |  228 ++++++++++++++++++++++++++++++++++++
 tools/perf/builtin-kmem.c          |    2 +-
 tools/perf/builtin-lock.c          |    2 +-
 tools/perf/builtin-record.c        |    2 +-
 tools/perf/builtin-report.c        |    2 +-
 tools/perf/builtin-sched.c         |    2 +-
 tools/perf/builtin-timechart.c     |    2 +-
 tools/perf/builtin-top.c           |    2 +-
 tools/perf/builtin-trace.c         |    2 +-
 tools/perf/builtin.h               |    1 +
 tools/perf/perf.c                  |    1 +
 tools/perf/util/header.c           |   35 +++++--
 tools/perf/util/session.c          |    3 +-
 tools/perf/util/session.h          |    3 +-
 tools/perf/util/trace-event-read.c |   19 +++-
 tools/perf/util/trace-event.h      |    2 +-
 20 files changed, 293 insertions(+), 24 deletions(-)
 create mode 100644 tools/perf/builtin-inject.c

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index c5ac0a9..0ef5cfe 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -490,6 +490,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o
 BUILTIN_OBJS += $(OUTPUT)builtin-lock.o
 BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
 BUILTIN_OBJS += $(OUTPUT)builtin-test.o
+BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
 
 PERFLIBS = $(LIB_FILE)
 
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index b57dbcf..ee154b5 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -554,7 +554,7 @@ static int __cmd_annotate(void)
 	int ret;
 	struct perf_session *session;
 
-	session = perf_session__new(input_name, O_RDONLY, force);
+	session = perf_session__new(input_name, O_RDONLY, force, false);
 	if (session == NULL)
 		return -ENOMEM;
 
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 7dc3b2e..44a47e1 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -39,7 +39,7 @@ static int __cmd_buildid_list(void)
 	int err = -1;
 	struct perf_session *session;
 
-	session = perf_session__new(input_name, O_RDONLY, force);
+	session = perf_session__new(input_name, O_RDONLY, force, false);
 	if (session == NULL)
 		return -1;
 
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 207e860..4cce68f 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -156,8 +156,8 @@ static int __cmd_diff(void)
 	int ret, i;
 	struct perf_session *session[2];
 
-	session[0] = perf_session__new(input_old, O_RDONLY, force);
-	session[1] = perf_session__new(input_new, O_RDONLY, force);
+	session[0] = perf_session__new(input_old, O_RDONLY, force, false);
+	session[1] = perf_session__new(input_new, O_RDONLY, force, false);
 	if (session[0] == NULL || session[1] == NULL)
 		return -ENOMEM;
 
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
new file mode 100644
index 0000000..a5902a3
--- /dev/null
+++ b/tools/perf/builtin-inject.c
@@ -0,0 +1,228 @@
+/*
+ * builtin-inject.c
+ *
+ * Builtin inject command: Examine the live mode (stdin) event stream
+ * and repipe it to stdout while optionally injecting additional
+ * events into it.
+ */
+#include "builtin.h"
+
+#include "perf.h"
+#include "util/session.h"
+#include "util/debug.h"
+
+#include "util/parse-options.h"
+
+static char		const *input_name = "-";
+static bool		inject_build_ids;
+
+static int event__repipe(event_t *event __used,
+			 struct perf_session *session __used)
+{
+	uint32_t size;
+	void *buf = event;
+
+	size = event->header.size;
+
+	while (size) {
+		int ret = write(STDOUT_FILENO, buf, size);
+		if (ret < 0)
+			return -errno;
+
+		size -= ret;
+		buf += ret;
+	}
+
+	return 0;
+}
+
+static int event__repipe_mmap(event_t *self, struct perf_session *session)
+{
+	int err;
+
+	err = event__process_mmap(self, session);
+	event__repipe(self, session);
+
+	return err;
+}
+
+static int event__repipe_task(event_t *self, struct perf_session *session)
+{
+	int err;
+
+	err = event__process_task(self, session);
+	event__repipe(self, session);
+
+	return err;
+}
+
+static int event__repipe_tracing_data(event_t *self,
+				      struct perf_session *session)
+{
+	int err;
+
+	event__repipe(self, session);
+	err = event__process_tracing_data(self, session);
+
+	return err;
+}
+
+static int read_buildid(struct map *self, struct perf_session *session)
+{
+	const char *name = self->dso->long_name;
+	int err;
+
+	if (filename__read_build_id(self->dso->long_name, self->dso->build_id,
+				    sizeof(self->dso->build_id)) > 0) {
+		char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+
+		self->dso->has_build_id = true;
+
+		build_id__sprintf(self->dso->build_id,
+				  sizeof(self->dso->build_id),
+				  sbuild_id);
+		pr_debug("build id found for %s: %s\n", self->dso->long_name,
+			 sbuild_id);
+	}
+
+	if (self->dso->has_build_id) {
+		u16 misc = PERF_RECORD_MISC_USER;
+		struct machine *machine;
+
+		misc = self->dso->kernel ? PERF_RECORD_MISC_KERNEL : misc;
+
+		machine = perf_session__find_host_machine(session);
+		if (!machine) {
+			pr_err("Can't find machine for session\n");
+			return -1;
+		}
+
+		err = event__synthesize_build_id(self->dso, misc,
+						 event__repipe, machine,
+						 session);
+		if (err) {
+			pr_err("Can't synthesize build_id event for %s\n",
+			       name);
+			return -1;
+		}
+	} else {
+		pr_debug("no build_id found for %s\n", name);
+		return -1;
+	}
+
+	return 0;
+}
+
+static int event__inject_buildid(event_t *event, struct perf_session *session)
+{
+	struct addr_location al;
+	struct thread *thread;
+	u8 cpumode;
+	int err = 0;
+
+	cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
+
+	thread = perf_session__findnew(session, event->ip.pid);
+	if (thread == NULL) {
+		pr_err("problem processing %d event, skipping it.\n",
+		       event->header.type);
+		err = -1;
+		goto repipe;
+	}
+
+	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
+			      event->ip.pid, event->ip.ip, &al);
+
+	if (al.map != NULL) {
+		if (!al.map->dso->hit) {
+			al.map->dso->hit = 1;
+			if (map__load(al.map, NULL) >= 0)
+				read_buildid(al.map, session);
+			else
+				pr_warning("no symbols found in %s, maybe "
+					   "install a debug package?\n",
+					   al.map->dso->long_name);
+		}
+	}
+
+repipe:
+	event__repipe(event, session);
+	return err;
+}
+
+struct perf_event_ops inject_ops = {
+	.sample		= event__repipe,
+	.mmap		= event__repipe,
+	.comm		= event__repipe,
+	.fork		= event__repipe,
+	.exit		= event__repipe,
+	.lost		= event__repipe,
+	.read		= event__repipe,
+	.throttle	= event__repipe,
+	.unthrottle	= event__repipe,
+	.attr		= event__repipe,
+	.event_type 	= event__repipe,
+	.tracing_data 	= event__repipe,
+	.build_id 	= event__repipe,
+};
+
+extern volatile int session_done;
+
+static void sig_handler(int sig __attribute__((__unused__)))
+{
+	session_done = 1;
+}
+
+static int __cmd_inject(void)
+{
+	struct perf_session *session;
+	int ret = -EINVAL;
+
+	signal(SIGINT, sig_handler);
+
+	if (inject_build_ids) {
+		inject_ops.sample	= event__inject_buildid;
+		inject_ops.mmap		= event__repipe_mmap;
+		inject_ops.fork		= event__repipe_task;
+		inject_ops.tracing_data	= event__repipe_tracing_data;
+	}
+
+	session = perf_session__new(input_name, O_RDONLY, false, true);
+	if (session == NULL)
+		return -ENOMEM;
+
+	ret = perf_session__process_events(session, &inject_ops);
+
+	perf_session__delete(session);
+
+	return ret;
+}
+
+static const char * const report_usage[] = {
+	"perf inject [<options>]",
+	NULL
+};
+
+static const struct option options[] = {
+	OPT_BOOLEAN('b', "inject build-ids", &inject_build_ids,
+		    "Inject build-ids into the output stream"),
+	OPT_INCR('v', "verbose", &verbose,
+		 "be more verbose (show build ids, etc)"),
+	OPT_END()
+};
+
+int cmd_inject(int argc, const char **argv, const char *prefix __used)
+{
+	argc = parse_options(argc, argv, options, report_usage, 0);
+
+	/*
+	 * Any (unrecognized) arguments left?
+	 */
+	if (argc)
+		usage_with_options(report_usage, options);
+
+	if (symbol__init() < 0)
+		return -1;
+
+	return __cmd_inject();
+}
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index ee05dba..31f60a2 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -492,7 +492,7 @@ static void sort_result(void)
 static int __cmd_kmem(void)
 {
 	int err = -EINVAL;
-	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
+	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
 	if (session == NULL)
 		return -ENOMEM;
 
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index ce27675..6605000 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -818,7 +818,7 @@ static struct perf_event_ops eops = {
 
 static int read_events(void)
 {
-	session = perf_session__new(input_name, O_RDONLY, 0);
+	session = perf_session__new(input_name, O_RDONLY, 0, false);
 	if (!session)
 		die("Initializing perf session failed\n");
 
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 1a73796..e382d93 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -548,7 +548,7 @@ static int __cmd_record(int argc, const char **argv)
 	}
 
 	session = perf_session__new(output_name, O_WRONLY,
-				    write_mode == WRITE_FORCE);
+				    write_mode == WRITE_FORCE, false);
 	if (session == NULL) {
 		pr_err("Not enough memory for reading perf file header\n");
 		return -1;
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index f1b46eb..0152b54 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -289,7 +289,7 @@ static int __cmd_report(void)
 
 	signal(SIGINT, sig_handler);
 
-	session = perf_session__new(input_name, O_RDONLY, force);
+	session = perf_session__new(input_name, O_RDONLY, force, false);
 	if (session == NULL)
 		return -ENOMEM;
 
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 94453f1..aef6ed0 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1660,7 +1660,7 @@ static struct perf_event_ops event_ops = {
 static int read_events(void)
 {
 	int err = -EINVAL;
-	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
+	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
 	if (session == NULL)
 		return -ENOMEM;
 
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index c35aa44..5a52ed9 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -936,7 +936,7 @@ static struct perf_event_ops event_ops = {
 
 static int __cmd_timechart(void)
 {
-	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
+	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
 	int ret = -EINVAL;
 
 	if (session == NULL)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index d95281f..3de3977 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1287,7 +1287,7 @@ static int __cmd_top(void)
 	 * FIXME: perf_session__new should allow passing a O_MMAP, so that all this
 	 * mmap reading, etc is encapsulated in it. Use O_WRONLY for now.
 	 */
-	struct perf_session *session = perf_session__new(NULL, O_WRONLY, false);
+	struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false);
 	if (session == NULL)
 		return -ENOMEM;
 
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 77f556f..9c483e9 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -661,7 +661,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
 	if (!script_name)
 		setup_pager();
 
-	session = perf_session__new(input_name, O_RDONLY, 0);
+	session = perf_session__new(input_name, O_RDONLY, 0, false);
 	if (session == NULL)
 		return -ENOMEM;
 
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 34a8a9a..921245b 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -34,5 +34,6 @@ extern int cmd_kmem(int argc, const char **argv, const char *prefix);
 extern int cmd_lock(int argc, const char **argv, const char *prefix);
 extern int cmd_kvm(int argc, const char **argv, const char *prefix);
 extern int cmd_test(int argc, const char **argv, const char *prefix);
+extern int cmd_inject(int argc, const char **argv, const char *prefix);
 
 #endif
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 5ff9b5b..08e0e5d 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -309,6 +309,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "lock",	cmd_lock,	0 },
 		{ "kvm",	cmd_kvm,	0 },
 		{ "test",	cmd_test,	0 },
+		{ "inject",	cmd_inject,	0 },
 	};
 	unsigned int i;
 	static const char ext[] = STRIP_EXTENSION;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 2d1d97e..79da0e5 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -713,10 +713,18 @@ static int __event_process_build_id(struct build_id_event *bev,
 
 	dso = __dsos__findnew(head, filename);
 	if (dso != NULL) {
+		char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+
 		dso__set_build_id(dso, &bev->build_id);
-			if (filename[0] == '[')
-				dso->kernel = dso_type;
-		}
+
+		if (filename[0] == '[')
+			dso->kernel = dso_type;
+
+		build_id__sprintf(dso->build_id, sizeof(dso->build_id),
+				  sbuild_id);
+		pr_debug("build id event received for %s: %s\n",
+			 dso->long_name, sbuild_id);
+	}
 
 	err = 0;
 out:
@@ -767,7 +775,7 @@ static int perf_file_section__process(struct perf_file_section *self,
 
 	switch (feat) {
 	case HEADER_TRACE_INFO:
-		trace_report(fd);
+		trace_report(fd, false);
 		break;
 
 	case HEADER_BUILD_ID:
@@ -782,12 +790,16 @@ static int perf_file_section__process(struct perf_file_section *self,
 }
 
 static int perf_file_header__read_pipe(struct perf_pipe_file_header *self,
-				       struct perf_header *ph, int fd)
+				       struct perf_header *ph, int fd,
+				       bool repipe)
 {
 	if (do_read(fd, self, sizeof(*self)) <= 0 ||
 	    memcmp(&self->magic, __perf_magic, sizeof(self->magic)))
 		return -1;
 
+	if (repipe && do_write(STDOUT_FILENO, self, sizeof(*self)) < 0)
+		return -1;
+
 	if (self->size != sizeof(*self)) {
 		u64 size = bswap_64(self->size);
 
@@ -805,7 +817,8 @@ static int perf_header__read_pipe(struct perf_session *session, int fd)
 	struct perf_header *self = &session->header;
 	struct perf_pipe_file_header f_header;
 
-	if (perf_file_header__read_pipe(&f_header, self, fd) < 0) {
+	if (perf_file_header__read_pipe(&f_header, self, fd,
+					session->repipe) < 0) {
 		pr_debug("incompatible file format\n");
 		return -EINVAL;
 	}
@@ -1096,12 +1109,17 @@ int event__process_tracing_data(event_t *self,
 	lseek(session->fd, offset + sizeof(struct tracing_data_event),
 	      SEEK_SET);
 
-	size_read = trace_report(session->fd);
+	size_read = trace_report(session->fd, session->repipe);
 
 	padding = ALIGN(size_read, sizeof(u64)) - size_read;
 
 	if (read(session->fd, buf, padding) < 0)
 		die("reading input file");
+	if (session->repipe) {
+		int retw = write(STDOUT_FILENO, buf, padding);
+		if (retw <= 0 || retw != padding)
+			die("repiping tracing data padding");
+	}
 
 	if (size_read + padding != size)
 		die("tracing data size mismatch");
@@ -1110,7 +1128,8 @@ int event__process_tracing_data(event_t *self,
 }
 
 int event__synthesize_build_id(struct dso *pos, u16 misc,
-			       event__handler_t process, struct machine *machine,
+			       event__handler_t process,
+			       struct machine *machine,
 			       struct perf_session *session)
 {
 	event_t ev;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index a8dd73e..5d353e7 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -77,7 +77,7 @@ int perf_session__create_kernel_maps(struct perf_session *self)
 	return ret;
 }
 
-struct perf_session *perf_session__new(const char *filename, int mode, bool force)
+struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe)
 {
 	size_t len = filename ? strlen(filename) + 1 : 0;
 	struct perf_session *self = zalloc(sizeof(*self) + len);
@@ -97,6 +97,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
 	self->cwdlen = 0;
 	self->unknown_events = 0;
 	self->machines = RB_ROOT;
+	self->repipe = repipe;
 	self->ordered_samples.flush_limit = ULLONG_MAX;
 	INIT_LIST_HEAD(&self->ordered_samples.samples_head);
 
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 61ca92e..f2b2c6a 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -34,6 +34,7 @@ struct perf_session {
 	u64			sample_type;
 	int			fd;
 	bool			fd_pipe;
+	bool			repipe;
 	int			cwdlen;
 	char			*cwd;
 	struct ordered_samples	ordered_samples;
@@ -59,7 +60,7 @@ struct perf_event_ops {
 	bool	ordered_samples;
 };
 
-struct perf_session *perf_session__new(const char *filename, int mode, bool force);
+struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe);
 void perf_session__delete(struct perf_session *self);
 
 void perf_event_header__bswap(struct perf_event_header *self);
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index 44889c9..43f19c1 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -51,6 +51,7 @@ static int long_size;
 static unsigned long	page_size;
 
 static ssize_t calc_data_size;
+static bool repipe;
 
 static int do_read(int fd, void *buf, int size)
 {
@@ -62,6 +63,13 @@ static int do_read(int fd, void *buf, int size)
 		if (ret <= 0)
 			return -1;
 
+		if (repipe) {
+			int retw = write(STDOUT_FILENO, buf, ret);
+
+			if (retw <= 0 || retw != ret)
+				die("repiping input file");
+		}
+
 		size -= ret;
 		buf += ret;
 	}
@@ -116,6 +124,13 @@ static char *read_string(void)
 		if (!r)
 			die("no data");
 
+		if (repipe) {
+			int retw = write(STDOUT_FILENO, &c, 1);
+
+			if (retw <= 0 || retw != r)
+				die("repiping input file string");
+		}
+
 		buf[size++] = c;
 
 		if (!c)
@@ -454,7 +469,7 @@ struct record *trace_read_data(int cpu)
 	return data;
 }
 
-ssize_t trace_report(int fd)
+ssize_t trace_report(int fd, bool __repipe)
 {
 	char buf[BUFSIZ];
 	char test[] = { 23, 8, 68 };
@@ -465,6 +480,7 @@ ssize_t trace_report(int fd)
 	ssize_t size;
 
 	calc_data_size = 1;
+	repipe = __repipe;
 
 	input_fd = fd;
 
@@ -499,6 +515,7 @@ ssize_t trace_report(int fd)
 
 	size = calc_data_size - 1;
 	calc_data_size = 0;
+	repipe = false;
 
 	if (show_funcs) {
 		print_funcs();
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 1f45d46..ebfee80 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -163,7 +163,7 @@ struct record *trace_read_data(int cpu);
 
 void parse_set_info(int nr_cpus, int long_sz);
 
-ssize_t trace_report(int fd);
+ssize_t trace_report(int fd, bool repipe);
 
 void *malloc_or_die(unsigned int size);
 
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/5] perf record: Don't exit in live mode when no tracepoints are enabled
  2010-05-02 22:58 [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Arnaldo Carvalho de Melo
                   ` (2 preceding siblings ...)
  2010-05-02 22:59 ` [PATCH 3/5] perf: add perf-inject builtin Arnaldo Carvalho de Melo
@ 2010-05-02 22:59 ` Arnaldo Carvalho de Melo
  2010-05-03  5:51   ` Tom Zanussi
  2010-05-02 22:59 ` [PATCH 5/5] perf inject: Refactor read_buildid function Arnaldo Carvalho de Melo
  2010-05-03  6:24 ` [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Ingo Molnar
  5 siblings, 1 reply; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-05-02 22:59 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo,
	Frédéric Weisbecker, Mike Galbraith, Paul Mackerras,
	Peter Zijlstra, Tom Zanussi

From: Arnaldo Carvalho de Melo <acme@redhat.com>

With this I was able to actually test Tom Zanussi's two previous patches
in my usual perf testing ways, i.e. without any tracepoints activated.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-record.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e382d93..ac989e9 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -666,12 +666,15 @@ static int __cmd_record(int argc, const char **argv)
 						     nr_counters,
 						     process_synthesized_event,
 						     session);
-		if (err <= 0) {
-			pr_err("Couldn't record tracing data.\n");
-			return err;
-		}
-
-		advance_output(err);
+		/*
+		 * FIXME err <= 0 here actually means that there were no tracepoints
+		 * so its not really an error, just that we don't need to synthesize
+		 * anything.
+		 * We really have to return this more properly and also propagate
+		 * errors that now are calling die()
+		 */
+		if (err > 0)
+			advance_output(err);
 	}
 
 	machine = perf_session__find_host_machine(session);
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 5/5] perf inject: Refactor read_buildid function
  2010-05-02 22:58 [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Arnaldo Carvalho de Melo
                   ` (3 preceding siblings ...)
  2010-05-02 22:59 ` [PATCH 4/5] perf record: Don't exit in live mode when no tracepoints are enabled Arnaldo Carvalho de Melo
@ 2010-05-02 22:59 ` Arnaldo Carvalho de Melo
  2010-05-03  6:24 ` [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Ingo Molnar
  5 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-05-02 22:59 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo,
	Frédéric Weisbecker, Mike Galbraith, Paul Mackerras,
	Peter Zijlstra, Tom Zanussi

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Into two functions, one that actually reads the build_id for the dso if
it wasn't already read, and another taht will inject the event if the
build_id is available.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-inject.c |   76 +++++++++++++++++++++---------------------
 1 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index a5902a3..59e981a 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -67,46 +67,44 @@ static int event__repipe_tracing_data(event_t *self,
 	return err;
 }
 
-static int read_buildid(struct map *self, struct perf_session *session)
+static int dso__read_build_id(struct dso *self)
 {
-	const char *name = self->dso->long_name;
-	int err;
+	if (self->has_build_id)
+		return 0;
 
-	if (filename__read_build_id(self->dso->long_name, self->dso->build_id,
-				    sizeof(self->dso->build_id)) > 0) {
-		char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+	if (filename__read_build_id(self->long_name, self->build_id,
+				    sizeof(self->build_id)) > 0) {
+		self->has_build_id = true;
+		return 0;
+	}
 
-		self->dso->has_build_id = true;
+	return -1;
+}
 
-		build_id__sprintf(self->dso->build_id,
-				  sizeof(self->dso->build_id),
-				  sbuild_id);
-		pr_debug("build id found for %s: %s\n", self->dso->long_name,
-			 sbuild_id);
-	}
+static int dso__inject_build_id(struct dso *self, struct perf_session *session)
+{
+	u16 misc = PERF_RECORD_MISC_USER;
+	struct machine *machine;
+	int err;
 
-	if (self->dso->has_build_id) {
-		u16 misc = PERF_RECORD_MISC_USER;
-		struct machine *machine;
+	if (dso__read_build_id(self) < 0) {
+		pr_debug("no build_id found for %s\n", self->long_name);
+		return -1;
+	}
 
-		misc = self->dso->kernel ? PERF_RECORD_MISC_KERNEL : misc;
+	machine = perf_session__find_host_machine(session);
+	if (machine == NULL) {
+		pr_err("Can't find machine for session\n");
+		return -1;
+	}
 
-		machine = perf_session__find_host_machine(session);
-		if (!machine) {
-			pr_err("Can't find machine for session\n");
-			return -1;
-		}
+	if (self->kernel)
+		misc = PERF_RECORD_MISC_KERNEL;
 
-		err = event__synthesize_build_id(self->dso, misc,
-						 event__repipe, machine,
-						 session);
-		if (err) {
-			pr_err("Can't synthesize build_id event for %s\n",
-			       name);
-			return -1;
-		}
-	} else {
-		pr_debug("no build_id found for %s\n", name);
+	err = event__synthesize_build_id(self, misc, event__repipe,
+					 machine, session);
+	if (err) {
+		pr_err("Can't synthesize build_id event for %s\n", self->long_name);
 		return -1;
 	}
 
@@ -118,7 +116,6 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
 	struct addr_location al;
 	struct thread *thread;
 	u8 cpumode;
-	int err = 0;
 
 	cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
 
@@ -126,7 +123,6 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
 	if (thread == NULL) {
 		pr_err("problem processing %d event, skipping it.\n",
 		       event->header.type);
-		err = -1;
 		goto repipe;
 	}
 
@@ -136,9 +132,13 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
 	if (al.map != NULL) {
 		if (!al.map->dso->hit) {
 			al.map->dso->hit = 1;
-			if (map__load(al.map, NULL) >= 0)
-				read_buildid(al.map, session);
-			else
+			if (map__load(al.map, NULL) >= 0) {
+				dso__inject_build_id(al.map->dso, session);
+				/*
+				 * If this fails, too bad, let the other side
+				 * account this as unresolved.
+				 */
+			} else
 				pr_warning("no symbols found in %s, maybe "
 					   "install a debug package?\n",
 					   al.map->dso->long_name);
@@ -147,7 +147,7 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
 
 repipe:
 	event__repipe(event, session);
-	return err;
+	return 0;
 }
 
 struct perf_event_ops inject_ops = {
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/5] perf record: Don't exit in live mode when no tracepoints are enabled
  2010-05-02 22:59 ` [PATCH 4/5] perf record: Don't exit in live mode when no tracepoints are enabled Arnaldo Carvalho de Melo
@ 2010-05-03  5:51   ` Tom Zanussi
  2010-05-03 13:23     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 16+ messages in thread
From: Tom Zanussi @ 2010-05-03  5:51 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, linux-kernel, Arnaldo Carvalho de Melo,
	Frédéric Weisbecker, Mike Galbraith, Paul Mackerras,
	Peter Zijlstra

Hi,

On Sun, 2010-05-02 at 19:59 -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> With this I was able to actually test Tom Zanussi's two previous patches
> in my usual perf testing ways, i.e. without any tracepoints activated.
> 
> Cc: Frédéric Weisbecker <fweisbec@gmail.com>
> Cc: Mike Galbraith <efault@gmx.de>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Tom Zanussi <tzanussi@gmail.com>
> LKML-Reference: <new-submission>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/builtin-record.c |   15 +++++++++------
>  1 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index e382d93..ac989e9 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -666,12 +666,15 @@ static int __cmd_record(int argc, const char **argv)
>  						     nr_counters,
>  						     process_synthesized_event,
>  						     session);
> -		if (err <= 0) {
> -			pr_err("Couldn't record tracing data.\n");
> -			return err;
> -		}
> -
> -		advance_output(err);
> +		/*
> +		 * FIXME err <= 0 here actually means that there were no tracepoints
> +		 * so its not really an error, just that we don't need to synthesize
> +		 * anything.
> +		 * We really have to return this more properly and also propagate
> +		 * errors that now are calling die()
> +		 */
> +		if (err > 0)
> +			advance_output(err);
>  	}
>  
>  	machine = perf_session__find_host_machine(session);

Thanks for taking these patches and fixing them up!

BTW, I posted a patch a couple days ago that also fixes this problem, in
response to a bug report for a non-live-mode problem seen when using
SAMPLE_RAW with no tracepoints:

http://lkml.org/lkml/2010/5/1/2

Here it is again, fixed up to apply to your tree...

Tom

From: Tom Zanussi <tzanussi@gmail.com>
Date: Mon, 3 May 2010 00:14:48 -0500
Subject: [PATCH] perf: record TRACE_INFO only if using tracepoints and
SAMPLE_RAW

The current perf code implicitly assumes SAMPLE_RAW means tracepoints
are being used, but doesn't check for that.  It happily records the
TRACE_INFO even if SAMPLE_RAW is used without tracepoints, but when
the perf data is read it won't go any further when it finds TRACE_INFO
but no tracepoints, and displays misleading errors.

This adds a check for both in perf-record, and won't record TRACE_INFO
unless both are true.  This at least allows perf report -D to dump raw
events, and avoids triggering a misleading error condition in perf
trace.  It doesn't actually enable the non-tracepoint raw events to be
displayed in perf trace, since perf trace currently only deals with
tracepoint events.

Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
---
 tools/perf/builtin-record.c        |   35
+++++++++++++++++++++--------------
 tools/perf/util/header.c           |    1 -
 tools/perf/util/parse-events.h     |    1 +
 tools/perf/util/trace-event-info.c |    5 +++++
 4 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index ac989e9..0ff67d1 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -560,11 +560,12 @@ static int __cmd_record(int argc, const char **argv)
 			return err;
 	}
 
-	if (raw_samples) {
+	if (raw_samples && have_tracepoints(attrs, nr_counters)) {
 		perf_header__set_feat(&session->header, HEADER_TRACE_INFO);
 	} else {
 		for (i = 0; i < nr_counters; i++) {
-			if (attrs[i].sample_type & PERF_SAMPLE_RAW) {
+			if (attrs[i].sample_type & PERF_SAMPLE_RAW &&
+				attrs[i].type == PERF_TYPE_TRACEPOINT) {
 				perf_header__set_feat(&session->header, HEADER_TRACE_INFO);
 				break;
 			}
@@ -662,19 +663,25 @@ static int __cmd_record(int argc, const char **argv)
 			return err;
 		}
 
-		err = event__synthesize_tracing_data(output, attrs,
-						     nr_counters,
-						     process_synthesized_event,
-						     session);
-		/*
-		 * FIXME err <= 0 here actually means that there were no tracepoints
-		 * so its not really an error, just that we don't need to synthesize
-		 * anything.
-		 * We really have to return this more properly and also propagate
-		 * errors that now are calling die()
-		 */
-		if (err > 0)
+		if (have_tracepoints(attrs, nr_counters)) {
+			/*
+			 * FIXME err <= 0 here actually means that
+			 * there were no tracepoints so its not really
+			 * an error, just that we don't need to
+			 * synthesize anything.  We really have to
+			 * return this more properly and also
+			 * propagate errors that now are calling die()
+			 */
+			err = event__synthesize_tracing_data(output, attrs,
+							     nr_counters,
+							     process_synthesized_event,
+							     session);
+			if (err <= 0) {
+				pr_err("Couldn't record tracing data.\n");
+				return err;
+			}
 			advance_output(err);
+		}
 	}
 
 	machine = perf_session__find_host_machine(session);
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 79da0e5..2b9f898 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -436,7 +436,6 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
 		trace_sec->size = lseek(fd, 0, SEEK_CUR) - trace_sec->offset;
 	}
 
-
 	if (perf_header__has_feat(self, HEADER_BUILD_ID)) {
 		struct perf_file_section *buildid_sec;
 
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index b8c1f64..fc4ab3f 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -13,6 +13,7 @@ struct tracepoint_path {
 };
 
 extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
+extern bool have_tracepoints(struct perf_event_attr *pattrs, int nb_events);
 
 extern int			nr_counters;
 
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index 30cd9b5..0a1fb9d 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -487,6 +487,11 @@ get_tracepoints_path(struct perf_event_attr *pattrs, int nb_events)
 	return nr_tracepoints > 0 ? path.next : NULL;
 }
 
+bool have_tracepoints(struct perf_event_attr *pattrs, int nb_events)
+{
+	return get_tracepoints_path(pattrs, nb_events) ? true : false;
+}
+
 int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events)
 {
 	char buf[BUFSIZ];
-- 
1.6.6.1







^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff
  2010-05-02 22:58 [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Arnaldo Carvalho de Melo
                   ` (4 preceding siblings ...)
  2010-05-02 22:59 ` [PATCH 5/5] perf inject: Refactor read_buildid function Arnaldo Carvalho de Melo
@ 2010-05-03  6:24 ` Ingo Molnar
  2010-05-03  6:29   ` H. Peter Anvin
  5 siblings, 1 reply; 16+ messages in thread
From: Ingo Molnar @ 2010-05-03  6:24 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, Arnaldo Carvalho de Melo, H. Peter Anvin,
	Fr??d??ric Weisbecker, Mike Galbraith, Paul Mackerras,
	Peter Zijlstra, Tom Zanussi


* Arnaldo Carvalho de Melo <acme@infradead.org> wrote:

> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> Hi Ingo,
> 
> 	Please consider pulling from:
> 
> 	git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 perf
> 
> - Arnaldo
> 
> Arnaldo Carvalho de Melo (3):
>   perf tools: Don't use code surrounded by __KERNEL__
>   perf record: Don't exit in live mode when no tracepoints are enabled
>   perf inject: Refactor read_buildid function
> 
> Tom Zanussi (2):
>   perf/live: don't synthesize build ids at the end of a live mode trace
>   perf: add perf-inject builtin
> 
>  tools/perf/Makefile                    |   17 +--
>  tools/perf/builtin-annotate.c          |    2 +-
>  tools/perf/builtin-buildid-list.c      |    2 +-
>  tools/perf/builtin-diff.c              |    4 +-
>  tools/perf/builtin-inject.c            |  228 ++++++++++++++++++++++++++++++++
>  tools/perf/builtin-kmem.c              |    2 +-
>  tools/perf/builtin-lock.c              |    2 +-
>  tools/perf/builtin-record.c            |   24 ++--
>  tools/perf/builtin-report.c            |    2 +-
>  tools/perf/builtin-sched.c             |    2 +-
>  tools/perf/builtin-timechart.c         |    2 +-
>  tools/perf/builtin-top.c               |    2 +-
>  tools/perf/builtin-trace.c             |    2 +-
>  tools/perf/builtin.h                   |    1 +
>  tools/perf/perf.c                      |    1 +
>  tools/perf/util/bitmap.c               |   21 +++
>  tools/perf/util/header.c               |   96 ++++----------
>  tools/perf/util/header.h               |    2 -
>  tools/perf/util/hweight.c              |   31 +++++
>  tools/perf/util/include/asm/bitops.h   |   18 ---
>  tools/perf/util/include/asm/hweight.h  |    8 +
>  tools/perf/util/include/linux/bitmap.h |   38 +++++-
>  tools/perf/util/include/linux/bitops.h |   20 ++--
>  tools/perf/util/session.c              |    3 +-
>  tools/perf/util/session.h              |    3 +-
>  tools/perf/util/trace-event-read.c     |   19 +++-
>  tools/perf/util/trace-event.h          |    2 +-
>  27 files changed, 407 insertions(+), 147 deletions(-)
>  create mode 100644 tools/perf/builtin-inject.c
>  create mode 100644 tools/perf/util/bitmap.c
>  create mode 100644 tools/perf/util/hweight.c
>  delete mode 100644 tools/perf/util/include/asm/bitops.h
>  create mode 100644 tools/perf/util/include/asm/hweight.h

Pulled, thanks a lot!

	Ingo

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff
  2010-05-03  6:24 ` [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Ingo Molnar
@ 2010-05-03  6:29   ` H. Peter Anvin
  2010-05-03  6:54     ` Ingo Molnar
  0 siblings, 1 reply; 16+ messages in thread
From: H. Peter Anvin @ 2010-05-03  6:29 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Arnaldo Carvalho de Melo,
	Fr??d??ric Weisbecker, Mike Galbraith, Paul Mackerras,
	Peter Zijlstra, Tom Zanussi

On 05/02/2010 11:24 PM, Ingo Molnar wrote:
> 
> Pulled, thanks a lot!
> 

With this, core/hweight should work properly, I hope.

	-hpa


-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff
  2010-05-03  6:29   ` H. Peter Anvin
@ 2010-05-03  6:54     ` Ingo Molnar
  2010-05-03  7:37       ` Ingo Molnar
  0 siblings, 1 reply; 16+ messages in thread
From: Ingo Molnar @ 2010-05-03  6:54 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Arnaldo Carvalho de Melo,
	Fr??d??ric Weisbecker, Mike Galbraith, Paul Mackerras,
	Peter Zijlstra, Tom Zanussi


* H. Peter Anvin <hpa@zytor.com> wrote:

> On 05/02/2010 11:24 PM, Ingo Molnar wrote:
> > 
> > Pulled, thanks a lot!
> > 
> 
> With this, core/hweight should work properly, I hope.

Ok, i merged that too - will let you know about any trouble.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff
  2010-05-03  6:54     ` Ingo Molnar
@ 2010-05-03  7:37       ` Ingo Molnar
  2010-05-03  8:13         ` Borislav Petkov
  2010-05-03 13:07         ` Borislav Petkov
  0 siblings, 2 replies; 16+ messages in thread
From: Ingo Molnar @ 2010-05-03  7:37 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Arnaldo Carvalho de Melo,
	Fr??d??ric Weisbecker, Mike Galbraith, Paul Mackerras,
	Peter Zijlstra, Tom Zanussi


* Ingo Molnar <mingo@elte.hu> wrote:

> 
> * H. Peter Anvin <hpa@zytor.com> wrote:
> 
> > On 05/02/2010 11:24 PM, Ingo Molnar wrote:
> > > 
> > > Pulled, thanks a lot!
> > > 
> > 
> > With this, core/hweight should work properly, I hope.
> 
> Ok, i merged that too - will let you know about any trouble.

It broke half of the non-x86 architectures. For example on Sparc defconfig:

In file included from /home/mingo/tip/include/asm-generic/bitops/hweight.h:4,
                 from /home/mingo/tip/arch/sparc/include/asm/bitops_32.h:103,
                 from /home/mingo/tip/arch/sparc/include/asm/bitops.h:6,
                 from /home/mingo/tip/include/linux/bitops.h:17,
                 from /home/mingo/tip/include/linux/kernel.h:15,
                 from /home/mingo/tip/include/linux/sched.h:54,
                 from /home/mingo/tip/arch/sparc/kernel/asm-offsets.c:13:
/home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight32':
/home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:8: error: implicit declaration of function '__sw_hweight32'
/home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight16':
/home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:13: error: implicit declaration of function '__sw_hweight16'
/home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight8':
/home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:18: error: implicit declaration of function '__sw_hweight8'
/home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight64':
/home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:23: error: implicit declaration of function '__sw_hweight64'

(the failure on other architectures looks similar)

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff
  2010-05-03  7:37       ` Ingo Molnar
@ 2010-05-03  8:13         ` Borislav Petkov
  2010-05-03 13:06           ` Ingo Molnar
  2010-05-03 13:07         ` Borislav Petkov
  1 sibling, 1 reply; 16+ messages in thread
From: Borislav Petkov @ 2010-05-03  8:13 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: H. Peter Anvin, Arnaldo Carvalho de Melo, linux-kernel,
	Arnaldo Carvalho de Melo, Fr??d??ric Weisbecker, Mike Galbraith,
	Paul Mackerras, Peter Zijlstra, Tom Zanussi

From: Ingo Molnar <mingo@elte.hu>
Date: Mon, May 03, 2010 at 09:37:49AM +0200

> It broke half of the non-x86 architectures. For example on Sparc defconfig:
> 
> In file included from /home/mingo/tip/include/asm-generic/bitops/hweight.h:4,
>                  from /home/mingo/tip/arch/sparc/include/asm/bitops_32.h:103,
>                  from /home/mingo/tip/arch/sparc/include/asm/bitops.h:6,
>                  from /home/mingo/tip/include/linux/bitops.h:17,
>                  from /home/mingo/tip/include/linux/kernel.h:15,
>                  from /home/mingo/tip/include/linux/sched.h:54,
>                  from /home/mingo/tip/arch/sparc/kernel/asm-offsets.c:13:
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight32':
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:8: error: implicit declaration of function '__sw_hweight32'
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight16':
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:13: error: implicit declaration of function '__sw_hweight16'
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight8':
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:18: error: implicit declaration of function '__sw_hweight8'
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight64':
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:23: error: implicit declaration of function '__sw_hweight64'
> 
> (the failure on other architectures looks similar)

Looks like we're missing the __sw_hweightXX prototype definitions in
that include maze. Ingo, which -tip branch is that and can you put it
somewhere for me to test?

Thanks.

-- 
Regards/Gruss,
    Boris.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff
  2010-05-03  8:13         ` Borislav Petkov
@ 2010-05-03 13:06           ` Ingo Molnar
  0 siblings, 0 replies; 16+ messages in thread
From: Ingo Molnar @ 2010-05-03 13:06 UTC (permalink / raw)
  To: Borislav Petkov, H. Peter Anvin, Arnaldo Carvalho de Melo,
	linux-kernel, Arnaldo Carvalho de Melo, Fr??d??ric Weisbecker,
	Mike Galbraith, Paul Mackerras, Peter Zijlstra, Tom Zanussi


* Borislav Petkov <bp@alien8.de> wrote:

> From: Ingo Molnar <mingo@elte.hu>
> Date: Mon, May 03, 2010 at 09:37:49AM +0200
> 
> > It broke half of the non-x86 architectures. For example on Sparc defconfig:
> > 
> > In file included from /home/mingo/tip/include/asm-generic/bitops/hweight.h:4,
> >                  from /home/mingo/tip/arch/sparc/include/asm/bitops_32.h:103,
> >                  from /home/mingo/tip/arch/sparc/include/asm/bitops.h:6,
> >                  from /home/mingo/tip/include/linux/bitops.h:17,
> >                  from /home/mingo/tip/include/linux/kernel.h:15,
> >                  from /home/mingo/tip/include/linux/sched.h:54,
> >                  from /home/mingo/tip/arch/sparc/kernel/asm-offsets.c:13:
> > /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight32':
> > /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:8: error: implicit declaration of function '__sw_hweight32'
> > /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight16':
> > /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:13: error: implicit declaration of function '__sw_hweight16'
> > /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight8':
> > /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:18: error: implicit declaration of function '__sw_hweight8'
> > /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight64':
> > /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:23: error: implicit declaration of function '__sw_hweight64'
> > 
> > (the failure on other architectures looks similar)
> 
> Looks like we're missing the __sw_hweightXX prototype definitions in
> that include maze. Ingo, which -tip branch is that and can you put it
> somewhere for me to test?

it's tip:core/hweight. You should be able to do 'git checkout 
tip/core/hweight' if you have -tip as a remote repository.

It's not merged into tip:master at the moment, but you can do it yourself via:

	git merge tip/core/hweight

to get the tree i tested.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff
  2010-05-03  7:37       ` Ingo Molnar
  2010-05-03  8:13         ` Borislav Petkov
@ 2010-05-03 13:07         ` Borislav Petkov
  2010-05-04 17:27           ` [tip:core/hweight] arch, hweight: Fix compilation errors tip-bot for Borislav Petkov
  1 sibling, 1 reply; 16+ messages in thread
From: Borislav Petkov @ 2010-05-03 13:07 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: H. Peter Anvin, Arnaldo Carvalho de Melo, linux-kernel,
	Arnaldo Carvalho de Melo, Fr??d??ric Weisbecker, Mike Galbraith,
	Paul Mackerras, Peter Zijlstra, Tom Zanussi

From: Ingo Molnar <mingo@elte.hu>
Date: Mon, May 03, 2010 at 09:37:49AM +0200

> It broke half of the non-x86 architectures. For example on Sparc defconfig:
> 
> In file included from /home/mingo/tip/include/asm-generic/bitops/hweight.h:4,
>                  from /home/mingo/tip/arch/sparc/include/asm/bitops_32.h:103,
>                  from /home/mingo/tip/arch/sparc/include/asm/bitops.h:6,
>                  from /home/mingo/tip/include/linux/bitops.h:17,
>                  from /home/mingo/tip/include/linux/kernel.h:15,
>                  from /home/mingo/tip/include/linux/sched.h:54,
>                  from /home/mingo/tip/arch/sparc/kernel/asm-offsets.c:13:
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight32':
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:8: error: implicit declaration of function '__sw_hweight32'
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight16':
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:13: error: implicit declaration of function '__sw_hweight16'
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight8':
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:18: error: implicit declaration of function '__sw_hweight8'
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h: In function '__arch_hweight64':
> /home/mingo/tip/include/asm-generic/bitops/arch_hweight.h:23: error: implicit declaration of function '__sw_hweight64'
> 
> (the failure on other architectures looks similar)

Right, so I could reproduce that with the crosstool on kernel.org when
compiling core/hweight. The patch below should fix those errors. x86 32-
and 64-bit are also fine with the patch.

--
From: Borislav Petkov <borislav.petkov@amd.com>
Date: Mon, 3 May 2010 14:57:11 +0200
Subject: [PATCH] arch, hweight: Fix compilation errors

Fix function prototypes visibility issues when cross-compiling. Tested
with crosstool (ftp://ftp.kernel.org/pub/tools/crosstool/) with alpha,
ia64 and sparc targets.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 include/asm-generic/bitops/arch_hweight.h |    8 ++++----
 include/linux/bitops.h                    |    5 +++++
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/asm-generic/bitops/arch_hweight.h b/include/asm-generic/bitops/arch_hweight.h
index 9a81c1e..6a211f4 100644
--- a/include/asm-generic/bitops/arch_hweight.h
+++ b/include/asm-generic/bitops/arch_hweight.h
@@ -3,22 +3,22 @@
 
 #include <asm/types.h>
 
-inline unsigned int __arch_hweight32(unsigned int w)
+static inline unsigned int __arch_hweight32(unsigned int w)
 {
 	return __sw_hweight32(w);
 }
 
-inline unsigned int __arch_hweight16(unsigned int w)
+static inline unsigned int __arch_hweight16(unsigned int w)
 {
 	return __sw_hweight16(w);
 }
 
-inline unsigned int __arch_hweight8(unsigned int w)
+static inline unsigned int __arch_hweight8(unsigned int w)
 {
 	return __sw_hweight8(w);
 }
 
-inline unsigned long __arch_hweight64(__u64 w)
+static inline unsigned long __arch_hweight64(__u64 w)
 {
 	return __sw_hweight64(w);
 }
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index c55d5bc..26caa60 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -10,6 +10,11 @@
 #define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 #endif
 
+extern unsigned int __sw_hweight8(unsigned int w);
+extern unsigned int __sw_hweight16(unsigned int w);
+extern unsigned int __sw_hweight32(unsigned int w);
+extern unsigned long __sw_hweight64(__u64 w);
+
 /*
  * Include this here because some architectures need generic_ffs/fls in
  * scope
-- 
1.6.4.4


-- 
Regards/Gruss,
Boris.

--
Advanced Micro Devices, Inc.
Operating Systems Research Center

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/5] perf record: Don't exit in live mode when no tracepoints are enabled
  2010-05-03  5:51   ` Tom Zanussi
@ 2010-05-03 13:23     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-05-03 13:23 UTC (permalink / raw)
  To: Tom Zanussi
  Cc: Ingo Molnar, linux-kernel, Frédéric Weisbecker,
	Mike Galbraith, Paul Mackerras, Peter Zijlstra

Em Mon, May 03, 2010 at 12:51:01AM -0500, Tom Zanussi escreveu:
> Hi,
> 
> 
> Thanks for taking these patches and fixing them up!
> 
> BTW, I posted a patch a couple days ago that also fixes this problem, in
> response to a bug report for a non-live-mode problem seen when using
> SAMPLE_RAW with no tracepoints:
> 
> http://lkml.org/lkml/2010/5/1/2
> 
> Here it is again, fixed up to apply to your tree...

Thanks, applying it.

- Arnaldo

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [tip:core/hweight] arch, hweight: Fix compilation errors
  2010-05-03 13:07         ` Borislav Petkov
@ 2010-05-04 17:27           ` tip-bot for Borislav Petkov
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot for Borislav Petkov @ 2010-05-04 17:27 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, borislav.petkov

Commit-ID:  4677d4a53e0d565742277e8913e91c821453e63e
Gitweb:     http://git.kernel.org/tip/4677d4a53e0d565742277e8913e91c821453e63e
Author:     Borislav Petkov <borislav.petkov@amd.com>
AuthorDate: Mon, 3 May 2010 14:57:11 +0200
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Tue, 4 May 2010 10:25:27 -0700

arch, hweight: Fix compilation errors

Fix function prototype visibility issues when compiling for non-x86
architectures. Tested with crosstool
(ftp://ftp.kernel.org/pub/tools/crosstool/) with alpha, ia64 and sparc
targets.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
LKML-Reference: <20100503130736.GD26107@aftab>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 include/asm-generic/bitops/arch_hweight.h |    8 ++++----
 include/linux/bitops.h                    |    5 +++++
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/asm-generic/bitops/arch_hweight.h b/include/asm-generic/bitops/arch_hweight.h
index 9a81c1e..6a211f4 100644
--- a/include/asm-generic/bitops/arch_hweight.h
+++ b/include/asm-generic/bitops/arch_hweight.h
@@ -3,22 +3,22 @@
 
 #include <asm/types.h>
 
-inline unsigned int __arch_hweight32(unsigned int w)
+static inline unsigned int __arch_hweight32(unsigned int w)
 {
 	return __sw_hweight32(w);
 }
 
-inline unsigned int __arch_hweight16(unsigned int w)
+static inline unsigned int __arch_hweight16(unsigned int w)
 {
 	return __sw_hweight16(w);
 }
 
-inline unsigned int __arch_hweight8(unsigned int w)
+static inline unsigned int __arch_hweight8(unsigned int w)
 {
 	return __sw_hweight8(w);
 }
 
-inline unsigned long __arch_hweight64(__u64 w)
+static inline unsigned long __arch_hweight64(__u64 w)
 {
 	return __sw_hweight64(w);
 }
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index c55d5bc..26caa60 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -10,6 +10,11 @@
 #define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 #endif
 
+extern unsigned int __sw_hweight8(unsigned int w);
+extern unsigned int __sw_hweight16(unsigned int w);
+extern unsigned int __sw_hweight32(unsigned int w);
+extern unsigned long __sw_hweight64(__u64 w);
+
 /*
  * Include this here because some architectures need generic_ffs/fls in
  * scope

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-05-04 17:27 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-02 22:58 [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Arnaldo Carvalho de Melo
2010-05-02 22:58 ` [PATCH 1/5] perf tools: Don't use code surrounded by __KERNEL__ Arnaldo Carvalho de Melo
2010-05-02 22:58 ` [PATCH 2/5] perf/live: don't synthesize build ids at the end of a live mode trace Arnaldo Carvalho de Melo
2010-05-02 22:59 ` [PATCH 3/5] perf: add perf-inject builtin Arnaldo Carvalho de Melo
2010-05-02 22:59 ` [PATCH 4/5] perf record: Don't exit in live mode when no tracepoints are enabled Arnaldo Carvalho de Melo
2010-05-03  5:51   ` Tom Zanussi
2010-05-03 13:23     ` Arnaldo Carvalho de Melo
2010-05-02 22:59 ` [PATCH 5/5] perf inject: Refactor read_buildid function Arnaldo Carvalho de Melo
2010-05-03  6:24 ` [PATCH 0/5] perf inject + say no to __KERNEL__ only stuff Ingo Molnar
2010-05-03  6:29   ` H. Peter Anvin
2010-05-03  6:54     ` Ingo Molnar
2010-05-03  7:37       ` Ingo Molnar
2010-05-03  8:13         ` Borislav Petkov
2010-05-03 13:06           ` Ingo Molnar
2010-05-03 13:07         ` Borislav Petkov
2010-05-04 17:27           ` [tip:core/hweight] arch, hweight: Fix compilation errors tip-bot for Borislav Petkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.