Skip to contentSkip to conversation

perfctr-2.7.2 for 2.6.6-mm2: core

PATCH In review Mikael Pettersson 3 participants 3 messages May 14, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 perfctr-2.7.2 for 2.6.6-mm2: core

perfctr-2.7.2 for 2.6.6-mm2, part 1/7:

- core driver files and kernel changes

 drivers/Makefile               |    1 
 drivers/perfctr/Kconfig        |   60 ++++
 drivers/perfctr/Makefile       |   21 +
 drivers/perfctr/cpumask.h      |   24 +
 drivers/perfctr/init.c         |  131 +++++++++
 drivers/perfctr/marshal.c      |   51 +++
 drivers/perfctr/marshal.h      |   16 +
 drivers/perfctr/marshal_core.c |  560 +++++++++++++++++++++++++++++++++++++++++
 drivers/perfctr/marshal_core.h |   79 +++++
 drivers/perfctr/version.h      |    1 
 include/linux/perfctr.h        |  211 +++++++++++++++
 kernel/sched.c                 |    3 
 kernel/sys.c                   |    1 
 kernel/timer.c                 |    2 
 14 files changed, 1161 insertions(+)
drivers/Makefile +1 -0
diff -ruN linux-2.6.6-mm2/drivers/Makefile linux-2.6.6-mm2.perfctr-2.7.2.core/drivers/Makefile
@@ -49,4 +49,5 @@
 obj-$(CONFIG_MCA)		+= mca/
 obj-$(CONFIG_EISA)		+= eisa/
 obj-$(CONFIG_CPU_FREQ)		+= cpufreq/
+obj-$(CONFIG_PERFCTR)		+= perfctr/
 obj-y				+= firmware/
drivers/perfctr/Kconfig +60 -0

60 lines not on this page · raw message

drivers/perfctr/Makefile +21 -0
diff -ruN linux-2.6.6-mm2/drivers/perfctr/Makefile linux-2.6.6-mm2.perfctr-2.7.2.core/drivers/perfctr/Makefile
@@ -0,0 +1,21 @@
+# $Id: Makefile,v 1.23 2004/05/13 23:32:49 mikpe Exp $
+# Makefile for the Performance-monitoring counters driver.
+
+perfctr-objs-$(CONFIG_X86) := x86.o
+tests-objs-$(CONFIG_X86) := x86_tests.o
+
+# Braindamage alert! x86_64 defines _both_ CONFIG_X86_64 and CONFIG_X86.
+# These assignments need to override those above.
+perfctr-objs-$(CONFIG_X86_64) := x86_64.o
+tests-objs-$(CONFIG_X86_64) := x86_tests.o
+
+perfctr-objs-$(CONFIG_PPC32) := ppc.o
+tests-objs-$(CONFIG_PPC32) := ppc_tests.o
+
+perfctr-objs-y += init.o marshal.o
+perfctr-objs-$(CONFIG_PERFCTR_INIT_TESTS) += $(tests-objs-y)
+perfctr-objs-$(CONFIG_PERFCTR_VIRTUAL) += virtual.o
+perfctr-objs-$(CONFIG_PERFCTR_GLOBAL) += global.o
+
+perfctr-objs		:= $(perfctr-objs-y)
+obj-$(CONFIG_PERFCTR)	:= perfctr.o
drivers/perfctr/cpumask.h +24 -0
diff -ruN linux-2.6.6-mm2/drivers/perfctr/cpumask.h linux-2.6.6-mm2.perfctr-2.7.2.core/drivers/perfctr/cpumask.h
@@ -0,0 +1,24 @@
+/* $Id: cpumask.h,v 1.7 2004/05/12 19:59:01 mikpe Exp $
+ * Performance-monitoring counters driver.
+ * Partial simulation of cpumask_t on non-cpumask_t kernels.
+ * Extension to allow inspecting a cpumask_t as array of ulong.
+ * Appropriate definition of perfctr_cpus_forbidden_mask.
+ *
+ * Copyright (C) 2003-2004  Mikael Pettersson
+ */
+
+#ifdef CPU_ARRAY_SIZE
+#define PERFCTR_CPUMASK_NRLONGS	CPU_ARRAY_SIZE
+#else
+#define PERFCTR_CPUMASK_NRLONGS	1
+#endif
+
+/* `perfctr_cpus_forbidden_mask' used to be defined in <asm/perfctr.h>,
+   but cpumask_t compatibility issues forced it to be moved here. */
+#if PERFCTR_CPUS_FORBIDDEN_MASK_NEEDED
+extern cpumask_t perfctr_cpus_forbidden_mask;
+#define perfctr_cpu_is_forbidden(cpu)	cpu_isset((cpu), perfctr_cpus_forbidden_mask)
+#else
+#define perfctr_cpus_forbidden_mask	CPU_MASK_NONE
+#define perfctr_cpu_is_forbidden(cpu)	0 /* cpu_isset() needs an lvalue :-( */
+#endif
drivers/perfctr/init.c +131 -0

