Skip to content

Commit f6195aa

Browse files
Steven Rostedtrostedt
authored andcommitted
ring-buffer: Place duplicate expression into a single function
While discussing the strictness of the 80 character limit on the Kernel Summit Discussion mailing list, I showed examples that I broke that limit slightly with some algorithms. In discussing with John Linville, what looked better, I realized that two of the 80 char breaking culprits were an identical expression. As a clean up, this patch moves the identical expression into its own helper function and that is used instead. As a side effect, the offending code is now under the 80 character limit. :-) This clean up code also changes the expression from (A - B) - C to A - (B + C) This makes the code look a little nicer too. Cc: John W. Linville <linville@tuxdriver.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent c9cf4a0 commit f6195aa

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

‎kernel/trace/ring_buffer.c‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,6 +2606,19 @@ void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu)
26062606
}
26072607
EXPORT_SYMBOL_GPL(ring_buffer_record_enable_cpu);
26082608

2609+
/*
2610+
* The total entries in the ring buffer is the running counter
2611+
* of entries entered into the ring buffer, minus the sum of
2612+
* the entries read from the ring buffer and the number of
2613+
* entries that were overwritten.
2614+
*/
2615+
static inline unsigned long
2616+
rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
2617+
{
2618+
return local_read(&cpu_buffer->entries) -
2619+
(local_read(&cpu_buffer->overrun) + cpu_buffer->read);
2620+
}
2621+
26092622
/**
26102623
* ring_buffer_entries_cpu - get the number of entries in a cpu buffer
26112624
* @buffer: The ring buffer
@@ -2614,16 +2627,13 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_enable_cpu);
26142627
unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu)
26152628
{
26162629
struct ring_buffer_per_cpu *cpu_buffer;
2617-
unsigned long ret;
26182630

26192631
if (!cpumask_test_cpu(cpu, buffer->cpumask))
26202632
return 0;
26212633

26222634
cpu_buffer = buffer->buffers[cpu];
2623-
ret = (local_read(&cpu_buffer->entries) - local_read(&cpu_buffer->overrun))
2624-
- cpu_buffer->read;
26252635

2626-
return ret;
2636+
return rb_num_of_entries(cpu_buffer);
26272637
}
26282638
EXPORT_SYMBOL_GPL(ring_buffer_entries_cpu);
26292639

@@ -2684,8 +2694,7 @@ unsigned long ring_buffer_entries(struct ring_buffer *buffer)
26842694
/* if you care about this being correct, lock the buffer */
26852695
for_each_buffer_cpu(buffer, cpu) {
26862696
cpu_buffer = buffer->buffers[cpu];
2687-
entries += (local_read(&cpu_buffer->entries) -
2688-
local_read(&cpu_buffer->overrun)) - cpu_buffer->read;
2697+
entries += rb_num_of_entries(cpu_buffer);
26892698
}
26902699

26912700
return entries;

0 commit comments

Comments
 (0)