Skip to content

Commit d60da50

Browse files
toyookarostedt
authored andcommitted
tracing: Add a resize function to make one buffer equivalent to another buffer
Trace buffer size is now per-cpu, so that there are the following two patterns in resizing of buffers. (1) resize per-cpu buffers to same given size (2) resize per-cpu buffers to another trace_array's buffer size for each CPU (such as preparing the max_tr which is equivalent to the global_trace's size) __tracing_resize_ring_buffer() can be used for (1), and had implemented (2) inside it for resetting the global_trace to the original size. (2) was also implemented in another place. So this patch assembles them in a new function - resize_buffer_duplicate_size(). Link: http://lkml.kernel.org/r/20121017025616.2627.91226.stgit@falsita Signed-off-by: Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 1c7d667 commit d60da50

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

kernel/trace/trace.c

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,6 +3034,31 @@ static void set_buffer_entries(struct trace_array *tr, unsigned long val)
30343034
tr->data[cpu]->entries = val;
30353035
}
30363036

3037+
/* resize @tr's buffer to the size of @size_tr's entries */
3038+
static int resize_buffer_duplicate_size(struct trace_array *tr,
3039+
struct trace_array *size_tr, int cpu_id)
3040+
{
3041+
int cpu, ret = 0;
3042+
3043+
if (cpu_id == RING_BUFFER_ALL_CPUS) {
3044+
for_each_tracing_cpu(cpu) {
3045+
ret = ring_buffer_resize(tr->buffer,
3046+
size_tr->data[cpu]->entries, cpu);
3047+
if (ret < 0)
3048+
break;
3049+
tr->data[cpu]->entries = size_tr->data[cpu]->entries;
3050+
}
3051+
} else {
3052+
ret = ring_buffer_resize(tr->buffer,
3053+
size_tr->data[cpu_id]->entries, cpu_id);
3054+
if (ret == 0)
3055+
tr->data[cpu_id]->entries =
3056+
size_tr->data[cpu_id]->entries;
3057+
}
3058+
3059+
return ret;
3060+
}
3061+
30373062
static int __tracing_resize_ring_buffer(unsigned long size, int cpu)
30383063
{
30393064
int ret;
@@ -3058,23 +3083,8 @@ static int __tracing_resize_ring_buffer(unsigned long size, int cpu)
30583083

30593084
ret = ring_buffer_resize(max_tr.buffer, size, cpu);
30603085
if (ret < 0) {
3061-
int r = 0;
3062-
3063-
if (cpu == RING_BUFFER_ALL_CPUS) {
3064-
int i;
3065-
for_each_tracing_cpu(i) {
3066-
r = ring_buffer_resize(global_trace.buffer,
3067-
global_trace.data[i]->entries,
3068-
i);
3069-
if (r < 0)
3070-
break;
3071-
}
3072-
} else {
3073-
r = ring_buffer_resize(global_trace.buffer,
3074-
global_trace.data[cpu]->entries,
3075-
cpu);
3076-
}
3077-
3086+
int r = resize_buffer_duplicate_size(&global_trace,
3087+
&global_trace, cpu);
30783088
if (r < 0) {
30793089
/*
30803090
* AARGH! We are left with different
@@ -3212,17 +3222,11 @@ static int tracing_set_tracer(const char *buf)
32123222

32133223
topts = create_trace_option_files(t);
32143224
if (t->use_max_tr) {
3215-
int cpu;
32163225
/* we need to make per cpu buffer sizes equivalent */
3217-
for_each_tracing_cpu(cpu) {
3218-
ret = ring_buffer_resize(max_tr.buffer,
3219-
global_trace.data[cpu]->entries,
3220-
cpu);
3221-
if (ret < 0)
3222-
goto out;
3223-
max_tr.data[cpu]->entries =
3224-
global_trace.data[cpu]->entries;
3225-
}
3226+
ret = resize_buffer_duplicate_size(&max_tr, &global_trace,
3227+
RING_BUFFER_ALL_CPUS);
3228+
if (ret < 0)
3229+
goto out;
32263230
}
32273231

32283232
if (t->init) {

0 commit comments

Comments
 (0)