Calculate synchronization accuracy within the chull module
[lttv.git] / lttv / lttv / sync / data_structures.h
CommitLineData
10341d26 1/* This file is part of the Linux Trace Toolkit viewer
277e5b53 2 * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca>
10341d26 3 *
277e5b53
BP
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or (at
7 * your option) any later version.
10341d26 8 *
277e5b53
BP
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
10341d26 13 *
277e5b53
BP
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
10341d26
BP
16 */
17
18#ifndef DATA_STRUCTURES_H
19#define DATA_STRUCTURES_H
20
21#include <glib.h>
22#include <stdbool.h>
23#include <stdint.h>
24
b2da0724
BP
25#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
26
f10c27a8
BP
27
28enum Direction
29{
30 OUT,
31 IN,
32};
33
34enum EventType
35{
36 TCP,
37 UDP,
2bd4b3e4 38 TYPE_COUNT // This must be the last field
f10c27a8
BP
39};
40
10341d26
BP
41// Stage 1 to 2: These structures are passed from processing to matching modules
42// TCP events
43typedef struct
44{
45 uint32_t saddr, daddr;
46 uint16_t source, dest;
47} ConnectionKey;
48
49typedef struct
50{
51 ConnectionKey connectionKey;
52 uint8_t ihl;
53 uint16_t tot_len;
54 uint32_t seq, ack_seq;
55 uint8_t doff;
56 uint8_t ack, rst, syn, fin;
57} SegmentKey;
58
10341d26
BP
59typedef struct
60{
61 enum Direction direction;
62 SegmentKey* segmentKey;
63} TCPEvent;
64
65// UDP events
66typedef struct
67{
68 uint32_t saddr, daddr;
f6691532
BP
69 uint16_t source, dest;
70 uint16_t ulen;
10341d26
BP
71 uint8_t dataKey[8];
72} DatagramKey;
73
74typedef struct
75{
76 enum Direction direction;
77 DatagramKey* datagramKey;
78 bool unicast;
79} UDPEvent;
80
76be6fc2
BP
81typedef struct
82{
83 uint32_t seconds;
84 uint32_t nanosec;
85} WallTime;
86
10341d26
BP
87typedef struct _Event
88{
89 unsigned long traceNum;
467066ee
BP
90 // wallTime is corrected according to factors in trace struct, cpuTime
91 // is not
76be6fc2
BP
92 uint64_t cpuTime;
93 WallTime wallTime;
10341d26
BP
94
95 // specific event structures and functions could be in separate files and
96 // type could be an int
f6691532 97 enum EventType type;
10341d26
BP
98 // event could be a void*, this union is to avoid having to cast
99 union {
100 TCPEvent* tcpEvent;
101 UDPEvent* udpEvent;
102 } event;
103
d4721e1a 104 void (*copy)(const struct _Event* const event, struct _Event** const newEvent);
10341d26
BP
105 void (*destroy)(struct _Event* const event);
106} Event;
107
108// Stage 2 to 3: These structures are passed from matching to analysis modules
109typedef struct _Message
110{
111 Event* inE, * outE;
112
113 void (*print)(const struct _Message* const message);
114} Message;
115
116typedef struct
117{
118 Message* message;
ffa21cfd 119 // Event* acks[]
10341d26
BP
120 GQueue* acks;
121} Exchange;
122
123typedef struct
124{
ffa21cfd 125 // Event* events[]
10341d26
BP
126 GQueue* events;
127} Broadcast;
128
0a87ec9a
BP
129// Stage 4: These structures contain correction factors
130/* Correction factors for each trace, this is the final result of
131 * synchronization */
10341d26
BP
132typedef struct
133{
134 double drift, offset;
135} Factors;
136
0a87ec9a
BP
137// Correction factors between trace pairs, to be used for reduction
138typedef enum
139{
140 EXACT,
141 /* Used for identity factors (a0= 0, a1= 1) that map a trace to itself. In
142 * this case, min, max and accuracy are NULL.
143 */
144
145 ACCURATE,
146 /* The approximation is the middle of the min and max limits. All fields
147 * are initialized.
148 */
149
150 APPROXIMATE,
151 /* min and max are not available. The approximation is a "best effort".
152 * min and max are NULL.
153 */
154
155 INCOMPLETE,
156 /* min or max is available but not both. approx and accuracy are not
157 * NULL.
158 */
159
160 ABSENT,
161 /* The pair of trace did not have communications in both directions (maybe
162 * even no communication at all). approx and accuracy are NULL.
163 */
164
ab6edc6a
BP
165 FAIL,
166 /* The algorithms are defective. All fields may be NULL.
0a87ec9a
BP
167 */
168
169 APPROX_NB, // This must be the last member
170} ApproxType;
171
172extern const char* const approxNames[APPROX_NB];
173
174typedef struct
175{
176 Factors* min, * max, * approx;
177 ApproxType type;
178 double accuracy;
179} PairFactors;
180
181typedef struct
182{
183 unsigned int refCount;
0a87ec9a
BP
184 PairFactors** pairFactors;
185} AllFactors;
186
10341d26 187
ab6edc6a
BP
188// This structure is used to return a corrected time value with accuracy
189// bounds
190typedef struct
191{
192 uint64_t time, min, max;
193} CorrectedTime;
194
195
10341d26
BP
196// ConnectionKey-related functions
197guint ghfConnectionKeyHash(gconstpointer key);
198
199gboolean gefConnectionKeyEqual(gconstpointer a, gconstpointer b);
200bool connectionKeyEqual(const ConnectionKey* const a, const ConnectionKey*
201 const b);
202
203void gdnConnectionKeyDestroy(gpointer data);
204
205// SegmentKey-related functions
206guint ghfSegmentKeyHash(gconstpointer key);
207gboolean gefSegmentKeyEqual(gconstpointer a, gconstpointer b);
208
f10c27a8
BP
209// DatagramKey-related functions
210guint ghfDatagramKeyHash(gconstpointer key);
211gboolean gefDatagramKeyEqual(gconstpointer a, gconstpointer b);
212void gdnDestroyDatagramKey(gpointer data);
213
10341d26
BP
214// Event-related functions
215void gdnDestroyEvent(gpointer data);
d4721e1a
BP
216void copyEvent(const Event* const event, Event** const newEvent);
217void copyTCPEvent(const Event* const event, Event** const newEvent);
218void copyUDPEvent(const Event* const event, Event** const newEvent);
10341d26
BP
219void destroyEvent(Event* const event);
220void destroyTCPEvent(Event* const event);
221void destroyUDPEvent(Event* const event);
f6691532 222void gfDestroyEvent(gpointer data, gpointer user_data);
76be6fc2 223double wallTimeSub(const WallTime const* tA, const WallTime const* tB);
66eaf2eb 224void gfAddEventToArray(gpointer data, gpointer user_data);
10341d26
BP
225
226// Message-related functions
227void printTCPSegment(const Message* const segment);
228void convertIP(char* const str, const uint32_t addr);
229
230gint gcfTCPSegmentAckCompare(gconstpointer a, gconstpointer b);
231bool isAcking(const Message* const ackSegment, const Message* const ackedSegment);
232
233void gdnTCPSegmentListDestroy(gpointer data);
234void gfTCPSegmentDestroy(gpointer data, gpointer user_data);
235void destroyTCPSegment(Message* const segment);
236
237// Exchange-related functions
238void destroyTCPExchange(Exchange* const exchange);
f6691532
BP
239
240// Broadcast-related functions
241void gdnDestroyBroadcast(gpointer data);
242void destroyBroadcast(Broadcast* const broadcast);
243
0a87ec9a
BP
244// Factor-related functions
245void destroyPairFactors(PairFactors* factorsCHull);
246
247AllFactors* createAllFactors(const unsigned int traceNb);
b2da0724 248void freeAllFactors(AllFactors* const allFactors, const unsigned int traceNb);
0a87ec9a 249
10341d26 250#endif
This page took 0.036088 seconds and 4 git commands to generate.