trace-cmd: Timetamps sync between host and guest machines, relying on vsock events.
v12 cover trace-cmd: Timetamps sync between host and guest machines, relying on vsock events.
POC implementation of algorithm for timestamps sync between guest and host machines. The algorithm relies on matching time stamps of guest and host vsock events.
The patch series depends on Slavomir's changes, introduced by the v13 patch series "Add VM kernel tracing over vsockets and FIFOs"
[
v12 changes:
- Rebased on top of Slavomir's v13 "Add VM kernel tracing over vsockets and FIFOs"
v11 changes:
- Rebased on top of Slavomir's v10 "Add VM kernel tracing over vsockets and FIFOs"
- Addressed Slavomir's commnents from version 10 of the patch series.
v10 changes:
- Fixed broken compilation, call to timestamp_correction_calc() in timestamp_correct was smashed.
- Replaced deprecated tep_data_event_from_type() API with tep_find_event().
- Fixed a warning on assignment const to non const.
v9 changes:
- Fixed implementation of binary search algorithm in timestamp_correct()
v8 changes:
- Added rmdir() call in tracecmd_remove_instance(), to completely remove the instance. However, there is an issue with deleting the instances using rmdir(), which is investigated.
- Few changes in read_qemu_guests_pids(), timestamp_correct(), tsync_offset_load()
tracecmd_clock_context_new() and find_raw_events() suggested by Slavomir.
v7 changes:
- Added warning messages in case time synchronization cannot be negotiated or fails.
- Few optimizations and checks in read_qemu_guests_pids(), tsync_offset_load(), and find_raw_events(), suggested by Slavomir Kaslev.
- Reworked timestamp_correct() to not use static variables.
- Check TRACECMD_OPTION_TIME_SHIFT before reading time sync samples from the trace.dat file
v6 changes:
- Refactored tracecmd_msg_snd_time_sync() and tracecmd_msg_rcv_time_sync() functions:
removed any time sync calculations logic as separate functions in trace-timesync.c file
- Defined TSYNC_PROBE, TSYNC_REQ and TSYNC_RESP messages, in order to make the time sync protocol comprehensible.
- Addressed Steven Rostedt comments.
- Addressed Slavomir Kaslev commnets.
v5 changes:
- Rebased to Slavomir's v8 "Add VM kernel tracing over vsockets and FIFOs" patch series.
- Implemented an algorithm for time drift correction.
- Addressed Slavomir's commnets.
- Refactored the code: moved all time sync specific implementation in trace-timesync.c
- Isolated all hardcoded event specific stuff in a structure, so it could be easily moved to external plugins.
- Added a check for VSOCK support: do not perform vsock dependent time synchronisation in case there is no VSOCK support.
v4 changes:
- Removed the implementation of PTP-like algorithm. The current logic relies on matching time stamps of kvm_exit/virtio_transport_recv_pkt events on host to virtio_transport_alloc_pkt/vp_notify events on guest.
- Rebased to Slavomir's v7 "Add VM kernel tracing over vsockets and FIFOs" patch series.
- Decreased the time synch probes from 5000 to 300.
- Addressed Steven Rostedt comments.
- Code cleanup.
v3 changes:
- Removed any magic constants, used in the PTP-like algorithm, as Slavomir Kaslev suggested.
- Implemented new algorithm, based on mapping kvm_exit events in host context to vsock_send events in guest context, suggested by Steven Rostedt.
v2 changes:
- Addressed Steven Rostedt comments.
- Modified PTP-like timestamps sync algorithm to gain more accuracy, with the help of Yordan Karadzhov and Slavomir Kaslev.
]
Tzvetomir Stoyanov (9):
trace-cmd: Implemented new lib API: tracecmd_local_events_system()
trace-cmd: Added support for negative time offsets in trace.dat file
trace-cmd: Fix tracecmd_read_page_record() to read more than one event
trace-cmd: Added implementation of htonll() and ntohll()
trace-cmd: Refactored few functions in trace-record.c
trace-cmd: Find and store pids of tasks, which run virtual CPUs of
given VM
trace-cmd: Implemented new API tracecmd_add_option_v()
trace-cmd: Implemented new option in trace.dat file:
TRACECMD_OPTION_TIME_SHIFT
trace-cmd [POC]: Implemented timestamps synch algorithm, using vsock
events.
include/trace-cmd/trace-cmd.h | 30 +- include/traceevent/event-parse.h | 1 + lib/trace-cmd/trace-input.c | 145 +++++- lib/trace-cmd/trace-util.c | 98 ++-- tracecmd/Makefile | 1 + tracecmd/include/trace-local.h | 42 +- tracecmd/include/trace-msg.h | 10 + tracecmd/trace-agent.c | 13 +- tracecmd/trace-msg.c | 210 +++++++- tracecmd/trace-output.c | 114 ++++- tracecmd/trace-read.c | 4 +- tracecmd/trace-record.c | 224 +++++++-- tracecmd/trace-timesync.c | 810 +++++++++++++++++++++++++++++++ 13 files changed, 1571 insertions(+), 131 deletions(-) create mode 100644 tracecmd/trace-timesync.c
Signature · 1 line
2.21.0
PATCH v12 1/9 trace-cmd: Implemented new lib API: tracecmd_local_events_system()
From: Tzvetomir Stoyanov <[email protected]>
The new tracecmd lib API tracecmd_local_events_system() creates a tep handler and initializes it with the events of the specified subsystems.
--- include/trace-cmd/trace-cmd.h | 2 + lib/trace-cmd/trace-util.c | 98 ++++++++++++++++++++++++----------- 2 files changed, 69 insertions(+), 31 deletions(-)
include/trace-cmd/trace-cmd.h +2 -0
@@ -32,6 +32,8 @@ void tracecmd_unload_plugins(struct tep_plugin_list *list, struct tep_handle *pechar **tracecmd_event_systems (const char *tracing_dir);char **tracecmd_system_events (const char *tracing_dir,const char *system);struct tep_handle *tracecmd_local_events (const char *tracing_dir); +struct tep_handle *tracecmd_local_events_system (const char *tracing_dir, +const char *const *sys_names);int tracecmd_fill_local_events (const char *tracing_dir,struct tep_handle *pevent,int *parsing_failures);char **tracecmd_local_plugins (const char *tracing_dir);
lib/trace-cmd/trace-util.c +67 -31
119 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH v12 1/9] trace-cmd: Implemented new lib API: tracecmd_local_events_system()
Quoted 1 line · On Wed, 28 Aug 2019 11:57:38 +0300 "Tzvetomir Stoyanov (VMware)"…
From: Tzvetomir Stoyanov <[email protected]>
Hi Ceco,
Nit on the subject. s/Implemented/Implement/. Same for all the other patches.
Quoted 46 lines
The new tracecmd lib API
tracecmd_local_events_system()creates a tep handler and initializes it with the events of the specified subsystems.Signed-off-by Tzvetomir Stoyanov <[email protected]>--- include/trace-cmd/trace-cmd.h | 2 + lib/trace-cmd/trace-util.c | 98 ++++++++++++++++++++++++----------- 2 files changed, 69 insertions(+), 31 deletions(-)include/trace-cmd/trace-cmd.h +2
-0@@ -32,6 +32,8 @@ void tracecmd_unload_plugins(struct tep_plugin_list *list, struct tep_handle *pechar **tracecmd_event_systems (const char *tracing_dir);char **tracecmd_system_events (const char *tracing_dir,const char *system);struct tep_handle *tracecmd_local_events (const char *tracing_dir); +struct tep_handle *tracecmd_local_events_system (const char *tracing_dir, +const char *const *sys_names);int tracecmd_fill_local_events (const char *tracing_dir,struct tep_handle *pevent,int *parsing_failures);char **tracecmd_local_plugins (const char *tracing_dir);lib/trace-cmd/trace-util.c +1
-12@@ -1120,39 +1120,20 @@ static int read_header(struct tep_handle *pevent, const char *events_dir)return ret; } -/** -* tracecmd_local_events - create a pevent from the events on system -* @tracing_dir: The directory that contains the events. -* -* Returns a pevent structure that contains the pevents local to -* the system. -*/ -struct tep_handle *tracecmd_local_events (const char *tracing_dir) +static bool contains (const char *name,const char *const *names) { -struct tep_handle *pevent =NULL ; - - pevent =tep_alloc (); -if (!pevent)
lib/trace-cmd/trace-util.c static int read_header(struct tep_handle *pevent, const char *events_dir) · line 1126
Quoted 10 lines
lib/trace-cmd/trace-util.c +2
-8-return NULL ; - -if (tracecmd_fill_local_events (tracing_dir, pevent,NULL )) { -tep_free (pevent); - pevent =NULL ; - } - -return pevent; +if (!names) +return false;
OK, if name is NULL, then we return false.
Quoted 24 lines
lib/trace-cmd/trace-util.c +8
-10+for (; *names; names++) +if (strcmp (name, *names) ==0 ) +return true; +return false; } -/** -* tracecmd_fill_local_events - Fill a pevent with the events on system -* @tracing_dir: The directory that contains the events. -* @pevent: Allocated pevent which will be filled -* @parsing_failures: return number of failures while parsing the event files -* -* Returns whether the operation succeeded -*/ -int tracecmd_fill_local_events (const char *tracing_dir, -struct tep_handle *pevent,int *parsing_failures) +static int tracecmd_fill_local_events_system (const char *tracing_dir, +struct tep_handle *pevent, +const char *const *sys_names, +int *parsing_failures) {struct dirent *dent;char *events_dir;
lib/trace-cmd/trace-util.c int tracecmd_fill_local_events(const char *tracing_dir, · line 1179
Quoted 6 lines
lib/trace-cmd/trace-util.c +2
-1@@ -1194,7 +1175,8 @@ int tracecmd_fill_local_events(const char *tracing_dir,if (strcmp (name,"." ) ==0 ||strcmp (name,".." ) ==0 )continue ; - +if (!contains (name, sys_names)) +continue ;
Hmm, doesn't this mean that when we pass in NULL for sys_names, we don't list anything?
Quoted 46 lines
lib/trace-cmd/trace-util.c +39
-0sys =append_file (events_dir, name); ret =stat (sys, &st);if (ret <0 || !S_ISDIR (st.st_mode)) {@@ -1220,6 +1202,60 @@ int tracecmd_fill_local_events(const char *tracing_dir,return ret; } +/** +* tracecmd_local_events_system - create a tep from the events of the specified subsystem. +* +* @tracing_dir: The directory that contains the events. +* @sys_name: Array of system names, to load the events from. +* The last element from the array must be NULL +* +* Returns a tep structure that contains the tep local to +* the system. +*/ +struct tep_handle *tracecmd_local_events_system (const char *tracing_dir, +const char *const *sys_names) +{ +struct tep_handle *tep =NULL ; + + tep =tep_alloc (); +if (!tep) +return NULL ; + +if (tracecmd_fill_local_events_system (tracing_dir, tep, sys_names,NULL )) { +tep_free (tep); + tep =NULL ; + } + +return tep; +} + +/** +* tracecmd_local_events - create a pevent from the events on system +* @tracing_dir: The directory that contains the events. +* +* Returns a pevent structure that contains the pevents local to +* the system. +*/ +struct tep_handle *tracecmd_local_events (const char *tracing_dir) +{ +return tracecmd_local_events_system (tracing_dir,NULL ); +} +
lib/trace-cmd/trace-util.c int tracecmd_fill_local_events(const char *tracing_dir, · line 1253
Quoted 10 lines
lib/trace-cmd/trace-util.c +10
-0+/** +* tracecmd_fill_local_events - Fill a pevent with the events on system +* @tracing_dir: The directory that contains the events. +* @pevent: Allocated pevent which will be filled +* @parsing_failures: return number of failures while parsing the event files +* +* Returns whether the operation succeeded +*/ +int tracecmd_fill_local_events (const char *tracing_dir, +struct tep_handle *pevent,int *parsing_failures)
When we touch a function, we should s/pevent/tep/
lib/trace-cmd/trace-util.c int tracecmd_fill_local_events(const char *tracing_dir, · line 1256
Quoted 3 lines
lib/trace-cmd/trace-util.c +3
-0+{ +return tracecmd_fill_local_events_system (tracing_dir, pevent, +NULL , parsing_failures);
Won't this return no events?
-- Steve
Quoted 5 lines
lib/trace-cmd/trace-util.c +2
-0+} +/** * tracecmd_local_plugins - returns an array of available tracer plugins * @tracing_dir: The directory that contains the tracing directory
Re: [PATCH v12 1/9] trace-cmd: Implemented new lib API: tracecmd_local_events_system()
On Tue, Oct 22, 2019 at 7:34 PM Steven Rostedt <[email protected]> wrote:
...
Quoted 8 lines
lib/trace-cmd/trace-util.c int tracecmd_fill_local_events(const char *tracing_dir, · line 1256
Quoted 3 lines
lib/trace-cmd/trace-util.c +3
-0+{ +return tracecmd_fill_local_events_system (tracing_dir, pevent, +NULL , parsing_failures);Won't this return no events?
-- Steve
Looks like it will return no events, I'll review the logic and the patch.
Quoted 6 lines
Quoted 5 lines
lib/trace-cmd/trace-util.c +2
-0+} +/** * tracecmd_local_plugins - returns an array of available tracer plugins * @tracing_dir: The directory that contains the tracing directory
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov VMware Open Source Technology Center
PATCH v12 2/9 trace-cmd: Added support for negative time offsets in trace.dat file
In reply to Tzvetomir Stoyanov (VMware)From: Tzvetomir Stoyanov <[email protected]>
When synchronizing timestamps between different machines, there are cases when the time offset is negative. This patch changes the way time offset is written and read from trace.dat file - as signed decimal, instead of hex.
--- include/trace-cmd/trace-cmd.h | 2 +- lib/trace-cmd/trace-input.c | 6 +++--- tracecmd/trace-read.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
include/trace-cmd/trace-cmd.h +1 -1
@@ -129,7 +129,7 @@ int tracecmd_is_buffer_instance(struct tracecmd_input *handle);void tracecmd_create_top_instance (char *name);void tracecmd_remove_instances (void ); -void tracecmd_set_ts_offset (struct tracecmd_input *handle,unsigned long long offset); +void tracecmd_set_ts_offset (struct tracecmd_input *handle,long long offset);void tracecmd_set_ts2secs (struct tracecmd_input *handle,unsigned long long hz);void tracecmd_print_events (struct tracecmd_input *handle,const char *regex);
lib/trace-cmd/trace-input.c +3 -3
@@ -90,7 +90,7 @@ struct tracecmd_input {bool read_page;bool use_pipe;struct cpu_data *cpu_data; -unsigned long long ts_offset; +long long ts_offset;double ts2secs;char * cpustats;char * uname;
@@ -2121,7 +2121,7 @@ static int init_cpu(struct tracecmd_input *handle, int cpu) }void tracecmd_set_ts_offset (struct tracecmd_input *handle, -unsigned long long offset) +long long offset) { handle->ts_offset = offset; }
@@ -2138,7 +2138,7 @@ void tracecmd_set_ts2secs(struct tracecmd_input *handle,static int handle_options (struct tracecmd_input *handle) { -unsigned long long offset; +long long offset;unsigned short option;unsigned int size;char *cpustats =NULL ;
tracecmd/trace-read.c +2 -2
@@ -58,7 +58,7 @@ static struct list_head handle_list;struct input_files {struct list_head list;const char *file; -unsigned long long tsoffset; +long long tsoffset;unsigned long long ts2secs; };static struct list_head input_files;
@@ -1422,7 +1422,7 @@ void trace_report (int argc, char **argv)struct input_files *inputs;struct handle_list *handles;enum output_type otype; -unsigned long long tsoffset =0 ; +long long tsoffset =0 ;unsigned long long ts2secs =0 ;unsigned long long ts2sc;int show_stat =0 ;
Signature · 1 line
2.21.0
PATCH v12 3/9 trace-cmd: Fix tracecmd_read_page_record() to read more than one event
In reply to Tzvetomir Stoyanov (VMware)From: Tzvetomir Stoyanov <[email protected]>
The kbuffer_next_event() will return the next event on the sub buffer. If we pass in the last_record to tracecmd_read_page_record(), it initializes the sub buffer, and by calling kbuffer_next_event() (instead of kbuffer_read_event()), the second event on the sub buffer is returned. This causes the match of the last_record not to match if the last_record happens to be the first event on the sub buffer.
--- lib/trace-cmd/trace-input.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
lib/trace-cmd/trace-input.c +8 -4
@@ -1720,18 +1720,22 @@ tracecmd_read_page_record(struct tep_handle *pevent, void *page, int size, goto out_free; } -do { + ptr =kbuffer_read_event (kbuf, &ts); +while (ptr < last_record->data) { ptr =kbuffer_next_event (kbuf,NULL );if (!ptr)break ; - }while (ptr < last_record->data); +if (ptr == last_record->data) +break ; + }if (ptr != last_record->data) {warning ("tracecmd_read_page_record: could not find last_record" ); goto out_free; } - } + ptr =kbuffer_next_event (kbuf, &ts); + }else + ptr =kbuffer_read_event (kbuf, &ts); - ptr =kbuffer_read_event (kbuf, &ts);if (!ptr) goto out_free;
Signature · 1 line
2.21.0
Re: [PATCH v12 3/9] trace-cmd: Fix tracecmd_read_page_record() to read more than one event
Quoted 8 lines · On Wed, 28 Aug 2019 11:57:40 +0300 "Tzvetomir Stoyanov (VMware)"…
From: Tzvetomir Stoyanov <[email protected]>
The
kbuffer_next_event()will return the next event on the sub buffer. If we pass in thelast_recordtotracecmd_read_page_record(), it initializes the sub buffer, and by callingkbuffer_next_event()(instead ofkbuffer_read_event()), the second event on the sub buffer is returned. This causes the match of thelast_recordnot to match if thelast_recordhappens to be the first event on the sub buffer.
Bah, I see why this was done incorrectly. Good catch.
This should be added independent of this series.
Thanks!
-- Steve
PATCH v12 4/9 trace-cmd: Added implementation of htonll() and ntohll()
In reply to Tzvetomir Stoyanov (VMware)From: Tzvetomir Stoyanov <[email protected]>
Added implementation of htonll() and ntohll() as
macros, if they are not already defined.
--- tracecmd/include/trace-msg.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
tracecmd/include/trace-msg.h +10 -0
@@ -15,4 +15,14 @@ extern unsigned int page_size;void plog (const char *fmt, ...);void pdie (const char *fmt, ...); +#ifndef htonll +# if __BYTE_ORDER == __LITTLE_ENDIAN +#define htonll (x) __bswap_64(x) +#define ntohll (x) __bswap_64(x) +#else +#define htonll (x) (x) +#define ntohll (x) (x) +#endif +#endif +#endif /* _TRACE_MSG_H_ */
Signature · 1 line
2.21.0
PATCH v12 5/9 trace-cmd: Refactored few functions in trace-record.c
In reply to Tzvetomir Stoyanov (VMware)From: Tzvetomir Stoyanov <[email protected]>
In order to reuse the code inside the trace-cmd application, few functions from trace-record.c are refactored:
- make_instances() and tracecmd_remove_instances() are splited.
New ones are created: tracecmd_make_instance() and tracecmd_remove_instance(), which are visible outside the trace-record.c
- Following functions are made non-static: tracecmd_init_instance()get_instance_dir(), write_instance_file(), write_tracing_on(), tracecmd_set_clock()
- New function is implemented: tracecmd_local_cpu_count(), an internal
API to get local_cpu_count.
--- tracecmd/include/trace-local.h | 9 ++++ tracecmd/trace-record.c | 88 +++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 38 deletions(-)
tracecmd/include/trace-local.h +9 -0
@@ -237,6 +237,15 @@ void update_first_instance(struct buffer_instance *instance, int topt);void show_instance_file (struct buffer_instance *instance,const char *name);int count_cpus (void ); +void write_tracing_on (struct buffer_instance *instance,int on); +char *get_instance_dir (struct buffer_instance *instance); +int write_instance_file (struct buffer_instance *instance, +const char *file,const char *str,const char *type); +void tracecmd_init_instance (struct buffer_instance *instance); +void tracecmd_make_instance (struct buffer_instance *instance); +int tracecmd_local_cpu_count (void ); +void tracecmd_set_clock (struct buffer_instance *instance); +void tracecmd_remove_instance (struct buffer_instance *instance);/* No longer in event-utils.h */ void __noreturn die (const char *fmt, ...);/* Can be overriden */
tracecmd/trace-record.c +50 -38
190 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH v12 5/9] trace-cmd: Refactored few functions in trace-record.c
Quoted 1 line · On Wed, 28 Aug 2019 11:57:42 +0300 "Tzvetomir Stoyanov (VMware)"…
From: Tzvetomir Stoyanov <[email protected]>
Patch looks good. Just need some fixes in the change log.
Subject: "trace-cmd: Refactored some functions in trace-record.c"
Quoted 2 lines
In order to reuse the code inside the trace-cmd application, few
"a few"
Quoted 2 lines
functions from
trace-record.care refactored:
-make_instances()andtracecmd_remove_instances()are splited.
"are split"
Quoted 1 line
New ones are created:
tracecmd_make_instance()andtracecmd_remove_instance(),
"Following functions were added to export static functionality:
tracecmd_make_instance() tracecmd_remove_instance()"
Quoted 1 line
which are visible outside the
trace-record.c
"outside of trace-record.c"
Quoted 3 lines
- Following functions are made non-static:
tracecmd_init_instance()get_instance_dir(),write_instance_file(),write_tracing_on(),tracecmd_set_clock()
Make the above more a visible list.
- The following functions are made non-static:
tracecmd_init_instance() get_instance_dir() write_instance_file() write_tracing_on() tracecmd_set_clock()
And don't be afraid to add empty lines between these bullet points. It makes it easier to read. Whitespace can be your friend ;-)
Quoted 2 lines
- New function is implemented:
tracecmd_local_cpu_count(), an internal
API to getlocal_cpu_count.
Turn the above into:
- Created a new function:
tracecmd_local_cpu_count() - an internal API to get the
local_cpu_count.
Note, if you do bullet lists, please keep everything aligned, and space out the bullet list.
Instead of:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Following functions are made non-static: tracecmd_init_instance()get_instance_dir(), write_instance_file(), write_tracing_on(), tracecmd_set_clock()
- New function is implemented: tracecmd_local_cpu_count(), an internal
API to get local_cpu_count.
<<<<
Have:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Following functions are made non-static: tracecmd_init_instance() get_instance_dir(), write_instance_file(), write_tracing_on(), tracecmd_set_clock()
- New function is implemented: tracecmd_local_cpu_count(), an internal API to get local_cpu_count.
<<<<
Much easier to read.
Proper spacing is critical for change logs. It makes things stand out much easier when scanning a "git log" looking for something specific. When there's a lot of text bound together, it's much harder to find something unless you know exactly what to search for via a search string.
Thanks!
-- Steve
Quoted 7 lines
Signed-off-by Tzvetomir Stoyanov <[email protected]>--- tracecmd/include/trace-local.h | 9 ++++ tracecmd/trace-record.c | 88 +++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 38 deletions(-)
PATCH v12 6/9 trace-cmd: Find and store pids of tasks, which run virtual CPUs of given VM
In reply to Tzvetomir Stoyanov (VMware)From: Tzvetomir Stoyanov <[email protected]>
In order to match host and guest events, a mapping between guest VCPU and the host task, running this VCPU is needed. Extended existing struct guest to hold such mapping and added logic in read_qemu_guests() function to initialize it. Implemented a new internal API, get_guest_vcpu_pid(), to retrieve VCPU-task mapping for given VM.
--- tracecmd/include/trace-local.h | 1 + tracecmd/trace-record.c | 57 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
tracecmd/include/trace-local.h +1 -0
@@ -247,6 +247,7 @@ int tracecmd_local_cpu_count(void);void tracecmd_set_clock (struct buffer_instance *instance);void tracecmd_remove_instance (struct buffer_instance *instance); +int get_guest_vcpu_pid (unsigned int guest_cid,unsigned int guest_vcpu);/* No longer in event-utils.h */ void __noreturn die (const char *fmt, ...);/* Can be overriden */ void *malloc_or_die (unsigned int size);/* Can be overridden */
tracecmd/trace-record.c +57 -0
85 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v12 7/9 trace-cmd: Implemented new API tracecmd_add_option_v()
In reply to Tzvetomir Stoyanov (VMware)From: Tzvetomir Stoyanov <[email protected]>
This patch implements a new tracecmd API, tracecmd_add_option_v() It adds new option in trace.dat, similar to tracecmd_add_option(), but the option's data is passed as list of buffers. The standard struct iovec is used as input parameter, containing the option's data buffers.
--- include/trace-cmd/trace-cmd.h | 5 ++ include/traceevent/event-parse.h | 1 + tracecmd/trace-output.c | 114 +++++++++++++++++++++++++++---- 3 files changed, 105 insertions(+), 15 deletions(-)
include/trace-cmd/trace-cmd.h +5 -0
@@ -249,11 +249,16 @@ struct tracecmd_output *tracecmd_create_init_file_override(const char *output_fistruct tracecmd_option *tracecmd_add_option (struct tracecmd_output *handle,unsigned short id,int size,const void *data); +struct tracecmd_option * +tracecmd_add_option_v (struct tracecmd_output *handle, +unsigned short id,const struct iovec *vector,int count); +struct tracecmd_option *tracecmd_add_buffer_option (struct tracecmd_output *handle,const char *name,int cpus);int tracecmd_write_cpus (struct tracecmd_output *handle,int cpus);int tracecmd_write_options (struct tracecmd_output *handle); +int tracecmd_append_options (struct tracecmd_output *handle);int tracecmd_update_option (struct tracecmd_output *handle,struct tracecmd_option *option,int size,const void *data);
include/traceevent/event-parse.h +1 -0
@@ -11,6 +11,7 @@#include <stdio.h> #include <regex.h> #include <string.h> +#include <sys/uio.h> #include "traceevent/trace-seq.h"
tracecmd/trace-output.c +99 -15
159 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH v12 7/9] trace-cmd: Implemented new API tracecmd_add_option_v()
Quoted 8 lines · On Wed, 28 Aug 2019 11:57:44 +0300 "Tzvetomir Stoyanov (VMware)"…
tracecmd/trace-output.c +8
-0+/** +* tracecmd_add_option - add options to the file +* @handle: the output file handle name +* @id: the id of the option +* @size: the size of the option data +* @data: the data to write to the file. +* +* Returns handle to update option if needed.
tracecmd/trace-output.c tracecmd_add_option(struct tracecmd_output *handle, · line 964
Quoted 10 lines
tracecmd/trace-output.c +10
-0+* Just the content can be updated, with smaller or equal to +* content than the specified size. +*/ +struct tracecmd_option * +tracecmd_add_option (struct tracecmd_output *handle, +unsigned short id,int size,const void *data) +{ +struct iovec vect; + + vect.iov_base = (void *) data;
Remove the space between (void *) and data.
tracecmd/trace-output.c int tracecmd_write_options(struct tracecmd_output *handle) · line 1016
Quoted 12 lines
tracecmd/trace-output.c +5
-0+ vect.iov_len = size; +return tracecmd_add_option_v (handle, id, &vect,1 ); +} +int tracecmd_write_cpus (struct tracecmd_output *handle,int cpus) { cpus =convert_endian_4 (handle, cpus);@@ -979,6 +1013,56 @@ int tracecmd_write_options(struct tracecmd_output *handle)return 0 ; } +int tracecmd_append_options (struct tracecmd_output *handle)
Hmm, this was added with no users, and was not mentioned in the change log. Probably belongs in another patch.
-- Steve
Quoted 52 lines
tracecmd/trace-output.c +49
-0+{ +struct tracecmd_option *options; +unsigned short option; +unsigned short endian2; +unsigned int endian4; +off_t offset; +int r; + +/* If already written, ignore */ +if (handle->options_written) +return 0 ; + +if (lseek64 (handle->fd,0 ,SEEK_END ) == (off_t)-1 ) +return -1 ; + offset =lseek64 (handle->fd,-2 ,SEEK_CUR ); +if (offset == (off_t)-1 ) +return -1 ; + + r =pread (handle->fd, &option,2 , offset); +if (r !=2 || option !=TRACECMD_OPTION_DONE ) +return -1 ; + +list_for_each_entry (options, &handle->options, list) { + endian2 =convert_endian_2 (handle, options->id); +if (do_write_check (handle, &endian2,2 )) +return -1 ; + + endian4 =convert_endian_4 (handle, options->size); +if (do_write_check (handle, &endian4,4 )) +return -1 ; + +/* Save the data location in case it needs to be updated */ + options->offset =lseek64 (handle->fd,0 ,SEEK_CUR ); + +if (do_write_check (handle, options->data, + options->size)) +return -1 ; + } + + option =TRACECMD_OPTION_DONE ; + +if (do_write_check (handle, &option,2 )) +return -1 ; + + handle->options_written =1 ; + +return 0 ; +} +int tracecmd_update_option (struct tracecmd_output *handle,struct tracecmd_option *option,int size,const void *data)
PATCH v12 8/9 trace-cmd: Implemented new option in trace.dat file: TRACECMD_OPTION_TIME_SHIFT
In reply to Tzvetomir Stoyanov (VMware)From: Tzvetomir Stoyanov <[email protected]>
The TRACECMD_OPTION_TIME_SHIFT is used when synchronizing trace time stamps between two trace.dat files. It contains multiple long long (time, offset) pairs, describing time stamps _offset_, measured in the given local _time_. The content of the option buffer is:
first 4 bytes - integer, count of timestamp offsets
long long array of size _count_, local time in which the offset is measured long long array of size _count_, offset of the time stamps
--- include/trace-cmd/trace-cmd.h | 1 + lib/trace-cmd/trace-input.c | 127 +++++++++++++++++++++++++++++++++- 2 files changed, 126 insertions(+), 2 deletions(-)
include/trace-cmd/trace-cmd.h +1 -0
@@ -84,6 +84,7 @@ enum {TRACECMD_OPTION_OFFSET ,TRACECMD_OPTION_CPUCOUNT ,TRACECMD_OPTION_VERSION , + TRACECMD_OPTION_TIME_SHIFT, }; enum {
lib/trace-cmd/trace-input.c +125 -2
175 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v12 9/9 trace-cmd [POC]: Implemented timestamps synch algorithm, using vsock events.
In reply to Tzvetomir Stoyanov (VMware)From: Tzvetomir Stoyanov <[email protected]>
This is a POC patch, implementing an algorithm for syncing timestamps between host and guest machines, using vsock trace events to catch the host / guest time.
--- include/trace-cmd/trace-cmd.h | 20 +- tracecmd/Makefile | 1 + tracecmd/include/trace-local.h | 32 +- tracecmd/trace-agent.c | 13 +- tracecmd/trace-msg.c | 210 ++++++++- tracecmd/trace-record.c | 79 +++- tracecmd/trace-timesync.c | 810 +++++++++++++++++++++++++++++++++ 7 files changed, 1130 insertions(+), 35 deletions(-) create mode 100644 tracecmd/trace-timesync.c
include/trace-cmd/trace-cmd.h +16 -4
@@ -347,17 +347,29 @@ bool tracecmd_msg_done(struct tracecmd_msg_handle *msg_handle);void tracecmd_msg_set_done (struct tracecmd_msg_handle *msg_handle);int tracecmd_msg_send_trace_req (struct tracecmd_msg_handle *msg_handle, -int argc,char **argv,bool use_fifos); +int argc,char **argv,bool use_fifos, +bool do_tsync);int tracecmd_msg_recv_trace_req (struct tracecmd_msg_handle *msg_handle, -int *argc,char ***argv,bool *use_fifos); +int *argc,char ***argv,bool *use_fifos, +bool *do_tsync);int tracecmd_msg_send_trace_resp (struct tracecmd_msg_handle *msg_handle,int nr_cpus,int page_size, -unsigned int *ports,bool use_fifos); +unsigned int *ports,bool use_fifos, +bool do_tsync);int tracecmd_msg_recv_trace_resp (struct tracecmd_msg_handle *msg_handle,int *nr_cpus,int *page_size, -unsigned int **ports,bool *use_fifos); +unsigned int **ports,bool *use_fifos, +bool *do_tsync); +struct tracecmd_clock_sync ; + +int tracecmd_msg_rcv_time_sync (struct tracecmd_msg_handle *msg_handle, +struct tracecmd_clock_sync *clock_sync, +long long *offset,long long *timestamp); +int tracecmd_msg_snd_time_sync (struct tracecmd_msg_handle *msg_handle, +struct tracecmd_clock_sync *clock_sync, +long long *offset,long long *timestamp);/* --- Plugin handling --- */ extern struct tep_plugin_option trace_ftrace_options[];
tracecmd/Makefile +1 -0
@@ -32,6 +32,7 @@ TRACE_CMD_OBJS += trace-list.o TRACE_CMD_OBJS += trace-output.o TRACE_CMD_OBJS += trace-usage.o TRACE_CMD_OBJS += trace-msg.o +TRACE_CMD_OBJS += trace-timesync.o ifeq ($(VSOCK_DEFINED), 1) TRACE_CMD_OBJS += trace-agent.o
tracecmd/include/trace-local.h +31 -1
@@ -101,7 +101,7 @@ void trace_usage(int argc, char **argv);int trace_record_agent (struct tracecmd_msg_handle *msg_handle,int cpus,int *fds, -int argc,char **argv,bool use_fifos); +int argc,char **argv,bool use_fifos,bool do_tsync);struct hook_list ;
@@ -216,6 +216,12 @@ struct buffer_instance {unsigned int port;int *fds;bool use_fifos; +bool do_tsync; + +struct tracecmd_clock_sync *clock_sync; +int time_sync_count; +long long *time_sync_ts; +long long *time_sync_offsets; };extern struct buffer_instance top_instance;
@@ -237,6 +243,30 @@ void update_first_instance(struct buffer_instance *instance, int topt);void show_instance_file (struct buffer_instance *instance,const char *name);int count_cpus (void ); + +struct tracecmd_time_sync_event { +int id; +int cpu; +int pid; +unsigned long long ts; +}; + +int tracecmd_clock_get_peer (struct tracecmd_clock_sync *clock_context, +unsigned int *remote_cid,unsigned int *remote_port); +bool tracecmd_time_sync_check (void ); +void tracecmd_clock_context_free (struct buffer_instance *instance); +int tracecmd_clock_find_event (struct tracecmd_clock_sync *clock,int cpu, +struct tracecmd_time_sync_event *event); +void tracecmd_clock_synch_enable (struct tracecmd_clock_sync *clock_context); +void tracecmd_clock_synch_disable (struct tracecmd_clock_sync *clock_context); +void tracecmd_clock_synch_calc_reset (struct tracecmd_clock_sync *clock_context); +void tracecmd_clock_synch_calc_probe (struct tracecmd_clock_sync *clock_context, +long long ts_local,long long ts_remote); +int tracecmd_clock_synch_calc (struct tracecmd_clock_sync *clock_context, +long long *offset_ret,long long *time_ret); +void sync_time_with_host_v3 (struct buffer_instance *instance); +void sync_time_with_guest_v3 (struct buffer_instance *instance); +void write_tracing_on (struct buffer_instance *instance,int on);char *get_instance_dir (struct buffer_instance *instance); int write_instance_file(struct buffer_instance *instance,
tracecmd/trace-agent.c +10 -3
@@ -132,6 +132,7 @@ static void agent_handle(int sd, int nr_cpus, int page_size)char **argv =NULL ;int argc =0 ;bool use_fifos; +bool do_tsync;int *fds;int ret;
@@ -144,7 +145,8 @@ static void agent_handle(int sd, int nr_cpus, int page_size)if (!msg_handle)die ("Failed to allocate message handle" ); - ret =tracecmd_msg_recv_trace_req (msg_handle, &argc, &argv, &use_fifos); + ret =tracecmd_msg_recv_trace_req (msg_handle, &argc, &argv, + &use_fifos, &do_tsync);if (ret <0 )die ("Failed to receive trace request" );
@@ -153,13 +155,18 @@ static void agent_handle(int sd, int nr_cpus, int page_size)if (!use_fifos)make_vsocks (nr_cpus, fds, ports); +if (do_tsync) { + do_tsync =tracecmd_time_sync_check (); +if (!do_tsync) +warning ("Failed to negotiate timestamps synchronization with the host" ); + } ret =tracecmd_msg_send_trace_resp (msg_handle, nr_cpus, page_size, - ports, use_fifos); + ports, use_fifos, do_tsync);if (ret <0 )die ("Failed to send trace response" ); -trace_record_agent (msg_handle, nr_cpus, fds, argc, argv, use_fifos); +trace_record_agent (msg_handle, nr_cpus, fds, argc, argv, use_fifos, do_tsync);free (argv[0 ]);free (argv);
tracecmd/trace-msg.c +187 -23
319 lines not on this page · raw message
tracecmd/trace-record.c +75 -4
158 lines not on this page · raw message
tracecmd/trace-timesync.c new file +810 -0
810 lines not on this page · raw message
Signature · 1 line
2.21.0