Skip to content

Commit 9745512

Browse files
fenrus75Ingo Molnar
authored andcommitted
sched: latencytop support
LatencyTOP kernel infrastructure; it measures latencies in the scheduler and tracks it system wide and per process. Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 326587b commit 9745512

11 files changed

Lines changed: 429 additions & 1 deletion

File tree

‎arch/x86/kernel/stacktrace.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,33 @@ static void save_stack_address(void *data, unsigned long addr)
3333
trace->entries[trace->nr_entries++] = addr;
3434
}
3535

36+
static void save_stack_address_nosched(void *data, unsigned long addr)
37+
{
38+
struct stack_trace *trace = (struct stack_trace *)data;
39+
if (in_sched_functions(addr))
40+
return;
41+
if (trace->skip > 0) {
42+
trace->skip--;
43+
return;
44+
}
45+
if (trace->nr_entries < trace->max_entries)
46+
trace->entries[trace->nr_entries++] = addr;
47+
}
48+
3649
static const struct stacktrace_ops save_stack_ops = {
3750
.warning = save_stack_warning,
3851
.warning_symbol = save_stack_warning_symbol,
3952
.stack = save_stack_stack,
4053
.address = save_stack_address,
4154
};
4255

56+
static const struct stacktrace_ops save_stack_ops_nosched = {
57+
.warning = save_stack_warning,
58+
.warning_symbol = save_stack_warning_symbol,
59+
.stack = save_stack_stack,
60+
.address = save_stack_address_nosched,
61+
};
62+
4363
/*
4464
* Save stack-backtrace addresses into a stack_trace buffer.
4565
*/
@@ -50,3 +70,10 @@ void save_stack_trace(struct stack_trace *trace)
5070
trace->entries[trace->nr_entries++] = ULONG_MAX;
5171
}
5272
EXPORT_SYMBOL(save_stack_trace);
73+
74+
void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
75+
{
76+
dump_trace(tsk, NULL, NULL, &save_stack_ops_nosched, trace);
77+
if (trace->nr_entries < trace->max_entries)
78+
trace->entries[trace->nr_entries++] = ULONG_MAX;
79+
}

‎fs/proc/base.c‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,77 @@ static int proc_pid_schedstat(struct task_struct *task, char *buffer)
310310
}
311311
#endif
312312

313+
#ifdef CONFIG_LATENCYTOP
314+
static int lstats_show_proc(struct seq_file *m, void *v)
315+
{
316+
int i;
317+
struct task_struct *task = m->private;
318+
seq_puts(m, "Latency Top version : v0.1\n");
319+
320+
for (i = 0; i < 32; i++) {
321+
if (task->latency_record[i].backtrace[0]) {
322+
int q;
323+
seq_printf(m, "%i %li %li ",
324+
task->latency_record[i].count,
325+
task->latency_record[i].time,
326+
task->latency_record[i].max);
327+
for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
328+
char sym[KSYM_NAME_LEN];
329+
char *c;
330+
if (!task->latency_record[i].backtrace[q])
331+
break;
332+
if (task->latency_record[i].backtrace[q] == ULONG_MAX)
333+
break;
334+
sprint_symbol(sym, task->latency_record[i].backtrace[q]);
335+
c = strchr(sym, '+');
336+
if (c)
337+
*c = 0;
338+
seq_printf(m, "%s ", sym);
339+
}
340+
seq_printf(m, "\n");
341+
}
342+
343+
}
344+
return 0;
345+
}
346+
347+
static int lstats_open(struct inode *inode, struct file *file)
348+
{
349+
int ret;
350+
struct seq_file *m;
351+
struct task_struct *task = get_proc_task(inode);
352+
353+
ret = single_open(file, lstats_show_proc, NULL);
354+
if (!ret) {
355+
m = file->private_data;
356+
m->private = task;
357+
}
358+
return ret;
359+
}
360+
361+
static ssize_t lstats_write(struct file *file, const char __user *buf,
362+
size_t count, loff_t *offs)
363+
{
364+
struct seq_file *m;
365+
struct task_struct *task;
366+
367+
m = file->private_data;
368+
task = m->private;
369+
clear_all_latency_tracing(task);
370+
371+
return count;
372+
}
373+
374+
static const struct file_operations proc_lstats_operations = {
375+
.open = lstats_open,
376+
.read = seq_read,
377+
.write = lstats_write,
378+
.llseek = seq_lseek,
379+
.release = single_release,
380+
};
381+
382+
#endif
383+
313384
/* The badness from the OOM killer */
314385
unsigned long badness(struct task_struct *p, unsigned long uptime);
315386
static int proc_oom_score(struct task_struct *task, char *buffer)
@@ -1020,6 +1091,7 @@ static const struct file_operations proc_fault_inject_operations = {
10201091
};
10211092
#endif
10221093

