Skip to contentSkip to conversation

RAS daemon prototype, v1

RFC PATCH In review Borislav Petkov 2 participants 24 messages Jul 1, 2010 – Jul 7, 2010

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

cover RAS daemon prototype, v1

From: Borislav Petkov <[email protected]>

(resubmitting since lkml wasn't on CC list)

Hi guys,

here's the first rough version of all the jerky code that attempts to implement a RAS daemon listening for MCEs using perf. This is a preview code only, I still need to figure out how to do the sample parsing the easiest and flesh out the daemon functionality a bit more. Also, I wanted to reuse as much code as possible therefore a lot had to be reengineered with the perf tool and all its library-like compilation units.

With this, you can do

make perf

or

make ras

and build the respective tool.

Even though I tried to split the patchset for easier review, please bear in mind that there are some fat guys there (241K is the biggest one). However, they don't do anything special except moving code around. As such, they might not appear on lkml due to vger size constraints so I've upped the whole patchset also at

git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git perf-v1

The patchset is based on tip/perf/core from last week. Here are some more details to some of the patches individually:

2: enables the mce tracepoint unconditionally. I had a problem with perf_event_attr.sample_period which is checked in perf_swevent_add(). Currently, I'm setting it to ULLONG_MAX but this is icky. I'd much rather have the check do something like

	if (event->type != PERF_EVENT_TYPE_PERSISTENT)
		if (!hwc->sample_period)
			return;

or similar.

4: sys_perf_event_open needs to know about already allocated and enabled events.

5-10: carves out a bunch of generic perf compilation units into a common lib. Split into 5 patches for easier review.

12-14: those are pulled in when exporting parse_events.c for external use.

16: lib/perf/misc.c contains functions and global variables like pager_in_use() or perf_guest or usage_with_options() which are used in generic utilities but are strictly perf-specific. Long term we should strive in making the library self-contained and getting rid of those.

19-20: those are only needed for testing, they'll go in over the edac tree in the next merge window. Added for completeness here.

21: only bare-bones implementation, needs a lot of fleshing out

Anyways, please have a look and let me know either way :)

Thanks,
Boris.

#1 lore raw

PATCH 1/21 perf_events: Export buffer handling functions

From: Borislav Petkov <[email protected]>

... for other in-kernel users.

---
 include/linux/perf_event.h |    8 ++++++++
 kernel/perf_event.c        |    8 ++++----
 2 files changed, 12 insertions(+), 4 deletions(-)
include/linux/perf_event.h +8 -0
index 63b5aa5..cb242bd 100644
@@ -1017,6 +1017,10 @@ extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
+extern struct perf_buffer *
+perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags);
+extern void perf_buffer_put(struct perf_buffer *buffer);
+
 #else
 static inline void
 perf_event_task_sched_in(struct task_struct *task)			{ }
@@ -1054,6 +1058,10 @@ static inline int  perf_swevent_get_recursion_context(void)		{ return -1; }
 static inline void perf_swevent_put_recursion_context(int rctx)		{ }
 static inline void perf_event_enable(struct perf_event *event)		{ }
 static inline void perf_event_disable(struct perf_event *event)		{ }
+extern struct perf_buffer *
+perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags)	{ return NULL; }
+static inline void perf_buffer_put(struct perf_buffer *buffer)		{}
+
 #endif
 
 #define perf_output_put(handle, x) \
kernel/perf_event.c +4 -4
index c772a3d..40478af 100644
@@ -1881,7 +1881,7 @@ static void free_event_rcu(struct rcu_head *head)
 }
 
 static void perf_pending_sync(struct perf_event *event);
-static void perf_buffer_put(struct perf_buffer *buffer);
+void perf_buffer_put(struct perf_buffer *buffer);
 
 static void free_event(struct perf_event *event)
 {
@@ -2424,7 +2424,7 @@ static void *perf_mmap_alloc_page(int cpu)
 	return page_address(page);
 }
 
-static struct perf_buffer *
+struct perf_buffer *
 perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags)
 {
 	struct perf_buffer *buffer;
@@ -2541,7 +2541,7 @@ static void perf_buffer_free(struct perf_buffer *buffer)
 	schedule_work(&buffer->work);
 }
 
-static struct perf_buffer *
+struct perf_buffer *
 perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags)
 {
 	struct perf_buffer *buffer;
@@ -2642,7 +2642,7 @@ static struct perf_buffer *perf_buffer_get(struct perf_event *event)
 	return buffer;
 }
 
-static void perf_buffer_put(struct perf_buffer *buffer)
+void perf_buffer_put(struct perf_buffer *buffer)
 {
 	if (!atomic_dec_and_test(&buffer->refcount))
 		return;
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/21 mce: Add persistent events

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Add the required glue to enable the mce_record tracepoint on boot thus simulating a persistent event with allocated buffers. Userspace daemon will hook into it later when booting is done.

---
 arch/x86/kernel/cpu/mcheck/mce.c |   89 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +89 -0
index 18cc425..42d2808 100644
@@ -95,6 +95,7 @@ static char			*mce_helper_argv[2] = { mce_helper, NULL };
 
 static DECLARE_WAIT_QUEUE_HEAD(mce_wait);
 static DEFINE_PER_CPU(struct mce, mces_seen);
+static DEFINE_PER_CPU(struct perf_event *, mce_event);
 static int			cpu_missing;
 
 /*
@@ -2063,6 +2064,91 @@ static void __cpuinit mce_reenable_cpu(void *h)
 	}
 }
 
+struct perf_event_attr pattr = {
+	.type	     = PERF_TYPE_TRACEPOINT,
+	.size	     = sizeof(pattr),
+	.sample_type = PERF_SAMPLE_RAW | PERF_SAMPLE_CPU | PERF_SAMPLE_TIME,
+};
+
+static int mcheck_enable_perf_event_on_cpu(int cpu)
+{
+	struct perf_event *event;
+	struct perf_buffer *buffer;
+
+	if (!event_mce_record.event.type) {
+		printk(KERN_ERR "mce: Tracepoint not enumerated yet!\n");
+		return -EINVAL;
+	}
+	pattr.config = event_mce_record.event.type;
+	pattr.sample_period = ULLONG_MAX;
+
+	event = perf_event_create_kernel_counter(&pattr, cpu, -1, NULL);
+	if (IS_ERR(event))
+		return -EINVAL;
+
+	buffer = perf_buffer_alloc(128, 0, cpu, 0);
+	if (IS_ERR(buffer))
+		goto err;
+
+	rcu_assign_pointer(event->buffer, buffer);
+	per_cpu(mce_event, cpu) = event;
+
+	perf_event_enable(event);
+
+	return 0;
+
+err:
+	perf_event_release_kernel(event);
+	return -EINVAL;
+}
+
+static void mcheck_disable_perf_event_on_cpu(int cpu)
+{
+	struct perf_event *event = per_cpu(mce_event, cpu);
+
+	if (!event)
+		return;
+
+	perf_event_disable(event);
+
+	if (event->buffer) {
+		perf_buffer_put(event->buffer);
+		rcu_assign_pointer(event->buffer, NULL);
+	}
+
+	per_cpu(mce_event, cpu) = NULL;
+
+	perf_event_release_kernel(event);
+}
+
+static int mcheck_init_perf_event(void)
+{
+	int cpu, i, err = 0;
+
+	get_online_cpus();
+
+	for_each_online_cpu(cpu) {
+		err = mcheck_enable_perf_event_on_cpu(cpu);
+		if (err) {
+			printk(KERN_ERR "mce: error initializing mce tracepoint"
+					" on cpu %d\n", cpu);
+
+			for (i = cpu - 1; i >= 0; i--)
+				mcheck_disable_perf_event_on_cpu(i);
+		}
+	}
+
+	put_online_cpus();
+
+	return err;
+}
+
+/*
+ * This has to run after after event_trace_init() which is an fs_initcall()
+ * currently
+ */
+device_initcall(mcheck_init_perf_event);
+
 /* Get notified when a cpu comes on/off. Be hotplug friendly. */
 static int __cpuinit
 mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
@@ -2076,6 +2162,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 		mce_create_device(cpu);
 		if (threshold_cpu_callback)
 			threshold_cpu_callback(action, cpu);
+		mcheck_enable_perf_event_on_cpu(cpu);
 		break;
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
@@ -2087,6 +2174,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 	case CPU_DOWN_PREPARE_FROZEN:
 		del_timer_sync(t);
 		smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
+		mcheck_disable_perf_event_on_cpu(cpu);
 		break;
 	case CPU_DOWN_FAILED:
 	case CPU_DOWN_FAILED_FROZEN:
@@ -2096,6 +2184,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 			add_timer_on(t, cpu);
 		}
 		smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
+		mcheck_enable_perf_event_on_cpu(cpu);
 		break;
 	case CPU_POST_DEAD:
 		/* intentionally ignoring frozen here */
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/21 perf_events: Add a helper to search for an event in a context

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

This is a straignt-forward helper to look for, e.g. already allocated and enabled events (think persistent events here).

---
 kernel/perf_event.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
kernel/perf_event.c +21 -0
index 40478af..168764b 100644
@@ -307,6 +307,27 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx)
 		ctx->nr_stat++;
 }
 
