--- linux-2.6.18-128.el5.perfctr26/CREDITS.~1~	2008-12-18 19:28:24.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/CREDITS	2009-01-23 16:52:23.000000000 +0100
@@ -2635,9 +2635,10 @@ S: Ottawa, Ontario
 S: Canada K2P 0X8
 
 N: Mikael Pettersson
-E: mikpe@csd.uu.se
-W: http://www.csd.uu.se/~mikpe/
+E: mikpe@it.uu.se
+W: http://user.it.uu.se/~mikpe/linux/
 D: Miscellaneous fixes
+D: Performance-monitoring counters driver
 
 N: Reed H. Petty
 E: rhp@draper.net
--- linux-2.6.18-128.el5.perfctr26/Documentation/ioctl-number.txt.~1~	2006-09-20 05:42:06.000000000 +0200
+++ linux-2.6.18-128.el5.perfctr26/Documentation/ioctl-number.txt	2009-01-23 16:52:23.000000000 +0100
@@ -187,6 +187,8 @@ Code	Seq#	Include File		Comments
 0xB1	00-1F	PPPoX			<mailto:mostrows@styx.uwaterloo.ca>
 0xCB	00-1F	CBM serial IEC bus	in development:
 					<mailto:michael.klein@puffin.lb.shuttle.de>
+0xD0	all	performance counters	see drivers/perfctr/
+					<mailto:mikpe@it.uu.se>
 0xDD	00-3F	ZFCP device driver	see drivers/s390/scsi/
 					<mailto:aherrman@de.ibm.com>
 0xF3	00-3F	video/sisfb.h		sisfb (in development)
--- linux-2.6.18-128.el5.perfctr26/MAINTAINERS.~1~	2008-12-18 19:29:05.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/MAINTAINERS	2009-01-23 16:52:23.000000000 +0100
@@ -2341,6 +2341,12 @@ M:	nagar@watson.ibm.com
 L:	linux-kernel@vger.kernel.org
 S:	Maintained
 
+PERFORMANCE-MONITORING COUNTERS DRIVER
+P:	Mikael Pettersson
+M:	mikpe@it.uu.se
+W:	http://user.it.uu.se/~mikpe/linux/perfctr/
+S:	Maintained
+
 PERSONALITY HANDLING
 P:	Christoph Hellwig
 M:	hch@infradead.org
--- linux-2.6.18-128.el5.perfctr26/arch/i386/Kconfig.~1~	2008-12-18 19:29:01.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/arch/i386/Kconfig	2009-01-23 16:52:23.000000000 +0100
@@ -773,6 +773,8 @@ config VGA_NOPROBE
          data.  Say N here unless you are absolutely sure this is what you
          want.
 
+source "drivers/perfctr/Kconfig"
+
 source kernel/Kconfig.hz
 
 config KEXEC
--- linux-2.6.18-128.el5.perfctr26/arch/i386/kernel/entry.S.~1~	2008-12-18 19:28:30.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/arch/i386/kernel/entry.S	2009-01-23 16:52:23.000000000 +0100
@@ -586,6 +586,22 @@ ENTRY(name)				\
 /* The include is where all of the SMP etc. interrupts come from */
 #include "entry_arch.h"
 
+#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_KPERFCTR)
+ENTRY(perfctr_interrupt)
+	RING0_INT_FRAME
+	pushl $~(LOCAL_PERFCTR_VECTOR)
+	CFI_ADJUST_CFA_OFFSET 4
+	SAVE_ALL
+	TRACE_IRQS_OFF
+	pushl %esp
+	CFI_ADJUST_CFA_OFFSET 4
+	call smp_perfctr_interrupt
+	addl $4, %esp
+	CFI_ADJUST_CFA_OFFSET -4
+	jmp ret_from_intr
+	CFI_ENDPROC
+#endif
+
 ENTRY(divide_error)
 	RING0_INT_FRAME
 	pushl $0			# no error code
