Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 121066
b: refs/heads/master
c: 9036990
h: refs/heads/master
v: v3
  • Loading branch information
Steven Rostedt authored and Ingo Molnar committed Nov 6, 2008
1 parent 523cf1e commit 6949986
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 49 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: 0f04870148ecb825133bc2733f473b1c5773ac0b
refs/heads/master: 9036990d462e09366f7297a2d1da6582c3e6b1d3
64 changes: 28 additions & 36 deletions trunk/kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ static DEFINE_PER_CPU(struct trace_array_cpu, max_data);
/* tracer_enabled is used to toggle activation of a tracer */
static int tracer_enabled = 1;

/**
* tracing_is_enabled - return tracer_enabled status
*
* This function is used by other tracers to know the status
* of the tracer_enabled flag. Tracers may use this function
* to know if it should enable their features when starting
* up. See irqsoff tracer for an example (start_irqsoff_tracer).
*/
int tracing_is_enabled(void)
{
return tracer_enabled;
}

/* function tracing enabled */
int ftrace_function_enabled;

Expand Down Expand Up @@ -1041,8 +1054,7 @@ void tracing_start_function_trace(void)
trace_ops.func = function_trace_call;

register_ftrace_function(&trace_ops);
if (tracer_enabled)
ftrace_function_enabled = 1;
ftrace_function_enabled = 1;
}

void tracing_stop_function_trace(void)
Expand Down Expand Up @@ -1189,10 +1201,6 @@ static void *s_start(struct seq_file *m, loff_t *pos)

atomic_inc(&trace_record_cmdline_disabled);

/* let the tracer grab locks here if needed */
if (current_trace->start)
current_trace->start(iter);

