Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 116606
b: refs/heads/master
c: 1b6cced
h: refs/heads/master
v: v3
  • Loading branch information
Steven Rostedt authored and Ingo Molnar committed Oct 14, 2008
1 parent b3373c1 commit 9d4f773
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d53475b5aa946752e3306b2ecb5a8c9c51cf8dd0
refs/heads/master: 1b6cced6ec9677fa65471e890dfdcb4bf5387643
90 changes: 73 additions & 17 deletions trunk/kernel/trace/trace_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

#define STACK_TRACE_ENTRIES 500

static unsigned long stack_dump_trace[STACK_TRACE_ENTRIES] =
{ [0 ... (STACK_TRACE_ENTRIES-1)] = ULONG_MAX };
static unsigned long stack_dump_trace[STACK_TRACE_ENTRIES+1] =
{ [0 ... (STACK_TRACE_ENTRIES)] = ULONG_MAX };
static unsigned stack_dump_index[STACK_TRACE_ENTRIES];

static struct stack_trace max_stack_trace = {
.max_entries = STACK_TRACE_ENTRIES,
.entries = stack_dump_trace,
Expand All @@ -32,8 +34,9 @@ static DEFINE_PER_CPU(int, trace_active);

static inline void check_stack(void)
{
unsigned long this_size;
unsigned long flags;
unsigned long this_size, flags;
unsigned long *p, *top, *start;
int i;

this_size = ((unsigned long)&this_size) & (THREAD_SIZE-1);
this_size = THREAD_SIZE - this_size;
Expand All @@ -51,10 +54,42 @@ static inline void check_stack(void)
max_stack_size = this_size;

max_stack_trace.nr_entries = 0;
max_stack_trace.skip = 1;
max_stack_trace.skip = 3;

save_stack_trace(&max_stack_trace);

/*
* Now find where in the stack these are.
*/
i = 0;
start = &this_size;
top = (unsigned long *)
(((unsigned long)start & ~(THREAD_SIZE-1)) + THREAD_SIZE);

/*
* Loop through all the entries. One of the entries may
* for some reason be missed on the stack, so we may
* have to account for them. If they are all there, this
* loop will only happen once. This code only takes place
* on a new max, so it is far from a fast path.
*/
while (i < max_stack_trace.nr_entries) {

stack_dump_index[i] = this_size;
p = start;

for (; p < top && i < max_stack_trace.nr_entries; p++) {
if (*p == stack_dump_trace[i]) {
this_size = stack_dump_index[i++] =
(top - p) * sizeof(unsigned long);
/* Start the search from here */
start = p + 1;
}
}

i++;
}

out:
__raw_spin_unlock(&max_stack_lock);
raw_local_irq_restore(flags);
Expand Down Expand Up @@ -145,22 +180,24 @@ static struct file_operations stack_max_size_fops = {
static void *
t_next(struct seq_file *m, void *v, loff_t *pos)
{
unsigned long *t = m->private;
long i = (long)m->private;

(*pos)++;

if (!t || *t == ULONG_MAX)
i++;

if (i >= max_stack_trace.nr_entries ||
stack_dump_trace[i] == ULONG_MAX)
return NULL;

t++;
m->private = t;
m->private = (void *)i;

return t;
return &m->private;
}

static void *t_start(struct seq_file *m, loff_t *pos)
{
unsigned long *t = m->private;
void *t = &m->private;
loff_t l = 0;

local_irq_disable();
Expand All @@ -178,27 +215,46 @@ static void t_stop(struct seq_file *m, void *p)
local_irq_enable();
}

static int trace_lookup_stack(struct seq_file *m, unsigned long addr)
static int trace_lookup_stack(struct seq_file *m, long i)
{
unsigned long addr = stack_dump_trace[i];
#ifdef CONFIG_KALLSYMS
char str[KSYM_SYMBOL_LEN];

sprint_symbol(str, addr);

return seq_printf(m, "[<%p>] %s\n", (void*)addr, str);
return seq_printf(m, "%s\n", str);
#else
return seq_printf(m, "%p\n", (void*)addr);
#endif
}

static int t_show(struct seq_file *m, void *v)
{
unsigned long *t = v;
long i = *(long *)v;
int size;

if (i < 0) {
seq_printf(m, " Depth Size Location"
" (%d entries)\n"
" ----- ---- --------\n",
max_stack_trace.nr_entries);
return 0;
}

if (!t || *t == ULONG_MAX)
if (i >= max_stack_trace.nr_entries ||
stack_dump_trace[i] == ULONG_MAX)
return 0;

trace_lookup_stack(m, *t);
if (i+1 == max_stack_trace.nr_entries ||
stack_dump_trace[i+1] == ULONG_MAX)
size = stack_dump_index[i];
else
size = stack_dump_index[i] - stack_dump_index[i+1];

seq_printf(m, "%3ld) %8d %5d ", i, stack_dump_index[i], size);

trace_lookup_stack(m, i);

return 0;
}
Expand All @@ -217,7 +273,7 @@ static int stack_trace_open(struct inode *inode, struct file *file)
ret = seq_open(file, &stack_trace_seq_ops);
if (!ret) {
struct seq_file *m = file->private_data;
m->private = stack_dump_trace;
m->private = (void *)-1;
}

return ret;
Expand Down

0 comments on commit 9d4f773

Please sign in to comment.