perf events: Add time-of-day to perf samples
cover perf events: Add time-of-day to perf samples
Rather than collecting data to correlate the perf_clock timestamps to time-of-day this approach adds the realtime clock value directly to the perf sample.
David Ahern (5):
perf events: add support for realtime clock attribute perf events: userspace plumbing for realtime sample attribute perf record: add time-of-day option
perf script: add support for time-of-day strings in output perf python: add REALTIME to constants
include/linux/perf_event.h | 4 +- kernel/perf_event.c | 12 ++++ tools/perf/Documentation/perf-record.txt | 4 ++ tools/perf/Documentation/perf-script.txt | 8 +++- tools/perf/builtin-record.c | 5 ++ tools/perf/builtin-script.c | 84 +++++++++++++++++++++++++++++- tools/perf/util/event.c | 1 + tools/perf/util/event.h | 1 + tools/perf/util/evsel.c | 10 ++++ tools/perf/util/python.c | 1 + tools/perf/util/session.c | 6 ++ 11 files changed, 133 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.4
PATCH 1/5 perf events: add support for realtime clock attribute
Kernel side plumbing for PERF_SAMPLE_REALTIME.
--- include/linux/perf_event.h | 4 +++- kernel/perf_event.c | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletions(-)
include/linux/perf_event.h +3 -1
@@ -125,8 +125,9 @@ enum perf_event_sample_format {PERF_SAMPLE_PERIOD =1U <<8 ,PERF_SAMPLE_STREAM_ID =1U <<9 ,PERF_SAMPLE_RAW =1U <<10 , +PERF_SAMPLE_REALTIME =1U <<11 , - PERF_SAMPLE_MAX = 1U << 11, /* non-ABI */ + PERF_SAMPLE_MAX = 1U << 12, /* non-ABI */ };/*
@@ -998,6 +999,7 @@ struct perf_sample_data {u32 cpu;u32 reserved; } cpu_entry; +u64 realtime;u64 period;struct perf_callchain_entry *callchain;struct perf_raw_record *raw;
kernel/perf_event.c +12 -0
@@ -903,6 +903,9 @@ static void perf_event__id_header_size(struct perf_event *event)if (sample_type &PERF_SAMPLE_CPU ) size +=sizeof (data->cpu_entry); +if (sample_type &PERF_SAMPLE_REALTIME ) + size +=sizeof (data->realtime); + event->id_header_size = size; }
@@ -4016,6 +4019,9 @@ static void __perf_event_header__init_id(struct perf_event_header *header, data->cpu_entry.cpu =raw_smp_processor_id (); data->cpu_entry.reserved =0 ; } + +if (sample_type &PERF_SAMPLE_REALTIME ) + data->realtime =ktime_to_ns (ktime_get_real ()); } static void perf_event_header__init_id(struct perf_event_header *header,
@@ -4045,6 +4051,9 @@ static void __perf_event__output_id_sample(struct perf_output_handle *handle,if (sample_type &PERF_SAMPLE_CPU )perf_output_put (handle, data->cpu_entry); + +if (sample_type &PERF_SAMPLE_REALTIME ) +perf_output_put (handle, data->realtime); } static void perf_event__output_id_sample(struct perf_event *event,
@@ -4289,6 +4298,9 @@ void perf_output_sample(struct perf_output_handle *handle,if (sample_type &PERF_SAMPLE_CPU )perf_output_put (handle, data->cpu_entry); +if (sample_type &PERF_SAMPLE_REALTIME ) +perf_output_put (handle, data->realtime); +if (sample_type &PERF_SAMPLE_PERIOD )perf_output_put (handle, data->period);
Signature · 1 line
1.7.4
Re: [PATCH 1/5] perf events: add support for realtime clock attribute
kernel/perf_event.c static void __perf_event_header__init_id(struct perf_event_header *header, · line 4024
Quoted 3 lines · David Ahern
kernel/perf_event.c +3
-0+ +if (sample_type &PERF_SAMPLE_REALTIME ) + data->realtime =ktime_to_ns (ktime_get_real ());
That's going to live lock on any sample which happens to hit in a xtime_lock write locked section. I knew why I suggested adding tracepoints to the timekeeping code :)
Thanks,
tglx
Re: [PATCH 1/5] perf events: add support for realtime clock attribute
Quoted 8 lines · Thomas Gleixner
kernel/perf_event.c static void __perf_event_header__init_id(struct perf_event_header *header, · line 4024
Quoted 3 lines · David Ahern
kernel/perf_event.c +3
-0+ +if (sample_type &PERF_SAMPLE_REALTIME ) + data->realtime =ktime_to_ns (ktime_get_real ());That's going to live lock on any sample which happens to hit in a
xtime_lockwrite locked section. I knew why I suggested adding tracepoints to the timekeeping code :)
Hmmm.... Can you give an example of when perf samples could be generated with xtime write locked? What are the rules for when ktime_get_real can be invoked?
David
Quoted 4 lines
Thanks,
tglx
Re: [PATCH 1/5] perf events: add support for realtime clock attribute
Quoted 12 lines · David Ahern
Quoted 8 lines · Thomas Gleixner
kernel/perf_event.c static void __perf_event_header__init_id(struct perf_event_header *header, · line 4024
Quoted 3 lines · David Ahern
kernel/perf_event.c +3
-0+ +if (sample_type &PERF_SAMPLE_REALTIME ) + data->realtime =ktime_to_ns (ktime_get_real ());That's going to live lock on any sample which happens to hit in a
xtime_lockwrite locked section. I knew why I suggested adding tracepoints to the timekeeping code :)
Quoted 2 lines
Hmmm.... Can you give an example of when perf samples could be generated with xtime write locked?
NMI triggered samples can hit at any time.
Any tracepoint which we might add to the time keeping code inside the xtime locked regions. And I don't want to see a restriction there.
Quoted 1 line
What are the rules for when
ktime_get_realcan be invoked?
Outside of xtime write locked regions.
Thanks,
tglx
PATCH 2/5 perf events: userspace plumbing for realtime sample attribute
In reply to David Ahern--- tools/perf/util/event.c | 1 + tools/perf/util/event.h | 1 + tools/perf/util/evsel.c | 10 ++++++++++ tools/perf/util/session.c | 6 ++++++ 4 files changed, 18 insertions(+), 0 deletions(-)
tools/perf/util/event.c +1 -0
@@ -39,6 +39,7 @@ static struct perf_sample synth_sample = { .pid = -1, .tid = -1, .time = -1, + .realtime = -1, .stream_id = -1, .cpu = -1, .period = 1,
tools/perf/util/event.h +1 -0
@@ -65,6 +65,7 @@ struct perf_sample {u64 ip;u32 pid, tid;u64 time; +u64 realtime;u64 addr;u64 id;u64 stream_id;
tools/perf/util/evsel.c +10 -0
@@ -286,6 +286,11 @@ static int perf_event__parse_id_sample(const union perf_event *event, u64 type, array += ((event->header.size -sizeof (event->header)) /sizeof (u64)) -1 ; +if (type &PERF_SAMPLE_REALTIME ) { + sample->realtime = *array; + array--; + } +if (type &PERF_SAMPLE_CPU ) {u32 *p = (u32 *)array; sample->cpu = *p;
@@ -371,6 +376,11 @@ int perf_event__parse_sample(const union perf_event *event, u64 type, array++; } +if (type &PERF_SAMPLE_REALTIME ) { + data->realtime = *array; + array++; + } +if (type &PERF_SAMPLE_PERIOD ) { data->period = *array; array++;
tools/perf/util/session.c +6 -0
@@ -90,6 +90,9 @@ static void perf_session__id_header_size(struct perf_session *session)if (sample_type &PERF_SAMPLE_CPU ) size +=sizeof (data->cpu) *2 ; + +if (sample_type &PERF_SAMPLE_REALTIME ) + size +=sizeof (data->realtime); out: session->id_hdr_size = size; }
@@ -658,6 +661,9 @@ static void perf_session__print_tstamp(struct perf_session *session,if (session->sample_type &PERF_SAMPLE_TIME )printf ("%" PRIu64" " , sample->time); + +if (session->sample_type &PERF_SAMPLE_REALTIME ) +printf ("%" PRIu64" " , sample->realtime); } static void dump_event(struct perf_session *session, union perf_event *event,
Signature · 1 line
1.7.4
PATCH 3/5 perf record: add time-of-day option
In reply to David Ahern--- tools/perf/Documentation/perf-record.txt | 4 ++++ tools/perf/builtin-record.c | 5 +++++ 2 files changed, 9 insertions(+), 0 deletions(-)
tools/perf/Documentation/perf-record.txt +4 -0
@@ -116,6 +116,10 @@ OPTIONS Sample timestamps. Use it with 'perf report -D' to see the timestamps, for instance. +--tod:: + Collect data for time-of-day strings when printing events. This option + adds the realtime attribute to samples. + -n:: --no-samples:: Don't sample.
tools/perf/builtin-record.c +5 -0
@@ -53,6 +53,7 @@ static bool nodelay = false;static bool raw_samples = false;static bool sample_id_all_avail = true;static bool system_wide = false; +static bool want_tod = false;static pid_t target_pid =-1 ;static pid_t target_tid =-1 ;static pid_t child_pid =-1 ;
@@ -214,6 +215,9 @@ static void config_attr(struct perf_evsel *evsel, struct perf_evlist *evlist) attr->sample_type |=PERF_SAMPLE_CPU ; } +if (want_tod) + attr->sample_type |=PERF_SAMPLE_REALTIME ; +if (nodelay) { attr->watermark =0 ; attr->wakeup_events =1 ;
@@ -764,6 +768,7 @@ const struct option record_options[] = {OPT_BOOLEAN ('d' ,"data" , &sample_address,"Sample addresses" ),OPT_BOOLEAN ('T' ,"timestamp" , &sample_time,"Sample timestamps" ), +OPT_BOOLEAN (0 ,"tod" , &want_tod,"Collect data for Time-of-day strings." ),OPT_BOOLEAN ('n' ,"no-samples" , &no_samples,"don't sample" ), OPT_BOOLEAN('N', "no-buildid-cache", &no_buildid_cache,
Signature · 1 line
1.7.4
PATCH 4/5 perf script: add support for time-of-day strings in output
In reply to David AhernFormat of time-of-day strings handled through strftime. Any format recognized by it can be used. Default format is %H:%M:%S with microseconds appended.
--- tools/perf/Documentation/perf-script.txt | 8 +++- tools/perf/builtin-script.c | 84 +++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-script.txt +7 -1
@@ -115,7 +115,7 @@ OPTIONS -f:: --fields Comma separated list of fields to print. Options are: - comm, tid, pid, time, cpu, event, trace, sym. Field + tod, comm, tid, pid, time, cpu, event, trace, sym. Field list must be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -f sw:comm,tid,time,sym and -f trace:time,cpu,trace
@@ -134,6 +134,12 @@ OPTIONS --hide-call-graph:: When printing symbols do not display call chain. +--tod:: + Format for time-of-day strings. Format string is passed to + strftime, so any format recognized by it can be used (see + man strftime). Default format is "%H:%M:%S". Microseocnds + are appended to the time string. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +83 -1
136 lines not on this page · raw message
Signature · 1 line
1.7.4
PATCH 5/5 perf python: add REALTIME to constants
In reply to David Ahern--- tools/perf/util/python.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
tools/perf/util/python.c +1 -0
@@ -827,6 +827,7 @@ static struct { { "SAMPLE_CALLCHAIN", PERF_SAMPLE_CALLCHAIN }, { "SAMPLE_ID", PERF_SAMPLE_ID }, { "SAMPLE_CPU", PERF_SAMPLE_CPU }, + { "SAMPLE_REALTIME", PERF_SAMPLE_REALTIME }, { "SAMPLE_PERIOD", PERF_SAMPLE_PERIOD }, { "SAMPLE_STREAM_ID", PERF_SAMPLE_STREAM_ID }, { "SAMPLE_RAW", PERF_SAMPLE_RAW },
Signature · 1 line
1.7.4