--- linux-2.6.18-128.el5.perfctr26/arch/i386/kernel/i8259.c.~1~	2006-09-20 05:42:06.000000000 +0200
+++ linux-2.6.18-128.el5.perfctr26/arch/i386/kernel/i8259.c	2009-01-23 16:52:23.000000000 +0100
@@ -22,6 +22,7 @@
 #include <asm/apic.h>
 #include <asm/arch_hooks.h>
 #include <asm/i8259.h>
+#include <asm/perfctr.h>
 
 #include <io_ports.h>
 
@@ -420,6 +421,8 @@ void __init init_IRQ(void)
 	 */
 	intr_init_hook();
 
+	perfctr_vector_init();
+
 	/*
 	 * Set the clock to HZ Hz, we already have a valid
 	 * vector now:
--- linux-2.6.18-128.el5.perfctr26/arch/i386/kernel/process.c.~1~	2008-12-18 19:28:52.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/arch/i386/kernel/process.c	2009-01-23 16:52:23.000000000 +0100
@@ -32,6 +32,7 @@
 #include <linux/delay.h>
 #include <linux/reboot.h>
 #include <linux/init.h>
+#include <linux/perfctr.h>
 #include <linux/mc146818rtc.h>
 #include <linux/module.h>
 #include <linux/kallsyms.h>
@@ -375,6 +376,7 @@ void exit_thread(void)
 		tss->io_bitmap_base = INVALID_IO_BITMAP_OFFSET;
 		put_cpu();
 	}
+	perfctr_exit_thread(&current->thread);
 }
 
 void flush_thread(void)
@@ -427,6 +429,8 @@ int copy_thread(int nr, unsigned long cl
 	savesegment(fs,p->thread.fs);
 	savesegment(gs,p->thread.gs);
 
+	perfctr_copy_task(p, regs);
+
 	tsk = current;
 	if (unlikely(test_tsk_thread_flag(tsk, TIF_IO_BITMAP))) {
 		p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
@@ -694,6 +698,8 @@ struct task_struct fastcall * __switch_t
 
 	disable_tsc(prev_p, next_p);
 
+	perfctr_resume_thread(next);
+
 	return prev_p;
 }
 
--- linux-2.6.18-128.el5.perfctr26/arch/powerpc/Kconfig.~1~	2008-12-18 19:29:03.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/arch/powerpc/Kconfig	2009-01-23 16:52:23.000000000 +0100
@@ -335,6 +335,11 @@ config NOT_COHERENT_CACHE
 	bool
 	depends on 4xx || 8xx || E200
 	default y
+
+if PPC32
+source "drivers/perfctr/Kconfig"
+endif
+
 endmenu
 
 source "init/Kconfig"
--- linux-2.6.18-128.el5.perfctr26/arch/powerpc/kernel/process.c.~1~	2008-12-18 19:28:54.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/arch/powerpc/kernel/process.c	2009-01-23 16:52:23.000000000 +0100
@@ -31,6 +31,7 @@
 #include <linux/init_task.h>
 #include <linux/module.h>
 #include <linux/kallsyms.h>
+#include <linux/perfctr.h>
 #include <linux/mqueue.h>
 #include <linux/hardirq.h>
 #include <linux/utsname.h>
@@ -338,7 +339,9 @@ struct task_struct *__switch_to(struct t
 	account_process_vtime(current);
 	calculate_steal_time();
 
+	perfctr_suspend_thread(&prev->thread);
 	last = _switch(old_thread, new_thread);
+	perfctr_resume_thread(&current->thread);
 
 	local_irq_restore(flags);
 
@@ -470,6 +473,7 @@ void show_regs(struct pt_regs * regs)
 void exit_thread(void)
 {
 	discard_lazy_cpu_state();
+	perfctr_exit_thread(&current->thread);
 }
 
 void flush_thread(void)
@@ -582,6 +586,8 @@ int copy_thread(int nr, unsigned long cl
 	p->thread.last_syscall = -1;
 #endif
 
+	perfctr_copy_task(p, regs);
+
 	return 0;
 }
 
--- linux-2.6.18-128.el5.perfctr26/arch/x86_64/Kconfig.~1~	2008-12-18 19:29:04.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/arch/x86_64/Kconfig	2009-01-23 16:52:23.000000000 +0100
@@ -602,6 +602,8 @@ config SECCOMP
 
 	  If unsure, say Y. Only embedded should say N here.
 
+source "drivers/perfctr/Kconfig"
+
 source kernel/Kconfig.hz
 
 config REORDER
--- linux-2.6.18-128.el5.perfctr26/arch/x86_64/kernel/entry.S.~1~	2008-12-18 19:28:49.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/arch/x86_64/kernel/entry.S	2009-01-23 16:52:23.000000000 +0100
@@ -699,6 +699,12 @@ ENTRY(spurious_interrupt)
 END(spurious_interrupt)
 #endif
 				
+#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_KPERFCTR)
+ENTRY(perfctr_interrupt)
+	apicinterrupt LOCAL_PERFCTR_VECTOR,smp_perfctr_interrupt
+END(perfctr_interrupt)
+#endif
+
 /*
  * Exception entry points.
  */ 		
