Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 257098
b: refs/heads/master
c: 4f271a2
h: refs/heads/master
v: v3
  • Loading branch information
Vaibhav Nagarnaik authored and Steven Rostedt committed Jun 15, 2011
1 parent 2bb36c4 commit 7fa3cbc
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 36 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: 7ea5906405a1f3fc1c0033dfd7e02f2cfd1de5e5
refs/heads/master: 4f271a2a60c748599b30bb4dafff30d770439b96
108 changes: 73 additions & 35 deletions trunk/kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2768,7 +2768,7 @@ int tracer_init(struct tracer *t, struct trace_array *tr)
return t->init(tr);
}

static int tracing_resize_ring_buffer(unsigned long size)
static int __tracing_resize_ring_buffer(unsigned long size)
{
int ret;

Expand Down Expand Up @@ -2820,6 +2820,41 @@ static int tracing_resize_ring_buffer(unsigned long size)
return ret;
}

static ssize_t tracing_resize_ring_buffer(unsigned long size)
{
int cpu, ret = size;

mutex_lock(&trace_types_lock);

tracing_stop();

/* disable all cpu buffers */
for_each_tracing_cpu(cpu) {
if (global_trace.data[cpu])
atomic_inc(&global_trace.data[cpu]->disabled);
if (max_tr.data[cpu])
atomic_inc(&max_tr.data[cpu]->disabled);
}

if (size != global_trace.entries)
ret = __tracing_resize_ring_buffer(size);

if (ret < 0)
ret = -ENOMEM;

for_each_tracing_cpu(cpu) {
if (global_trace.data[cpu])
atomic_dec(&global_trace.data[cpu]->disabled);
if (max_tr.data[cpu])
atomic_dec(&max_tr.data[cpu]->disabled);
}

tracing_start();
mutex_unlock(&trace_types_lock);

return ret;
}


/**
* tracing_update_buffers - used by tracing facility to expand ring buffers
Expand All @@ -2837,7 +2872,7 @@ int tracing_update_buffers(void)

mutex_lock(&trace_types_lock);
if (!ring_buffer_expanded)
ret = tracing_resize_ring_buffer(trace_buf_size);
ret = __tracing_resize_ring_buffer(trace_buf_size);
mutex_unlock(&trace_types_lock);

return ret;
Expand All @@ -2861,7 +2896,7 @@ static int tracing_set_tracer(const char *buf)
mutex_lock(&trace_types_lock);

if (!ring_buffer_expanded) {
ret = tracing_resize_ring_buffer(trace_buf_size);
ret = __tracing_resize_ring_buffer(trace_buf_size);
if (ret < 0)
goto out;
ret = 0;
Expand Down Expand Up @@ -3436,7 +3471,7 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,
{
unsigned long val;
char buf[64];
int ret, cpu;
int ret;

if (cnt >= sizeof(buf))
return -EINVAL;
Expand All @@ -3454,48 +3489,43 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,
if (!val)
return -EINVAL;

mutex_lock(&trace_types_lock);

tracing_stop();

/* disable all cpu buffers */
for_each_tracing_cpu(cpu) {
if (global_trace.data[cpu])
atomic_inc(&global_trace.data[cpu]->disabled);
if (max_tr.data[cpu])
atomic_inc(&max_tr.data[cpu]->disabled);
}

/* value is in KB */
val <<= 10;

if (val != global_trace.entries) {
ret = tracing_resize_ring_buffer(val);
if (ret < 0) {
cnt = ret;
goto out;
}
}
ret = tracing_resize_ring_buffer(val);
if (ret < 0)
return ret;

*ppos += cnt;

/* If check pages failed, return ENOMEM */
if (tracing_disabled)
cnt = -ENOMEM;
out:
for_each_tracing_cpu(cpu) {
if (global_trace.data[cpu])
atomic_dec(&global_trace.data[cpu]->disabled);
if (max_tr.data[cpu])
atomic_dec(&max_tr.data[cpu]->disabled);
}
return cnt;
}

tracing_start();
mutex_unlock(&trace_types_lock);
static ssize_t
tracing_free_buffer_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos)
{
/*
* There is no need to read what the user has written, this function
* is just to make sure that there is no error when "echo" is used
*/

*ppos += cnt;

return cnt;
}

static int
tracing_free_buffer_release(struct inode *inode, struct file *filp)
{
/* disable tracing */
tracing_off();
/* resize the ring buffer to 0 */
tracing_resize_ring_buffer(0);

return 0;
}

static int mark_printk(const char *fmt, ...)
{
int ret;
Expand Down Expand Up @@ -3641,6 +3671,11 @@ static const struct file_operations tracing_entries_fops = {
.llseek = generic_file_llseek,
};

static const struct file_operations tracing_free_buffer_fops = {
.write = tracing_free_buffer_write,
.release = tracing_free_buffer_release,
};

static const struct file_operations tracing_mark_fops = {
.open = tracing_open_generic,
.write = tracing_mark_write,
Expand Down Expand Up @@ -4365,6 +4400,9 @@ static __init int tracer_init_debugfs(void)
trace_create_file("buffer_size_kb", 0644, d_tracer,
&global_trace, &tracing_entries_fops);

trace_create_file("free_buffer", 0644, d_tracer,
&global_trace, &tracing_free_buffer_fops);

trace_create_file("trace_marker", 0220, d_tracer,
NULL, &tracing_mark_fops);

Expand Down

0 comments on commit 7fa3cbc

Please sign in to comment.