131 lines not on this page · raw message

drivers/perfctr/marshal.c +51 -0

51 lines not on this page · raw message

drivers/perfctr/marshal.h +16 -0
diff -ruN linux-2.6.6-mm2/drivers/perfctr/marshal.h linux-2.6.6-mm2.perfctr-2.7.2.core/drivers/perfctr/marshal.h
@@ -0,0 +1,16 @@
+/* $Id: marshal.h,v 1.2 2004/05/13 17:48:59 mikpe Exp $
+ * Performance-monitoring counters driver.
+ * Structure marshalling support, kernel-level declarations.
+ *
+ * Copyright (C) 2003-2004  Mikael Pettersson
+ */
+
+#include "marshal_core.h"
+
+int perfctr_copy_to_user(struct perfctr_struct_buf *argp,
+			 void *struct_address,
+			 const struct perfctr_struct_desc *sdesc);
+
+int perfctr_copy_from_user(void *struct_address,
+			   struct perfctr_struct_buf *argp,
+			   const struct perfctr_struct_desc *sdesc);
drivers/perfctr/marshal_core.c +560 -0

560 lines not on this page · raw message

drivers/perfctr/marshal_core.h +79 -0

79 lines not on this page · raw message

drivers/perfctr/version.h +1 -0
diff -ruN linux-2.6.6-mm2/drivers/perfctr/version.h linux-2.6.6-mm2.perfctr-2.7.2.core/drivers/perfctr/version.h
@@ -0,0 +1 @@
+#define VERSION "2.7.2"
include/linux/perfctr.h +211 -0

211 lines not on this page · raw message

kernel/sched.c +3 -0
diff -ruN linux-2.6.6-mm2/kernel/sched.c linux-2.6.6-mm2.perfctr-2.7.2.core/kernel/sched.c
@@ -39,6 +39,7 @@
 #include <linux/rcupdate.h>
 #include <linux/cpu.h>
 #include <linux/percpu.h>
+#include <linux/perfctr.h>
 #include <linux/kthread.h>
 #include <linux/seq_file.h>
 #include <linux/times.h>
@@ -3463,6 +3464,8 @@
 	migration_req_t req;
 	runqueue_t *rq;
 
+	perfctr_set_cpus_allowed(p, new_mask);
+
 	rq = task_rq_lock(p, &flags);
 	if (any_online_cpu(new_mask) == NR_CPUS) {
 		ret = -EINVAL;
kernel/sys.c +1 -0
diff -ruN linux-2.6.6-mm2/kernel/sys.c linux-2.6.6-mm2.perfctr-2.7.2.core/kernel/sys.c
@@ -279,6 +279,7 @@
 cond_syscall(sys_pciconfig_read)
 cond_syscall(sys_pciconfig_write)
 cond_syscall(sys_pciconfig_iobase)
+cond_syscall(sys_perfctr)
 
 static int set_one_prio(struct task_struct *p, int niceval, int error)
 {
kernel/timer.c +2 -0
diff -ruN linux-2.6.6-mm2/kernel/timer.c linux-2.6.6-mm2.perfctr-2.7.2.core/kernel/timer.c
@@ -31,6 +31,7 @@
 #include <linux/time.h>
 #include <linux/jiffies.h>
 #include <linux/cpu.h>
+#include <linux/perfctr.h>
 
 #include <asm/uaccess.h>
 #include <asm/div64.h>
@@ -834,6 +835,7 @@
 	do_process_times(p, user, system);
 	do_it_virt(p, user);
 	do_it_prof(p);
+	perfctr_sample_thread(&p->thread);
 }	
 
 /*
#1 lore raw

Haven't looked over much of the code yet, but the people who support 32bit userspace on 64bit architectures will probably kill you for the multiplexer syscall. And even without that it's a really horrible interface. Any chance to do a proper fs-based interface ala oprofile?

#2 lore raw
In reply to Mikael Pettersson
Quoted 2 lines · Mikael Pettersson

- core driver files and kernel changes

Looks like we need six system calls if we're going to do it that way.

All that marshalling and unmarshalling code is a bit evil. I wonder if there's some way in which it can be flattened out.

One option would be to present all the info to userspace as a virtual filesystem, although it would be a bit weird that the contents of the "files" depends upon the process which reads them.

Maybe a mkdir() on that filesystem could create a directory which contains files which contain the counters for the process which made the directory? The directory would need to be auto-rmdir'ed on process exit. It's basically the same semantics as /proc/pid.

But /proc/pid can be read by processes other than "pid". Does the same apply to the perfcntr instrumentation? (Being able to read another process's perfcntr info sounds useful. Is it?)