aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/perf_counter.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-12-14 06:34:15 -0500
committerIngo Molnar <mingo@elte.hu>2008-12-14 14:31:26 -0500
commit6c594c21fcb02c662f11c97be4d7d2b73060a205 (patch)
treedbd56d57fbc4576e18002a5cc08b1f4327a2248f /kernel/perf_counter.c
parent5d6a27d8a096868ae313f71f563b06074a7e34fe (diff)
perfcounters: add task migrations counter
Impact: add new feature, new sw counter Add a counter that counts the number of cross-CPU migrations a task is suffering. Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/perf_counter.c')
-rw-r--r--kernel/perf_counter.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 09287091c526..fb11e351e44e 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -936,6 +936,52 @@ static const struct hw_perf_counter_ops perf_ops_context_switches = {
936 .hw_perf_counter_read = context_switches_perf_counter_read, 936 .hw_perf_counter_read = context_switches_perf_counter_read,
937}; 937};
938 938
939static inline u64 get_cpu_migrations(void)
940{
941 return current->se.nr_migrations;
942}
943
944static void cpu_migrations_perf_counter_update(struct perf_counter *counter)
945{
946 u64 prev, now;
947 s64 delta;
948
949 prev = atomic64_read(&counter->hw.prev_count);
950 now = get_cpu_migrations();
951
952 atomic64_set(&counter->hw.prev_count, now);
953
954 delta = now - prev;
955 if (WARN_ON_ONCE(delta < 0))
956 delta = 0;
957
958 atomic64_add(delta, &counter->count);
959}
960
961static void cpu_migrations_perf_counter_read(struct perf_counter *counter)
962{
963 cpu_migrations_perf_counter_update(counter);
964}
965
966static void cpu_migrations_perf_counter_enable(struct perf_counter *counter)
967{
968 /*
969 * se.nr_migrations is a per-task value already,
970 * so we dont have to clear it on switch-in.
971 */
972}
973
974static void cpu_migrations_perf_counter_disable(struct perf_counter *counter)
975{
976 cpu_migrations_perf_counter_update(counter);
977}
978
979static const struct hw_perf_counter_ops perf_ops_cpu_migrations = {
980 .hw_perf_counter_enable = cpu_migrations_perf_counter_enable,
981 .hw_perf_counter_disable = cpu_migrations_perf_counter_disable,
982 .hw_perf_counter_read = cpu_migrations_perf_counter_read,
983};
984
939static const struct hw_perf_counter_ops * 985static const struct hw_perf_counter_ops *
940sw_perf_counter_init(struct perf_counter *counter) 986sw_perf_counter_init(struct perf_counter *counter)
941{ 987{
@@ -951,6 +997,9 @@ sw_perf_counter_init(struct perf_counter *counter)
951 case PERF_COUNT_CONTEXT_SWITCHES: 997 case PERF_COUNT_CONTEXT_SWITCHES:
952 hw_ops = &perf_ops_context_switches; 998 hw_ops = &perf_ops_context_switches;
953 break; 999 break;
1000 case PERF_COUNT_CPU_MIGRATIONS:
1001 hw_ops = &perf_ops_cpu_migrations;
1002 break;
954 default: 1003 default:
955 break; 1004 break;
956 } 1005 }