From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: mingo@elte.hu, paulus@samba.org
Cc: linux-kernel@vger.kernel.org, Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [PATCH 2/4] perf_counter: provide pagefault software events
Date: Tue, 10 Mar 2009 15:19:15 +0100 [thread overview]
Message-ID: <20090310142015.761644317@chello.nl> (raw)
In-Reply-To: 20090310141913.961861111@chello.nl
[-- Attachment #1: perf_swcounter_pgfault.patch --]
[-- Type: text/plain, Size: 3515 bytes --]
We use the generic software counter infrastructure to provide page fault
events.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
arch/powerpc/mm/fault.c | 3 ++
arch/x86/mm/fault.c | 3 ++
kernel/perf_counter.c | 53 ++----------------------------------------------
3 files changed, 9 insertions(+), 50 deletions(-)
Index: linux-2.6/kernel/perf_counter.c
===================================================================
--- linux-2.6.orig/kernel/perf_counter.c
+++ linux-2.6/kernel/perf_counter.c
@@ -1601,57 +1601,10 @@ static const struct hw_perf_counter_ops
* 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,
};
/*
Index: linux-2.6/arch/powerpc/mm/fault.c
===================================================================
--- linux-2.6.orig/arch/powerpc/mm/fault.c
+++ linux-2.6/arch/powerpc/mm/fault.c
@@ -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_re
die("Weird page fault", regs, SIGSEGV);
}
+ perf_swcount_event(PERF_COUNT_PAGE_FAULTS, 1, 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: linux-2.6/arch/x86/mm/fault.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/fault.c
+++ linux-2.6/arch/x86/mm/fault.c
@@ -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>
@@ -1056,6 +1057,8 @@ do_page_fault(struct pt_regs *regs, unsi
if (unlikely(error_code & PF_RSVD))
pgtable_bad(regs, error_code, address);
+ perf_swcounter_event(PERF_COUNT_PAGE_FAULTS, 1, 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:
--
next prev parent reply other threads:[~2009-03-10 14:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-10 14:19 [PATCH 0/4] generic software counters Peter Zijlstra
2009-03-10 14:19 ` [PATCH 1/4] perf_counter: software counter event infrastructure Peter Zijlstra
2009-03-10 14:19 ` Peter Zijlstra [this message]
2009-03-10 14:59 ` [PATCH 2/4] perf_counter: provide pagefault software events Ingo Molnar
2009-03-10 15:06 ` Peter Zijlstra
2009-03-10 14:19 ` [PATCH 3/4] perf_counter: x86: fix 32bit irq_period assumption Peter Zijlstra
2009-03-10 14:19 ` [PATCH 4/4] perf_counter: use list_move_tail Peter Zijlstra
2009-03-10 14:35 ` [PATCH 0/4] generic software counters Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090310142015.761644317@chello.nl \
--to=a.p.zijlstra@chello.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox