kernprof
[Top] [All Lists]

[patch 2.5.25] NMI patch for kernprof

To: lse <lse-tech@xxxxxxxxxxxxxxxxxxxxx>
Subject: [patch 2.5.25] NMI patch for kernprof
From: Ravikiran G Thirumalai <kiran@xxxxxxxxxx>
Date: Fri, 26 Jul 2002 16:13:42 +0530
Cc: kernprof <kernprof@xxxxxxxxxxx>
Sender: owner-kernprof@xxxxxxxxxxx
User-agent: Mutt/1.2.5i
Following  patch works on top of Adam Litke's  2.5.25 Kernprof profiler 
available on lse.  This patch modifies the PMC event generated
interupts to be delivered in NMI mode.  This works just like
oprofile (oprofile uses PMCs for profiling too).  With this patch
and PMC domain profiling, Profilng is done from the NMI handler and not
from the timer interrupt.  

Eg Usage:

1. kernprof -b -c all -d pmc -a 0x0020079 -f 8000 
  - To start profiling (in NMI mode with CPU_CLKS_UNHALTED event) 
    the -f 8000 argument implies 8000 CPU_CLKS_UNHALTED event
    cause a profiling interrupt. i.e one profiling interrupt every 10 us
    on a 800MHz machine. (Event shown is for P6 family) 

2. kernprof -i -m /boot/System.map for reporting as usual
        
I made this for my use. But just in case anybody needs to use this.....
Comments/flames welcome.

Thanks,
-Kiran


diff -ruN -X dontdiff linux-2.5.25/arch/i386/Config.help 
profile-2.5.25/arch/i386/Config.help
--- linux-2.5.25/arch/i386/Config.help  Wed Jul 24 13:11:19 2002
+++ profile-2.5.25/arch/i386/Config.help        Wed Jul 24 13:03:55 2002
@@ -950,6 +950,12 @@
   The module will be called profile.o. If you want to compile it as a
   module, say M here and read Documentation/modules.txt.
 
+CONFIG_NMI_PROFILING
+  Saying Y here will set the interrupt delivery mode for PMC domain
+  profiling to NMI. This is useful if you want to profile kernel code
+  paths which mask interrputs (eg. code between spin_lock_irq and
+  spin_unlock_irq).
+
 CONFIG_MCOUNT
   This will instrument the kernel with calls to mcount(), which enables 
   call-graph and call-count profiling.  Because mcount() is called at 
diff -ruN -X dontdiff linux-2.5.25/arch/i386/config.in 
profile-2.5.25/arch/i386/config.in
--- linux-2.5.25/arch/i386/config.in    Wed Jul 24 13:11:19 2002
+++ profile-2.5.25/arch/i386/config.in  Wed Jul 24 13:03:55 2002
@@ -424,6 +424,7 @@
 tristate 'Kernel Profiling Support' CONFIG_PROFILING
 if [ "$CONFIG_PROFILING" != "n" ]; then
    define_bool CONFIG_FRAME_POINTER y
+   bool '  Use NMI delivery for PMC events profiling' CONFIG_NMI_PROFILING
 fi
 bool 'Instrument kernel at entry to all C functions' CONFIG_MCOUNT
 if [ "$CONFIG_MCOUNT" = "y" ]; then
diff -ruN -X dontdiff linux-2.5.25/arch/i386/kernel/apic.c 
profile-2.5.25/arch/i386/kernel/apic.c
--- linux-2.5.25/arch/i386/kernel/apic.c        Wed Jul 24 13:11:19 2002
+++ profile-2.5.25/arch/i386/kernel/apic.c      Wed Jul 24 13:03:55 2002
@@ -30,6 +30,7 @@
 #include <asm/mtrr.h>
 #include <asm/mpspec.h>
 #include <asm/pgalloc.h>
+#include <asm/profile.h>
 
 /* Using APIC to generate smp_local_timer_interrupt? */
 int using_apic_timer = 0;
@@ -984,7 +985,7 @@
 void __init setup_APIC_perfctr_vector(void *unused)
 {
        (void) apic_read(APIC_LVTPC);
-       apic_write(APIC_LVTPC, PERFCTR_OVFL_VECTOR);
+       apic_write(APIC_LVTPC, PERFCTR_OVFL_VECTOR_MODE);
 }
  
 void __init setup_APIC_perfctr(void)
diff -ruN -X dontdiff linux-2.5.25/arch/i386/kernel/traps.c 
profile-2.5.25/arch/i386/kernel/traps.c
--- linux-2.5.25/arch/i386/kernel/traps.c       Sat Jul  6 05:12:14 2002
+++ profile-2.5.25/arch/i386/kernel/traps.c     Wed Jul 24 13:03:55 2002
@@ -491,6 +491,10 @@
                        return;
                }
 #endif
+#if    CONFIG_NMI_PROFILING
+               smp_apic_perfctr_overflow_interrupt(*regs);
+               return;
+#endif
                unknown_nmi_error(reason, regs);
                return;
        }
diff -ruN -X dontdiff linux-2.5.25/include/asm-i386/profile.h 
profile-2.5.25/include/asm-i386/profile.h
--- linux-2.5.25/include/asm-i386/profile.h     Wed Jul 24 13:11:19 2002
+++ profile-2.5.25/include/asm-i386/profile.h   Wed Jul 24 13:03:55 2002
@@ -137,6 +137,12 @@
        wrmsr(MSR_P6_EVNTSEL1, 0, 0);
        wrmsr(MSR_P6_EVNTSEL0, EVENTSEL0_ENABLE_MASK | (evt), 0);
 }
+#ifdef CONFIG_NMI_PROFILING
+#define PERFCTR_OVFL_VECTOR_MODE                                        \
+        SET_APIC_DELIVERY_MODE(PERFCTR_OVFL_VECTOR, APIC_MODE_NMI)
+#else
+#define PERFCTR_OVFL_VECTOR_MODE        PERFCTR_OVFL_VECTOR
+#endif
 #else
 #define have_perfctr()         0
 #define valid_perfctr_event(e) 0

<Prev in Thread] Current Thread [Next in Thread>
  • [patch 2.5.25] NMI patch for kernprof, Ravikiran G Thirumalai <=