aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-12-11 08:03:20 -0500
committerIngo Molnar <mingo@elte.hu>2008-12-11 09:45:54 -0500
commitbae43c9945ebeef15e7952e317efb02393d3bfc7 (patch)
tree78d12a494fa9c3f73e76e8d7895ceb94d48d517d
parent01b2838c4298c5e0d30b4993c195ac34dd9df61e (diff)
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>
-rw-r--r--include/linux/perf_counter.h7
-rw-r--r--kernel/perf_counter.c22
2 files changed, 27 insertions, 2 deletions
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index 68f6e3ad531f..30c0ec8c1ee3 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -50,8 +50,11 @@ enum hw_event_types {
50 */ 50 */
51 PERF_COUNT_CPU_CLOCK = -1, 51 PERF_COUNT_CPU_CLOCK = -1,
52 PERF_COUNT_TASK_CLOCK = -2, 52 PERF_COUNT_TASK_CLOCK = -2,
53 PERF_COUNT_PAGE_FAULTS = -3, 53 /*
54 PERF_COUNT_CONTEXT_SWITCHES = -4, 54 * Future software events:
55 */
56 /* PERF_COUNT_PAGE_FAULTS = -3,
57 PERF_COUNT_CONTEXT_SWITCHES = -4, */
55}; 58};
56 59
57/* 60/*
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 = {
855 .hw_perf_counter_read = cpu_clock_perf_counter_read, 855 .hw_perf_counter_read = cpu_clock_perf_counter_read,
856}; 856};
857 857
858static void task_clock_perf_counter_enable(struct perf_counter *counter)
859{
860}
861
862static void task_clock_perf_counter_disable(struct perf_counter *counter)
863{
864}
865
866static void task_clock_perf_counter_read(struct perf_counter *counter)
867{
868 atomic64_counter_set(counter, current->se.sum_exec_runtime);
869}
870
871static const struct hw_perf_counter_ops perf_ops_task_clock = {
872 .hw_perf_counter_enable = task_clock_perf_counter_enable,
873 .hw_perf_counter_disable = task_clock_perf_counter_disable,
874 .hw_perf_counter_read = task_clock_perf_counter_read,
875};
876
858static const struct hw_perf_counter_ops * 877static const struct hw_perf_counter_ops *
859sw_perf_counter_init(struct perf_counter *counter) 878sw_perf_counter_init(struct perf_counter *counter)
860{ 879{
@@ -864,6 +883,9 @@ sw_perf_counter_init(struct perf_counter *counter)
864 case PERF_COUNT_CPU_CLOCK: 883 case PERF_COUNT_CPU_CLOCK:
865 hw_ops = &perf_ops_cpu_clock; 884 hw_ops = &perf_ops_cpu_clock;
866 break; 885 break;
886 case PERF_COUNT_TASK_CLOCK:
887 hw_ops = &perf_ops_task_clock;
888 break;
867 default: 889 default:
868 break; 890 break;
869 } 891 }