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 |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 22 | #define C1 0x2 |
| 23 | #define C2 0x4 |
| 24 | #define C3 0x8 |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 25 | #define C_ALL (CC | C0 | C1 | C2 | C3) |
| 26 | #define NUM_L1_CTRS 4 |
| 27 | #define NUM_L2_PERCPU 2 |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 28 | |
| 29 | #include <linux/sched.h> |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 30 | #include <linux/cpumask.h> |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 31 | #include <linux/tracepoint.h> |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 32 | #include <mach/msm-krait-l2-accessors.h> |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 33 | |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 34 | DECLARE_PER_CPU(u32, previous_ccnt); |
| 35 | DECLARE_PER_CPU(u32[NUM_L1_CTRS], previous_l1_cnts); |
| 36 | DECLARE_PER_CPU(u32[NUM_L2_PERCPU], previous_l2_cnts); |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 37 | TRACE_EVENT(sched_switch_with_ctrs, |
| 38 | |
| 39 | TP_PROTO(pid_t prev, pid_t next), |
| 40 | |
| 41 | TP_ARGS(prev, next), |
| 42 | |
| 43 | TP_STRUCT__entry( |
| 44 | __field(pid_t, old_pid) |
| 45 | __field(pid_t, new_pid) |
| 46 | __field(u32, cctr) |
| 47 | __field(u32, ctr0) |
| 48 | __field(u32, ctr1) |
| 49 | __field(u32, ctr2) |
| 50 | __field(u32, ctr3) |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 51 | __field(u32, lctr0) |
| 52 | __field(u32, lctr1) |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 53 | ), |
| 54 | |
| 55 | TP_fast_assign( |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 56 | u32 cpu = smp_processor_id(); |
| 57 | u32 idx; |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 58 | u32 i; |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 59 | u32 counter_reg; |
| 60 | u32 val; |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 61 | u32 cnten_val; |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 62 | u32 num_l2ctrs; |
| 63 | u32 num_cores = nr_cpu_ids; |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 64 | u32 total_ccnt = 0; |
| 65 | u32 total_cnt = 0; |
| 66 | u32 delta_l1_cnts[NUM_L1_CTRS]; |
| 67 | u32 delta_l2_cnts[NUM_L2_PERCPU]; |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 68 | __entry->old_pid = prev; |
| 69 | __entry->new_pid = next; |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 70 | |
| 71 | val = get_l2_indirect_reg(L2PMCR); |
| 72 | num_l2ctrs = ((val >> 11) & 0x1f) + 1; |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 73 | |
| 74 | /* Read PMCNTENSET */ |
| 75 | asm volatile("mrc p15, 0, %0, c9, c12, 1" |
| 76 | : "=r"(cnten_val)); |
| 77 | /* Disable all the counters that were enabled */ |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 78 | asm volatile("mcr p15, 0, %0, c9, c12, 2" |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 79 | : : "r"(cnten_val)); |
| 80 | if (cnten_val & CC) { |
| 81 | /* Read value */ |
| 82 | asm volatile("mrc p15, 0, %0, c9, c13, 0" |
| 83 | : "=r"(total_ccnt)); |
| 84 | __entry->cctr = total_ccnt - |
| 85 | per_cpu(previous_ccnt, cpu); |
| 86 | per_cpu(previous_ccnt, cpu) = total_ccnt; |
| 87 | } |
| 88 | for (i = 0; i < NUM_L1_CTRS; i++) { |
| 89 | if (cnten_val & (1 << i)) { |
| 90 | /* Select */ |
| 91 | asm volatile( |
| 92 | "mcr p15, 0, %0, c9, c12, 5" |
| 93 | : : "r"(i)); |
| 94 | /* Read value */ |
| 95 | asm volatile( |
| 96 | "mrc p15, 0, %0, c9, c13, 2" |
| 97 | : "=r"(total_cnt)); |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 98 | |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 99 | delta_l1_cnts[i] = total_cnt - |
| 100 | per_cpu(previous_l1_cnts[i], cpu); |
| 101 | per_cpu(previous_l1_cnts[i], cpu) = |
| 102 | total_cnt; |
| 103 | } else |
| 104 | delta_l1_cnts[i] = 0; |
| 105 | } |
| 106 | /* Enable all the counters that were disabled */ |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 107 | asm volatile("mcr p15, 0, %0, c9, c12, 1" |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 108 | : : "r"(cnten_val)); |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 109 | |
| 110 | /* L2 counters */ |
| 111 | /* Assign L2 counters to cores sequentially starting |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 112 | * from zero. A core could have multiple L2 counters |
| 113 | * allocated if # L2 counters is more than the # cores |
| 114 | */ |
| 115 | cnten_val = get_l2_indirect_reg(L2PMCNTENSET); |
| 116 | for (i = 0; i < NUM_L2_PERCPU; i++) { |
| 117 | idx = cpu + (num_cores * i); |
| 118 | if (idx < num_l2ctrs && |
| 119 | (cnten_val & (1 << idx))) { |
| 120 | /* Disable */ |
| 121 | set_l2_indirect_reg(L2PMCNTENCLR, |
| 122 | (1 << idx)); |
| 123 | /* L2PMEVCNTR values go from 0x421, |
| 124 | * 0x431.. |
| 125 | * So we multiply idx by 16 to get the |
| 126 | * counter reg value |
| 127 | */ |
| 128 | counter_reg = (idx * 16) + |
| 129 | IA_L2PMXEVCNTR_BASE; |
| 130 | total_cnt = |
| 131 | get_l2_indirect_reg(counter_reg); |
| 132 | /* Enable */ |
| 133 | set_l2_indirect_reg(L2PMCNTENSET, |
| 134 | (1 << idx)); |
| 135 | delta_l2_cnts[i] = total_cnt - |
| 136 | per_cpu(previous_l2_cnts[i], cpu); |
| 137 | per_cpu(previous_l2_cnts[i], cpu) = |
| 138 | total_cnt; |
| 139 | } else |
| 140 | delta_l2_cnts[i] = 0; |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 141 | } |
Sheetal Sahasrabudhe | e2ec980 | 2013-10-15 14:48:52 -0400 | [diff] [blame] | 142 | __entry->ctr0 = delta_l1_cnts[0]; |
| 143 | __entry->ctr1 = delta_l1_cnts[1]; |
| 144 | __entry->ctr2 = delta_l1_cnts[2]; |
| 145 | __entry->ctr3 = delta_l1_cnts[3]; |
| 146 | __entry->lctr0 = delta_l2_cnts[0]; |
| 147 | __entry->lctr1 = delta_l2_cnts[1]; |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 148 | ), |
| 149 | |
| 150 | TP_printk("prev_pid=%d, next_pid=%d, CCNTR: %u, CTR0: %u," \ |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 151 | " CTR1: %u, CTR2: %u, CTR3: %u," \ |
Neil Leeder | 3e908cd | 2013-12-18 13:10:04 -0500 | [diff] [blame] | 152 | " L2CTR0: %u, L2CTR1: %u", |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 153 | __entry->old_pid, __entry->new_pid, |
| 154 | __entry->cctr, __entry->ctr0, __entry->ctr1, |
Sheetal Sahasrabudhe | 1b3051e | 2013-07-23 10:54:06 -0400 | [diff] [blame] | 155 | __entry->ctr2, __entry->ctr3, |
| 156 | __entry->lctr0, __entry->lctr1) |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 157 | ); |
| 158 | |
| 159 | #endif |
| 160 | #undef TRACE_INCLUDE_PATH |
Bryan Huntsman | 99f13a3 | 2013-06-03 18:48:08 -0700 | [diff] [blame] | 161 | #define TRACE_INCLUDE_PATH ../../arch/arm/mach-msm |
Ashwin Chaugule | 4eaee1a | 2013-03-14 18:37:49 -0400 | [diff] [blame] | 162 | #define TRACE_INCLUDE_FILE perf_trace_counters |
| 163 | #include <trace/define_trace.h> |