summaryrefslogtreecommitdiffstats
path: root/kernel/perf_counter.c
diff options
context:
space:
mode:
authorIngo Molnar2008-12-11 14:03:20 +0100
committerIngo Molnar2008-12-11 15:45:54 +0100
commitbae43c9945ebeef15e7952e317efb02393d3bfc7 (patch)
tree78d12a494fa9c3f73e76e8d7895ceb94d48d517d /kernel/perf_counter.c
parentperf counters: consolidate hw_perf save/restore APIs (diff)
downloadkernel-qcow2-linux-bae43c9945ebeef15e7952e317efb02393d3bfc7.tar.gz
kernel-qcow2-linux-bae43c9945ebeef15e7952e317efb02393d3bfc7.tar.xz
kernel-qcow2-linux-bae43c9945ebeef15e7952e317efb02393d3bfc7.zip
perf counters: implement PERF_COUNT_TASK_CLOCK
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>
Diffstat (limited to 'kernel/perf_counter.c')
-rw-r--r--kernel/perf_counter.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 0e93fea17120..a0fe8474ee29 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -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;
}