aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2009-06-02 23:00:53 -0400
committerSteven Rostedt <rostedt@goodmis.org>2009-06-03 10:15:22 -0400
commitedd813bffc62a980bb4fb9b1243f31c1cce78da3 (patch)
tree45dd8b0ca7b74f05bd545a1c3c7c4d2137f1b1d0 /kernel/trace
parenta2023556409cf7fec5d67a26f7fcfa57c5a4086d (diff)
ring-buffer: try to discard unneeded timestamps
There are times that a race may happen that we add a timestamp in a nested write. This timestamp would just contain a zero delta and serves no purpose. Now that we have a way to discard events, this patch will try to discard the timestamp instead of just wasting the space in the ring buffer. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/ring_buffer.c67
1 files changed, 41 insertions, 26 deletions
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 945302368691..50926601a28d 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -1335,6 +1335,38 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
1335 return event; 1335 return event;
1336} 1336}
1337 1337
1338static inline int
1339rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
1340 struct ring_buffer_event *event)
1341{
1342 unsigned long new_index, old_index;
1343 struct buffer_page *bpage;
1344 unsigned long index;
1345 unsigned long addr;
1346
1347 new_index = rb_event_index(event);
1348 old_index = new_index + rb_event_length(event);
1349 addr = (unsigned long)event;
1350 addr &= PAGE_MASK;
1351
1352 bpage = cpu_buffer->tail_page;
1353
1354 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
1355 /*
1356 * This is on the tail page. It is possible that
1357 * a write could come in and move the tail page
1358 * and write to the next page. That is fine
1359 * because we just shorten what is on this page.
1360 */
1361 index = local_cmpxchg(&bpage->write, old_index, new_index);
1362 if (index == old_index)
1363 return 1;
1364 }
1365
1366 /* could not discard */
1367 return 0;
1368}
1369
1338static int 1370static int
1339rb_add_time_stamp(struct ring_buffer_per_cpu *cpu_buffer, 1371rb_add_time_stamp(struct ring_buffer_per_cpu *cpu_buffer,
1340 u64 *ts, u64 *delta) 1372 u64 *ts, u64 *delta)
@@ -1384,10 +1416,13 @@ rb_add_time_stamp(struct ring_buffer_per_cpu *cpu_buffer,
1384 /* let the caller know this was the commit */ 1416 /* let the caller know this was the commit */
1385 ret = 1; 1417 ret = 1;
1386 } else { 1418 } else {
1387 /* Darn, this is just wasted space */ 1419 /* Try to discard the event */
1388 event->time_delta = 0; 1420 if (!rb_try_to_discard(cpu_buffer, event)) {
1389 event->array[0] = 0; 1421 /* Darn, this is just wasted space */
1390 ret = 0; 1422 event->time_delta = 0;
1423 event->array[0] = 0;
1424 ret = 0;
1425 }
1391 } 1426 }
1392 1427
1393 *delta = 0; 1428 *delta = 0;
@@ -1682,10 +1717,6 @@ void ring_buffer_discard_commit(struct ring_buffer *buffer,
1682 struct ring_buffer_event *event) 1717 struct ring_buffer_event *event)
1683{ 1718{
1684 struct ring_buffer_per_cpu *cpu_buffer; 1719 struct ring_buffer_per_cpu *cpu_buffer;
1685 unsigned long new_index, old_index;
1686 struct buffer_page *bpage;
1687 unsigned long index;
1688 unsigned long addr;
1689 int cpu; 1720 int cpu;
1690 1721
1691 /* The event is discarded regardless */ 1722 /* The event is discarded regardless */
@@ -1701,24 +1732,8 @@ void ring_buffer_discard_commit(struct ring_buffer *buffer,
1701 cpu = smp_processor_id(); 1732 cpu = smp_processor_id();
1702 cpu_buffer = buffer->buffers[cpu]; 1733 cpu_buffer = buffer->buffers[cpu];
1703 1734
1704 new_index = rb_event_index(event); 1735 if (!rb_try_to_discard(cpu_buffer, event))
1705 old_index = new_index + rb_event_length(event); 1736 goto out;
1706 addr = (unsigned long)event;
1707 addr &= PAGE_MASK;
1708
1709 bpage = cpu_buffer->tail_page;
1710
1711 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
1712 /*
1713 * This is on the tail page. It is possible that
1714 * a write could come in and move the tail page
1715 * and write to the next page. That is fine
1716 * because we just shorten what is on this page.
1717 */
1718 index = local_cmpxchg(&bpage->write, old_index, new_index);
1719 if (index == old_index)
1720 goto out;
1721 }
1722 1737
1723 /* 1738 /*
1724 * The commit is still visible by the reader, so we 1739 * The commit is still visible by the reader, so we