All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCHSET 0/12] RAS daemon v4
@ 2011-01-21 15:09 Borislav Petkov
  2011-01-21 15:09 ` [PATCH 01/12] perf: Start the massive restructuring Borislav Petkov
                   ` (11 more replies)
  0 siblings, 12 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Hi,

here's another round of the RAS daemon patchset. This time I'd like to
get some ACKs/NACKs on the perf bits and whether this is agreeable to
do. To some of the patches:

* 0001-perf-Start-the-massive-restructuring.patch:

This renames perf_event.c into events/core.c, as talked about earlier.
This is only a first step though, the rest should come from perf people
I guess...

* 0002-perf-Add-persistent-event-facilities.patch

... and this one puts the persistent bits in persistent.c

* 0004-perf-Add-Makefile.lib.patch
* 0005-perf-Export-trace-event-utils.patch

I'm adding a toplevel tools/Makefile here which we could use for the
other tools in there since we keep growing even more tools with each
kernel release.

* 0007-perf-Export-debugfs-utilities.patch

This one is needed only temporary, as we're moving the perf events to
/sysfs. After that work is done, the persistent fd will be read from
there.

For more details, check the individual patches.

Btw, the patches are ontop of tip/master from ~two weeks ago, i.e.:
cf1f6cd677a9ce8c80e5de61724a25074ad9a8cf.

In order to run this patchset, you need only this hunk:

---
diff --git a/drivers/edac/mce_amd.c b/drivers/edac/mce_amd.c
index c018109..7bffbc6 100644
--- a/drivers/edac/mce_amd.c
+++ b/drivers/edac/mce_amd.c
@@ -1,5 +1,6 @@
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <trace/events/mce.h>
 
 #include "mce_amd.h"
 
@@ -598,6 +599,8 @@ int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 
 	amd_decode_err_code(m->status & 0xffff);
 
+	trace_mce_record(m);
+
 	return NOTIFY_STOP;
 }
 EXPORT_SYMBOL_GPL(amd_decode_mce);
---

so that you can inject some MCEs like so:

$ cd tools/
$ make -j ras
$ ./ras/rasd
$ modprobe mce_amd_inj (built by CONFIG_EDAC_MCE_INJ)
$ echo 0x9c00410000010016 > /sys/devices/system/edac/mce/status
$ echo 0 > /sys/devices/system/edac/mce/bank

And after 30 sec the latest, /var/log/ras.log will contain:

Got MCE, cpu: 0, status: 0x9c00410000010016, addr: 0x0000000000000000

This is still undecoded yet but I'm working on it.

Anyway, please take a look and send me all comments you'd have.

Thanks.

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

* [PATCH 01/12] perf: Start the massive restructuring
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 15:09 ` [PATCH 02/12] perf: Add persistent event facilities Borislav Petkov
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

mv kernel/perf_event.c -> kernel/events/core.c. From there, all other
sensible splitting can happen.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 kernel/Makefile                        |    5 +++--
 kernel/events/Makefile                 |    5 +++++
 kernel/{perf_event.c => events/core.c} |    0
 3 files changed, 8 insertions(+), 2 deletions(-)
 create mode 100644 kernel/events/Makefile
 rename kernel/{perf_event.c => events/core.c} (100%)

diff --git a/kernel/Makefile b/kernel/Makefile
index 0b5ff08..e9d9deb 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -21,7 +21,6 @@ CFLAGS_REMOVE_mutex-debug.o = -pg
 CFLAGS_REMOVE_rtmutex-debug.o = -pg
 CFLAGS_REMOVE_cgroup-debug.o = -pg
 CFLAGS_REMOVE_sched_clock.o = -pg
-CFLAGS_REMOVE_perf_event.o = -pg
 CFLAGS_REMOVE_irq_work.o = -pg
 endif
 
@@ -102,7 +101,9 @@ obj-$(CONFIG_X86_DS) += trace/
 obj-$(CONFIG_RING_BUFFER) += trace/
 obj-$(CONFIG_SMP) += sched_cpupri.o
 obj-$(CONFIG_IRQ_WORK) += irq_work.o
-obj-$(CONFIG_PERF_EVENTS) += perf_event.o
+
+obj-$(CONFIG_PERF_EVENTS) += events/
+
 obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
 obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
 obj-$(CONFIG_PADATA) += padata.o
diff --git a/kernel/events/Makefile b/kernel/events/Makefile
new file mode 100644
index 0000000..26c00e4
--- /dev/null
+++ b/kernel/events/Makefile
@@ -0,0 +1,5 @@
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_core.o = -pg
+endif
+
+obj-y += core.o
diff --git a/kernel/perf_event.c b/kernel/events/core.c
similarity index 100%
rename from kernel/perf_event.c
rename to kernel/events/core.c
-- 
1.7.4.rc2


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

* [PATCH 02/12] perf: Add persistent event facilities
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
  2011-01-21 15:09 ` [PATCH 01/12] perf: Start the massive restructuring Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 15:09 ` [PATCH 03/12] x86, mce: Add persistent MCE event Borislav Petkov
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Add a barebones implementation for registering persistent events with
perf. For that, we don't destroy the buffers when they're unmapped and
we map them read-only so that multiple agents can access them.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 include/linux/perf_event.h |   22 ++++++++++++++++-
 kernel/events/Makefile     |    2 +-
 kernel/events/core.c       |   32 ++++++++++++++++++++----
 kernel/events/persistent.c |   56 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 104 insertions(+), 8 deletions(-)
 create mode 100644 kernel/events/persistent.c

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index dda5b0a..bcc47d8 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -216,8 +216,9 @@ struct perf_event_attr {
 				precise_ip     :  2, /* skid constraint       */
 				mmap_data      :  1, /* non-exec mmap data    */
 				sample_id_all  :  1, /* sample_type all events */
+				persistent     :  1, /* event always on */
 
-				__reserved_1   : 45;
+				__reserved_1   : 44;
 
 	union {
 		__u32		wakeup_events;	  /* wakeup every n events */
@@ -1121,6 +1122,15 @@ 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 void perf_event_task_tick(void);
+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);
+extern struct perf_event *
+perf_enable_persistent_event(struct perf_event_attr *attr,
+			     int cpu, unsigned bufsz);
+extern void perf_disable_persistent_event(struct perf_event *event, int cpu);
+extern int perf_persistent_open(struct inode *inode, struct file *file);
+extern const struct file_operations perf_pers_fops;
 #else
 static inline void
 perf_event_task_sched_in(struct task_struct *task)			{ }
@@ -1155,6 +1165,16 @@ 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)		{ }
 static inline void perf_event_task_tick(void)				{ }
+static inline 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)		{}
+static inline struct perf_event *
+perf_enable_persistent_event(struct perf_event_attr *attr, int cpu,
+			     unsigned bufsz)				{ return -EINVAL; }
+static inline void
+perf_disable_persistent_event(struct perf_event *event, int cpu)	{}
+static inline int
+perf_persistent_open(struct inode *inode, struct file *file)		{ return -1; }
 #endif
 
 #define perf_output_put(handle, x) \
diff --git a/kernel/events/Makefile b/kernel/events/Makefile
index 26c00e4..e2d4d8e 100644
--- a/kernel/events/Makefile
+++ b/kernel/events/Makefile
@@ -2,4 +2,4 @@ ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_core.o = -pg
 endif
 
-obj-y += core.o
+obj-y += core.o persistent.o
diff --git a/kernel/events/core.c b/kernel/events/core.c
index b782b7a..a019e0f 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2301,7 +2301,7 @@ static void free_event_rcu(struct rcu_head *head)
 	kfree(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)
 {
@@ -2854,7 +2854,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;
@@ -2971,7 +2971,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;
@@ -3072,7 +3072,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;
@@ -3091,6 +3091,11 @@ static void perf_mmap_close(struct vm_area_struct *vma)
 {
 	struct perf_event *event = vma->vm_file->private_data;
 
+	if (event->attr.persistent) {
+		atomic_dec(&event->mmap_count);
+		return;
+	}
+
 	if (atomic_dec_and_mutex_lock(&event->mmap_count, &event->mmap_mutex)) {
 		unsigned long size = perf_data_size(event->buffer);
 		struct user_struct *user = event->mmap_user;
@@ -3133,7 +3138,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
 	if (event->cpu == -1 && event->attr.inherit)
 		return -EINVAL;
 
-	if (!(vma->vm_flags & VM_SHARED))
+	if (!(vma->vm_flags & VM_SHARED) && !event->attr.persistent)
 		return -EINVAL;
 
 	vma_size = vma->vm_end - vma->vm_start;
@@ -3242,6 +3247,16 @@ static const struct file_operations perf_fops = {
 	.fasync			= perf_fasync,
 };
 
+const struct file_operations perf_pers_fops = {
+	.llseek		= no_llseek,
+	.open		= perf_persistent_open,
+	.poll		= perf_poll,
+	.unlocked_ioctl	= perf_ioctl,
+	.compat_ioctl	= perf_ioctl,
+	.mmap		= perf_mmap,
+	.fasync		= perf_fasync,
+};
+
 /*
  * Perf event wakeup
  *
@@ -6043,7 +6058,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
 	mutex_unlock(&ctx->mutex);
 
 	return event;
-
 err_free:
 	free_event(event);
 err:
@@ -6093,6 +6107,12 @@ __perf_event_exit_task(struct perf_event *child_event,
 {
 	struct perf_event *parent_event;
 
+	/*
+	 * do not remove persistent events on task exit
+	 */
+	if (child_event->attr.persistent)
+		return;
+
 	perf_event_remove_from_context(child_event);
 
 	parent_event = child_event->parent;
diff --git a/kernel/events/persistent.c b/kernel/events/persistent.c
new file mode 100644
index 0000000..495ff87
--- /dev/null
+++ b/kernel/events/persistent.c
@@ -0,0 +1,56 @@
+#include <linux/perf_event.h>
+
+/*
+ * Pass in the @event pointer which receives the allocated event from
+ * perf on success. Check return code before touching @event further.
+ *
+ * @attr: perf attr template
+ * @cpu: on which cpu
+ * @nr_pages: perf buffer size in pages
+ *
+ */
+struct perf_event *perf_enable_persistent_event(struct perf_event_attr *attr,
+						int cpu, unsigned nr_pages)
+{
+	struct perf_buffer *buffer;
+	struct perf_event *ev;
+
+	ev = perf_event_create_kernel_counter(attr, cpu, NULL, NULL);
+	if (IS_ERR(ev))
+		return ev;
+
+	buffer = perf_buffer_alloc(nr_pages, 0, cpu, PERF_BUFFER_WRITABLE);
+	if (IS_ERR(buffer))
+		goto err;
+
+	rcu_assign_pointer(ev->buffer, buffer);
+	perf_event_enable(ev);
+
+	return ev;
+
+err:
+	perf_event_release_kernel(ev);
+	return ERR_PTR(-EINVAL);
+}
+
+void perf_disable_persistent_event(struct perf_event *event, int cpu)
+{
+	if (!event)
+		return;
+
+	perf_event_disable(event);
+
+	if (event->buffer) {
+		perf_buffer_put(event->buffer);
+		rcu_assign_pointer(event->buffer, NULL);
+	}
+
+	perf_event_release_kernel(event);
+}
+
+int perf_persistent_open(struct inode *inode, struct file *file)
+{
+	file->private_data = inode->i_private;
+
+	return 0;
+}
-- 
1.7.4.rc2


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

* [PATCH 03/12] x86, mce: Add persistent MCE event
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
  2011-01-21 15:09 ` [PATCH 01/12] perf: Start the massive restructuring Borislav Petkov
  2011-01-21 15:09 ` [PATCH 02/12] perf: Add persistent event facilities Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 15:09 ` [PATCH 04/12] perf: Add Makefile.lib Borislav Petkov
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Add the necessary glue to enable the mce_record tracepoint on boot,
turning it into a persistent event. This exports the MCE buffer to a
userspace daemon which will hook into it through debugfs when booting is
finished.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 arch/x86/include/asm/mce.h       |    8 ++++
 arch/x86/kernel/cpu/mcheck/mce.c |   86 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h
index eb16e94..eae0e29 100644
--- a/arch/x86/include/asm/mce.h
+++ b/arch/x86/include/asm/mce.h
@@ -91,6 +91,14 @@ struct mce_log {
 	struct mce entry[MCE_LOG_LEN];
 };
 
+/*
+ * a per-cpu descriptor of the persistent MCE tracepoint
+ */
+struct mce_tp_desc {
+	struct perf_event *event;
+	struct dentry *debugfs_entry;
+};
+
 #define MCE_OVERFLOW 0		/* bit 0 in flags means overflow */
 
 #define MCE_LOG_SIGNATURE	"MACHINECHECK"
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 7a35b72..56dc10d 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -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 mce_tp_desc, mce_event);
 static int			cpu_missing;
 
 /*
@@ -2053,6 +2054,90 @@ 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,
+	.persistent	= 1,
+};
+
+static struct dentry *mce_add_event_debugfs(struct perf_event *event, int cpu)
+{
+	char buf[14];
+
+	sprintf(buf, "mce_record%d", cpu);
+
+	return debugfs_create_file(buf, S_IRUGO | S_IWUSR,
+				   mce_get_debugfs_dir(),
+				   event, &perf_pers_fops);
+}
+
+#define PERF_MMAP_PAGES 128
+static int mce_enable_perf_event_on_cpu(int cpu)
+{
+	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+	int err = -EINVAL;
+
+	pattr.sample_period = 1;
+
+	d->event = perf_enable_persistent_event(&pattr, cpu, PERF_MMAP_PAGES);
+	if (IS_ERR(d->event)) {
+		printk(KERN_ERR "MCE: Error enabling event on cpu %d\n", cpu);
+		goto ret;
+	}
+
+	d->debugfs_entry = mce_add_event_debugfs(d->event, cpu);
+	if (!d->debugfs_entry) {
+		printk(KERN_ERR "MCE: Error adding event debugfs entry on cpu %d\n", cpu);
+		goto disable;
+	}
+
+	return 0;
+
+disable:
+	perf_disable_persistent_event(d->event, cpu);
+
+ret:
+	return err;
+}
+
+static void mce_disable_perf_event_on_cpu(int cpu)
+{
+	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+	debugfs_remove(d->debugfs_entry);
+	perf_disable_persistent_event(d->event, cpu);
+}
+
+static __init int mcheck_init_persistent_event(void)
+{
+	int cpu, err = 0;
+
+	get_online_cpus();
+
+	pattr.config = event_mce_record.event.type;
+
+	for_each_online_cpu(cpu)
+		if (mce_enable_perf_event_on_cpu(cpu))
+			goto err_unwind;
+
+	goto unlock;
+
+err_unwind:
+	err = -EINVAL;
+	for (--cpu; cpu >= 0; cpu--)
+		mce_disable_perf_event_on_cpu(cpu);
+
+unlock:
+	put_online_cpus();
+
+	return err;
+}
+
+/*
+ * This has to run after event_trace_init()
+ */
+device_initcall(mcheck_init_persistent_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)
@@ -2066,6 +2151,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);
+		mce_enable_perf_event_on_cpu(cpu);
 		break;
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
-- 
1.7.4.rc2


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