1094+
10231095
#ifdef CONFIG_SCHED_DEBUG
10241096
/*
10251097
* Print out various scheduling related per-task fields:
@@ -2230,6 +2302,9 @@ static const struct pid_entry tgid_base_stuff[] = {
22302302
#ifdef CONFIG_SCHEDSTATS
22312303
INF("schedstat", S_IRUGO, pid_schedstat),
22322304
#endif
2305+
#ifdef CONFIG_LATENCYTOP
2306+
REG("latency", S_IRUGO, lstats),
2307+
#endif
22332308
#ifdef CONFIG_PROC_PID_CPUSET
22342309
REG("cpuset", S_IRUGO, cpuset),
22352310
#endif
@@ -2555,6 +2630,9 @@ static const struct pid_entry tid_base_stuff[] = {
25552630
#ifdef CONFIG_SCHEDSTATS
25562631
INF("schedstat", S_IRUGO, pid_schedstat),
25572632
#endif
2633+
#ifdef CONFIG_LATENCYTOP
2634+
REG("latency", S_IRUGO, lstats),
2635+
#endif
25582636
#ifdef CONFIG_PROC_PID_CPUSET
25592637
REG("cpuset", S_IRUGO, cpuset),
25602638
#endif

‎include/linux/latencytop.h‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* latencytop.h: Infrastructure for displaying latency
3+
*
4+
* (C) Copyright 2008 Intel Corporation
5+
* Author: Arjan van de Ven <arjan@linux.intel.com>
6+
*
7+
*/
8+
9+
#ifndef _INCLUDE_GUARD_LATENCYTOP_H_
10+
#define _INCLUDE_GUARD_LATENCYTOP_H_
11+
12+
#ifdef CONFIG_LATENCYTOP
13+
14+
#define LT_SAVECOUNT 32
15+
#define LT_BACKTRACEDEPTH 12
16+
17+
struct latency_record {
18+
unsigned long backtrace[LT_BACKTRACEDEPTH];
19+
unsigned int count;
20+
unsigned long time;
21+
unsigned long max;
22+
};
23+
24+
25+
struct task_struct;
26+
27+
void account_scheduler_latency(struct task_struct *task, int usecs, int inter);
28+
29+
void clear_all_latency_tracing(struct task_struct *p);
30+
31+
#else
32+
33+
static inline void
34+
account_scheduler_latency(struct task_struct *task, int usecs, int inter)
35+
{
36+
}
37+
38+
static inline void clear_all_latency_tracing(struct task_struct *p)
39+
{
40+
}
41+
42+
#endif
43+
44+
#endif

‎include/linux/sched.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct sched_param {
8888
#include <linux/hrtimer.h>
8989
#include <linux/task_io_accounting.h>
9090
#include <linux/kobject.h>
91+
#include <linux/latencytop.h>
9192

9293
#include <asm/processor.h>
9394

@@ -1220,6 +1221,10 @@ struct task_struct {
12201221
int make_it_fail;
12211222
#endif
12221223
struct prop_local_single dirties;
1224+
#ifdef CONFIG_LATENCYTOP
1225+
int latency_record_count;
1226+
struct latency_record latency_record[LT_SAVECOUNT];
1227+
#endif
12231228
};
12241229

12251230
/*

‎include/linux/stacktrace.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ struct stack_trace {
99
};
1010

1111
extern void save_stack_trace(struct stack_trace *trace);
12+
extern void save_stack_trace_tsk(struct task_struct *tsk,
13+
struct stack_trace *trace);
1214

1315
extern void print_stack_trace(struct stack_trace *trace, int spaces);
1416
#else
1517
# define save_stack_trace(trace) do { } while (0)
18+
# define save_stack_trace_tsk(tsk, trace) do { } while (0)
1619
# define print_stack_trace(trace, spaces) do { } while (0)
1720
#endif
1821

‎kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
6262
obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
6363
obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
6464
obj-$(CONFIG_MARKERS) += marker.o
65+
obj-$(CONFIG_LATENCYTOP) += latencytop.o
6566

6667
ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
6768
# According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is

‎kernel/fork.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
12051205
#ifdef TIF_SYSCALL_EMU
12061206
clear_tsk_thread_flag(p, TIF_SYSCALL_EMU);
12071207
#endif
1208+
clear_all_latency_tracing(p);
12081209

12091210
/* Our parent execution domain becomes current domain
12101211
These must match for thread signalling to apply */

0 commit comments

Comments
 (0)