Timestamp synchronization of host - guest tracing session
v27 cover Timestamp synchronization of host - guest tracing session
Basic infrastructure for host - guest timestamp synchronization and a PoC implementation of PTP-like and KVM algorithms.
The KVM plugin is with higher weight than PTP, it is preferred in case both are active. KVM is used only if x86-tsc clock is selected for the current trace, PTP is used for all other cases.
v27 changes:
- Fixed broken compilation due to usage of old libtracefs APIs.
- Rewrote complex macros to follow the Linux kernel requirements for macros.
- Removed pathces from the set, that were already merged upstream.
v26 changes:
- Rebased on top of latest master.
- Abstracted Time sync protocol names in a structure, to avoid using triple char pointers.
- Removed a patch from the set, as it is already merged:
"trace-cmd: Add new libtrasefs API to get the current trace clock".
- Minor coding style changes, for better code readability.
v25 changes:
- Addressed Steven's comments.
- Reorded the patches in the plugin - put the PTP and KVM PoC patches last and all other fixes and improvements before them.
- Implemented a new libtrasefs API to get the current trace clock.
- Replaced IDs of trace timestamps synchronization protocols with strings.
- Implemented an "accuracy" parameter for timestamps synchronization protocols.
- Added "scaling ratio" correction, calculated by the timestamp synchronization protocols.
- Added flags, declared by the timestamps synchronization protocols, and stored in the trace.dat file, together with the calculated time offsets.
- Implemented timestamp offset calculation per virtual CPU.
v24 changes:
- trace-cmd internal refactoring, needed for KVM timestamp synchronization plugin.
- Added KVM timestamp synchronization plugin.
v23 changes:
- Added flags to PTP start message to control the behaviour of the algorithm. This is for development purposes mostly, to compare and evaluate how these changes affect the accuracy.
PTP_FLAG_FASTEST_RESPONSE: Consider only the probe with fastest
response time, otherwise make a histogram from all probes.
PTP_FLAG_USE_MARKER: Use trace marker to get the clock,
otherwise use directly the system clock
v22 changes, addressed Steven's comments:
- Fixed error flow in read_qemu_guests_pids(), free allocated resources in case of an error.
- Fixed initialisation of reallocated memmory in set_vcpu_pid_mapping().
- Fixed bitmask logic in tracecmd_tsync_proto_select().
- Fixed usage of wrong structure in make_trace_resp().
v21 changes:
- Rebased on top of latest master.
- Remove these two patches from the set, as they are already merged:
trace-cmd: Add new library API for local CPU count
trace-cmd: Add support for negative time offsets in trace.dat file
- Added more descriptive warning message when fails to extract Time Shift information from the trace.dat file.
- Added a warning message when fails to obtain vcpu - pid mappings.
- Handle the case with sparse VCPU numbers in VCPU - PID mapping array.
- Fixed broken recording over FIFOs.
v20 changes:
- Rebased on top of latest master.
- Removed the VCPUS_MAX hardcoded limit, reimplemented the cpu_pid[] array to be dynamically allocated.
- Added a warning when reading of TRACECMD_OPTION_TIME_SHIFT option fails, due to unexpected option's size.
- Improved loading of TRACECMD_OPTION_GUEST option data, as Steven suggested.
v19 changes:
- Rebased on top of latest master. The librtacefs is already merged, this allows to drop few patches from the set and use librtacefs APIs instead.
- Reimplemented all new trace.dat options to be in binary format, instead of text. Leverage the new "trace-cmd dump" sub command to track what is written in the file.
- Addressed Steven's comments.
v18 changes: addressed Steven Rostdet comments:
- Replaced semaphores with pthread mutexes.
- Made bitmask with time sync protocols unlimited, so we can support more than 32 protocols. That required to redesign the trace request packet format.
- A lot of small fixes.
v17 changes:
- Implemented new PTP logic for calculating the clocks offset, using histogram of all PTP samples. It gives better results than the logic with the fastest response time, so set the new one as default in the POC patch.
v16 changes:
- Fixed compilation in case no VSOCK is available (Thanks to Slavomir Kaslev)
- Fixed a typo in trace-cmd-record.1.txt (Thanks to Slavomir Kaslev)
- Added forgotten file in the patch "trace-cmd: Add new library APIs for ftrace instances." - trace-instance.c
- Fixed few compilation warnings related to TSYNC_DEBUG code.
- Removed a blank line at the end of "tsync_readme" file.
v15 changes:
- Removed the patch for "--proc-map" from the series, as it should not be part of it.
v14 changes:
- Bring back the PTP-like algorithm and removed the ftrace event based logic.
- Reimplemented the PTP-like algorithm to use raw ftrace markers, instead of clock_gettime() API.
- Refactored the logic to be algorithm independent and plugin friendly.
- Implemented continuous timestamps synchronization, while the trace is running.
- Moved logic from trace-cmd application to libtracecmd, as new library APIs.
- Implemented new trace id functionality.
- Implemented new guest section in host trace.dat file.
v13 changes:
- Remove few patches from the set, as they were merged.
- Rebased to the latest master, Slavomirs patchest "Add VM kernel tracing over vsockets and FIFOs" got merged!
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 (VMware) (5):
trace-cmd: Add timestamp synchronization per vCPU
trace-cmd: Add dummy function to initialize timestamp sync logic
trace-cmd: [POC] PTP-like algorithm for host - guest timestamp
synchronization
trace-cmd: Debug scripts for PTP-like algorithm for host - guest
timestamp synchronization
trace-cmd [POC]: Add KVM timestamp synchronization plugin
lib/trace-cmd/Makefile | 2 + .../include/private/trace-cmd-private.h | 2 +- lib/trace-cmd/include/trace-tsync-local.h | 23 +- lib/trace-cmd/trace-input.c | 188 +++-- lib/trace-cmd/trace-timesync-kvm.c | 460 +++++++++++ lib/trace-cmd/trace-timesync-ptp.c | 715 ++++++++++++++++++ lib/trace-cmd/trace-timesync.c | 224 ++++-- scripts/debug/tsync_hist.py | 57 ++ scripts/debug/tsync_readme | 12 + scripts/debug/tsync_res.py | 46 ++ tracecmd/trace-agent.c | 2 + tracecmd/trace-dump.c | 52 +- tracecmd/trace-record.c | 23 +- tracecmd/trace-tsync.c | 67 +- 14 files changed, 1693 insertions(+), 180 deletions(-) create mode 100644 lib/trace-cmd/trace-timesync-kvm.c create mode 100644 lib/trace-cmd/trace-timesync-ptp.c create mode 100644 scripts/debug/tsync_hist.py create mode 100644 scripts/debug/tsync_readme create mode 100644 scripts/debug/tsync_res.py
Signature · 1 line
2.29.2
PATCH v27 1/5 trace-cmd: Add timestamp synchronization per vCPU
Timestamp synchronization logic is changed to work per virtual CPU. Some hypervisors maintain time offset and scaling per vCPU. The host-guest communication protocol is changed to request time stamp offset calculation for particular vCPU. The guest thread, responsible for running that logic is pinned to the requested CPU. The time sync medata data, saved in the trace.dat file is changed to an array of vCPUs. When an event time stamp is corrected, the CPU on that the event happened is used to get the correct offset.
--- .../include/private/trace-cmd-private.h | 2 +- lib/trace-cmd/include/trace-tsync-local.h | 22 +- lib/trace-cmd/trace-input.c | 188 +++++++++------ lib/trace-cmd/trace-timesync.c | 215 +++++++++++++----- tracecmd/trace-dump.c | 52 +++-- tracecmd/trace-tsync.c | 67 ++++-- 6 files changed, 374 insertions(+), 172 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +1 -1
@@ -443,7 +443,7 @@ const char *tracecmd_tsync_proto_select(struct tracecmd_tsync_protos *protos, chbool tsync_proto_is_supported (const char *proto_name);void tracecmd_tsync_with_host (struct tracecmd_time_sync *tsync);void tracecmd_tsync_with_guest (struct tracecmd_time_sync *tsync); -int tracecmd_tsync_get_offsets (struct tracecmd_time_sync *tsync, +int tracecmd_tsync_get_offsets (struct tracecmd_time_sync *tsync,int cpu,int *count,long long **ts,long long **offsets,long long **scalings); int tracecmd_tsync_get_proto_flags(struct tracecmd_time_sync *tsync,
lib/trace-cmd/include/trace-tsync-local.h +15 -7
@@ -8,12 +8,7 @@#include <stdbool.h> -struct clock_sync_context { -void *proto_data;/* time sync protocol specific data */ -bool is_server;/* server side time sync role */ -bool is_guest;/* guest or host time sync role */ -struct tracefs_instance *instance;/* ftrace buffer, used for time sync events */ - +struct clock_sync_offsets {/* Arrays with calculated time offsets at given time */ int sync_size;/* Allocated size of sync_ts, * sync_offsets and sync_scalings
@@ -24,6 +19,18 @@ struct clock_sync_context {long long *sync_ts;long long *sync_offsets;long long *sync_scalings; +}; + +struct clock_sync_context { +void *proto_data;/* time sync protocol specific data */ +bool is_server;/* server side time sync role */ +bool is_guest;/* guest or host time sync role */ +struct tracefs_instance *instance;/* ftrace buffer, used for time sync events */ + +int cpu_count; +struct clock_sync_offsets *offsets;/* Array of size cpu_count +* calculated offsets per CPU +*/ /* Identifiers of local and remote time sync peers: cid and port */ unsigned int local_cid;
@@ -37,7 +44,8 @@ int tracecmd_tsync_proto_register(const char *proto_name, int accuracy, int roleint (*init)(struct tracecmd_time_sync *), int (*free)(struct tracecmd_time_sync *), int (*calc)(struct tracecmd_time_sync *, - long long *, long long *, long long *)); +long long *,long long *, + long long *, unsigned int));int tracecmd_tsync_proto_unregister (char *proto_name);int ptp_clock_sync_register (void );
lib/trace-cmd/trace-input.c +123 -65
297 lines not on this page · raw message
lib/trace-cmd/trace-timesync.c +160 -55
359 lines not on this page · raw message
tracecmd/trace-dump.c +29 -23
65 lines not on this page · raw message
tracecmd/trace-tsync.c +46 -21
103 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [PATCH v27 1/5] trace-cmd: Add timestamp synchronization per vCPU
lib/trace-cmd/trace-timesync.c line 25
Quoted 7 lines · On Mon, 1 Feb 2021 18:03:35 +0200 "Tzvetomir Stoyanov (VMware)"…
lib/trace-cmd/trace-timesync.c +1
-0@@ -22,6 +22,8 @@#include "event-utils.h" #include "trace-tsync-local.h" +typedef __be16 be16 ;
I'm curious to why you added this, because I have a machine that doesn't define __be16. I'm guessing it comes from "#include <linux/limits.h>", was there a reason to use that?
I really don't see the difference between __be16 and unsigned short. I think it's mostly used for static parsers. Perhaps its best to use __u16, or "unsigned short" to make sure it compiles on older systems.
-- Steve
Quoted 15 lines
lib/trace-cmd/trace-timesync.c +5
-1+struct tsync_proto {struct tsync_proto *next;char proto_name[TRACECMD_TSYNC_PNAME_LENGTH ];@@ -34,9 +36,13 @@ struct tsync_proto {int (*clock_sync_free)(struct tracecmd_time_sync *clock_context);int (*clock_sync_calc)(struct tracecmd_time_sync *clock_context,long long *offset,long long *scaling, -long long *timestamp); +long long *timestamp,unsigned int cpu); }; +struct tsync_probe_request_msg { +be16 cpu; +} __packed;
Re: [PATCH v27 1/5] trace-cmd: Add timestamp synchronization per vCPU
Quoted 10 lines · Steven Rostedt
Quoted 6 lines · On Mon, 1 Feb 2021 18:03:35 +0200 "Tzvetomir Stoyanov (VMware)"…
lib/trace-cmd/trace-timesync.c +0
-0@@ -22,6 +22,8 @@#include "event-utils.h" #include "trace-tsync-local.h"
Quoted 6 lines
lib/trace-cmd/trace-timesync.c line 25
Quoted 1 line
lib/trace-cmd/trace-timesync.c +1
-0+typedef __be16 be16 ;I'm curious to why you added this, because I have a machine that doesn't define
__be16. I'm guessing it comes from "#include <linux/limits.h>", was there a reason to use that?
I added it to be consistent with the other messages, defined in trace-msg.c - for signed / unsigned 32bit and 64bit fields. The other reason is that I used to define packet's structure in that way in my previous job - to be clear exactly
how many bits are exchanged over the network.
I agree that that is useless here and will replace it with an unsigned short.
Quoted 23 lines
I really don't see the difference between
__be16and unsigned short. I think it's mostly used for static parsers. Perhaps its best to use__u16, or "unsigned short" to make sure it compiles on older systems.-- Steve
Quoted 15 lines
lib/trace-cmd/trace-timesync.c +5
-1+struct tsync_proto {struct tsync_proto *next;char proto_name[TRACECMD_TSYNC_PNAME_LENGTH ];@@ -34,9 +36,13 @@ struct tsync_proto {int (*clock_sync_free)(struct tracecmd_time_sync *clock_context);int (*clock_sync_calc)(struct tracecmd_time_sync *clock_context,long long *offset,long long *scaling, -long long *timestamp); +long long *timestamp,unsigned int cpu); }; +struct tsync_probe_request_msg { +be16 cpu; +} __packed;
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov VMware Open Source Technology Center
PATCH v27 2/5 trace-cmd: Add dummy function to initialize timestamp sync logic
In reply to Tzvetomir Stoyanov (VMware)A dummy empty function is added, will be used to initialize timestamp synchronization logic:
tracecmd_tsync_init()
When this code is implemented as real plugins, this function will be removed. Then the initializion will be triggered at plugin load time.
--- lib/trace-cmd/trace-timesync.c | 8 ++++++++ tracecmd/trace-agent.c | 2 ++ tracecmd/trace-record.c | 23 +++++++++++++++-------- 3 files changed, 25 insertions(+), 8 deletions(-)
lib/trace-cmd/trace-timesync.c +8 -0
@@ -59,6 +59,14 @@ static struct tsync_proto *tsync_proto_find(const char *proto_name)return NULL ; } +/** +* tracecmd_tsync_init - Initialize the global, per task, time sync data. +*/ +void tracecmd_tsync_init (void ) +{ + +} + int tracecmd_tsync_proto_register(const char *proto_name, int accuracy, int roles, int supported_clocks, unsigned int flags, int (*init)(struct tracecmd_time_sync *),
tracecmd/trace-agent.c +2 -0
@@ -248,6 +248,8 @@ static void agent_serve(unsigned int port)if (sd <0 )die ("Failed to open vsocket" ); +tracecmd_tsync_init (); +if (!get_local_cid (&cid))printf ("listening on @%u:%u\n" , cid, port);
tracecmd/trace-record.c +15 -8
@@ -6219,10 +6219,6 @@ static bool has_local_instances(void)return false; } -/* -* This function contains common code for the following commands: -* record, start, stream, profile. -*/ static void record_trace (int argc,char **argv,struct common_record_context *ctx) {
@@ -6380,12 +6376,23 @@ static void record_trace(int argc, char **argv,finalize_record_trace (ctx); } +/* +* This function contains common code for the following commands: +* record, start, stream, profile. +*/ +static void record_trace_command (int argc,char **argv, +struct common_record_context *ctx) +{ +tracecmd_tsync_init (); +record_trace (argc, argv, ctx); +} +void trace_start (int argc,char **argv) {struct common_record_context ctx;parse_record_options (argc, argv, CMD_start, &ctx); -record_trace (argc, argv, &ctx); +record_trace_command (argc, argv, &ctx);exit (0 ); }
@@ -6477,7 +6484,7 @@ void trace_stream(int argc, char **argv)struct common_record_context ctx;parse_record_options (argc, argv, CMD_stream, &ctx); -record_trace (argc, argv, &ctx); +record_trace_command (argc, argv, &ctx);exit (0 ); }
@@ -6496,7 +6503,7 @@ void trace_profile(int argc, char **argv)if (!buffer_instances) top_instance.flags |=BUFFER_FL_PROFILE ; -record_trace (argc, argv, &ctx); +record_trace_command (argc, argv, &ctx);do_trace_profile ();exit (0 ); }
@@ -6506,7 +6513,7 @@ void trace_record(int argc, char **argv)struct common_record_context ctx;parse_record_options (argc, argv, CMD_record, &ctx); -record_trace (argc, argv, &ctx); +record_trace_command (argc, argv, &ctx);exit (0 ); }
Signature · 1 line
2.29.2
PATCH v27 3/5 trace-cmd: [POC] PTP-like algorithm for host - guest timestamp synchronization
In reply to Tzvetomir Stoyanov (VMware)PTP protocol is designed for synchronizing clocks of machines in a local network. The same approach can be used for host - guest timestamp synchronization. This implementation uses ftrace raw markers to track trace timestamps of PTP events. The patch is a POC, two different algorithms for PTP calculations are proposed:
- Choosing the sample with the fastest response time for calculating the clocks offset.
- Calculating the clocks offset using the average of all PTP samples.
The implementation can be tuned using those parameters:
- #define FASTEST_RESPONSE - is defined, the sample with the fastest response time is used for calculating the clocks offset. Otherwise the histogram of all samples is used.
- #define PTP_SYNC_LOOP 340 - defines the number of samples, used for one calculation.
- --tsync-interval - a trace-cmd argument, choose the intervals between offset calculations, performed continuously during the trace.
- #define TSYNC_DEBUG - if defined, a debug information is collected and stored in files, in the guest machine:
s-cid*.txt - For each offset calculation: host and guest clocks and calculated offset. res-cid*.txt - For each tracing session: all calculated clock offsets.
--- lib/trace-cmd/Makefile | 1 + lib/trace-cmd/trace-timesync-ptp.c | 715 +++++++++++++++++++++++++++++ lib/trace-cmd/trace-timesync.c | 2 +- 3 files changed, 717 insertions(+), 1 deletion(-) create mode 100644 lib/trace-cmd/trace-timesync-ptp.c
lib/trace-cmd/Makefile +1 -0
@@ -19,6 +19,7 @@ OBJS += trace-msg.o OBJS += trace-plugin.o ifeq ($(VSOCK_DEFINED), 1) OBJS += trace-timesync.o +OBJS += trace-timesync-ptp.o endif # Additional util objects
lib/trace-cmd/trace-timesync-ptp.c new file +715 -0
715 lines not on this page · raw message
lib/trace-cmd/trace-timesync.c +1 -1
@@ -64,7 +64,7 @@ static struct tsync_proto *tsync_proto_find(const char *proto_name)*/ void tracecmd_tsync_init (void ) { - +ptp_clock_sync_register (); } int tracecmd_tsync_proto_register(const char *proto_name, int accuracy, int roles,
Signature · 1 line
2.29.2
PATCH v27 4/5 trace-cmd: Debug scripts for PTP-like algorithm for host - guest timestamp synchronization
In reply to Tzvetomir Stoyanov (VMware)These scripts can be used to visualise debug files, written when the PTP-like algorithm is compiled with TSYNC_DEBUG defined. The files are located in the guest machine:
s-cid*.txt - For each offset calculation: host and guest clocks and calculated offset. res-cid*.txt - For each tracing session: all calculated clock offsets.
tsync_hist.py plots a histogram, using data from a s-cid*.txt file:
"python tsync_hist.py s-cid2_1.txt"
tsync_res.py plots a line, using data from res-cid*.txt file:
"python tsync_res.py res-cid2.txt"
--- scripts/debug/tsync_hist.py | 57 +++++++++++++++++++++++++++++++++++++ scripts/debug/tsync_readme | 12 ++++++++ scripts/debug/tsync_res.py | 46 ++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 scripts/debug/tsync_hist.py create mode 100644 scripts/debug/tsync_readme create mode 100644 scripts/debug/tsync_res.py
scripts/debug/tsync_hist.py new file +57 -0
@@ -0,0 +1,57 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2019, VMware Inc, Tzvetomir Stoyanov <[email protected]> +# Copyright (C) 2019, VMware Inc, Yordan Karadzhov <[email protected]> + + +import matplotlib.pyplot as plt +import matplotlib.lines as mlines +import numpy as np +import sys + +def newline(p1, p2): + ax = plt.gca() + xmin, xmax = ax.get_xbound() + + if(p2[0] == p1[0]): + xmin = xmax = p1[0] + ymin, ymax = ax.get_ybound() + else: + ymax = p1[1]+(p2[1]-p1[1])/(p2[0]-p1[0])*(xmax-p1[0]) + ymin = p1[1]+(p2[1]-p1[1])/(p2[0]-p1[0])*(xmin-p1[0]) + + l = mlines.Line2D([xmin,xmax], [ymin,ymax], color='red') + ax.add_line(l) + return l + + +data = np.loadtxt(fname = sys.argv[1]) +selected_ts = data[-1, 1] +selected_ofs = data[-1, 0] +data = data[:-1,:] + +x = data[:, 1] - data[:, 0] + +mean = x.mean() +std = x.std() + +num_bins = 500 +min = x.min() #+ .4 * (x.max() - x.min()) +max = x.max() #- .4 * (x.max() - x.min()) +bins = np.linspace(min, max, num_bins, endpoint = False, dtype=int) + +fig, ax = plt.subplots() + +# the histogram of the data +n, bins, patches = ax.hist(x, bins, histtype=u'step'); + +ax.set_xlabel('clock offset [$\mu$s]') +ax.set_ylabel('entries') +ax.set_title("$\sigma$=%i" % std) + +x1, y1 = [selected_ofs, min], [selected_ofs, max] +newline(x1, y1) + +# Tweak spacing to prevent clipping of ylabel +fig.tight_layout() +plt.show()
scripts/debug/tsync_readme new file +12 -0
@@ -0,0 +1,12 @@ +PTP-like algorithm debug +======================== + +tsync_*.py scripts can be used to visualise debug files, written when the PTP-like algorithm +is compiled with TSYNC_DEBUG defined. The files are located in the guest machine: + s-cid*.txt - For each offset calculation: host and guest clocks and calculated offset. + res-cid*.txt - For each tracing session: all calculated clock offsets. + +tsync_hist.py plots a histogram, using data from a s-cid*.txt file: + "python tsync_hist.py s-cid2_1.txt" +tsync_res.py plots a line, using data from res-cid*.txt file: + "python tsync_res.py res-cid2.txt"
scripts/debug/tsync_res.py new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH v27 5/5 trace-cmd [POC]: Add KVM timestamp synchronization plugin
In reply to Tzvetomir Stoyanov (VMware)Added new timestamp synchronization plugin for KVM hosts. It reads the clock offsets directly from the KVM debug filesystem, if available. The plugin works only with x86-tsc ftrace clock.
--- lib/trace-cmd/Makefile | 1 + lib/trace-cmd/include/trace-tsync-local.h | 1 + lib/trace-cmd/trace-timesync-kvm.c | 460 ++++++++++++++++++++++ lib/trace-cmd/trace-timesync.c | 1 + 4 files changed, 463 insertions(+) create mode 100644 lib/trace-cmd/trace-timesync-kvm.c
lib/trace-cmd/Makefile +1 -0
@@ -20,6 +20,7 @@ OBJS += trace-plugin.o ifeq ($(VSOCK_DEFINED), 1) OBJS += trace-timesync.o OBJS += trace-timesync-ptp.o +OBJS += trace-timesync-kvm.o endif # Additional util objects
lib/trace-cmd/include/trace-tsync-local.h +1 -0
@@ -49,5 +49,6 @@ int tracecmd_tsync_proto_register(const char *proto_name, int accuracy, int roleint tracecmd_tsync_proto_unregister (char *proto_name);int ptp_clock_sync_register (void ); +int kvm_clock_sync_register (void );#endif /* _TRACE_TSYNC_LOCAL_H */
lib/trace-cmd/trace-timesync-kvm.c new file +460 -0
460 lines not on this page · raw message
lib/trace-cmd/trace-timesync.c +1 -0
@@ -65,6 +65,7 @@ static struct tsync_proto *tsync_proto_find(const char *proto_name)void tracecmd_tsync_init (void ) {ptp_clock_sync_register (); +kvm_clock_sync_register (); } int tracecmd_tsync_proto_register(const char *proto_name, int accuracy, int roles,
Signature · 1 line
2.29.2
Re: [PATCH v27 5/5] trace-cmd [POC]: Add KVM timestamp synchronization plugin
Quoted 19 lines · On Mon, 1 Feb 2021 18:03:39 +0200 "Tzvetomir Stoyanov (VMware)"…
+++
b/lib/trace-cmd/trace-timesync-kvm.clib/trace-cmd/trace-timesync-kvm.c new file +17
-0@@ -0,0 +1,460 @@ +// SPDX-License-Identifier: LGPL-2.1 +/* +* Copyright (C) 2020, VMware, Tzvetomir Stoyanov [email protected]> +* +*/ + +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/stat.h> +#include <dirent.h> + +#include "trace-cmd.h" +#include "trace-cmd-private.h" +#include "tracefs.h" +#include "trace-tsync-local.h" +
lib/trace-cmd/trace-timesync-kvm.c line 27
Quoted 10 lines
lib/trace-cmd/trace-timesync-kvm.c new file +10
-0+#define KVM_DEBUG_FS "/sys/kernel/debug/kvm" +#define KVM_DEBUG_OFFSET_FILE "tsc-offset" +#define KVM_DEBUG_SCALING_FILE "tsc-scaling-ratio" +#define KVM_DEBUG_VCPU_DIR "vcpu" + +#define KVM_SYNC_PKT_REQUEST 1 +#define KVM_SYNC_PKT_RESPONSE 2 + +typedef __s64 s64 ; +
I have the same issue with __s64 on the one machine. Best to use:
typdef long long s64;
-- Steve