mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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>
			
			
This commit is contained in:
		
							parent
							
								
									1c7d667324
								
							
						
					
					
						commit
						d60da506cb
					
				
					 1 changed files with 31 additions and 27 deletions
				
			
		| 
						 | 
					@ -3034,6 +3034,31 @@ static void set_buffer_entries(struct trace_array *tr, unsigned long val)
 | 
				
			||||||
		tr->data[cpu]->entries = val;
 | 
							tr->data[cpu]->entries = val;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* resize @tr's buffer to the size of @size_tr's entries */
 | 
				
			||||||
 | 
					static int resize_buffer_duplicate_size(struct trace_array *tr,
 | 
				
			||||||
 | 
										struct trace_array *size_tr, int cpu_id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int cpu, ret = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (cpu_id == RING_BUFFER_ALL_CPUS) {
 | 
				
			||||||
 | 
							for_each_tracing_cpu(cpu) {
 | 
				
			||||||
 | 
								ret = ring_buffer_resize(tr->buffer,
 | 
				
			||||||
 | 
										size_tr->data[cpu]->entries, cpu);
 | 
				
			||||||
 | 
								if (ret < 0)
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								tr->data[cpu]->entries = size_tr->data[cpu]->entries;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							ret = ring_buffer_resize(tr->buffer,
 | 
				
			||||||
 | 
										size_tr->data[cpu_id]->entries, cpu_id);
 | 
				
			||||||
 | 
							if (ret == 0)
 | 
				
			||||||
 | 
								tr->data[cpu_id]->entries =
 | 
				
			||||||
 | 
									size_tr->data[cpu_id]->entries;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int __tracing_resize_ring_buffer(unsigned long size, int cpu)
 | 
					static int __tracing_resize_ring_buffer(unsigned long size, int cpu)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret;
 | 
						int ret;
 | 
				
			||||||
| 
						 | 
					@ -3058,23 +3083,8 @@ static int __tracing_resize_ring_buffer(unsigned long size, int cpu)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = ring_buffer_resize(max_tr.buffer, size, cpu);
 | 
						ret = ring_buffer_resize(max_tr.buffer, size, cpu);
 | 
				
			||||||
	if (ret < 0) {
 | 
						if (ret < 0) {
 | 
				
			||||||
		int r = 0;
 | 
							int r = resize_buffer_duplicate_size(&global_trace,
 | 
				
			||||||
 | 
											     &global_trace, cpu);
 | 
				
			||||||
		if (cpu == RING_BUFFER_ALL_CPUS) {
 | 
					 | 
				
			||||||
			int i;
 | 
					 | 
				
			||||||
			for_each_tracing_cpu(i) {
 | 
					 | 
				
			||||||
				r = ring_buffer_resize(global_trace.buffer,
 | 
					 | 
				
			||||||
						global_trace.data[i]->entries,
 | 
					 | 
				
			||||||
						i);
 | 
					 | 
				
			||||||
				if (r < 0)
 | 
					 | 
				
			||||||
					break;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			r = ring_buffer_resize(global_trace.buffer,
 | 
					 | 
				
			||||||
						global_trace.data[cpu]->entries,
 | 
					 | 
				
			||||||
						cpu);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (r < 0) {
 | 
							if (r < 0) {
 | 
				
			||||||
			/*
 | 
								/*
 | 
				
			||||||
			 * AARGH! We are left with different
 | 
								 * AARGH! We are left with different
 | 
				
			||||||
| 
						 | 
					@ -3212,17 +3222,11 @@ static int tracing_set_tracer(const char *buf)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	topts = create_trace_option_files(t);
 | 
						topts = create_trace_option_files(t);
 | 
				
			||||||
	if (t->use_max_tr) {
 | 
						if (t->use_max_tr) {
 | 
				
			||||||
		int cpu;
 | 
					 | 
				
			||||||
		/* we need to make per cpu buffer sizes equivalent */
 | 
							/* we need to make per cpu buffer sizes equivalent */
 | 
				
			||||||
		for_each_tracing_cpu(cpu) {
 | 
							ret = resize_buffer_duplicate_size(&max_tr, &global_trace,
 | 
				
			||||||
			ret = ring_buffer_resize(max_tr.buffer,
 | 
											   RING_BUFFER_ALL_CPUS);
 | 
				
			||||||
						global_trace.data[cpu]->entries,
 | 
					 | 
				
			||||||
						cpu);
 | 
					 | 
				
			||||||
		if (ret < 0)
 | 
							if (ret < 0)
 | 
				
			||||||
			goto out;
 | 
								goto out;
 | 
				
			||||||
			max_tr.data[cpu]->entries =
 | 
					 | 
				
			||||||
					global_trace.data[cpu]->entries;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (t->init) {
 | 
						if (t->init) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue