Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #undef TRACE_SYSTEM |
| 14 | #define TRACE_SYSTEM perf_trace_counters |
| 15 | |
| 16 | #if !defined(_PERF_TRACE_COUNTERS_H_) || defined(TRACE_HEADER_MULTI_READ) |
| 17 | #define _PERF_TRACE_COUNTERS_H_ |
| 18 | |
| 19 | /* Ctr index for PMCNTENSET/CLR */ |
| 20 | #define CC 0x80000000 |
| 21 | #define C0 0x1 |
| 22 | #define C1 0x10 |
| 23 | #define C2 0x100 |
| 24 | #define C3 0x1000 |
| 25 | |
| 26 | |
| 27 | #include <linux/sched.h> |
| 28 | #include <linux/tracepoint.h> |
| 29 | |
| 30 | TRACE_EVENT(sched_switch_with_ctrs, |
| 31 | |
| 32 | TP_PROTO(pid_t prev, pid_t next), |
| 33 | |
| 34 | TP_ARGS(prev, next), |
| 35 | |
| 36 | TP_STRUCT__entry( |
| 37 | __field(pid_t, old_pid) |
| 38 | __field(pid_t, new_pid) |
| 39 | __field(u32, cctr) |
| 40 | __field(u32, ctr0) |
| 41 | __field(u32, ctr1) |
| 42 | __field(u32, ctr2) |
| 43 | __field(u32, ctr3) |
| 44 | ), |
| 45 | |
| 46 | TP_fast_assign( |
| 47 | __entry->old_pid = prev; |
| 48 | __entry->new_pid = next; |
| 49 | |
| 50 | /* cycle counter */ |
| 51 | /* Disable */ |
| 52 | asm volatile("mcr p15, 0, %0, c9, c12, 2" : : "r"(CC)); |
| 53 | /* Read value */ |
| 54 | asm volatile("mrc p15, 0, %0, c9, c13, 0" |
| 55 | : "=r"(__entry->cctr)); |
| 56 | /* Reset */ |
| 57 | asm volatile("mcr p15, 0, %0, c9, c13, 0" : : "r"(0)); |
| 58 | /* Enable */ |
| 59 | asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r"(CC)); |
| 60 | |
| 61 | /* ctr 0 */ |
| 62 | /* Disable */ |
| 63 | asm volatile("mcr p15, 0, %0, c9, c12, 2" : : "r"(C0)); |
| 64 | /* Select */ |
| 65 | asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r"(0)); |
| 66 | /* Read value */ |
| 67 | asm volatile("mrc p15, 0, %0, c9, c13, 2" |
| 68 | : "=r"(__entry->ctr0)); |
| 69 | /* Reset */ |
| 70 | asm volatile("mcr p15, 0, %0, c9, c13, 2" : : "r"(0)); |
| 71 | /* Enable */ |
| 72 | asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r"(C0)); |
| 73 | |
| 74 | /* ctr 1 */ |
| 75 | /* Disable */ |
| 76 | asm volatile("mcr p15, 0, %0, c9, c12, 2" : : "r"(C1)); |
| 77 | /* Select */ |
| 78 | asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r"(1)); |
| 79 | /* Read value */ |
| 80 | asm volatile("mrc p15, 0, %0, c9, c13, 2" |
| 81 | : "=r"(__entry->ctr1)); |
| 82 | /* Reset */ |
| 83 | asm volatile("mcr p15, 0, %0, c9, c13, 2" : : "r"(0)); |
| 84 | /* Enable */ |
| 85 | asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r"(C1)); |
| 86 | |
| 87 | /* ctr 2 */ |
| 88 | /* Disable */ |
| 89 | asm volatile("mcr p15, 0, %0, c9, c12, 2" : : "r"(C2)); |
| 90 | /* Select */ |
| 91 | asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r"(2)); |
| 92 | /* Read value */ |
| 93 | asm volatile("mrc p15, 0, %0, c9, c13, 2" |
| 94 | : "=r"(__entry->ctr2)); |
| 95 | /* Reset */ |
| 96 | asm volatile("mcr p15, 0, %0, c9, c13, 2" : : "r"(0)); |
| 97 | /* Enable */ |
| 98 | asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r"(C2)); |
| 99 | |
| 100 | /* ctr 3 */ |
| 101 | /* Disable */ |
| 102 | asm volatile("mcr p15, 0, %0, c9, c12, 2" : : "r"(C3)); |
| 103 | /* Select */ |
| 104 | asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r"(3)); |
| 105 | /* Read value */ |
| 106 | asm volatile("mrc p15, 0, %0, c9, c13, 2" |
| 107 | : "=r"(__entry->ctr3)); |
| 108 | /* Reset */ |
| 109 | asm volatile("mcr p15, 0, %0, c9, c13, 2" : : "r"(0)); |
| 110 | /* Enable */ |
| 111 | asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r"(C3)); |
| 112 | |
| 113 | ), |
| 114 | |
| 115 | TP_printk("prev_pid=%d, next_pid=%d, CCNTR: %u, CTR0: %u," \ |
| 116 | " CTR1: %u, CTR2: %u, CTR3: %u", |
| 117 | __entry->old_pid, __entry->new_pid, |
| 118 | __entry->cctr, __entry->ctr0, __entry->ctr1, |
| 119 | __entry->ctr2, __entry->ctr3) |
| 120 | ); |
| 121 | |
| 122 | #endif |
| 123 | #undef TRACE_INCLUDE_PATH |
| 124 | #define TRACE_INCLUDE_PATH . |
| 125 | #define TRACE_INCLUDE_FILE perf_trace_counters |
| 126 | #include <trace/define_trace.h> |
| 127 | |