* [PATCH 04/12] perf: Add Makefile.lib
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
                   ` (2 preceding siblings ...)
  2011-01-21 15:09 ` [PATCH 03/12] x86, mce: Add persistent MCE event Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 15:09 ` [PATCH 05/12] perf: Export trace-event utils Borislav Petkov
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Put build settings which will be reused by other tools into a common
.lib file.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/perf/Makefile        |   63 +-----------------------------------------
 tools/scripts/Makefile.lib |   66 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 62 deletions(-)
 create mode 100644 tools/scripts/Makefile.lib

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 2b5387d..2c879e9 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -1,16 +1,8 @@
-ifeq ("$(origin O)", "command line")
-	OUTPUT := $(O)/
-endif
+include ../scripts/Makefile.lib
 
 # The default target of this Makefile is...
 all::
 
-ifneq ($(OUTPUT),)
-# check that the output directory actually exists
-OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
-$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
-endif
-
 # Define V=1 to have a more verbose compile.
 # Define V=2 to have an even more verbose compile.
 #
@@ -193,33 +185,6 @@ endif
 
 # CFLAGS and LDFLAGS are for the users to override from the command line.
 
-#
-# 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
-
 ifeq ("$(origin DEBUG)", "command line")
   PERF_DEBUG = $(DEBUG)
 endif
@@ -857,32 +822,6 @@ ifeq ($(PERL_PATH),)
 NO_PERL=NoThanks
 endif
 
-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_MKDIR    = @echo '   ' MKDIR $@;
-	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
-
 ifdef ASCIIDOC8
 	export ASCIIDOC8
 endif
diff --git a/tools/scripts/Makefile.lib b/tools/scripts/Makefile.lib
new file mode 100644
index 0000000..32cd06c
--- /dev/null
+++ b/tools/scripts/Makefile.lib
@@ -0,0 +1,66 @@
+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_MKDIR    = @echo '   ' MKDIR $@;
+	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)/
+	LIB_OUTPUT := $(OUTPUT)generic-lib/
+	__dummy := $(shell if [ ! -d $(LIB_OUTPUT) ]; then mkdir -p $(LIB_OUTPUT); fi)
+else
+        LIB_OUTPUT := $(PERF_TOP_DIR)/lib/
+endif
+
+ifneq ($(OUTPUT),)
+# check that the output directory actually exists
+OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
+$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
+endif
+
+#
+# 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
-- 
1.7.4.rc2


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

* [PATCH 05/12] perf: Export trace-event utils
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
                   ` (3 preceding siblings ...)
  2011-01-21 15:09 ` [PATCH 04/12] perf: Add Makefile.lib Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 15:09 ` [PATCH 06/12] perf: Remove duplicate enum trace_flag_type Borislav Petkov
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Export trace-event* utils into a sub-lib for wider use. While at it,
export functions for use by other entities later.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/Makefile                                     |   24 ++++++++
 tools/lib/trace/Makefile                           |   59 ++++++++++++++++++++
 tools/{perf/util => lib/trace}/trace-event-info.c  |   18 +++---
 tools/{perf/util => lib/trace}/trace-event-parse.c |   16 +++---
 tools/{perf/util => lib/trace}/trace-event-read.c  |    4 +-
 tools/{perf/util => lib/trace}/trace-event.h       |   16 ++++-
 tools/perf/Makefile                                |   10 +--
 tools/perf/bench/bench.h                           |    2 +
 tools/perf/builtin-kmem.c                          |    2 +-
 tools/perf/builtin-kvm.c                           |    2 +-
 tools/perf/builtin-lock.c                          |    2 +-
 tools/perf/builtin-sched.c                         |    2 +-
 tools/perf/builtin-script.c                        |    2 +-
 tools/perf/scripts/perl/Perf-Trace-Util/Context.c  |    2 +-
 .../perf/scripts/python/Perf-Trace-Util/Context.c  |    2 +-
 tools/perf/util/cache.h                            |    1 +
 tools/perf/util/header.c                           |    2 +-
 tools/perf/util/probe-event.c                      |    2 +-
 .../perf/util/scripting-engines/trace-event-perl.c |    2 +-
 .../util/scripting-engines/trace-event-python.c    |    2 +-
 tools/perf/util/trace-event-scripting.c            |    2 +-
 21 files changed, 132 insertions(+), 42 deletions(-)
 create mode 100644 tools/Makefile
 create mode 100644 tools/lib/trace/Makefile
 rename tools/{perf/util => lib/trace}/trace-event-info.c (97%)
 rename tools/{perf/util => lib/trace}/trace-event-parse.c (99%)
 rename tools/{perf/util => lib/trace}/trace-event-read.c (99%)
 rename tools/{perf/util => lib/trace}/trace-event.h (93%)

diff --git a/tools/Makefile b/tools/Makefile
new file mode 100644
index 0000000..cba6fcf
--- /dev/null
+++ b/tools/Makefile
@@ -0,0 +1,24 @@
+include scripts/Makefile.lib
+
+PERF_TOP_DIR := $(CURDIR)
+export PERF_TOP_DIR
+
+BASIC_CFLAGS = -I$(CURDIR)/lib
+
+# temporary for lib/trace/
+BASIC_CFLAGS += -I$(CURDIR)/perf/util/include
+
+export BASIC_CFLAGS
+
+perf: libtrace .FORCE
+	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
+
+libtrace: .FORCE
+	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1)
+
+clean:
+	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
+
+
+.PHONY: clean .FORCE
diff --git a/tools/lib/trace/Makefile b/tools/lib/trace/Makefile
new file mode 100644
index 0000000..d712317
--- /dev/null
+++ b/tools/lib/trace/Makefile
@@ -0,0 +1,59 @@
+include ../../scripts/Makefile.lib
+
+CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
+
+# Make the path relative to DESTDIR, not to prefix
+ifndef DESTDIR
+prefix = $(HOME)
+endif
+bindir_relative = bin
+bindir = $(prefix)/$(bindir_relative)
+mandir = share/man
+infodir = share/info
+sharedir = $(prefix)/share
+ifeq ($(prefix),/usr)
+sysconfdir = /etc
+else
+sysconfdir = $(prefix)/etc
+endif
+
+export prefix bindir sharedir sysconfdir
+
+CC = $(CROSS_COMPILE)gcc
+AR = $(CROSS_COMPILE)ar
+RM = rm -f
+TAR = tar
+FIND = find
+INSTALL = install
+RPMBUILD = rpmbuild
+PTHREAD_LIBS = -lpthread
+
+ifeq ("$(origin V)", "command line")
+  VERBOSE = $(V)
+endif
+ifndef VERBOSE
+  VERBOSE = 0
+endif
+
+TRACE_LIB = $(LIB_OUTPUT)libtrace.a
+
+all: $(TRACE_LIB)
+
+TRACE_LIB_H += trace-event.h
+
+TRACE_LIB_OBJS += trace-event-parse.o
+TRACE_LIB_OBJS += trace-event-read.o
+TRACE_LIB_OBJS += trace-event-info.o
+
+ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+
+$(OUTPUT)%.o: %.c
+	$(QUIET_CC)$(CC) -g -o $@ -c $(ALL_CFLAGS) $<
+
+$(TRACE_LIB): $(TRACE_LIB_OBJS) $(TRACE_LIB_H)
+	$(RM) $@;  $(AR) rcs $@ $(TRACE_LIB_OBJS)
+
+clean:
+	$(RM) *.a *.o *~ *.so $(TRACE_LIB)
+
+.PHONY: clean
diff --git a/tools/perf/util/trace-event-info.c b/tools/lib/trace/trace-event-info.c
similarity index 97%
rename from tools/perf/util/trace-event-info.c
rename to tools/lib/trace/trace-event-info.c
index 35729f4..052bf96 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/lib/trace/trace-event-info.c
@@ -37,10 +37,10 @@
 #include <linux/list.h>
 #include <linux/kernel.h>
 
-#include "../perf.h"
+#include "../../perf/perf.h"
 #include "trace-event.h"
-#include "debugfs.h"
-#include "evsel.h"
+#include "../../perf/util/debugfs.h"
+#include "../../perf/util/evsel.h"
 
 #define VERSION "0.5"
 
@@ -72,8 +72,6 @@ struct events {
 	char *name;
 };
 
-
-
 static void die(const char *fmt, ...)
 {
 	va_list ap;
@@ -136,7 +134,7 @@ static const char *find_tracing_dir(void)
 	return tracing;
 }
 
-static char *get_tracing_file(const char *name)
+char *get_tracing_file(const char *name)
 {
 	const char *tracing;
 	char *file;
@@ -231,7 +229,7 @@ static unsigned long get_size_fd(int fd)
 	return size;
 }
 
-static unsigned long get_size(const char *file)
+unsigned long get_filesize(const char *file)
 {
 	unsigned long long size = 0;
 	int fd;
@@ -340,7 +338,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)
 
 		if (ret >= 0) {
 			/* unfortunately, you can not stat debugfs files for size */
-			size = get_size(format);
+			size = get_filesize(format);
 			write_or_die(&size, 8);
 			check_size = copy_file(format);
 			if (size != check_size)
@@ -438,7 +436,7 @@ static void read_proc_kallsyms(void)
 		write_or_die(&size, 4);
 		return;
 	}
-	size = get_size(path);
+	size = get_filesize(path);
 	write_or_die(&size, 4);
 	check_size = copy_file(path);
 	if (size != check_size)
@@ -461,7 +459,7 @@ static void read_ftrace_printk(void)
 		write_or_die(&size, 4);
 		goto out;
 	}
-	size = get_size(path);
+	size = get_filesize(path);
 	write_or_die(&size, 4);
 	check_size = copy_file(path);
 	if (size != check_size)
diff --git a/tools/perf/util/trace-event-parse.c b/tools/lib/trace/trace-event-parse.c
similarity index 99%
rename from tools/perf/util/trace-event-parse.c
rename to tools/lib/trace/trace-event-parse.c
index 73a0222..eefae97 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/lib/trace/trace-event-parse.c
@@ -29,8 +29,8 @@
 #include <errno.h>
 
 #undef _GNU_SOURCE
-#include "../perf.h"
-#include "util.h"
+#include "../../perf/perf.h"
+#include "../../perf/util/util.h"
 #include "trace-event.h"
 
 int header_page_ts_offset;
@@ -44,7 +44,7 @@ int header_page_data_size;
 
 bool latency_format;
 
-static char *input_buf;
+static const char *input_buf;
 static unsigned long long input_buf_ptr;
 static unsigned long long input_buf_siz;
 
@@ -56,7 +56,7 @@ 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)
+void init_input_buf(const char *buf, unsigned long long size)
 {
 	input_buf = buf;
 	input_buf_siz = size;
@@ -338,7 +338,7 @@ void print_printk(void)
 	}
 }
 
