1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3 * Copyright (C) 2019, VMware, Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
4 *
5 */
6 #ifndef _TRACE_TSYNC_LOCAL_H
7 #define _TRACE_TSYNC_LOCAL_H
8
9 #include <stdbool.h>
10
11 struct tracecmd_time_sync {
12 pthread_t thread;
13 bool thread_running;
14 unsigned long long trace_id;
15 char *proto_name;
16 int loop_interval;
17 pthread_mutex_t lock;
18 pthread_cond_t cond;
19 pthread_barrier_t first_sync;
20 char *clock_str;
21 struct tracecmd_msg_handle *msg_handle;
22 void *context;
23 int guest_pid;
24 int vcpu_count;
25 int remote_id;
26 int local_id;
27 };
28
29 struct clock_sync_offsets {
30 /* Arrays with calculated time offsets at given time */
31 int sync_size; /* Allocated size of sync_ts,
32 * sync_offsets, sync_scalings and sync_frac
33 */
34 int sync_count; /* Number of elements in sync_ts,
35 * sync_offsets, sync_scalings and sync_frac
36 */
37 long long *sync_ts;
38 long long *sync_offsets;
39 long long *sync_scalings;
40 long long *sync_frac;
41 };
42
43 struct clock_sync_context {
44 void *proto_data; /* time sync protocol specific data */
45 bool is_server; /* server side time sync role */
46 bool is_guest; /* guest or host time sync role */
47 struct tracefs_instance *instance; /* ftrace buffer, used for time sync events */
48
49 int cpu_count;
50 struct clock_sync_offsets *offsets; /* Array of size cpu_count
51 * calculated offsets per CPU
52 */
53
54 /* Identifiers of local and remote time sync peers */
55 unsigned int local_id;
56 unsigned int remote_id;
57 };
58
59 int tracecmd_tsync_proto_register(const char *proto_name, int accuracy, int roles,
60 int supported_clocks, unsigned int flags,
61 int (*init)(struct tracecmd_time_sync *),
62 int (*free)(struct tracecmd_time_sync *),
63 int (*calc)(struct tracecmd_time_sync *,
64 long long *, long long *, long long*,
65 long long *, unsigned int));
66 int tracecmd_tsync_proto_unregister(char *proto_name);
67 int ptp_clock_sync_register(void);
68
69 #ifdef VSOCK
70 int kvm_clock_sync_register(void);
71 #else
kvm_clock_sync_register(void)72 static inline int kvm_clock_sync_register(void)
73 {
74 return 0;
75 }
76 #endif
77
78 #endif /* _TRACE_TSYNC_LOCAL_H */
79