perf_counter: provide pagefault software events
authorPeter Zijlstra <a.p.zijlstra@chello.nl>
Fri, 13 Mar 2009 11:21:33 +0000 (12:21 +0100)
committerIngo Molnar <mingo@elte.hu>
Mon, 6 Apr 2009 07:29:37 +0000 (09:29 +0200)
We use the generic software counter infrastructure to provide
page fault events.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/powerpc/mm/fault.c
arch/x86/mm/fault.c
kernel/perf_counter.c

index 76993941cac95a12f7c95972eb55f9e0b00fe769..eda5b0ca4af26f5090111215c9a8f11f81d1c801 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/module.h>
 #include <linux/kprobes.h>
 #include <linux/kdebug.h>
+#include <linux/perf_counter.h>
 
 #include <asm/firmware.h>
 #include <asm/page.h>
@@ -170,6 +171,8 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
                die("Weird page fault", regs, SIGSEGV);
        }
 
+       perf_swcounter_event(PERF_COUNT_PAGE_FAULTS, 1, 0, regs);
+
        /* When running in the kernel we expect faults to occur only to
         * addresses in user space.  All other faults represent errors in the
         * kernel and should generate an OOPS.  Unfortunately, in the case of an
index a03b7279efa018850def9042339fec4af4249042..c8725752b6cdb6df9bb33b3ecfa95e7150d2f23c 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/tty.h>
 #include <linux/smp.h>
 #include <linux/mm.h>
+#include <linux/perf_counter.h>
 
 #include <asm-generic/sections.h>
 
@@ -1044,6 +1045,8 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
        if (unlikely(error_code & PF_RSVD))
                pgtable_bad(regs, error_code, address);
 
+       perf_swcounter_event(PERF_COUNT_PAGE_FAULTS, 1, 0, regs);
+
        /*
         * If we're in an interrupt, have no user context or are running
         * in an atomic region then we must not take the fault:
index eeb1b46cf707016cf3fa466e895bc8677f591616..1773c5d7427dc9e9d57eded65ee3f8b4cf9a4134 100644 (file)
@@ -1607,57 +1607,10 @@ static const struct hw_perf_counter_ops perf_ops_task_clock = {
  * Software counter: page faults
  */
 
-#ifdef CONFIG_VM_EVENT_COUNTERS
-#define cpu_page_faults()      __get_cpu_var(vm_event_states).event[PGFAULT]
-#else
-#define cpu_page_faults()      0
-#endif
-
-static u64 get_page_faults(struct perf_counter *counter)
-{
-       struct task_struct *curr = counter->ctx->task;
-
-       if (curr)
-               return curr->maj_flt + curr->min_flt;
-       return cpu_page_faults();
-}
-
-static void page_faults_perf_counter_update(struct perf_counter *counter)
-{
-       u64 prev, now;
-       s64 delta;
-
-       prev = atomic64_read(&counter->hw.prev_count);
-       now = get_page_faults(counter);
-
-       atomic64_set(&counter->hw.prev_count, now);
-
-       delta = now - prev;
-
-       atomic64_add(delta, &counter->count);
-}
-
-static void page_faults_perf_counter_read(struct perf_counter *counter)
-{
-       page_faults_perf_counter_update(counter);
-}
-
-static int page_faults_perf_counter_enable(struct perf_counter *counter)
-{
-       if (counter->prev_state <= PERF_COUNTER_STATE_OFF)
-               atomic64_set(&counter->hw.prev_count, get_page_faults(counter));
-       return 0;
-}
-
-static void page_faults_perf_counter_disable(struct perf_counter *counter)
-{
-       page_faults_perf_counter_update(counter);
-}
-
 static const struct hw_perf_counter_ops perf_ops_page_faults = {
-       .enable         = page_faults_perf_counter_enable,
-       .disable        = page_faults_perf_counter_disable,
-       .read           = page_faults_perf_counter_read,
+       .enable         = perf_swcounter_enable,
+       .disable        = perf_swcounter_disable,
+       .read           = perf_swcounter_read,
 };
 
 /*