-static struct event *alloc_event(void)
+struct event *alloc_event(void)
 {
 	struct event *event;
 
@@ -701,7 +701,7 @@ 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 *event_read_name(void)
 {
 	char *token;
 
@@ -721,7 +721,7 @@ static char *event_read_name(void)
 	return NULL;
 }
 
-static int event_read_id(void)
+int event_read_id(void)
 {
 	char *token;
 	int id;
@@ -986,7 +986,7 @@ fail_expect:
 	return -1;
 }
 
-static int event_read_format(struct event *event)
+int event_read_format(struct event *event)
 {
 	char *token;
 	int ret;
diff --git a/tools/perf/util/trace-event-read.c b/tools/lib/trace/trace-event-read.c
similarity index 99%
rename from tools/perf/util/trace-event-read.c
rename to tools/lib/trace/trace-event-read.c
index f55cc3a..f65dcaa 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/lib/trace/trace-event-read.c
@@ -36,8 +36,8 @@
 #include <ctype.h>
 #include <errno.h>
 
-#include "../perf.h"
-#include "util.h"
+#include "../../perf/perf.h"
+#include "../../perf/util/util.h"
 #include "trace-event.h"
 
 static int input_fd;
diff --git a/tools/perf/util/trace-event.h b/tools/lib/trace/trace-event.h
similarity index 93%
rename from tools/perf/util/trace-event.h
rename to tools/lib/trace/trace-event.h
index b5f12ca..4be3d7a 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/lib/trace/trace-event.h
@@ -1,8 +1,8 @@
-#ifndef __PERF_TRACE_EVENTS_H
-#define __PERF_TRACE_EVENTS_H
+#ifndef __LIB_TRACE_EVENTS_H
+#define __LIB_TRACE_EVENTS_H
 
 #include <stdbool.h>
-#include "parse-events.h"
+#include "../../perf/util/parse-events.h"
 
 #define __unused __attribute__((unused))
 
@@ -265,6 +265,14 @@ unsigned long long eval_flag(const char *flag);
 int read_tracing_data(int fd, struct list_head *pattrs);
 ssize_t read_tracing_data_size(int fd, struct list_head *pattrs);
 
+extern struct event *alloc_event(void);
+extern void init_input_buf(const char *buf, unsigned long long size);
+extern char *event_read_name(void);
+extern int event_read_id(void);
+extern int event_read_format(struct event *event);
+unsigned long get_filesize(const char *file);
+char *get_tracing_file(const char *name);
+
 /* taken from kernel/trace/trace.h */
 enum trace_flag_type {
 	TRACE_FLAG_IRQS_OFF		= 0x01,
@@ -296,4 +304,4 @@ int common_pc(struct scripting_context *context);
 int common_flags(struct scripting_context *context);
 int common_lock_depth(struct scripting_context *context);
 
-#endif /* __PERF_TRACE_EVENTS_H */
+#endif /* __LIB_TRACE_EVENTS_H */
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 2c879e9..292e163 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -265,7 +265,7 @@ endif
 # Those must not be GNU-specific; they are shared with perl/ which may
 # be built by a different compiler. (Note that this is an artifact now
 # but it still might be nice to keep that distinction.)
-BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include
+BASIC_CFLAGS += -Iutil/include -Iarch/$(ARCH)/include
 BASIC_LDFLAGS =
 
 # Guard against environment variables
@@ -326,6 +326,8 @@ export PERL_PATH
 
 LIB_FILE=$(OUTPUT)libperf.a
 
+EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a
+
 LIB_H += ../../include/linux/perf_event.h
 LIB_H += ../../include/linux/rbtree.h
 LIB_H += ../../include/linux/list.h
@@ -385,7 +387,6 @@ LIB_H += util/values.h
 LIB_H += util/sort.h
 LIB_H += util/hist.h
 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
@@ -429,9 +430,6 @@ 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
-LIB_OBJS += $(OUTPUT)util/trace-event-read.o
-LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
 LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
@@ -472,7 +470,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
 BUILTIN_OBJS += $(OUTPUT)builtin-test.o
 BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
 
-PERFLIBS = $(LIB_FILE)
+PERFLIBS = $(LIB_FILE) $(EXTRA_LIBS)
 
 #
 # Platform specific tweaks
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index f7781c6..0c7ee07 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -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);
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index def7ddc..9c13cb7 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -9,7 +9,7 @@
 #include "util/session.h"
 
 #include "util/parse-options.h"
-#include "util/trace-event.h"
+#include <trace/trace-event.h>
 
 #include "util/debug.h"
 
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 34d1e85..1981fe4 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -9,7 +9,7 @@
 #include "util/session.h"
 
 #include "util/parse-options.h"
-#include "util/trace-event.h"
+#include <trace/trace-event.h>
 
 #include "util/debug.h"
 
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index b9c6e54..c8729ae 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -8,7 +8,7 @@
 #include "util/header.h"
 
 #include "util/parse-options.h"
-#include "util/trace-event.h"
+#include <trace/trace-event.h>
 
 #include "util/debug.h"
 #include "util/session.h"
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 7a4ebeb..49f5b5a 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -9,7 +9,7 @@
 #include "util/session.h"
 
 #include "util/parse-options.h"
-#include "util/trace-event.h"
+#include <trace/trace-event.h>
 
 #include "util/debug.h"
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 150a606..b0a9ae3 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -9,7 +9,7 @@
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/thread.h"
-#include "util/trace-event.h"
+#include <trace/trace-event.h>
 #include "util/parse-options.h"
 #include "util/util.h"
 
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/Context.c b/tools/perf/scripts/perl/Perf-Trace-Util/Context.c
index 790ceba..bb52853 100644
--- a/tools/perf/scripts/perl/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/perl/Perf-Trace-Util/Context.c
@@ -32,7 +32,7 @@
 #include "perl.h"
 #include "XSUB.h"
 #include "../../../perf.h"
-#include "../../../util/trace-event.h"
+#include <trace/trace-event.h>
 
 #ifndef PERL_UNUSED_VAR
 #  define PERL_UNUSED_VAR(var) if (0) var = var
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index 315067b..7621a46 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -21,7 +21,7 @@
 
 #include <Python.h>
 #include "../../../perf.h"
-#include "../../../util/trace-event.h"
+#include <trace/trace-event.h>
 
 PyMODINIT_FUNC initperf_trace_context(void);
 
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index a772979..27e9ea3 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -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="
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 989fa2d..9010e69 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -11,7 +11,7 @@
 #include "util.h"
 #include "header.h"
 #include "../perf.h"
-#include "trace-event.h"
+#include <trace/trace-event.h>
 #include "session.h"
 #include "symbol.h"
 #include "debug.h"
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 128aaab..5fae966 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -43,7 +43,7 @@
 #include "symbol.h"
 #include "thread.h"
 #include "debugfs.h"
-#include "trace-event.h"	/* For __unused */
+#include <linux/compiler.h>	/* For __unused */
 #include "probe-event.h"
 #include "probe-finder.h"
 
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 9368081..15e6f7f 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -27,7 +27,7 @@
 
 #include "../../perf.h"
 #include "../util.h"
-#include "../trace-event.h"
+#include <trace/trace-event.h>
 
 #include <EXTERN.h>
 #include <perl.h>
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index c6d9933..5040bcc 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -29,7 +29,7 @@
 
 #include "../../perf.h"
 #include "../util.h"
-#include "../trace-event.h"
+#include <trace/trace-event.h>
 
 PyMODINIT_FUNC initperf_trace_context(void);
 
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index f7af2fc..94471ee 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -27,7 +27,7 @@
 
 #include "../perf.h"
 #include "util.h"
-#include "trace-event.h"
+#include <trace/trace-event.h>
 
 struct scripting_context *scripting_context;
 
-- 
1.7.4.rc2


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

* [PATCH 06/12] perf: Remove duplicate enum trace_flag_type
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
                   ` (4 preceding siblings ...)
  2011-01-21 15:09 ` [PATCH 05/12] perf: Export trace-event utils Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 15:09 ` [PATCH 07/12] perf: Export debugfs utilities Borislav Petkov
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Merge the two definitions.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/trace/trace-event.h  |   10 +++++++++-
 tools/perf/builtin-timechart.c |   21 ++-------------------
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/tools/lib/trace/trace-event.h b/tools/lib/trace/trace-event.h
index 4be3d7a..0c06b5b 100644
--- a/tools/lib/trace/trace-event.h
+++ b/tools/lib/trace/trace-event.h
@@ -273,7 +273,15 @@ extern int event_read_format(struct event *event);
 unsigned long get_filesize(const char *file);
 char *get_tracing_file(const char *name);
 
-/* taken from kernel/trace/trace.h */
+/*
+ * trace_flag_type is an enumeration that holds different
+ * states when a trace occurs. These are:
+ *  IRQS_OFF            - interrupts were disabled
+ *  IRQS_NOSUPPORT      - arch does not support irqs_disabled_flags
+ *  NEED_RESCED         - reschedule is requested
+ *  HARDIRQ             - inside an interrupt handler
+ *  SOFTIRQ             - inside a softirq handler
+ */
 enum trace_flag_type {
 	TRACE_FLAG_IRQS_OFF		= 0x01,
 	TRACE_FLAG_IRQS_NOSUPPORT	= 0x02,
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 746cf03..5333746 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -32,6 +32,8 @@
 #include "util/session.h"
 #include "util/svghelper.h"
 
+#include <trace/trace-event.h>
+
 #define SUPPORT_OLD_POWER_EVENTS 1
 #define PWR_EVENT_EXIT -1
 
@@ -330,25 +332,6 @@ struct wakeup_entry {
 	int   success;
 };
 
-/*
- * trace_flag_type is an enumeration that holds different
- * states when a trace occurs. These are:
- *  IRQS_OFF            - interrupts were disabled
- *  IRQS_NOSUPPORT      - arch does not support irqs_disabled_flags
- *  NEED_RESCED         - reschedule is requested
- *  HARDIRQ             - inside an interrupt handler
- *  SOFTIRQ             - inside a softirq handler
- */
-enum trace_flag_type {
-	TRACE_FLAG_IRQS_OFF		= 0x01,
-	TRACE_FLAG_IRQS_NOSUPPORT	= 0x02,
-	TRACE_FLAG_NEED_RESCHED		= 0x04,
-	TRACE_FLAG_HARDIRQ		= 0x08,
-	TRACE_FLAG_SOFTIRQ		= 0x10,
-};
-
-
-
 struct sched_switch {
 	struct trace_entry te;
 	char prev_comm[TASK_COMM_LEN];
-- 
1.7.4.rc2


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

* [PATCH 07/12] perf: Export debugfs utilities
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
                   ` (5 preceding siblings ...)
  2011-01-21 15:09 ` [PATCH 06/12] perf: Remove duplicate enum trace_flag_type Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 15:09 ` [PATCH 08/12] perf: Carve out mmap helpers for general use Borislav Petkov
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Export /proc/mounts parser and other debugfs-related helpers for general
use.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/Makefile                                     |    6 +++-
 tools/lib/lk/Makefile                              |   38 ++++++++++++++++++++
 tools/{perf/util => lib/lk}/debugfs.c              |    2 +-
 tools/{perf/util => lib/lk}/debugfs.h              |    7 ++--
 tools/{perf/util => lib/lk}/types.h                |    6 ++--
 tools/{perf/util => lib/lk}/usage.c                |    0
 tools/{perf/util => lib/lk}/util.h                 |    0
 tools/lib/perf/shared.h                            |    9 +++++
 tools/lib/trace/trace-event-info.c                 |    2 +-
 tools/lib/trace/trace-event-parse.c                |    2 +-
 tools/lib/trace/trace-event-read.c                 |    2 +-
 tools/perf/Makefile                                |    7 +---
 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-script.c                        |    2 +-
 tools/perf/builtin-stat.c                          |    2 +-
 tools/perf/builtin-timechart.c                     |    2 +-
 tools/perf/builtin-top.c                           |    2 +-
 tools/perf/builtin.h                               |    2 +-
 tools/perf/perf.c                                  |   21 +++++++----
 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/cpumap.c                           |    2 +-
 tools/perf/util/debug.c                            |    2 +-
 tools/perf/util/evsel.c                            |    2 +-
 tools/perf/util/evsel.h                            |    2 +-
 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-scripting.c            |    2 +-
 tools/perf/util/ui/browser.c                       |    2 +-
 tools/perf/util/ui/browser.h                       |    2 +-
 tools/perf/util/ui/browsers/hists.c                |    4 +-
 tools/perf/util/ui/util.c                          |    2 +-
 tools/perf/util/util.c                             |    2 +-
 tools/perf/util/values.c                           |    2 +-
 tools/perf/util/values.h                           |    2 +-
 tools/perf/util/xyarray.c                          |    2 +-
 67 files changed, 136 insertions(+), 83 deletions(-)
 create mode 100644 tools/lib/lk/Makefile
 rename tools/{perf/util => lib/lk}/debugfs.c (99%)
 rename tools/{perf/util => lib/lk}/debugfs.h (85%)
 rename tools/{perf/util => lib/lk}/types.h (83%)
 rename tools/{perf/util => lib/lk}/usage.c (100%)
 rename tools/{perf/util => lib/lk}/util.h (100%)
 create mode 100644 tools/lib/perf/shared.h

diff --git a/tools/Makefile b/tools/Makefile
index cba6fcf..779b141 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -10,14 +10,18 @@ BASIC_CFLAGS += -I$(CURDIR)/perf/util/include
 
 export BASIC_CFLAGS
 
-perf: libtrace .FORCE
+perf: libtrace liblk .FORCE
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
 
 libtrace: .FORCE
 	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1)
 
+liblk: .FORCE
+	$(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1)
+
 clean:
 	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
 
 
diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
new file mode 100644
index 0000000..0d58c28
--- /dev/null
+++ b/tools/lib/lk/Makefile
@@ -0,0 +1,38 @@
+include ../../scripts/Makefile.lib
+
+# guard against environment variables
+LIB_H=
+LIB_OBJS=
+
+LIB_H += debugfs.h
+LIB_H += util.h
+LIB_H += types.h
+
+LIB_OBJS += debugfs.o
+LIB_OBJS += usage.o
+
+LIBFILE = $(LIB_OUTPUT)liblk.a
+
+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)
+
+RM = rm -f
+
+$(LIBFILE): $(LIB_OBJS)
+	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
+
+$(LIB_OBJS): $(LIB_H)
+
+%.o: %.c
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+%.s: %.c
+	$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
+%.o: %.S
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+
+clean:
+	$(RM) $(LIB_OBJS) $(LIBFILE)
+
+.PHONY: clean
diff --git a/tools/perf/util/debugfs.c b/tools/lib/lk/debugfs.c
similarity index 99%
rename from tools/perf/util/debugfs.c
rename to tools/lib/lk/debugfs.c
index a88fefc..569b6b2 100644
--- a/tools/perf/util/debugfs.c
+++ b/tools/lib/lk/debugfs.c
@@ -1,6 +1,6 @@
 #include "util.h"
 #include "debugfs.h"
-#include "cache.h"
+#include <perf/shared.h>
 
 static int debugfs_premounted;
 static char debugfs_mountpoint[MAX_PATH+1];
diff --git a/tools/perf/util/debugfs.h b/tools/lib/lk/debugfs.h
similarity index 85%
rename from tools/perf/util/debugfs.h
rename to tools/lib/lk/debugfs.h
index 83a0287..8d12a5b 100644
--- a/tools/perf/util/debugfs.h
+++ b/tools/lib/lk/debugfs.h
@@ -1,7 +1,8 @@
-#ifndef __DEBUGFS_H__
-#define __DEBUGFS_H__
+#ifndef __LK_DEBUGFS_H__
+#define __LK_DEBUGFS_H__
 
 #include <sys/mount.h>
+#include <sys/types.h>
 
 #ifndef MAX_PATH
 # define MAX_PATH 256
