Skip to contentSkip to conversation

Performance counter in-kernel virtualization API

PATCH Mathieu Desnoyers 1 participant 1 message Dec 10, 2008

lore
Share & tools
lore
#0 lore raw

Hello !

I finally found some code I've written 1.5 year ago which aimed at providing an in-kernel virtualization API which would be useful for tracers, and eventually a layer on top of it could be done to save/restore per-thread offset values so it makes sense for userspace too.

The state of these patches is : really really far from completeness. Actually, I think that at this stage, they can only be used as API and data structures ideas to represent some of the "features" inherent to performance counter handling (e.g. mapping control registers to physical counter registers...)

Sadly I don't have much time to put on PMC, given tracing is my focus. Also, I did not go through any of the recent PMC code, so the approach I propose here might be completely wrong. The only thing I want people to keep in mind is that an in-kernel API for performance counters is good.

And.. the code style is imperfect, it's not documented and it does not compile. ;) So feel free to ignore it. It's provided "as-is".

Mathieu

pmc-low-level-api

---
 include/linux/pmc.h |   31 +++++++++++++++++++++++++++++++
 kernel/Makefile     |    1 +
 kernel/pmc.c        |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+)
kernel/Makefile +1 -0
Index: linux-2.6-lttng/kernel/Makefile
===================================================================
@@ -60,6 +60,7 @@
 obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
 obj-$(CONFIG_IMMEDIATE) += immediate.o
 obj-$(CONFIG_MARKERS) += marker.o
+obj-$(CONFIG_PMC) += pmc.o
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
include/linux/pmc.h new file +31 -0
Index: linux-2.6-lttng/include/linux/pmc.h
===================================================================
@@ -0,0 +1,31 @@
+
+#include <linux/list.h>
+#include <linux/types.h>
+#include <asm/pmc.h>
+
+/*
+ * Two PMC modes : simply count or call a callback whenever the counter reach
+ * the "interval" value.
+ */
+enum pmc_mode { PMC_COUNT, PMC_SIGNAL };
+
+#define PMC_FLAG_DISABLED	0
+
+typedef void (*pmc_callback)(struct pmc_client *handle);
+
+struct pmc_client {
+				/* bitfield of usable logical PMCs */
+	unsigned long allowed[NR_LOGICAL_PMC/(8*sizeof(unsigned long))];
+	uint64_t interval;	/* Interval between signals (pmc increments) */
+	uint64_t count;		/* Current count updated by PMC (internal) */
+	uint64_t offset;	/* offset of count (internal) */
+	struct list_head node[NR_PHYSICAL_PMC];	/* List node (internal) */
+	pmc_callback *cb;	/* Callback to call when signal is ready */
+	void *private_data;	/* Private data, for the callback */
+	enum pmc_mode mode;	/* PMC mode : count or signal */
+	int prio;		/* Priority: highest have precedence */
+	int assigned;		/* Logical PMC assigned (internal) */
+	int control;		/* Control PMC assigned (internal) */
+};
+
+
kernel/pmc.c new file +50 -0

50 lines not on this page · raw message

pmc-low-level-api-i386.patch

---
 arch/i386/Kconfig.debug |    5 +
 arch/i386/kernel/pmc.c  |  198 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/asm-i386/pmc.h  |   50 ++++++++++++
 3 files changed, 253 insertions(+)
arch/i386/Kconfig.debug +5 -0
Index: linux-2.6-lttng/arch/i386/Kconfig.debug
===================================================================
@@ -84,5 +84,10 @@
           would otherwise cause a system to silently reboot. Disabling this
           option saves about 4k and might cause you much additional grey
           hair.
+config PMC
+	default y
+	bool "Enable Performance Monitoring Counter Abstraction"
+	help
+	  This option enables abstracted PMCs.
 
 endmenu
include/asm-i386/pmc.h new file +50 -0

50 lines not on this page · raw message

arch/i386/kernel/pmc.c new file +198 -0

198 lines not on this page · raw message

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68