Skip to content

Commit 7c4b4a5

Browse files
committed
ring-buffer: Incorporate absolute timestamp into add_timestamp logic
Instead of calling out the absolute test for each time to check if the ring buffer wants absolute time stamps for all its recording, incorporate it with the add_timestamp field and turn it into flags for faster processing between wanting a absolute tag and needing to force one. Link: http://lkml.kernel.org/r/20200629025259.154892368@goodmis.org Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent a389d86 commit 7c4b4a5

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

kernel/trace/ring_buffer.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,15 @@ struct rb_event_info {
422422
/*
423423
* Used for the add_timestamp
424424
* NONE
425-
* NORMAL - may be for either time extend or absolute
425+
* EXTEND - wants a time extend
426+
* ABSOLUTE - the buffer requests all events to have absolute time stamps
426427
* FORCE - force a full time stamp.
427428
*/
428429
enum {
429-
RB_ADD_STAMP_NONE,
430-
RB_ADD_STAMP_NORMAL,
431-
RB_ADD_STAMP_FORCE
430+
RB_ADD_STAMP_NONE = 0,
431+
RB_ADD_STAMP_EXTEND = BIT(1),
432+
RB_ADD_STAMP_ABSOLUTE = BIT(2),
433+
RB_ADD_STAMP_FORCE = BIT(3)
432434
};
433435
/*
434436
* Used for which event context the event is in.
@@ -2434,8 +2436,8 @@ rb_update_event(struct ring_buffer_per_cpu *cpu_buffer,
24342436
* add it to the start of the reserved space.
24352437
*/
24362438
if (unlikely(info->add_timestamp)) {
2437-
bool abs = info->add_timestamp == RB_ADD_STAMP_FORCE ||
2438-
ring_buffer_time_stamp_abs(cpu_buffer->buffer);
2439+
bool abs = info->add_timestamp &
2440+
(RB_ADD_STAMP_FORCE | RB_ADD_STAMP_ABSOLUTE);
24392441

24402442
event = rb_add_time_stamp(event, abs ? info->delta : delta, abs);
24412443
length -= RB_LEN_TIME_EXTEND;
@@ -2884,8 +2886,8 @@ int ring_buffer_unlock_commit(struct trace_buffer *buffer,
28842886
EXPORT_SYMBOL_GPL(ring_buffer_unlock_commit);
28852887

28862888
static noinline void
2887-
rb_handle_timestamp(struct ring_buffer_per_cpu *cpu_buffer,
2888-
struct rb_event_info *info)
2889+
rb_check_timestamp(struct ring_buffer_per_cpu *cpu_buffer,
2890+
struct rb_event_info *info)
28892891
{
28902892
WARN_ONCE(info->delta > (1ULL << 59),
28912893
KERN_WARNING "Delta way too big! %llu ts=%llu write stamp = %llu\n%s",
@@ -2897,7 +2899,6 @@ rb_handle_timestamp(struct ring_buffer_per_cpu *cpu_buffer,
28972899
"please switch to the trace global clock:\n"
28982900
" echo global > /sys/kernel/debug/tracing/trace_clock\n"
28992901
"or add trace_clock=global to the kernel command line\n");
2900-
info->add_timestamp = RB_ADD_STAMP_NORMAL;
29012902
}
29022903

29032904
static struct ring_buffer_event *
@@ -2908,7 +2909,6 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
29082909
struct buffer_page *tail_page;
29092910
unsigned long tail, write, w;
29102911
u64 before, after;
2911-
bool abs = false;
29122912

29132913
/* Don't let the compiler play games with cpu_buffer->tail_page */
29142914
tail_page = info->tail_page = READ_ONCE(cpu_buffer->tail_page);
@@ -2922,20 +2922,23 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
29222922

29232923
if (ring_buffer_time_stamp_abs(cpu_buffer->buffer)) {
29242924
info->delta = info->ts;
2925-
abs = true;
2925+
info->add_timestamp = RB_ADD_STAMP_ABSOLUTE;
29262926
} else {
29272927
info->delta = info->ts - after;
29282928
}
29292929

2930-
if (unlikely(test_time_stamp(info->delta)))
2931-
rb_handle_timestamp(cpu_buffer, info);
2930+
if (unlikely(test_time_stamp(info->delta))) {
2931+
rb_check_timestamp(cpu_buffer, info);
2932+
info->add_timestamp |= RB_ADD_STAMP_EXTEND;
2933+
}
29322934

29332935
/*
29342936
* If interrupting an event time update, we may need an absolute timestamp.
29352937
* Don't bother if this is the start of a new page (w == 0).
29362938
*/
29372939
if (unlikely(before != after && w))
2938-
info->add_timestamp = RB_ADD_STAMP_FORCE;
2940+
info->add_timestamp |= RB_ADD_STAMP_FORCE | RB_ADD_STAMP_EXTEND;
2941+
29392942
/*
29402943
* If the time delta since the last event is too big to
29412944
* hold in the time field of the event, then we append a
@@ -2972,7 +2975,8 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
29722975
/*D*/ local64_set(&cpu_buffer->write_stamp, info->ts);
29732976
barrier();
29742977
/*E*/ save_before = local64_read(&cpu_buffer->before_stamp);
2975-
if (likely(info->add_timestamp != RB_ADD_STAMP_FORCE))
2978+
if (likely(!(info->add_timestamp &
2979+
(RB_ADD_STAMP_FORCE | RB_ADD_STAMP_ABSOLUTE))))
29762980
/* This did not interrupt any time update */
29772981
info->delta = info->ts - after;
29782982
else
@@ -3015,15 +3019,15 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
30153019
*/
30163020
info->delta = 0;
30173021
}
3018-
if (info->add_timestamp == RB_ADD_STAMP_FORCE)
3019-
info->add_timestamp = RB_ADD_STAMP_NORMAL;
3022+
info->add_timestamp &= ~RB_ADD_STAMP_FORCE;
30203023
}
30213024

30223025
/*
30233026
* If this is the first commit on the page, then it has the same
30243027
* timestamp as the page itself.
30253028
*/
3026-
if (unlikely(!tail && info->add_timestamp != RB_ADD_STAMP_FORCE && !abs))
3029+
if (unlikely(!tail && !(info->add_timestamp &
3030+
(RB_ADD_STAMP_FORCE | RB_ADD_STAMP_ABSOLUTE))))
30273031
info->delta = 0;
30283032

30293033
/* We reserved something on the buffer */

0 commit comments

Comments
 (0)