@@ -22,4 +23,4 @@ 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__ */
+#endif /* __LK_DEBUGFS_H__ */
diff --git a/tools/perf/util/types.h b/tools/lib/lk/types.h
similarity index 83%
rename from tools/perf/util/types.h
rename to tools/lib/lk/types.h
index 7d6b833..eda6c0c 100644
--- a/tools/perf/util/types.h
+++ b/tools/lib/lk/types.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_TYPES_H
-#define __PERF_TYPES_H
+#ifndef __LK_TYPES_H
+#define __LK_TYPES_H
 
 /*
  * We define u64 as unsigned long long for every architecture
@@ -14,4 +14,4 @@ typedef signed short	   s16;
 typedef unsigned char	   u8;
 typedef signed char	   s8;
 
-#endif /* __PERF_TYPES_H */
+#endif /* __LK_TYPES_H */
diff --git a/tools/perf/util/usage.c b/tools/lib/lk/usage.c
similarity index 100%
rename from tools/perf/util/usage.c
rename to tools/lib/lk/usage.c
diff --git a/tools/perf/util/util.h b/tools/lib/lk/util.h
similarity index 100%
rename from tools/perf/util/util.h
rename to tools/lib/lk/util.h
diff --git a/tools/lib/perf/shared.h b/tools/lib/perf/shared.h
new file mode 100644
index 0000000..77344ff
--- /dev/null
+++ b/tools/lib/perf/shared.h
@@ -0,0 +1,9 @@
+#ifndef __PERF_SHARED_H
+#define __PERF_SHARED_H
+
+/*
+ * Common defines shared between perf and the libs
+ */
+#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
+
+#endif /* __PERF_SHARED_H */
diff --git a/tools/lib/trace/trace-event-info.c b/tools/lib/trace/trace-event-info.c
index 052bf96..808bdfa 100644
--- a/tools/lib/trace/trace-event-info.c
+++ b/tools/lib/trace/trace-event-info.c
@@ -39,7 +39,7 @@
 
 #include "../../perf/perf.h"
 #include "trace-event.h"
-#include "../../perf/util/debugfs.h"
+#include <lk/debugfs.h>
 #include "../../perf/util/evsel.h"
 
 #define VERSION "0.5"
diff --git a/tools/lib/trace/trace-event-parse.c b/tools/lib/trace/trace-event-parse.c
index eefae97..9e46957 100644
--- a/tools/lib/trace/trace-event-parse.c
+++ b/tools/lib/trace/trace-event-parse.c
@@ -30,7 +30,7 @@
 
 #undef _GNU_SOURCE
 #include "../../perf/perf.h"
-#include "../../perf/util/util.h"
+#include <lk/util.h>
 #include "trace-event.h"
 
 int header_page_ts_offset;
diff --git a/tools/lib/trace/trace-event-read.c b/tools/lib/trace/trace-event-read.c
index f65dcaa..1eda805 100644
--- a/tools/lib/trace/trace-event-read.c
+++ b/tools/lib/trace/trace-event-read.c
@@ -37,7 +37,7 @@
 #include <errno.h>
 
 #include "../../perf/perf.h"
-#include "../../perf/util/util.h"
+#include <lk/util.h>
 #include "trace-event.h"
 
 static int input_fd;
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 292e163..b27c1fe 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -326,7 +326,7 @@ export PERL_PATH
 
 LIB_FILE=$(OUTPUT)libperf.a
 
-EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a
+EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a
 
 LIB_H += ../../include/linux/perf_event.h
 LIB_H += ../../include/linux/rbtree.h
@@ -361,17 +361,14 @@ 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/evsel.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/xyarray.h
 LIB_H += util/header.h
 LIB_H += util/help.h
@@ -398,7 +395,6 @@ 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/evsel.o
@@ -416,7 +412,6 @@ 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
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c
index db82021..96e0ff3 100644
--- a/tools/perf/bench/mem-memcpy.c
+++ b/tools/perf/bench/mem-memcpy.c
@@ -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"
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c
index d1d1b30..37f12ad 100644
--- a/tools/perf/bench/sched-messaging.c
+++ b/tools/perf/bench/sched-messaging.c
@@ -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"
diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index d9ab3ce..9b05c92 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -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"
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index c056cdc..fab6c44 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -7,7 +7,7 @@
  */
 #include "builtin.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 
 #include "util/color.h"
 #include <linux/list.h>
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index fcb9626..4ae8ea2 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -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"
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 3153e49..c6ecc77 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -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>
 
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 9c13cb7..dc8c362 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -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"
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 1981fe4..e09ed03 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -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"
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index c8729ae..6023e3a 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -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"
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index add163c..80e57cd 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -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"
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 7bc0490..d19b25b 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -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"
 
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 75183a4..60e2535 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -7,7 +7,7 @@
  */
 #include "builtin.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 
 #include "util/color.h"
 #include <linux/list.h>
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 49f5b5a..517ff2d 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -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"
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index b0a9ae3..7a874f2 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -11,7 +11,7 @@
 #include "util/thread.h"
 #include <trace/trace-event.h>
 #include "util/parse-options.h"
-#include "util/util.h"
+#include <lk/util.h>
 
 static char const		*script_name;
 static char const		*generate_script_lang;
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 2dfcb61..f9f0e4c 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -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"
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 5333746..db93b4f 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -14,7 +14,7 @@
 
 #include "builtin.h"
 
-#include "util/util.h"
+#include <lk/util.h>
 
 #include "util/color.h"
 #include <linux/list.h>
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 1e67ab9..e9ed062 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -25,7 +25,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"
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index c7798c7..8500642 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -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[];
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 5b1ecd6..8204bad 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -13,7 +13,8 @@
 #include "util/quote.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
-#include "util/debugfs.h"
+#include <lk/debugfs.h>
+#include <perf/shared.h>
 
 const char perf_usage_string[] =
 	"perf [--version] [--help] COMMAND [ARGS]";
@@ -418,14 +419,17 @@ static int run_argv(int *argcp, const char ***argv)
 }
 
 /* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
-static void get_debugfs_mntpt(void)
+static bool get_debugfs_mntpt(void)
 {
 	const char *path = debugfs_mount(NULL);
 
-	if (path)
+	if (path) {
 		strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
-	else
-		debugfs_mntpt[0] = '\0';
+		return true;
+	}
+
+	debugfs_mntpt[0] = '\0';
+	return false;
 }
 
 int main(int argc, const char **argv)
@@ -435,8 +439,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();
+
+	/* Establish a debugfs mountpoint */
+	if (!get_debugfs_mntpt())
+		die("cannot find valid debugfs mountpoint");
+
 	/*
 	 * "perf-xxxx" is the same as "perf xxxx", but we obviously:
 	 *
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 95aaf56..4bfd513 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -91,7 +91,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>
 
 /*
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index deffb8c..0055cc8 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -6,7 +6,7 @@
  * Copyright (C) 2009, 2010 Red Hat Inc.
  * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com>
  */
-#include "util.h"
+#include <lk/util.h>
 #include <stdio.h>
 #include "build-id.h"
 #include "event.h"
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 27e9ea3..67f8a56 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -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 *);
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index e12d539..732fe7d 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -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)
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index e02d78c..bb2f5a0 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -5,7 +5,7 @@
  * Copyright (C) Johannes Schindelin, 2005
  *
  */
-#include "util.h"
+#include <lk/util.h>
 #include "cache.h"
 #include "exec_cmd.h"
 
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 3ccaa10..92a09cb 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "../perf.h"
 #include "cpumap.h"
 #include <assert.h>
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 01bbe8e..d0f2332 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -10,7 +10,7 @@
 #include "color.h"
 #include "event.h"
 #include "debug.h"
-#include "util.h"
+#include <lk/util.h>
 
 int verbose;
 bool dump_trace = false, quiet = false;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 1a5591d..9a49069 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1,6 +1,6 @@
 #include "evsel.h"
 #include "../perf.h"
-#include "util.h"
+#include <lk/util.h>
 #include "cpumap.h"
 #include "thread.h"
 
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index b2d755f..b252220 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -4,7 +4,7 @@
 #include <linux/list.h>
 #include <stdbool.h>
 #include "../../../include/linux/perf_event.h"
-#include "types.h"
+#include <lk/types.h>
 #include "xyarray.h"
  
 struct perf_counts_values {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 9010e69..8e4c5c8 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -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/trace-event.h>
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 33f16be..0a7d04a 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -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>
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index c749ba6..0b958d5 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "build-id.h"
 #include "hist.h"
 #include "session.h"
diff --git a/tools/perf/util/include/linux/ctype.h b/tools/perf/util/include/linux/ctype.h
index a53d4ee..0698f26 100644
--- a/tools/perf/util/include/linux/ctype.h
+++ b/tools/perf/util/include/linux/ctype.h
@@ -1 +1 @@
-#include "../util.h"
+#include <lk/util.h>
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index b397c03..7e78d8b 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -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,
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 5cb6f4b..b17b01f 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1,5 +1,5 @@
 #include "../../../include/linux/hw_breakpoint.h"
-#include "util.h"
+#include <lk/util.h>
 #include "../perf.h"
 #include "evsel.h"
 #include "parse-options.h"
@@ -9,7 +9,7 @@
 #include "symbol.h"
 #include "cache.h"
 #include "header.h"
-#include "debugfs.h"
+#include <lk/debugfs.h>
 
 int				nr_counters;
 
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 99d02aa..25b57fc 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "parse-options.h"
 #include "cache.h"
 
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 5fae966..d0c1973 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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 <linux/compiler.h>	/* For __unused */
 #include "probe-event.h"
 #include "probe-finder.h"
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index ab83b6a..c7db30a 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -35,7 +35,7 @@
 
 #include "event.h"
 #include "debug.h"
-#include "util.h"
+#include <lk/util.h>
 #include "symbol.h"
 #include "probe-finder.h"
 
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index beaefc3..688c3a4 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -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
diff --git a/tools/perf/util/pstack.c b/tools/perf/util/pstack.c
index 13d36fa..aacedb8 100644
--- a/tools/perf/util/pstack.c
+++ b/tools/perf/util/pstack.c
@@ -4,7 +4,7 @@
  * (c) 2010 Arnaldo Carvalho de Melo <acme@redhat.com>
  */
 
-#include "util.h"
+#include <lk/util.h>
 #include "pstack.h"
 #include <linux/kernel.h>
 #include <stdlib.h>
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 15e6f7f..413c1b6 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -26,7 +26,7 @@
 #include <errno.h>
 
 #include "../../perf.h"
-#include "../util.h"
+#include <lk/util.h>
 #include <trace/trace-event.h>
 
 #include <EXTERN.h>
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 5040bcc..537313d 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -28,7 +28,7 @@
 #include <errno.h>
 
 #include "../../perf.h"
-#include "../util.h"
+#include <lk/util.h>
 #include <trace/trace-event.h>
 
 PyMODINIT_FUNC initperf_trace_context(void);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 6fb4694..414c1a5 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -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)
 {
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 0b91053..ecfd0c6 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -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>
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index 8fc0bd3..026472d 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include "string.h"
 
 #define K 1024LL
diff --git a/tools/perf/util/svghelper.h b/tools/perf/util/svghelper.h
index e078198..ac74b40 100644
--- a/tools/perf/util/svghelper.h
+++ b/tools/perf/util/svghelper.h
@@ -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);
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 00f4ead..aabd3cc 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -4,7 +4,7 @@
 #include <string.h>
 #include "session.h"
 #include "thread.h"
-#include "util.h"
+#include <lk/util.h>
 #include "debug.h"
 
 /* Skip "." and ".." directories */
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index 94471ee..e97b15a 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -26,7 +26,7 @@
 #include <errno.h>
 
 #include "../perf.h"
-#include "util.h"
+#include <lk/util.h>
 #include <trace/trace-event.h>
 
 struct scripting_context *scripting_context;
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c
index 8bc010e..55cd105 100644
--- a/tools/perf/util/ui/browser.c
+++ b/tools/perf/util/ui/browser.c
@@ -7,7 +7,7 @@
 #include "browser.h"
 #include "helpline.h"
 #include "../color.h"
-#include "../util.h"
+#include <lk/util.h>
 #include <stdio.h>
 
 static int ui_browser__percent_color(double percent, bool current)
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h
index 0dc7e4d..cf5ce00 100644
--- a/tools/perf/util/ui/browser.h
+++ b/tools/perf/util/ui/browser.h
@@ -4,7 +4,7 @@
 #include <stdbool.h>
 #include <newt.h>
 #include <sys/types.h>
-#include "../types.h"
+#include <lk/types.h>
 
 #define HE_COLORSET_TOP		50
 #define HE_COLORSET_MEDIUM	51
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c
index ebda8c3..27f6e09 100644
--- a/tools/perf/util/ui/browsers/hists.c
+++ b/tools/perf/util/ui/browsers/hists.c
@@ -10,11 +10,11 @@
 #include "../../hist.h"
 #include "../../pstack.h"
 #include "../../sort.h"
-#include "../../util.h"
+#include <lk/util.h>
 
 #include "../browser.h"
 #include "../helpline.h"
-#include "../util.h"
+#include <lk/util.h>
 #include "map.h"
 
 struct hist_browser {
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c
index 7b5a892..c4a7bcd 100644
--- a/tools/perf/util/ui/util.c
+++ b/tools/perf/util/ui/util.c
@@ -9,7 +9,7 @@
 #include "../debug.h"
 #include "browser.h"
 #include "helpline.h"
-#include "util.h"
+#include <lk/util.h>
 
 static void newt_form__set_exit_keys(newtComponent self)
 {
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 5b3ea49..87c30b1 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -1,4 +1,4 @@
-#include "util.h"
+#include <lk/util.h>
 #include <sys/mman.h>
 
 int mkdir_p(char *path, mode_t mode)
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c
index cfa55d6..648fc48 100644
--- a/tools/perf/util/values.c
+++ b/tools/perf/util/values.c
@@ -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)
diff --git a/tools/perf/util/values.h b/tools/perf/util/values.h
index 2fa967e..f762cb7 100644
--- a/tools/perf/util/values.h
+++ b/tools/perf/util/values.h
@@ -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;
diff --git a/tools/perf/util/xyarray.c b/tools/perf/util/xyarray.c
index 22afbf6..979a90f 100644
--- a/tools/perf/util/xyarray.c
+++ b/tools/perf/util/xyarray.c
@@ -1,5 +1,5 @@
 #include "xyarray.h"
-#include "util.h"
+#include <lk/util.h>
 
 struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
 {
-- 
1.7.4.rc2


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

* [PATCH 08/12] perf: Carve out mmap helpers for general use
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
                   ` (6 preceding siblings ...)
  2011-01-21 15:09 ` [PATCH 07/12] perf: Export debugfs utilities Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 17:29   ` Arnaldo Carvalho de Melo
  2011-01-21 15:09 ` [PATCH 09/12] perf: Export util.ch into library Borislav Petkov
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

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

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/Makefile              |    8 +++-
 tools/lib/perf/Makefile     |   35 +++++++++++++++
 tools/lib/perf/mmap.c       |   91 ++++++++++++++++++++++++++++++++++++++
 tools/lib/perf/mmap.h       |   13 +++++
 tools/perf/Makefile         |    2 +-
 tools/perf/builtin-record.c |  103 ++++---------------------------------------
 tools/perf/builtin-top.c    |   25 ++--------
 7 files changed, 160 insertions(+), 117 deletions(-)
 create mode 100644 tools/lib/perf/Makefile
 create mode 100644 tools/lib/perf/mmap.c
 create mode 100644 tools/lib/perf/mmap.h

diff --git a/tools/Makefile b/tools/Makefile
index 779b141..71dce04 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -3,14 +3,14 @@ include scripts/Makefile.lib
 PERF_TOP_DIR := $(CURDIR)
 export PERF_TOP_DIR
 
-BASIC_CFLAGS = -I$(CURDIR)/lib
+BASIC_CFLAGS = -I$(CURDIR)/lib -I$(CURDIR)/perf
 
 # temporary for lib/trace/
 BASIC_CFLAGS += -I$(CURDIR)/perf/util/include
 
 export BASIC_CFLAGS
 
-perf: libtrace liblk .FORCE
+perf: libtrace liblk liblkperf .FORCE
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1)
 
 libtrace: .FORCE
@@ -19,9 +19,13 @@ libtrace: .FORCE
 liblk: .FORCE
 	$(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1)
 
+liblkperf:
+	$(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1)
+
 clean:
 	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
 
 
diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile
new file mode 100644
index 0000000..2ae7e8d
--- /dev/null
+++ b/tools/lib/perf/Makefile
@@ -0,0 +1,35 @@
+include ../../scripts/Makefile.lib
+
+# guard against environment variables
+LIB_H=
+LIB_OBJS=
+
+LIB_H += mmap.h
+
+LIB_OBJS += mmap.o
+
+LIBFILE = $(LIB_OUTPUT)liblkperf.a
+
+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)
+
+RM = rm -f
+
+$(LIBFILE): $(LIB_OBJS)
+	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
+
+$(LIB_OBJS): $(LIB_H)
+
+%.o: %.c
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+%.s: %.c
+	$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
+%.o: %.S
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+
+clean:
+	$(RM) $(LIB_OBJS) $(LIBFILE)
+
+.PHONY: clean
diff --git a/tools/lib/perf/mmap.c b/tools/lib/perf/mmap.c
new file mode 100644
index 0000000..250148d
--- /dev/null
+++ b/tools/lib/perf/mmap.c
@@ -0,0 +1,91 @@
+#include <stdio.h>
+#include <perf.h>
+#include "mmap.h"
+
+unsigned long mmap_read_head(struct mmap_data *md)
+{
+	struct perf_event_mmap_page *pc = md->base;
+	long head;
+
+	head = pc->data_head;
+	rmb();
+
+	return head;
+}
+
+static void mmap_write_tail(struct mmap_data *md, unsigned long tail)
+{
+	struct perf_event_mmap_page *pc = md->base;
+
+	/*
+	 * ensure all reads are done before we write the tail out.
+	 */
+	/* mb(); */
+	pc->data_tail = tail;
+}
+
+static unsigned long mmap_read(struct mmap_data *md,
+			       void (*write_output)(void *, size_t))
+{
+	unsigned int head = mmap_read_head(md);
+	unsigned int old = md->prev;
+	unsigned int page_size = sysconf(_SC_PAGE_SIZE);
+	unsigned char *data = md->base + page_size;
+	unsigned long size, samples = 0;
+	void *buf;
+	int diff;
+
+	/*
+	 * If we're further behind than half the buffer, there's a chance
+	 * the writer will bite our tail and mess up the samples under us.
+	 *
+	 * If we somehow ended up ahead of the head, we got messed up.
+	 *
+	 * In either case, truncate and restart at head.
+	 */
+	diff = head - old;
+	if (diff < 0) {
+		fprintf(stderr, "WARNING: failed to keep up with mmap data\n");
+		/*
+		 * head points to a known good entry, start there.
+		 */
+		old = head;
+	}
+
+	if (old != head)
+		samples++;
+
+	size = head - old;
+
+	if ((old & md->mask) + size != (head & md->mask)) {
+		buf = &data[old & md->mask];
+		size = md->mask + 1 - (old & md->mask);
+		old += size;
+
+		write_output(buf, size);
+	}
+
+	buf = &data[old & md->mask];
+	size = head - old;
+	old += size;
+
+	write_output(buf, size);
+
+	md->prev = old;
+	mmap_write_tail(md, old);
+
+	return samples;
+}
+
+unsigned long mmap_read_all(struct mmap_data *mmap_array, int nr_cpus,
+			    void (*write_output)(void *, size_t))
+{
+	int i;
+	unsigned long samples = 0;
+
+	for (i = 0; i < nr_cpus; i++) {
+		if (mmap_array[i].base)
+			samples += mmap_read(&mmap_array[i], write_output);
+	}
+	return samples;
+}
diff --git a/tools/lib/perf/mmap.h b/tools/lib/perf/mmap.h
new file mode 100644
index 0000000..e2f30ef
--- /dev/null
+++ b/tools/lib/perf/mmap.h
@@ -0,0 +1,13 @@
+#ifndef __PERF_MMAP_H
+#define __PERF_MMAP_H
+
+struct mmap_data {
+	void			*base;
+	unsigned int		mask;
+	unsigned int		prev;
+};
+
+unsigned long mmap_read_head(struct mmap_data *);
+unsigned long mmap_read_all(struct mmap_data *, int,
+			    void (*write_output)(void *, size_t));
+#endif /* __PERF_MMAP_H */
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index b27c1fe..bab175d 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -326,7 +326,7 @@ export PERL_PATH
 
 LIB_FILE=$(OUTPUT)libperf.a
 
-EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a
+EXTRA_LIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a $(LIB_OUTPUT)liblkperf.a
 
 LIB_H += ../../include/linux/perf_event.h
 LIB_H += ../../include/linux/rbtree.h
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d19b25b..17d7217 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -12,7 +12,6 @@
 #include "perf.h"
 
 #include "util/build-id.h"
-#include <lk/util.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 
@@ -24,6 +23,9 @@
 #include "util/symbol.h"
 #include "util/cpumap.h"
 
+#include <lk/util.h>
+#include <perf/mmap.h>
+
 #include <unistd.h>
 #include <sched.h>
 #include <sys/mman.h>
@@ -66,7 +68,7 @@ static bool			sample_time			=  false;
 static bool			no_buildid			=  false;
 static bool			no_buildid_cache		=  false;
 
-static long			samples				=      0;
+static unsigned long		samples				=      0;
 static u64			bytes_written			=      0;
 
 static struct pollfd		*event_array;
@@ -80,36 +82,8 @@ static off_t			post_processing_offset;
 static struct perf_session	*session;
 static const char		*cpu_list;
 
-struct mmap_data {
-	void			*base;
-	unsigned int		mask;
-	unsigned int		prev;
-};
-
 static struct mmap_data		mmap_array[MAX_NR_CPUS];
 
-static unsigned long mmap_read_head(struct mmap_data *md)
-{
-	struct perf_event_mmap_page *pc = md->base;
-	long head;
-
-	head = pc->data_head;
-	rmb();
-
-	return head;
-}
-
-static void mmap_write_tail(struct mmap_data *md, unsigned long tail)
-{
-	struct perf_event_mmap_page *pc = md->base;
-
-	/*
-	 * ensure all reads are done before we write the tail out.
-	 */
-	/* mb(); */
-	pc->data_tail = tail;
-}
-
 static void advance_output(size_t size)
 {
 	bytes_written += size;
@@ -138,55 +112,6 @@ static int process_synthesized_event(event_t *event,
 	return 0;
 }
 
-static void mmap_read(struct mmap_data *md)
-{
-	unsigned int head = mmap_read_head(md);
-	unsigned int old = md->prev;
-	unsigned char *data = md->base + page_size;
-	unsigned long size;
-	void *buf;
-	int diff;
-
-	/*
-	 * If we're further behind than half the buffer, there's a chance
-	 * the writer will bite our tail and mess up the samples under us.
-	 *
-	 * If we somehow ended up ahead of the head, we got messed up.
-	 *
-	 * In either case, truncate and restart at head.
-	 */
-	diff = head - old;
-	if (diff < 0) {
-		fprintf(stderr, "WARNING: failed to keep up with mmap data\n");
-		/*
-		 * head points to a known good entry, start there.
-		 */
-		old = head;
-	}
-
-	if (old != head)
-		samples++;
-
-	size = head - old;
-
-	if ((old & md->mask) + size != (head & md->mask)) {
-		buf = &data[old & md->mask];
-		size = md->mask + 1 - (old & md->mask);
-		old += size;
-
-		write_output(buf, size);
-	}
-
-	buf = &data[old & md->mask];
-	size = head - old;
-	old += size;
-
-	write_output(buf, size);
-
-	md->prev = old;
-	mmap_write_tail(md, old);
-}
-
 static volatile int done = 0;
 static volatile int signr = -1;
 
@@ -522,19 +447,6 @@ static struct perf_event_header finished_round_event = {
 	.type = PERF_RECORD_FINISHED_ROUND,
 };
 
-static void mmap_read_all(void)
-{
-	int i;
-
-	for (i = 0; i < nr_cpu; i++) {
-		if (mmap_array[i].base)
-			mmap_read(&mmap_array[i]);
-	}
-
-	if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO))
-		write_output(&finished_round_event, sizeof(finished_round_event));
-}
-
 static int __cmd_record(int argc, const char **argv)
 {
 	int i;
@@ -774,10 +686,13 @@ static int __cmd_record(int argc, const char **argv)
 		close(go_pipe[1]);
 
 	for (;;) {
-		int hits = samples;
+		unsigned long hits = samples;
 		int thread;
 
-		mmap_read_all();
+		samples = mmap_read_all(mmap_array, nr_cpu, write_output);
+
+		if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO))
+			write_output(&finished_round_event, sizeof(finished_round_event));
 
 		if (hits == samples) {
 			if (done)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index e9ed062..703899b 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -25,8 +25,6 @@
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/thread.h"
-#include <lk/util.h>
-#include <linux/rbtree.h>
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 #include "util/cpumap.h"
@@ -34,6 +32,10 @@
 
 #include "util/debug.h"
 
+#include <linux/rbtree.h>
+#include <lk/util.h>
+#include <perf/mmap.h>
+
 #include <assert.h>
 #include <fcntl.h>
 
@@ -1091,12 +1093,6 @@ static void event__process_sample(const event_t *self,
 	}
 }
 
-struct mmap_data {
-	void			*base;
-	int			mask;
-	unsigned int		prev;
-};
-
 static int perf_evsel__alloc_mmap_per_thread(struct perf_evsel *evsel,
 					     int ncpus, int nthreads)
 {
@@ -1110,17 +1106,6 @@ static void perf_evsel__free_mmap(struct perf_evsel *evsel)
 	evsel->priv = NULL;
 }
 
-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 perf_evsel *evsel,
 					    int cpu, int thread_idx)
@@ -1142,7 +1127,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 int)diff > md->mask / 2 || diff < 0) {
 		fprintf(stderr, "WARNING: failed to keep up with mmap data.\n");
 
 		/*
-- 
1.7.4.rc2


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

* [PATCH 09/12] perf: Export util.ch into library
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
                   ` (7 preceding siblings ...)
  2011-01-21 15:09 ` [PATCH 08/12] perf: Carve out mmap helpers for general use Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 15:09 ` [PATCH 10/12] perf: Export ctype.c Borislav Petkov
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

This is needed for shared common functionality.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/lk/Makefile              |    1 +
 tools/{perf/util => lib/lk}/util.c |    0
 tools/lib/perf/Makefile            |    1 +
 tools/lib/perf/util.h              |    8 ++++++++
 tools/perf/Makefile                |    1 -
 tools/perf/perf.h                  |    3 ---
 tools/perf/util/cpumap.c           |    2 +-
 tools/perf/util/parse-events.h     |    1 +
 8 files changed, 12 insertions(+), 5 deletions(-)
 rename tools/{perf/util => lib/lk}/util.c (100%)
 create mode 100644 tools/lib/perf/util.h

diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
index 0d58c28..2e7e02c 100644
--- a/tools/lib/lk/Makefile
+++ b/tools/lib/lk/Makefile
@@ -10,6 +10,7 @@ LIB_H += types.h
 
 LIB_OBJS += debugfs.o
 LIB_OBJS += usage.o
+LIB_OBJS += util.o
 
 LIBFILE = $(LIB_OUTPUT)liblk.a
 
diff --git a/tools/perf/util/util.c b/tools/lib/lk/util.c
similarity index 100%
rename from tools/perf/util/util.c
rename to tools/lib/lk/util.c
diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile
index 2ae7e8d..68def92 100644
--- a/tools/lib/perf/Makefile
+++ b/tools/lib/perf/Makefile
@@ -5,6 +5,7 @@ LIB_H=
 LIB_OBJS=
 
 LIB_H += mmap.h
+LIB_H += util.h
 
 LIB_OBJS += mmap.o
 
diff --git a/tools/lib/perf/util.h b/tools/lib/perf/util.h
new file mode 100644
index 0000000..4b774b9
--- /dev/null
+++ b/tools/lib/perf/util.h
@@ -0,0 +1,8 @@
+#ifndef __PERF_UTIL_H
+#define __PERF_UTIL_H
+
+#define MAX_COUNTERS			256
+#define MAX_NR_CPUS			256
+
+#endif /* __PERF_UTIL_H */
+
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index bab175d..2edc5d9 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -430,7 +430,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
 LIB_OBJS += $(OUTPUT)util/xyarray.o
 LIB_OBJS += $(OUTPUT)util/cpumap.o
 
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 4bfd513..785a200 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -136,9 +136,6 @@ sys_perf_event_open(struct perf_event_attr *attr,
 		       group_fd, flags);
 }
 
