Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 100627
b: refs/heads/master
c: 56a08bd
h: refs/heads/master
i:
  100625: d1ae7a7
  100623: 47a197d
v: v3
  • Loading branch information
Ingo Molnar authored and Thomas Gleixner committed May 23, 2008
1 parent 3bb2cf8 commit a1ed7a1
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 5 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: 0075fa80305f3231a2d5df97b00d7f55a48ea27e
refs/heads/master: 56a08bdcff20f0022bd9160c1093e56f763499aa
80 changes: 76 additions & 4 deletions trunk/kernel/trace/trace_sysprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,104 @@
*
* Copyright (C) 2007 Steven Rostedt <srostedt@redhat.com>
* Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
*
* Copyright (C) 2004, 2005, Soeren Sandmann
*/
#include <linux/kallsyms.h>
#include <linux/debugfs.h>
#include <linux/hrtimer.h>
#include <linux/uaccess.h>
#include <linux/ftrace.h>
#include <linux/module.h>
#include <linux/irq.h>
#include <linux/fs.h>

#include "trace.h"

static struct trace_array *ctx_trace;
static struct trace_array *sysprof_trace;
static int __read_mostly tracer_enabled;

/*
* 10 msecs for now:
*/
static const unsigned long sample_period = 1000000;

/*
* Per CPU hrtimers that do the profiling:
*/
static DEFINE_PER_CPU(struct hrtimer, stack_trace_hrtimer);

struct stack_frame {
const void __user *next_fp;
unsigned long return_address;
};

static int copy_stack_frame(const void __user *fp, struct stack_frame *frame)
{
if (!access_ok(VERIFY_READ, fp, sizeof(*frame)))
return 0;

if (__copy_from_user_inatomic(frame, frame_pointer, sizeof(*frame)))
return 0;

return 1;
}

#define SYSPROF_MAX_ADDRESSES 512

static void timer_notify(struct pt_regs *regs, int cpu)
{
const void __user *frame_pointer;
struct trace_array_cpu *data;
struct stack_frame frame;
struct trace_array *tr;
int is_user;
int i;

if (!regs)
return;

tr = sysprof_trace;
data = tr->data[cpu];
is_user = user_mode(regs);

if (!current || current->pid == 0)
return;

if (is_user && current->state != TASK_RUNNING)
return;

if (!is_user) {
/* kernel */
ftrace(tr, data, current->pid, 1, 0);
return;

}

trace_special(tr, data, 0, current->pid, regs->ip);

frame_pointer = (void __user *)regs->bp;

for (i = 0; i < SYSPROF_MAX_ADDRESSES; i++) {
if (!copy_stack_frame(frame_pointer, &frame))
break;
if ((unsigned long)frame_pointer < regs->sp)
break;

trace_special(tr, data, 1, frame.return_address,
(unsigned long)frame_pointer);
frame_pointer = frame.next_fp;
}

trace_special(tr, data, 2, current->pid, i);

if (i == SYSPROF_MAX_ADDRESSES)
trace_special(tr, data, -1, -1, -1);
}

static enum hrtimer_restart stack_trace_timer_fn(struct hrtimer *hrtimer)
{
/* trace here */
panic_timeout++;
timer_notify(get_irq_regs(), smp_processor_id());

hrtimer_forward_now(hrtimer, ns_to_ktime(sample_period));

Expand Down Expand Up @@ -100,7 +172,7 @@ static notrace void stop_stack_trace(struct trace_array *tr)

static notrace void stack_trace_init(struct trace_array *tr)
{
ctx_trace = tr;
sysprof_trace = tr;

if (tr->ctrl)
start_stack_trace(tr);
Expand Down

0 comments on commit a1ed7a1

Please sign in to comment.