perf counters: implement PERF_COUNT_TASK_CLOCK
authorIngo Molnar <mingo@elte.hu>
Thu, 11 Dec 2008 13:03:20 +0000 (14:03 +0100)
committerIngo Molnar <mingo@elte.hu>
Thu, 11 Dec 2008 14:45:54 +0000 (15:45 +0100)
Impact: add new perf-counter type

The 'task clock' counter counts the amount of time a task is executing,
in nanoseconds. It stops ticking when a task is scheduled out either due
to it blocking, sleeping or it being preempted.

This counter type is a Linux kernel based abstraction, it is available
even if the hardware does not support native hardware performance counters.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/linux/perf_counter.h
kernel/perf_counter.c

index 68f6e3ad531fb55a488106b645a6f364475399c0..30c0ec8c1ee353f281ecce8b8b1ac1d9e1f1dbe8 100644 (file)
@@ -50,8 +50,11 @@ enum hw_event_types {
         */
        PERF_COUNT_CPU_CLOCK            = -1,
        PERF_COUNT_TASK_CLOCK           = -2,
-       PERF_COUNT_PAGE_FAULTS          = -3,
-       PERF_COUNT_CONTEXT_SWITCHES     = -4,
+       /*
+        * Future software events:
+        */
+       /* PERF_COUNT_PAGE_FAULTS       = -3,
+          PERF_COUNT_CONTEXT_SWITCHES  = -4, */
 };
 
 /*
index 0e93fea17120c0a2b98da8dca8be4eba9c9ee7dc..a0fe8474ee29709d831fc4fb577efc3b7e7fe91b 100644 (file)
@@ -855,6 +855,25 @@ static const struct hw_perf_counter_ops perf_ops_cpu_clock = {
        .hw_perf_counter_read           = cpu_clock_perf_counter_read,
 };
 
+static void task_clock_perf_counter_enable(struct perf_counter *counter)
+{
+}
+
+static void task_clock_perf_counter_disable(struct perf_counter *counter)
+{
+}
+
+static void task_clock_perf_counter_read(struct perf_counter *counter)
+{
+       atomic64_counter_set(counter, current->se.sum_exec_runtime);
+}
+
+static const struct hw_perf_counter_ops perf_ops_task_clock = {
+       .hw_perf_counter_enable         = task_clock_perf_counter_enable,
+       .hw_perf_counter_disable        = task_clock_perf_counter_disable,
+       .hw_perf_counter_read           = task_clock_perf_counter_read,
+};
+
 static const struct hw_perf_counter_ops *
 sw_perf_counter_init(struct perf_counter *counter)
 {
@@ -864,6 +883,9 @@ sw_perf_counter_init(struct perf_counter *counter)
        case PERF_COUNT_CPU_CLOCK:
                hw_ops = &perf_ops_cpu_clock;
                break;
+       case PERF_COUNT_TASK_CLOCK:
+               hw_ops = &perf_ops_task_clock;
+               break;
        default:
                break;
        }