-#define MAX_COUNTERS			256
-#define MAX_NR_CPUS			256
-
 struct ip_callchain {
 	u64 nr;
 	u64 ips[0];
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 92a09cb..76f3de5 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -1,5 +1,5 @@
 #include <lk/util.h>
-#include "../perf.h"
+#include <perf/util.h>
 #include "cpumap.h"
 #include <assert.h>
 #include <stdio.h>
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index b82cafb..c29c407 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -3,6 +3,7 @@
 /*
  * Parse symbolic events/counts passed in as options:
  */
+#include <perf/util.h>
 
 #include "../../../include/linux/perf_event.h"
 
-- 
1.7.4.rc2


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

* [PATCH 10/12] perf: Export ctype.c
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
                   ` (8 preceding siblings ...)
  2011-01-21 15:09 ` [PATCH 09/12] perf: Export util.ch into library Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 15:09 ` [PATCH 11/12] perf: Export tracepoint_id_to_path Borislav Petkov
  2011-01-21 15:09 ` [PATCH] ras: Add RAS daemon Borislav Petkov
  11 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

This is needed when linking against libtrace.a

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/lk/Makefile               |    1 +
 tools/{perf/util => lib/lk}/ctype.c |    2 +-
 tools/perf/Makefile                 |    1 -
 3 files changed, 2 insertions(+), 2 deletions(-)
 rename tools/{perf/util => lib/lk}/ctype.c (98%)

diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
index 2e7e02c..cb5587a 100644
--- a/tools/lib/lk/Makefile
+++ b/tools/lib/lk/Makefile
@@ -11,6 +11,7 @@ LIB_H += types.h
 LIB_OBJS += debugfs.o
 LIB_OBJS += usage.o
 LIB_OBJS += util.o
+LIB_OBJS += ctype.o
 
 LIBFILE = $(LIB_OUTPUT)liblk.a
 
diff --git a/tools/perf/util/ctype.c b/tools/lib/lk/ctype.c
similarity index 98%
rename from tools/perf/util/ctype.c
rename to tools/lib/lk/ctype.c
index 3507362..aada3ac 100644
--- a/tools/perf/util/ctype.c
+++ b/tools/lib/lk/ctype.c
@@ -3,7 +3,7 @@
  *
  * No surprises, and works with signed and unsigned chars.
  */
-#include "cache.h"
+#include "util.h"
 
 enum {
 	S = GIT_SPACE,
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 2edc5d9..bb0a2f7 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -394,7 +394,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/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/evsel.o
-- 
1.7.4.rc2


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

* [PATCH 11/12] perf: Export tracepoint_id_to_path
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
                   ` (9 preceding siblings ...)
  2011-01-21 15:09 ` [PATCH 10/12] perf: Export ctype.c Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 15:09 ` [PATCH] ras: Add RAS daemon Borislav Petkov
  11 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

This is needed when linking against libtrace.a so move it to
<lib/trace/trace-event-info.c> and adjust all headers accordingly.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/trace/trace-event-info.c |  123 ++++++++++++++++++++++++++++++-----
 tools/lib/trace/trace-event.h      |   19 ++++++
 tools/perf/util/parse-events.c     |  104 +-----------------------------
 tools/perf/util/parse-events.h     |    1 -
 tools/perf/util/parse-options.h    |    1 +
 5 files changed, 128 insertions(+), 120 deletions(-)

diff --git a/tools/lib/trace/trace-event-info.c b/tools/lib/trace/trace-event-info.c
index 808bdfa..77fade5 100644
--- a/tools/lib/trace/trace-event-info.c
+++ b/tools/lib/trace/trace-event-info.c
@@ -18,7 +18,6 @@
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  */
-#define _GNU_SOURCE
 #include <dirent.h>
 #include <mntent.h>
 #include <stdio.h>
@@ -26,6 +25,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <sys/types.h>
+#include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <pthread.h>
@@ -39,9 +39,11 @@
 
 #include "../../perf/perf.h"
 #include "trace-event.h"
-#include <lk/debugfs.h>
 #include "../../perf/util/evsel.h"
 
+#include <lk/util.h>
+#include <lk/debugfs.h>
+
 #define VERSION "0.5"
 
 #define _STR(x) #x
@@ -58,6 +60,7 @@
 unsigned int page_size;
 
 static const char *output_file = "trace.info";
+static const char *dfs_path;
 static int output_fd;
 
 struct event_list {
@@ -72,7 +75,7 @@ struct events {
 	char *name;
 };
 
-static void die(const char *fmt, ...)
+static void t_die(const char *fmt, ...)
 {
 	va_list ap;
 	int ret = errno;
@@ -97,7 +100,7 @@ void *malloc_or_die(unsigned int size)
 
 	data = malloc(size);
 	if (!data)
-		die("malloc");
+		t_die("malloc");
 	return data;
 }
 
@@ -106,7 +109,7 @@ static const char *find_debugfs(void)
 	const char *path = debugfs_mount(NULL);
 
 	if (!path)
-		die("Your kernel not support debugfs filesystem");
+		t_die("Your kernel not support debugfs filesystem");
 
 	return path;
 }
@@ -167,7 +170,7 @@ static ssize_t write_or_die(const void *buf, size_t len)
 
 	ret = write(output_fd, buf, len);
 	if (ret < 0)
-		die("writing to '%s'", output_file);
+		t_die("writing to '%s'", output_file);
 
 	return ret;
 }
@@ -205,7 +208,7 @@ static unsigned long long copy_file(const char *file)
 
 	fd = open(file, O_RDONLY);
 	if (fd < 0)
-		die("Can't read '%s'", file);
+		t_die("Can't read '%s'", file);
 	size = copy_file_fd(fd);
 	close(fd);
 
@@ -236,7 +239,7 @@ unsigned long get_filesize(const char *file)
 
 	fd = open(file, O_RDONLY);
 	if (fd < 0)
-		die("Can't read '%s'", file);
+		t_die("Can't read '%s'", file);
 	size = get_size_fd(fd);
 	close(fd);
 
@@ -252,7 +255,7 @@ static void read_header_files(void)
 	path = get_tracing_file("events/header_page");
 	fd = open(path, O_RDONLY);
 	if (fd < 0)
-		die("can't read '%s'", path);
+		t_die("can't read '%s'", path);
 
 	/* unfortunately, you can not stat debugfs files for size */
 	size = get_size_fd(fd);
@@ -263,14 +266,14 @@ static void read_header_files(void)
 	close(fd);
 
 	if (size != check_size)
-		die("wrong size for '%s' size=%lld read=%lld",
+		t_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);
+		t_die("can't read '%s'", path);
 
 	size = get_size_fd(fd);
 
@@ -278,7 +281,7 @@ static void read_header_files(void)
 	write_or_die(&size, 8);
 	check_size = copy_file_fd(fd);
 	if (size != check_size)
-		die("wrong size for '%s'", path);
+		t_die("wrong size for '%s'", path);
 	put_tracing_file(path);
 	close(fd);
 }
@@ -306,7 +309,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)
 
 	dir = opendir(sys);
 	if (!dir)
-		die("can't read directory '%s'", sys);
+		t_die("can't read directory '%s'", sys);
 
 	while ((dent = readdir(dir))) {
 		if (dent->d_type != DT_DIR ||
@@ -342,7 +345,7 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)
 			write_or_die(&size, 8);
 			check_size = copy_file(format);
 			if (size != check_size)
-				die("error in size of file '%s'", format);
+				t_die("error in size of file '%s'", format);
 		}
 
 		free(format);
@@ -386,7 +389,7 @@ static void read_event_files(struct tracepoint_path *tps)
 
 	dir = opendir(path);
 	if (!dir)
-		die("can't read directory '%s'", path);
+		t_die("can't read directory '%s'", path);
 
 	while ((dent = readdir(dir))) {
 		if (dent->d_type != DT_DIR ||
@@ -440,7 +443,7 @@ static void read_proc_kallsyms(void)
 	write_or_die(&size, 4);
 	check_size = copy_file(path);
 	if (size != check_size)
-		die("error in size of file '%s'", path);
+		t_die("error in size of file '%s'", path);
 
 }
 
@@ -463,11 +466,95 @@ static void read_ftrace_printk(void)
 	write_or_die(&size, 4);
 	check_size = copy_file(path);
 	if (size != check_size)
-		die("error in size of file '%s'", path);
+		t_die("error in size of file '%s'", path);
 out:
 	put_tracing_file(path);
 }
 
+int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
+{
+	char evt_path[MAXPATHLEN];
+	int fd;
+
+	snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", dfs_path,
+			sys_dir->d_name, evt_dir->d_name);
+	fd = open(evt_path, O_RDONLY);
+	if (fd < 0)
+		return -EINVAL;
+	close(fd);
+
+	return 0;
+}
+
+struct tracepoint_path *tracepoint_id_to_path(u64 config)
+{
+	struct tracepoint_path *path = NULL;
+	DIR *sys_dir, *evt_dir;
+	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
+	char id_buf[4];
+	int fd;
+	u64 id;
+	char evt_path[MAXPATHLEN];
+	char dir_path[MAXPATHLEN];
+
+	dfs_path = debugfs_mount(NULL);
+	if (!dfs_path)
+		return NULL;
+
+	sys_dir = opendir(dfs_path);
+	if (!sys_dir)
+		return NULL;
+
+	for_each_subsystem(sys_dir, sys_dirent, sys_next) {
+
+		snprintf(dir_path, MAXPATHLEN, "%s/%s", dfs_path,
+			 sys_dirent.d_name);
+		evt_dir = opendir(dir_path);
+		if (!evt_dir)
+			continue;
+
+		for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
+
+			snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
+				 evt_dirent.d_name);
+			fd = open(evt_path, O_RDONLY);
+			if (fd < 0)
+				continue;
+			if (read(fd, id_buf, sizeof(id_buf)) < 0) {
+				close(fd);
+				continue;
+			}
+			close(fd);
+			id = atoll(id_buf);
+			if (id == config) {
+				closedir(evt_dir);
+				closedir(sys_dir);
+				path = zalloc(sizeof(*path));
+				path->system = malloc(MAX_EVENT_LENGTH);
+				if (!path->system) {
+					free(path);
+					return NULL;
+				}
+				path->name = malloc(MAX_EVENT_LENGTH);
+				if (!path->name) {
+					free(path->system);
+					free(path);
+					return NULL;
+				}
+				strncpy(path->system, sys_dirent.d_name,
+					MAX_EVENT_LENGTH);
+				strncpy(path->name, evt_dirent.d_name,
+					MAX_EVENT_LENGTH);
+				return path;
+			}
+		}
+		closedir(evt_dir);
+	}
+
+	closedir(sys_dir);
+	return NULL;
+}
+
 static struct tracepoint_path *
 get_tracepoints_path(struct list_head *pattrs)
 {
@@ -481,7 +568,7 @@ get_tracepoints_path(struct list_head *pattrs)
 		++nr_tracepoints;
 		ppath->next = tracepoint_id_to_path(pos->attr.config);
 		if (!ppath->next)
-			die("%s\n", "No memory to alloc tracepoints list");
+			t_die("%s\n", "No memory to alloc tracepoints list");
 		ppath = ppath->next;
 	}
 
diff --git a/tools/lib/trace/trace-event.h b/tools/lib/trace/trace-event.h
index 0c06b5b..501e1ad 100644
--- a/tools/lib/trace/trace-event.h
+++ b/tools/lib/trace/trace-event.h
@@ -2,6 +2,7 @@
 #define __LIB_TRACE_EVENTS_H
 
 #include <stdbool.h>
+#include <dirent.h>
 #include "../../perf/util/parse-events.h"
 
 #define __unused __attribute__((unused))
@@ -312,4 +313,22 @@ int common_pc(struct scripting_context *context);
 int common_flags(struct scripting_context *context);
 int common_lock_depth(struct scripting_context *context);
 
+#define MAX_EVENT_LENGTH 512
+#define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1)
+
+#define for_each_subsystem(sys_dir, sys_dirent, sys_next)	       \
+	while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next)	       \
+	if (sys_dirent.d_type == DT_DIR &&				       \
+	   (strcmp(sys_dirent.d_name, ".")) &&				       \
+	   (strcmp(sys_dirent.d_name, "..")))
+
+#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next)	       \
+	while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next)        \
+	if (evt_dirent.d_type == DT_DIR &&				       \
+	   (strcmp(evt_dirent.d_name, ".")) &&				       \
+	   (strcmp(evt_dirent.d_name, "..")) &&				       \
+	   (!tp_event_has_id(&sys_dirent, &evt_dirent)))
+
+extern int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir);
+extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
 #endif /* __LIB_TRACE_EVENTS_H */
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index b17b01f..f336cba 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1,5 +1,4 @@
 #include "../../../include/linux/hw_breakpoint.h"
-#include <lk/util.h>
 #include "../perf.h"
 #include "evsel.h"
 #include "parse-options.h"
@@ -9,7 +8,10 @@
 #include "symbol.h"
 #include "cache.h"
 #include "header.h"
+
 #include <lk/debugfs.h>
+#include <lk/util.h>
+#include <trace/trace-event.h>
 
 int				nr_counters;
 
@@ -125,106 +127,6 @@ static unsigned long hw_cache_stat[C(MAX)] = {
  [C(BPU)]	= (CACHE_READ),
 };
 
-#define for_each_subsystem(sys_dir, sys_dirent, sys_next)	       \
-	while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next)	       \
-	if (sys_dirent.d_type == DT_DIR &&				       \
-	   (strcmp(sys_dirent.d_name, ".")) &&				       \
-	   (strcmp(sys_dirent.d_name, "..")))
-
-static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
-{
-	char evt_path[MAXPATHLEN];
-	int fd;
-
-	snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
-			sys_dir->d_name, evt_dir->d_name);
-	fd = open(evt_path, O_RDONLY);
-	if (fd < 0)
-		return -EINVAL;
-	close(fd);
-
-	return 0;
-}
-
-#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next)	       \
-	while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next)        \
-	if (evt_dirent.d_type == DT_DIR &&				       \
-	   (strcmp(evt_dirent.d_name, ".")) &&				       \
-	   (strcmp(evt_dirent.d_name, "..")) &&				       \
-	   (!tp_event_has_id(&sys_dirent, &evt_dirent)))
-
-#define MAX_EVENT_LENGTH 512
-
-
-struct tracepoint_path *tracepoint_id_to_path(u64 config)
-{
-	struct tracepoint_path *path = NULL;
-	DIR *sys_dir, *evt_dir;
-	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
-	char id_buf[4];
-	int fd;
-	u64 id;
-	char evt_path[MAXPATHLEN];
-	char dir_path[MAXPATHLEN];
-
-	if (debugfs_valid_mountpoint(debugfs_path))
-		return NULL;
-
-	sys_dir = opendir(debugfs_path);
-	if (!sys_dir)
-		return NULL;
-
-	for_each_subsystem(sys_dir, sys_dirent, sys_next) {
-
-		snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
-			 sys_dirent.d_name);
-		evt_dir = opendir(dir_path);
-		if (!evt_dir)
-			continue;
-
-		for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
-
-			snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
-				 evt_dirent.d_name);
-			fd = open(evt_path, O_RDONLY);
-			if (fd < 0)
-				continue;
-			if (read(fd, id_buf, sizeof(id_buf)) < 0) {
-				close(fd);
-				continue;
-			}
-			close(fd);
-			id = atoll(id_buf);
-			if (id == config) {
-				closedir(evt_dir);
-				closedir(sys_dir);
-				path = zalloc(sizeof(*path));
-				path->system = malloc(MAX_EVENT_LENGTH);
-				if (!path->system) {
-					free(path);
-					return NULL;
-				}
-				path->name = malloc(MAX_EVENT_LENGTH);
-				if (!path->name) {
-					free(path->system);
-					free(path);
-					return NULL;
-				}
-				strncpy(path->system, sys_dirent.d_name,
-					MAX_EVENT_LENGTH);
-				strncpy(path->name, evt_dirent.d_name,
-					MAX_EVENT_LENGTH);
-				return path;
-			}
-		}
-		closedir(evt_dir);
-	}
-
-	closedir(sys_dir);
-	return NULL;
-}
-
-#define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1)
 static const char *tracepoint_id_to_name(u64 config)
 {
 	static char buf[TP_PATH_LEN];
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index c29c407..946dc44 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -23,7 +23,6 @@ struct tracepoint_path {
 	struct tracepoint_path *next;
 };
 
-extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
 extern bool have_tracepoints(struct list_head *evsel_list);
 
 extern int			nr_counters;
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index abc31a1..6bcb9a4 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -3,6 +3,7 @@
 
 #include <linux/kernel.h>
 #include <stdbool.h>
+#include <lk/util.h>
 
 enum parse_opt_type {
 	/* special types */
-- 
1.7.4.rc2


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

* [PATCH] ras: Add RAS daemon
  2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
                   ` (10 preceding siblings ...)
  2011-01-21 15:09 ` [PATCH 11/12] perf: Export tracepoint_id_to_path Borislav Petkov
@ 2011-01-21 15:09 ` Borislav Petkov
  2011-01-21 17:54   ` Tony Luck
  11 siblings, 1 reply; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 15:09 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tony.luck, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/Makefile     |    4 +
 tools/ras/Makefile |   16 +++
 tools/ras/rasd.c   |  311 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 331 insertions(+), 0 deletions(-)
 create mode 100644 tools/ras/Makefile
 create mode 100644 tools/ras/rasd.c

diff --git a/tools/Makefile b/tools/Makefile
index 71dce04..a012fa3 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -22,11 +22,15 @@ liblk: .FORCE
 liblkperf:
 	$(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1)
 
+ras: libtrace liblk liblkperf .FORCE
+	$(QUIET_SUBDIR0)ras/ $(QUIET_SUBDIR1)
+
 clean:
 	$(QUIET_SUBDIR0)lib/trace/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)lib/lk/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)lib/perf/ $(QUIET_SUBDIR1) clean
 	$(QUIET_SUBDIR0)perf/ $(QUIET_SUBDIR1) clean
+	$(QUIET_SUBDIR0)ras/ $(QUIET_SUBDIR1) clean
 
 
 .PHONY: clean .FORCE
diff --git a/tools/ras/Makefile b/tools/ras/Makefile
new file mode 100644
index 0000000..0b2f458
--- /dev/null
+++ b/tools/ras/Makefile
@@ -0,0 +1,16 @@
+include ../scripts/Makefile.lib
+
+CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 -DNO_NEWT_SUPPORT $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
+ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+ALL_LDFLAGS = $(LDFLAGS)
+
+RASLIBS=$(LIB_OUTPUT)libtrace.a $(LIB_OUTPUT)liblk.a $(LIB_OUTPUT)liblkperf.a
+
+rasd: rasd.o
+	$(QUIET_CC)$(CC) $(ALL_CFLAGS) -o $@ $^ $(RASLIBS)
+
+%.o: %.c
+	$(QUIET_CC)$(CC) $(ALL_CFLAGS) -c $<
+
+clean:
+	rm -rf *.o rasd
diff --git a/tools/ras/rasd.c b/tools/ras/rasd.c
new file mode 100644
index 0000000..a8b14b7
--- /dev/null
+++ b/tools/ras/rasd.c
@@ -0,0 +1,311 @@
+/*
+ * Linux RAS daemon.
+ *
+ * Initial code reused from Linux Daemon Writing HOWTO
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+
+#include <lk/util.h>
+#include <lk/debugfs.h>
+#include <perf/mmap.h>
+#include <perf/util.h>
+#include <trace/trace-event.h>
+
+#include "../../arch/x86/include/asm/mce.h"
+
+#ifdef DEBUG
+#define dbg(fmt, args...) \
+	fprintf(stderr, "DBG %s: " fmt "\n", __func__, ##args)
+#else
+#define dbg(fmt, args...) do { } while (0)
+#endif
+
+#define MMAP_PAGES		128
+#define MCE_TP			"mce/mce_record"
+
+#define PFX "rasd: "
+
+static int fds[MAX_NR_CPUS];
+static struct mmap_data mmaps[MAX_NR_CPUS];
+static struct event *mce_event;
+static struct mce m;
+static const char *dfs_root;
+
+static int nr_cpus;
+static unsigned int page_size;
+
+const char *logf_path = "/var/log/ras.log";
+
+static unsigned long long read_file(const char *file, void *buf)
+{
+	unsigned long long size = 0;
+	int fd, r;
+
+	fd = open(file, O_RDONLY);
+	if (fd < 0)
+		die("Can't read '%s'", file);
+
+	do {
+		r = read(fd, buf, BUFSIZ);
+		if (r > 0)
+			size += r;
+	} while (r > 0);
+
+	close(fd);
+
+	return size;
+}
+
+static void parse_mce_event(void)
+{
+	struct stat st;
+	char *format_path, *format_buf, *path;
+	int fsize, err = 0;
+
+	path = get_tracing_file("events");
+
+	dbg("Got %s", path);
+
+	format_path = malloc_or_die(MAXPATHLEN + sizeof(MCE_TP) + 10);
+	sprintf(format_path, "%s/%s/format", path, MCE_TP);
+
+	err = stat(format_path, &st);
+	if (err < 0)
+		die("accessing %s", format_path);
+
+	dbg("Format access %s ok", format_path);
+
+	fsize = get_filesize(format_path);
+	dbg("Format file size: %d", fsize);
+
+	format_buf = malloc_or_die(fsize);
+	if (!format_buf)
+		die("allocating format buffer");
+
+	if (!read_file(format_path, format_buf))
+		die("reading in format file");
+
+	dbg("Format file contents:\n%s", format_buf);
+
+	init_input_buf(format_buf, fsize);
+
+	mce_event = alloc_event();
+	if (!mce_event)
+		die("Cannot alloc mce_event");
+
+	mce_event->name = event_read_name();
+	if (!mce_event->name)
+		error("no event name");
+
+	mce_event->id = event_read_id();
+	if (mce_event->id < 0)
+		error(PFX "failed to read event id");
+
+	if (event_read_format(mce_event))
+		die("parsing event");
+
+
+	free(format_buf);
+	free(format_path);
+	free(path);
+}
+
+static void fill_mce_data(void *vbuf, size_t buflen)
+{
+	struct format_field *field;
+	char *buf = vbuf;
+	u32 tp_len;
+#ifdef DEBUG
+	unsigned i;
+#endif
+
+	if (!buflen)
+		return;
+
+#ifdef DEBUG
+	dbg("buflen %lu", buflen);
+
+	for (i = 0; i < buflen; i++) {
+
+		if (!(i & 0xf) && i)
+			printf("\n");
+
+		printf("0x%2.2x ", *(unsigned char *)(buf + i));
+	}
+#endif
+
+	/* skip event header for now, u32 size inclusive */
+	buf    += sizeof(struct perf_event_header);
+	buflen -= sizeof(struct perf_event_header) + 4;
+
+	tp_len = *(u32 *)buf;
+
+	if (tp_len != buflen)
+		warning("bufsize mismatch: %lu <-> %u (tp)\n", buflen, tp_len);
+
+	/* skip size */
+	buf += 4;
+
+	for (field = mce_event->format.fields; field; field = field->next) {
+		if ((size_t)(field->offset + field->size) > buflen)
+			warning("MCE buf truncated? (off: %d <-> buflen: %lu)",
+				field->offset, buflen);
+
+		dbg("field %s, offset: %d", field->name, field->offset);
+
+		if (!strncmp(field->name, "bank", 4))
+			m.bank = *(u8 *)(buf + field->offset);
+		else if (!strncmp(field->name, "status", 6))
+			m.status = *(u64 *)(buf + field->offset);
+		else if (!strncmp(field->name, "addr", 4))
+			m.addr = *(u64 *)(buf + field->offset);
+		else if (!strncmp(field->name, "misc", 4))
+			m.misc = *(u64 *)(buf + field->offset);
+		else if (!strncmp(field->name, "ip", 2))
+			m.ip = *(u64 *)(buf + field->offset);
+		else if (!strncmp(field->name, "cs", 2))
+			m.cs = *(u8 *)(buf + field->offset);
+		else if (!strncmp(field->name, "tsc", 3))
+			m.tsc = *(u64 *)(buf + field->offset);
+		else if (!strncmp(field->name, "cpu", 3))
+			m.cpu = *(u8 *)(buf + field->offset);
+		else
+			warning("skipping %s", field->name);
+	}
+}
+
+static int ras_init(void)
+{
+	int cpu;
+
+	fprintf(stderr, PFX "Starting daemon.\n");
+
+	page_size = sysconf(_SC_PAGE_SIZE);
+
+	dfs_root = debugfs_mount(NULL);
+	if (!dfs_root) {
+		error("Cannot mount debugfs, exiting... ");
+		return 1;
+	}
+
+	nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
+	if (nr_cpus < 0) {
+		error("Cannot get # CPUs, exiting... ");
+		return 1;
+	}
+
+	parse_mce_event();
+	assert(mce_event);
+
+	for (cpu = 0; cpu < nr_cpus; cpu++) {
+		char dfs_path[MAXPATHLEN];
+
+		snprintf(dfs_path, MAXPATHLEN, "%s/%s%d",
+			 dfs_root, MCE_TP, cpu);
+
+		dbg("dfs_path: %s", dfs_path);
+
+		fds[cpu] = open(dfs_path, O_RDWR, O_NONBLOCK);
+		if (fds[cpu] < 0) {
+			error("open perf event on cpu %d\n", cpu);
+			return 1;
+		} else
+			dbg("cpu %d, fd %d", cpu, fds[cpu]);
+	}
+
+	for (cpu = 0; cpu < nr_cpus; cpu++) {
+		mmaps[cpu].prev = 0;
+		mmaps[cpu].mask = MMAP_PAGES*page_size - 1;
+		mmaps[cpu].base = mmap(NULL, (MMAP_PAGES + 1) * page_size,
+				       PROT_READ | PROT_WRITE, MAP_SHARED,
+				       fds[cpu], 0);
+
+		if (mmaps[cpu].base == MAP_FAILED) {
+			error("cannot mmap: %s (%d).", strerror(errno), errno);
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+static void ras_exit(void)
+{
+	free(mce_event);
+}
+
+int main(void)
+{
+	pid_t pid, sid;
+	FILE *logfile = NULL;
+	int err = 0;
+
+	pid = fork();
+	if (pid < 0) {
+		error(PFX "Error forking daemon thread.");
+		exit(EXIT_FAILURE);
+	}
+
+	/* parent can disappear now */
+	if (pid > 0)
+		exit(EXIT_SUCCESS);
+
+	umask(0);
+
+	sid = setsid();
+	if (sid < 0) {
+		error(PFX "Error creating session.");
+		exit(EXIT_FAILURE);
+	}
+
+	if (chdir("/") < 0) {
+		error(PFX "Error chdir to /");
+		exit(EXIT_FAILURE);
+	}
+
+	logfile = fopen(logf_path, "a");
+	if (!logfile) {
+		error(PFX "Error opening logs: %s\n", strerror(errno));
+		err = errno;
+		goto exit;
+	}
+
+	close(STDIN_FILENO);
+	close(STDOUT_FILENO);
+	close(STDERR_FILENO);
+
+	if (ras_init()) {
+		err = -EINVAL;
+		goto cleanup;
+	}
+
+	while (1) {
+
+		if (mmap_read_all(mmaps, nr_cpus, fill_mce_data)) {
+			fprintf(logfile,
+				"Got MCE, cpu: %d, status: 0x%016llx, addr: 0x%016llx\n",
+				m.cpu, m.status, m.addr);
+			fflush(logfile);
+		}
+
+		sleep(30);
+	}
+
+	ras_exit();
+
+cleanup:
+	fclose(logfile);
+
+exit:
+	return err;
+
+}
-- 
1.7.4.rc2


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

* Re: [PATCH 08/12] perf: Carve out mmap helpers for general use
  2011-01-21 15:09 ` [PATCH 08/12] perf: Carve out mmap helpers for general use Borislav Petkov
@ 2011-01-21 17:29   ` Arnaldo Carvalho de Melo
  2011-01-24  9:04     ` Borislav Petkov
  0 siblings, 1 reply; 20+ messages in thread
From: Arnaldo Carvalho de Melo @ 2011-01-21 17:29 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: peterz, mingo, tony.luck, rostedt, fweisbec, linux-edac,
	linux-kernel, Borislav Petkov

Em Fri, Jan 21, 2011 at 04:09:31PM +0100, Borislav Petkov escreveu:
> From: Borislav Petkov <borislav.petkov@amd.com>
> 
> Export the mmap_read* helpers into tools/lib/perf/mmap.[ch]

Borislav, can you take a look at:

http://git.kernel.org/?p=linux/kernel/git/acme/linux-2.6.git;a=shortlog;h=refs/heads/perf/core

More specifically take a look at the function test__basic_mmap in:

http://git.kernel.org/?p=linux/kernel/git/acme/linux-2.6.git;a=blob;f=tools/perf/builtin-test.c;h=f03798a298b00b328a11f06ce20cc352d123ec28;hb=refs/heads/perf/core

434 /*
435  * This test will generate random numbers of calls to some getpid syscalls,
436  * then establish an mmap for a group of events that are created to monitor
437  * the syscalls.
438  *
439  * It will receive the events, using mmap, use its PERF_SAMPLE_ID generated
440  * sample.id field to map back to its respective perf_evsel instance.
441  *
442  * Then it checks if the number of syscalls reported as perf events by
443  * the kernel corresponds to the number of syscalls made.
444  */

I'll read the rest of your patchset to see if there are more things like
this.

- Arnaldo

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

* Re: [PATCH] ras: Add RAS daemon
  2011-01-21 15:09 ` [PATCH] ras: Add RAS daemon Borislav Petkov
@ 2011-01-21 17:54   ` Tony Luck
  2011-01-21 18:06     ` Borislav Petkov
  0 siblings, 1 reply; 20+ messages in thread
From: Tony Luck @ 2011-01-21 17:54 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: peterz, mingo, acme, rostedt, fweisbec, linux-edac, linux-kernel,
	Borislav Petkov

On Fri, Jan 21, 2011 at 7:09 AM, Borislav Petkov <bp@amd64.org> wrote:
> +       format_buf = malloc_or_die(fsize);
> +       if (!format_buf)
> +               die("allocating format buffer");

You don't trust "malloc_or_die()" to make it dead enough? :-)

Will take a look through the rest of bits - looks very interesting.

-Tony

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

* Re: [PATCH] ras: Add RAS daemon
  2011-01-21 17:54   ` Tony Luck
@ 2011-01-21 18:06     ` Borislav Petkov
  0 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2011-01-21 18:06 UTC (permalink / raw)
  To: Tony Luck
  Cc: Borislav Petkov, peterz, mingo, acme, rostedt, fweisbec,
	linux-edac, linux-kernel

On Fri, Jan 21, 2011 at 12:54:20PM -0500, Tony Luck wrote:
> On Fri, Jan 21, 2011 at 7:09 AM, Borislav Petkov <bp@amd64.org> wrote:
> > +       format_buf = malloc_or_die(fsize);
> > +       if (!format_buf)
> > +               die("allocating format buffer");
> 
> You don't trust "malloc_or_die()" to make it dead enough? :-)

Yeah, it ain't dead yet! That's me with the big hammer.

Good catch, will fix.

> Will take a look through the rest of bits - looks very interesting.

Thanks a lot sir :).

-- 
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

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

* Re: [PATCH 08/12] perf: Carve out mmap helpers for general use
  2011-01-21 17:29   ` Arnaldo Carvalho de Melo
@ 2011-01-24  9:04     ` Borislav Petkov
  2011-01-24 12:39       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 20+ messages in thread
From: Borislav Petkov @ 2011-01-24  9:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Borislav Petkov, peterz, mingo, tony.luck, rostedt, fweisbec,
	linux-edac, linux-kernel

On Fri, Jan 21, 2011 at 12:29:37PM -0500, Arnaldo Carvalho de Melo wrote:
> Em Fri, Jan 21, 2011 at 04:09:31PM +0100, Borislav Petkov escreveu:
> > From: Borislav Petkov <borislav.petkov@amd.com>
> > 
> > Export the mmap_read* helpers into tools/lib/perf/mmap.[ch]
> 
> Borislav, can you take a look at:
> 
> http://git.kernel.org/?p=linux/kernel/git/acme/linux-2.6.git;a=shortlog;h=refs/heads/perf/core
> 
> More specifically take a look at the function test__basic_mmap in:
> 
> http://git.kernel.org/?p=linux/kernel/git/acme/linux-2.6.git;a=blob;f=tools/perf/builtin-test.c;h=f03798a298b00b328a11f06ce20cc352d123ec28;hb=refs/heads/perf/core
> 
> 434 /*
> 435  * This test will generate random numbers of calls to some getpid syscalls,
> 436  * then establish an mmap for a group of events that are created to monitor
> 437  * the syscalls.
> 438  *
> 439  * It will receive the events, using mmap, use its PERF_SAMPLE_ID generated
> 440  * sample.id field to map back to its respective perf_evsel instance.
> 441  *
> 442  * Then it checks if the number of syscalls reported as perf events by
> 443  * the kernel corresponds to the number of syscalls made.
> 444  */

Ok, I see at least one problem with my patch - you've reworked the
mmaping functionality in evlist.c/evsel.c and I should use it too, I
guess. For that, I think you'd want me to apply my stuff ontop of your
perf/core branch, right?

Am I missing something else?

Thanks.

-- 
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

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

* Re: [PATCH 08/12] perf: Carve out mmap helpers for general use
  2011-01-24  9:04     ` Borislav Petkov
@ 2011-01-24 12:39       ` Arnaldo Carvalho de Melo
  2011-01-26  1:00         ` Borislav Petkov
  0 siblings, 1 reply; 20+ messages in thread
From: Arnaldo Carvalho de Melo @ 2011-01-24 12:39 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: peterz, mingo, tony.luck, rostedt, fweisbec, linux-edac, linux-kernel

Em Mon, Jan 24, 2011 at 10:04:10AM +0100, Borislav Petkov escreveu:
> Ok, I see at least one problem with my patch - you've reworked the
> mmaping functionality in evlist.c/evsel.c and I should use it too, I
> guess. For that, I think you'd want me to apply my stuff ontop of your
> perf/core branch, right?

Right, I hope to have that branch merged by Ingo soon.
 
> Am I missing something else?

Nope, you're not. Doing that we erode your patchset a bit, reducing its
size.

One related experience I'm doing now is to have a perf.so python
binding, the setup.py file for it with the list of files needed for this
specific binding is at:

http://userweb.kernel.org/~acme/setup.py

A simple tool using the resulting binding is a thread
fork/comm/exit/sample watcher, available at:

http://userweb.kernel.org/~acme/twatch

In this process I'm moving functions around so as to reduce the number
of tools/perf/util.c files to link into this perf.so python binding,
untangling things as much as possible.

The binding proper is:

http://userweb.kernel.org/~acme/python.c

I'm digressing, but twatch is an example of a simple "daemon" consuming
perf events where performance is not much of a problem.

And provides a prototyping ground when starting to design perf events
consuming daemons :-)

- Arnaldo

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

* Re: [PATCH 08/12] perf: Carve out mmap helpers for general use
  2011-01-24 12:39       ` Arnaldo Carvalho de Melo
@ 2011-01-26  1:00         ` Borislav Petkov
  2011-01-26 13:13           ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 20+ messages in thread
From: Borislav Petkov @ 2011-01-26  1:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Borislav Petkov, peterz, mingo, tony.luck, rostedt, fweisbec,
	linux-edac, linux-kernel

On Mon, Jan 24, 2011 at 10:39:36AM -0200, Arnaldo Carvalho de Melo wrote:
> Em Mon, Jan 24, 2011 at 10:04:10AM +0100, Borislav Petkov escreveu:
> > Ok, I see at least one problem with my patch - you've reworked the
> > mmaping functionality in evlist.c/evsel.c and I should use it too, I
> > guess. For that, I think you'd want me to apply my stuff ontop of your
> > perf/core branch, right?
> 
> Right, I hope to have that branch merged by Ingo soon.
>  
> > Am I missing something else?
> 
> Nope, you're not. Doing that we erode your patchset a bit, reducing its
> size.

.. which means less work for me, heey, nice! :)

