1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
#include <linux/ring_buffer.h>
#include "kernel/trace/trace.h"
#include <linux/mtk_ftrace.h>
#ifdef CONFIG_MTK_KERNEL_MARKER
static unsigned long __read_mostly tracing_mark_write_addr = 0;
static int kernel_marker_on = 0;
static void inline update_tracing_mark_write_addr(void)
{
if (unlikely(tracing_mark_write_addr == 0))
tracing_mark_write_addr = kallsyms_lookup_name("tracing_mark_write");
}
void inline mt_kernel_trace_begin(char *name)
{
if (unlikely(kernel_marker_on) && name)
event_trace_printk(tracing_mark_write_addr, "B|%d|%s\n", current->tgid, name);
}
EXPORT_SYMBOL(mt_kernel_trace_begin);
void inline mt_kernel_trace_counter(char *name, int count)
{
if (unlikely(kernel_marker_on) && name)
event_trace_printk(tracing_mark_write_addr,
"C|%d|%s|%d\n", current->tgid, name, count);
}
EXPORT_SYMBOL(mt_kernel_trace_counter);
void inline mt_kernel_trace_end(void)
{
if (unlikely(kernel_marker_on))
event_trace_printk(tracing_mark_write_addr, "E\n");
}
EXPORT_SYMBOL(mt_kernel_trace_end);
static ssize_t
kernel_marker_on_simple_read(struct file *filp, char __user *ubuf,
size_t cnt, loff_t *ppos)
{
char buf[64];
int r;
r = sprintf(buf, "%d\n", kernel_marker_on);
return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
}
static ssize_t
kernel_marker_on_simple_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos)
{
unsigned long val;
int ret;
ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
if (ret)
return ret;
kernel_marker_on = !!val;
if (kernel_marker_on)
update_tracing_mark_write_addr();
(*ppos)++;
return cnt;
}
static const struct file_operations kernel_marker_on_simple_fops = {
.open = tracing_open_generic,
.read = kernel_marker_on_simple_read,
.write = kernel_marker_on_simple_write,
.llseek = default_llseek,
};
static __init int init_kernel_marker(void)
{
struct dentry *d_tracer;
d_tracer = tracing_init_dentry();
if (!d_tracer)
return 0;
trace_create_file("kernel_marker_on", 0644, d_tracer,
NULL, &kernel_marker_on_simple_fops);
return 0;
}
fs_initcall(init_kernel_marker);
#endif
#if defined(CONFIG_MTK_HIBERNATION) && defined(CONFIG_MTK_SCHED_TRACERS)
int resize_ring_buffer_for_hibernation(int enable)
{
int ret = 0;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
struct trace_array *tr = NULL;
#endif
if (enable) {
ring_buffer_expanded = 0;
ret = tracing_update_buffers();
} else {
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
ret = tracing_resize_ring_buffer(0, RING_BUFFER_ALL_CPUS);
#else
tr = top_trace_array();
if (tr)
ret = tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS);
#endif
}
return ret;
}
#endif
#ifdef CONFIG_MTK_SCHED_TRACERS
void print_enabled_events(struct seq_file *m)
{
struct ftrace_event_call *call;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
struct ftrace_event_file *file;
struct trace_array *tr;
#endif
seq_puts(m, "# enabled events:");
/* mutex_lock(&event_mutex); */
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
list_for_each_entry(call, &ftrace_events, list) {
if (call->flags & TRACE_EVENT_FL_ENABLED)
seq_printf(m, " %s:%s", call->class->system, call->name);
}
#else
list_for_each_entry(tr, &ftrace_trace_arrays, list) {
list_for_each_entry(file, &tr->events, list) {
call = file->event_call;
if (file->flags & FTRACE_EVENT_FL_ENABLED)
seq_printf(m, " %s:%s", call->class->system, call->name);
}
}
#endif
/* mutex_unlock(&event_mutex); */
seq_puts(m, "\n");
}
/* ftrace's switch function for MTK solution */
void mt_ftrace_enable_disable(int enable)
{
if (enable) {
trace_set_clr_event(NULL, "sched_switch", 1);
trace_set_clr_event(NULL, "sched_wakeup", 1);
trace_set_clr_event(NULL, "sched_wakeup_new", 1);
trace_set_clr_event(NULL, "softirq_entry", 1);
trace_set_clr_event(NULL, "softirq_exit", 1);
trace_set_clr_event(NULL, "softirq_raise", 1);
#ifdef CONFIG_SMP
trace_set_clr_event(NULL, "sched_migrate_task", 1);
#endif
trace_set_clr_event(NULL, "workqueue_execute_start", 1);
trace_set_clr_event(NULL, "workqueue_execute_end", 1);
trace_set_clr_event(NULL, "block_bio_frontmerge", 1);
trace_set_clr_event(NULL, "block_bio_backmerge", 1);
trace_set_clr_event(NULL, "block_rq_issue", 1);
trace_set_clr_event(NULL, "block_rq_insert", 1);
trace_set_clr_event(NULL, "block_rq_complete", 1);
trace_set_clr_event(NULL, "debug_allocate_large_pages", 1);
trace_set_clr_event(NULL, "dump_allocate_large_pages", 1);
trace_set_clr_event("mtk_events", NULL, 1);
trace_set_clr_event("ipi", NULL, 1);
trace_set_clr_event("met_bio", NULL, 1);
trace_set_clr_event("met_fuse", NULL, 1);
tracing_on();
} else {
tracing_off();
trace_set_clr_event(NULL, NULL, 0);
}
}
#endif
#if defined(CONFIG_MTK_SCHED_TRACERS) && defined(CONFIG_HOTPLUG_CPU)
#include <linux/cpu.h>
#include <trace/events/mtk_events.h>
static DEFINE_PER_CPU(unsigned long long, last_event_ts);
static struct notifier_block hotplug_event_notifier;
static int hotplug_event_notify(struct notifier_block *self,
unsigned long action, void *hcpu)
{
long cpu = (long)hcpu;
switch (action) {
case CPU_STARTING:
case CPU_STARTING_FROZEN:
trace_cpu_hotplug(cpu, 1, per_cpu(last_event_ts, cpu));
per_cpu(last_event_ts, cpu) = ns2usecs(ftrace_now(cpu));
break;
case CPU_DEAD:
case CPU_DEAD_FROZEN:
trace_cpu_hotplug(cpu, 0, per_cpu(last_event_ts, cpu));
per_cpu(last_event_ts, cpu) = ns2usecs(ftrace_now(cpu));
break;
default:
break;
}
return NOTIFY_OK;
}
static __init int hotplug_events_init(void)
{
hotplug_event_notifier.notifier_call = hotplug_event_notify;
hotplug_event_notifier.priority = 0;
register_cpu_notifier(&hotplug_event_notifier);
return 0;
}
early_initcall(hotplug_events_init);
#endif
|