Skip to content

Commit fd91e12

Browse files
soheilhydavem330
authored andcommitted
sock: document timestamping via cmsg in Documentation
Update docs and add code snippet for using cmsg for timestamping. Signed-off-by: Soheil Hassas Yeganeh <[email protected]> Acked-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c14ac94 commit fd91e12

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

Documentation/networking/timestamping.txt

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ timeval of SO_TIMESTAMP (ms).
4444
Supports multiple types of timestamp requests. As a result, this
4545
socket option takes a bitmap of flags, not a boolean. In
4646

47-
err = setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, (void *) val, &val);
47+
err = setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, (void *) val,
48+
sizeof(val));
4849

4950
val is an integer with any of the following bits set. Setting other
5051
bit returns EINVAL and does not change the current state.
5152

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+
5258

5359
1.3.1 Timestamp Generation
5460

@@ -71,13 +77,16 @@ SOF_TIMESTAMPING_RX_SOFTWARE:
7177
kernel receive stack.
7278

7379
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.
7582

7683
SOF_TIMESTAMPING_TX_SOFTWARE:
7784
Request tx timestamps when data leaves the kernel. These timestamps
7885
are generated in the device driver as close as possible, but always
7986
prior to, passing the packet to the network interface. Hence, they
8087
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+
8190

8291
SOF_TIMESTAMPING_TX_SCHED:
8392
Request tx timestamps prior to entering the packet scheduler. Kernel
@@ -90,7 +99,8 @@ SOF_TIMESTAMPING_TX_SCHED:
9099
machines with virtual devices where a transmitted packet travels
91100
through multiple devices and, hence, multiple packet schedulers,
92101
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.
94104

95105
SOF_TIMESTAMPING_TX_ACK:
96106
Request tx timestamps when all data in the send buffer has been
@@ -99,6 +109,7 @@ SOF_TIMESTAMPING_TX_ACK:
99109
over-report measurement, because the timestamp is generated when all
100110
data up to and including the buffer at send() was acknowledged: the
101111
cumulative acknowledgment. The mechanism ignores SACK and FACK.
112+
This flag can be enabled via both socket options and control messages.
102113

103114

104115
1.3.2 Timestamp Reporting
@@ -183,6 +194,37 @@ having access to the contents of the original packet, so cannot be
183194
combined with SOF_TIMESTAMPING_OPT_TSONLY.
184195

185196

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+
186228
1.4 Bytestream Timestamps
187229

188230
The SO_TIMESTAMPING interface supports timestamping of bytes in a

0 commit comments

Comments
 (0)