> One related experience I'm doing now is to have a perf.so python
> binding, the setup.py file for it with the list of files needed for this
> specific binding is at:
> 
> http://userweb.kernel.org/~acme/setup.py
> 
> A simple tool using the resulting binding is a thread
> fork/comm/exit/sample watcher, available at:
> 
> http://userweb.kernel.org/~acme/twatch
> 
> In this process I'm moving functions around so as to reduce the number
> of tools/perf/util.c files to link into this perf.so python binding,
> untangling things as much as possible.
> 
> The binding proper is:
> 
> http://userweb.kernel.org/~acme/python.c
> 
> I'm digressing, but twatch is an example of a simple "daemon" consuming
> perf events where performance is not much of a problem.
> 
> And provides a prototyping ground when starting to design perf events
> consuming daemons :-)

Yaay, twatch looks almost like a child's play and even my grandma can
profile her system now :).

But yeah, I thought about pythonizing the ras thingy too but the reasons
against it are that we might run on systems which don't have python,
have some obscure/old version of it or we simply don't want to depend on
it or any other additional tool for that matter. Generally, we want to
run with as low overhead as possible when handling hw error info and be
as self-contained as possible.

-- 
Regards/Gruss,
    Boris.

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

* Re: [PATCH 08/12] perf: Carve out mmap helpers for general use
  2011-01-26  1:00         ` Borislav Petkov
@ 2011-01-26 13:13           ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 20+ messages in thread
From: Arnaldo Carvalho de Melo @ 2011-01-26 13:13 UTC (permalink / raw)
  To: Borislav Petkov, Borislav Petkov, peterz, mingo, tony.luck,
	rostedt, fweisbec, linux-edac, linux-kernel

Em Wed, Jan 26, 2011 at 02:00:02AM +0100, Borislav Petkov escreveu:
> On Mon, Jan 24, 2011 at 10:39:36AM -0200, Arnaldo Carvalho de Melo wrote:
> > Em Mon, Jan 24, 2011 at 10:04:10AM +0100, Borislav Petkov escreveu:
> > I'm digressing, but twatch is an example of a simple "daemon" consuming
> > perf events where performance is not much of a problem.

> > And provides a prototyping ground when starting to design perf events
> > consuming daemons :-)

> Yaay, twatch looks almost like a child's play and even my grandma can
> profile her system now :).

> But yeah, I thought about pythonizing the ras thingy too but the
> reasons against it are that we might run on systems which don't have
> python, have some obscure/old version of it or we simply don't want to
> depend on it or any other additional tool for that matter. Generally,
> we want to run with as low overhead as possible when handling hw error
> info and be as self-contained as possible.

Right, that is why I try to have the python abstractions as close as
possible to the abstractions a C program, like your RAS thingy should
use.

I.e. one can go on introducing the kernel interfaces and testing them
using python, where you can, for instance, from the python interpreter
command line, create counters, read its values, i.e. test the kernel
stuff quickly and easily.

Moving to a C version then becomes easy after the testing phase is over
and the kernel bits are set in stone.

- Arnaldo

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

end of thread, other threads:[~2011-01-26 13:13 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-21 15:09 [RFC PATCHSET 0/12] RAS daemon v4 Borislav Petkov
2011-01-21 15:09 ` [PATCH 01/12] perf: Start the massive restructuring Borislav Petkov
2011-01-21 15:09 ` [PATCH 02/12] perf: Add persistent event facilities Borislav Petkov
2011-01-21 15:09 ` [PATCH 03/12] x86, mce: Add persistent MCE event Borislav Petkov
2011-01-21 15:09 ` [PATCH 04/12] perf: Add Makefile.lib Borislav Petkov
2011-01-21 15:09 ` [PATCH 05/12] perf: Export trace-event utils Borislav Petkov
2011-01-21 15:09 ` [PATCH 06/12] perf: Remove duplicate enum trace_flag_type Borislav Petkov
2011-01-21 15:09 ` [PATCH 07/12] perf: Export debugfs utilities Borislav Petkov
2011-01-21 15:09 ` [PATCH 08/12] perf: Carve out mmap helpers for general use Borislav Petkov
2011-01-21 17:29   ` Arnaldo Carvalho de Melo
2011-01-24  9:04     ` Borislav Petkov
2011-01-24 12:39       ` Arnaldo Carvalho de Melo
2011-01-26  1:00         ` Borislav Petkov
2011-01-26 13:13           ` Arnaldo Carvalho de Melo
2011-01-21 15:09 ` [PATCH 09/12] perf: Export util.ch into library Borislav Petkov
2011-01-21 15:09 ` [PATCH 10/12] perf: Export ctype.c Borislav Petkov
2011-01-21 15:09 ` [PATCH 11/12] perf: Export tracepoint_id_to_path Borislav Petkov
2011-01-21 15:09 ` [PATCH] ras: Add RAS daemon Borislav Petkov
2011-01-21 17:54   ` Tony Luck
2011-01-21 18:06     ` Borislav Petkov

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