--- linux-2.6.15.perfctr26/CREDITS.~1~ 2008-06-22 18:22:10.000000000 +0200 +++ linux-2.6.15.perfctr26/CREDITS 2008-06-22 18:25:45.000000000 +0200 @@ -2631,9 +2631,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/ D: Miscellaneous fixes +D: Performance-monitoring counters driver N: Reed H. Petty E: rhp@draper.net --- linux-2.6.15.perfctr26/Documentation/ioctl-number.txt.~1~ 2008-06-22 18:08:15.000000000 +0200 +++ linux-2.6.15.perfctr26/Documentation/ioctl-number.txt 2008-06-22 18:25:38.000000000 +0200 @@ -188,6 +188,8 @@ Code Seq# Include File Comments 0xB1 00-1F PPPoX 0xCB 00-1F CBM serial IEC bus in development: +0xD0 all performance counters see drivers/perfctr/ + 0xDD 00-3F ZFCP device driver see drivers/s390/scsi/ 0xF3 00-3F video/sisfb.h sisfb (in development) --- linux-2.6.15.perfctr26/MAINTAINERS.~1~ 2008-06-22 18:22:10.000000000 +0200 +++ linux-2.6.15.perfctr26/MAINTAINERS 2008-06-22 18:25:45.000000000 +0200 @@ -2027,6 +2027,12 @@ M: tsbogend@alpha.franken.de L: netdev@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 + PHRAM MTD DRIVER P: Jörn Engel M: joern@wh.fh-wedel.de --- linux-2.6.15.perfctr26/arch/i386/Kconfig.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/i386/Kconfig 2008-06-22 18:25:38.000000000 +0200 @@ -647,6 +647,8 @@ config SECCOMP If unsure, say Y. Only embedded should say N here. +source "drivers/perfctr/Kconfig" + source kernel/Kconfig.hz config PHYSICAL_START --- linux-2.6.15.perfctr26/arch/i386/kernel/entry.S.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/i386/kernel/entry.S 2008-06-22 18:25:38.000000000 +0200 @@ -430,6 +430,16 @@ 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) + pushl $LOCAL_PERFCTR_VECTOR-256 + SAVE_ALL + pushl %esp + call smp_perfctr_interrupt + addl $4, %esp + jmp ret_from_intr +#endif + ENTRY(divide_error) pushl $0 # no error code pushl $do_divide_error --- linux-2.6.15.perfctr26/arch/i386/kernel/i8259.c.~1~ 2008-06-22 17:55:14.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/i386/kernel/i8259.c 2008-06-22 18:25:38.000000000 +0200 @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -421,6 +422,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.15.perfctr26/arch/i386/kernel/process.c.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/i386/kernel/process.c 2008-06-22 18:25:38.000000000 +0200 @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -387,6 +388,7 @@ void exit_thread(void) tss->io_bitmap_base = INVALID_IO_BITMAP_OFFSET; put_cpu(); } + perfctr_exit_thread(&tsk->thread); } void flush_thread(void) @@ -459,6 +461,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(NULL != tsk->thread.io_bitmap_ptr)) { p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL); @@ -722,6 +726,8 @@ struct task_struct fastcall * __switch_t disable_tsc(prev_p, next_p); + perfctr_resume_thread(next); + return prev_p; } --- linux-2.6.15.perfctr26/arch/powerpc/Kconfig.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/powerpc/Kconfig 2008-06-22 18:25:38.000000000 +0200 @@ -237,6 +237,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.15.perfctr26/arch/powerpc/kernel/head_32.S.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/powerpc/kernel/head_32.S 2008-06-22 18:25:38.000000000 +0200 @@ -458,7 +458,11 @@ SystemCall: Trap_0f: EXCEPTION_PROLOG addi r3,r1,STACK_FRAME_OVERHEAD +#ifdef CONFIG_PERFCTR_INTERRUPT_SUPPORT + EXC_XFER_EE(0xf00, do_perfctr_interrupt) +#else EXC_XFER_EE(0xf00, unknown_exception) +#endif /* * Handle TLB miss for instruction on 603/603e. --- linux-2.6.15.perfctr26/arch/powerpc/kernel/process.c.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/powerpc/kernel/process.c 2008-06-22 18:25:38.000000000 +0200 @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -328,7 +329,9 @@ struct task_struct *__switch_to(struct t #endif local_irq_save(flags); + perfctr_suspend_thread(&prev->thread); last = _switch(old_thread, new_thread); + perfctr_resume_thread(¤t->thread); local_irq_restore(flags); @@ -457,6 +460,7 @@ void exit_thread(void) { kprobe_flush_task(current); discard_lazy_cpu_state(); + perfctr_exit_thread(¤t->thread); } void flush_thread(void) @@ -569,6 +573,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.15.perfctr26/arch/ppc/Kconfig.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/ppc/Kconfig 2008-06-22 18:25:38.000000000 +0200 @@ -288,6 +288,8 @@ config NOT_COHERENT_CACHE depends on 4xx || 8xx || E200 default y +source "drivers/perfctr/Kconfig" + endmenu menu "Platform options" --- linux-2.6.15.perfctr26/arch/ppc/kernel/head.S.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/ppc/kernel/head.S 2008-06-22 18:25:38.000000000 +0200 @@ -502,7 +502,11 @@ SystemCall: Trap_0f: EXCEPTION_PROLOG addi r3,r1,STACK_FRAME_OVERHEAD +#ifdef CONFIG_PERFCTR_INTERRUPT_SUPPORT + EXC_XFER_EE(0xf00, do_perfctr_interrupt) +#else EXC_XFER_EE(0xf00, unknown_exception) +#endif /* * Handle TLB miss for instruction on 603/603e. --- linux-2.6.15.perfctr26/arch/ppc/kernel/process.c.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/ppc/kernel/process.c 2008-06-22 18:25:38.000000000 +0200 @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -363,7 +364,9 @@ struct task_struct *__switch_to(struct t #endif /* CONFIG_SPE */ new_thread = &new->thread; old_thread = ¤t->thread; + perfctr_suspend_thread(&prev->thread); last = _switch(old_thread, new_thread); + perfctr_resume_thread(¤t->thread); local_irq_restore(s); return last; } @@ -426,6 +429,7 @@ void exit_thread(void) if (last_task_used_spe == current) last_task_used_spe = NULL; #endif + perfctr_exit_thread(¤t->thread); preempt_enable(); } @@ -521,6 +525,8 @@ copy_thread(int nr, unsigned long clone_ p->thread.last_syscall = -1; + perfctr_copy_task(p, regs); + return 0; } --- linux-2.6.15.perfctr26/arch/x86_64/Kconfig.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/x86_64/Kconfig 2008-06-22 18:25:38.000000000 +0200 @@ -444,6 +444,8 @@ config SECCOMP If unsure, say Y. Only embedded should say N here. +source "drivers/perfctr/Kconfig" + source kernel/Kconfig.hz endmenu --- linux-2.6.15.perfctr26/arch/x86_64/kernel/entry.S.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/x86_64/kernel/entry.S 2008-06-22 18:25:38.000000000 +0200 @@ -648,6 +648,11 @@ ENTRY(spurious_interrupt) apicinterrupt SPURIOUS_APIC_VECTOR,smp_spurious_interrupt #endif +#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_KPERFCTR) +ENTRY(perfctr_interrupt) + apicinterrupt LOCAL_PERFCTR_VECTOR,smp_perfctr_interrupt +#endif + /* * Exception entry points. */ --- linux-2.6.15.perfctr26/arch/x86_64/kernel/i8259.c.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/x86_64/kernel/i8259.c 2008-06-22 18:25:38.000000000 +0200 @@ -23,6 +23,7 @@ #include #include #include +#include /* * Common place to define all x86 IRQ vectors @@ -592,6 +593,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.15.perfctr26/arch/x86_64/kernel/process.c.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/arch/x86_64/kernel/process.c 2008-06-22 18:25:38.000000000 +0200 @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -344,6 +345,7 @@ void exit_thread(void) t->io_bitmap_max = 0; put_cpu(); } + perfctr_exit_thread(&me->thread); } void flush_thread(void) @@ -445,6 +447,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) { @@ -597,6 +601,8 @@ __switch_to(struct task_struct *prev_p, } } + perfctr_resume_thread(next); + return prev_p; } --- linux-2.6.15.perfctr26/drivers/Makefile.~1~ 2008-06-22 18:22:11.000000000 +0200 +++ linux-2.6.15.perfctr26/drivers/Makefile 2008-06-22 18:25:38.000000000 +0200 @@ -67,6 +67,7 @@ obj-$(CONFIG_CPU_FREQ) += cpufreq/ obj-$(CONFIG_MMC) += mmc/ obj-$(CONFIG_INFINIBAND) += infiniband/ obj-$(CONFIG_SGI_IOC4) += sn/ +obj-$(CONFIG_KPERFCTR) += perfctr/ obj-y += firmware/ obj-$(CONFIG_CRYPTO) += crypto/ obj-$(CONFIG_SUPERH) += sh/ --- linux-2.6.15.perfctr26/fs/exec.c.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/fs/exec.c 2008-06-22 18:25:45.000000000 +0200 @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -883,6 +884,7 @@ int flush_old_exec(struct linux_binprm * set_task_comm(current, tcomm); current->flags &= ~PF_RANDOMIZE; + perfctr_flush_thread(¤t->thread); flush_thread(); if (bprm->e_uid != current->euid || bprm->e_gid != current->egid || --- linux-2.6.15.perfctr26/include/asm-i386/mach-default/irq_vectors.h.~1~ 2008-06-22 15:56:54.000000000 +0200 +++ linux-2.6.15.perfctr26/include/asm-i386/mach-default/irq_vectors.h 2008-06-22 18:25:38.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 --- linux-2.6.15.perfctr26/include/asm-i386/mach-visws/irq_vectors.h.~1~ 2008-06-22 15:56:54.000000000 +0200 +++ linux-2.6.15.perfctr26/include/asm-i386/mach-visws/irq_vectors.h 2008-06-22 18:25:38.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 --- linux-2.6.15.perfctr26/include/asm-i386/processor.h.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/include/asm-i386/processor.h 2008-06-22 18:25:38.000000000 +0200 @@ -460,6 +460,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.15.perfctr26/include/asm-i386/system.h.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/include/asm-i386/system.h 2008-06-22 18:25:38.000000000 +0200 @@ -14,6 +14,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("pushl %%ebp\n\t" \ "movl %%esp,%0\n\t" /* save ESP */ \ "movl %5,%%esp\n\t" /* restore ESP */ \ --- linux-2.6.15.perfctr26/include/asm-powerpc/processor.h.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/include/asm-powerpc/processor.h 2008-06-22 18:25:38.000000000 +0200 @@ -194,6 +194,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.15.perfctr26/include/asm-x86_64/hw_irq.h.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/include/asm-x86_64/hw_irq.h 2008-06-22 18:25:38.000000000 +0200 @@ -67,14 +67,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.15.perfctr26/include/asm-x86_64/irq.h.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/include/asm-x86_64/irq.h 2008-06-22 18:25:38.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 */ #ifdef CONFIG_PCI_MSI #define NR_IRQS FIRST_SYSTEM_VECTOR --- linux-2.6.15.perfctr26/include/asm-x86_64/processor.h.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/include/asm-x86_64/processor.h 2008-06-22 18:25:38.000000000 +0200 @@ -254,6 +254,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.15.perfctr26/include/asm-x86_64/system.h.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/include/asm-x86_64/system.h 2008-06-22 18:25:38.000000000 +0200 @@ -26,7 +26,8 @@ #define __EXTRA_CLOBBER \ ,"rcx","rbx","rdx","r8","r9","r10","r11","r12","r13","r14","r15" -#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 */ \ @@ -46,7 +47,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.15.perfctr26/kernel/exit.c.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/kernel/exit.c 2008-06-22 18:25:38.000000000 +0200 @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -101,6 +102,7 @@ repeat: zap_leader = (leader->exit_signal == -1); } + perfctr_release_task(p); sched_exit(p); write_unlock_irq(&tasklist_lock); spin_unlock(&p->proc_lock); --- linux-2.6.15.perfctr26/kernel/sched.c.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/kernel/sched.c 2008-06-22 18:25:38.000000000 +0200 @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -4458,6 +4459,8 @@ int set_cpus_allowed(task_t *p, cpumask_ migration_req_t req; runqueue_t *rq; + 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.15.perfctr26/kernel/timer.c.~1~ 2008-06-22 18:22:12.000000000 +0200 +++ linux-2.6.15.perfctr26/kernel/timer.c 2008-06-22 18:25:38.000000000 +0200 @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -791,6 +792,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);