ring-buffer: Allow ring_buffer_event_time_stamp() to return time stamp of all events
Currently, ring_buffer_event_time_stamp() only returns an accurate time stamp of the event if it has an absolute extended time stamp attached to it. To make it more robust, use the event_stamp() in case the event does not have an absolute value attached to it. This will allow ring_buffer_event_time_stamp() to be used in more cases than just histograms, and it will also allow histograms to not require including absolute values all the time. Link: https://lkml.kernel.org/r/20210316164113.704830885@goodmis.org Reviewed-by: Tom Zanussi <zanussi@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
This commit is contained in:
parent
b47e330231
commit
efe6196a6b
|
@ -61,7 +61,8 @@ enum ring_buffer_type {
|
||||||
|
|
||||||
unsigned ring_buffer_event_length(struct ring_buffer_event *event);
|
unsigned ring_buffer_event_length(struct ring_buffer_event *event);
|
||||||
void *ring_buffer_event_data(struct ring_buffer_event *event);
|
void *ring_buffer_event_data(struct ring_buffer_event *event);
|
||||||
u64 ring_buffer_event_time_stamp(struct ring_buffer_event *event);
|
u64 ring_buffer_event_time_stamp(struct trace_buffer *buffer,
|
||||||
|
struct ring_buffer_event *event);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ring_buffer_discard_commit will remove an event that has not
|
* ring_buffer_discard_commit will remove an event that has not
|
||||||
|
|
|
@ -298,21 +298,6 @@ static u64 rb_event_time_stamp(struct ring_buffer_event *event)
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ring_buffer_event_time_stamp - return the event's extended timestamp
|
|
||||||
* @event: the event to get the timestamp of
|
|
||||||
*
|
|
||||||
* Returns the extended timestamp associated with a data event.
|
|
||||||
* An extended time_stamp is a 64-bit timestamp represented
|
|
||||||
* internally in a special way that makes the best use of space
|
|
||||||
* contained within a ring buffer event. This function decodes
|
|
||||||
* it and maps it to a straight u64 value.
|
|
||||||
*/
|
|
||||||
u64 ring_buffer_event_time_stamp(struct ring_buffer_event *event)
|
|
||||||
{
|
|
||||||
return rb_event_time_stamp(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Flag when events were overwritten */
|
/* Flag when events were overwritten */
|
||||||
#define RB_MISSED_EVENTS (1 << 31)
|
#define RB_MISSED_EVENTS (1 << 31)
|
||||||
/* Missed count stored at end */
|
/* Missed count stored at end */
|
||||||
|
@ -757,6 +742,51 @@ static bool rb_time_cmpxchg(rb_time_t *t, u64 expect, u64 set)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline u64 rb_time_stamp(struct trace_buffer *buffer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ring_buffer_event_time_stamp - return the event's current time stamp
|
||||||
|
* @buffer: The buffer that the event is on
|
||||||
|
* @event: the event to get the time stamp of
|
||||||
|
*
|
||||||
|
* Note, this must be called after @event is reserved, and before it is
|
||||||
|
* committed to the ring buffer. And must be called from the same
|
||||||
|
* context where the event was reserved (normal, softirq, irq, etc).
|
||||||
|
*
|
||||||
|
* Returns the time stamp associated with the current event.
|
||||||
|
* If the event has an extended time stamp, then that is used as
|
||||||
|
* the time stamp to return.
|
||||||
|
* In the highly unlikely case that the event was nested more than
|
||||||
|
* the max nesting, then the write_stamp of the buffer is returned,
|
||||||
|
* otherwise current time is returned, but that really neither of
|
||||||
|
* the last two cases should ever happen.
|
||||||
|
*/
|
||||||
|
u64 ring_buffer_event_time_stamp(struct trace_buffer *buffer,
|
||||||
|
struct ring_buffer_event *event)
|
||||||
|
{
|
||||||
|
struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[smp_processor_id()];
|
||||||
|
unsigned int nest;
|
||||||
|
u64 ts;
|
||||||
|
|
||||||
|
/* If the event includes an absolute time, then just use that */
|
||||||
|
if (event->type_len == RINGBUF_TYPE_TIME_STAMP)
|
||||||
|
return rb_event_time_stamp(event);
|
||||||
|
|
||||||
|
/* Read the current saved nesting level time stamp */
|
||||||
|
nest = local_read(&cpu_buffer->committing) - 1;
|
||||||
|
if (likely(nest < MAX_NEST))
|
||||||
|
return cpu_buffer->event_stamp[nest];
|
||||||
|
|
||||||
|
WARN_ON_ONCE(1);
|
||||||
|
|
||||||
|
/* Can only fail on 32 bit */
|
||||||
|
if (!rb_time_read(&cpu_buffer->write_stamp, &ts))
|
||||||
|
/* Screw it, just read the current time */
|
||||||
|
ts = rb_time_stamp(cpu_buffer->buffer);
|
||||||
|
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ring_buffer_nr_pages - get the number of buffer pages in the ring buffer
|
* ring_buffer_nr_pages - get the number of buffer pages in the ring buffer
|
||||||
* @buffer: The ring_buffer to get the number of pages from
|
* @buffer: The ring_buffer to get the number of pages from
|
||||||
|
|
|
@ -644,7 +644,7 @@ static u64 hist_field_timestamp(struct hist_field *hist_field,
|
||||||
struct hist_trigger_data *hist_data = hist_field->hist_data;
|
struct hist_trigger_data *hist_data = hist_field->hist_data;
|
||||||
struct trace_array *tr = hist_data->event_file->tr;
|
struct trace_array *tr = hist_data->event_file->tr;
|
||||||
|
|
||||||
u64 ts = ring_buffer_event_time_stamp(rbe);
|
u64 ts = ring_buffer_event_time_stamp(buffer, rbe);
|
||||||
|
|
||||||
if (hist_data->attrs->ts_in_usecs && trace_clock_in_ns(tr))
|
if (hist_data->attrs->ts_in_usecs && trace_clock_in_ns(tr))
|
||||||
ts = ns2usecs(ts);
|
ts = ns2usecs(ts);
|
||||||
|
|
Loading…
Reference in New Issue