--- linux-2.6.18-128.el5.perfctr26/arch/x86_64/kernel/i8259.c.~1~	2008-12-18 19:28:20.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/arch/x86_64/kernel/i8259.c	2009-01-23 16:52:23.000000000 +0100
@@ -22,6 +22,7 @@
 #include <asm/delay.h>
 #include <asm/desc.h>
 #include <asm/apic.h>
+#include <asm/perfctr.h>
 
 /*
  * Common place to define all x86 IRQ vectors
@@ -591,6 +592,8 @@ void __init init_IRQ(void)
 	set_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
 #endif
 
+	perfctr_vector_init();
+
 	/*
 	 * Set the clock to HZ Hz, we already have a valid
 	 * vector now:
--- linux-2.6.18-128.el5.perfctr26/arch/x86_64/kernel/process.c.~1~	2008-12-18 19:28:52.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/arch/x86_64/kernel/process.c	2009-01-23 16:52:23.000000000 +0100
@@ -32,6 +32,7 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/ptrace.h>
+#include <linux/perfctr.h>
 #include <linux/utsname.h>
 #include <linux/random.h>
 #include <linux/notifier.h>
@@ -360,6 +361,7 @@ void exit_thread(void)
 		t->io_bitmap_max = 0;
 		put_cpu();
 	}
+	perfctr_exit_thread(&me->thread);
 }
 
 void flush_thread(void)
@@ -464,6 +466,8 @@ int copy_thread(int nr, unsigned long cl
 	asm("mov %%es,%0" : "=m" (p->thread.es));
 	asm("mov %%ds,%0" : "=m" (p->thread.ds));
 
+	perfctr_copy_task(p, regs);
+
 	if (unlikely(me->thread.io_bitmap_ptr != NULL)) { 
 		p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
 		if (!p->thread.io_bitmap_ptr) {
@@ -620,6 +624,8 @@ __switch_to(struct task_struct *prev_p, 
 		}
 	}
 
+	perfctr_resume_thread(next);
+
 	return prev_p;
 }
 
--- linux-2.6.18-128.el5.perfctr26/drivers/Makefile.~1~	2008-12-18 19:29:01.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/drivers/Makefile	2009-01-23 16:52:23.000000000 +0100
@@ -75,6 +75,7 @@ obj-$(CONFIG_NEW_LEDS)		+= leds/
 obj-$(CONFIG_INFINIBAND)	+= infiniband/
 obj-$(CONFIG_IPATH_CORE)	+= infiniband/
 obj-$(CONFIG_SGI_SN)		+= sn/
+obj-$(CONFIG_KPERFCTR)		+= perfctr/
 obj-y				+= firmware/
 obj-$(CONFIG_CRYPTO)		+= crypto/
 obj-$(CONFIG_SUPERH)		+= sh/
--- linux-2.6.18.x86_64/fs/exec.c.orig	2010-05-03 20:08:13.000000000 +0200
+++ linux-2.6.18.x86_64/fs/exec.c	2010-05-03 20:15:15.000000000 +0200
@@ -50,6 +50,7 @@
 #include <linux/acct.h>
 #include <linux/cn_proc.h>
 #include <linux/audit.h>
+#include <linux/perfctr.h>
 #include <trace/signal.h>
 
 #include <asm/uaccess.h>
@@ -1070,6 +1071,7 @@
 	set_task_comm(current, tcomm);
 
 	current->flags &= ~PF_RANDOMIZE;
+	perfctr_flush_thread(&current->thread);
 	flush_thread();
 
 	/* Set the new mm task size. We have to do that late because it may
--- linux-2.6.18-128.el5.perfctr26/include/asm-i386/mach-default/irq_vectors.h.~1~	2006-09-20 05:42:06.000000000 +0200
+++ linux-2.6.18-128.el5.perfctr26/include/asm-i386/mach-default/irq_vectors.h	2009-01-23 16:52:23.000000000 +0100
@@ -56,14 +56,15 @@
  * sources per level' errata.
  */
 #define LOCAL_TIMER_VECTOR	0xef
+#define LOCAL_PERFCTR_VECTOR	0xee
 
 /*
- * First APIC vector available to drivers: (vectors 0x30-0xee)
+ * First APIC vector available to drivers: (vectors 0x30-0xed)
  * we start at 0x31 to spread out vectors evenly between priority
  * levels. (0x80 is the syscall vector)
  */
 #define FIRST_DEVICE_VECTOR	0x31
-#define FIRST_SYSTEM_VECTOR	0xef
+#define FIRST_SYSTEM_VECTOR	0xee
 
 #define TIMER_IRQ 0
 
--- linux-2.6.18-128.el5.perfctr26/include/asm-i386/mach-visws/irq_vectors.h.~1~	2006-09-20 05:42:06.000000000 +0200
+++ linux-2.6.18-128.el5.perfctr26/include/asm-i386/mach-visws/irq_vectors.h	2009-01-23 16:52:23.000000000 +0100
@@ -35,14 +35,15 @@
  * sources per level' errata.
  */
 #define LOCAL_TIMER_VECTOR	0xef
+#define LOCAL_PERFCTR_VECTOR	0xee
 
 /*
- * First APIC vector available to drivers: (vectors 0x30-0xee)
+ * First APIC vector available to drivers: (vectors 0x30-0xed)
  * we start at 0x31 to spread out vectors evenly between priority
  * levels. (0x80 is the syscall vector)
  */
 #define FIRST_DEVICE_VECTOR	0x31
-#define FIRST_SYSTEM_VECTOR	0xef
+#define FIRST_SYSTEM_VECTOR	0xee
 
 #define TIMER_IRQ 0
 
--- linux-2.6.18-128.el5.perfctr26/include/asm-i386/processor.h.~1~	2008-12-18 19:28:38.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/include/asm-i386/processor.h	2009-01-23 16:52:23.000000000 +0100
@@ -475,6 +475,8 @@ struct thread_struct {
  	unsigned long	iopl;
 /* max allowed port in the bitmap, in bytes: */
 	unsigned long	io_bitmap_max;
+/* performance counters */
+	struct vperfctr *perfctr;
 };
 
 #define INIT_THREAD  {							\
