@@ -44,11 +44,17 @@ timeval of SO_TIMESTAMP (ms).
44
44
Supports multiple types of timestamp requests. As a result , this
45
45
socket option takes a bitmap of flags , not a boolean. In
46
46
47
- err = setsockopt(fd , SOL_SOCKET , SO_TIMESTAMPING , (void *) val , &val);
47
+ err = setsockopt(fd , SOL_SOCKET , SO_TIMESTAMPING , (void *) val ,
48
+ sizeof(val));
48
49
49
50
val is an integer with any of the following bits set. Setting other
50
51
bit returns EINVAL and does not change the current state.
51
52
53
+ The socket option configures timestamp generation for individual
54
+ sk_buffs (1.3.1) , timestamp reporting to the socket's error
55
+ queue (1.3.2) and options (1.3.3). Timestamp generation can also
56
+ be enabled for individual sendmsg calls using cmsg (1.3.4).
57
+
52
58
53
59
1.3.1 Timestamp Generation
54
60
@@ -71,13 +77,16 @@ SOF_TIMESTAMPING_RX_SOFTWARE:
71
77
kernel receive stack.
72
78
73
79
SOF_TIMESTAMPING_TX_HARDWARE:
74
- Request tx timestamps generated by the network adapter.
80
+ Request tx timestamps generated by the network adapter. This flag
81
+ can be enabled via both socket options and control messages.
75
82
76
83
SOF_TIMESTAMPING_TX_SOFTWARE:
77
84
Request tx timestamps when data leaves the kernel. These timestamps
78
85
are generated in the device driver as close as possible , but always
79
86
prior to , passing the packet to the network interface. Hence , they
80
87
require driver support and may not be available for all devices.
88
+ This flag can be enabled via both socket options and control messages.
89
+
81
90
82
91
SOF_TIMESTAMPING_TX_SCHED:
83
92
Request tx timestamps prior to entering the packet scheduler. Kernel
@@ -90,7 +99,8 @@ SOF_TIMESTAMPING_TX_SCHED:
90
99
machines with virtual devices where a transmitted packet travels
91
100
through multiple devices and , hence , multiple packet schedulers ,
92
101
a timestamp is generated at each layer. This allows for fine
93
- grained measurement of queuing delay.
102
+ grained measurement of queuing delay. This flag can be enabled
103
+ via both socket options and control messages.
94
104
95
105
SOF_TIMESTAMPING_TX_ACK:
96
106
Request tx timestamps when all data in the send buffer has been
@@ -99,6 +109,7 @@ SOF_TIMESTAMPING_TX_ACK:
99
109
over-report measurement , because the timestamp is generated when all
100
110
data up to and including the buffer at send() was acknowledged: the
101
111
cumulative acknowledgment. The mechanism ignores SACK and FACK.
112
+ This flag can be enabled via both socket options and control messages.
102
113
103
114
104
115
1.3.2 Timestamp Reporting
@@ -183,6 +194,37 @@ having access to the contents of the original packet, so cannot be
183
194
combined with SOF_TIMESTAMPING_OPT_TSONLY.
184
195
185
196
197
+ 1.3.4. Enabling timestamps via control messages
198
+
199
+ In addition to socket options , timestamp generation can be requested
200
+ per write via cmsg , only for SOF_TIMESTAMPING_TX_* (see Section 1.3.1).
201
+ Using this feature , applications can sample timestamps per sendmsg()
202
+ without paying the overhead of enabling and disabling timestamps via
203
+ setsockopt:
204
+
205
+ struct msghdr *msg;
206
+ ...
207
+ cmsg = CMSG_FIRSTHDR(msg);
208
+ cmsg->cmsg_level = SOL_SOCKET;
209
+ cmsg->cmsg_type = SO_TIMESTAMPING;
210
+ cmsg->cmsg_len = CMSG_LEN(sizeof(__u32));
211
+ *((__u32 *) CMSG_DATA(cmsg)) = SOF_TIMESTAMPING_TX_SCHED |
212
+ SOF_TIMESTAMPING_TX_SOFTWARE |
213
+ SOF_TIMESTAMPING_TX_ACK;
214
+ err = sendmsg(fd , msg , 0);
215
+
216
+ The SOF_TIMESTAMPING_TX_* flags set via cmsg will override
217
+ the SOF_TIMESTAMPING_TX_* flags set via setsockopt.
218
+
219
+ Moreover , applications must still enable timestamp reporting via
220
+ setsockopt to receive timestamps:
221
+
222
+ __u32 val = SOF_TIMESTAMPING_SOFTWARE |
223
+ SOF_TIMESTAMPING_OPT_ID /* or any other flag */;
224
+ err = setsockopt(fd , SOL_SOCKET , SO_TIMESTAMPING , (void *) val ,
225
+ sizeof(val));
226
+
227
+
186
228
1.4 Bytestream Timestamps
187
229
188
230
The SO_TIMESTAMPING interface supports timestamping of bytes in a
0 commit comments