summaryrefslogtreecommitdiffstats
path: root/kernel/perf_counter.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-12-14 14:44:31 +0100
committerIngo Molnar <mingo@elte.hu>2008-12-14 20:31:27 +0100
commite06c61a879910869aa5bf3f8f634abfee1a7bebc (patch)
tree30add308b26946b618bb0e2d711c2b1c27f58714 /kernel/perf_counter.c
parentperfcounters: add task migrations counter (diff)
downloadlinux-e06c61a879910869aa5bf3f8f634abfee1a7bebc.tar.xz
linux-e06c61a879910869aa5bf3f8f634abfee1a7bebc.zip
perfcounters: add nr-of-faults counter
Impact: add new feature, new sw counter Add a counter that counts the number of pagefaults a task is experiencing. Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to '')
-rw-r--r--kernel/perf_counter.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index fb11e351e44e..59c52f9ee431 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -888,6 +888,54 @@ static const struct hw_perf_counter_ops perf_ops_task_clock = {
.hw_perf_counter_read = task_clock_perf_counter_read,
};
+static u64 get_page_faults(void)
+{
+ struct task_struct *curr = current;
+
+ return curr->maj_flt + curr->min_flt;
+}
+
+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();
+
+ atomic64_set(&counter->hw.prev_count, now);
+
+ delta = now - prev;
+ if (WARN_ON_ONCE(delta < 0))
+ delta = 0;
+
+ atomic64_add(delta, &counter->count);
+}
+
+static void page_faults_perf_counter_read(struct perf_counter *counter)
+{
+ page_faults_perf_counter_update(counter);
+}
+
+static void page_faults_perf_counter_enable(struct perf_counter *counter)
+{
+ /*
+ * page-faults is a per-task value already,
+ * so we dont have to clear it on switch-in.
+ */
+}
+
+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 = {
+ .hw_perf_counter_enable = page_faults_perf_counter_enable,
+ .hw_perf_counter_disable = page_faults_perf_counter_disable,
+ .hw_perf_counter_read = page_faults_perf_counter_read,
+};
+
static u64 get_context_switches(void)
{
struct task_struct *curr = current;
@@ -994,6 +1042,9 @@ sw_perf_counter_init(struct perf_counter *counter)
case PERF_COUNT_TASK_CLOCK:
hw_ops = &perf_ops_task_clock;
break;
+ case PERF_COUNT_PAGE_FAULTS:
+ hw_ops = &perf_ops_page_faults;
+ break;
case PERF_COUNT_CONTEXT_SWITCHES:
hw_ops = &perf_ops_context_switches;
break;