--- linux-2.6.18-128.el5.perfctr26/include/asm-i386/system.h.~1~	2006-09-20 05:42:06.000000000 +0200
+++ linux-2.6.18-128.el5.perfctr26/include/asm-i386/system.h	2009-01-23 16:52:23.000000000 +0100
@@ -17,6 +17,7 @@ extern struct task_struct * FASTCALL(__s
  */
 #define switch_to(prev,next,last) do {					\
 	unsigned long esi,edi;						\
+	perfctr_suspend_thread(&(prev)->thread);			\
 	asm volatile("pushfl\n\t"		/* Save flags */	\
 		     "pushl %%ebp\n\t"					\
 		     "movl %%esp,%0\n\t"	/* save ESP */		\
--- linux-2.6.18-128.el5.perfctr26/include/asm-powerpc/processor.h.~1~	2006-09-20 05:42:06.000000000 +0200
+++ linux-2.6.18-128.el5.perfctr26/include/asm-powerpc/processor.h	2009-01-23 16:52:23.000000000 +0100
@@ -169,6 +169,9 @@ struct thread_struct {
 	unsigned long	spefscr;	/* SPE & eFP status */
 	int		used_spe;	/* set if process has used spe */
 #endif /* CONFIG_SPE */
+#ifdef CONFIG_PERFCTR_VIRTUAL
+	struct vperfctr *perfctr;	/* performance counters */
+#endif
 };
 
 #define ARCH_MIN_TASKALIGN 16
--- linux-2.6.18-128.el5.perfctr26/include/asm-x86_64/hw_irq.h.~1~	2006-09-20 05:42:06.000000000 +0200
+++ linux-2.6.18-128.el5.perfctr26/include/asm-x86_64/hw_irq.h	2009-01-23 16:52:23.000000000 +0100
@@ -64,14 +64,15 @@ struct hw_interrupt_type;
  * sources per level' errata.
  */
 #define LOCAL_TIMER_VECTOR	0xef
+#define LOCAL_PERFCTR_VECTOR	0xee
 
 /*
- * First APIC vector available to drivers: (vectors 0x30-0xee)
+ * First APIC vector available to drivers: (vectors 0x30-0xed)
  * we start at 0x31 to spread out vectors evenly between priority
  * levels. (0x80 is the syscall vector)
  */
 #define FIRST_DEVICE_VECTOR	0x31
-#define FIRST_SYSTEM_VECTOR	0xef   /* duplicated in irq.h */
+#define FIRST_SYSTEM_VECTOR	0xee   /* duplicated in irq.h */
 
 
 #ifndef __ASSEMBLY__
--- linux-2.6.18-128.el5.perfctr26/include/asm-x86_64/irq.h.~1~	2006-09-20 05:42:06.000000000 +0200
+++ linux-2.6.18-128.el5.perfctr26/include/asm-x86_64/irq.h	2009-01-23 16:52:23.000000000 +0100
@@ -29,7 +29,7 @@
  */
 #define NR_VECTORS 256
 
-#define FIRST_SYSTEM_VECTOR	0xef   /* duplicated in hw_irq.h */
+#define FIRST_SYSTEM_VECTOR	0xee   /* duplicated in hw_irq.h */
 
 #ifdef CONFIG_PCI_MSI
 #define NR_IRQS FIRST_SYSTEM_VECTOR
--- linux-2.6.18-128.el5.perfctr26/include/asm-x86_64/processor.h.~1~	2008-12-18 19:28:38.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/include/asm-x86_64/processor.h	2009-01-23 16:52:23.000000000 +0100
@@ -275,6 +275,8 @@ struct thread_struct {
 	unsigned io_bitmap_max;
 /* cached TLS descriptors. */
 	u64 tls_array[GDT_ENTRY_TLS_ENTRIES];
+/* performance counters */
+	struct vperfctr *perfctr;
 } __attribute__((aligned(16)));
 
 #define INIT_THREAD  { \
--- linux-2.6.18-128.el5.perfctr26/include/asm-x86_64/system.h.~1~	2008-12-18 19:28:19.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/include/asm-x86_64/system.h	2009-01-23 16:52:23.000000000 +0100
@@ -21,7 +21,8 @@
 	,"rcx","rbx","rdx","r8","r9","r10","r11","r12","r13","r14","r15"
 
 /* Save restore flags to clear handle leaking NT */
-#define switch_to(prev,next,last) \
+#define switch_to(prev,next,last) do { \
+	perfctr_suspend_thread(&(prev)->thread); \
 	asm volatile(SAVE_CONTEXT						    \
 		     "movq %%rsp,%P[threadrsp](%[prev])\n\t" /* save RSP */	  \
 		     "movq %P[threadrsp](%[next]),%%rsp\n\t" /* restore RSP */	  \
@@ -41,7 +42,8 @@
 		       [tif_fork] "i" (TIF_FORK),			  \
 		       [thread_info] "i" (offsetof(struct task_struct, thread_info)), \
 		       [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent))   \
-		     : "memory", "cc" __EXTRA_CLOBBER)
+		     : "memory", "cc" __EXTRA_CLOBBER); \
+} while (0)
     
 extern void load_gs_index(unsigned); 
 