+/*
+ * Find an event in a context.
+ * Must be called with ctx->mutex and ctx->lock held.
+ */
+static struct perf_event *find_event_in_context(struct perf_event_attr *attr,
+						struct perf_event_context *ctx)
+{
+	struct perf_event *event;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(event, &ctx->event_list, event_entry) {
+		if (event->attr.config == attr->config) {
+			rcu_read_unlock();
+			return event;
+		}
+	}
+	rcu_read_unlock();
+
+	return NULL;
+}
+
 static void perf_group_attach(struct perf_event *event)
 {
 	struct perf_event *group_leader = event->group_leader;
Signature · 1 line
1.7.1
#4 lore raw

PATCH 4/21 perf_events: Handle persistent events accordingly

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Add a persistent events flag which is passed to sys_perf_event_open(). Also, teach the perf syscall to differentiate between previously allocated persistent events and new ones which are about to be created.

---
 include/linux/perf_event.h |    5 +++--
 kernel/perf_event.c        |   28 +++++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 5 deletions(-)
include/linux/perf_event.h +3 -2
index cb242bd..1d7907a 100644
@@ -452,8 +452,9 @@ enum perf_callchain_context {
 	PERF_CONTEXT_MAX		= (__u64)-4095,
 };
 
-#define PERF_FLAG_FD_NO_GROUP	(1U << 0)
-#define PERF_FLAG_FD_OUTPUT	(1U << 1)
+#define PERF_FLAG_FD_NO_GROUP		(1U << 0)
+#define PERF_FLAG_FD_OUTPUT		(1U << 1)
+#define PERF_FLAG_EVENT_PERSISTENT	(1U << 2)
 
 #ifdef __KERNEL__
 /*
kernel/perf_event.c +25 -3
index 168764b..8b41a4e 100644
@@ -5107,7 +5107,9 @@ SYSCALL_DEFINE5(perf_event_open,
 	int err;
 
 	/* for future expandability... */
-	if (flags & ~(PERF_FLAG_FD_NO_GROUP | PERF_FLAG_FD_OUTPUT))
+	if (flags & ~(PERF_FLAG_FD_NO_GROUP |
+		      PERF_FLAG_FD_OUTPUT |
+		      PERF_FLAG_EVENT_PERSISTENT))
 		return -EINVAL;
 
 	err = perf_copy_attr(attr_uptr, &attr);
@@ -5175,8 +5177,23 @@ SYSCALL_DEFINE5(perf_event_open,
 			goto err_put_context;
 	}
 
-	event = perf_event_alloc(&attr, cpu, ctx, group_leader,
-				     NULL, NULL, GFP_KERNEL);
+	if (flags & PERF_FLAG_EVENT_PERSISTENT) {
+		mutex_lock(&ctx->mutex);
+		raw_spin_lock(&ctx->lock);
+
+		event = find_event_in_context(&attr, ctx);
+
+		raw_spin_unlock(&ctx->lock);
+		mutex_unlock(&ctx->mutex);
+
+		if (!event) {
+			printk(KERN_WARNING "Hmm, uninitialized persistent event?!");
+			return -EINVAL;
+		}
+	} else
+		event = perf_event_alloc(&attr, cpu, ctx, group_leader,
+					 NULL, NULL, GFP_KERNEL);
+
 	if (IS_ERR(event)) {
 		err = PTR_ERR(event);
 		goto err_put_context;
@@ -5195,6 +5212,10 @@ SYSCALL_DEFINE5(perf_event_open,
 	}
 
 	event->filp = event_file;
+
+	if (flags & PERF_FLAG_EVENT_PERSISTENT)
+		goto out_drop_ref;
+
 	WARN_ON_ONCE(ctx->parent_ctx);
 	mutex_lock(&ctx->mutex);
 	perf_install_in_context(ctx, event, cpu);
@@ -5207,6 +5228,7 @@ SYSCALL_DEFINE5(perf_event_open,
 	list_add_tail(&event->owner_entry, &current->perf_event_list);
 	mutex_unlock(&current->perf_event_mutex);
 
+out_drop_ref:
 	/*
 	 * Drop the reference on the group_event after placing the
 	 * new event on the sibling_list. This ensures destruction
Signature · 1 line
1.7.1
#5 lore raw

PATCH 5/21 perf: rewire generic library stuff, p1

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Carve out generic library stuff into tools/lib/lk/ and rewire it with perf. Add a top-level Makefile which selects between targets depending on the tool we want to build. Also, add a Makefile.lib for common facilities used by all the Makefiles.

---
 tools/Makefile              |   58 ++++++++++++++++++++++
 tools/Makefile.lib          |   28 +++++++++++
 tools/lib/Makefile          |   38 ++++++++++++++
 tools/lib/lk/bitmap.c       |   21 ++++++++
 tools/lib/lk/cpumap.c       |  114 +++++++++++++++++++++++++++++++++++++++++++
 tools/lib/lk/cpumap.h       |    7 +++
 tools/lib/lk/hweight.c      |   31 ++++++++++++
 tools/perf/Makefile         |   41 ++--------------
 tools/perf/bench/bench.h    |    2 +
 tools/perf/builtin-record.c |    2 +-
 tools/perf/builtin-stat.c   |    2 +-
 tools/perf/builtin-top.c    |    2 +-
 tools/perf/util/bitmap.c    |   21 --------
 tools/perf/util/cache.h     |    1 +
 tools/perf/util/cpumap.c    |  114 -------------------------------------------
 tools/perf/util/cpumap.h    |    7 ---
 tools/perf/util/hweight.c   |   31 ------------
 17 files changed, 308 insertions(+), 212 deletions(-)
 create mode 100644 tools/Makefile
 create mode 100644 tools/Makefile.lib
 create mode 100644 tools/lib/Makefile
 create mode 100644 tools/lib/lk/bitmap.c
 create mode 100644 tools/lib/lk/cpumap.c
 create mode 100644 tools/lib/lk/cpumap.h
 create mode 100644 tools/lib/lk/hweight.c
 delete mode 100644 tools/perf/util/bitmap.c
 delete mode 100644 tools/perf/util/cpumap.c
 delete mode 100644 tools/perf/util/cpumap.h
 delete mode 100644 tools/perf/util/hweight.c
tools/Makefile new file +58 -0
new file mode 100644
index 0000000..e645761
@@ -0,0 +1,58 @@
+# CFLAGS and LDFLAGS are for the users to override from the command line.
+#
+
+include Makefile.lib
+
+#
+# Include saner warnings here, which can catch bugs:
+#
+EXTRA_WARNINGS := -Wformat
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-security
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-y2k
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wshadow
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Winit-self
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wpacked
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wredundant-decls
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstack-protector
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-aliasing=3
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-default
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-enum
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wno-system-headers
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wundef
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wvolatile-register-var
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wwrite-strings
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wbad-function-cast
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-declarations
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-prototypes
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wnested-externs
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes
+EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement
+
+export EXTRA_WARNINGS
+
+ifeq ("$(origin DEBUG)", "command line")
+  PERF_DEBUG = $(DEBUG)
+endif
+ifndef PERF_DEBUG
+  CFLAGS_OPTIMIZE = -O6
+  export CFLAGS_OPTIMIZE
+endif
+
+#
+# lib includes for submake
+BASIC_CFLAGS = -I$(CURDIR)/lib -I$(CURDIR)/perf -I$(CURDIR)/perf/util/include
+
+export BASIC_CFLAGS
+
+perf: lib .FORCE
+	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
+
+lib: .FORCE
+	$(QUIET_SUBDIR0)lib/ $(QUIET_SUBDIR1)
+
+clean:
+	$(QUIET_SUBDIR0)lib/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
+
+.PHONY: clean .FORCE
tools/Makefile.lib new file +28 -0
new file mode 100644
index 0000000..aac6be9
@@ -0,0 +1,28 @@
+QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
+QUIET_SUBDIR1  =
+
+ifneq ($(findstring $(MAKEFLAGS),w),w)
+PRINT_DIR = --no-print-directory
+else # "make -w"
+NO_SUBDIR = :
+endif
+
+ifneq ($(findstring $(MAKEFLAGS),s),s)
+ifndef V
+	QUIET_CC       = @echo '   ' CC $@;
+	QUIET_AR       = @echo '   ' AR $@;
+	QUIET_LINK     = @echo '   ' LINK $@;
+	QUIET_BUILT_IN = @echo '   ' BUILTIN $@;
+	QUIET_GEN      = @echo '   ' GEN $@;
+	QUIET_SUBDIR0  = +@subdir=
+	QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
+			 $(MAKE) $(PRINT_DIR) -C $$subdir
+	export V
+	export QUIET_GEN
+	export QUIET_BUILT_IN
+endif
+endif
+
+ifeq ("$(origin O)", "command line")
+	OUTPUT := $(O)/
+endif
tools/lib/Makefile new file +38 -0
new file mode 100644
index 0000000..48f8e21
@@ -0,0 +1,38 @@
+include ../Makefile.lib
+
+# Guard against environment variables
+LIB_H =
+LIB_OBJS =
+
+LIB_H += lk/cpumap.h
+
+LIB_OBJS += $(OUTPUT)lk/bitmap.o
+LIB_OBJS += $(OUTPUT)lk/cpumap.o
+LIB_OBJS += $(OUTPUT)lk/hweight.o
+
+LIBFILE = lklib.a
+
+RM = rm -f
+
+CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
+EXTLIBS = -lpthread -lrt -lelf -lm
+ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+ALL_LDFLAGS = $(LDFLAGS)
+STRIP ?= strip
+
+$(LIBFILE): $(LIB_OBJS)
+	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
+
+$(LIB_OBJS): $(LIB_H)
+
+$(OUTPUT)%.o: %.c
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+$(OUTPUT)%.s: %.c
+	$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
+$(OUTPUT)%.o: %.S
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+
+clean:
+	$(RM) $(LIB_OBJS)
+
+.PHONY: clean
tools/lib/lk/bitmap.c new file +21 -0
new file mode 100644
index 0000000..5e230ac
@@ -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;
+}
tools/lib/lk/cpumap.c new file +114 -0

114 lines not on this page · raw message

tools/lib/lk/cpumap.h new file +7 -0
new file mode 100644
index 0000000..1d7bd56
@@ -0,0 +1,7 @@
+#ifndef __LK_CPUMAP_H
+#define __LK_CPUMAP_H
+
+extern int read_cpu_map(const char *cpu_list);
+extern int cpumap[];
+
+#endif /* __LK_CPUMAP_H */
tools/lib/lk/hweight.c new file +31 -0
new file mode 100644
index 0000000..5c1d0d0
@@ -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
+}
tools/perf/Makefile +5 -36

80 lines not on this page · raw message

tools/perf/bench/bench.h +2 -0
index f7781c6..0c7ee07 100644
@@ -1,6 +1,8 @@
 #ifndef BENCH_H
 #define BENCH_H
 
+#include <linux/compiler.h>
+
 extern int bench_sched_messaging(int argc, const char **argv, const char *prefix);
 extern int bench_sched_pipe(int argc, const char **argv, const char *prefix);
 extern int bench_mem_memcpy(int argc, const char **argv, const char *prefix __used);
tools/perf/builtin-record.c +1 -1
index 86b1c3b..499dc75 100644
@@ -21,7 +21,7 @@
 #include "util/debug.h"
 #include "util/session.h"
 #include "util/symbol.h"
-#include "util/cpumap.h"
+#include <lk/cpumap.h>
 
 #include <unistd.h>
 #include <sched.h>
tools/perf/builtin-stat.c +1 -1
index a6b4d44..4430d51 100644
@@ -45,7 +45,7 @@
 #include "util/event.h"
 #include "util/debug.h"
 #include "util/header.h"
-#include "util/cpumap.h"
+#include <lk/cpumap.h>
 #include "util/thread.h"
 
 #include <sys/prctl.h>
tools/perf/builtin-top.c +1 -1
index 1e8e92e..def254a 100644
@@ -28,7 +28,7 @@
 #include <linux/rbtree.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
-#include "util/cpumap.h"
+#include <lk/cpumap.h>
 
 #include "util/debug.h"
 
tools/perf/util/bitmap.c deleted +0 -21
deleted file mode 100644
index 5e230ac..0000000
@@ -1,21 +0,0 @@
-/*
- * 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;
-}
tools/perf/util/cache.h +1 -0
index 27e9ebe..0444fc2 100644
@@ -5,6 +5,7 @@
 #include "util.h"
 #include "strbuf.h"
 #include "../perf.h"
+#include <linux/compiler.h>
 
 #define CMD_EXEC_PATH "--exec-path"
 #define CMD_PERF_DIR "--perf-dir="
tools/perf/util/cpumap.c deleted +0 -114

114 lines not on this page · raw message

tools/perf/util/cpumap.h deleted +0 -7
deleted file mode 100644
index 3e60f56..0000000
@@ -1,7 +0,0 @@
-#ifndef __PERF_CPUMAP_H
-#define __PERF_CPUMAP_H
-
-extern int read_cpu_map(const char *cpu_list);
-extern int cpumap[];
-
-#endif /* __PERF_CPUMAP_H */
tools/perf/util/hweight.c deleted +0 -31
deleted file mode 100644
index 5c1d0d0..0000000
@@ -1,31 +0,0 @@
-#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
-}
Signature · 1 line
1.7.1
#6 lore raw

PATCH 6/21 perf: rewire generic library stuff, p2

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Carve out generic library stuff into tools/lib/lk/ and rewire it with perf. Relocate bits from perf includes into generic include files to satisfy build dependencies.

---
 tools/lib/Makefile                                 |    6 +
 tools/lib/lk/cpumap.c                              |    2 +-
 tools/lib/lk/ctype.c                               |   39 +++
 tools/lib/lk/debugfs.c                             |  239 ++++++++++++++++
 tools/lib/lk/debugfs.h                             |   27 ++
 tools/lib/lk/types.h                               |   17 ++
 tools/lib/lk/util.c                                |  116 ++++++++
 tools/lib/lk/util.h                                |  285 ++++++++++++++++++++
 tools/perf/Makefile                                |    6 -
 tools/perf/bench/mem-memcpy.c                      |    2 +-
 tools/perf/bench/sched-messaging.c                 |    2 +-
 tools/perf/bench/sched-pipe.c                      |    2 +-
 tools/perf/builtin-annotate.c                      |    2 +-
 tools/perf/builtin-bench.c                         |    2 +-
 tools/perf/builtin-diff.c                          |    2 +-
 tools/perf/builtin-kmem.c                          |    2 +-
 tools/perf/builtin-kvm.c                           |    2 +-
 tools/perf/builtin-lock.c                          |    2 +-
 tools/perf/builtin-probe.c                         |    4 +-
 tools/perf/builtin-record.c                        |    2 +-
 tools/perf/builtin-report.c                        |    2 +-
 tools/perf/builtin-sched.c                         |    2 +-
 tools/perf/builtin-stat.c                          |    2 +-
 tools/perf/builtin-timechart.c                     |    2 +-
 tools/perf/builtin-top.c                           |    2 +-
 tools/perf/builtin-trace.c                         |    2 +-
 tools/perf/builtin.h                               |    2 +-
 tools/perf/perf.c                                  |    2 +-
 tools/perf/perf.h                                  |    2 +-
 tools/perf/util/build-id.c                         |    2 +-
 tools/perf/util/cache.h                            |    3 +-
 tools/perf/util/callchain.c                        |    2 +-
 tools/perf/util/config.c                           |    2 +-
 tools/perf/util/ctype.c                            |   39 ---
 tools/perf/util/debug.c                            |    2 +-
 tools/perf/util/debugfs.c                          |  240 ----------------
 tools/perf/util/debugfs.h                          |   25 --
 tools/perf/util/header.c                           |    2 +-
 tools/perf/util/header.h                           |    2 +-
 tools/perf/util/hist.c                             |    2 +-
 tools/perf/util/include/linux/ctype.h              |    2 +-
 tools/perf/util/map.h                              |    2 +-
 tools/perf/util/parse-events.c                     |    4 +-
 tools/perf/util/parse-options.c                    |    2 +-
 tools/perf/util/probe-event.c                      |    4 +-
 tools/perf/util/probe-finder.c                     |    2 +-
 tools/perf/util/probe-finder.h                     |    2 +-
 tools/perf/util/pstack.c                           |    2 +-
 .../perf/util/scripting-engines/trace-event-perl.c |    2 +-
 .../util/scripting-engines/trace-event-python.c    |    2 +-
 tools/perf/util/session.c                          |    2 +-
 tools/perf/util/sort.h                             |    2 +-
 tools/perf/util/string.c                           |    2 +-
 tools/perf/util/svghelper.h                        |    2 +-
 tools/perf/util/thread.c                           |    2 +-
 tools/perf/util/trace-event-info.c                 |    2 +-
 tools/perf/util/trace-event-parse.c                |    2 +-
 tools/perf/util/trace-event-read.c                 |    2 +-
 tools/perf/util/trace-event-scripting.c            |    2 +-
 tools/perf/util/types.h                            |   17 --
 tools/perf/util/usage.c                            |    2 +-
 tools/perf/util/util.c                             |  116 --------
 tools/perf/util/util.h                             |  285 --------------------
 tools/perf/util/values.c                           |    2 +-
 tools/perf/util/values.h                           |    2 +-
 65 files changed, 783 insertions(+), 783 deletions(-)
 create mode 100644 tools/lib/lk/ctype.c
 create mode 100644 tools/lib/lk/debugfs.c
 create mode 100644 tools/lib/lk/debugfs.h
 create mode 100644 tools/lib/lk/types.h
 create mode 100644 tools/lib/lk/util.c
 create mode 100644 tools/lib/lk/util.h
 delete mode 100644 tools/perf/util/ctype.c
 delete mode 100644 tools/perf/util/debugfs.c
 delete mode 100644 tools/perf/util/debugfs.h
 delete mode 100644 tools/perf/util/types.h
 delete mode 100644 tools/perf/util/util.c
 delete mode 100644 tools/perf/util/util.h
tools/lib/Makefile +6 -0
index 48f8e21..7ebcf8c 100644
@@ -5,10 +5,16 @@ LIB_H =
 LIB_OBJS =
 
 LIB_H += lk/cpumap.h
+LIB_H += lk/debugfs.h
+LIB_H += lk/util.h
+LIB_H += lk/types.h
 
 LIB_OBJS += $(OUTPUT)lk/bitmap.o
 LIB_OBJS += $(OUTPUT)lk/cpumap.o
+LIB_OBJS += $(OUTPUT)lk/ctype.o
+LIB_OBJS += $(OUTPUT)lk/debugfs.o
 LIB_OBJS += $(OUTPUT)lk/hweight.o
+LIB_OBJS += $(OUTPUT)lk/util.o
 
 LIBFILE = lklib.a
 
tools/lib/lk/cpumap.c +1 -1
index 71e376b..22626eb 100644
@@ -1,4 +1,4 @@
-#include <util/util.h>
+#include "util.h"
 #include <perf.h>
 #include "cpumap.h"
 #include <assert.h>
tools/lib/lk/ctype.c new file +39 -0
new file mode 100644
index 0000000..aada3ac
@@ -0,0 +1,39 @@
+/*
+ * Sane locale-independent, ASCII ctype.
+ *
+ * No surprises, and works with signed and unsigned chars.
+ */
+#include "util.h"
+
+enum {
+	S = GIT_SPACE,
+	A = GIT_ALPHA,
+	D = GIT_DIGIT,
+	G = GIT_GLOB_SPECIAL,	/* *, ?, [, \\ */
+	R = GIT_REGEX_SPECIAL,	/* $, (, ), +, ., ^, {, | * */
+	P = GIT_PRINT_EXTRA,	/* printable - alpha - digit - glob - regex */
+
+	PS = GIT_SPACE | GIT_PRINT_EXTRA,
+};
+
+unsigned char sane_ctype[256] = {
+/*	0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F			    */
+
+	0, 0, 0, 0, 0, 0, 0, 0, 0, S, S, 0, 0, S, 0, 0,		/*   0.. 15 */
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,		/*  16.. 31 */
+	PS,P, P, P, R, P, P, P, R, R, G, R, P, P, R, P,		/*  32.. 47 */
+	D, D, D, D, D, D, D, D, D, D, P, P, P, P, P, G,		/*  48.. 63 */
+	P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,		/*  64.. 79 */
+	A, A, A, A, A, A, A, A, A, A, A, G, G, P, R, P,		/*  80.. 95 */
+	P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,		/*  96..111 */
+	A, A, A, A, A, A, A, A, A, A, A, R, R, P, P, 0,		/* 112..127 */
+	/* Nothing in the 128.. range */
+};
+
+const char *graph_line =
+	"_____________________________________________________________________"
+	"_____________________________________________________________________";
+const char *graph_dotted_line =
+	"---------------------------------------------------------------------"
+	"---------------------------------------------------------------------"
+	"---------------------------------------------------------------------";
tools/lib/lk/debugfs.c new file +239 -0

239 lines not on this page · raw message

tools/lib/lk/debugfs.h new file +27 -0
new file mode 100644
index 0000000..8c02e72
@@ -0,0 +1,27 @@
+#ifndef __DEBUGFS_H__
+#define __DEBUGFS_H__
+
+#include <sys/mount.h>
+
+#ifndef MAX_PATH
+# define MAX_PATH 256
+#endif
+
+#ifndef STR
+# define _STR(x) #x
+# define STR(x) _STR(x)
+#endif
+
+#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
+
+extern const char *debugfs_find_mountpoint(void);
+extern int debugfs_valid_mountpoint(const char *debugfs);
+extern int debugfs_valid_entry(const char *path);
+extern char *debugfs_mount(const char *mountpoint);
+extern int debugfs_umount(void);
+extern int debugfs_write(const char *entry, const char *value);
+extern int debugfs_read(const char *entry, char *buffer, size_t size);
+extern void debugfs_force_cleanup(void);
+extern int debugfs_make_path(const char *element, char *buffer, int size);
+
+#endif /* __DEBUGFS_H__ */
tools/lib/lk/types.h new file +17 -0
new file mode 100644
index 0000000..eda6c0c
@@ -0,0 +1,17 @@
+#ifndef __LK_TYPES_H
+#define __LK_TYPES_H
+
+/*
+ * We define u64 as unsigned long long for every architecture
+ * so that we can print it with %Lx without getting warnings.
+ */
+typedef unsigned long long u64;
+typedef signed long long   s64;
+typedef unsigned int	   u32;
+typedef signed int	   s32;
+typedef unsigned short	   u16;
+typedef signed short	   s16;
+typedef unsigned char	   u8;
+typedef signed char	   s8;
+
+#endif /* __LK_TYPES_H */
tools/lib/lk/util.c new file +116 -0

116 lines not on this page · raw message

tools/lib/lk/util.h new file +285 -0

285 lines not on this page · raw message

tools/perf/Makefile +0 -6
index df815d6..e224788 100644
@@ -356,16 +356,13 @@ LIB_H += util/cache.h
 LIB_H += util/callchain.h
 LIB_H += util/build-id.h
 LIB_H += util/debug.h
-LIB_H += util/debugfs.h
 LIB_H += util/event.h
 LIB_H += util/exec_cmd.h
-LIB_H += util/types.h
 LIB_H += util/levenshtein.h
 LIB_H += util/map.h
 LIB_H += util/parse-options.h
 LIB_H += util/parse-events.h
 LIB_H += util/quote.h
-LIB_H += util/util.h
 LIB_H += util/header.h
 LIB_H += util/help.h
 LIB_H += util/session.h
@@ -389,8 +386,6 @@ LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
 LIB_OBJS += $(OUTPUT)util/build-id.o
 LIB_OBJS += $(OUTPUT)util/config.o
-LIB_OBJS += $(OUTPUT)util/ctype.o
-LIB_OBJS += $(OUTPUT)util/debugfs.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/exec_cmd.o
@@ -427,7 +422,6 @@ LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
 LIB_OBJS += $(OUTPUT)util/hist.o
 LIB_OBJS += $(OUTPUT)util/probe-event.o
-LIB_OBJS += $(OUTPUT)util/util.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 
tools/perf/bench/mem-memcpy.c +1 -1
index 38dae74..1b2f508 100644
@@ -8,7 +8,7 @@
 #include <ctype.h>
 
 #include "../perf.h"
-#include "../util/util.h"
+#include <lk/util.h>
 #include "../util/parse-options.h"
 #include "../util/header.h"
 #include "bench.h"
tools/perf/bench/sched-messaging.c +1 -1
index d1d1b30..37f12ad 100644
@@ -10,7 +10,7 @@
  */
 
 #include "../perf.h"
-#include "../util/util.h"
+#include <lk/util.h>
 #include "../util/parse-options.h"
 #include "../builtin.h"
 #include "bench.h"
tools/perf/bench/sched-pipe.c +1 -1
index d9ab3ce..9b05c92 100644
@@ -11,7 +11,7 @@
  */
 
 #include "../perf.h"
-#include "../util/util.h"
+#include <lk/util.h>
 #include "../util/parse-options.h"
 #include "../builtin.h"
 #include "bench.h"
tools/perf/builtin-annotate.c +1 -1
index fd20670..03f80e9 100644
@@ -7,7 +7,7 @@
  */
 #include "builtin.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 
 #include "util/color.h"
 #include <linux/list.h>
tools/perf/builtin-bench.c +1 -1
index fcb9626..4ae8ea2 100644
@@ -17,7 +17,7 @@
  */
 
 #include "perf.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/parse-options.h"
 #include "builtin.h"
 #include "bench/bench.h"
tools/perf/builtin-diff.c +1 -1
index 39e6627..2f5a711 100644
@@ -12,7 +12,7 @@
 #include "util/session.h"
 #include "util/sort.h"
 #include "util/symbol.h"
-#include "util/util.h"
+#include <lk/util.h>
 
 #include <stdlib.h>
 
tools/perf/builtin-kmem.c +1 -1
index 31f60a2..68a6ec0 100644
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
tools/perf/builtin-kvm.c +1 -1
index 34d1e85..3e5d0fc 100644
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
tools/perf/builtin-lock.c +1 -1
index 821c158..bafb8c5 100644
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
tools/perf/builtin-probe.c +2 -2
index 5455186..be24b54 100644
@@ -34,11 +34,11 @@
 #undef _GNU_SOURCE
 #include "perf.h"
 #include "builtin.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/strlist.h"
 #include "util/symbol.h"
 #include "util/debug.h"
-#include "util/debugfs.h"
+#include <lk/debugfs.h>
 #include "util/parse-options.h"
 #include "util/probe-finder.h"
 #include "util/probe-event.h"
tools/perf/builtin-record.c +1 -1
index 499dc75..b92e009 100644
@@ -12,7 +12,7 @@
 #include "perf.h"
 
 #include "util/build-id.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 
tools/perf/builtin-report.c +1 -1
index 371a3c9..4be3c67 100644
@@ -7,7 +7,7 @@
  */
 #include "builtin.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 
 #include "util/color.h"
 #include <linux/list.h>
tools/perf/builtin-sched.c +1 -1
index 55f3b5d..c47cf08 100644
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
tools/perf/builtin-stat.c +1 -1
index 4430d51..1f60239 100644
@@ -39,7 +39,7 @@
 
 #include "perf.h"
 #include "builtin.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 #include "util/event.h"
tools/perf/builtin-timechart.c +1 -1
index 5a52ed9..92f7230 100644
@@ -14,7 +14,7 @@
 
 #include "builtin.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 
 #include "util/color.h"
 #include <linux/list.h>
tools/perf/builtin-top.c +1 -1
index def254a..9813351 100644
@@ -24,7 +24,7 @@
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/thread.h"
-#include "util/util.h"
+#include <lk/util.h>
 #include <linux/rbtree.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
tools/perf/builtin-trace.c +1 -1
index dddf3f0..3f9308a 100644
@@ -1,6 +1,6 @@
 #include "builtin.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
tools/perf/builtin.h +1 -1
index 921245b..08e69d2 100644
@@ -1,7 +1,7 @@
 #ifndef BUILTIN_H
 #define BUILTIN_H
 
-#include "util/util.h"
+#include <lk/util.h>
 #include "util/strbuf.h"
 
 extern const char perf_version_string[];
tools/perf/perf.c +1 -1
index cdd6c03..2fda133 100644
@@ -13,7 +13,7 @@
 #include "util/quote.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
-#include "util/debugfs.h"
+#include <lk/debugfs.h>
 
 const char perf_usage_string[] =
 	"perf [--version] [--help] COMMAND [ARGS]";
tools/perf/perf.h +1 -1
index ef7aa0a..2344078 100644
@@ -79,7 +79,7 @@ void get_term_dimensions(struct winsize *ws);
 #include <sys/syscall.h>
 
 #include "../../include/linux/perf_event.h"
-#include "util/types.h"
+#include <lk/types.h>
 #include <stdbool.h>
 
 /*
tools/perf/util/build-id.c +1 -1
index 5c26e2d..5de09e2 100644
@@ -6,7 +6,7 @@
  * Copyright (C) 2009, 2010 Red Hat Inc.
  * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <[email protected]>
  */
-#include "util.h"
+#include <lk/util.h>
 #include <stdio.h>
 #include "build-id.h"
 #include "event.h"
tools/perf/util/cache.h +1 -2
index 0444fc2..ce83e82 100644
@@ -2,7 +2,7 @@
 #define __PERF_CACHE_H
 
 #include <stdbool.h>
-#include "util.h"
+#include <lk/util.h>
 #include "strbuf.h"
 #include "../perf.h"
 #include <linux/compiler.h>
@@ -16,7 +16,6 @@
 #define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
 #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
-#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int perf_default_config(const char *, const char *, void *);
tools/perf/util/callchain.c +1 -1
index e63c997..a6c99a3 100644
@@ -15,7 +15,7 @@
 #include <errno.h>
 #include <math.h>
 
-#include "util.h"
+#include <lk/util.h>
 #include "callchain.h"
 
 bool ip_callchain__valid(struct ip_callchain *chain, const event_t *event)
tools/perf/util/config.c +1 -1
index e02d78c..bb2f5a0 100644
@@ -5,7 +5,7 @@
  * Copyright (C) Johannes Schindelin, 2005
  *
  */
-#include "util.h"
+#include <lk/util.h>
 #include "cache.h"
 #include "exec_cmd.h"
 
tools/perf/util/ctype.c deleted +0 -39
deleted file mode 100644
index 3507362..0000000
@@ -1,39 +0,0 @@
-/*
- * Sane locale-independent, ASCII ctype.
- *
- * No surprises, and works with signed and unsigned chars.
- */
-#include "cache.h"
-
-enum {
-	S = GIT_SPACE,
-	A = GIT_ALPHA,
-	D = GIT_DIGIT,
-	G = GIT_GLOB_SPECIAL,	/* *, ?, [, \\ */
-	R = GIT_REGEX_SPECIAL,	/* $, (, ), +, ., ^, {, | * */
-	P = GIT_PRINT_EXTRA,	/* printable - alpha - digit - glob - regex */
-
-	PS = GIT_SPACE | GIT_PRINT_EXTRA,
-};
-
-unsigned char sane_ctype[256] = {
-/*	0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F			    */
-
-	0, 0, 0, 0, 0, 0, 0, 0, 0, S, S, 0, 0, S, 0, 0,		/*   0.. 15 */
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,		/*  16.. 31 */
-	PS,P, P, P, R, P, P, P, R, R, G, R, P, P, R, P,		/*  32.. 47 */
-	D, D, D, D, D, D, D, D, D, D, P, P, P, P, P, G,		/*  48.. 63 */
-	P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,		/*  64.. 79 */
-	A, A, A, A, A, A, A, A, A, A, A, G, G, P, R, P,		/*  80.. 95 */
-	P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,		/*  96..111 */
-	A, A, A, A, A, A, A, A, A, A, A, R, R, P, P, 0,		/* 112..127 */
-	/* Nothing in the 128.. range */
-};
-
-const char *graph_line =
-	"_____________________________________________________________________"
-	"_____________________________________________________________________";
-const char *graph_dotted_line =
-	"---------------------------------------------------------------------"
-	"---------------------------------------------------------------------"
-	"---------------------------------------------------------------------";
tools/perf/util/debug.c +1 -1
index 318dab1..96cb72a 100644
@@ -10,7 +10,7 @@
 #include "color.h"
 #include "event.h"
 #include "debug.h"
-#include "util.h"
+#include <lk/util.h>
 
 int verbose = 0;
 bool dump_trace = false;
tools/perf/util/debugfs.c deleted +0 -240

240 lines not on this page · raw message

tools/perf/util/debugfs.h deleted +0 -25
deleted file mode 100644
index 83a0287..0000000
@@ -1,25 +0,0 @@
-#ifndef __DEBUGFS_H__
-#define __DEBUGFS_H__
-
-#include <sys/mount.h>
-
-#ifndef MAX_PATH
-# define MAX_PATH 256
-#endif
-
-#ifndef STR
-# define _STR(x) #x
-# define STR(x) _STR(x)
-#endif
-
-extern const char *debugfs_find_mountpoint(void);
-extern int debugfs_valid_mountpoint(const char *debugfs);
-extern int debugfs_valid_entry(const char *path);
-extern char *debugfs_mount(const char *mountpoint);
-extern int debugfs_umount(void);
-extern int debugfs_write(const char *entry, const char *value);
-extern int debugfs_read(const char *entry, char *buffer, size_t size);
-extern void debugfs_force_cleanup(void);
-extern int debugfs_make_path(const char *element, char *buffer, int size);
-
-#endif /* __DEBUGFS_H__ */
tools/perf/util/header.c +1 -1
index d7e67b1..0ebd301 100644
@@ -8,7 +8,7 @@
 #include <linux/list.h>
 #include <linux/kernel.h>
 
-#include "util.h"
+#include <lk/util.h>
 #include "header.h"
 #include "../perf.h"
 #include "trace-event.h"
tools/perf/util/header.h +1 -1
index 402ac24..fb6f0eb 100644
@@ -4,7 +4,7 @@
 #include "../../../include/linux/perf_event.h"
 #include <sys/types.h>
 #include <stdbool.h>
-#include "types.h"
+#include <lk/types.h>
 #include "event.h"
 
 #include <linux/bitmap.h>
tools/perf/util/hist.c +1 -1
index 68d288c..a409e27 100644
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "build-id.h"
 #include "hist.h"
 #include "session.h"
tools/perf/util/include/linux/ctype.h +1 -1
index a53d4ee..0698f26 100644
@@ -1 +1 @@
-#include "../util.h"
+#include <lk/util.h>
tools/perf/util/map.h +1 -1
index f391345..c7ed844 100644
@@ -6,7 +6,7 @@
 #include <linux/rbtree.h>
 #include <stdio.h>
 #include <stdbool.h>
-#include "types.h"
+#include <lk/types.h>
 
 enum map_type {
 	MAP__FUNCTION = 0,
tools/perf/util/parse-events.c +2 -2
index 9bf0f40..3a76c8e 100644
@@ -1,5 +1,5 @@
 #include "../../../include/linux/hw_breakpoint.h"
-#include "util.h"
+#include <lk/util.h>
 #include "../perf.h"
 #include "parse-options.h"
 #include "parse-events.h"
@@ -8,7 +8,7 @@
 #include "symbol.h"
 #include "cache.h"
 #include "header.h"
-#include "debugfs.h"
+#include <lk/debugfs.h>
 
 int				nr_counters;
 
tools/perf/util/parse-options.c +1 -1
index 99d02aa..25b57fc 100644
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "parse-options.h"
 #include "cache.h"
 
tools/perf/util/probe-event.c +2 -2
index 914c670..723b10d 100644
@@ -33,7 +33,7 @@
 #include <limits.h>
 
 #undef _GNU_SOURCE
-#include "util.h"
+#include <lk/util.h>
 #include "event.h"
 #include "string.h"
 #include "strlist.h"
@@ -42,7 +42,7 @@
 #include "color.h"
 #include "symbol.h"
 #include "thread.h"
-#include "debugfs.h"
+#include <lk/debugfs.h>
 #include "trace-event.h"	/* For __unused */
 #include "probe-event.h"
 #include "probe-finder.h"
tools/perf/util/probe-finder.c +1 -1
index baf6653..eb4eb26 100644
@@ -36,7 +36,7 @@
 #include "string.h"
 #include "event.h"
 #include "debug.h"
-#include "util.h"
+#include <lk/util.h>
 #include "symbol.h"
 #include "probe-finder.h"
 
tools/perf/util/probe-finder.h +1 -1
index e1f61dc..470611b 100644
@@ -2,7 +2,7 @@
 #define _PROBE_FINDER_H
 
 #include <stdbool.h>
-#include "util.h"
+#include <lk/util.h>
 #include "probe-event.h"
 
 #define MAX_PATH_LEN		 256
tools/perf/util/pstack.c +1 -1
index 13d36fa..aacedb8 100644
@@ -4,7 +4,7 @@
  * (c) 2010 Arnaldo Carvalho de Melo <[email protected]>
  */
 
-#include "util.h"
+#include <lk/util.h>
 #include "pstack.h"
 #include <linux/kernel.h>
 #include <stdlib.h>
tools/perf/util/scripting-engines/trace-event-perl.c +1 -1
index b059dc5..78af7d1 100644
@@ -26,7 +26,7 @@
 #include <errno.h>
 
 #include "../../perf.h"
-#include "../util.h"
+#include <lk/util.h>
 #include "../trace-event.h"
 
 #include <EXTERN.h>
tools/perf/util/scripting-engines/trace-event-python.c +1 -1
index 33a6325..9ddc198 100644
@@ -28,7 +28,7 @@
 #include <errno.h>
 
 #include "../../perf.h"
-#include "../util.h"
+#include <lk/util.h>
 #include "../trace-event.h"
 
 PyMODINIT_FUNC initperf_trace_context(void);
tools/perf/util/session.c +1 -1
index 0564a5c..638ecd0 100644
@@ -9,7 +9,7 @@
 
 #include "session.h"
 #include "sort.h"
-#include "util.h"
+#include <lk/util.h>
 
 static int perf_session__open(struct perf_session *self, bool force)
 {
tools/perf/util/sort.h +1 -1
index 560c855..8ead949 100644
@@ -2,7 +2,7 @@
 #define __PERF_SORT_H
 #include "../builtin.h"
 
-#include "util.h"
+#include <lk/util.h>
 
 #include "color.h"
 #include <linux/list.h>
tools/perf/util/string.c +1 -1
index 0409fc7..881ef63 100644
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "string.h"
 
 #define K 1024LL
tools/perf/util/svghelper.h +1 -1
index e078198..ac74b40 100644
@@ -1,7 +1,7 @@
 #ifndef __PERF_SVGHELPER_H
 #define __PERF_SVGHELPER_H
 
-#include "types.h"
+#include <lk/types.h>
 
 extern void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end);
 extern void svg_box(int Yslot, u64 start, u64 end, const char *type);
tools/perf/util/thread.c +1 -1
index 1f7ecd4..deb30a8 100644
@@ -4,7 +4,7 @@
 #include <string.h>
 #include "session.h"
 #include "thread.h"
-#include "util.h"
+#include <lk/util.h>
 #include "debug.h"
 
 int find_all_tid(int pid, pid_t ** all_tid)
tools/perf/util/trace-event-info.c +1 -1
index b157260..0918a63 100644
@@ -38,7 +38,7 @@
 
 #include "../perf.h"
 #include "trace-event.h"
-#include "debugfs.h"
+#include <lk/debugfs.h>
 
 #define VERSION "0.5"
 
tools/perf/util/trace-event-parse.c +1 -1
index 73a0222..9a46fa1 100644
@@ -30,7 +30,7 @@
 
 #undef _GNU_SOURCE
 #include "../perf.h"
-#include "util.h"
+#include <lk/util.h>
 #include "trace-event.h"
 
 int header_page_ts_offset;
tools/perf/util/trace-event-read.c +1 -1
index f55cc3a..2583227 100644
@@ -37,7 +37,7 @@
 #include <errno.h>
 
 #include "../perf.h"
-#include "util.h"
+#include <lk/util.h>
 #include "trace-event.h"
 
 static int input_fd;
tools/perf/util/trace-event-scripting.c +1 -1
index 7ea983a..dae67df 100644
@@ -26,7 +26,7 @@
 #include <errno.h>
 
 #include "../perf.h"
-#include "util.h"
+#include <lk/util.h>
 #include "trace-event.h"
 
 struct scripting_context *scripting_context;
tools/perf/util/types.h deleted +0 -17
deleted file mode 100644
index 7d6b833..0000000
@@ -1,17 +0,0 @@
-#ifndef __PERF_TYPES_H
-#define __PERF_TYPES_H
-
-/*
- * We define u64 as unsigned long long for every architecture
- * so that we can print it with %Lx without getting warnings.
- */
-typedef unsigned long long u64;
-typedef signed long long   s64;
-typedef unsigned int	   u32;
-typedef signed int	   s32;
-typedef unsigned short	   u16;
-typedef signed short	   s16;
-typedef unsigned char	   u8;
-typedef signed char	   s8;
-
-#endif /* __PERF_TYPES_H */
tools/perf/util/usage.c +1 -1
index e16bf9a..d438743 100644
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "util.h"
+#include <lk/util.h>
 
 static void report(const char *prefix, const char *err, va_list params)
 {
tools/perf/util/util.c deleted +0 -116

116 lines not on this page · raw message

tools/perf/util/util.h deleted +0 -285

285 lines not on this page · raw message

tools/perf/util/values.c +1 -1
index cfa55d6..648fc48 100644
@@ -1,6 +1,6 @@
 #include <stdlib.h>
 
-#include "util.h"
+#include <lk/util.h>
 #include "values.h"
 
 void perf_read_values_init(struct perf_read_values *values)
tools/perf/util/values.h +1 -1
index 2fa967e..f762cb7 100644
@@ -1,7 +1,7 @@
 #ifndef __PERF_VALUES_H
 #define __PERF_VALUES_H
 
-#include "types.h"
+#include <lk/types.h>
 
 struct perf_read_values {
 	int threads;
Signature · 1 line
1.7.1
#7 lore raw

PATCH 7/21 perf: rewire generic library stuff, p3

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Carve out generic library stuff into tools/lib/lk/ and rewire it with perf. Relocate more generic stuff into <lk/util.h>

---
 tools/lib/Makefile       |    5 ++
 tools/lib/lk/pstack.c    |   75 ++++++++++++++++++++++++++
 tools/lib/lk/pstack.h    |   12 ++++
 tools/lib/lk/strbuf.c    |  133 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/lib/lk/strbuf.h    |   99 ++++++++++++++++++++++++++++++++++
 tools/lib/lk/usage.c     |   80 +++++++++++++++++++++++++++
 tools/lib/lk/util.h      |   21 +++++++-
 tools/perf/Makefile      |    5 --
 tools/perf/builtin.h     |    2 +-
 tools/perf/util/cache.h  |   23 +--------
 tools/perf/util/pstack.c |   75 --------------------------
 tools/perf/util/pstack.h |   12 ----
 tools/perf/util/strbuf.c |  133 ----------------------------------------------
 tools/perf/util/strbuf.h |   92 --------------------------------
 tools/perf/util/usage.c  |   80 ---------------------------
 15 files changed, 426 insertions(+), 421 deletions(-)
 create mode 100644 tools/lib/lk/pstack.c
 create mode 100644 tools/lib/lk/pstack.h
 create mode 100644 tools/lib/lk/strbuf.c
 create mode 100644 tools/lib/lk/strbuf.h
 create mode 100644 tools/lib/lk/usage.c
 delete mode 100644 tools/perf/util/pstack.c
 delete mode 100644 tools/perf/util/pstack.h
 delete mode 100644 tools/perf/util/strbuf.c
 delete mode 100644 tools/perf/util/strbuf.h
 delete mode 100644 tools/perf/util/usage.c
tools/lib/Makefile +5 -0
index 7ebcf8c..64c0dbd 100644
@@ -8,6 +8,8 @@ LIB_H += lk/cpumap.h
 LIB_H += lk/debugfs.h
 LIB_H += lk/util.h
 LIB_H += lk/types.h
+LIB_H += lk/pstack.h
+LIB_H += lk/strbuf.h
 
 LIB_OBJS += $(OUTPUT)lk/bitmap.o
 LIB_OBJS += $(OUTPUT)lk/cpumap.o
@@ -15,6 +17,9 @@ LIB_OBJS += $(OUTPUT)lk/ctype.o
 LIB_OBJS += $(OUTPUT)lk/debugfs.o
 LIB_OBJS += $(OUTPUT)lk/hweight.o
 LIB_OBJS += $(OUTPUT)lk/util.o
+LIB_OBJS += $(OUTPUT)lk/pstack.o
+LIB_OBJS += $(OUTPUT)lk/strbuf.o
+LIB_OBJS += $(OUTPUT)lk/usage.o
 
 LIBFILE = lklib.a
 
tools/lib/lk/pstack.c new file +75 -0

75 lines not on this page · raw message

tools/lib/lk/pstack.h new file +12 -0
new file mode 100644
index 0000000..aa0c248
@@ -0,0 +1,12 @@
+#ifndef __LK_PSTACK_H
+#define __LK_PSTACK_H
+
+struct pstack;
+struct pstack *pstack__new(unsigned short max_nr_entries);
+void pstack__delete(struct pstack *self);
+bool pstack__empty(const struct pstack *self);
+void pstack__remove(struct pstack *self, void *key);
+void pstack__push(struct pstack *self, void *key);
+void *pstack__pop(struct pstack *self);
+
+#endif /* __LK_PSTACK_H */
tools/lib/lk/strbuf.c new file +133 -0

133 lines not on this page · raw message

tools/lib/lk/strbuf.h new file +99 -0

99 lines not on this page · raw message

tools/lib/lk/usage.c new file +80 -0

80 lines not on this page · raw message

tools/lib/lk/util.h +20 -1
index f380fed..dc88970 100644
@@ -141,6 +141,26 @@ extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1,
 extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
 
+#define alloc_nr(x) (((x)+16)*3/2)
+
+/*
+ * Realloc the buffer pointed at by variable 'x' so that it can hold
+ * at least 'nr' entries; the number of entries currently allocated
+ * is 'alloc', using the standard growing factor alloc_nr() macro.
+ *
+ * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
+ */
+#define ALLOC_GROW(x, nr, alloc) \
+	do { \
+		if ((nr) > alloc) { \
+			if (alloc_nr(alloc) < (nr)) \
+				alloc = (nr); \
+			else \
+				alloc = alloc_nr(alloc); \
+			x = xrealloc((x), alloc * sizeof(*(x))); \
+		} \
+	} while(0)
+
 #include "../../../include/linux/stringify.h"
 
 #define DIE_IF(cnd)	\
@@ -152,7 +172,6 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
 
 extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
 
-extern int prefixcmp(const char *str, const char *prefix);
 extern void set_buildid_dir(void);
 extern void disable_buildid_cache(void);
 
tools/perf/Makefile +0 -5
index e224788..6fc4c4a 100644
@@ -366,7 +366,6 @@ LIB_H += util/quote.h
 LIB_H += util/header.h
 LIB_H += util/help.h
 LIB_H += util/session.h
-LIB_H += util/strbuf.h
 LIB_H += util/strlist.h
 LIB_H += util/svghelper.h
 LIB_H += util/run-command.h
@@ -380,7 +379,6 @@ LIB_H += util/thread.h
 LIB_H += util/trace-event.h
 LIB_H += util/probe-finder.h
 LIB_H += util/probe-event.h
-LIB_H += util/pstack.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -397,10 +395,8 @@ LIB_OBJS += $(OUTPUT)util/path.o
 LIB_OBJS += $(OUTPUT)util/rbtree.o
 LIB_OBJS += $(OUTPUT)util/run-command.o
 LIB_OBJS += $(OUTPUT)util/quote.o
-LIB_OBJS += $(OUTPUT)util/strbuf.o
 LIB_OBJS += $(OUTPUT)util/string.o
 LIB_OBJS += $(OUTPUT)util/strlist.o
-LIB_OBJS += $(OUTPUT)util/usage.o
 LIB_OBJS += $(OUTPUT)util/wrapper.o
 LIB_OBJS += $(OUTPUT)util/sigchain.o
 LIB_OBJS += $(OUTPUT)util/symbol.o
@@ -411,7 +407,6 @@ LIB_OBJS += $(OUTPUT)util/callchain.o
 LIB_OBJS += $(OUTPUT)util/values.o
 LIB_OBJS += $(OUTPUT)util/debug.o
 LIB_OBJS += $(OUTPUT)util/map.o
-LIB_OBJS += $(OUTPUT)util/pstack.o
 LIB_OBJS += $(OUTPUT)util/session.o
 LIB_OBJS += $(OUTPUT)util/thread.o
 LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
tools/perf/builtin.h +1 -1
index 08e69d2..8d46079 100644
@@ -2,7 +2,7 @@
 #define BUILTIN_H
 
 #include <lk/util.h>
-#include "util/strbuf.h"
+#include <lk/strbuf.h>
 
 extern const char perf_version_string[];
 extern const char perf_usage_string[];
tools/perf/util/cache.h +1 -22
index ce83e82..93570a8 100644
@@ -3,7 +3,7 @@
 
 #include <stdbool.h>
 #include <lk/util.h>
-#include "strbuf.h"
+#include <lk/strbuf.h>
 #include "../perf.h"
 #include <linux/compiler.h>
 
@@ -47,27 +47,6 @@ void exit_browser(bool wait_for_ok);
 char *alias_lookup(const char *alias);
 int split_cmdline(char *cmdline, const char ***argv);
 
-#define alloc_nr(x) (((x)+16)*3/2)
-
-/*
- * Realloc the buffer pointed at by variable 'x' so that it can hold
- * at least 'nr' entries; the number of entries currently allocated
- * is 'alloc', using the standard growing factor alloc_nr() macro.
- *
- * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
- */
-#define ALLOC_GROW(x, nr, alloc) \
-	do { \
-		if ((nr) > alloc) { \
-			if (alloc_nr(alloc) < (nr)) \
-				alloc = (nr); \
-			else \
-				alloc = alloc_nr(alloc); \
-			x = xrealloc((x), alloc * sizeof(*(x))); \
-		} \
-	} while(0)
-
-
 static inline int is_absolute_path(const char *path)
 {
 	return path[0] == '/';
tools/perf/util/pstack.c deleted +0 -75

75 lines not on this page · raw message

tools/perf/util/pstack.h deleted +0 -12
deleted file mode 100644
index 5ad0702..0000000
@@ -1,12 +0,0 @@
-#ifndef _PERF_PSTACK_
-#define _PERF_PSTACK_
-
-struct pstack;
-struct pstack *pstack__new(unsigned short max_nr_entries);
-void pstack__delete(struct pstack *self);
-bool pstack__empty(const struct pstack *self);
-void pstack__remove(struct pstack *self, void *key);
-void pstack__push(struct pstack *self, void *key);
-void *pstack__pop(struct pstack *self);
-
-#endif /* _PERF_PSTACK_ */
tools/perf/util/strbuf.c deleted +0 -133

133 lines not on this page · raw message

tools/perf/util/strbuf.h deleted +0 -92

92 lines not on this page · raw message

tools/perf/util/usage.c deleted +0 -80

80 lines not on this page · raw message

Signature · 1 line
1.7.1
#8 lore raw

PATCH 8/21 perf: rewire generic library stuff, p4

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Split util/config.c and util/color.c into a generic and a perf-specific parts. As a result, remove unused perf_config_colorbool() and perf_color_default_config(). Move pager.c elements used in color.c temporarily into it. Will be moved to tools/perf/perf.c unit later.

---
 tools/lib/Makefile             |    3 +
 tools/lib/lk/color.c           |  306 ++++++++++++++++++++++++++
 tools/lib/lk/color.h           |   46 ++++
 tools/lib/lk/config.c          |  388 +++++++++++++++++++++++++++++++++
 tools/lib/lk/config.h          |   18 ++
 tools/lib/lk/util.h            |    1 -
 tools/perf/Makefile            |    5 +-
 tools/perf/builtin-annotate.c  |    4 +-
 tools/perf/builtin-help.c      |   13 +-
 tools/perf/builtin-report.c    |    2 +-
 tools/perf/builtin-timechart.c |    2 +-
 tools/perf/builtin-top.c       |    2 +-
 tools/perf/perf.c              |    7 +-
 tools/perf/util/alias.c        |    4 +-
 tools/perf/util/build-id.c     |   51 +++++
 tools/perf/util/build-id.h     |    2 +
 tools/perf/util/cache.h        |   10 -
 tools/perf/util/color.c        |  324 ----------------------------
 tools/perf/util/color.h        |   46 ----
 tools/perf/util/config.c       |  460 ++--------------------------------------
 tools/perf/util/config.h       |    8 +
 tools/perf/util/debug.c        |    4 +-
 tools/perf/util/environment.c  |    3 +-
 tools/perf/util/help.c         |    7 +-
 tools/perf/util/pager.c        |   18 +--
 tools/perf/util/probe-event.c  |    4 +-
 tools/perf/util/sort.h         |    2 +-
 27 files changed, 875 insertions(+), 865 deletions(-)
 create mode 100644 tools/lib/lk/color.c
 create mode 100644 tools/lib/lk/color.h
 create mode 100644 tools/lib/lk/config.c
 create mode 100644 tools/lib/lk/config.h
 delete mode 100644 tools/perf/util/color.c
 delete mode 100644 tools/perf/util/color.h
 create mode 100644 tools/perf/util/config.h
tools/lib/Makefile +3 -0
index 64c0dbd..7acb91d 100644
@@ -10,6 +10,7 @@ LIB_H += lk/util.h
 LIB_H += lk/types.h
 LIB_H += lk/pstack.h
 LIB_H += lk/strbuf.h
+LIB_H += lk/color.h
 
 LIB_OBJS += $(OUTPUT)lk/bitmap.o
 LIB_OBJS += $(OUTPUT)lk/cpumap.o
@@ -20,6 +21,8 @@ LIB_OBJS += $(OUTPUT)lk/util.o
 LIB_OBJS += $(OUTPUT)lk/pstack.o
 LIB_OBJS += $(OUTPUT)lk/strbuf.o
 LIB_OBJS += $(OUTPUT)lk/usage.o
+LIB_OBJS += $(OUTPUT)lk/color.o
+LIB_OBJS += $(OUTPUT)lk/config.o
 
 LIBFILE = lklib.a
 
tools/lib/lk/color.c new file +306 -0

306 lines not on this page · raw message

tools/lib/lk/color.h new file +46 -0

46 lines not on this page · raw message

tools/lib/lk/config.c new file +388 -0

388 lines not on this page · raw message

tools/lib/lk/config.h new file +18 -0
new file mode 100644
index 0000000..6bcce49
@@ -0,0 +1,18 @@
+#ifndef __LK_CONFIG_H
+#define __LK_CONFIG_H
+
+#define DEBUG_CACHE_DIR ".debug"
+
+typedef int (*config_fn_t)(const char *, const char *, void *);
+
+extern const char *lk_config_exclusive_filename;
+
+extern int lk_env_bool(const char *k, int def);
+extern int lk_config_int(const char *, const char *);
+extern int lk_config_bool(const char *name, const char *value);
+extern const char *lk_config_dirname(const char *name, const char *value);
+extern int lk_config_from_file(config_fn_t fn, const char *filename, void *data);
+extern int lk_default_config(const char *, const char *, void *);
+extern int lk_config_error_nonbool(const char *var);
+
+#endif /* __LK_CONFIG_H */
tools/lib/lk/util.h +0 -1
index dc88970..4db0f3f 100644
@@ -172,7 +172,6 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
 
 extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
 
-extern void set_buildid_dir(void);
 extern void disable_buildid_cache(void);
 
 static inline const char *skip_prefix(const char *str, const char *prefix)
tools/perf/Makefile +2 -3
index 6fc4c4a..42a1756 100644
@@ -371,7 +371,6 @@ LIB_H += util/svghelper.h
 LIB_H += util/run-command.h
 LIB_H += util/sigchain.h
 LIB_H += util/symbol.h
-LIB_H += util/color.h
 LIB_H += util/values.h
 LIB_H += util/sort.h
 LIB_H += util/hist.h
@@ -379,11 +378,11 @@ LIB_H += util/thread.h
 LIB_H += util/trace-event.h
 LIB_H += util/probe-finder.h
 LIB_H += util/probe-event.h
+LIB_H += util/config.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
 LIB_OBJS += $(OUTPUT)util/build-id.o
-LIB_OBJS += $(OUTPUT)util/config.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/exec_cmd.o
@@ -400,7 +399,6 @@ LIB_OBJS += $(OUTPUT)util/strlist.o
 LIB_OBJS += $(OUTPUT)util/wrapper.o
 LIB_OBJS += $(OUTPUT)util/sigchain.o
 LIB_OBJS += $(OUTPUT)util/symbol.o
-LIB_OBJS += $(OUTPUT)util/color.o
 LIB_OBJS += $(OUTPUT)util/pager.o
 LIB_OBJS += $(OUTPUT)util/header.o
 LIB_OBJS += $(OUTPUT)util/callchain.o
@@ -417,6 +415,7 @@ LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
 LIB_OBJS += $(OUTPUT)util/hist.o
 LIB_OBJS += $(OUTPUT)util/probe-event.o
+LIB_OBJS += $(OUTPUT)util/config.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 
tools/perf/builtin-annotate.c +2 -2
index 03f80e9..42caf9c 100644
@@ -9,7 +9,7 @@
 
 #include <lk/util.h>
 
-#include "util/color.h"
+#include <lk/color.h>
 #include <linux/list.h>
 #include "util/cache.h"
 #include <linux/rbtree.h>
@@ -130,7 +130,7 @@ static int objdump_line__print(struct objdump_line *self,
 
 		color_fprintf(stdout, color, " %7.2f", percent);
 		printf(" :	");
-		color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", self->line);
+		color_fprintf(stdout, LK_COLOR_BLUE, "%s\n", self->line);
 	} else {
 		if (!*self->line)
 			printf("         :\n");
tools/perf/builtin-help.c +8 -5
index 6d5a8a7..b6b7e1a 100644
@@ -5,6 +5,7 @@
  */
 #include "perf.h"
 #include "util/cache.h"
+#include "util/config.h"
 #include "builtin.h"
 #include "util/exec_cmd.h"
 #include "common-cmds.h"
@@ -12,6 +13,8 @@
 #include "util/run-command.h"
 #include "util/help.h"
 
+#include <lk/config.h>
+
 static struct man_viewer_list {
 	struct man_viewer_list *next;
 	char name[FLEX_ARRAY];
@@ -240,12 +243,12 @@ static int add_man_viewer_info(const char *var, const char *value)
 
 	if (!strcmp(subkey, ".path")) {
 		if (!value)
-			return config_error_nonbool(var);
+			return lk_config_error_nonbool(var);
 		return add_man_viewer_path(name, subkey - name, value);
 	}
 	if (!strcmp(subkey, ".cmd")) {
 		if (!value)
-			return config_error_nonbool(var);
+			return lk_config_error_nonbool(var);
 		return add_man_viewer_cmd(name, subkey - name, value);
 	}
 
@@ -257,20 +260,20 @@ static int perf_help_config(const char *var, const char *value, void *cb)
 {
 	if (!strcmp(var, "help.format")) {
 		if (!value)
-			return config_error_nonbool(var);
+			return lk_config_error_nonbool(var);
 		help_format = parse_help_format(value);
 		return 0;
 	}
 	if (!strcmp(var, "man.viewer")) {
 		if (!value)
-			return config_error_nonbool(var);
+			return lk_config_error_nonbool(var);
 		add_man_viewer(value);
 		return 0;
 	}
 	if (!prefixcmp(var, "man."))
 		return add_man_viewer_info(var, value);
 
-	return perf_default_config(var, value, cb);
+	return lk_default_config(var, value, cb);
 }
 
 static struct cmdnames main_cmds, other_cmds;
tools/perf/builtin-report.c +1 -1
index 4be3c67..9a618ac 100644
@@ -9,7 +9,7 @@
 
 #include <lk/util.h>
 
-#include "util/color.h"
+#include <lk/color.h>
 #include <linux/list.h>
 #include "util/cache.h"
 #include <linux/rbtree.h>
tools/perf/builtin-timechart.c +1 -1
index 92f7230..5440b11 100644
@@ -16,7 +16,7 @@
 
 #include <lk/util.h>
 
-#include "util/color.h"
+#include <lk/color.h>
 #include <linux/list.h>
 #include "util/cache.h"
 #include <linux/rbtree.h>
tools/perf/builtin-top.c +1 -1
index 9813351..2b4dce1 100644
@@ -20,7 +20,7 @@
 
 #include "perf.h"
 
-#include "util/color.h"
+#include <lk/color.h>
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/thread.h"
tools/perf/perf.c +5 -2
index 2fda133..9600a2d 100644
@@ -10,10 +10,13 @@
 
 #include "util/exec_cmd.h"
 #include "util/cache.h"
+#include "util/config.h"
 #include "util/quote.h"
+#include "util/build-id.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
 #include <lk/debugfs.h>
+#include <lk/config.h>
 
 const char perf_usage_string[] =
 	"perf [--version] [--help] COMMAND [ARGS]";
@@ -35,7 +38,7 @@ static int pager_command_config(const char *var, const char *value, void *data)
 {
 	struct pager_config *c = data;
 	if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd))
-		c->val = perf_config_bool(var, value);
+		c->val = lk_config_bool(var, value);
 	return 0;
 }
 
@@ -53,7 +56,7 @@ static int tui_command_config(const char *var, const char *value, void *data)
 {
 	struct pager_config *c = data;
 	if (!prefixcmp(var, "tui.") && !strcmp(var + 4, c->cmd))
-		c->val = perf_config_bool(var, value);
+		c->val = lk_config_bool(var, value);
 	return 0;
 }
 
tools/perf/util/alias.c +3 -1
index b8144e8..57b303a 100644
@@ -1,4 +1,6 @@
 #include "cache.h"
+#include <lk/config.h>
+#include "config.h"
 
 static const char *alias_key;
 static char *alias_val;
@@ -7,7 +9,7 @@ static int alias_lookup_cb(const char *k, const char *v, void *cb __used)
 {
 	if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) {
 		if (!v)
-			return config_error_nonbool(k);
+			return lk_config_error_nonbool(k);
 		alias_val = strdup(v);
 		return 0;
 	}
tools/perf/util/build-id.c +51 -0

60 lines not on this page · raw message

tools/perf/util/build-id.h +2 -0
index 5dafb00..e72ed79 100644
@@ -2,9 +2,11 @@
 #define PERF_BUILD_ID_H_ 1
 
 #include "session.h"
+#include "config.h"
 
 extern struct perf_event_ops build_id__mark_dso_hit_ops;
 
 char *dso__build_id_filename(struct dso *self, char *bf, size_t size);
+extern void set_buildid_dir(void);
 
 #endif
tools/perf/util/cache.h +0 -10
index 93570a8..b0902b8 100644
@@ -17,19 +17,9 @@
 #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
 
-typedef int (*config_fn_t)(const char *, const char *, void *);
-extern int perf_default_config(const char *, const char *, void *);
-extern int perf_config(config_fn_t fn, void *);
-extern int perf_config_int(const char *, const char *);
-extern int perf_config_bool(const char *, const char *);
-extern int config_error_nonbool(const char *);
-extern const char *perf_config_dirname(const char *, const char *);
-
 /* pager.c */
 extern void setup_pager(void);
 extern const char *pager_program;
-extern int pager_in_use(void);
-extern int pager_use_color;
 
 extern int use_browser;
 
tools/perf/util/color.c deleted +0 -324

324 lines not on this page · raw message

tools/perf/util/color.h deleted +0 -46

46 lines not on this page · raw message

tools/perf/util/config.c +14 -446

498 lines not on this page · raw message

tools/perf/util/config.h new file +8 -0
new file mode 100644
index 0000000..120ad69
@@ -0,0 +1,8 @@
+#ifndef __PERF_CONFIG_H
+#define __PERF_CONFIG_H
+
+#include <lk/config.h>
+
+extern int perf_config(config_fn_t fn, void *data);
+
+#endif /* __PERF_CONFIG_H */
tools/perf/util/debug.c +2 -2
index 96cb72a..56635de 100644
@@ -7,10 +7,10 @@
 #include <stdio.h>
 
 #include "cache.h"
-#include "color.h"
 #include "event.h"
 #include "debug.h"
 #include <lk/util.h>
+#include <lk/color.h>
 
 int verbose = 0;
 bool dump_trace = false;
@@ -64,7 +64,7 @@ static int dump_printf_color(const char *fmt, const char *color, ...)
 void trace_event(event_t *event)
 {
 	unsigned char *raw_event = (void *)event;
-	const char *color = PERF_COLOR_BLUE;
+	const char *color = LK_COLOR_BLUE;
 	int i, j;
 
 	if (!dump_trace)
tools/perf/util/environment.c +1 -2
index 275b0ee..bd61953 100644
@@ -3,7 +3,6 @@
  * file, so that programs can link against the config parser
  * without having to link against all the rest of perf.
  */
-#include "cache.h"
+#include <lk/color.h>
 
 const char *pager_program;
-int pager_use_color = 1;
tools/perf/util/help.c +5 -2
index 6f2975a..109ebc8 100644
@@ -3,6 +3,9 @@
 #include "exec_cmd.h"
 #include "levenshtein.h"
 #include "help.h"
+#include "config.h"
+
+#include <lk/config.h>
 
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
@@ -237,12 +240,12 @@ static struct cmdnames aliases;
 static int perf_unknown_cmd_config(const char *var, const char *value, void *cb)
 {
 	if (!strcmp(var, "help.autocorrect"))
-		autocorrect = perf_config_int(var,value);
+		autocorrect = lk_config_int(var,value);
 	/* Also use aliases for command lookup */
 	if (!prefixcmp(var, "alias."))
 		add_cmdname(&aliases, var + 6, strlen(var + 6));
 
-	return perf_default_config(var, value, cb);
+	return lk_default_config(var, value, cb);
 }
 
 static int levenshtein_compare(const void *p1, const void *p2)
tools/perf/util/pager.c +5 -13
index 1915de2..7afdad7 100644
@@ -1,4 +1,8 @@
+#include <lk/config.h>
+#include <lk/color.h>
+
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "sigchain.h"
 
@@ -7,7 +11,6 @@
  * something different on Windows.
  */
 
-static int spawned_pager;
 
 static void pager_preexec(void)
 {
@@ -52,7 +55,7 @@ void setup_pager(void)
 		return;
 	if (!pager) {
 		if (!pager_program)
-			perf_config(perf_default_config, NULL);
+			perf_config(lk_default_config, NULL);
 		pager = pager_program;
 	}
 	if (!pager)
@@ -83,14 +86,3 @@ void setup_pager(void)
 	sigchain_push_common(wait_for_pager_signal);
 	atexit(wait_for_pager);
 }
-
-int pager_in_use(void)
-{
-	const char *env;
-
-	if (spawned_pager)
-		return 1;
-
-	env = getenv("PERF_PAGER_IN_USE");
-	return env ? perf_config_bool("PERF_PAGER_IN_USE", env) : 0;
-}
tools/perf/util/probe-event.c +2 -2
index 723b10d..74efa4a 100644
@@ -39,7 +39,7 @@
 #include "strlist.h"
 #include "debug.h"
 #include "cache.h"
-#include "color.h"
+#include <lk/color.h>
 #include "symbol.h"
 #include "thread.h"
 #include <lk/debugfs.h>
@@ -201,7 +201,7 @@ static int try_to_find_kprobe_trace_events(struct perf_probe_event *pev,
 static int show_one_line(FILE *fp, int l, bool skip, bool show_num)
 {
 	char buf[LINEBUF_SIZE];
-	const char *color = PERF_COLOR_BLUE;
+	const char *color = LK_COLOR_BLUE;
 
 	if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
 		goto error;
tools/perf/util/sort.h +1 -1
index 8ead949..4dd264a 100644
@@ -4,7 +4,7 @@
 
 #include <lk/util.h>
 
-#include "color.h"
+#include <lk/color.h>
 #include <linux/list.h>
 #include "cache.h"
 #include <linux/rbtree.h>
Signature · 1 line
1.7.1
#9 lore raw

PATCH 9/21 perf: rewire generic library stuff, p5

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Carve out debug.[ch] and string.c and make them generic.

---
 tools/lib/Makefile                       |    3 +
 tools/lib/lk/debug.c                     |  108 +++++++++++
 tools/lib/lk/debug.h                     |   50 +++++
 tools/lib/lk/pstack.c                    |    2 +-
 tools/lib/lk/string.c                    |  296 ++++++++++++++++++++++++++++++
 tools/lib/lk/util.h                      |    2 +-
 tools/perf/Makefile                      |    3 -
 tools/perf/bench/mem-memcpy.c            |    2 +-
 tools/perf/builtin-annotate.c            |    2 +-
 tools/perf/builtin-buildid-cache.c       |    2 +-
 tools/perf/builtin-buildid-list.c        |    2 +-
 tools/perf/builtin-diff.c                |    2 +-
 tools/perf/builtin-inject.c              |    2 +-
 tools/perf/builtin-kmem.c                |    2 +-
 tools/perf/builtin-kvm.c                 |    2 +-
 tools/perf/builtin-lock.c                |    2 +-
 tools/perf/builtin-probe.c               |    2 +-
 tools/perf/builtin-record.c              |    2 +-
 tools/perf/builtin-report.c              |    2 +-
 tools/perf/builtin-sched.c               |    2 +-
 tools/perf/builtin-stat.c                |    2 +-
 tools/perf/builtin-test.c                |    2 +-
 tools/perf/builtin-timechart.c           |    2 +-
 tools/perf/builtin-top.c                 |    2 +-
 tools/perf/builtin-trace.c               |    3 +-
 tools/perf/perf.c                        |    2 +-
 tools/perf/util/build-id.c               |    1 +
 tools/perf/util/cache.h                  |    2 -
 tools/perf/util/callchain.c              |    1 +
 tools/perf/util/debug.c                  |   98 ----------
 tools/perf/util/debug.h                  |   39 ----
 tools/perf/util/event.c                  |    2 +-
 tools/perf/util/header.c                 |    2 +-
 tools/perf/util/include/linux/compiler.h |    1 +
 tools/perf/util/include/linux/kernel.h   |    3 -
 tools/perf/util/map.c                    |   32 ++--
 tools/perf/util/newt.c                   |    2 +-
 tools/perf/util/parse-events.c           |    1 +
 tools/perf/util/probe-event.c            |    2 +-
 tools/perf/util/probe-finder.c           |    2 +-
 tools/perf/util/sort.h                   |    2 +-
 tools/perf/util/string.c                 |  296 ------------------------------
 tools/perf/util/symbol.c                 |    2 +
 tools/perf/util/thread.c                 |    2 +-
 44 files changed, 509 insertions(+), 484 deletions(-)
 create mode 100644 tools/lib/lk/debug.c
 create mode 100644 tools/lib/lk/debug.h
 create mode 100644 tools/lib/lk/string.c
 delete mode 100644 tools/perf/util/debug.c
 delete mode 100644 tools/perf/util/debug.h
 delete mode 100644 tools/perf/util/string.c
tools/lib/Makefile +3 -0
index 7acb91d..df60156 100644
@@ -11,6 +11,7 @@ LIB_H += lk/types.h
 LIB_H += lk/pstack.h
 LIB_H += lk/strbuf.h
 LIB_H += lk/color.h
+LIB_H += lk/debug.h
 
 LIB_OBJS += $(OUTPUT)lk/bitmap.o
 LIB_OBJS += $(OUTPUT)lk/cpumap.o
@@ -23,6 +24,8 @@ LIB_OBJS += $(OUTPUT)lk/strbuf.o
 LIB_OBJS += $(OUTPUT)lk/usage.o
 LIB_OBJS += $(OUTPUT)lk/color.o
 LIB_OBJS += $(OUTPUT)lk/config.o
+LIB_OBJS += $(OUTPUT)lk/debug.o
+LIB_OBJS += $(OUTPUT)lk/string.o
 
 LIBFILE = lklib.a
 
tools/lib/lk/debug.c new file +108 -0

108 lines not on this page · raw message

tools/lib/lk/debug.h new file +50 -0

50 lines not on this page · raw message

tools/lib/lk/pstack.c +1 -1
index 13d36fa..acb758b 100644
@@ -5,8 +5,8 @@
  */
 
 #include "util.h"
+#include "debug.h"
 #include "pstack.h"
-#include <linux/kernel.h>
 #include <stdlib.h>
 
 struct pstack {
tools/lib/lk/string.c new file +296 -0

296 lines not on this page · raw message

tools/lib/lk/util.h +1 -1
index 4db0f3f..ec87421 100644
@@ -277,7 +277,7 @@ static inline int sane_case(int x, int high)
 int mkdir_p(char *path, mode_t mode);
 int copyfile(const char *from, const char *to);
 
-s64 perf_atoll(const char *str);
+s64 lk_atoll(const char *str);
 char **argv_split(const char *str, int *argcp);
 void argv_free(char **argv);
 bool strglobmatch(const char *str, const char *pat);
tools/perf/Makefile +0 -3
index 42a1756..8770ff4 100644
@@ -355,7 +355,6 @@ LIB_H += perf.h
 LIB_H += util/cache.h
 LIB_H += util/callchain.h
 LIB_H += util/build-id.h
-LIB_H += util/debug.h
 LIB_H += util/event.h
 LIB_H += util/exec_cmd.h
 LIB_H += util/levenshtein.h
@@ -394,7 +393,6 @@ LIB_OBJS += $(OUTPUT)util/path.o
 LIB_OBJS += $(OUTPUT)util/rbtree.o
 LIB_OBJS += $(OUTPUT)util/run-command.o
 LIB_OBJS += $(OUTPUT)util/quote.o
-LIB_OBJS += $(OUTPUT)util/string.o
 LIB_OBJS += $(OUTPUT)util/strlist.o
 LIB_OBJS += $(OUTPUT)util/wrapper.o
 LIB_OBJS += $(OUTPUT)util/sigchain.o
@@ -403,7 +401,6 @@ LIB_OBJS += $(OUTPUT)util/pager.o
 LIB_OBJS += $(OUTPUT)util/header.o
 LIB_OBJS += $(OUTPUT)util/callchain.o
 LIB_OBJS += $(OUTPUT)util/values.o
-LIB_OBJS += $(OUTPUT)util/debug.o
 LIB_OBJS += $(OUTPUT)util/map.o
 LIB_OBJS += $(OUTPUT)util/session.o
 LIB_OBJS += $(OUTPUT)util/thread.o
tools/perf/bench/mem-memcpy.c +1 -1
index 1b2f508..86db09e 100644
@@ -105,7 +105,7 @@ int bench_mem_memcpy(int argc, const char **argv,
 
 	tv_diff.tv_sec = 0;
 	tv_diff.tv_usec = 0;
-	length = (size_t)perf_atoll((char *)length_str);
+	length = (size_t)lk_atoll((char *)length_str);
 
 	if ((s64)length <= 0) {
 		fprintf(stderr, "Invalid length:%s\n", length_str);
tools/perf/builtin-annotate.c +1 -1
index 42caf9c..04afd8a 100644
@@ -16,7 +16,7 @@
 #include "util/symbol.h"
 
 #include "perf.h"
-#include "util/debug.h"
+#include <lk/debug.h>
 
 #include "util/event.h"
 #include "util/parse-options.h"
tools/perf/builtin-buildid-cache.c +1 -1
index 29ad20e..5621017 100644
@@ -9,7 +9,7 @@
 #include "builtin.h"
 #include "perf.h"
 #include "util/cache.h"
-#include "util/debug.h"
+#include <lk/debug.h>
 #include "util/header.h"
 #include "util/parse-options.h"
 #include "util/strlist.h"
tools/perf/builtin-buildid-list.c +1 -1
index 9989072..b767dde 100644
@@ -10,7 +10,7 @@
 #include "perf.h"
 #include "util/build-id.h"
 #include "util/cache.h"
-#include "util/debug.h"
+#include <lk/debug.h>
 #include "util/parse-options.h"
 #include "util/session.h"
 #include "util/symbol.h"
tools/perf/builtin-diff.c +1 -1
index 2f5a711..b346e7f 100644
@@ -6,7 +6,7 @@
  */
 #include "builtin.h"
 
-#include "util/debug.h"
+#include <lk/debug.h>
 #include "util/event.h"
 #include "util/hist.h"
 #include "util/session.h"
tools/perf/builtin-inject.c +1 -1
index 8e3e47b..c9127a9 100644
@@ -9,7 +9,7 @@
 
 #include "perf.h"
 #include "util/session.h"
-#include "util/debug.h"
+#include <lk/debug.h>
 
 #include "util/parse-options.h"
 
tools/perf/builtin-kmem.c +1 -1
index 68a6ec0..a31c848 100644
@@ -11,7 +11,7 @@
 #include "util/parse-options.h"
 #include "util/trace-event.h"
 
-#include "util/debug.h"
+#include <lk/debug.h>
 
 #include <linux/rbtree.h>
 
tools/perf/builtin-kvm.c +1 -1
index 3e5d0fc..173dd9f 100644
@@ -11,7 +11,7 @@
 #include "util/parse-options.h"
 #include "util/trace-event.h"
 
-#include "util/debug.h"
+#include <lk/debug.h>
 
 #include <sys/prctl.h>
 
tools/perf/builtin-lock.c +1 -1
index bafb8c5..80327f1 100644
@@ -10,7 +10,7 @@
 #include "util/parse-options.h"
 #include "util/trace-event.h"
 
-#include "util/debug.h"
+#include <lk/debug.h>
 #include "util/session.h"
 
 #include <sys/types.h>
tools/perf/builtin-probe.c +1 -1
index be24b54..8679663 100644
@@ -37,7 +37,7 @@
 #include <lk/util.h>
 #include "util/strlist.h"
 #include "util/symbol.h"
-#include "util/debug.h"
+#include <lk/debug.h>
 #include <lk/debugfs.h>
 #include "util/parse-options.h"
 #include "util/probe-finder.h"
tools/perf/builtin-record.c +1 -1
index b92e009..1dee3a0 100644
@@ -18,7 +18,7 @@
 
 #include "util/header.h"
 #include "util/event.h"
-#include "util/debug.h"
+#include <lk/debug.h>
 #include "util/session.h"
 #include "util/symbol.h"
 #include <lk/cpumap.h>
tools/perf/builtin-report.c +1 -1
index 9a618ac..e87180f 100644
@@ -19,7 +19,7 @@
 #include "util/values.h"
 
 #include "perf.h"
-#include "util/debug.h"
+#include <lk/debug.h>
 #include "util/header.h"
 #include "util/session.h"
 
tools/perf/builtin-sched.c +1 -1
index c47cf08..6bbc31a 100644
@@ -11,7 +11,7 @@
 #include "util/parse-options.h"
 #include "util/trace-event.h"
 
-#include "util/debug.h"
+#include <lk/debug.h>
 
 #include <sys/prctl.h>
 
tools/perf/builtin-stat.c +1 -1
index 1f60239..b4cc93e 100644
@@ -43,7 +43,7 @@
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 #include "util/event.h"
-#include "util/debug.h"
+#include <lk/debug.h>
 #include "util/header.h"
 #include <lk/cpumap.h>
 #include "util/thread.h"
tools/perf/builtin-test.c +1 -1
index 035b9fa..1be7ad9 100644
@@ -6,7 +6,7 @@
 #include "builtin.h"
 
 #include "util/cache.h"
-#include "util/debug.h"
+#include <lk/debug.h>
 #include "util/parse-options.h"
 #include "util/session.h"
 #include "util/symbol.h"
tools/perf/builtin-timechart.c +1 -1
index 5440b11..c90a68f 100644
@@ -15,7 +15,7 @@
 #include "builtin.h"
 
 #include <lk/util.h>
-
+#include <lk/debug.h>
 #include <lk/color.h>
 #include <linux/list.h>
 #include "util/cache.h"
tools/perf/builtin-top.c +1 -1
index 2b4dce1..e402ba4 100644
@@ -30,7 +30,7 @@
 #include "util/parse-events.h"
 #include <lk/cpumap.h>
 
-#include "util/debug.h"
+#include <lk/debug.h>
 
 #include <assert.h>
 #include <fcntl.h>
tools/perf/builtin-trace.c +2 -1
index 3f9308a..be67b73 100644
@@ -1,6 +1,7 @@
 #include "builtin.h"
 
 #include <lk/util.h>
+#include <lk/debug.h>
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
@@ -61,7 +62,7 @@ static int cleanup_scripting(void)
 #include "util/parse-options.h"
 
 #include "perf.h"
-#include "util/debug.h"
+#include <lk/debug.h>
 
 #include "util/trace-event.h"
 #include "util/exec_cmd.h"
tools/perf/perf.c +1 -1
index 9600a2d..b92b3fd 100644
@@ -17,6 +17,7 @@
 #include "util/parse-events.h"
 #include <lk/debugfs.h>
 #include <lk/config.h>
+#include <lk/debug.h>
 
 const char perf_usage_string[] =
 	"perf [--version] [--help] COMMAND [ARGS]";
@@ -24,7 +25,6 @@ const char perf_usage_string[] =
 const char perf_more_info_string[] =
 	"See 'perf help COMMAND' for more information on a specific command.";
 
-int use_browser = -1;
 static int use_pager = -1;
 
 struct pager_config {
tools/perf/util/build-id.c +1 -0
index 44f2878..a338745 100644
@@ -7,6 +7,7 @@
  * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <[email protected]>
  */
 #include <lk/util.h>
+#include <lk/debug.h>
 #include <lk/config.h>
 #include <lk/strbuf.h>
 #include <stdio.h>
tools/perf/util/cache.h +0 -2
index b0902b8..4ae67b4 100644
@@ -21,8 +21,6 @@
 extern void setup_pager(void);
 extern const char *pager_program;
 
-extern int use_browser;
-
 #ifdef NO_NEWT_SUPPORT
 static inline void setup_browser(void)
 {
tools/perf/util/callchain.c +1 -0
index a6c99a3..dcc0254 100644
@@ -16,6 +16,7 @@
 #include <math.h>
 
 #include <lk/util.h>
+#include <lk/debug.h>
 #include "callchain.h"
 
 bool ip_callchain__valid(struct ip_callchain *chain, const event_t *event)
tools/perf/util/debug.c deleted +0 -98

98 lines not on this page · raw message

tools/perf/util/debug.h deleted +0 -39
deleted file mode 100644
index 047ac33..0000000
@@ -1,39 +0,0 @@
-/* For debugging general purposes */
-#ifndef __PERF_DEBUG_H
-#define __PERF_DEBUG_H
-
-#include <stdbool.h>
-#include "event.h"
-
-extern int verbose;
-extern bool dump_trace;
-
-int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
-void trace_event(event_t *event);
-
-struct ui_progress;
-
-#ifdef NO_NEWT_SUPPORT
-static inline int browser__show_help(const char *format __used, va_list ap __used)
-{
-	return 0;
-}
-
-static inline struct ui_progress *ui_progress__new(const char *title __used,
-						   u64 total __used)
-{
-	return (struct ui_progress *)1;
-}
-
-static inline void ui_progress__update(struct ui_progress *self __used,
-				       u64 curr __used) {}
-
-static inline void ui_progress__delete(struct ui_progress *self __used) {}
-#else
-int browser__show_help(const char *format, va_list ap);
-struct ui_progress *ui_progress__new(const char *title, u64 total);
-void ui_progress__update(struct ui_progress *self, u64 curr);
-void ui_progress__delete(struct ui_progress *self);
-#endif
-
-#endif	/* __PERF_DEBUG_H */
tools/perf/util/event.c +1 -1
index a746086..928d3de 100644
@@ -1,6 +1,6 @@
 #include <linux/types.h>
 #include "event.h"
-#include "debug.h"
+#include <lk/debug.h>
 #include "session.h"
 #include "sort.h"
 #include "string.h"
tools/perf/util/header.c +1 -1
index 0ebd301..2177cfb 100644
@@ -14,7 +14,7 @@
 #include "trace-event.h"
 #include "session.h"
 #include "symbol.h"
-#include "debug.h"
+#include <lk/debug.h>
 
 static bool no_buildid_cache = false;
 
tools/perf/util/include/linux/compiler.h +1 -0
index 791f9dd..8a9ca88 100644
@@ -8,5 +8,6 @@
 #define __attribute_const__
 
 #define __used		__attribute__((__unused__))
+#define __weak         __attribute__((weak))
 
 #endif
tools/perf/util/include/linux/kernel.h +0 -3
index 1eb804f..614bb72 100644
@@ -87,9 +87,6 @@ simple_strtoul(const char *nptr, char **endptr, int base)
 	return strtoul(nptr, endptr, base);
 }
 
-int eprintf(int level,
-	    const char *fmt, ...) __attribute__((format(printf, 2, 3)));
-
 #ifndef pr_fmt
 #define pr_fmt(fmt) fmt
 #endif
tools/perf/util/map.c +17 -15
index e672f2f..fa82eba 100644
@@ -5,6 +5,8 @@
 #include <string.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <lk/debug.h>
+
 #include "map.h"
 
 const char *map_type__name[MAP__NR_TYPES] = {
@@ -309,7 +311,7 @@ struct symbol *map_groups__find_symbol_by_name(struct map_groups *self,
 }
 
 size_t __map_groups__fprintf_maps(struct map_groups *self,
-				  enum map_type type, int verbose, FILE *fp)
+				  enum map_type type, int _verbose, FILE *fp)
 {
 	size_t printed = fprintf(fp, "%s:\n", map_type__name[type]);
 	struct rb_node *nd;
@@ -318,7 +320,7 @@ size_t __map_groups__fprintf_maps(struct map_groups *self,
 		struct map *pos = rb_entry(nd, struct map, rb_node);
 		printed += fprintf(fp, "Map:");
 		printed += map__fprintf(pos, fp);
-		if (verbose > 2) {
+		if (_verbose > 2) {
 			printed += dso__fprintf(pos->dso, type, fp);
 			printed += fprintf(fp, "--\n");
 		}
@@ -327,17 +329,17 @@ size_t __map_groups__fprintf_maps(struct map_groups *self,
 	return printed;
 }
 
-size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp)
+size_t map_groups__fprintf_maps(struct map_groups *self, int _verbose, FILE *fp)
 {
 	size_t printed = 0, i;
 	for (i = 0; i < MAP__NR_TYPES; ++i)
-		printed += __map_groups__fprintf_maps(self, i, verbose, fp);
+		printed += __map_groups__fprintf_maps(self, i, _verbose, fp);
 	return printed;
 }
 
 static size_t __map_groups__fprintf_removed_maps(struct map_groups *self,
 						 enum map_type type,
-						 int verbose, FILE *fp)
+						 int _verbose, FILE *fp)
 {
 	struct map *pos;
 	size_t printed = 0;
@@ -345,7 +347,7 @@ static size_t __map_groups__fprintf_removed_maps(struct map_groups *self,
 	list_for_each_entry(pos, &self->removed_maps[type], node) {
 		printed += fprintf(fp, "Map:");
 		printed += map__fprintf(pos, fp);
-		if (verbose > 1) {
+		if (_verbose > 1) {
 			printed += dso__fprintf(pos->dso, type, fp);
 			printed += fprintf(fp, "--\n");
 		}
@@ -354,23 +356,23 @@ static size_t __map_groups__fprintf_removed_maps(struct map_groups *self,
 }
 
 static size_t map_groups__fprintf_removed_maps(struct map_groups *self,
-					       int verbose, FILE *fp)
+					       int _verbose, FILE *fp)
 {
 	size_t printed = 0, i;
 	for (i = 0; i < MAP__NR_TYPES; ++i)
-		printed += __map_groups__fprintf_removed_maps(self, i, verbose, fp);
+		printed += __map_groups__fprintf_removed_maps(self, i, _verbose, fp);
 	return printed;
 }
 
-size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp)
+size_t map_groups__fprintf(struct map_groups *self, int _verbose, FILE *fp)
 {
-	size_t printed = map_groups__fprintf_maps(self, verbose, fp);
+	size_t printed = map_groups__fprintf_maps(self, _verbose, fp);
 	printed += fprintf(fp, "Removed maps:\n");
-	return printed + map_groups__fprintf_removed_maps(self, verbose, fp);
+	return printed + map_groups__fprintf_removed_maps(self, _verbose, fp);
 }
 
 int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
-				   int verbose, FILE *fp)
+				   int _verbose, FILE *fp)
 {
 	struct rb_root *root = &self->maps[map->type];
 	struct rb_node *next = rb_first(root);
@@ -382,7 +384,7 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
 		if (!map__overlap(pos, map))
 			continue;
 
-		if (verbose >= 2) {
+		if (_verbose >= 2) {
 			fputs("overlapping maps:\n", fp);
 			map__fprintf(map, fp);
 			map__fprintf(pos, fp);
@@ -407,7 +409,7 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
 
 			before->end = map->start - 1;
 			map_groups__insert(self, before);
-			if (verbose >= 2)
+			if (_verbose >= 2)
 				map__fprintf(before, fp);
 		}
 
@@ -419,7 +421,7 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
 
 			after->start = map->end + 1;
 			map_groups__insert(self, after);
-			if (verbose >= 2)
+			if (_verbose >= 2)
 				map__fprintf(after, fp);
 		}
 	}
tools/perf/util/newt.c +1 -1
index cf182ca..3918f22 100644
@@ -117,7 +117,7 @@ static void ui_helpline__puts(const char *msg)
 
 static char browser__last_msg[1024];
 
-int browser__show_help(const char *format, va_list ap)
+int _browser__show_help(const char *format, va_list ap)
 {
 	int ret;
 	static int backlog;
tools/perf/util/parse-events.c +1 -0
index 3a76c8e..f298a43 100644
@@ -1,5 +1,6 @@
 #include "../../../include/linux/hw_breakpoint.h"
 #include <lk/util.h>
+#include <lk/debug.h>
 #include "../perf.h"
 #include "parse-options.h"
 #include "parse-events.h"
tools/perf/util/probe-event.c +1 -1
index 74efa4a..c33e17d 100644
@@ -37,7 +37,7 @@
 #include "event.h"
 #include "string.h"
 #include "strlist.h"
-#include "debug.h"
+#include <lk/debug.h>
 #include "cache.h"
 #include <lk/color.h>
 #include "symbol.h"
tools/perf/util/probe-finder.c +1 -1
index eb4eb26..8ac178d 100644
@@ -35,7 +35,7 @@
 
 #include "string.h"
 #include "event.h"
-#include "debug.h"
+#include <lk/debug.h>
 #include <lk/util.h>
 #include "symbol.h"
 #include "probe-finder.h"
tools/perf/util/sort.h +1 -1
index 4dd264a..174b9c1 100644
@@ -15,7 +15,7 @@
 #include "values.h"
 
 #include "../perf.h"
-#include "debug.h"
+#include <lk/debug.h>
 #include "header.h"
 
 #include "parse-options.h"
tools/perf/util/string.c deleted +0 -296

296 lines not on this page · raw message

tools/perf/util/symbol.c +2 -0
index 971d0a0..7012560 100644
@@ -21,6 +21,8 @@
 #include <limits.h>
 #include <sys/utsname.h>
 
+#include <lk/debug.h>
+
 #ifndef NT_GNU_BUILD_ID
 #define NT_GNU_BUILD_ID 3
 #endif
tools/perf/util/thread.c +1 -1
index deb30a8..c2652fd 100644
@@ -5,7 +5,7 @@
 #include "session.h"
 #include "thread.h"
 #include <lk/util.h>
-#include "debug.h"
+#include <lk/debug.h>
 
 int find_all_tid(int pid, pid_t ** all_tid)
 {
Signature · 1 line
1.7.1
#10 lore raw

PATCH 10/21 perf: rewire generic library stuff, p6

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Carve out strlist.[ch] and rbtree.c and make them generic.

---
 tools/lib/Makefile                 |    6 +
 tools/lib/lk/strlist.c             |  200 ++++++++++++++++++++++++++++++++++++
 tools/lib/lk/strlist.h             |   78 ++++++++++++++
 tools/perf/Makefile                |    6 -
 tools/perf/builtin-buildid-cache.c |    2 +-
 tools/perf/builtin-probe.c         |    2 +-
 tools/perf/builtin-report.c        |    2 +-
 tools/perf/builtin-timechart.c     |    2 +-
 tools/perf/util/event.c            |    2 +-
 tools/perf/util/probe-event.c      |    2 +-
 tools/perf/util/probe-event.h      |    2 +-
 tools/perf/util/sort.h             |    2 +-
 tools/perf/util/strlist.c          |  200 ------------------------------------
 tools/perf/util/strlist.h          |   78 --------------
 tools/perf/util/symbol.c           |    2 +-
 15 files changed, 293 insertions(+), 293 deletions(-)
 create mode 100644 tools/lib/lk/strlist.c
 create mode 100644 tools/lib/lk/strlist.h
 delete mode 100644 tools/perf/util/strlist.c
 delete mode 100644 tools/perf/util/strlist.h
tools/lib/Makefile +6 -0
index df60156..818be02 100644
@@ -12,6 +12,7 @@ LIB_H += lk/pstack.h
 LIB_H += lk/strbuf.h
 LIB_H += lk/color.h
 LIB_H += lk/debug.h
+LIB_H += lk/strlist.h
 
 LIB_OBJS += $(OUTPUT)lk/bitmap.o
 LIB_OBJS += $(OUTPUT)lk/cpumap.o
@@ -26,6 +27,8 @@ LIB_OBJS += $(OUTPUT)lk/color.o
 LIB_OBJS += $(OUTPUT)lk/config.o
 LIB_OBJS += $(OUTPUT)lk/debug.o
 LIB_OBJS += $(OUTPUT)lk/string.o
+LIB_OBJS += $(OUTPUT)lk/rbtree.o
+LIB_OBJS += $(OUTPUT)lk/strlist.o
 
 LIBFILE = lklib.a
 
@@ -42,6 +45,9 @@ $(LIBFILE): $(LIB_OBJS)
 
 $(LIB_OBJS): $(LIB_H)
 
+$(OUTPUT)lk/rbtree.o: ../../lib/rbtree.c
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+
 $(OUTPUT)%.o: %.c
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
 $(OUTPUT)%.s: %.c
tools/lib/lk/strlist.c new file +200 -0

200 lines not on this page · raw message

tools/lib/lk/strlist.h new file +78 -0

78 lines not on this page · raw message

tools/perf/Makefile +0 -6
index 8770ff4..65a8a7b 100644
@@ -365,7 +365,6 @@ LIB_H += util/quote.h
 LIB_H += util/header.h
 LIB_H += util/help.h
 LIB_H += util/session.h
-LIB_H += util/strlist.h
 LIB_H += util/svghelper.h
 LIB_H += util/run-command.h
 LIB_H += util/sigchain.h
@@ -390,10 +389,8 @@ LIB_OBJS += $(OUTPUT)util/levenshtein.o
 LIB_OBJS += $(OUTPUT)util/parse-options.o
 LIB_OBJS += $(OUTPUT)util/parse-events.o
 LIB_OBJS += $(OUTPUT)util/path.o
-LIB_OBJS += $(OUTPUT)util/rbtree.o
 LIB_OBJS += $(OUTPUT)util/run-command.o
 LIB_OBJS += $(OUTPUT)util/quote.o
-LIB_OBJS += $(OUTPUT)util/strlist.o
 LIB_OBJS += $(OUTPUT)util/wrapper.o
 LIB_OBJS += $(OUTPUT)util/sigchain.o
 LIB_OBJS += $(OUTPUT)util/symbol.o
@@ -921,9 +918,6 @@ $(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)util/newt.o: util/newt.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
 
-$(OUTPUT)util/rbtree.o: ../../lib/rbtree.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 $<
 
tools/perf/builtin-buildid-cache.c +1 -1
index 5621017..3cac2d6 100644
@@ -12,7 +12,7 @@
 #include <lk/debug.h>
 #include "util/header.h"
 #include "util/parse-options.h"
-#include "util/strlist.h"
+#include <lk/strlist.h>
 #include "util/symbol.h"
 
 static char const *add_name_list_str, *remove_name_list_str;
tools/perf/builtin-probe.c +1 -1
index 8679663..f53edba 100644
@@ -35,7 +35,7 @@
 #include "perf.h"
 #include "builtin.h"
 #include <lk/util.h>
-#include "util/strlist.h"
+#include <lk/strlist.h>
 #include "util/symbol.h"
 #include <lk/debug.h>
 #include <lk/debugfs.h>
tools/perf/builtin-report.c +1 -1
index e87180f..57fe707 100644
@@ -15,7 +15,7 @@
 #include <linux/rbtree.h>
 #include "util/symbol.h"
 #include "util/callchain.h"
-#include "util/strlist.h"
+#include <lk/strlist.h>
 #include "util/values.h"
 
 #include "perf.h"
tools/perf/builtin-timechart.c +1 -1
index c90a68f..6e2dd8f 100644
@@ -22,7 +22,7 @@
 #include <linux/rbtree.h>
 #include "util/symbol.h"
 #include "util/callchain.h"
-#include "util/strlist.h"
+#include <lk/strlist.h>
 
 #include "perf.h"
 #include "util/header.h"
tools/perf/util/event.c +1 -1
index 928d3de..fda3406 100644
@@ -4,7 +4,7 @@
 #include "session.h"
 #include "sort.h"
 #include "string.h"
-#include "strlist.h"
+#include <lk/strlist.h>
 #include "thread.h"
 
 const char *event__name[] = {
tools/perf/util/probe-event.c +1 -1
index c33e17d..26f29ca 100644
@@ -36,7 +36,7 @@
 #include <lk/util.h>
 #include "event.h"
 #include "string.h"
-#include "strlist.h"
+#include <lk/strlist.h>
 #include <lk/debug.h>
 #include "cache.h"
 #include <lk/color.h>
tools/perf/util/probe-event.h +1 -1
index e9db1a2..22a6f17 100644
@@ -2,7 +2,7 @@
 #define _PROBE_EVENT_H
 
 #include <stdbool.h>
-#include "strlist.h"
+#include <lk/strlist.h>
 
 extern bool probe_event_dry_run;
 
tools/perf/util/sort.h +1 -1
index 174b9c1..7a266b8 100644
@@ -11,7 +11,7 @@
 #include "symbol.h"
 #include "string.h"
 #include "callchain.h"
-#include "strlist.h"
+#include <lk/strlist.h>
 #include "values.h"
 
 #include "../perf.h"
tools/perf/util/strlist.c deleted +0 -200

200 lines not on this page · raw message

tools/perf/util/strlist.h deleted +0 -78

78 lines not on this page · raw message

tools/perf/util/symbol.c +1 -1
index 7012560..edd8202 100644
@@ -13,7 +13,7 @@
 #include <unistd.h>
 #include "build-id.h"
 #include "symbol.h"
-#include "strlist.h"
+#include <lk/strlist.h>
 
 #include <libelf.h>
 #include <gelf.h>
Signature · 1 line
1.7.1
#11 lore raw

PATCH 11/21 perf: Export /proc/mounts parser

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Carve out relevant debugfs setup utils for general use.

---
 tools/lib/lk/debugfs.c         |   25 +++++++++++++++++++++++++
 tools/lib/lk/debugfs.h         |    5 +++++
 tools/perf/perf.c              |   27 ++++-----------------------
 tools/perf/util/parse-events.c |    2 --
 tools/perf/util/parse-events.h |    1 -
 5 files changed, 34 insertions(+), 26 deletions(-)
tools/lib/lk/debugfs.c +25 -0
index bbe3a83..8ef3fa6 100644
@@ -3,6 +3,8 @@
 
 static int debugfs_premounted;
 static char debugfs_mountpoint[MAX_PATH+1];
+char debugfs_mntpt[MAXPATHLEN];
+char debugfs_path[MAXPATHLEN];
 
 static const char *debugfs_known_mountpoints[] = {
 	"/sys/kernel/debug/",
@@ -237,3 +239,26 @@ int debugfs_read(const char *entry, char *buffer, size_t size)
 	/* return the number of chars read */
 	return ret;
 }
+
+void set_debugfs_path(void)
+{
+	char *path;
+
+	path = getenv(PERF_DEBUGFS_ENVIRONMENT);
+	snprintf(debugfs_path, MAXPATHLEN, "%s/%s", path ?: debugfs_mntpt,
+		 "tracing/events");
+}
+
+/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
+int get_debugfs_mntpt(void)
+{
+	const char *path = debugfs_mount(NULL);
+
+	if (path) {
+		strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
+		return 0;
+	}
+
+	debugfs_mntpt[0] = '\0';
+	return 1;
+}
tools/lib/lk/debugfs.h +5 -0
index 8c02e72..1187fa8 100644
@@ -14,6 +14,9 @@
 
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 
+extern char debugfs_path[];
+extern char debugfs_mntpt[];
+
 extern const char *debugfs_find_mountpoint(void);
 extern int debugfs_valid_mountpoint(const char *debugfs);
 extern int debugfs_valid_entry(const char *path);
@@ -23,5 +26,7 @@ extern int debugfs_write(const char *entry, const char *value);
 extern int debugfs_read(const char *entry, char *buffer, size_t size);
 extern void debugfs_force_cleanup(void);
 extern int debugfs_make_path(const char *element, char *buffer, int size);
+extern int get_debugfs_mntpt(void);
+extern void set_debugfs_path(void);
 
 #endif /* __DEBUGFS_H__ */
tools/perf/perf.c +4 -23
index b92b3fd..58c1a56 100644
@@ -32,8 +32,6 @@ struct pager_config {
 	int val;
 };
 
-static char debugfs_mntpt[MAXPATHLEN];
-
 static int pager_command_config(const char *var, const char *value, void *data)
 {
 	struct pager_config *c = data;
@@ -84,15 +82,6 @@ static void commit_pager_choice(void)
 	}
 }
 
-static void set_debugfs_path(void)
-{
-	char *path;
-
-	path = getenv(PERF_DEBUGFS_ENVIRONMENT);
-	snprintf(debugfs_path, MAXPATHLEN, "%s/%s", path ?: debugfs_mntpt,
-		 "tracing/events");
-}
-
 static int handle_options(const char ***argv, int *argc, int *envchanged)
 {
 	int handled = 0;
@@ -418,17 +407,6 @@ static int run_argv(int *argcp, const char ***argv)
 	return done_alias;
 }
 
-/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
-static void get_debugfs_mntpt(void)
-{
-	const char *path = debugfs_mount(NULL);
-
-	if (path)
-		strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
-	else
-		debugfs_mntpt[0] = '\0';
-}
-
 int main(int argc, const char **argv)
 {
 	const char *cmd;
@@ -436,8 +414,11 @@ int main(int argc, const char **argv)
 	cmd = perf_extract_argv0_path(argv[0]);
 	if (!cmd)
 		cmd = "perf-help";
+
 	/* get debugfs mount point from /proc/mounts */
-	get_debugfs_mntpt();
+	if (get_debugfs_mntpt())
+		die("Can't establish valid debugfs mountpoint!\n");
+
 	/*
 	 * "perf-xxxx" is the same as "perf xxxx", but we obviously:
 	 *
tools/perf/util/parse-events.c +0 -2
index f298a43..215d4f3 100644
@@ -29,8 +29,6 @@ enum event_result {
 	EVT_HANDLED_ALL
 };
 
-char debugfs_path[MAXPATHLEN];
-
 #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
 #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
 
tools/perf/util/parse-events.h +0 -1
index fc4ab3f..436c831 100644
@@ -30,7 +30,6 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);
 
 extern void print_events(void);
 
-extern char debugfs_path[];
 extern int valid_debugfs_mount(const char *debugfs);
 
 
Signature · 1 line
1.7.1
#12 lore raw

PATCH 12/21 perf: Carve out perf bits for general usage, p1

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

That is, take perf-specific compilation units used by other tools and put them in tools/lib/perf/.

---
 tools/Makefile                     |   17 +-
 tools/lib/Makefile                 |    4 +
 tools/lib/perf/header.c            | 1199 ++++++++++++++++++++++++++++++++++++
 tools/lib/perf/header.h            |  110 ++++
 tools/lib/perf/parse-events.c      |  957 ++++++++++++++++++++++++++++
 tools/lib/perf/parse-events.h      |   38 ++
 tools/perf/Makefile                |   21 +-
 tools/perf/bench/mem-memcpy.c      |    2 +-
 tools/perf/builtin-annotate.c      |    2 +-
 tools/perf/builtin-buildid-cache.c |    2 +-
 tools/perf/builtin-inject.c        |    1 +
 tools/perf/builtin-kmem.c          |    2 +-
 tools/perf/builtin-kvm.c           |    2 +-
 tools/perf/builtin-list.c          |    2 +-
 tools/perf/builtin-lock.c          |    2 +-
 tools/perf/builtin-record.c        |    4 +-
 tools/perf/builtin-report.c        |    4 +-
 tools/perf/builtin-sched.c         |    2 +-
 tools/perf/builtin-stat.c          |    4 +-
 tools/perf/builtin-timechart.c     |    4 +-
 tools/perf/builtin-top.c           |    2 +-
 tools/perf/builtin-trace.c         |    2 +-
 tools/perf/perf.c                  |    2 +-
 tools/perf/util/header.c           | 1199 ------------------------------------
 tools/perf/util/header.h           |  127 ----
 tools/perf/util/parse-events.c     |  957 ----------------------------
 tools/perf/util/parse-events.h     |   36 --
 tools/perf/util/session.h          |   17 +-
 tools/perf/util/sort.h             |    4 +-
 tools/perf/util/trace-event.h      |    2 +-
 30 files changed, 2364 insertions(+), 2363 deletions(-)
 create mode 100644 tools/lib/perf/header.c
 create mode 100644 tools/lib/perf/header.h
 create mode 100644 tools/lib/perf/parse-events.c
 create mode 100644 tools/lib/perf/parse-events.h
 delete mode 100644 tools/perf/util/header.c
 delete mode 100644 tools/perf/util/header.h
 delete mode 100644 tools/perf/util/parse-events.c
 delete mode 100644 tools/perf/util/parse-events.h
tools/Makefile +16 -1
index e645761..9949133 100644
@@ -43,7 +43,22 @@ endif
 # lib includes for submake
 BASIC_CFLAGS = -I$(CURDIR)/lib -I$(CURDIR)/perf -I$(CURDIR)/perf/util/include
 
-export BASIC_CFLAGS
+ifdef NO_NEWT
+	BASIC_CFLAGS += -DNO_NEWT_SUPPORT
+else
+	FLAGS_NEWT=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lnewt
+	ifneq ($(call try-cc,$(SOURCE_NEWT),$(FLAGS_NEWT)),y)
+		msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev);
+		BASIC_CFLAGS += -DNO_NEWT_SUPPORT
+	else
+		# Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
+		BASIC_CFLAGS += -I/usr/include/slang
+		EXTLIBS += -lnewt -lslang
+		LIB_OBJS += $(OUTPUT)util/newt.o
+	endif
+endif
+
+export BASIC_CFLAGS EXTLIBS
 
 perf: lib .FORCE
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
tools/lib/Makefile +4 -0
index 818be02..ed81953 100644
@@ -13,6 +13,8 @@ LIB_H += lk/strbuf.h
 LIB_H += lk/color.h
 LIB_H += lk/debug.h
 LIB_H += lk/strlist.h
+LIB_H += perf/parse-events.h
+LIB_H += perf/header.h
 
 LIB_OBJS += $(OUTPUT)lk/bitmap.o
 LIB_OBJS += $(OUTPUT)lk/cpumap.o
@@ -29,6 +31,8 @@ LIB_OBJS += $(OUTPUT)lk/debug.o
 LIB_OBJS += $(OUTPUT)lk/string.o
 LIB_OBJS += $(OUTPUT)lk/rbtree.o
 LIB_OBJS += $(OUTPUT)lk/strlist.o
+LIB_OBJS += $(OUTPUT)perf/parse-events.o
+LIB_OBJS += $(OUTPUT)perf/header.o
 
 LIBFILE = lklib.a
 
tools/lib/perf/header.c new file +1199 -0

1,199 lines not on this page · raw message

tools/lib/perf/header.h new file +110 -0

110 lines not on this page · raw message

tools/lib/perf/parse-events.c new file +957 -0

957 lines not on this page · raw message

tools/lib/perf/parse-events.h new file +38 -0
new file mode 100644
index 0000000..8c55d6c
@@ -0,0 +1,38 @@
+#ifndef __PERF_PARSE_EVENTS_H
+#define __PERF_PARSE_EVENTS_H
+/*
+ * Parse symbolic events/counts passed in as options:
+ */
+#include "../../../include/linux/perf_event.h"
+#include <perf.h>
+
+struct option;
+
+struct tracepoint_path {
+	char *system;
+	char *name;
+	struct tracepoint_path *next;
+};
+
+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;
+
+extern struct perf_event_attr attrs[MAX_COUNTERS];
+extern char *filters[MAX_COUNTERS];
+
+extern const char *event_name(int ctr);
+extern const char *__event_name(int type, u64 config);
+
+extern int parse_events(const struct option *opt, const char *str, int unset);
+extern int parse_filter(const struct option *opt, const char *str, int unset);
+
+#define EVENTS_HELP_MAX (128*1024)
+
+extern void print_events(void);
+
+extern int valid_debugfs_mount(const char *debugfs);
+
+
+#endif /* __PERF_PARSE_EVENTS_H */
tools/perf/Makefile +1 -20
index 65a8a7b..0a5b00f 100644
@@ -197,7 +197,7 @@ ifndef PERF_DEBUG
 endif
 
 CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
-EXTLIBS = -lpthread -lrt -lelf -lm
+EXTLIBS += -lpthread -lrt -lelf -lm
 ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
 ALL_LDFLAGS = $(LDFLAGS)
 STRIP ?= strip
@@ -360,9 +360,7 @@ LIB_H += util/exec_cmd.h
 LIB_H += util/levenshtein.h
 LIB_H += util/map.h
 LIB_H += util/parse-options.h
-LIB_H += util/parse-events.h
 LIB_H += util/quote.h
-LIB_H += util/header.h
 LIB_H += util/help.h
 LIB_H += util/session.h
 LIB_H += util/svghelper.h
@@ -387,7 +385,6 @@ LIB_OBJS += $(OUTPUT)util/exec_cmd.o
 LIB_OBJS += $(OUTPUT)util/help.o
 LIB_OBJS += $(OUTPUT)util/levenshtein.o
 LIB_OBJS += $(OUTPUT)util/parse-options.o
-LIB_OBJS += $(OUTPUT)util/parse-events.o
 LIB_OBJS += $(OUTPUT)util/path.o
 LIB_OBJS += $(OUTPUT)util/run-command.o
 LIB_OBJS += $(OUTPUT)util/quote.o
@@ -395,7 +392,6 @@ LIB_OBJS += $(OUTPUT)util/wrapper.o
 LIB_OBJS += $(OUTPUT)util/sigchain.o
 LIB_OBJS += $(OUTPUT)util/symbol.o
 LIB_OBJS += $(OUTPUT)util/pager.o
-LIB_OBJS += $(OUTPUT)util/header.o
 LIB_OBJS += $(OUTPUT)util/callchain.o
 LIB_OBJS += $(OUTPUT)util/values.o
 LIB_OBJS += $(OUTPUT)util/map.o
@@ -508,21 +504,6 @@ else
 endif # PERF_HAVE_DWARF_REGS
 endif # NO_DWARF
 
-ifdef NO_NEWT
-	BASIC_CFLAGS += -DNO_NEWT_SUPPORT
-else
-	FLAGS_NEWT=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lnewt
-	ifneq ($(call try-cc,$(SOURCE_NEWT),$(FLAGS_NEWT)),y)
-		msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev);
-		BASIC_CFLAGS += -DNO_NEWT_SUPPORT
-	else
-		# Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
-		BASIC_CFLAGS += -I/usr/include/slang
-		EXTLIBS += -lnewt -lslang
-		LIB_OBJS += $(OUTPUT)util/newt.o
-	endif
-endif
-
 ifdef NO_LIBPERL
 	BASIC_CFLAGS += -DNO_LIBPERL
 else
tools/perf/bench/mem-memcpy.c +1 -1
index 86db09e..4bda7d1 100644
@@ -10,7 +10,7 @@
 #include "../perf.h"
 #include <lk/util.h>
 #include "../util/parse-options.h"
-#include "../util/header.h"
+#include <perf/header.h>
 #include "bench.h"
 
 #include <stdio.h>
tools/perf/builtin-annotate.c +1 -1
index 04afd8a..a4d9620 100644
@@ -20,7 +20,7 @@
 
 #include "util/event.h"
 #include "util/parse-options.h"
-#include "util/parse-events.h"
+#include <perf/parse-events.h>
 #include "util/thread.h"
 #include "util/sort.h"
 #include "util/hist.h"
tools/perf/builtin-buildid-cache.c +1 -1
index 3cac2d6..5fe42b6 100644
@@ -10,7 +10,7 @@
 #include "perf.h"
 #include "util/cache.h"
 #include <lk/debug.h>
-#include "util/header.h"
+#include <perf/header.h>
 #include "util/parse-options.h"
 #include <lk/strlist.h>
 #include "util/symbol.h"
tools/perf/builtin-inject.c +1 -0
index c9127a9..a6c3caa 100644
@@ -10,6 +10,7 @@
 #include "perf.h"
 #include "util/session.h"
 #include <lk/debug.h>
+#include <perf/header.h>
 
 #include "util/parse-options.h"
 
tools/perf/builtin-kmem.c +1 -1
index a31c848..6003678 100644
@@ -5,7 +5,7 @@
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
-#include "util/header.h"
+#include <perf/header.h>
 #include "util/session.h"
 
 #include "util/parse-options.h"
tools/perf/builtin-kvm.c +1 -1
index 173dd9f..1a110fa 100644
@@ -5,7 +5,7 @@
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
-#include "util/header.h"
+#include <perf/header.h>
 #include "util/session.h"
 
 #include "util/parse-options.h"
tools/perf/builtin-list.c +1 -1
index d88c696..c1a802b 100644
@@ -10,7 +10,7 @@
 
 #include "perf.h"
 
-#include "util/parse-events.h"
+#include <perf/parse-events.h>
 #include "util/cache.h"
 
 int cmd_list(int argc __used, const char **argv __used, const char *prefix __used)
tools/perf/builtin-lock.c +1 -1
index 80327f1..dc229ab 100644
@@ -5,7 +5,7 @@
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
-#include "util/header.h"
+#include <perf/header.h>
 
 #include "util/parse-options.h"
 #include "util/trace-event.h"
tools/perf/builtin-record.c +2 -2
index 1dee3a0..34bc049 100644
@@ -14,9 +14,9 @@
 #include "util/build-id.h"
 #include <lk/util.h>
 #include "util/parse-options.h"
-#include "util/parse-events.h"
+#include <perf/parse-events.h>
 
-#include "util/header.h"
+#include <perf/header.h>
 #include "util/event.h"
 #include <lk/debug.h>
 #include "util/session.h"
tools/perf/builtin-report.c +2 -2
index 57fe707..266f721 100644
@@ -20,11 +20,11 @@
 
 #include "perf.h"
 #include <lk/debug.h>
-#include "util/header.h"
+#include <perf/header.h>
 #include "util/session.h"
 
 #include "util/parse-options.h"
-#include "util/parse-events.h"
+#include <perf/parse-events.h>
 
 #include "util/thread.h"
 #include "util/sort.h"
tools/perf/builtin-sched.c +1 -1
index 6bbc31a..6af08bf 100644
@@ -5,7 +5,7 @@
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
-#include "util/header.h"
+#include <perf/header.h>
 #include "util/session.h"
 
 #include "util/parse-options.h"
tools/perf/builtin-stat.c +2 -2
index b4cc93e..56c47bc 100644
@@ -41,10 +41,10 @@
 #include "builtin.h"
 #include <lk/util.h>
 #include "util/parse-options.h"
-#include "util/parse-events.h"
+#include <perf/parse-events.h>
 #include "util/event.h"
 #include <lk/debug.h>
-#include "util/header.h"
+#include <perf/header.h>
 #include <lk/cpumap.h>
 #include "util/thread.h"
 
tools/perf/builtin-timechart.c +2 -2
index 6e2dd8f..1699cf6 100644
@@ -25,9 +25,9 @@
 #include <lk/strlist.h>
 
 #include "perf.h"
-#include "util/header.h"
+#include <perf/header.h>
 #include "util/parse-options.h"
-#include "util/parse-events.h"
+#include <perf/parse-events.h>
 #include "util/event.h"
 #include "util/session.h"
 #include "util/svghelper.h"
tools/perf/builtin-top.c +1 -1
index e402ba4..e4a5783 100644
@@ -27,7 +27,7 @@
 #include <lk/util.h>
 #include <linux/rbtree.h>
 #include "util/parse-options.h"
-#include "util/parse-events.h"
+#include <perf/parse-events.h>
 #include <lk/cpumap.h>
 
 #include <lk/debug.h>
tools/perf/builtin-trace.c +1 -1
index be67b73..6c3bc42 100644
@@ -5,7 +5,7 @@
 #include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
-#include "util/header.h"
+#include <perf/header.h>
 #include "util/exec_cmd.h"
 #include "util/trace-event.h"
 #include "util/session.h"
tools/perf/perf.c +1 -1
index 58c1a56..4d57b28 100644
@@ -14,7 +14,7 @@
 #include "util/quote.h"
 #include "util/build-id.h"
 #include "util/run-command.h"
-#include "util/parse-events.h"
+#include <perf/parse-events.h>
 #include <lk/debugfs.h>
 #include <lk/config.h>
 #include <lk/debug.h>
tools/perf/util/header.c deleted +0 -1199

463 lines not on this page · raw message

tools/perf/util/header.h deleted +0 -127

127 lines not on this page · raw message

tools/perf/util/parse-events.c deleted +0 -957

957 lines not on this page · raw message

tools/perf/util/parse-events.h deleted +0 -36
deleted file mode 100644
index 436c831..0000000

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

tools/perf/util/session.h +16 -1
index 55c6881..bf3b5c4 100644

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

tools/perf/util/sort.h +2 -2
index 7a266b8..0d6ed4c 100644

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

tools/perf/util/trace-event.h +1 -1
index b3e86b1..428383b 100644

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

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

Signature · 1 line
1.7.1

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

#13 lore raw

PATCH 13/21 perf: Carve out perf bits for general usage, p2

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Those are pulled in when linking parse-events.c with other tools like the RAS daemon so export them into tools/lib/perf/ too.

---
 tools/Makefile                     |   39 +-
 tools/lib/Makefile                 |    6 +
 tools/lib/perf/header.c            |    4 +-
 tools/lib/perf/header.h            |    2 +-
 tools/lib/perf/map.c               |  630 ++++++++++
 tools/lib/perf/map.h               |  217 ++++
 tools/lib/perf/parse-events.c      |    2 +-
 tools/lib/perf/session.c           |  906 ++++++++++++++
 tools/lib/perf/session.h           |  158 +++
 tools/lib/perf/symbol.c            | 2346 +++++++++++++++++++++++++++++++++++
 tools/lib/perf/symbol.h            |  221 ++++
 tools/perf/Makefile                |   41 -
 tools/perf/builtin-annotate.c      |    4 +-
 tools/perf/builtin-buildid-cache.c |    6 +-
 tools/perf/builtin-buildid-list.c  |    4 +-
 tools/perf/builtin-diff.c          |    4 +-
 tools/perf/builtin-inject.c        |    2 +-
 tools/perf/builtin-kmem.c          |    4 +-
 tools/perf/builtin-kvm.c           |    4 +-
 tools/perf/builtin-lock.c          |    4 +-
 tools/perf/builtin-probe.c         |    2 +-
 tools/perf/builtin-record.c        |    4 +-
 tools/perf/builtin-report.c        |    4 +-
 tools/perf/builtin-sched.c         |    4 +-
 tools/perf/builtin-test.c          |    4 +-
 tools/perf/builtin-timechart.c     |    4 +-
 tools/perf/builtin-top.c           |    4 +-
 tools/perf/builtin-trace.c         |    4 +-
 tools/perf/util/build-id.c         |    2 +-
 tools/perf/util/build-id.h         |    2 +-
 tools/perf/util/callchain.h        |    2 +-
 tools/perf/util/event.c            |    2 +-
 tools/perf/util/event.h            |    2 +-
 tools/perf/util/hist.c             |    2 +-
 tools/perf/util/map.c              |  630 ----------
 tools/perf/util/map.h              |  217 ----
 tools/perf/util/newt.c             |    4 +-
 tools/perf/util/probe-event.c      |    2 +-
 tools/perf/util/probe-finder.c     |    2 +-
 tools/perf/util/session.c          |  906 --------------
 tools/perf/util/session.h          |  158 ---
 tools/perf/util/sort.h             |    2 +-
 tools/perf/util/symbol.c           | 2347 ------------------------------------
 tools/perf/util/symbol.h           |  221 ----
 tools/perf/util/thread.c           |    2 +-
 tools/perf/util/thread.h           |    2 +-
 46 files changed, 4570 insertions(+), 4569 deletions(-)
 create mode 100644 tools/lib/perf/map.c
 create mode 100644 tools/lib/perf/map.h
 create mode 100644 tools/lib/perf/session.c
 create mode 100644 tools/lib/perf/session.h
 create mode 100644 tools/lib/perf/symbol.c
 create mode 100644 tools/lib/perf/symbol.h
 delete mode 100644 tools/perf/util/map.c
 delete mode 100644 tools/perf/util/map.h
 delete mode 100644 tools/perf/util/session.c
 delete mode 100644 tools/perf/util/session.h
 delete mode 100644 tools/perf/util/symbol.c
 delete mode 100644 tools/perf/util/symbol.h
tools/Makefile +38 -1
index 9949133..54dea0e 100644
@@ -2,6 +2,7 @@
 #
 
 include Makefile.lib
+-include perf/feature-tests.mak
 
 #
 # Include saner warnings here, which can catch bugs:
@@ -58,7 +59,43 @@ else
 	endif
 endif
 
-export BASIC_CFLAGS EXTLIBS
+ifdef NO_DEMANGLE
+	BASIC_CFLAGS += -DNO_DEMANGLE
+else ifdef HAVE_CPLUS_DEMANGLE
+	EXTLIBS += -liberty
+	BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
+else
+	FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd
+	has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD))
+	ifeq ($(has_bfd),y)
+		EXTLIBS += -lbfd
+	else
+		FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
+		has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY))
+		ifeq ($(has_bfd_iberty),y)
+			EXTLIBS += -lbfd -liberty
+		else
+			FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
+			has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z))
+			ifeq ($(has_bfd_iberty_z),y)
+				EXTLIBS += -lbfd -liberty -lz
+			else
+				FLAGS_CPLUS_DEMANGLE=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -liberty
+				has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE))
+				ifeq ($(has_cplus_demangle),y)
+					EXTLIBS += -liberty
+					BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
+				else
+					msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
+					BASIC_CFLAGS += -DNO_DEMANGLE
+				endif
+			endif
+		endif
+	endif
+endif
+
+
+export BASIC_CFLAGS EXTLIBS 
 
 perf: lib .FORCE
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
tools/lib/Makefile +6 -0
index ed81953..dd87c43 100644
@@ -15,6 +15,9 @@ LIB_H += lk/debug.h
 LIB_H += lk/strlist.h
 LIB_H += perf/parse-events.h
 LIB_H += perf/header.h
+LIB_H += perf/symbol.h
+LIB_H += perf/map.h
+LIB_H += perf/session.h
 
 LIB_OBJS += $(OUTPUT)lk/bitmap.o
 LIB_OBJS += $(OUTPUT)lk/cpumap.o
@@ -33,6 +36,9 @@ LIB_OBJS += $(OUTPUT)lk/rbtree.o
 LIB_OBJS += $(OUTPUT)lk/strlist.o
 LIB_OBJS += $(OUTPUT)perf/parse-events.o
 LIB_OBJS += $(OUTPUT)perf/header.o
+LIB_OBJS += $(OUTPUT)perf/symbol.o
+LIB_OBJS += $(OUTPUT)perf/map.o
+LIB_OBJS += $(OUTPUT)perf/session.o
 
 LIBFILE = lklib.a
 
tools/lib/perf/header.c +2 -2
index 6804546..572a243 100644
@@ -12,8 +12,8 @@
 #include "header.h"
 #include <perf.h>
 #include <util/trace-event.h>
-#include <util/session.h>
-#include <util/symbol.h>
+#include "session.h"
+#include "symbol.h"
 #include <lk/debug.h>
 
 static bool no_buildid_cache = false;
tools/lib/perf/header.h +1 -1
index e8cdb86..e930814 100644
@@ -6,7 +6,7 @@
 #include <stdbool.h>
 #include <lk/types.h>
 #include <util/event.h>
-#include <util/session.h>
+#include "session.h"
 
 #include <linux/bitmap.h>
 
tools/lib/perf/map.c new file +630 -0

630 lines not on this page · raw message

tools/lib/perf/map.h new file +217 -0

217 lines not on this page · raw message

tools/lib/perf/parse-events.c +1 -1
index f028838..629114e 100644
@@ -6,7 +6,7 @@
 #include "parse-events.h"
 #include <util/exec_cmd.h>
 #include "string.h"
-#include <util/symbol.h>
+#include "symbol.h"
 #include <util/cache.h>
 #include "header.h"
 #include <lk/debugfs.h>
tools/lib/perf/session.c new file +906 -0

906 lines not on this page · raw message

tools/lib/perf/session.h new file +158 -0

158 lines not on this page · raw message

tools/lib/perf/symbol.c new file +2346 -0

994 lines not on this page · raw message

tools/lib/perf/symbol.h new file +221 -0

221 lines not on this page · raw message

tools/perf/Makefile +0 -41

41 lines not on this page · raw message

tools/perf/builtin-annotate.c +2 -2
index a4d9620..1c78b75 100644

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

tools/perf/builtin-buildid-cache.c +3 -3
index 5fe42b6..440a92b 100644

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

tools/perf/builtin-buildid-list.c +2 -2
index b767dde..8cfc4d3 100644

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

tools/perf/builtin-diff.c +2 -2
index b346e7f..2d406dd 100644

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

tools/perf/builtin-inject.c +1 -1
index a6c3caa..fd1092e 100644

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

tools/perf/builtin-kmem.c +2 -2
index 6003678..3129210 100644

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

tools/perf/builtin-kvm.c +2 -2
index 1a110fa..509d11f 100644

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

tools/perf/builtin-lock.c +2 -2
index dc229ab..17abce4 100644

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

tools/perf/builtin-probe.c +1 -1
index f53edba..113213f 100644

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

tools/perf/builtin-record.c +2 -2
index 34bc049..e78efad 100644

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

tools/perf/builtin-report.c +2 -2
index 266f721..98284d1 100644

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

tools/perf/builtin-sched.c +2 -2
index 6af08bf..24dabdc 100644

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

tools/perf/builtin-test.c +2 -2
index 1be7ad9..f5d6686 100644

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

tools/perf/builtin-timechart.c +2 -2
index 1699cf6..eddeeae 100644

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

tools/perf/builtin-top.c +2 -2
index e4a5783..8edc974 100644

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

tools/perf/builtin-trace.c +2 -2
index 6c3bc42..1edffa4 100644

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

tools/perf/util/build-id.c +1 -1
index a338745..5969758 100644

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

tools/perf/util/build-id.h +1 -1
index e72ed79..a8a6bd9 100644

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

tools/perf/util/callchain.h +1 -1
index 809850f..ca8a73d 100644

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

tools/perf/util/event.c +1 -1
index fda3406..1669fcc 100644

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

tools/perf/util/event.h +1 -1
index 887ee63..fef5236 100644

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

tools/perf/util/hist.c +1 -1
index a409e27..2dfa141 100644

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

tools/perf/util/map.c deleted +0 -630

630 lines not on this page · raw message

tools/perf/util/map.h deleted +0 -217

217 lines not on this page · raw message

tools/perf/util/newt.c +2 -2
index 3918f22..63f89e0 100644

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

tools/perf/util/probe-event.c +1 -1
index 26f29ca..d3e911b 100644

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

tools/perf/util/probe-finder.c +1 -1
index 8ac178d..789c583 100644

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

tools/perf/util/session.c deleted +0 -906

906 lines not on this page · raw message

tools/perf/util/session.h deleted +0 -158

158 lines not on this page · raw message

tools/perf/util/sort.h +1 -1
index 0d6ed4c..ccc3045 100644

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

tools/perf/util/symbol.c deleted +0 -2347

2,347 lines not on this page · raw message

tools/perf/util/symbol.h deleted +0 -221

221 lines not on this page · raw message

tools/perf/util/thread.c +1 -1
index c2652fd..c5e5207 100644

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

tools/perf/util/thread.h +1 -1
index 1dfd9ff..93baaea 100644

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

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

Signature · 1 line
1.7.1

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

#14 lore raw

PATCH 14/21 perf: Carve out perf bits for general usage, p3

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Those are pulled in when linking parse-events.c with other tools like the RAS daemon so export them into tools/lib/perf/ too.

---
 tools/lib/Makefile                |   10 +
 tools/lib/lk/debug.h              |    2 +-
 tools/lib/perf/build-id.c         |  111 ++++
 tools/lib/perf/build-id.h         |   12 +
 tools/lib/perf/event.c            |  827 ++++++++++++++++++++++++++++
 tools/lib/perf/event.h            |  167 ++++++
 tools/lib/perf/header.h           |    2 +-
 tools/lib/perf/hist.c             | 1082 +++++++++++++++++++++++++++++++++++++
 tools/lib/perf/hist.h             |  129 +++++
 tools/lib/perf/session.c          |    3 +-
 tools/lib/perf/session.h          |    6 +-
 tools/lib/perf/sort.c             |  346 ++++++++++++
 tools/lib/perf/sort.h             |  115 ++++
 tools/lib/perf/symbol.c           |    2 +-
 tools/lib/perf/thread.c           |  164 ++++++
 tools/lib/perf/thread.h           |   44 ++
 tools/perf/Makefile               |   10 -
 tools/perf/builtin-annotate.c     |    8 +-
 tools/perf/builtin-buildid-list.c |    2 +-
 tools/perf/builtin-diff.c         |    6 +-
 tools/perf/builtin-kmem.c         |    2 +-
 tools/perf/builtin-kvm.c          |    2 +-
 tools/perf/builtin-lock.c         |    2 +-
 tools/perf/builtin-record.c       |    4 +-
 tools/perf/builtin-report.c       |    6 +-
 tools/perf/builtin-sched.c        |    2 +-
 tools/perf/builtin-stat.c         |    4 +-
 tools/perf/builtin-test.c         |    2 +-
 tools/perf/builtin-timechart.c    |    2 +-
 tools/perf/builtin-top.c          |    2 +-
 tools/perf/builtin-trace.c        |    2 +-
 tools/perf/perf.c                 |    2 +-
 tools/perf/util/build-id.c        |  111 ----
 tools/perf/util/build-id.h        |   12 -
 tools/perf/util/callchain.c       |    7 -
 tools/perf/util/callchain.h       |    3 +-
 tools/perf/util/event.c           |  820 ----------------------------
 tools/perf/util/event.h           |  166 ------
 tools/perf/util/hist.c            | 1082 -------------------------------------
 tools/perf/util/hist.h            |  129 -----
 tools/perf/util/newt.c            |    4 +-
 tools/perf/util/probe-event.c     |    4 +-
 tools/perf/util/probe-finder.c    |    2 +-
 tools/perf/util/sort.c            |  346 ------------
 tools/perf/util/sort.h            |  116 ----
 tools/perf/util/thread.c          |  164 ------
 tools/perf/util/thread.h          |   44 --
 47 files changed, 3044 insertions(+), 3046 deletions(-)
 create mode 100644 tools/lib/perf/build-id.c
 create mode 100644 tools/lib/perf/build-id.h
 create mode 100644 tools/lib/perf/event.c
 create mode 100644 tools/lib/perf/event.h
 create mode 100644 tools/lib/perf/hist.c
 create mode 100644 tools/lib/perf/hist.h
 create mode 100644 tools/lib/perf/sort.c
 create mode 100644 tools/lib/perf/sort.h
 create mode 100644 tools/lib/perf/thread.c
 create mode 100644 tools/lib/perf/thread.h
 delete mode 100644 tools/perf/util/build-id.c
 delete mode 100644 tools/perf/util/build-id.h
 delete mode 100644 tools/perf/util/event.c
 delete mode 100644 tools/perf/util/event.h
 delete mode 100644 tools/perf/util/hist.c
 delete mode 100644 tools/perf/util/hist.h
 delete mode 100644 tools/perf/util/sort.c
 delete mode 100644 tools/perf/util/sort.h
 delete mode 100644 tools/perf/util/thread.c
 delete mode 100644 tools/perf/util/thread.h
tools/lib/Makefile +10 -0
index dd87c43..cabef46 100644
@@ -18,6 +18,11 @@ LIB_H += perf/header.h
 LIB_H += perf/symbol.h
 LIB_H += perf/map.h
 LIB_H += perf/session.h
+LIB_H += perf/build-id.h
+LIB_H += perf/hist.h
+LIB_H += perf/thread.h
+LIB_H += perf/sort.h
+LIB_H += perf/event.h
 
 LIB_OBJS += $(OUTPUT)lk/bitmap.o
 LIB_OBJS += $(OUTPUT)lk/cpumap.o
@@ -39,6 +44,11 @@ LIB_OBJS += $(OUTPUT)perf/header.o
 LIB_OBJS += $(OUTPUT)perf/symbol.o
 LIB_OBJS += $(OUTPUT)perf/map.o
 LIB_OBJS += $(OUTPUT)perf/session.o
+LIB_OBJS += $(OUTPUT)perf/build-id.o
+LIB_OBJS += $(OUTPUT)perf/hist.o
+LIB_OBJS += $(OUTPUT)perf/thread.o
+LIB_OBJS += $(OUTPUT)perf/sort.o
+LIB_OBJS += $(OUTPUT)perf/event.o
 
 LIBFILE = lklib.a
 
tools/lib/lk/debug.h +1 -1
index 6df0457..44fdfab 100644
@@ -3,7 +3,7 @@
 #define __LK_DEBUG_H
 
 #include <stdbool.h>
-#include <util/event.h>
+#include <perf/event.h>
 
 extern int verbose;
 extern bool dump_trace;
tools/lib/perf/build-id.c new file +111 -0

111 lines not on this page · raw message

tools/lib/perf/build-id.h new file +12 -0
new file mode 100644
index 0000000..1b73726
@@ -0,0 +1,12 @@
+#ifndef PERF_BUILD_ID_H_
+#define PERF_BUILD_ID_H_ 1
+
+#include "session.h"
+#include <util/config.h>
+
+extern struct perf_event_ops build_id__mark_dso_hit_ops;
+
+char *dso__build_id_filename(struct dso *self, char *bf, size_t size);
+extern void set_buildid_dir(void);
+
+#endif
tools/lib/perf/event.c new file +827 -0

827 lines not on this page · raw message

tools/lib/perf/event.h new file +167 -0

167 lines not on this page · raw message

tools/lib/perf/header.h +1 -1
index e930814..3845118 100644
@@ -5,7 +5,7 @@
 #include <sys/types.h>
 #include <stdbool.h>
 #include <lk/types.h>
-#include <util/event.h>
+#include "event.h"
 #include "session.h"
 
 #include <linux/bitmap.h>
tools/lib/perf/hist.c new file +1082 -0

1,082 lines not on this page · raw message

tools/lib/perf/hist.h new file +129 -0

129 lines not on this page · raw message

tools/lib/perf/session.c +1 -2
index 5e9998c..c1589e9 100644
@@ -6,9 +6,8 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/mman.h>
-
 #include "session.h"
-#include <util/sort.h>
+#include "sort.h"
 #include <lk/util.h>
 
 static int perf_session__open(struct perf_session *self, bool force)
tools/lib/perf/session.h +3 -3
index 1bbece2..bf3b5c4 100644
@@ -1,10 +1,10 @@
 #ifndef __PERF_SESSION_H
 #define __PERF_SESSION_H
 
-#include <util/hist.h>
-#include <util/event.h>
+#include "hist.h"
+#include "event.h"
 #include "symbol.h"
-#include <util/thread.h>
+#include "thread.h"
 #include <linux/bitops.h>
 #include <linux/rbtree.h>
 #include "../../../include/linux/perf_event.h"
tools/lib/perf/sort.c new file +346 -0

346 lines not on this page · raw message

tools/lib/perf/sort.h new file +115 -0

115 lines not on this page · raw message

tools/lib/perf/symbol.c +1 -1
index 04593d2..dddbeab 100644
@@ -11,7 +11,7 @@
 #include <sys/param.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <util/build-id.h>
+#include "build-id.h"
 #include "symbol.h"
 #include <lk/strlist.h>
 #include <libelf.h>
tools/lib/perf/thread.c new file +164 -0

142 lines not on this page · raw message

tools/lib/perf/thread.h new file +44 -0

44 lines not on this page · raw message

tools/perf/Makefile +0 -10
index 653802b..001831e 100644

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

tools/perf/builtin-annotate.c +4 -4
index 1c78b75..29753d1 100644

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

tools/perf/builtin-buildid-list.c +1 -1
index 8cfc4d3..5e3253a 100644

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

tools/perf/builtin-diff.c +3 -3
index 2d406dd..9615c36 100644

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

tools/perf/builtin-kmem.c +1 -1
index 3129210..32476b9 100644

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

tools/perf/builtin-kvm.c +1 -1
index 509d11f..10a8c4d 100644

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

tools/perf/builtin-lock.c +1 -1
index 17abce4..8ded0a7 100644

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

tools/perf/builtin-record.c +2 -2
index e78efad..6072b83 100644

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

tools/perf/builtin-report.c +3 -3
index 98284d1..0803898 100644

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

tools/perf/builtin-sched.c +1 -1
index 24dabdc..6df3cb3 100644

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

tools/perf/builtin-stat.c +2 -2
index 56c47bc..e1186c0 100644

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

tools/perf/builtin-test.c +1 -1
index f5d6686..0028015 100644

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

tools/perf/builtin-timechart.c +1 -1
index eddeeae..71dd659 100644

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

tools/perf/builtin-top.c +1 -1
index 8edc974..866ba3d 100644

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

tools/perf/builtin-trace.c +1 -1
index 1edffa4..585af2e 100644

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

tools/perf/perf.c +1 -1
index 4d57b28..4268ed4 100644

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

tools/perf/util/build-id.c deleted +0 -111

111 lines not on this page · raw message

tools/perf/util/build-id.h deleted +0 -12
deleted file mode 100644
index a8a6bd9..0000000

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

tools/perf/util/callchain.c +0 -7
index dcc0254..6de3448 100644

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

tools/perf/util/callchain.h +1 -2
index ca8a73d..13176e6 100644

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

tools/perf/util/event.c deleted +0 -820

820 lines not on this page · raw message

tools/perf/util/event.h deleted +0 -166

166 lines not on this page · raw message

tools/perf/util/hist.c deleted +0 -1082

1,082 lines not on this page · raw message

tools/perf/util/hist.h deleted +0 -129

129 lines not on this page · raw message

tools/perf/util/newt.c +2 -2
index 63f89e0..dffe075 100644

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

tools/perf/util/probe-event.c +2 -2
index d3e911b..08b591f 100644

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

tools/perf/util/probe-finder.c +1 -1
index 789c583..de2c598 100644

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

tools/perf/util/sort.c deleted +0 -346

346 lines not on this page · raw message

tools/perf/util/sort.h deleted +0 -116

116 lines not on this page · raw message

tools/perf/util/thread.c deleted +0 -164

164 lines not on this page · raw message

tools/perf/util/thread.h deleted +0 -44

44 lines not on this page · raw message

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

Signature · 1 line
1.7.1

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

#15 lore raw

PATCH 15/21 perf: Export trace event utils

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Those are indirectly needed by parse-events.c too.

---
 tools/lib/Makefile                  |    3 +
 tools/lib/trace/trace-event-info.c  |  563 ++++++
 tools/lib/trace/trace-event-parse.c | 3233 +++++++++++++++++++++++++++++++++++
 tools/lib/trace/trace-event-read.c  |  539 ++++++
 tools/perf/Makefile                 |    3 -
 tools/perf/util/trace-event-info.c  |  563 ------
 tools/perf/util/trace-event-parse.c | 3233 -----------------------------------
 tools/perf/util/trace-event-read.c  |  539 ------
 8 files changed, 4338 insertions(+), 4338 deletions(-)
 create mode 100644 tools/lib/trace/trace-event-info.c
 create mode 100644 tools/lib/trace/trace-event-parse.c
 create mode 100644 tools/lib/trace/trace-event-read.c
 delete mode 100644 tools/perf/util/trace-event-info.c
 delete mode 100644 tools/perf/util/trace-event-parse.c
 delete mode 100644 tools/perf/util/trace-event-read.c
tools/lib/Makefile +3 -0
index cabef46..795fa3a 100644
@@ -49,6 +49,9 @@ LIB_OBJS += $(OUTPUT)perf/hist.o
 LIB_OBJS += $(OUTPUT)perf/thread.o
 LIB_OBJS += $(OUTPUT)perf/sort.o
 LIB_OBJS += $(OUTPUT)perf/event.o
+LIB_OBJS += $(OUTPUT)trace/trace-event-read.o
+LIB_OBJS += $(OUTPUT)trace/trace-event-info.o
+LIB_OBJS += $(OUTPUT)trace/trace-event-parse.o
 
 LIBFILE = lklib.a
 
tools/lib/trace/trace-event-info.c new file +563 -0

563 lines not on this page · raw message

tools/lib/trace/trace-event-parse.c new file +3233 -0

2,428 lines not on this page · raw message

tools/lib/trace/trace-event-read.c new file +539 -0

539 lines not on this page · raw message

tools/perf/Makefile +0 -3
index 001831e..590c8f6 100644

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

tools/perf/util/trace-event-info.c deleted +0 -563

563 lines not on this page · raw message

tools/perf/util/trace-event-parse.c deleted +0 -3233

3,233 lines not on this page · raw message

tools/perf/util/trace-event-read.c deleted +0 -539

539 lines not on this page · raw message

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

Signature · 1 line
1.7.1

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

#16 lore raw

Re: [PATCH 15/21] perf: Export trace event utils

Hi Borislav,

I'm actually working on making a libparsevent.a that does some of what you are doing.

The idea is, if I can separate out this code from perf, I can then bring it up to speed with what I have in trace-cmd.

-- Steve

Quoted 8,764 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

Those are indirectly needed by parse-events.c too.

---
 tools/lib/Makefile                  |    3 +
 tools/lib/trace/trace-event-info.c  |  563 ++++++
 tools/lib/trace/trace-event-parse.c | 3233 +++++++++++++++++++++++++++++++++++
 tools/lib/trace/trace-event-read.c  |  539 ++++++
 tools/perf/Makefile                 |    3 -
 tools/perf/util/trace-event-info.c  |  563 ------
 tools/perf/util/trace-event-parse.c | 3233 -----------------------------------
 tools/perf/util/trace-event-read.c  |  539 ------
 8 files changed, 4338 insertions(+), 4338 deletions(-)
 create mode 100644 tools/lib/trace/trace-event-info.c
 create mode 100644 tools/lib/trace/trace-event-parse.c
 create mode 100644 tools/lib/trace/trace-event-read.c
 delete mode 100644 tools/perf/util/trace-event-info.c
 delete mode 100644 tools/perf/util/trace-event-parse.c
 delete mode 100644 tools/perf/util/trace-event-read.c
tools/lib/Makefile +3 -0
index cabef46..795fa3a 100644
@@ -49,6 +49,9 @@ LIB_OBJS += $(OUTPUT)perf/hist.o
 LIB_OBJS += $(OUTPUT)perf/thread.o
 LIB_OBJS += $(OUTPUT)perf/sort.o
 LIB_OBJS += $(OUTPUT)perf/event.o
+LIB_OBJS += $(OUTPUT)trace/trace-event-read.o
+LIB_OBJS += $(OUTPUT)trace/trace-event-info.o
+LIB_OBJS += $(OUTPUT)trace/trace-event-parse.o
 
 LIBFILE = lklib.a
 
tools/lib/trace/trace-event-info.c new file +563 -0
new file mode 100644
index 0000000..e1ad23f
@@ -0,0 +1,563 @@
+/*
+ * Copyright (C) 2008,2009, Steven Rostedt <[email protected]>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License (not later!)
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#define _GNU_SOURCE
+#include <dirent.h>
+#include <mntent.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <pthread.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <linux/kernel.h>
+
+#include <perf.h>
+#include <util/trace-event.h>
+#include <lk/debugfs.h>
+
+#define VERSION "0.5"
+
+#define _STR(x) #x
+#define STR(x) _STR(x)
+#define MAX_PATH 256
+
+#define TRACE_CTRL	"tracing_on"
+#define TRACE		"trace"
+#define AVAILABLE	"available_tracers"
+#define CURRENT		"current_tracer"
+#define ITER_CTRL	"trace_options"
+#define MAX_LATENCY	"tracing_max_latency"
+
+unsigned int page_size;
+
+static const char *output_file = "trace.info";
+static int output_fd;
+
+struct event_list {
+	struct event_list *next;
+	const char *event;
+};
+
+struct events {
+	struct events *sibling;
+	struct events *children;
+	struct events *next;
+	char *name;
+};
+
+
+
+static void die(const char *fmt, ...)
+{
+	va_list ap;
+	int ret = errno;
+
+	if (errno)
+		perror("trace-cmd");
+	else
+		ret = -1;
+
+	va_start(ap, fmt);
+	fprintf(stderr, "  ");
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+
+	fprintf(stderr, "\n");
+	exit(ret);
+}
+
+void *malloc_or_die(unsigned int size)
+{
+	void *data;
+
+	data = malloc(size);
+	if (!data)
+		die("malloc");
+	return data;
+}
+
+static const char *find_debugfs(void)
+{
+	const char *path = debugfs_mount(NULL);
+
+	if (!path)
+		die("Your kernel not support debugfs filesystem");
+
+	return path;
+}
+
+/*
+ * Finds the path to the debugfs/tracing
+ * Allocates the string and stores it.
+ */
+static const char *find_tracing_dir(void)
+{
+	static char *tracing;
+	static int tracing_found;
+	const char *debugfs;
+
+	if (tracing_found)
+		return tracing;
+
+	debugfs = find_debugfs();
+
+	tracing = malloc_or_die(strlen(debugfs) + 9);
+
+	sprintf(tracing, "%s/tracing", debugfs);
+
+	tracing_found = 1;
+	return tracing;
+}
+
+static char *get_tracing_file(const char *name)
+{
+	const char *tracing;
+	char *file;
+
+	tracing = find_tracing_dir();
+	if (!tracing)
+		return NULL;
+
+	file = malloc_or_die(strlen(tracing) + strlen(name) + 2);
+
+	sprintf(file, "%s/%s", tracing, name);
+	return file;
+}
+
+static void put_tracing_file(char *file)
+{
+	free(file);
+}
+
+static ssize_t calc_data_size;
+
+static ssize_t write_or_die(const void *buf, size_t len)
+{
+	int ret;
+
+	if (calc_data_size) {
+		calc_data_size += len;
+		return len;
+	}
+
+	ret = write(output_fd, buf, len);
+	if (ret < 0)
+		die("writing to '%s'", output_file);
+
+	return ret;
+}
+
+int bigendian(void)
+{
+	unsigned char str[] = { 0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0};
+	unsigned int *ptr;
+
+	ptr = (unsigned int *)(void *)str;
+	return *ptr == 0x01020304;
+}
+
+static unsigned long long copy_file_fd(int fd)
+{
+	unsigned long long size = 0;
+	char buf[BUFSIZ];
+	int r;
+
+	do {
+		r = read(fd, buf, BUFSIZ);
+		if (r > 0) {
+			size += r;
+			write_or_die(buf, r);
+		}
+	} while (r > 0);
+
+	return size;
+}
+
+static unsigned long long copy_file(const char *file)
+{
+	unsigned long long size = 0;
+	int fd;
+
+	fd = open(file, O_RDONLY);
+	if (fd < 0)
+		die("Can't read '%s'", file);
+	size = copy_file_fd(fd);
+	close(fd);
+
+	return size;
+}
+
+static unsigned long get_size_fd(int fd)
+{
+	unsigned long long size = 0;
+	char buf[BUFSIZ];
+	int r;
+
+	do {
+		r = read(fd, buf, BUFSIZ);
+		if (r > 0)
+			size += r;
+	} while (r > 0);
+
+	lseek(fd, 0, SEEK_SET);
+
+	return size;
+}
+
+static unsigned long get_size(const char *file)
+{
+	unsigned long long size = 0;
+	int fd;
+
+	fd = open(file, O_RDONLY);
+	if (fd < 0)
+		die("Can't read '%s'", file);
+	size = get_size_fd(fd);
+	close(fd);
+
+	return size;
+}
+
+static void read_header_files(void)
+{
+	unsigned long long size, check_size;
+	char *path;
+	int fd;
+
+	path = get_tracing_file("events/header_page");
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+		die("can't read '%s'", path);
+
+	/* unfortunately, you can not stat debugfs files for size */
+	size = get_size_fd(fd);
+
+	write_or_die("header_page", 12);
+	write_or_die(&size, 8);
+	check_size = copy_file_fd(fd);
+	close(fd);
+
+	if (size != check_size)
+		die("wrong size for '%s' size=%lld read=%lld",
+		    path, size, check_size);
+	put_tracing_file(path);
+
+	path = get_tracing_file("events/header_event");
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+		die("can't read '%s'", path);
+
+	size = get_size_fd(fd);
+
+	write_or_die("header_event", 13);
+	write_or_die(&size, 8);
+	check_size = copy_file_fd(fd);
+	if (size != check_size)
+		die("wrong size for '%s'", path);
+	put_tracing_file(path);
+	close(fd);
+}
+
+static bool name_in_tp_list(char *sys, struct tracepoint_path *tps)
+{
+	while (tps) {
+		if (!strcmp(sys, tps->name))
+			return true;
+		tps = tps->next;
+	}
+
+	return false;
+}
+
+static void copy_event_system(const char *sys, struct tracepoint_path *tps)
+{
+	unsigned long long size, check_size;
+	struct dirent *dent;
+	struct stat st;
+	char *format;
+	DIR *dir;
+	int count = 0;
+	int ret;
+
+	dir = opendir(sys);
+	if (!dir)
+		die("can't read directory '%s'", sys);
+
+	while ((dent = readdir(dir))) {
+		if (dent->d_type != DT_DIR ||
+		    strcmp(dent->d_name, ".") == 0 ||
+		    strcmp(dent->d_name, "..") == 0 ||
+		    !name_in_tp_list(dent->d_name, tps))
+			continue;
+		format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10);
+		sprintf(format, "%s/%s/format", sys, dent->d_name);
+		ret = stat(format, &st);
+		free(format);
+		if (ret < 0)
+			continue;
+		count++;
+	}
+
+	write_or_die(&count, 4);
+
+	rewinddir(dir);
+	while ((dent = readdir(dir))) {
+		if (dent->d_type != DT_DIR ||
+		    strcmp(dent->d_name, ".") == 0 ||
+		    strcmp(dent->d_name, "..") == 0 ||
+		    !name_in_tp_list(dent->d_name, tps))
+			continue;
+		format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10);
+		sprintf(format, "%s/%s/format", sys, dent->d_name);
+		ret = stat(format, &st);
+
+		if (ret >= 0) {
+			/* unfortunately, you can not stat debugfs files for size */
+			size = get_size(format);
+			write_or_die(&size, 8);
+			check_size = copy_file(format);
+			if (size != check_size)
+				die("error in size of file '%s'", format);
+		}
+
+		free(format);
+	}
+	closedir(dir);
+}
+
+static void read_ftrace_files(struct tracepoint_path *tps)
+{
+	char *path;
+
+	path = get_tracing_file("events/ftrace");
+
+	copy_event_system(path, tps);
+
+	put_tracing_file(path);
+}
+
+static bool system_in_tp_list(char *sys, struct tracepoint_path *tps)
+{
+	while (tps) {
+		if (!strcmp(sys, tps->system))
+			return true;
+		tps = tps->next;
+	}
+
+	return false;
+}
+
+static void read_event_files(struct tracepoint_path *tps)
+{
+	struct dirent *dent;
+	struct stat st;
+	char *path;
+	char *sys;
+	DIR *dir;
+	int count = 0;
+	int ret;
+
+	path = get_tracing_file("events");
+
+	dir = opendir(path);
+	if (!dir)
+		die("can't read directory '%s'", path);
+
+	while ((dent = readdir(dir))) {
+		if (dent->d_type != DT_DIR ||
+		    strcmp(dent->d_name, ".") == 0 ||
+		    strcmp(dent->d_name, "..") == 0 ||
+		    strcmp(dent->d_name, "ftrace") == 0 ||
+		    !system_in_tp_list(dent->d_name, tps))
+			continue;
+		count++;
+	}
+
+	write_or_die(&count, 4);
+
+	rewinddir(dir);
+	while ((dent = readdir(dir))) {
+		if (dent->d_type != DT_DIR ||
+		    strcmp(dent->d_name, ".") == 0 ||
+		    strcmp(dent->d_name, "..") == 0 ||
+		    strcmp(dent->d_name, "ftrace") == 0 ||
+		    !system_in_tp_list(dent->d_name, tps))
+			continue;
+		sys = malloc_or_die(strlen(path) + strlen(dent->d_name) + 2);
+		sprintf(sys, "%s/%s", path, dent->d_name);
+		ret = stat(sys, &st);
+		if (ret >= 0) {
+			write_or_die(dent->d_name, strlen(dent->d_name) + 1);
+			copy_event_system(sys, tps);
+		}
+		free(sys);
+	}
+
+	closedir(dir);
+	put_tracing_file(path);
+}
+
+static void read_proc_kallsyms(void)
+{
+	unsigned int size, check_size;
+	const char *path = "/proc/kallsyms";
+	struct stat st;
+	int ret;
+
+	ret = stat(path, &st);
+	if (ret < 0) {
+		/* not found */
+		size = 0;
+		write_or_die(&size, 4);
+		return;
+	}
+	size = get_size(path);
+	write_or_die(&size, 4);
+	check_size = copy_file(path);
+	if (size != check_size)
+		die("error in size of file '%s'", path);
+
+}
+
+static void read_ftrace_printk(void)
+{
+	unsigned int size, check_size;
+	char *path;
+	struct stat st;
+	int ret;
+
+	path = get_tracing_file("printk_formats");
+	ret = stat(path, &st);
+	if (ret < 0) {
+		/* not found */
+		size = 0;
+		write_or_die(&size, 4);
+		goto out;
+	}
+	size = get_size(path);
+	write_or_die(&size, 4);
+	check_size = copy_file(path);
+	if (size != check_size)
+		die("error in size of file '%s'", path);
+out:
+	put_tracing_file(path);
+}
+
+static struct tracepoint_path *
+get_tracepoints_path(struct perf_event_attr *pattrs, int nb_events)
+{
+	struct tracepoint_path path, *ppath = &path;
+	int i, nr_tracepoints = 0;
+
+	for (i = 0; i < nb_events; i++) {
+		if (pattrs[i].type != PERF_TYPE_TRACEPOINT)
+			continue;
+		++nr_tracepoints;
+		ppath->next = tracepoint_id_to_path(pattrs[i].config);
+		if (!ppath->next)
+			die("%s\n", "No memory to alloc tracepoints list");
+		ppath = ppath->next;
+	}
+
+	return nr_tracepoints > 0 ? path.next : NULL;
+}
+
+bool have_tracepoints(struct perf_event_attr *pattrs, int nb_events)
+{
+	int i;
+
+	for (i = 0; i < nb_events; i++)
+		if (pattrs[i].type == PERF_TYPE_TRACEPOINT)
+			return true;
+
+	return false;
+}
+
+int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events)
+{
+	char buf[BUFSIZ];
+	struct tracepoint_path *tps = get_tracepoints_path(pattrs, nb_events);
+
+	/*
+	 * What? No tracepoints? No sense writing anything here, bail out.
+	 */
+	if (tps == NULL)
+		return -1;
+
+	output_fd = fd;
+
+	buf[0] = 23;
+	buf[1] = 8;
+	buf[2] = 68;
+	memcpy(buf + 3, "tracing", 7);
+
+	write_or_die(buf, 10);
+
+	write_or_die(VERSION, strlen(VERSION) + 1);
+
+	/* save endian */
+	if (bigendian())
+		buf[0] = 1;
+	else
+		buf[0] = 0;
+
+	write_or_die(buf, 1);
+
+	/* save size of long */
+	buf[0] = sizeof(long);
+	write_or_die(buf, 1);
+
+	/* save page_size */
+	page_size = sysconf(_SC_PAGESIZE);
+	write_or_die(&page_size, 4);
+
+	read_header_files();
+	read_ftrace_files(tps);
+	read_event_files(tps);
+	read_proc_kallsyms();
+	read_ftrace_printk();
+
+	return 0;
+}
+
+ssize_t read_tracing_data_size(int fd, struct perf_event_attr *pattrs,
+			       int nb_events)
+{
+	ssize_t size;
+	int err = 0;
+
+	calc_data_size = 1;
+	err = read_tracing_data(fd, pattrs, nb_events);
+	size = calc_data_size - 1;
+	calc_data_size = 0;
+
+	if (err < 0)
+		return err;
+
+	return size;
+}
tools/lib/trace/trace-event-parse.c new file +3233 -0
new file mode 100644
index 0000000..d76c350
@@ -0,0 +1,3233 @@
+/*
+ * Copyright (C) 2009, Steven Rostedt <[email protected]>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License (not later!)
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  The parts for function graph printing was taken and modified from the
+ *  Linux Kernel that were written by Frederic Weisbecker.
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+
+#undef _GNU_SOURCE
+#include <perf.h>
+#include <lk/util.h>
+#include <util/trace-event.h>
+
+int header_page_ts_offset;
+int header_page_ts_size;
+int header_page_size_offset;
+int header_page_size_size;
+int header_page_overwrite_offset;
+int header_page_overwrite_size;
+int header_page_data_offset;
+int header_page_data_size;
+
+bool latency_format;
+
+static char *input_buf;
+static unsigned long long input_buf_ptr;
+static unsigned long long input_buf_siz;
+
+static int cpus;
+static int long_size;
+static int is_flag_field;
+static int is_symbolic_field;
+
+static struct format_field *
+find_any_field(struct event *event, const char *name);
+
+static void init_input_buf(char *buf, unsigned long long size)
+{
+	input_buf = buf;
+	input_buf_siz = size;
+	input_buf_ptr = 0;
+}
+
+struct cmdline {
+	char *comm;
+	int pid;
+};
+
+static struct cmdline *cmdlines;
+static int cmdline_count;
+
+static int cmdline_cmp(const void *a, const void *b)
+{
+	const struct cmdline *ca = a;
+	const struct cmdline *cb = b;
+
+	if (ca->pid < cb->pid)
+		return -1;
+	if (ca->pid > cb->pid)
+		return 1;
+
+	return 0;
+}
+
+void parse_cmdlines(char *file, int size __unused)
+{
+	struct cmdline_list {
+		struct cmdline_list	*next;
+		char			*comm;
+		int			pid;
+	} *list = NULL, *item;
+	char *line;
+	char *next = NULL;
+	int i;
+
+	line = strtok_r(file, "\n", &next);
+	while (line) {
+		item = malloc_or_die(sizeof(*item));
+		sscanf(line, "%d %as", &item->pid,
+		       (float *)(void *)&item->comm); /* workaround gcc warning */
+		item->next = list;
+		list = item;
+		line = strtok_r(NULL, "\n", &next);
+		cmdline_count++;
+	}
+
+	cmdlines = malloc_or_die(sizeof(*cmdlines) * cmdline_count);
+
+	i = 0;
+	while (list) {
+		cmdlines[i].pid = list->pid;
+		cmdlines[i].comm = list->comm;
+		i++;
+		item = list;
+		list = list->next;
+		free(item);
+	}
+
+	qsort(cmdlines, cmdline_count, sizeof(*cmdlines), cmdline_cmp);
+}
+
+static struct func_map {
+	unsigned long long		addr;
+	char				*func;
+	char				*mod;
+} *func_list;
+static unsigned int func_count;
+
+static int func_cmp(const void *a, const void *b)
+{
+	const struct func_map *fa = a;
+	const struct func_map *fb = b;
+
+	if (fa->addr < fb->addr)
+		return -1;
+	if (fa->addr > fb->addr)
+		return 1;
+
+	return 0;
+}
+
+void parse_proc_kallsyms(char *file, unsigned int size __unused)
+{
+	struct func_list {
+		struct func_list	*next;
+		unsigned long long	addr;
+		char			*func;
+		char			*mod;
+	} *list = NULL, *item;
+	char *line;
+	char *next = NULL;
+	char *addr_str;
+	char ch;
+	int ret;
+	int i;
+
+	line = strtok_r(file, "\n", &next);
+	while (line) {
+		item = malloc_or_die(sizeof(*item));
+		item->mod = NULL;
+		ret = sscanf(line, "%as %c %as\t[%as",
+			     (float *)(void *)&addr_str, /* workaround gcc warning */
+			     &ch,
+			     (float *)(void *)&item->func,
+			     (float *)(void *)&item->mod);
+		item->addr = strtoull(addr_str, NULL, 16);
+		free(addr_str);
+
+		/* truncate the extra ']' */
+		if (item->mod)
+			item->mod[strlen(item->mod) - 1] = 0;
+
+
+		item->next = list;
+		list = item;
+		line = strtok_r(NULL, "\n", &next);
+		func_count++;
+	}
+
+	func_list = malloc_or_die(sizeof(*func_list) * (func_count + 1));
+
+	i = 0;
+	while (list) {
+		func_list[i].func = list->func;
+		func_list[i].addr = list->addr;
+		func_list[i].mod = list->mod;
+		i++;
+		item = list;
+		list = list->next;
+		free(item);
+	}
+
+	qsort(func_list, func_count, sizeof(*func_list), func_cmp);
+
+	/*
+	 * Add a special record at the end.
+	 */
+	func_list[func_count].func = NULL;
+	func_list[func_count].addr = 0;
+	func_list[func_count].mod = NULL;
+}
+
+/*
+ * We are searching for a record in between, not an exact
+ * match.
+ */
+static int func_bcmp(const void *a, const void *b)
+{
+	const struct func_map *fa = a;
+	const struct func_map *fb = b;
+
+	if ((fa->addr == fb->addr) ||
+
+	    (fa->addr > fb->addr &&
+	     fa->addr < (fb+1)->addr))
+		return 0;
+
+	if (fa->addr < fb->addr)
+		return -1;
+
+	return 1;
+}
+
+static struct func_map *find_func(unsigned long long addr)
+{
+	struct func_map *func;
+	struct func_map key;
+
+	key.addr = addr;
+
+	func = bsearch(&key, func_list, func_count, sizeof(*func_list),
+		       func_bcmp);
+
+	return func;
+}
+
+void print_funcs(void)
+{
+	int i;
+
+	for (i = 0; i < (int)func_count; i++) {
+		printf("%016llx %s",
+		       func_list[i].addr,
+		       func_list[i].func);
+		if (func_list[i].mod)
+			printf(" [%s]\n", func_list[i].mod);
+		else
+			printf("\n");
+	}
+}
+
+static struct printk_map {
+	unsigned long long		addr;
+	char				*printk;
+} *printk_list;
+static unsigned int printk_count;
+
+static int printk_cmp(const void *a, const void *b)
+{
+	const struct func_map *fa = a;
+	const struct func_map *fb = b;
+
+	if (fa->addr < fb->addr)
+		return -1;
+	if (fa->addr > fb->addr)
+		return 1;
+
+	return 0;
+}
+
+static struct printk_map *find_printk(unsigned long long addr)
+{
+	struct printk_map *printk;
+	struct printk_map key;
+
+	key.addr = addr;
+
+	printk = bsearch(&key, printk_list, printk_count, sizeof(*printk_list),
+			 printk_cmp);
+
+	return printk;
+}
+
+void parse_ftrace_printk(char *file, unsigned int size __unused)
+{
+	struct printk_list {
+		struct printk_list	*next;
+		unsigned long long	addr;
+		char			*printk;
+	} *list = NULL, *item;
+	char *line;
+	char *next = NULL;
+	char *addr_str;
+	int i;
+
+	line = strtok_r(file, "\n", &next);
+	while (line) {
+		addr_str = strsep(&line, ":");
+		if (!line) {
+			warning("error parsing print strings");
+			break;
+		}
+		item = malloc_or_die(sizeof(*item));
+		item->addr = strtoull(addr_str, NULL, 16);
+		/* fmt still has a space, skip it */
+		item->printk = strdup(line+1);
+		item->next = list;
+		list = item;
+		line = strtok_r(NULL, "\n", &next);
+		printk_count++;
+	}
+
+	printk_list = malloc_or_die(sizeof(*printk_list) * printk_count + 1);
+
+	i = 0;
+	while (list) {
+		printk_list[i].printk = list->printk;
+		printk_list[i].addr = list->addr;
+		i++;
+		item = list;
+		list = list->next;
+		free(item);
+	}
+
+	qsort(printk_list, printk_count, sizeof(*printk_list), printk_cmp);
+}
+
+void print_printk(void)
+{
+	int i;
+
+	for (i = 0; i < (int)printk_count; i++) {
+		printf("%016llx %s\n",
+		       printk_list[i].addr,
+		       printk_list[i].printk);
+	}
+}
+
+static struct event *alloc_event(void)
+{
+	struct event *event;
+
+	event = malloc_or_die(sizeof(*event));
+	memset(event, 0, sizeof(*event));
+
+	return event;
+}
+
+enum event_type {
+	EVENT_ERROR,
+	EVENT_NONE,
+	EVENT_SPACE,
+	EVENT_NEWLINE,
+	EVENT_OP,
+	EVENT_DELIM,
+	EVENT_ITEM,
+	EVENT_DQUOTE,
+	EVENT_SQUOTE,
+};
+
+static struct event *event_list;
+
+static void add_event(struct event *event)
+{
+	event->next = event_list;
+	event_list = event;
+}
+
+static int event_item_type(enum event_type type)
+{
+	switch (type) {
+	case EVENT_ITEM ... EVENT_SQUOTE:
+		return 1;
+	case EVENT_ERROR ... EVENT_DELIM:
+	default:
+		return 0;
+	}
+}
+
+static void free_arg(struct print_arg *arg)
+{
+	if (!arg)
+		return;
+
+	switch (arg->type) {
+	case PRINT_ATOM:
+		if (arg->atom.atom)
+			free(arg->atom.atom);
+		break;
+	case PRINT_NULL:
+	case PRINT_FIELD ... PRINT_OP:
+	default:
+		/* todo */
+		break;
+	}
+
+	free(arg);
+}
+
+static enum event_type get_type(int ch)
+{
+	if (ch == '\n')
+		return EVENT_NEWLINE;
+	if (isspace(ch))
+		return EVENT_SPACE;
+	if (isalnum(ch) || ch == '_')
+		return EVENT_ITEM;
+	if (ch == '\'')
+		return EVENT_SQUOTE;
+	if (ch == '"')
+		return EVENT_DQUOTE;
+	if (!isprint(ch))
+		return EVENT_NONE;
+	if (ch == '(' || ch == ')' || ch == ',')
+		return EVENT_DELIM;
+
+	return EVENT_OP;
+}
+
+static int __read_char(void)
+{
+	if (input_buf_ptr >= input_buf_siz)
+		return -1;
+
+	return input_buf[input_buf_ptr++];
+}
+
+static int __peek_char(void)
+{
+	if (input_buf_ptr >= input_buf_siz)
+		return -1;
+
+	return input_buf[input_buf_ptr];
+}
+
+static enum event_type __read_token(char **tok)
+{
+	char buf[BUFSIZ];
+	int ch, last_ch, quote_ch, next_ch;
+	int i = 0;
+	int tok_size = 0;
+	enum event_type type;
+
+	*tok = NULL;
+
+
+	ch = __read_char();
+	if (ch < 0)
+		return EVENT_NONE;
+
+	type = get_type(ch);
+	if (type == EVENT_NONE)
+		return type;
+
+	buf[i++] = ch;
+
+	switch (type) {
+	case EVENT_NEWLINE:
+	case EVENT_DELIM:
+		*tok = malloc_or_die(2);
+		(*tok)[0] = ch;
+		(*tok)[1] = 0;
+		return type;
+
+	case EVENT_OP:
+		switch (ch) {
+		case '-':
+			next_ch = __peek_char();
+			if (next_ch == '>') {
+				buf[i++] = __read_char();
+				break;
+			}
+			/* fall through */
+		case '+':
+		case '|':
+		case '&':
+		case '>':
+		case '<':
+			last_ch = ch;
+			ch = __peek_char();
+			if (ch != last_ch)
+				goto test_equal;
+			buf[i++] = __read_char();
+			switch (last_ch) {
+			case '>':
+			case '<':
+				goto test_equal;
+			default:
+				break;
+			}
+			break;
+		case '!':
+		case '=':
+			goto test_equal;
+		default: /* what should we do instead? */
+			break;
+		}
+		buf[i] = 0;
+		*tok = strdup(buf);
+		return type;
+
+ test_equal:
+		ch = __peek_char();
+		if (ch == '=')
+			buf[i++] = __read_char();
+		break;
+
+	case EVENT_DQUOTE:
+	case EVENT_SQUOTE:
+		/* don't keep quotes */
+		i--;
+		quote_ch = ch;
+		last_ch = 0;
+		do {
+			if (i == (BUFSIZ - 1)) {
+				buf[i] = 0;
+				if (*tok) {
+					*tok = realloc(*tok, tok_size + BUFSIZ);
+					if (!*tok)
+						return EVENT_NONE;
+					strcat(*tok, buf);
+				} else
+					*tok = strdup(buf);
+
+				if (!*tok)
+					return EVENT_NONE;
+				tok_size += BUFSIZ;
+				i = 0;
+			}
+			last_ch = ch;
+			ch = __read_char();
+			buf[i++] = ch;
+			/* the '\' '\' will cancel itself */
+			if (ch == '\\' && last_ch == '\\')
+				last_ch = 0;
+		} while (ch != quote_ch || last_ch == '\\');
+		/* remove the last quote */
+		i--;
+		goto out;
+
+	case EVENT_ERROR ... EVENT_SPACE:
+	case EVENT_ITEM:
+	default:
+		break;
+	}
+
+	while (get_type(__peek_char()) == type) {
+		if (i == (BUFSIZ - 1)) {
+			buf[i] = 0;
+			if (*tok) {
+				*tok = realloc(*tok, tok_size + BUFSIZ);
+				if (!*tok)
+					return EVENT_NONE;
+				strcat(*tok, buf);
+			} else
+				*tok = strdup(buf);
+
+			if (!*tok)
+				return EVENT_NONE;
+			tok_size += BUFSIZ;
+			i = 0;
+		}
+		ch = __read_char();
+		buf[i++] = ch;
+	}
+
+ out:
+	buf[i] = 0;
+	if (*tok) {
+		*tok = realloc(*tok, tok_size + i);
+		if (!*tok)
+			return EVENT_NONE;
+		strcat(*tok, buf);
+	} else
+		*tok = strdup(buf);
+	if (!*tok)
+		return EVENT_NONE;
+
+	return type;
+}
+
+static void free_token(char *tok)
+{
+	if (tok)
+		free(tok);
+}
+
+static enum event_type read_token(char **tok)
+{
+	enum event_type type;
+
+	for (;;) {
+		type = __read_token(tok);
+		if (type != EVENT_SPACE)
+			return type;
+
+		free_token(*tok);
+	}
+
+	/* not reached */
+	return EVENT_NONE;
+}
+
+/* no newline */
+static enum event_type read_token_item(char **tok)
+{
+	enum event_type type;
+
+	for (;;) {
+		type = __read_token(tok);
+		if (type != EVENT_SPACE && type != EVENT_NEWLINE)
+			return type;
+
+		free_token(*tok);
+	}
+
+	/* not reached */
+	return EVENT_NONE;
+}
+
+static int test_type(enum event_type type, enum event_type expect)
+{
+	if (type != expect) {
+		warning("Error: expected type %d but read %d",
+		    expect, type);
+		return -1;
+	}
+	return 0;
+}
+
+static int __test_type_token(enum event_type type, char *token,
+			     enum event_type expect, const char *expect_tok,
+			     bool warn)
+{
+	if (type != expect) {
+		if (warn)
+			warning("Error: expected type %d but read %d",
+				expect, type);
+		return -1;
+	}
+
+	if (strcmp(token, expect_tok) != 0) {
+		if (warn)
+			warning("Error: expected '%s' but read '%s'",
+				expect_tok, token);
+		return -1;
+	}
+	return 0;
+}
+
+static int test_type_token(enum event_type type, char *token,
+			   enum event_type expect, const char *expect_tok)
+{
+	return __test_type_token(type, token, expect, expect_tok, true);
+}
+
+static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
+{
+	enum event_type type;
+
+	if (newline_ok)
+		type = read_token(tok);
+	else
+		type = read_token_item(tok);
+	return test_type(type, expect);
+}
+
+static int read_expect_type(enum event_type expect, char **tok)
+{
+	return __read_expect_type(expect, tok, 1);
+}
+
+static int __read_expected(enum event_type expect, const char *str,
+			   int newline_ok, bool warn)
+{
+	enum event_type type;
+	char *token;
+	int ret;
+
+	if (newline_ok)
+		type = read_token(&token);
+	else
+		type = read_token_item(&token);
+
+	ret = __test_type_token(type, token, expect, str, warn);
+
+	free_token(token);
+
+	return ret;
+}
+
+static int read_expected(enum event_type expect, const char *str)
+{
+	return __read_expected(expect, str, 1, true);
+}
+
+static int read_expected_item(enum event_type expect, const char *str)
+{
+	return __read_expected(expect, str, 0, true);
+}
+
+static char *event_read_name(void)
+{
+	char *token;
+
+	if (read_expected(EVENT_ITEM, "name") < 0)
+		return NULL;
+
+	if (read_expected(EVENT_OP, ":") < 0)
+		return NULL;
+
+	if (read_expect_type(EVENT_ITEM, &token) < 0)
+		goto fail;
+
+	return token;
+
+ fail:
+	free_token(token);
+	return NULL;
+}
+
+static int event_read_id(void)
+{
+	char *token;
+	int id;
+
+	if (read_expected_item(EVENT_ITEM, "ID") < 0)
+		return -1;
+
+	if (read_expected(EVENT_OP, ":") < 0)
+		return -1;
+
+	if (read_expect_type(EVENT_ITEM, &token) < 0)
+		goto fail;
+
+	id = strtoul(token, NULL, 0);
+	free_token(token);
+	return id;
+
+ fail:
+	free_token(token);
+	return -1;
+}
+
+static int field_is_string(struct format_field *field)
+{
+	if ((field->flags & FIELD_IS_ARRAY) &&
+	    (!strstr(field->type, "char") || !strstr(field->type, "u8") ||
+	     !strstr(field->type, "s8")))
+		return 1;
+
+	return 0;
+}
+
+static int field_is_dynamic(struct format_field *field)
+{
+	if (!strncmp(field->type, "__data_loc", 10))
+		return 1;
+
+	return 0;
+}
+
+static int event_read_fields(struct event *event, struct format_field **fields)
+{
+	struct format_field *field = NULL;
+	enum event_type type;
+	char *token;
+	char *last_token;
+	int count = 0;
+
+	do {
+		type = read_token(&token);
+		if (type == EVENT_NEWLINE) {
+			free_token(token);
+			return count;
+		}
+
+		count++;
+
+		if (test_type_token(type, token, EVENT_ITEM, "field"))
+			goto fail;
+		free_token(token);
+
+		type = read_token(&token);
+		/*
+		 * The ftrace fields may still use the "special" name.
+		 * Just ignore it.
+		 */
+		if (event->flags & EVENT_FL_ISFTRACE &&
+		    type == EVENT_ITEM && strcmp(token, "special") == 0) {
+			free_token(token);
+			type = read_token(&token);
+		}
+
+		if (test_type_token(type, token, EVENT_OP, ":") < 0)
+			return -1;
+
+		if (read_expect_type(EVENT_ITEM, &token) < 0)
+			goto fail;
+
+		last_token = token;
+
+		field = malloc_or_die(sizeof(*field));
+		memset(field, 0, sizeof(*field));
+
+		/* read the rest of the type */
+		for (;;) {
+			type = read_token(&token);
+			if (type == EVENT_ITEM ||
+			    (type == EVENT_OP && strcmp(token, "*") == 0) ||
+			    /*
+			     * Some of the ftrace fields are broken and have
+			     * an illegal "." in them.
+			     */
+			    (event->flags & EVENT_FL_ISFTRACE &&
+			     type == EVENT_OP && strcmp(token, ".") == 0)) {
+
+				if (strcmp(token, "*") == 0)
+					field->flags |= FIELD_IS_POINTER;
+
+				if (field->type) {
+					field->type = realloc(field->type,
+							      strlen(field->type) +
+							      strlen(last_token) + 2);
+					strcat(field->type, " ");
+					strcat(field->type, last_token);
+				} else
+					field->type = last_token;
+				last_token = token;
+				continue;
+			}
+
+			break;
+		}
+
+		if (!field->type) {
+			die("no type found");
+			goto fail;
+		}
+		field->name = last_token;
+
+		if (test_type(type, EVENT_OP))
+			goto fail;
+
+		if (strcmp(token, "[") == 0) {
+			enum event_type last_type = type;
+			char *brackets = token;
+			int len;
+
+			field->flags |= FIELD_IS_ARRAY;
+
+			type = read_token(&token);
+		        while (strcmp(token, "]") != 0) {
+				if (last_type == EVENT_ITEM &&
+				    type == EVENT_ITEM)
+					len = 2;
+				else
+					len = 1;
+				last_type = type;
+
+				brackets = realloc(brackets,
+						   strlen(brackets) +
+						   strlen(token) + len);
+				if (len == 2)
+					strcat(brackets, " ");
+				strcat(brackets, token);
+				free_token(token);
+				type = read_token(&token);
+				if (type == EVENT_NONE) {
+					die("failed to find token");
+					goto fail;
+				}
+			}
+
+			free_token(token);
+
+			brackets = realloc(brackets, strlen(brackets) + 2);
+			strcat(brackets, "]");
+
+			/* add brackets to type */
+
+			type = read_token(&token);
+			/*
+			 * If the next token is not an OP, then it is of
+			 * the format: type [] item;
+			 */
+			if (type == EVENT_ITEM) {
+				field->type = realloc(field->type,
+						      strlen(field->type) +
+						      strlen(field->name) +
+						      strlen(brackets) + 2);
+				strcat(field->type, " ");
+				strcat(field->type, field->name);
+				free_token(field->name);
+				strcat(field->type, brackets);
+				field->name = token;
+				type = read_token(&token);
+			} else {
+				field->type = realloc(field->type,
+						      strlen(field->type) +
+						      strlen(brackets) + 1);
+				strcat(field->type, brackets);
+			}
+			free(brackets);
+		}
+
+		if (field_is_string(field)) {
+			field->flags |= FIELD_IS_STRING;
+			if (field_is_dynamic(field))
+				field->flags |= FIELD_IS_DYNAMIC;
+		}
+
+		if (test_type_token(type, token,  EVENT_OP, ";"))
+			goto fail;
+		free_token(token);
+
+		if (read_expected(EVENT_ITEM, "offset") < 0)
+			goto fail_expect;
+
+		if (read_expected(EVENT_OP, ":") < 0)
+			goto fail_expect;
+
+		if (read_expect_type(EVENT_ITEM, &token))
+			goto fail;
+		field->offset = strtoul(token, NULL, 0);
+		free_token(token);
+
+		if (read_expected(EVENT_OP, ";") < 0)
+			goto fail_expect;
+
+		if (read_expected(EVENT_ITEM, "size") < 0)
+			goto fail_expect;
+
+		if (read_expected(EVENT_OP, ":") < 0)
+			goto fail_expect;
+
+		if (read_expect_type(EVENT_ITEM, &token))
+			goto fail;
+		field->size = strtoul(token, NULL, 0);
+		free_token(token);
+
+		if (read_expected(EVENT_OP, ";") < 0)
+			goto fail_expect;
+
+		type = read_token(&token);
+		if (type != EVENT_NEWLINE) {
+			/* newer versions of the kernel have a "signed" type */
+			if (test_type_token(type, token, EVENT_ITEM, "signed"))
+				goto fail;
+
+			free_token(token);
+
+			if (read_expected(EVENT_OP, ":") < 0)
+				goto fail_expect;
+
+			if (read_expect_type(EVENT_ITEM, &token))
+				goto fail;
+
+			if (strtoul(token, NULL, 0))
+				field->flags |= FIELD_IS_SIGNED;
+
+			free_token(token);
+			if (read_expected(EVENT_OP, ";") < 0)
+				goto fail_expect;
+
+			if (read_expect_type(EVENT_NEWLINE, &token))
+				goto fail;
+		}
+
+		free_token(token);
+
+		*fields = field;
+		fields = &field->next;
+
+	} while (1);
+
+	return 0;
+
+fail:
+	free_token(token);
+fail_expect:
+	if (field)
+		free(field);
+	return -1;
+}
+
+static int event_read_format(struct event *event)
+{
+	char *token;
+	int ret;
+
+	if (read_expected_item(EVENT_ITEM, "format") < 0)
+		return -1;
+
+	if (read_expected(EVENT_OP, ":") < 0)
+		return -1;
+
+	if (read_expect_type(EVENT_NEWLINE, &token))
+		goto fail;
+	free_token(token);
+
+	ret = event_read_fields(event, &event->format.common_fields);
+	if (ret < 0)
+		return ret;
+	event->format.nr_common = ret;
+
+	ret = event_read_fields(event, &event->format.fields);
+	if (ret < 0)
+		return ret;
+	event->format.nr_fields = ret;
+
+	return 0;
+
+ fail:
+	free_token(token);
+	return -1;
+}
+
+enum event_type
+process_arg_token(struct event *event, struct print_arg *arg,
+		  char **tok, enum event_type type);
+
+static enum event_type
+process_arg(struct event *event, struct print_arg *arg, char **tok)
+{
+	enum event_type type;
+	char *token;
+
+	type = read_token(&token);
+	*tok = token;
+
+	return process_arg_token(event, arg, tok, type);
+}
+
+static enum event_type
+process_cond(struct event *event, struct print_arg *top, char **tok)
+{
+	struct print_arg *arg, *left, *right;
+	enum event_type type;
+	char *token = NULL;
+
+	arg = malloc_or_die(sizeof(*arg));
+	memset(arg, 0, sizeof(*arg));
+
+	left = malloc_or_die(sizeof(*left));
+
+	right = malloc_or_die(sizeof(*right));
+
+	arg->type = PRINT_OP;
+	arg->op.left = left;
+	arg->op.right = right;
+
+	*tok = NULL;
+	type = process_arg(event, left, &token);
+	if (test_type_token(type, token, EVENT_OP, ":"))
+		goto out_free;
+
+	arg->op.op = token;
+
+	type = process_arg(event, right, &token);
+
+	top->op.right = arg;
+
+	*tok = token;
+	return type;
+
+out_free:
+	free_token(*tok);
+	free(right);
+	free(left);
+	free_arg(arg);
+	return EVENT_ERROR;
+}
+
+static enum event_type
+process_array(struct event *event, struct print_arg *top, char **tok)
+{
+	struct print_arg *arg;
+	enum event_type type;
+	char *token = NULL;
+
+	arg = malloc_or_die(sizeof(*arg));
+	memset(arg, 0, sizeof(*arg));
+
+	*tok = NULL;
+	type = process_arg(event, arg, &token);
+	if (test_type_token(type, token, EVENT_OP, "]"))
+		goto out_free;
+
+	top->op.right = arg;
+
+	free_token(token);
+	type = read_token_item(&token);
+	*tok = token;
+
+	return type;
+
+out_free:
+	free_token(*tok);
+	free_arg(arg);
+	return EVENT_ERROR;
+}
+
+static int get_op_prio(char *op)
+{
+	if (!op[1]) {
+		switch (op[0]) {
+		case '*':
+		case '/':
+		case '%':
+			return 6;
+		case '+':
+		case '-':
+			return 7;
+			/* '>>' and '<<' are 8 */
+		case '<':
+		case '>':
+			return 9;
+			/* '==' and '!=' are 10 */
+		case '&':
+			return 11;
+		case '^':
+			return 12;
+		case '|':
+			return 13;
+		case '?':
+			return 16;
+		default:
+			die("unknown op '%c'", op[0]);
+			return -1;
+		}
+	} else {
+		if (strcmp(op, "++") == 0 ||
+		    strcmp(op, "--") == 0) {
+			return 3;
+		} else if (strcmp(op, ">>") == 0 ||
+			   strcmp(op, "<<") == 0) {
+			return 8;
+		} else if (strcmp(op, ">=") == 0 ||
+			   strcmp(op, "<=") == 0) {
+			return 9;
+		} else if (strcmp(op, "==") == 0 ||
+			   strcmp(op, "!=") == 0) {
+			return 10;
+		} else if (strcmp(op, "&&") == 0) {
+			return 14;
+		} else if (strcmp(op, "||") == 0) {
+			return 15;
+		} else {
+			die("unknown op '%s'", op);
+			return -1;
+		}
+	}
+}
+
+static void set_op_prio(struct print_arg *arg)
+{
+
+	/* single ops are the greatest */
+	if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
+		arg->op.prio = 0;
+		return;
+	}
+
+	arg->op.prio = get_op_prio(arg->op.op);
+}
+
+static enum event_type
+process_op(struct event *event, struct print_arg *arg, char **tok)
+{
+	struct print_arg *left, *right = NULL;
+	enum event_type type;
+	char *token;
+
+	/* the op is passed in via tok */
+	token = *tok;
+
+	if (arg->type == PRINT_OP && !arg->op.left) {
+		/* handle single op */
+		if (token[1]) {
+			die("bad op token %s", token);
+			return EVENT_ERROR;
+		}
+		switch (token[0]) {
+		case '!':
+		case '+':
+		case '-':
+			break;
+		default:
+			die("bad op token %s", token);
+			return EVENT_ERROR;
+		}
+
+		/* make an empty left */
+		left = malloc_or_die(sizeof(*left));
+		left->type = PRINT_NULL;
+		arg->op.left = left;
+
+		right = malloc_or_die(sizeof(*right));
+		arg->op.right = right;
+
+		type = process_arg(event, right, tok);
+
+	} else if (strcmp(token, "?") == 0) {
+
+		left = malloc_or_die(sizeof(*left));
+		/* copy the top arg to the left */
+		*left = *arg;
+
+		arg->type = PRINT_OP;
+		arg->op.op = token;
+		arg->op.left = left;
+		arg->op.prio = 0;
+
+		type = process_cond(event, arg, tok);
+
+	} else if (strcmp(token, ">>") == 0 ||
+		   strcmp(token, "<<") == 0 ||
+		   strcmp(token, "&") == 0 ||
+		   strcmp(token, "|") == 0 ||
+		   strcmp(token, "&&") == 0 ||
+		   strcmp(token, "||") == 0 ||
+		   strcmp(token, "-") == 0 ||
+		   strcmp(token, "+") == 0 ||
+		   strcmp(token, "*") == 0 ||
+		   strcmp(token, "^") == 0 ||
+		   strcmp(token, "/") == 0 ||
+		   strcmp(token, "<") == 0 ||
+		   strcmp(token, ">") == 0 ||
+		   strcmp(token, "==") == 0 ||
+		   strcmp(token, "!=") == 0) {
+
+		left = malloc_or_die(sizeof(*left));
+
+		/* copy the top arg to the left */
+		*left = *arg;
+
+		arg->type = PRINT_OP;
+		arg->op.op = token;
+		arg->op.left = left;
+
+		set_op_prio(arg);
+
+		right = malloc_or_die(sizeof(*right));
+
+		type = read_token_item(&token);
+		*tok = token;
+
+		/* could just be a type pointer */
+		if ((strcmp(arg->op.op, "*") == 0) &&
+		    type == EVENT_DELIM && (strcmp(token, ")") == 0)) {
+			if (left->type != PRINT_ATOM)
+				die("bad pointer type");
+			left->atom.atom = realloc(left->atom.atom,
+					    sizeof(left->atom.atom) + 3);
+			strcat(left->atom.atom, " *");
+			*arg = *left;
+			free(arg);
+
+			return type;
+		}
+
+		type = process_arg_token(event, right, tok, type);
+
+		arg->op.right = right;
+
+	} else if (strcmp(token, "[") == 0) {
+
+		left = malloc_or_die(sizeof(*left));
+		*left = *arg;
+
+		arg->type = PRINT_OP;
+		arg->op.op = token;
+		arg->op.left = left;
+
+		arg->op.prio = 0;
+		type = process_array(event, arg, tok);
+
+	} else {
+		warning("unknown op '%s'", token);
+		event->flags |= EVENT_FL_FAILED;
+		/* the arg is now the left side */
+		return EVENT_NONE;
+	}
+
+	if (type == EVENT_OP) {
+		int prio;
+
+		/* higher prios need to be closer to the root */
+		prio = get_op_prio(*tok);
+
+		if (prio > arg->op.prio)
+			return process_op(event, arg, tok);
+
+		return process_op(event, right, tok);
+	}
+
+	return type;
+}
+
+static enum event_type
+process_entry(struct event *event __unused, struct print_arg *arg,
+	      char **tok)
+{
+	enum event_type type;
+	char *field;
+	char *token;
+
+	if (read_expected(EVENT_OP, "->") < 0)
+		return EVENT_ERROR;
+
+	if (read_expect_type(EVENT_ITEM, &token) < 0)
+		goto fail;
+	field = token;
+
+	arg->type = PRINT_FIELD;
+	arg->field.name = field;
+
+	if (is_flag_field) {
+		arg->field.field = find_any_field(event, arg->field.name);
+		arg->field.field->flags |= FIELD_IS_FLAG;
+		is_flag_field = 0;
+	} else if (is_symbolic_field) {
+		arg->field.field = find_any_field(event, arg->field.name);
+		arg->field.field->flags |= FIELD_IS_SYMBOLIC;
+		is_symbolic_field = 0;
+	}
+
+	type = read_token(&token);
+	*tok = token;
+
+	return type;
+
+fail:
+	free_token(token);
+	return EVENT_ERROR;
+}
+
+static char *arg_eval (struct print_arg *arg);
+
+static long long arg_num_eval(struct print_arg *arg)
+{
+	long long left, right;
+	long long val = 0;
+
+	switch (arg->type) {
+	case PRINT_ATOM:
+		val = strtoll(arg->atom.atom, NULL, 0);
+		break;
+	case PRINT_TYPE:
+		val = arg_num_eval(arg->typecast.item);
+		break;
+	case PRINT_OP:
+		switch (arg->op.op[0]) {
+		case '|':
+			left = arg_num_eval(arg->op.left);
+			right = arg_num_eval(arg->op.right);
+			if (arg->op.op[1])
+				val = left || right;
+			else
+				val = left | right;
+			break;
+		case '&':
+			left = arg_num_eval(arg->op.left);
+			right = arg_num_eval(arg->op.right);
+			if (arg->op.op[1])
+				val = left && right;
+			else
+				val = left & right;
+			break;
+		case '<':
+			left = arg_num_eval(arg->op.left);
+			right = arg_num_eval(arg->op.right);
+			switch (arg->op.op[1]) {
+			case 0:
+				val = left < right;
+				break;
+			case '<':
+				val = left << right;
+				break;
+			case '=':
+				val = left <= right;
+				break;
+			default:
+				die("unknown op '%s'", arg->op.op);
+			}
+			break;
+		case '>':
+			left = arg_num_eval(arg->op.left);
+			right = arg_num_eval(arg->op.right);
+			switch (arg->op.op[1]) {
+			case 0:
+				val = left > right;
+				break;
+			case '>':
+				val = left >> right;
+				break;
+			case '=':
+				val = left >= right;
+				break;
+			default:
+				die("unknown op '%s'", arg->op.op);
+			}
+			break;
+		case '=':
+			left = arg_num_eval(arg->op.left);
+			right = arg_num_eval(arg->op.right);
+
+			if (arg->op.op[1] != '=')
+				die("unknown op '%s'", arg->op.op);
+
+			val = left == right;
+			break;
+		case '!':
+			left = arg_num_eval(arg->op.left);
+			right = arg_num_eval(arg->op.right);
+
+			switch (arg->op.op[1]) {
+			case '=':
+				val = left != right;
+				break;
+			default:
+				die("unknown op '%s'", arg->op.op);
+			}
+			break;
+		default:
+			die("unknown op '%s'", arg->op.op);
+		}
+		break;
+
+	case PRINT_NULL:
+	case PRINT_FIELD ... PRINT_SYMBOL:
+	case PRINT_STRING:
+	default:
+		die("invalid eval type %d", arg->type);
+
+	}
+	return val;
+}
+
+static char *arg_eval (struct print_arg *arg)
+{
+	long long val;
+	static char buf[20];
+
+	switch (arg->type) {
+	case PRINT_ATOM:
+		return arg->atom.atom;
+	case PRINT_TYPE:
+		return arg_eval(arg->typecast.item);
+	case PRINT_OP:
+		val = arg_num_eval(arg);
+		sprintf(buf, "%lld", val);
+		return buf;
+
+	case PRINT_NULL:
+	case PRINT_FIELD ... PRINT_SYMBOL:
+	case PRINT_STRING:
+	default:
+		die("invalid eval type %d", arg->type);
+		break;
+	}
+
+	return NULL;
+}
+
+static enum event_type
+process_fields(struct event *event, struct print_flag_sym **list, char **tok)
+{
+	enum event_type type;
+	struct print_arg *arg = NULL;
+	struct print_flag_sym *field;
+	char *token = NULL;
+	char *value;
+
+	do {
+		free_token(token);
+		type = read_token_item(&token);
+		if (test_type_token(type, token, EVENT_OP, "{"))
+			break;
+
+		arg = malloc_or_die(sizeof(*arg));
+
+		free_token(token);
+		type = process_arg(event, arg, &token);
+		if (test_type_token(type, token, EVENT_DELIM, ","))
+			goto out_free;
+
+		field = malloc_or_die(sizeof(*field));
+		memset(field, 0, sizeof(*field));
+
+		value = arg_eval(arg);
+		field->value = strdup(value);
+
+		free_token(token);
+		type = process_arg(event, arg, &token);
+		if (test_type_token(type, token, EVENT_OP, "}"))
+			goto out_free;
+
+		value = arg_eval(arg);
+		field->str = strdup(value);
+		free_arg(arg);
+		arg = NULL;
+
+		*list = field;
+		list = &field->next;
+
+		free_token(token);
+		type = read_token_item(&token);
+	} while (type == EVENT_DELIM && strcmp(token, ",") == 0);
+
+	*tok = token;
+	return type;
+
+out_free:
+	free_arg(arg);
+	free_token(token);
+
+	return EVENT_ERROR;
+}
+
+static enum event_type
+process_flags(struct event *event, struct print_arg *arg, char **tok)
+{
+	struct print_arg *field;
+	enum event_type type;
+	char *token;
+
+	memset(arg, 0, sizeof(*arg));
+	arg->type = PRINT_FLAGS;
+
+	if (read_expected_item(EVENT_DELIM, "(") < 0)
+		return EVENT_ERROR;
+
+	field = malloc_or_die(sizeof(*field));
+
+	type = process_arg(event, field, &token);
+	if (test_type_token(type, token, EVENT_DELIM, ","))
+		goto out_free;
+
+	arg->flags.field = field;
+
+	type = read_token_item(&token);
+	if (event_item_type(type)) {
+		arg->flags.delim = token;
+		type = read_token_item(&token);
+	}
+
+	if (test_type_token(type, token, EVENT_DELIM, ","))
+		goto out_free;
+
+	type = process_fields(event, &arg->flags.flags, &token);
+	if (test_type_token(type, token, EVENT_DELIM, ")"))
+		goto out_free;
+
+	free_token(token);
+	type = read_token_item(tok);
+	return type;
+
+out_free:
+	free_token(token);
+	return EVENT_ERROR;
+}
+
+static enum event_type
+process_symbols(struct event *event, struct print_arg *arg, char **tok)
+{
+	struct print_arg *field;
+	enum event_type type;
+	char *token;
+
+	memset(arg, 0, sizeof(*arg));
+	arg->type = PRINT_SYMBOL;
+
+	if (read_expected_item(EVENT_DELIM, "(") < 0)
+		return EVENT_ERROR;
+
+	field = malloc_or_die(sizeof(*field));
+
+	type = process_arg(event, field, &token);
+	if (test_type_token(type, token, EVENT_DELIM, ","))
+		goto out_free;
+
+	arg->symbol.field = field;
+
+	type = process_fields(event, &arg->symbol.symbols, &token);
+	if (test_type_token(type, token, EVENT_DELIM, ")"))
+		goto out_free;
+
+	free_token(token);
+	type = read_token_item(tok);
+	return type;
+
+out_free:
+	free_token(token);
+	return EVENT_ERROR;
+}
+
+static enum event_type
+process_paren(struct event *event, struct print_arg *arg, char **tok)
+{
+	struct print_arg *item_arg;
+	enum event_type type;
+	char *token;
+
+	type = process_arg(event, arg, &token);
+
+	if (type == EVENT_ERROR)
+		return EVENT_ERROR;
+
+	if (type == EVENT_OP)
+		type = process_op(event, arg, &token);
+
+	if (type == EVENT_ERROR)
+		return EVENT_ERROR;
+
+	if (test_type_token(type, token, EVENT_DELIM, ")")) {
+		free_token(token);
+		return EVENT_ERROR;
+	}
+
+	free_token(token);
+	type = read_token_item(&token);
+
+	/*
+	 * If the next token is an item or another open paren, then
+	 * this was a typecast.
+	 */
+	if (event_item_type(type) ||
+	    (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
+
+		/* make this a typecast and contine */
+
+		/* prevous must be an atom */
+		if (arg->type != PRINT_ATOM)
+			die("previous needed to be PRINT_ATOM");
+
+		item_arg = malloc_or_die(sizeof(*item_arg));
+
+		arg->type = PRINT_TYPE;
+		arg->typecast.type = arg->atom.atom;
+		arg->typecast.item = item_arg;
+		type = process_arg_token(event, item_arg, &token, type);
+
+	}
+
+	*tok = token;
+	return type;
+}
+
+
+static enum event_type
+process_str(struct event *event __unused, struct print_arg *arg, char **tok)
+{
+	enum event_type type;
+	char *token;
+
+	if (read_expected(EVENT_DELIM, "(") < 0)
+		return EVENT_ERROR;
+
+	if (read_expect_type(EVENT_ITEM, &token) < 0)
+		goto fail;
+
+	arg->type = PRINT_STRING;
+	arg->string.string = token;
+	arg->string.offset = -1;
+
+	if (read_expected(EVENT_DELIM, ")") < 0)
+		return EVENT_ERROR;
+
+	type = read_token(&token);
+	*tok = token;
+
+	return type;
+fail:
+	free_token(token);
+	return EVENT_ERROR;
+}
+
+enum event_type
+process_arg_token(struct event *event, struct print_arg *arg,
+		  char **tok, enum event_type type)
+{
+	char *token;
+	char *atom;
+
+	token = *tok;
+
+	switch (type) {
+	case EVENT_ITEM:
+		if (strcmp(token, "REC") == 0) {
+			free_token(token);
+			type = process_entry(event, arg, &token);
+		} else if (strcmp(token, "__print_flags") == 0) {
+			free_token(token);
+			is_flag_field = 1;
+			type = process_flags(event, arg, &token);
+		} else if (strcmp(token, "__print_symbolic") == 0) {
+			free_token(token);
+			is_symbolic_field = 1;
+			type = process_symbols(event, arg, &token);
+		} else if (strcmp(token, "__get_str") == 0) {
+			free_token(token);
+			type = process_str(event, arg, &token);
+		} else {
+			atom = token;
+			/* test the next token */
+			type = read_token_item(&token);
+
+			/* atoms can be more than one token long */
+			while (type == EVENT_ITEM) {
+				atom = realloc(atom, strlen(atom) + strlen(token) + 2);
+				strcat(atom, " ");
+				strcat(atom, token);
+				free_token(token);
+				type = read_token_item(&token);
+			}
+
+			/* todo, test for function */
+
+			arg->type = PRINT_ATOM;
+			arg->atom.atom = atom;
+		}
+		break;
+	case EVENT_DQUOTE:
+	case EVENT_SQUOTE:
+		arg->type = PRINT_ATOM;
+		arg->atom.atom = token;
+		type = read_token_item(&token);
+		break;
+	case EVENT_DELIM:
+		if (strcmp(token, "(") == 0) {
+			free_token(token);
+			type = process_paren(event, arg, &token);
+			break;
+		}
+	case EVENT_OP:
+		/* handle single ops */
+		arg->type = PRINT_OP;
+		arg->op.op = token;
+		arg->op.left = NULL;
+		type = process_op(event, arg, &token);
+
+		break;
+
+	case EVENT_ERROR ... EVENT_NEWLINE:
+	default:
+		die("unexpected type %d", type);
+	}
+	*tok = token;
+
+	return type;
+}
+
+static int event_read_print_args(struct event *event, struct print_arg **list)
+{
+	enum event_type type = EVENT_ERROR;
+	struct print_arg *arg;
+	char *token;
+	int args = 0;
+
+	do {
+		if (type == EVENT_NEWLINE) {
+			free_token(token);
+			type = read_token_item(&token);
+			continue;
+		}
+
+		arg = malloc_or_die(sizeof(*arg));
+		memset(arg, 0, sizeof(*arg));
+
+		type = process_arg(event, arg, &token);
+
+		if (type == EVENT_ERROR) {
+			free_arg(arg);
+			return -1;
+		}
+
+		*list = arg;
+		args++;
+
+		if (type == EVENT_OP) {
+			type = process_op(event, arg, &token);
+			list = &arg->next;
+			continue;
+		}
+
+		if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
+			free_token(token);
+			*list = arg;
+			list = &arg->next;
+			continue;
+		}
+		break;
+	} while (type != EVENT_NONE);
+
+	if (type != EVENT_NONE)
+		free_token(token);
+
+	return args;
+}
+
+static int event_read_print(struct event *event)
+{
+	enum event_type type;
+	char *token;
+	int ret;
+
+	if (read_expected_item(EVENT_ITEM, "print") < 0)
+		return -1;
+
+	if (read_expected(EVENT_ITEM, "fmt") < 0)
+		return -1;
+
+	if (read_expected(EVENT_OP, ":") < 0)
+		return -1;
+
+	if (read_expect_type(EVENT_DQUOTE, &token) < 0)
+		goto fail;
+
+ concat:
+	event->print_fmt.format = token;
+	event->print_fmt.args = NULL;
+
+	/* ok to have no arg */
+	type = read_token_item(&token);
+
+	if (type == EVENT_NONE)
+		return 0;
+
+	/* Handle concatination of print lines */
+	if (type == EVENT_DQUOTE) {
+		char *cat;
+
+		cat = malloc_or_die(strlen(event->print_fmt.format) +
+				    strlen(token) + 1);
+		strcpy(cat, event->print_fmt.format);
+		strcat(cat, token);
+		free_token(token);
+		free_token(event->print_fmt.format);
+		event->print_fmt.format = NULL;
+		token = cat;
+		goto concat;
+	}
+
+	if (test_type_token(type, token, EVENT_DELIM, ","))
+		goto fail;
+
+	free_token(token);
+
+	ret = event_read_print_args(event, &event->print_fmt.args);
+	if (ret < 0)
+		return -1;
+
+	return ret;
+
+ fail:
+	free_token(token);
+	return -1;
+}
+
+static struct format_field *
+find_common_field(struct event *event, const char *name)
+{
+	struct format_field *format;
+
+	for (format = event->format.common_fields;
+	     format; format = format->next) {
+		if (strcmp(format->name, name) == 0)
+			break;
+	}
+
+	return format;
+}
+
+static struct format_field *
+find_field(struct event *event, const char *name)
+{
+	struct format_field *format;
+
+	for (format = event->format.fields;
+	     format; format = format->next) {
+		if (strcmp(format->name, name) == 0)
+			break;
+	}
+
+	return format;
+}
+
+static struct format_field *
+find_any_field(struct event *event, const char *name)
+{
+	struct format_field *format;
+
+	format = find_common_field(event, name);
+	if (format)
+		return format;
+	return find_field(event, name);
+}
+
+unsigned long long read_size(void *ptr, int size)
+{
+	switch (size) {
+	case 1:
+		return *(unsigned char *)ptr;
+	case 2:
+		return data2host2(ptr);
+	case 4:
+		return data2host4(ptr);
+	case 8:
+		return data2host8(ptr);
+	default:
+		/* BUG! */
+		return 0;
+	}
+}
+
+unsigned long long
+raw_field_value(struct event *event, const char *name, void *data)
+{
+	struct format_field *field;
+
+	field = find_any_field(event, name);
+	if (!field)
+		return 0ULL;
+
+	return read_size(data + field->offset, field->size);
+}
+
+void *raw_field_ptr(struct event *event, const char *name, void *data)
+{
+	struct format_field *field;
+
+	field = find_any_field(event, name);
+	if (!field)
+		return NULL;
+
+	if (field->flags & FIELD_IS_DYNAMIC) {
+		int offset;
+
+		offset = *(int *)(data + field->offset);
+		offset &= 0xffff;
+
+		return data + offset;
+	}
+
+	return data + field->offset;
+}
+
+static int get_common_info(const char *type, int *offset, int *size)
+{
+	struct event *event;
+	struct format_field *field;
+
+	/*
+	 * All events should have the same common elements.
+	 * Pick any event to find where the type is;
+	 */
+	if (!event_list)
+		die("no event_list!");
+
+	event = event_list;
+	field = find_common_field(event, type);
+	if (!field)
+		die("field '%s' not found", type);
+
+	*offset = field->offset;
+	*size = field->size;
+
+	return 0;
+}
+
+static int __parse_common(void *data, int *size, int *offset,
+			  const char *name)
+{
+	int ret;
+
+	if (!*size) {
+		ret = get_common_info(name, offset, size);
+		if (ret < 0)
+			return ret;
+	}
+	return read_size(data + *offset, *size);
+}
+
+int trace_parse_common_type(void *data)
+{
+	static int type_offset;
+	static int type_size;
+
+	return __parse_common(data, &type_size, &type_offset,
+			      "common_type");
+}
+
+int trace_parse_common_pid(void *data)
+{
+	static int pid_offset;
+	static int pid_size;
+
+	return __parse_common(data, &pid_size, &pid_offset,
+			      "common_pid");
+}
+
+int parse_common_pc(void *data)
+{
+	static int pc_offset;
+	static int pc_size;
+
+	return __parse_common(data, &pc_size, &pc_offset,
+			      "common_preempt_count");
+}
+
+int parse_common_flags(void *data)
+{
+	static int flags_offset;
+	static int flags_size;
+
+	return __parse_common(data, &flags_size, &flags_offset,
+			      "common_flags");
+}
+
+int parse_common_lock_depth(void *data)
+{
+	static int ld_offset;
+	static int ld_size;
+	int ret;
+
+	ret = __parse_common(data, &ld_size, &ld_offset,
+			     "common_lock_depth");
+	if (ret < 0)
+		return -1;
+
+	return ret;
+}
+
+struct event *trace_find_event(int id)
+{
+	struct event *event;
+
+	for (event = event_list; event; event = event->next) {
+		if (event->id == id)
+			break;
+	}
+	return event;
+}
+
+struct event *trace_find_next_event(struct event *event)
+{
+	if (!event)
+		return event_list;
+
+	return event->next;
+}
+
+static unsigned long long eval_num_arg(void *data, int size,
+				   struct event *event, struct print_arg *arg)
+{
+	unsigned long long val = 0;
+	unsigned long long left, right;
+	struct print_arg *larg;
+
+	switch (arg->type) {
+	case PRINT_NULL:
+		/* ?? */
+		return 0;
+	case PRINT_ATOM:
+		return strtoull(arg->atom.atom, NULL, 0);
+	case PRINT_FIELD:
+		if (!arg->field.field) {
+			arg->field.field = find_any_field(event, arg->field.name);
+			if (!arg->field.field)
+				die("field %s not found", arg->field.name);
+		}
+		/* must be a number */
+		val = read_size(data + arg->field.field->offset,
+				arg->field.field->size);
+		break;
+	case PRINT_FLAGS:
+	case PRINT_SYMBOL:
+		break;
+	case PRINT_TYPE:
+		return eval_num_arg(data, size, event, arg->typecast.item);
+	case PRINT_STRING:
+		return 0;
+		break;
+	case PRINT_OP:
+		if (strcmp(arg->op.op, "[") == 0) {
+			/*
+			 * Arrays are special, since we don't want
+			 * to read the arg as is.
+			 */
+			if (arg->op.left->type != PRINT_FIELD)
+				goto default_op; /* oops, all bets off */
+			larg = arg->op.left;
+			if (!larg->field.field) {
+				larg->field.field =
+					find_any_field(event, larg->field.name);
+				if (!larg->field.field)
+					die("field %s not found", larg->field.name);
+			}
+			right = eval_num_arg(data, size, event, arg->op.right);
+			val = read_size(data + larg->field.field->offset +
+					right * long_size, long_size);
+			break;
+		}
+ default_op:
+		left = eval_num_arg(data, size, event, arg->op.left);
+		right = eval_num_arg(data, size, event, arg->op.right);
+		switch (arg->op.op[0]) {
+		case '|':
+			if (arg->op.op[1])
+				val = left || right;
+			else
+				val = left | right;
+			break;
+		case '&':
+			if (arg->op.op[1])
+				val = left && right;
+			else
+				val = left & right;
+			break;
+		case '<':
+			switch (arg->op.op[1]) {
+			case 0:
+				val = left < right;
+				break;
+			case '<':
+				val = left << right;
+				break;
+			case '=':
+				val = left <= right;
+				break;
+			default:
+				die("unknown op '%s'", arg->op.op);
+			}
+			break;
+		case '>':
+			switch (arg->op.op[1]) {
+			case 0:
+				val = left > right;
+				break;
+			case '>':
+				val = left >> right;
+				break;
+			case '=':
+				val = left >= right;
+				break;
+			default:
+				die("unknown op '%s'", arg->op.op);
+			}
+			break;
+		case '=':
+			if (arg->op.op[1] != '=')
+				die("unknown op '%s'", arg->op.op);
+			val = left == right;
+			break;
+		case '-':
+			val = left - right;
+			break;
+		case '+':
+			val = left + right;
+			break;
+		default:
+			die("unknown op '%s'", arg->op.op);
+		}
+		break;
+	default: /* not sure what to do there */
+		return 0;
+	}
+	return val;
+}
+
+struct flag {
+	const char *name;
+	unsigned long long value;
+};
+
+static const struct flag flags[] = {
+	{ "HI_SOFTIRQ", 0 },
+	{ "TIMER_SOFTIRQ", 1 },
+	{ "NET_TX_SOFTIRQ", 2 },
+	{ "NET_RX_SOFTIRQ", 3 },
+	{ "BLOCK_SOFTIRQ", 4 },
+	{ "BLOCK_IOPOLL_SOFTIRQ", 5 },
+	{ "TASKLET_SOFTIRQ", 6 },
+	{ "SCHED_SOFTIRQ", 7 },
+	{ "HRTIMER_SOFTIRQ", 8 },
+	{ "RCU_SOFTIRQ", 9 },
+
+	{ "HRTIMER_NORESTART", 0 },
+	{ "HRTIMER_RESTART", 1 },
+};
+
+unsigned long long eval_flag(const char *flag)
+{
+	int i;
+
+	/*
+	 * Some flags in the format files do not get converted.
+	 * If the flag is not numeric, see if it is something that
+	 * we already know about.
+	 */
+	if (isdigit(flag[0]))
+		return strtoull(flag, NULL, 0);
+
+	for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
+		if (strcmp(flags[i].name, flag) == 0)
+			return flags[i].value;
+
+	return 0;
+}
+
+static void print_str_arg(void *data, int size,
+			  struct event *event, struct print_arg *arg)
+{
+	struct print_flag_sym *flag;
+	unsigned long long val, fval;
+	char *str;
+	int print;
+
+	switch (arg->type) {
+	case PRINT_NULL:
+		/* ?? */
+		return;
+	case PRINT_ATOM:
+		printf("%s", arg->atom.atom);
+		return;
+	case PRINT_FIELD:
+		if (!arg->field.field) {
+			arg->field.field = find_any_field(event, arg->field.name);
+			if (!arg->field.field)
+				die("field %s not found", arg->field.name);
+		}
+		str = malloc_or_die(arg->field.field->size + 1);
+		memcpy(str, data + arg->field.field->offset,
+		       arg->field.field->size);
+		str[arg->field.field->size] = 0;
+		printf("%s", str);
+		free(str);
+		break;
+	case PRINT_FLAGS:
+		val = eval_num_arg(data, size, event, arg->flags.field);
+		print = 0;
+		for (flag = arg->flags.flags; flag; flag = flag->next) {
+			fval = eval_flag(flag->value);
+			if (!val && !fval) {
+				printf("%s", flag->str);
+				break;
+			}
+			if (fval && (val & fval) == fval) {
+				if (print && arg->flags.delim)
+					printf("%s", arg->flags.delim);
+				printf("%s", flag->str);
+				print = 1;
+				val &= ~fval;
+			}
+		}
+		break;
+	case PRINT_SYMBOL:
+		val = eval_num_arg(data, size, event, arg->symbol.field);
+		for (flag = arg->symbol.symbols; flag; flag = flag->next) {
+			fval = eval_flag(flag->value);
+			if (val == fval) {
+				printf("%s", flag->str);
+				break;
+			}
+		}
+		break;
+
+	case PRINT_TYPE:
+		break;
+	case PRINT_STRING: {
+		int str_offset;
+
+		if (arg->string.offset == -1) {
+			struct format_field *f;
+
+			f = find_any_field(event, arg->string.string);
+			arg->string.offset = f->offset;
+		}
+		str_offset = *(int *)(data + arg->string.offset);
+		str_offset &= 0xffff;
+		printf("%s", ((char *)data) + str_offset);
+		break;
+	}
+	case PRINT_OP:
+		/*
+		 * The only op for string should be ? :
+		 */
+		if (arg->op.op[0] != '?')
+			return;
+		val = eval_num_arg(data, size, event, arg->op.left);
+		if (val)
+			print_str_arg(data, size, event, arg->op.right->op.left);
+		else
+			print_str_arg(data, size, event, arg->op.right->op.right);
+		break;
+	default:
+		/* well... */
+		break;
+	}
+}
+
+static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event *event)
+{
+	static struct format_field *field, *ip_field;
+	struct print_arg *args, *arg, **next;
+	unsigned long long ip, val;
+	char *ptr;
+	void *bptr;
+
+	if (!field) {
+		field = find_field(event, "buf");
+		if (!field)
+			die("can't find buffer field for binary printk");
+		ip_field = find_field(event, "ip");
+		if (!ip_field)
+			die("can't find ip field for binary printk");
+	}
+
+	ip = read_size(data + ip_field->offset, ip_field->size);
+
+	/*
+	 * The first arg is the IP pointer.
+	 */
+	args = malloc_or_die(sizeof(*args));
+	arg = args;
+	arg->next = NULL;
+	next = &arg->next;
+
+	arg->type = PRINT_ATOM;
+	arg->atom.atom = malloc_or_die(32);
+	sprintf(arg->atom.atom, "%lld", ip);
+
+	/* skip the first "%pf : " */
+	for (ptr = fmt + 6, bptr = data + field->offset;
+	     bptr < data + size && *ptr; ptr++) {
+		int ls = 0;
+
+		if (*ptr == '%') {
+ process_again:
+			ptr++;
+			switch (*ptr) {
+			case '%':
+				break;
+			case 'l':
+				ls++;
+				goto process_again;
+			case 'L':
+				ls = 2;
+				goto process_again;
+			case '0' ... '9':
+				goto process_again;
+			case 'p':
+				ls = 1;
+				/* fall through */
+			case 'd':
+			case 'u':
+			case 'x':
+			case 'i':
+				/* the pointers are always 4 bytes aligned */
+				bptr = (void *)(((unsigned long)bptr + 3) &
+						~3);
+				switch (ls) {
+				case 0:
+				case 1:
+					ls = long_size;
+					break;
+				case 2:
+					ls = 8;
+				default:
+					break;
+				}
+				val = read_size(bptr, ls);
+				bptr += ls;
+				arg = malloc_or_die(sizeof(*arg));
+				arg->next = NULL;
+				arg->type = PRINT_ATOM;
+				arg->atom.atom = malloc_or_die(32);
+				sprintf(arg->atom.atom, "%lld", val);
+				*next = arg;
+				next = &arg->next;
+				break;
+			case 's':
+				arg = malloc_or_die(sizeof(*arg));
+				arg->next = NULL;
+				arg->type = PRINT_STRING;
+				arg->string.string = strdup(bptr);
+				bptr += strlen(bptr) + 1;
+				*next = arg;
+				next = &arg->next;
+			default:
+				break;
+			}
+		}
+	}
+
+	return args;
+}
+
+static void free_args(struct print_arg *args)
+{
+	struct print_arg *next;
+
+	while (args) {
+		next = args->next;
+
+		if (args->type == PRINT_ATOM)
+			free(args->atom.atom);
+		else
+			free(args->string.string);
+		free(args);
+		args = next;
+	}
+}
+
+static char *get_bprint_format(void *data, int size __unused, struct event *event)
+{
+	unsigned long long addr;
+	static struct format_field *field;
+	struct printk_map *printk;
+	char *format;
+	char *p;
+
+	if (!field) {
+		field = find_field(event, "fmt");
[… more lines in the raw message]

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

tools/lib/trace/trace-event-read.c new file +539 -0
new file mode 100644
index 0000000..d7d8ceb

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

tools/perf/Makefile +0 -3
index 001831e..590c8f6 100644

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

tools/perf/util/trace-event-info.c deleted +0 -563
deleted file mode 100644
index 0918a63..0000000

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

tools/perf/util/trace-event-parse.c deleted +0 -3233
deleted file mode 100644
index 9a46fa1..0000000

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

tools/perf/util/trace-event-read.c deleted +0 -539
deleted file mode 100644
index 2583227..0000000

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

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

Signature · 7 lines
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

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

#17 lore raw

Re: [PATCH 15/21] perf: Export trace event utils

From: Steven Rostedt <[email protected]>
Date: Tue, Jul 06, 2010 at 06:18:43PM -0400

Hi Steven,

Quoted 5 lines

I'm actually working on making a libparsevent.a that does some of what you are doing.

The idea is, if I can separate out this code from perf, I can then bring it up to speed with what I have in trace-cmd.

Ok this is good. I moved those to a generic place only because perf/util/parse-events.c pulled them out as a build dependency but all the trace events parsing code should be a library-like since it can very much be reused by a lot of other tools.

We should sync our stuff then, after you've moved those to tools/lib/trace/ or somewhere similar, and I can rebase my stuff on top. Or maybe you have a better idea, please keep me posted so that we don't step on each other's toes.

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#18 lore raw

PATCH 16/21 perf: Add a common misc.c compilation unit

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

This is a temporary unit for sharing code between perf and the library.

---
 tools/lib/Makefile            |    2 +
 tools/lib/lk/color.c          |   16 ------------
 tools/lib/lk/color.h          |    5 +---
 tools/lib/lk/debug.c          |    6 +----
 tools/lib/lk/debug.h          |    2 -
 tools/lib/perf/misc.c         |   54 +++++++++++++++++++++++++++++++++++++++++
 tools/lib/perf/misc.h         |   11 ++++++++
 tools/perf/builtin-annotate.c |    4 +++
 tools/perf/builtin-kvm.c      |    4 +--
 tools/perf/builtin-record.c   |   11 ++++----
 tools/perf/builtin-report.c   |    1 +
 tools/perf/perf.c             |    1 +
 tools/perf/perf.h             |    3 --
 tools/perf/util/newt.c        |    1 +
 14 files changed, 83 insertions(+), 38 deletions(-)
 create mode 100644 tools/lib/perf/misc.c
 create mode 100644 tools/lib/perf/misc.h
tools/lib/Makefile +2 -0
index 795fa3a..780c4fc 100644
@@ -23,6 +23,7 @@ LIB_H += perf/hist.h
 LIB_H += perf/thread.h
 LIB_H += perf/sort.h
 LIB_H += perf/event.h
+LIB_H += perf/misc.h
 
 LIB_OBJS += $(OUTPUT)lk/bitmap.o
 LIB_OBJS += $(OUTPUT)lk/cpumap.o
@@ -49,6 +50,7 @@ LIB_OBJS += $(OUTPUT)perf/hist.o
 LIB_OBJS += $(OUTPUT)perf/thread.o
 LIB_OBJS += $(OUTPUT)perf/sort.o
 LIB_OBJS += $(OUTPUT)perf/event.o
+LIB_OBJS += $(OUTPUT)perf/misc.o
 LIB_OBJS += $(OUTPUT)trace/trace-event-read.o
 LIB_OBJS += $(OUTPUT)trace/trace-event-info.o
 LIB_OBJS += $(OUTPUT)trace/trace-event-parse.o
tools/lib/lk/color.c +0 -16
index 93d6381..b3d067b 100644
@@ -6,22 +6,6 @@
  */
 static int use_color_default = -1;
 
-/*
- * This is going into tools/perf/perf.c next
- */
-int spawned_pager, pager_use_color = 1;
-
-int pager_in_use(void)
-{
-	const char *env;
-
-	if (spawned_pager)
-		return 1;
-
-	env = getenv("PERF_PAGER_IN_USE");
-	return env ? lk_config_bool("PERF_PAGER_IN_USE", env) : 0;
-}
-
 static int parse_color(const char *name, int len)
 {
 	static const char * const color_names[] = {
tools/lib/lk/color.h +1 -4
index c962e1d..03927fc 100644
@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include "util.h"
+#include <perf/misc.h>
 
 /* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
 #define COLOR_MAXLEN 24
@@ -26,10 +27,6 @@
 #define MIN_GREEN	0.5
 #define MIN_RED		5.0
 
-extern int spawned_pager, pager_use_color;
-
-extern int pager_in_use(void);
-
 void color_parse(const char *value, const char *var, char *dst);
 void color_parse_mem(const char *value, int len, const char *var, char *dst);
 int color_vsnprintf(char *bf, size_t size, const char *color,
tools/lib/lk/debug.c +1 -5
index 73edbb8..b183c4d 100644
@@ -8,11 +8,7 @@
 #include "debug.h"
 #include <lk/util.h>
 #include <lk/color.h>
-
-/*
- * will move to tools/perf/perf.c
- */
-int use_browser = -1;
+#include <perf/misc.h>
 
 int verbose = 0;
 bool dump_trace = false;
tools/lib/lk/debug.h +0 -2
index 44fdfab..6badf99 100644
@@ -8,8 +8,6 @@
 extern int verbose;
 extern bool dump_trace;
 
-extern int use_browser;
-
 int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
 void trace_event(event_t *event);
 
tools/lib/perf/misc.c new file +54 -0

54 lines not on this page · raw message

tools/lib/perf/misc.h new file +11 -0
new file mode 100644
index 0000000..2073b8c
@@ -0,0 +1,11 @@
+#ifndef __PERF_MISC_H
+#define __PERF_MISC_H
+
+#include <stdbool.h>
+
+extern int spawned_pager, pager_use_color;
+extern int use_browser;
+extern int pager_in_use(void);
+extern bool perf_host, perf_guest;
+
+#endif /* __PERF_MISC_H */
tools/perf/builtin-annotate.c +4 -0
index 29753d1..87e78ae 100644
@@ -24,6 +24,10 @@
 #include <perf/thread.h>
 #include <perf/sort.h>
 #include <perf/hist.h>
+#include <perf/misc.h>
+#include <perf/thread.h>
+#include <perf/sort.h>
+#include <perf/hist.h>
 #include <perf/session.h>
 
 static char		const *input_name = "perf.data";
tools/perf/builtin-kvm.c +1 -3
index 10a8c4d..8e92448 100644
@@ -3,6 +3,7 @@
 
 #include <lk/util.h>
 #include "util/cache.h"
+#include <perf/misc.h>
 #include <perf/symbol.h>
 #include <perf/thread.h>
 #include <perf/header.h>
@@ -22,9 +23,6 @@
 static const char		*file_name;
 static char			name_buffer[256];
 
-bool				perf_host = 1;
-bool				perf_guest;
-
 static const char * const kvm_usage[] = {
 	"perf kvm [<options>] {top|record|report|diff|buildid-list}",
 	NULL
tools/perf/builtin-record.c +6 -5
index 6072b83..241c334 100644
@@ -11,17 +11,18 @@
 
 #include "perf.h"
 
-#include <perf/build-id.h>
 #include <lk/util.h>
-#include "util/parse-options.h"
+#include <lk/cpumap.h>
+#include <lk/debug.h>
+#include <perf/misc.h>
 #include <perf/parse-events.h>
-
+#include <perf/build-id.h>
 #include <perf/header.h>
 #include <perf/event.h>
-#include <lk/debug.h>
 #include <perf/session.h>
 #include <perf/symbol.h>
-#include <lk/cpumap.h>
+
+#include "util/parse-options.h"
 
 #include <unistd.h>
 #include <sched.h>
tools/perf/builtin-report.c +1 -0
index 0803898..9eccc66 100644
@@ -25,6 +25,7 @@
 
 #include "util/parse-options.h"
 #include <perf/parse-events.h>
+#include <perf/misc.h>
 
 #include <perf/thread.h>
 #include <perf/sort.h>
tools/perf/perf.c +1 -0
index 4268ed4..9a1b725 100644
@@ -15,6 +15,7 @@
 #include <perf/build-id.h>
 #include "util/run-command.h"
 #include <perf/parse-events.h>
+#include <perf/misc.h>
 #include <lk/debugfs.h>
 #include <lk/config.h>
 #include <lk/debug.h>
tools/perf/perf.h +0 -3
index 2344078..86b7ea1 100644
@@ -131,7 +131,4 @@ struct ip_callchain {
 	u64 nr;
 	u64 ips[0];
 };
-
-extern bool perf_host, perf_guest;
-
 #endif
tools/perf/util/newt.c +1 -0
index dffe075..3a8c453 100644
@@ -21,6 +21,7 @@
 #include <perf/session.h>
 #include <perf/sort.h>
 #include <perf/symbol.h>
+#include <perf/misc.h>
 
 #if SLANG_VERSION < 20104
 #define slsmg_printf(msg, args...) SLsmg_printf((char *)msg, ##args)
Signature · 1 line
1.7.1
#19 lore raw

PATCH 17/21 perf: Carve out mmap helpers for general use

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Export the mmap_read* helpers into tools/lib/perf/mmap.[ch]

---
 tools/lib/Makefile          |    2 +
 tools/lib/perf/mmap.c       |   97 +++++++++++++++++++++++++++++++++++++
 tools/lib/perf/mmap.h       |   15 ++++++
 tools/perf/builtin-record.c |  113 +++++--------------------------------------
 tools/perf/builtin-top.c    |   21 +-------
 5 files changed, 129 insertions(+), 119 deletions(-)
 create mode 100644 tools/lib/perf/mmap.c
 create mode 100644 tools/lib/perf/mmap.h
tools/lib/Makefile +2 -0
index 780c4fc..6f7102b 100644
@@ -13,6 +13,7 @@ LIB_H += lk/strbuf.h
 LIB_H += lk/color.h
 LIB_H += lk/debug.h
 LIB_H += lk/strlist.h
+LIB_H += perf/mmap.h
 LIB_H += perf/parse-events.h
 LIB_H += perf/header.h
 LIB_H += perf/symbol.h
@@ -40,6 +41,7 @@ LIB_OBJS += $(OUTPUT)lk/debug.o
 LIB_OBJS += $(OUTPUT)lk/string.o
 LIB_OBJS += $(OUTPUT)lk/rbtree.o
 LIB_OBJS += $(OUTPUT)lk/strlist.o
+LIB_OBJS += $(OUTPUT)perf/mmap.o
 LIB_OBJS += $(OUTPUT)perf/parse-events.o
 LIB_OBJS += $(OUTPUT)perf/header.o
 LIB_OBJS += $(OUTPUT)perf/symbol.o
tools/lib/perf/mmap.c new file +97 -0

97 lines not on this page · raw message

tools/lib/perf/mmap.h new file +15 -0
new file mode 100644
index 0000000..b6622e5
@@ -0,0 +1,15 @@
+#ifndef __PERF_MMAP_H
+#define __PERF_MMAP_H
+
+struct mmap_data {
+	int			counter;
+	void			*base;
+	unsigned int		mask;
+	unsigned int		prev;
+};
+
+unsigned long mmap_read_head(struct mmap_data *md);
+unsigned long mmap_read_all(struct mmap_data *, int,
+			    void (*write_output)(void *, size_t));
+
+#endif /* __PERF_MMAP_H */
tools/perf/builtin-record.c +13 -100

160 lines not on this page · raw message

tools/perf/builtin-top.c +2 -19
index 866ba3d..1522ca0 100644
@@ -28,6 +28,7 @@
 #include <linux/rbtree.h>
 #include "util/parse-options.h"
 #include <perf/parse-events.h>
+#include <perf/mmap.h>
 #include <lk/cpumap.h>
 
 #include <lk/debug.h>
@@ -1102,24 +1103,6 @@ static int event__process(event_t *event, struct perf_session *session)
 	return 0;
 }
 
-struct mmap_data {
-	int			counter;
-	void			*base;
-	int			mask;
-	unsigned int		prev;
-};
-
-static unsigned int mmap_read_head(struct mmap_data *md)
-{
-	struct perf_event_mmap_page *pc = md->base;
-	int head;
-
-	head = pc->data_head;
-	rmb();
-
-	return head;
-}
-
 static void perf_session__mmap_read_counter(struct perf_session *self,
 					    struct mmap_data *md)
 {
@@ -1137,7 +1120,7 @@ static void perf_session__mmap_read_counter(struct perf_session *self,
 	 * In either case, truncate and restart at head.
 	 */
 	diff = head - old;
-	if (diff > md->mask / 2 || diff < 0) {
+	if ((unsigned)diff > md->mask / 2 || diff < 0) {
 		fprintf(stderr, "WARNING: failed to keep up with mmap data.\n");
 
 		/*
Signature · 1 line
1.7.1
#20 lore raw

PATCH 18/21 perf: Split build-id.c

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

... into perf-specific and generic part.

---
 tools/lib/perf/build-id.c  |   49 --------------------------------------------
 tools/lib/perf/build-id.h  |    4 +++
 tools/perf/Makefile        |    1 +
 tools/perf/util/build-id.c |   48 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 49 deletions(-)
 create mode 100644 tools/perf/util/build-id.c
tools/lib/perf/build-id.c +0 -49
index 5969758..c4c1267 100644
@@ -60,52 +60,3 @@ char *dso__build_id_filename(struct dso *self, char *bf, size_t size)
 			 build_id_hex, build_id_hex + 2);
 	return bf;
 }
-
-struct buildid_dir_config {
-	char *dir;
-};
-
-static int buildid_dir_command_config(const char *var, const char *value,
-				      void *data)
-{
-	struct buildid_dir_config *c = data;
-	const char *v;
-
-	/* same dir for all commands */
-	if (!prefixcmp(var, "buildid.") && !strcmp(var + 8, "dir")) {
-		v = lk_config_dirname(var, value);
-		if (!v)
-			return -1;
-		strncpy(c->dir, v, MAXPATHLEN-1);
-		c->dir[MAXPATHLEN-1] = '\0';
-	}
-	return 0;
-}
-static void check_buildid_dir_config(void)
-{
-	struct buildid_dir_config c;
-	c.dir = buildid_dir;
-	perf_config(buildid_dir_command_config, &c);
-}
-
-void set_buildid_dir(void)
-{
-	buildid_dir[0] = '\0';
-
-	/* try config file */
-	check_buildid_dir_config();
-
-	/* default to $HOME/.debug */
-	if (buildid_dir[0] == '\0') {
-		char *v = getenv("HOME");
-		if (v) {
-			snprintf(buildid_dir, MAXPATHLEN-1, "%s/%s",
-				 v, DEBUG_CACHE_DIR);
-		} else {
-			strncpy(buildid_dir, DEBUG_CACHE_DIR, MAXPATHLEN-1);
-		}
-		buildid_dir[MAXPATHLEN-1] = '\0';
-	}
-	/* for communicating with external commands */
-	setenv("PERF_BUILDID_DIR", buildid_dir, 1);
-}
tools/lib/perf/build-id.h +4 -0
index 1b73726..224c90b 100644
@@ -6,6 +6,10 @@
 
 extern struct perf_event_ops build_id__mark_dso_hit_ops;
 
+struct buildid_dir_config {
+	char *dir;
+};
+
 char *dso__build_id_filename(struct dso *self, char *bf, size_t size);
 extern void set_buildid_dir(void);
 
tools/perf/Makefile +1 -0
index 590c8f6..7d6ee06 100644
@@ -387,6 +387,7 @@ LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
 LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/probe-event.o
 LIB_OBJS += $(OUTPUT)util/config.o
+LIB_OBJS += $(OUTPUT)util/build-id.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 
tools/perf/util/build-id.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
1.7.1
#21 lore raw

PATCH 19/21 x86, mce: Notify about corrected events too

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Notify all parties registered on the mce decoder chain about logged correctable MCEs.

---
 arch/x86/kernel/cpu/mcheck/mce.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +1 -0
index 42d2808..4dc20f0 100644
@@ -601,6 +601,7 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
 		 */
 		if (!(flags & MCP_DONTLOG) && !mce_dont_log_ce) {
 			mce_log(&m);
+			atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, &m);
 			add_taint(TAINT_MACHINE_CHECK);
 		}
 
Signature · 1 line
1.7.1
#22 lore raw

PATCH 20/21 amd64_edac: Remove polling mechanism

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Switch to reusing the mcheck core's machine check polling mechanism instead of duplicating functionality by using the EDAC polling routine.

Correct formatting while at it.

---
 drivers/edac/amd64_edac.c   |  118 -------------------------------------------
 drivers/edac/edac_mce_amd.c |   16 +++---
 2 files changed, 8 insertions(+), 126 deletions(-)
drivers/edac/amd64_edac.c +0 -118
index cf17dbb..df47daf 100644
@@ -1975,107 +1975,6 @@ static int get_channel_from_ecc_syndrome(struct mem_ctl_info *mci, u16 syndrome)
 }
 
 /*
- * Check for valid error in the NB Status High register. If so, proceed to read
- * NB Status Low, NB Address Low and NB Address High registers and store data
- * into error structure.
- *
- * Returns:
- *	- 1: if hardware regs contains valid error info
- *	- 0: if no valid error is indicated
- */
-static int amd64_get_error_info_regs(struct mem_ctl_info *mci,
-				     struct err_regs *regs)
-{
-	struct amd64_pvt *pvt;
-	struct pci_dev *misc_f3_ctl;
-
-	pvt = mci->pvt_info;
-	misc_f3_ctl = pvt->misc_f3_ctl;
-
-	if (amd64_read_pci_cfg(misc_f3_ctl, K8_NBSH, &regs->nbsh))
-		return 0;
-
-	if (!(regs->nbsh & K8_NBSH_VALID_BIT))
-		return 0;
-
-	/* valid error, read remaining error information registers */
-	if (amd64_read_pci_cfg(misc_f3_ctl, K8_NBSL, &regs->nbsl) ||
-	    amd64_read_pci_cfg(misc_f3_ctl, K8_NBEAL, &regs->nbeal) ||
-	    amd64_read_pci_cfg(misc_f3_ctl, K8_NBEAH, &regs->nbeah) ||
-	    amd64_read_pci_cfg(misc_f3_ctl, K8_NBCFG, &regs->nbcfg))
-		return 0;
-
-	return 1;
-}
-
-/*
- * This function is called to retrieve the error data from hardware and store it
- * in the info structure.
- *
- * Returns:
- *	- 1: if a valid error is found
- *	- 0: if no error is found
- */
-static int amd64_get_error_info(struct mem_ctl_info *mci,
-				struct err_regs *info)
-{
-	struct amd64_pvt *pvt;
-	struct err_regs regs;
-
-	pvt = mci->pvt_info;
-
-	if (!amd64_get_error_info_regs(mci, info))
-		return 0;
-
-	/*
-	 * Here's the problem with the K8's EDAC reporting: There are four
-	 * registers which report pieces of error information. They are shared
-	 * between CEs and UEs. Furthermore, contrary to what is stated in the
-	 * BKDG, the overflow bit is never used! Every error always updates the
-	 * reporting registers.
-	 *
-	 * Can you see the race condition? All four error reporting registers
-	 * must be read before a new error updates them! There is no way to read
-	 * all four registers atomically. The best than can be done is to detect
-	 * that a race has occured and then report the error without any kind of
-	 * precision.
-	 *
-	 * What is still positive is that errors are still reported and thus
-	 * problems can still be detected - just not localized because the
-	 * syndrome and address are spread out across registers.
-	 *
-	 * Grrrrr!!!!!  Here's hoping that AMD fixes this in some future K8 rev.
-	 * UEs and CEs should have separate register sets with proper overflow
-	 * bits that are used! At very least the problem can be fixed by
-	 * honoring the ErrValid bit in 'nbsh' and not updating registers - just
-	 * set the overflow bit - unless the current error is CE and the new
-	 * error is UE which would be the only situation for overwriting the
-	 * current values.
-	 */
-
-	regs = *info;
-
-	/* Use info from the second read - most current */
-	if (unlikely(!amd64_get_error_info_regs(mci, info)))
-		return 0;
-
-	/* clear the error bits in hardware */
-	pci_write_bits32(pvt->misc_f3_ctl, K8_NBSH, 0, K8_NBSH_VALID_BIT);
-
-	/* Check for the possible race condition */
-	if ((regs.nbsh != info->nbsh) ||
-	     (regs.nbsl != info->nbsl) ||
-	     (regs.nbeah != info->nbeah) ||
-	     (regs.nbeal != info->nbeal)) {
-		amd64_mc_printk(mci, KERN_WARNING,
-				"hardware STATUS read access race condition "
-				"detected!\n");
-		return 0;
-	}
-	return 1;
-}
-
-/*
  * Handle any Correctable Errors (CEs) that have occurred. Check for valid ERROR
  * ADDRESS and process.
  */
@@ -2199,20 +2098,6 @@ void amd64_decode_bus_error(int node_id, struct err_regs *regs)
 }
 
 /*
- * The main polling 'check' function, called FROM the edac core to perform the
- * error checking and if an error is encountered, error processing.
- */
-static void amd64_check(struct mem_ctl_info *mci)
-{
-	struct err_regs regs;
-
-	if (amd64_get_error_info(mci, &regs)) {
-		struct amd64_pvt *pvt = mci->pvt_info;
-		amd_decode_nb_mce(pvt->mc_node_id, &regs, 1);
-	}
-}
-
-/*
  * Input:
  *	1) struct amd64_pvt which contains pvt->dram_f2_ctl pointer
  *	2) AMD Family index value
@@ -2739,9 +2624,6 @@ static void amd64_setup_mci_misc_attributes(struct mem_ctl_info *mci)
 	mci->dev_name		= pci_name(pvt->dram_f2_ctl);
 	mci->ctl_page_to_phys	= NULL;
 
-	/* IMPORTANT: Set the polling 'check' function in this module */
-	mci->edac_check		= amd64_check;
-
 	/* memory scrubber interface */
 	mci->set_sdram_scrub_rate = amd64_set_scrub_rate;
 	mci->get_sdram_scrub_rate = amd64_get_scrub_rate;
drivers/edac/edac_mce_amd.c +8 -8
index 97e64bc..bae9351 100644
@@ -133,7 +133,7 @@ static void amd_decode_dc_mce(u64 mc0_status)
 	u32 ec  = mc0_status & 0xffff;
 	u32 xec = (mc0_status >> 16) & 0xf;
 
-	pr_emerg(" Data Cache Error");
+	pr_emerg("Data Cache Error");
 
 	if (xec == 1 && TLB_ERROR(ec))
 		pr_cont(": %s TLB multimatch.\n", LL_MSG(ec));
@@ -176,7 +176,7 @@ static void amd_decode_ic_mce(u64 mc1_status)
 	u32 ec  = mc1_status & 0xffff;
 	u32 xec = (mc1_status >> 16) & 0xf;
 
-	pr_emerg(" Instruction Cache Error");
+	pr_emerg("Instruction Cache Error");
 
 	if (xec == 1 && TLB_ERROR(ec))
 		pr_cont(": %s TLB multimatch.\n", LL_MSG(ec));
@@ -233,7 +233,7 @@ static void amd_decode_bu_mce(u64 mc2_status)
 	u32 ec = mc2_status & 0xffff;
 	u32 xec = (mc2_status >> 16) & 0xf;
 
-	pr_emerg(" Bus Unit Error");
+	pr_emerg("Bus Unit Error");
 
 	if (xec == 0x1)
 		pr_cont(" in the write data buffers.\n");
@@ -275,7 +275,7 @@ static void amd_decode_ls_mce(u64 mc3_status)
 	u32 ec  = mc3_status & 0xffff;
 	u32 xec = (mc3_status >> 16) & 0xf;
 
-	pr_emerg(" Load Store Error");
+	pr_emerg("Load Store Error");
 
 	if (xec == 0x0) {
 		u8 rrrr = (ec >> 4) & 0xf;
@@ -304,7 +304,7 @@ void amd_decode_nb_mce(int node_id, struct err_regs *regs, int handle_errors)
 	if (TLB_ERROR(ec) && !report_gart_errors)
 		return;
 
-	pr_emerg(" Northbridge Error, node %d", node_id);
+	pr_emerg("Northbridge Error, node %d", node_id);
 
 	/*
 	 * F10h, revD can disable ErrCpu[3:0] so check that first and also the
@@ -342,13 +342,13 @@ static void amd_decode_fr_mce(u64 mc5_status)
 static inline void amd_decode_err_code(unsigned int ec)
 {
 	if (TLB_ERROR(ec)) {
-		pr_emerg(" Transaction: %s, Cache Level %s\n",
+		pr_emerg("Transaction: %s, Cache Level %s\n",
 			 TT_MSG(ec), LL_MSG(ec));
 	} else if (MEM_ERROR(ec)) {
-		pr_emerg(" Transaction: %s, Type: %s, Cache Level: %s",
+		pr_emerg("Transaction: %s, Type: %s, Cache Level: %s",
 			 RRRR_MSG(ec), TT_MSG(ec), LL_MSG(ec));
 	} else if (BUS_ERROR(ec)) {
-		pr_emerg(" Transaction type: %s(%s), %s, Cache Level: %s, "
+		pr_emerg("Transaction type: %s(%s), %s, Cache Level: %s, "
 			 "Participating Processor: %s\n",
 			  RRRR_MSG(ec), II_MSG(ec), TO_MSG(ec), LL_MSG(ec),
 			  PP_MSG(ec));
Signature · 1 line
1.7.1
#23 lore raw

PATCH 21/21 tools, ras: Add a RAS daemon

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

---
 tools/Makefile     |    4 +
 tools/lib/Makefile |    2 +-
 tools/ras/Makefile |   18 ++++++
 tools/ras/rasd.c   |  155 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 178 insertions(+), 1 deletions(-)
 create mode 100644 tools/ras/Makefile
 create mode 100644 tools/ras/rasd.c
tools/Makefile +4 -0
index 54dea0e..270c027 100644
@@ -100,11 +100,15 @@ export BASIC_CFLAGS EXTLIBS
 perf: lib .FORCE
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
 
+ras: lib .FORCE
+	$(QUIET_SUBDIR0)ras/ $(QUIET_SUBDIR1)
+
 lib: .FORCE
 	$(QUIET_SUBDIR0)lib/ $(QUIET_SUBDIR1)
 
 clean:
 	$(QUIET_SUBDIR0)lib/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)ras/ $(QUIET_SUBDIR1) clean
 
 .PHONY: clean .FORCE
tools/lib/Makefile +1 -1
index 6f7102b..0786588 100644
@@ -83,6 +83,6 @@ $(OUTPUT)%.o: %.S
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
 
 clean:
-	$(RM) $(LIB_OBJS)
+	$(RM) $(LIB_OBJS) $(LIBFILE)
 
 .PHONY: clean
tools/ras/Makefile new file +18 -0
new file mode 100644
index 0000000..26525e7
@@ -0,0 +1,18 @@
+include ../Makefile.lib
+
+CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
+EXTLIBS += -lpthread -lrt -lelf -lm
+ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+ALL_LDFLAGS = $(LDFLAGS)
+LIBFILE = ../lib/lklib.a
+
+rasd: rasd.o $(LIBFILE)
+	$(QUIET_CC)$(CC) $(ALL_CFLAGS) -o $@ $^ $(EXTLIBS)
+
+%.o: %.c
+	$(QUIET_CC)$(CC) $(ALL_CFLAGS) -c $<
+
+clean:
+	rm -rf *.o rasd
+
+.PHONY: clean
tools/ras/rasd.c new file +155 -0

155 lines not on this page · raw message

Signature · 1 line
1.7.1