diff options
author | Soheil Hassas Yeganeh <soheil@google.com> | 2016-04-02 23:08:13 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-04-04 15:50:30 -0400 |
commit | fd91e12f594b40fdb2dad530e8b895cc5c07db21 (patch) | |
tree | 389af6ce3edd29017764f8f325c92c8e9cdb7569 /Documentation/networking/timestamping.txt | |
parent | c14ac9451c34832554db33386a4393be8bba3a7b (diff) |
sock: document timestamping via cmsg in Documentation
Update docs and add code snippet for using cmsg for timestamping.
Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'Documentation/networking/timestamping.txt')
-rw-r--r-- | Documentation/networking/timestamping.txt | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/Documentation/networking/timestamping.txt b/Documentation/networking/timestamping.txt index a977339fbe0a..671cccf0dcd2 100644 --- a/Documentation/networking/timestamping.txt +++ b/Documentation/networking/timestamping.txt | |||
@@ -44,11 +44,17 @@ timeval of SO_TIMESTAMP (ms). | |||
44 | Supports multiple types of timestamp requests. As a result, this | 44 | Supports multiple types of timestamp requests. As a result, this |
45 | socket option takes a bitmap of flags, not a boolean. In | 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 | val is an integer with any of the following bits set. Setting other | 50 | val is an integer with any of the following bits set. Setting other |
50 | bit returns EINVAL and does not change the current state. | 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 | 1.3.1 Timestamp Generation | 59 | 1.3.1 Timestamp Generation |
54 | 60 | ||
@@ -71,13 +77,16 @@ SOF_TIMESTAMPING_RX_SOFTWARE: | |||
71 | kernel receive stack. | 77 | kernel receive stack. |
72 | 78 | ||
73 | SOF_TIMESTAMPING_TX_HARDWARE: | 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 | SOF_TIMESTAMPING_TX_SOFTWARE: | 83 | SOF_TIMESTAMPING_TX_SOFTWARE: |
77 | Request tx timestamps when data leaves the kernel. These timestamps | 84 | Request tx timestamps when data leaves the kernel. These timestamps |
78 | are generated in the device driver as close as possible, but always | 85 | are generated in the device driver as close as possible, but always |
79 | prior to, passing the packet to the network interface. Hence, they | 86 | prior to, passing the packet to the network interface. Hence, they |
80 | require driver support and may not be available for all devices. | 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 | SOF_TIMESTAMPING_TX_SCHED: | 91 | SOF_TIMESTAMPING_TX_SCHED: |
83 | Request tx timestamps prior to entering the packet scheduler. Kernel | 92 | Request tx timestamps prior to entering the packet scheduler. Kernel |
@@ -90,7 +99,8 @@ SOF_TIMESTAMPING_TX_SCHED: | |||
90 | machines with virtual devices where a transmitted packet travels | 99 | machines with virtual devices where a transmitted packet travels |
91 | through multiple devices and, hence, multiple packet schedulers, | 100 | through multiple devices and, hence, multiple packet schedulers, |
92 | a timestamp is generated at each layer. This allows for fine | 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 | SOF_TIMESTAMPING_TX_ACK: | 105 | SOF_TIMESTAMPING_TX_ACK: |
96 | Request tx timestamps when all data in the send buffer has been | 106 | Request tx timestamps when all data in the send buffer has been |
@@ -99,6 +109,7 @@ SOF_TIMESTAMPING_TX_ACK: | |||
99 | over-report measurement, because the timestamp is generated when all | 109 | over-report measurement, because the timestamp is generated when all |
100 | data up to and including the buffer at send() was acknowledged: the | 110 | data up to and including the buffer at send() was acknowledged: the |
101 | cumulative acknowledgment. The mechanism ignores SACK and FACK. | 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 | 1.3.2 Timestamp Reporting | 115 | 1.3.2 Timestamp Reporting |
@@ -183,6 +194,37 @@ having access to the contents of the original packet, so cannot be | |||
183 | combined with SOF_TIMESTAMPING_OPT_TSONLY. | 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 | 1.4 Bytestream Timestamps | 228 | 1.4 Bytestream Timestamps |
187 | 229 | ||
188 | The SO_TIMESTAMPING interface supports timestamping of bytes in a | 230 | The SO_TIMESTAMPING interface supports timestamping of bytes in a |