--- linux-2.6.18-128.el5.perfctr26/include/linux/config.h.~1~	2008-12-18 19:28:06.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/include/linux/config.h	2009-01-23 16:52:23.000000000 +0100
@@ -3,6 +3,8 @@
 /* This file is no longer in use and kept only for backward compatibility.
  * autoconf.h is now included via -imacros on the commandline
  */
+#define HAVE_EXPORT___put_task_struct 1
+#define DONT_HAVE_i_blksize 1
 #warning Including config.h is deprecated.
 #include <linux/autoconf.h>
 #if !defined (__KERNEL__) && !defined(__KERNGLUE__)
--- linux-2.6.18-128.el5.perfctr26/kernel/exit.c.~1~	2008-12-18 19:29:03.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/kernel/exit.c	2009-01-23 16:52:23.000000000 +0100
@@ -26,6 +26,7 @@
 #include <linux/mount.h>
 #include <linux/proc_fs.h>
 #include <linux/mempolicy.h>
+#include <linux/perfctr.h>
 #include <linux/taskstats_kern.h>
 #include <linux/delayacct.h>
 #include <linux/cpuset.h>
@@ -182,6 +183,7 @@ repeat:
 		}
 	}
 
+	perfctr_release_task(p);
 	sched_exit(p);
 	write_unlock_irq(&tasklist_lock);
 	proc_flush_task(p);
--- linux-2.6.18-128.el5.perfctr26/kernel/sched.c.~1~	2008-12-18 19:29:04.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/kernel/sched.c	2009-01-23 16:52:23.000000000 +0100
@@ -45,6 +45,7 @@
 #include <linux/cpu.h>
 #include <linux/cpuset.h>
 #include <linux/percpu.h>
+#include <linux/perfctr.h>
 #include <linux/kthread.h>
 #include <linux/seq_file.h>
 #include <linux/syscalls.h>
@@ -5117,6 +5118,8 @@ int set_cpus_allowed(struct task_struct 
 	struct rq *rq;
 	int ret = 0;
 
+	perfctr_set_cpus_allowed(p, new_mask);
+
 	rq = task_rq_lock(p, &flags);
 	if (!cpus_intersects(new_mask, cpu_online_map)) {
 		ret = -EINVAL;
--- linux-2.6.18-128.el5.perfctr26/kernel/timer.c.~1~	2008-12-18 19:29:06.000000000 +0100
+++ linux-2.6.18-128.el5.perfctr26/kernel/timer.c	2009-01-23 16:52:23.000000000 +0100
@@ -32,6 +32,7 @@
 #include <linux/jiffies.h>
 #include <linux/posix-timers.h>
 #include <linux/cpu.h>
+#include <linux/perfctr.h>
 #include <linux/syscalls.h>
 #include <linux/delay.h>
 
@@ -1315,6 +1316,7 @@ void update_process_times(int user_tick,
 		account_user_time(p, jiffies_to_cputime(1));
 	else
 		account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(1));
+	perfctr_sample_thread(&p->thread);
 	run_local_timers(regs);
 	if (rcu_pending(cpu))
 		rcu_check_callbacks(cpu, user_tick);
