diff -rupN linux-2.6.22/CREDITS linux-2.6.22.perfctr27/CREDITS
--- linux-2.6.22/CREDITS 2007-07-09 22:01:30.000000000 +0200
+++ linux-2.6.22.perfctr27/CREDITS 2007-09-28 12:46:31.000000000 +0200
@@ -2685,7 +2685,7 @@ S: Canada K2P 0X8
N: Mikael Pettersson
E: mikpe@it.uu.se
-W: http://www.csd.uu.se/~mikpe/
+W: http://user.it.uu.se/~mikpe/
D: Miscellaneous fixes
N: Reed H. Petty
diff -rupN linux-2.6.22/MAINTAINERS linux-2.6.22.perfctr27/MAINTAINERS
--- linux-2.6.22/MAINTAINERS 2007-07-09 22:01:30.000000000 +0200
+++ linux-2.6.22.perfctr27/MAINTAINERS 2007-09-28 12:46:31.000000000 +0200
@@ -2844,6 +2844,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
diff -rupN linux-2.6.22/arch/i386/Kconfig linux-2.6.22.perfctr27/arch/i386/Kconfig
--- linux-2.6.22/arch/i386/Kconfig 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/i386/Kconfig 2007-09-28 12:46:31.000000000 +0200
@@ -781,6 +781,8 @@ config SECCOMP
If unsure, say Y. Only embedded should say N here.
+source "drivers/perfctr/Kconfig"
+
source kernel/Kconfig.hz
config KEXEC
diff -rupN linux-2.6.22/arch/i386/kernel/entry.S linux-2.6.22.perfctr27/arch/i386/kernel/entry.S
--- linux-2.6.22/arch/i386/kernel/entry.S 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/i386/kernel/entry.S 2007-09-28 12:46:31.000000000 +0200
@@ -637,6 +637,22 @@ ENDPROC(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_PERFCTR)
+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
+
KPROBE_ENTRY(page_fault)
RING0_EC_FRAME
pushl $do_page_fault
diff -rupN linux-2.6.22/arch/i386/kernel/i8259.c linux-2.6.22.perfctr27/arch/i386/kernel/i8259.c
--- linux-2.6.22/arch/i386/kernel/i8259.c 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/i386/kernel/i8259.c 2007-09-28 12:46:31.000000000 +0200
@@ -21,6 +21,7 @@
#include <asm/apic.h>
#include <asm/arch_hooks.h>
#include <asm/i8259.h>
+#include <asm/perfctr.h>
#include <io_ports.h>
@@ -409,6 +410,8 @@ void __init native_init_IRQ(void)
*/
intr_init_hook();
+ perfctr_vector_init();
+
/*
* External FPU? Set up irq13 if so, for
* original braindamaged IBM FERR coupling.
diff -rupN linux-2.6.22/arch/i386/kernel/process.c linux-2.6.22.perfctr27/arch/i386/kernel/process.c
--- linux-2.6.22/arch/i386/kernel/process.c 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/i386/kernel/process.c 2007-09-28 12:46:31.000000000 +0200
@@ -31,6 +31,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>
@@ -384,6 +385,7 @@ void exit_thread(void)
tss->x86_tss.io_bitmap_base = INVALID_IO_BITMAP_OFFSET;
put_cpu();
}
+ perfctr_exit_thread(¤t->thread);
}
void flush_thread(void)
@@ -435,6 +437,8 @@ int copy_thread(int nr, unsigned long cl
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 = kmemdup(tsk->thread.io_bitmap_ptr,
@@ -719,6 +723,8 @@ struct task_struct fastcall * __switch_t
x86_write_percpu(current_task, next_p);
+ perfctr_resume_thread(next);
+
return prev_p;
}
diff -rupN linux-2.6.22/arch/i386/kernel/syscall_table.S linux-2.6.22.perfctr27/arch/i386/kernel/syscall_table.S
--- linux-2.6.22/arch/i386/kernel/syscall_table.S 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/i386/kernel/syscall_table.S 2007-09-28 12:53:08.000000000 +0200
@@ -323,3 +323,8 @@ ENTRY(sys_call_table)
.long sys_signalfd
.long sys_timerfd
.long sys_eventfd
+ .long sys_ni_syscall
+ .long sys_vperfctr_open /* 325 */
+ .long sys_vperfctr_control
+ .long sys_vperfctr_write
+ .long sys_vperfctr_read
diff -rupN linux-2.6.22/arch/powerpc/Kconfig linux-2.6.22.perfctr27/arch/powerpc/Kconfig
--- linux-2.6.22/arch/powerpc/Kconfig 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/powerpc/Kconfig 2007-09-28 12:55:07.000000000 +0200
@@ -393,6 +393,9 @@ config NOT_COHERENT_CACHE
config CONFIG_CHECK_CACHE_COHERENCY
bool
+
+source "drivers/perfctr/Kconfig"
+
endmenu
source "init/Kconfig"
diff -rupN linux-2.6.22/arch/powerpc/kernel/process.c linux-2.6.22.perfctr27/arch/powerpc/kernel/process.c
--- linux-2.6.22/arch/powerpc/kernel/process.c 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/powerpc/kernel/process.c 2007-09-28 12:46:31.000000000 +0200
@@ -30,6 +30,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>
@@ -329,7 +330,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(¤t->thread);
local_irq_restore(flags);
@@ -455,6 +458,7 @@ void show_regs(struct pt_regs * regs)
void exit_thread(void)
{
discard_lazy_cpu_state();
+ perfctr_exit_thread(¤t->thread);
}
void flush_thread(void)
@@ -571,6 +575,8 @@ int copy_thread(int nr, unsigned long cl
kregs->nip = (unsigned long)ret_from_fork;
#endif
+ perfctr_copy_task(p, regs);
+
return 0;
}
diff -rupN linux-2.6.22/arch/x86_64/Kconfig linux-2.6.22.perfctr27/arch/x86_64/Kconfig
--- linux-2.6.22/arch/x86_64/Kconfig 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/x86_64/Kconfig 2007-09-28 12:46:31.000000000 +0200
@@ -661,6 +661,8 @@ config CC_STACKPROTECTOR_ALL
functions that use large-ish on-stack buffers. By enabling
this option, GCC will be asked to do this for ALL functions.
+source "drivers/perfctr/Kconfig"
+
source kernel/Kconfig.hz
config K8_NB
diff -rupN linux-2.6.22/arch/x86_64/ia32/ia32entry.S linux-2.6.22.perfctr27/arch/x86_64/ia32/ia32entry.S
--- linux-2.6.22/arch/x86_64/ia32/ia32entry.S 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/x86_64/ia32/ia32entry.S 2007-09-28 12:54:03.000000000 +0200
@@ -719,4 +719,9 @@ ia32_sys_call_table:
.quad compat_sys_signalfd
.quad compat_sys_timerfd
.quad sys_eventfd
+ .quad quiet_ni_syscall
+ .quad sys_vperfctr_open /* 325 */
+ .quad sys_vperfctr_control
+ .quad sys_vperfctr_write
+ .quad sys_vperfctr_read
ia32_syscall_end:
diff -rupN linux-2.6.22/arch/x86_64/kernel/entry.S linux-2.6.22.perfctr27/arch/x86_64/kernel/entry.S
--- linux-2.6.22/arch/x86_64/kernel/entry.S 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/x86_64/kernel/entry.S 2007-09-28 12:46:31.000000000 +0200
@@ -692,6 +692,12 @@ ENTRY(spurious_interrupt)
apicinterrupt SPURIOUS_APIC_VECTOR,smp_spurious_interrupt
END(spurious_interrupt)
+#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_PERFCTR)
+ENTRY(perfctr_interrupt)
+ apicinterrupt LOCAL_PERFCTR_VECTOR,smp_perfctr_interrupt
+END(perfctr_interrupt)
+#endif
+
/*
* Exception entry points.
*/
diff -rupN linux-2.6.22/arch/x86_64/kernel/i8259.c linux-2.6.22.perfctr27/arch/x86_64/kernel/i8259.c
--- linux-2.6.22/arch/x86_64/kernel/i8259.c 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/x86_64/kernel/i8259.c 2007-09-28 12:46:31.000000000 +0200
@@ -21,6 +21,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
@@ -551,6 +552,8 @@ void __init init_IRQ(void)
set_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
set_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
+ perfctr_vector_init();
+
/*
* Set the clock to HZ Hz, we already have a valid
* vector now:
diff -rupN linux-2.6.22/arch/x86_64/kernel/process.c linux-2.6.22.perfctr27/arch/x86_64/kernel/process.c
--- linux-2.6.22/arch/x86_64/kernel/process.c 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/arch/x86_64/kernel/process.c 2007-09-28 12:46:31.000000000 +0200
@@ -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>
@@ -379,6 +380,7 @@ void exit_thread(void)
t->io_bitmap_max = 0;
put_cpu();
}
+ perfctr_exit_thread(t);
}
void flush_thread(void)
@@ -487,6 +489,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(test_tsk_thread_flag(me, TIF_IO_BITMAP))) {
p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
if (!p->thread.io_bitmap_ptr) {
@@ -670,6 +674,9 @@ __switch_to(struct task_struct *prev_p,
*/
if (next_p->fpu_counter>5)
math_state_restore();
+
+ perfctr_resume_thread(next);
+
return prev_p;
}
diff -rupN linux-2.6.22/drivers/Makefile linux-2.6.22.perfctr27/drivers/Makefile
--- linux-2.6.22/drivers/Makefile 2007-07-09 22:01:31.000000000 +0200
+++ linux-2.6.22.perfctr27/drivers/Makefile 2007-09-28 12:46:31.000000000 +0200
@@ -74,6 +74,7 @@ obj-$(CONFIG_MMC) += mmc/
obj-$(CONFIG_NEW_LEDS) += leds/
obj-$(CONFIG_INFINIBAND) += infiniband/
obj-$(CONFIG_SGI_SN) += sn/
+obj-$(CONFIG_PERFCTR) += perfctr/
obj-y += firmware/
obj-$(CONFIG_CRYPTO) += crypto/
obj-$(CONFIG_SUPERH) += sh/
diff -rupN linux-2.6.22/include/asm-i386/mach-default/irq_vectors.h linux-2.6.22.perfctr27/include/asm-i386/mach-default/irq_vectors.h
--- linux-2.6.22/include/asm-i386/mach-default/irq_vectors.h 2007-02-04 19:44:54.000000000 +0100
+++ linux-2.6.22.perfctr27/include/asm-i386/mach-default/irq_vectors.h 2007-09-28 12:46:31.000000000 +0200
@@ -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
diff -rupN linux-2.6.22/include/asm-i386/mach-visws/irq_vectors.h linux-2.6.22.perfctr27/include/asm-i386/mach-visws/irq_vectors.h
--- linux-2.6.22/include/asm-i386/mach-visws/irq_vectors.h 2007-02-04 19:44:54.000000000 +0100
+++ linux-2.6.22.perfctr27/include/asm-i386/mach-visws/irq_vectors.h 2007-09-28 12:46:31.000000000 +0200
@@ -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
diff -rupN linux-2.6.22/include/asm-i386/processor.h linux-2.6.22.perfctr27/include/asm-i386/processor.h
--- linux-2.6.22/include/asm-i386/processor.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-i386/processor.h 2007-09-28 12:46:31.000000000 +0200
@@ -370,6 +370,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 { \
diff -rupN linux-2.6.22/include/asm-i386/system.h linux-2.6.22.perfctr27/include/asm-i386/system.h
--- linux-2.6.22/include/asm-i386/system.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-i386/system.h 2007-09-28 12:46:31.000000000 +0200
@@ -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 */ \
diff -rupN linux-2.6.22/include/asm-i386/unistd.h linux-2.6.22.perfctr27/include/asm-i386/unistd.h
--- linux-2.6.22/include/asm-i386/unistd.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-i386/unistd.h 2007-09-28 12:52:10.000000000 +0200
@@ -329,10 +329,14 @@
#define __NR_signalfd 321
#define __NR_timerfd 322
#define __NR_eventfd 323
+#define __NR_vperfctr_open 325
+#define __NR_vperfctr_control (__NR_vperfctr_open+1)
+#define __NR_vperfctr_write (__NR_vperfctr_open+2)
+#define __NR_vperfctr_read (__NR_vperfctr_open+3)
#ifdef __KERNEL__
-#define NR_syscalls 324
+#define NR_syscalls 329
#define __ARCH_WANT_IPC_PARSE_VERSION
#define __ARCH_WANT_OLD_READDIR
diff -rupN linux-2.6.22/include/asm-powerpc/processor.h linux-2.6.22.perfctr27/include/asm-powerpc/processor.h
--- linux-2.6.22/include/asm-powerpc/processor.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-powerpc/processor.h 2007-09-28 12:46:31.000000000 +0200
@@ -165,6 +165,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
diff -rupN linux-2.6.22/include/asm-powerpc/reg.h linux-2.6.22.perfctr27/include/asm-powerpc/reg.h
--- linux-2.6.22/include/asm-powerpc/reg.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-powerpc/reg.h 2007-09-28 12:46:31.000000000 +0200
@@ -368,10 +368,8 @@
#define SPRN_PURR 0x135 /* Processor Utilization of Resources Reg */
#define SPRN_PVR 0x11F /* Processor Version Register */
#define SPRN_RPA 0x3D6 /* Required Physical Address Register */
-#define SPRN_SDA 0x3BF /* Sampled Data Address Register */
#define SPRN_SDR1 0x019 /* MMU Hash Base Register */
#define SPRN_ASR 0x118 /* Address Space Register */
-#define SPRN_SIA 0x3BB /* Sampled Instruction Address Register */
#define SPRN_SPRG0 0x110 /* Special Purpose Register General 0 */
#define SPRN_SPRG1 0x111 /* Special Purpose Register General 1 */
#define SPRN_SPRG2 0x112 /* Special Purpose Register General 2 */
@@ -414,13 +412,6 @@
#define SPRN_THRM3 0x3FE /* Thermal Management Register 3 */
#define THRM3_E (1<<0)
#define SPRN_TLBMISS 0x3D4 /* 980 7450 TLB Miss Register */
-#define SPRN_UMMCR0 0x3A8 /* User Monitor Mode Control Register 0 */
-#define SPRN_UMMCR1 0x3AC /* User Monitor Mode Control Register 0 */
-#define SPRN_UPMC1 0x3A9 /* User Performance Counter Register 1 */
-#define SPRN_UPMC2 0x3AA /* User Performance Counter Register 2 */
-#define SPRN_UPMC3 0x3AD /* User Performance Counter Register 3 */
-#define SPRN_UPMC4 0x3AE /* User Performance Counter Register 4 */
-#define SPRN_USIA 0x3AB /* User Sampled Instruction Address Register */
#define SPRN_VRSAVE 0x100 /* Vector Register Save Register */
#define SPRN_XER 0x001 /* Fixed Point Exception Register */
@@ -533,33 +524,7 @@
#define SPRN_PA6T_PMC5 792
#else /* 32-bit */
-#define SPRN_MMCR0 952 /* Monitor Mode Control Register 0 */
-#define MMCR0_FC 0x80000000UL /* freeze counters */
-#define MMCR0_FCS 0x40000000UL /* freeze in supervisor state */
-#define MMCR0_FCP 0x20000000UL /* freeze in problem state */
-#define MMCR0_FCM1 0x10000000UL /* freeze counters while MSR mark = 1 */
-#define MMCR0_FCM0 0x08000000UL /* freeze counters while MSR mark = 0 */
-#define MMCR0_PMXE 0x04000000UL /* performance monitor exception enable */
-#define MMCR0_FCECE 0x02000000UL /* freeze ctrs on enabled cond or event */
-#define MMCR0_TBEE 0x00400000UL /* time base exception enable */
-#define MMCR0_PMC1CE 0x00008000UL /* PMC1 count enable*/
#define MMCR0_PMCnCE 0x00004000UL /* count enable for all but PMC 1*/
-#define MMCR0_TRIGGER 0x00002000UL /* TRIGGER enable */
-#define MMCR0_PMC1SEL 0x00001fc0UL /* PMC 1 Event */
-#define MMCR0_PMC2SEL 0x0000003fUL /* PMC 2 Event */
-
-#define SPRN_MMCR1 956
-#define MMCR1_PMC3SEL 0xf8000000UL /* PMC 3 Event */
-#define MMCR1_PMC4SEL 0x07c00000UL /* PMC 4 Event */
-#define MMCR1_PMC5SEL 0x003e0000UL /* PMC 5 Event */
-#define MMCR1_PMC6SEL 0x0001f800UL /* PMC 6 Event */
-#define SPRN_MMCR2 944
-#define SPRN_PMC1 953 /* Performance Counter Register 1 */
-#define SPRN_PMC2 954 /* Performance Counter Register 2 */
-#define SPRN_PMC3 957 /* Performance Counter Register 3 */
-#define SPRN_PMC4 958 /* Performance Counter Register 4 */
-#define SPRN_PMC5 945 /* Performance Counter Register 5 */
-#define SPRN_PMC6 946 /* Performance Counter Register 6 */
#define SPRN_SIAR 955 /* Sampled Instruction Address Register */
@@ -571,6 +536,77 @@
#define MMCR0_PMC2_CYCLES 0x1
#define MMCR0_PMC2_ITLB 0x7
#define MMCR0_PMC2_LOADMISSTIME 0x5
+
+/* Performance-monitoring control and counter registers */
+#define SPRN_MMCR0 0x3B8 /* Monitor Mode Control Register 0 (604 and up) */
+#define SPRN_MMCR1 0x3BC /* Monitor Mode Control Register 1 (604e and up) */
+#define SPRN_MMCR2 0x3B0 /* Monitor Mode Control Register 2 (7400 and up) */
+#define SPRN_PMC1 0x3B9 /* Performance Counter Register 1 (604 and up) */
+#define SPRN_PMC2 0x3BA /* Performance Counter Register 2 (604 and up) */
+#define SPRN_PMC3 0x3BD /* Performance Counter Register 3 (604e and up) */
+#define SPRN_PMC4 0x3BE /* Performance Counter Register 4 (604e and up) */
+#define SPRN_PMC5 0x3B1 /* Performance Counter Register 5 (7450 and up) */
+#define SPRN_PMC6 0x3B2 /* Performance Counter Register 6 (7450 and up) */
+#define SPRN_SIA 0x3BB /* Sampled Instruction Address Register (604 and up) */
+#define SPRN_SDA 0x3BF /* Sampled Data Address Register (604/604e only) */
+#define SPRN_BAMR 0x3B7 /* Breakpoint Address Mask Register (7400 and up) */
+
+#define SPRN_UMMCR0 0x3A8 /* User Monitor Mode Control Register 0 (750 and up) */
+#define SPRN_UMMCR1 0x3AC /* User Monitor Mode Control Register 0 (750 and up) */
+#define SPRN_UMMCR2 0x3A0 /* User Monitor Mode Control Register 0 (7400 and up) */
+#define SPRN_UPMC1 0x3A9 /* User Performance Counter Register 1 (750 and up) */
+#define SPRN_UPMC2 0x3AA /* User Performance Counter Register 2 (750 and up) */
+#define SPRN_UPMC3 0x3AD /* User Performance Counter Register 3 (750 and up) */
+#define SPRN_UPMC4 0x3AE /* User Performance Counter Register 4 (750 and up) */
+#define SPRN_UPMC5 0x3A1 /* User Performance Counter Register 5 (7450 and up) */
+#define SPRN_UPMC6 0x3A2 /* User Performance Counter Register 5 (7450 and up) */
+#define SPRN_USIA 0x3AB /* User Sampled Instruction Address Register (750 and up) */
+#define SPRN_UBAMR 0x3A7 /* User Breakpoint Address Mask Register (7400 and up) */
+
+/* MMCR0 layout (74xx terminology) */
+#define MMCR0_FC 0x80000000 /* Freeze counters unconditionally. */
+#define MMCR0_FCS 0x40000000 /* Freeze counters while MSR[PR]=0 (supervisor mode). */
+#define MMCR0_FCP 0x20000000 /* Freeze counters while MSR[PR]=1 (user mode). */
+#define MMCR0_FCM1 0x10000000 /* Freeze counters while MSR[PM]=1. */
+#define MMCR0_FCM0 0x08000000 /* Freeze counters while MSR[PM]=0. */
+#define MMCR0_PMXE 0x04000000 /* Enable performance monitor exceptions.
+ * Cleared by hardware when a PM exception occurs.
+ * 604: PMXE is not cleared by hardware.
+ */
+#define MMCR0_FCECE 0x02000000 /* Freeze counters on enabled condition or event.
+ * FCECE is treated as 0 if TRIGGER is 1.
+ * 74xx: FC is set when the event occurs.
+ * 604/750: ineffective when PMXE=0.
+ */
+#define MMCR0_TBSEL 0x01800000 /* Time base lower (TBL) bit selector.
+ * 00: bit 31, 01: bit 23, 10: bit 19, 11: bit 15.
+ */
+#define MMCR0_TBEE 0x00400000 /* Enable event on TBL bit transition from 0 to 1. */
+#define MMCR0_THRESHOLD 0x003F0000 /* Threshold value for certain events. */
+#define MMCR0_PMC1CE 0x00008000 /* Enable event on PMC1 overflow. */
+#define MMCR0_PMCjCE 0x00004000 /* Enable event on PMC2-PMC6 overflow.
+ * 604/750: Overrides FCECE (DISCOUNT).
+ */
+#define MMCR0_TRIGGER 0x00002000 /* Disable PMC2-PMC6 until PMC1 overflow or other event.
+ * 74xx: cleared by hardware when the event occurs.
+ */
+#define MMCR0_PMC1SEL 0x00001FC0 /* PMC1 event selector, 7 bits. */
+#define MMCR0_PMC2SEL 0x0000003F /* PMC2 event selector, 6 bits. */
+
+/* MMCR1 layout (604e-7457) */
+#define MMCR1_PMC3SEL 0xF8000000 /* PMC3 event selector, 5 bits. */
+#define MMCR1_PMC4SEL 0x07C00000 /* PMC4 event selector, 5 bits. */
+#define MMCR1_PMC5SEL 0x003E0000 /* PMC5 event selector, 5 bits. (745x only) */
+#define MMCR1_PMC6SEL 0x0001F800 /* PMC6 event selector, 6 bits. (745x only) */
+#define MMCR1__RESERVED 0x000007FF /* should be zero */
+
+/* MMCR2 layout (7400-7457) */
+#define MMCR2_THRESHMULT 0x80000000 /* MMCR0[THRESHOLD] multiplier. */
+#define MMCR2_SMCNTEN 0x40000000 /* 7400/7410 only, should be zero. */
+#define MMCR2_SMINTEN 0x20000000 /* 7400/7410 only, should be zero. */
+#define MMCR2__RESERVED 0x1FFFFFFF /* should be zero */
+#define MMCR2_RESERVED (MMCR2_SMCNTEN | MMCR2_SMINTEN | MMCR2__RESERVED)
+
#endif
/*
diff -rupN linux-2.6.22/include/asm-powerpc/systbl.h linux-2.6.22.perfctr27/include/asm-powerpc/systbl.h
--- linux-2.6.22/include/asm-powerpc/systbl.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-powerpc/systbl.h 2007-09-28 12:49:16.000000000 +0200
@@ -311,4 +311,9 @@ COMPAT_SYS_SPU(utimensat)
COMPAT_SYS_SPU(signalfd)
COMPAT_SYS_SPU(timerfd)
SYSCALL_SPU(eventfd)
-COMPAT_SYS_SPU(sync_file_range2)
+COMPAT_SYS_SPU(sync_file_range2) /* 308 */
+SYSCALL(ni_syscall) /* 309 */
+SYSCALL(vperfctr_open) /* 310 */
+SYSCALL(vperfctr_control)
+SYSCALL(vperfctr_write)
+SYSCALL(vperfctr_read)
diff -rupN linux-2.6.22/include/asm-powerpc/unistd.h linux-2.6.22.perfctr27/include/asm-powerpc/unistd.h
--- linux-2.6.22/include/asm-powerpc/unistd.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-powerpc/unistd.h 2007-09-28 12:48:25.000000000 +0200
@@ -331,10 +331,14 @@
#define __NR_timerfd 306
#define __NR_eventfd 307
#define __NR_sync_file_range2 308
+#define __NR_vperfctr_open 310
+#define __NR_vperfctr_control (__NR_vperfctr_open+1)
+#define __NR_vperfctr_write (__NR_vperfctr_open+2)
+#define __NR_vperfctr_read (__NR_vperfctr_open+3)
#ifdef __KERNEL__
-#define __NR_syscalls 309
+#define __NR_syscalls 314
#define __NR__exit __NR_exit
#define NR_syscalls __NR_syscalls
diff -rupN linux-2.6.22/include/asm-x86_64/hw_irq.h linux-2.6.22.perfctr27/include/asm-x86_64/hw_irq.h
--- linux-2.6.22/include/asm-x86_64/hw_irq.h 2007-04-26 14:59:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-x86_64/hw_irq.h 2007-09-28 12:46:31.000000000 +0200
@@ -84,14 +84,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 0x41 to spread out vectors evenly between priority
* levels. (0x80 is the syscall vector)
*/
#define FIRST_DEVICE_VECTOR (IRQ15_VECTOR + 2)
-#define FIRST_SYSTEM_VECTOR 0xef /* duplicated in irq.h */
+#define FIRST_SYSTEM_VECTOR 0xee /* duplicated in irq.h */
#ifndef __ASSEMBLY__
diff -rupN linux-2.6.22/include/asm-x86_64/irq.h linux-2.6.22.perfctr27/include/asm-x86_64/irq.h
--- linux-2.6.22/include/asm-x86_64/irq.h 2007-02-04 19:44:54.000000000 +0100
+++ linux-2.6.22.perfctr27/include/asm-x86_64/irq.h 2007-09-28 12:46:31.000000000 +0200
@@ -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 */
#define NR_IRQS (NR_VECTORS + (32 *NR_CPUS))
#define NR_IRQ_VECTORS NR_IRQS
diff -rupN linux-2.6.22/include/asm-x86_64/processor.h linux-2.6.22.perfctr27/include/asm-x86_64/processor.h
--- linux-2.6.22/include/asm-x86_64/processor.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-x86_64/processor.h 2007-09-28 12:46:31.000000000 +0200
@@ -239,6 +239,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 { \
diff -rupN linux-2.6.22/include/asm-x86_64/system.h linux-2.6.22.perfctr27/include/asm-x86_64/system.h
--- linux-2.6.22/include/asm-x86_64/system.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-x86_64/system.h 2007-09-28 12:46:31.000000000 +0200
@@ -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, stack)), \
[pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \
- : "memory", "cc" __EXTRA_CLOBBER)
+ : "memory", "cc" __EXTRA_CLOBBER); \
+} while (0)
extern void load_gs_index(unsigned);
diff -rupN linux-2.6.22/include/asm-x86_64/unistd.h linux-2.6.22.perfctr27/include/asm-x86_64/unistd.h
--- linux-2.6.22/include/asm-x86_64/unistd.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/asm-x86_64/unistd.h 2007-09-28 12:50:48.000000000 +0200
@@ -630,6 +630,15 @@ __SYSCALL(__NR_signalfd, sys_signalfd)
__SYSCALL(__NR_timerfd, sys_timerfd)
#define __NR_eventfd 284
__SYSCALL(__NR_eventfd, sys_eventfd)
+__SYSCALL(285, sys_ni_syscall) /* fallocate */
+#define __NR_vperfctr_open 286
+__SYSCALL(__NR_vperfctr_open, sys_vperfctr_open)
+#define __NR_vperfctr_control (__NR_vperfctr_open+1)
+__SYSCALL(__NR_vperfctr_control, sys_vperfctr_control)
+#define __NR_vperfctr_write (__NR_vperfctr_open+2)
+__SYSCALL(__NR_vperfctr_write, sys_vperfctr_write)
+#define __NR_vperfctr_read (__NR_vperfctr_open+3)
+__SYSCALL(__NR_vperfctr_read, sys_vperfctr_read)
#ifndef __NO_STUBS
#define __ARCH_WANT_OLD_READDIR
diff -rupN linux-2.6.22/include/linux/sched.h linux-2.6.22.perfctr27/include/linux/sched.h
--- linux-2.6.22/include/linux/sched.h 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/include/linux/sched.h 2007-09-28 12:46:31.000000000 +0200
@@ -1496,6 +1496,9 @@ static inline int thread_group_empty(str
* subscriptions and synchronises with wait4(). Also used in procfs. Also
* pins the final release of task.io_context. Also protects ->cpuset.
*
+ * Synchronises set_cpus_allowed(), unlink, and creat of ->thread.perfctr.
+ * [if CONFIG_PERFCTR_VIRTUAL]
+ *
* Nests both inside and outside of read_lock(&tasklist_lock).
* It must not be nested with write_lock_irq(&tasklist_lock),
* neither inside nor outside.
diff -rupN linux-2.6.22/kernel/exit.c linux-2.6.22.perfctr27/kernel/exit.c
--- linux-2.6.22/kernel/exit.c 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/kernel/exit.c 2007-09-28 12:46:31.000000000 +0200
@@ -29,6 +29,7 @@
#include <linux/proc_fs.h>
#include <linux/kthread.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:
zap_leader = (leader->exit_signal == -1);
}
+ perfctr_release_task(p);
sched_exit(p);
write_unlock_irq(&tasklist_lock);
proc_flush_task(p);
diff -rupN linux-2.6.22/kernel/sched.c linux-2.6.22.perfctr27/kernel/sched.c
--- linux-2.6.22/kernel/sched.c 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/kernel/sched.c 2007-09-28 12:46:31.000000000 +0200
@@ -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>
@@ -5121,6 +5122,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;
diff -rupN linux-2.6.22/kernel/sys_ni.c linux-2.6.22.perfctr27/kernel/sys_ni.c
--- linux-2.6.22/kernel/sys_ni.c 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/kernel/sys_ni.c 2007-09-28 12:46:31.000000000 +0200
@@ -73,6 +73,10 @@ cond_syscall(compat_sys_mq_timedsend);
cond_syscall(compat_sys_mq_timedreceive);
cond_syscall(compat_sys_mq_notify);
cond_syscall(compat_sys_mq_getsetattr);
+cond_syscall(sys_vperfctr_open);
+cond_syscall(sys_vperfctr_control);
+cond_syscall(sys_vperfctr_write);
+cond_syscall(sys_vperfctr_read);
cond_syscall(sys_mbind);
cond_syscall(sys_get_mempolicy);
cond_syscall(sys_set_mempolicy);
diff -rupN linux-2.6.22/kernel/timer.c linux-2.6.22.perfctr27/kernel/timer.c
--- linux-2.6.22/kernel/timer.c 2007-07-09 22:01:37.000000000 +0200
+++ linux-2.6.22.perfctr27/kernel/timer.c 2007-09-28 12:46:31.000000000 +0200
@@ -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>
#include <linux/tick.h>
@@ -816,6 +817,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();
if (rcu_pending(cpu))
rcu_check_callbacks(cpu, user_tick);