56 #include <linux/export.h>
57 #include <linux/sched.h>
58 #include <linux/list.h>
64 static struct latency_record latency_record[
MAXLR];
76 memset(&p->latency_record, 0,
sizeof(p->latency_record));
77 p->latency_record_count = 0;
81 static void clear_global_latency_tracing(
void)
86 memset(&latency_record, 0,
sizeof(latency_record));
91 account_global_scheduler_latency(
struct task_struct *tsk,
struct latency_record *lat)
93 int firstnonnull =
MAXLR + 1;
103 for (i = 0; i <
MAXLR; i++) {
107 if (!latency_record[i].backtrace[0]) {
108 if (firstnonnull > i)
112 for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
113 unsigned long record = lat->backtrace[
q];
115 if (latency_record[i].backtrace[q] != record) {
125 latency_record[
i].count++;
126 latency_record[
i].time += lat->time;
127 if (lat->time > latency_record[i].max)
128 latency_record[
i].max = lat->time;
138 memcpy(&latency_record[i], lat,
sizeof(
struct latency_record));
144 static inline void store_stacktrace(
struct task_struct *tsk,
145 struct latency_record *lat)
147 struct stack_trace
trace;
150 trace.max_entries = LT_BACKTRACEDEPTH;
151 trace.entries = &lat->backtrace[0];
176 struct latency_record lat;
179 if (inter && usecs > 5000)
187 memset(&lat, 0,
sizeof(lat));
191 store_stacktrace(tsk, &lat);
195 account_global_scheduler_latency(tsk, &lat);
197 for (i = 0; i < tsk->latency_record_count; i++) {
198 struct latency_record *mylat;
201 mylat = &tsk->latency_record[
i];
202 for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
203 unsigned long record = lat.backtrace[
q];
205 if (mylat->backtrace[q] != record) {
216 mylat->time += lat.time;
217 if (lat.time > mylat->max)
218 mylat->max = lat.time;
226 if (tsk->latency_record_count >= LT_SAVECOUNT)
230 i = tsk->latency_record_count++;
231 memcpy(&tsk->latency_record[i], &lat,
sizeof(
struct latency_record));
237 static int lstats_show(
struct seq_file *
m,
void *
v)
241 seq_puts(m,
"Latency Top version : v0.1\n");
243 for (i = 0; i <
MAXLR; i++) {
244 struct latency_record *
lr = &latency_record[
i];
246 if (lr->backtrace[0]) {
249 lr->
count, lr->time, lr->max);
250 for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
251 unsigned long bt = lr->backtrace[
q];
268 clear_global_latency_tracing();
281 .write = lstats_write,
286 static int __init init_lstats_procfs(
void)
288 proc_create(
"latency_stats", 0644,
NULL, &lstats_fops);