blob: fce176e72b44da0497e4cdfe56f4f76d2cf0dfdb [file] [log] [blame]
Ashwin Chaugule4eaee1a2013-03-14 18:37:49 -04001/* 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 Sahasrabudhe1b3051e2013-07-23 10:54:06 -040022#define C1 0x2
23#define C2 0x4
24#define C3 0x8
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -040025#define C_ALL (CC | C0 | C1 | C2 | C3)
26#define NUM_L1_CTRS 4
27#define NUM_L2_PERCPU 2
Ashwin Chaugule4eaee1a2013-03-14 18:37:49 -040028
29#include <linux/sched.h>
Sheetal Sahasrabudhe1b3051e2013-07-23 10:54:06 -040030#include <linux/cpumask.h>
Ashwin Chaugule4eaee1a2013-03-14 18:37:49 -040031#include <linux/tracepoint.h>
Sheetal Sahasrabudhe1b3051e2013-07-23 10:54:06 -040032#include <mach/msm-krait-l2-accessors.h>
Ashwin Chaugule4eaee1a2013-03-14 18:37:49 -040033
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -040034DECLARE_PER_CPU(u32, previous_ccnt);
35DECLARE_PER_CPU(u32[NUM_L1_CTRS], previous_l1_cnts);
36DECLARE_PER_CPU(u32[NUM_L2_PERCPU], previous_l2_cnts);
Ashwin Chaugule4eaee1a2013-03-14 18:37:49 -040037TRACE_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 Sahasrabudhe1b3051e2013-07-23 10:54:06 -040051 __field(u32, lctr0)
52 __field(u32, lctr1)
Ashwin Chaugule4eaee1a2013-03-14 18:37:49 -040053 ),
54
55 TP_fast_assign(
Sheetal Sahasrabudhe1b3051e2013-07-23 10:54:06 -040056 u32 cpu = smp_processor_id();
57 u32 idx;
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -040058 u32 i;
Sheetal Sahasrabudhe1b3051e2013-07-23 10:54:06 -040059 u32 counter_reg;
60 u32 val;
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -040061 u32 cnten_val;
Sheetal Sahasrabudhe1b3051e2013-07-23 10:54:06 -040062 u32 num_l2ctrs;
63 u32 num_cores = nr_cpu_ids;
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -040064 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 Chaugule4eaee1a2013-03-14 18:37:49 -040068 __entry->old_pid = prev;
69 __entry->new_pid = next;
Sheetal Sahasrabudhe1b3051e2013-07-23 10:54:06 -040070
71 val = get_l2_indirect_reg(L2PMCR);
72 num_l2ctrs = ((val >> 11) & 0x1f) + 1;
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -040073
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 Sahasrabudhe1b3051e2013-07-23 10:54:06 -040078 asm volatile("mcr p15, 0, %0, c9, c12, 2"
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -040079 : : "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 Chaugule4eaee1a2013-03-14 18:37:49 -040098
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -040099 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 Sahasrabudhe1b3051e2013-07-23 10:54:06 -0400107 asm volatile("mcr p15, 0, %0, c9, c12, 1"
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -0400108 : : "r"(cnten_val));
Sheetal Sahasrabudhe1b3051e2013-07-23 10:54:06 -0400109
110 /* L2 counters */
111 /* Assign L2 counters to cores sequentially starting
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -0400112 * 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 Sahasrabudhe1b3051e2013-07-23 10:54:06 -0400141 }
Sheetal Sahasrabudhee2ec9802013-10-15 14:48:52 -0400142 __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 Chaugule4eaee1a2013-03-14 18:37:49 -0400148 ),
149
150 TP_printk("prev_pid=%d, next_pid=%d, CCNTR: %u, CTR0: %u," \
Sheetal Sahasrabudhe1b3051e2013-07-23 10:54:06 -0400151 " CTR1: %u, CTR2: %u, CTR3: %u," \
Neil Leeder3e908cd2013-12-18 13:10:04 -0500152 " L2CTR0: %u, L2CTR1: %u",
Ashwin Chaugule4eaee1a2013-03-14 18:37:49 -0400153 __entry->old_pid, __entry->new_pid,
154 __entry->cctr, __entry->ctr0, __entry->ctr1,
Sheetal Sahasrabudhe1b3051e2013-07-23 10:54:06 -0400155 __entry->ctr2, __entry->ctr3,
156 __entry->lctr0, __entry->lctr1)
Ashwin Chaugule4eaee1a2013-03-14 18:37:49 -0400157);
158
159#endif
160#undef TRACE_INCLUDE_PATH
Bryan Huntsman99f13a32013-06-03 18:48:08 -0700161#define TRACE_INCLUDE_PATH ../../arch/arm/mach-msm
Ashwin Chaugule4eaee1a2013-03-14 18:37:49 -0400162#define TRACE_INCLUDE_FILE perf_trace_counters
163#include <trace/define_trace.h>