if (*pos != iter->pos) {
iter->ent = NULL;
iter->cpu = 0;
Expand All @@ -1219,14 +1227,7 @@ static void *s_start(struct seq_file *m, loff_t *pos)

static void s_stop(struct seq_file *m, void *p)
{
struct trace_iterator *iter = m->private;

atomic_dec(&trace_record_cmdline_disabled);

/* let the tracer release locks here if needed */
if (current_trace && current_trace == iter->trace && iter->trace->stop)
iter->trace->stop(iter);

mutex_unlock(&trace_types_lock);
}

Expand Down Expand Up @@ -2056,10 +2057,7 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
m->private = iter;

/* stop the trace while dumping */
if (iter->tr->ctrl) {
tracer_enabled = 0;
ftrace_function_enabled = 0;
}
tracing_stop();

if (iter->trace && iter->trace->open)
iter->trace->open(iter);
Expand Down Expand Up @@ -2104,14 +2102,7 @@ int tracing_release(struct inode *inode, struct file *file)
iter->trace->close(iter);

/* reenable tracing if it was previously enabled */
if (iter->tr->ctrl) {
tracer_enabled = 1;
/*
* It is safe to enable function tracing even if it
* isn't used
*/
ftrace_function_enabled = 1;
}
tracing_start();
mutex_unlock(&trace_types_lock);

seq_release(inode, file);
Expand Down Expand Up @@ -2449,11 +2440,10 @@ static ssize_t
tracing_ctrl_read(struct file *filp, char __user *ubuf,
size_t cnt, loff_t *ppos)
{
struct trace_array *tr = filp->private_data;
char buf[64];
int r;

r = sprintf(buf, "%ld\n", tr->ctrl);
r = sprintf(buf, "%u\n", tracer_enabled);
return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
}

Expand Down Expand Up @@ -2481,16 +2471,18 @@ tracing_ctrl_write(struct file *filp, const char __user *ubuf,
val = !!val;

mutex_lock(&trace_types_lock);
if (tr->ctrl ^ val) {
if (val)
if (tracer_enabled ^ val) {
if (val) {
tracer_enabled = 1;
else
if (current_trace->start)
current_trace->start(tr);
tracing_start();
} else {
tracer_enabled = 0;

tr->ctrl = val;

if (current_trace && current_trace->ctrl_update)
current_trace->ctrl_update(tr);
tracing_stop();
if (current_trace->stop)
current_trace->stop(tr);
}
}
mutex_unlock(&trace_types_lock);

Expand Down Expand Up @@ -3372,7 +3364,7 @@ __init static int tracer_alloc_buffers(void)
#endif

/* All seems OK, enable tracing */
global_trace.ctrl = tracer_enabled;
global_trace.ctrl = 1;
tracing_disabled = 0;

atomic_notifier_chain_register(&panic_notifier_list,
Expand Down
5 changes: 3 additions & 2 deletions trunk/kernel/trace/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ struct tracer {
const char *name;
void (*init)(struct trace_array *tr);
void (*reset)(struct trace_array *tr);
void (*start)(struct trace_array *tr);
void (*stop)(struct trace_array *tr);
void (*open)(struct trace_iterator *iter);
void (*pipe_open)(struct trace_iterator *iter);
void (*close)(struct trace_iterator *iter);
void (*start)(struct trace_iterator *iter);
void (*stop)(struct trace_iterator *iter);
ssize_t (*read)(struct trace_iterator *iter,
struct file *filp, char __user *ubuf,
size_t cnt, loff_t *ppos);
Expand Down Expand Up @@ -282,6 +282,7 @@ struct trace_iterator {
long idx;
};

int tracing_is_enabled(void);
void trace_wake_up(void);
void tracing_reset(struct trace_array *tr, int cpu);
int tracing_open_generic(struct inode *inode, struct file *filp);
Expand Down
6 changes: 6 additions & 0 deletions trunk/kernel/trace/trace_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ static void function_trace_ctrl_update(struct trace_array *tr)
stop_function_trace(tr);
}

static void function_trace_start(struct trace_array *tr)
{
function_reset(tr);
}

static struct tracer function_trace __read_mostly =
{
.name = "function",
.init = function_trace_init,
.reset = function_trace_reset,
.start = function_trace_start,
.ctrl_update = function_trace_ctrl_update,
#ifdef CONFIG_FTRACE_SELFTEST
.selftest = trace_selftest_startup_function,
Expand Down
41 changes: 36 additions & 5 deletions trunk/kernel/trace/trace_irqsoff.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,28 @@ void trace_preempt_off(unsigned long a0, unsigned long a1)
}
#endif /* CONFIG_PREEMPT_TRACER */

/*
* save_tracer_enabled is used to save the state of the tracer_enabled
* variable when we disable it when we open a trace output file.
*/
static int save_tracer_enabled;

static void start_irqsoff_tracer(struct trace_array *tr)
{
register_ftrace_function(&trace_ops);
tracer_enabled = 1;
if (tracing_is_enabled()) {
tracer_enabled = 1;
save_tracer_enabled = 1;
} else {
tracer_enabled = 0;
save_tracer_enabled = 0;
}
}

static void stop_irqsoff_tracer(struct trace_array *tr)
{
tracer_enabled = 0;
save_tracer_enabled = 0;
unregister_ftrace_function(&trace_ops);
}

Expand Down Expand Up @@ -389,17 +402,29 @@ static void irqsoff_tracer_ctrl_update(struct trace_array *tr)
stop_irqsoff_tracer(tr);
}

static void irqsoff_tracer_start(struct trace_array *tr)
{
irqsoff_tracer_reset(tr);
tracer_enabled = 1;
save_tracer_enabled = 1;
}

static void irqsoff_tracer_stop(struct trace_array *tr)
{
tracer_enabled = 0;
save_tracer_enabled = 0;
}

static void irqsoff_tracer_open(struct trace_iterator *iter)
{
/* stop the trace while dumping */
if (iter->tr->ctrl)
stop_irqsoff_tracer(iter->tr);
tracer_enabled = 0;
}

static void irqsoff_tracer_close(struct trace_iterator *iter)
{
if (iter->tr->ctrl)
start_irqsoff_tracer(iter->tr);
/* restart tracing */
tracer_enabled = save_tracer_enabled;
}

#ifdef CONFIG_IRQSOFF_TRACER
Expand All @@ -414,6 +439,8 @@ static struct tracer irqsoff_tracer __read_mostly =
.name = "irqsoff",
.init = irqsoff_tracer_init,
.reset = irqsoff_tracer_reset,
.start = irqsoff_tracer_start,
.stop = irqsoff_tracer_stop,
.open = irqsoff_tracer_open,
.close = irqsoff_tracer_close,
.ctrl_update = irqsoff_tracer_ctrl_update,
Expand All @@ -440,6 +467,8 @@ static struct tracer preemptoff_tracer __read_mostly =
.name = "preemptoff",
.init = preemptoff_tracer_init,
.reset = irqsoff_tracer_reset,
.start = irqsoff_tracer_start,
.stop = irqsoff_tracer_stop,
.open = irqsoff_tracer_open,
.close = irqsoff_tracer_close,
.ctrl_update = irqsoff_tracer_ctrl_update,
Expand Down Expand Up @@ -468,6 +497,8 @@ static struct tracer preemptirqsoff_tracer __read_mostly =
.name = "preemptirqsoff",
.init = preemptirqsoff_tracer_init,
.reset = irqsoff_tracer_reset,
.start = irqsoff_tracer_start,
.stop = irqsoff_tracer_stop,
.open = irqsoff_tracer_open,
.close = irqsoff_tracer_close,
.ctrl_update = irqsoff_tracer_ctrl_update,
Expand Down
13 changes: 13 additions & 0 deletions trunk/kernel/trace/trace_sched_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,24 @@ static void sched_switch_trace_ctrl_update(struct trace_array *tr)
stop_sched_trace(tr);
}

static void sched_switch_trace_start(struct trace_array *tr)
{
sched_switch_reset(tr);
tracing_start_sched_switch();
}

static void sched_switch_trace_stop(struct trace_array *tr)
{
tracing_stop_sched_switch();
}

struct tracer sched_switch_trace __read_mostly =
{
.name = "sched_switch",
.init = sched_switch_trace_init,
.reset = sched_switch_trace_reset,
.start = sched_switch_trace_start,
.stop = sched_switch_trace_stop,
.ctrl_update = sched_switch_trace_ctrl_update,
#ifdef CONFIG_FTRACE_SELFTEST
.selftest = trace_selftest_startup_sched_switch,
Expand Down
39 changes: 34 additions & 5 deletions trunk/kernel/trace/trace_sched_wakeup.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ probe_wakeup(struct rq *rq, struct task_struct *p)
atomic_dec(&wakeup_trace->data[cpu]->disabled);
}

/*
* save_tracer_enabled is used to save the state of the tracer_enabled
* variable when we disable it when we open a trace output file.
*/
static int save_tracer_enabled;

static void start_wakeup_tracer(struct trace_array *tr)
{
int ret;
Expand Down Expand Up @@ -300,7 +306,13 @@ static void start_wakeup_tracer(struct trace_array *tr)

register_ftrace_function(&trace_ops);

tracer_enabled = 1;
if (tracing_is_enabled()) {
tracer_enabled = 1;
save_tracer_enabled = 1;
} else {
tracer_enabled = 0;
save_tracer_enabled = 0;
}

return;
fail_deprobe_wake_new:
Expand All @@ -312,6 +324,7 @@ static void start_wakeup_tracer(struct trace_array *tr)
static void stop_wakeup_tracer(struct trace_array *tr)
{
tracer_enabled = 0;
save_tracer_enabled = 0;
unregister_ftrace_function(&trace_ops);
unregister_trace_sched_switch(probe_wakeup_sched_switch);
unregister_trace_sched_wakeup_new(probe_wakeup);
Expand Down Expand Up @@ -343,25 +356,41 @@ static void wakeup_tracer_ctrl_update(struct trace_array *tr)
stop_wakeup_tracer(tr);
}

static void wakeup_tracer_start(struct trace_array *tr)
{
wakeup_reset(tr);
tracer_enabled = 1;
save_tracer_enabled = 1;
}

static void wakeup_tracer_stop(struct trace_array *tr)
{
tracer_enabled = 0;
save_tracer_enabled = 0;
}

static void wakeup_tracer_open(struct trace_iterator *iter)
{
/* stop the trace while dumping */
if (iter->tr->ctrl)
stop_wakeup_tracer(iter->tr);
tracer_enabled = 0;
}

static void wakeup_tracer_close(struct trace_iterator *iter)
{
/* forget about any processes we were recording */
if (iter->tr->ctrl)
start_wakeup_tracer(iter->tr);
if (save_tracer_enabled) {
wakeup_reset(iter->tr);
tracer_enabled = 1;
}
}

static struct tracer wakeup_tracer __read_mostly =
{
.name = "wakeup",
.init = wakeup_tracer_init,
.reset = wakeup_tracer_reset,
.start = wakeup_tracer_start,
.stop = wakeup_tracer_stop,
.open = wakeup_tracer_open,
.close = wakeup_tracer_close,
.ctrl_update = wakeup_tracer_ctrl_update,
Expand Down

0 comments on commit 6949986

Please sign in to comment.