Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

docs: networking: convert timestamping.txt to ReST

- add SPDX header;
- add a document title;
- adjust titles and chapters, adding proper markups;
- mark code blocks and literals as such;
- adjust identation, whitespaces and blank lines where needed;
- add to networking/index.rst.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Mauro Carvalho Chehab and committed by
David S. Miller
06bfa47e aa8a6ee3

+91 -70
+1
Documentation/networking/index.rst
··· 109 109 tc-actions-env-rules 110 110 tcp-thin 111 111 team 112 + timestamping 112 113 113 114 .. only:: subproject and html 114 115
+2 -2
Documentation/networking/packet_mmap.rst
··· 1030 1030 NIC is capable of timestamping packets in hardware, you can request those 1031 1031 hardware timestamps to be used. Note: you may need to enable the generation 1032 1032 of hardware timestamps with SIOCSHWTSTAMP (see related information from 1033 - Documentation/networking/timestamping.txt). 1033 + Documentation/networking/timestamping.rst). 1034 1034 1035 1035 PACKET_TIMESTAMP accepts the same integer bit field as SO_TIMESTAMPING:: 1036 1036 ··· 1069 1069 members do not contain a valid value. For TX_RINGs, by default no timestamp 1070 1070 is generated! 1071 1071 1072 - See include/linux/net_tstamp.h and Documentation/networking/timestamping.txt 1072 + See include/linux/net_tstamp.h and Documentation/networking/timestamping.rst 1073 1073 for more information on hardware timestamps. 1074 1074 1075 1075 Miscellaneous bits
+87 -67
Documentation/networking/timestamping.txt Documentation/networking/timestamping.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + ============ 4 + Timestamping 5 + ============ 6 + 1 7 2 8 1. Control Interfaces 9 + ===================== 3 10 4 11 The interfaces for receiving network packages timestamps are: 5 12 6 - * SO_TIMESTAMP 13 + SO_TIMESTAMP 7 14 Generates a timestamp for each incoming packet in (not necessarily 8 15 monotonic) system time. Reports the timestamp via recvmsg() in a 9 16 control message in usec resolution. ··· 20 13 SO_TIMESTAMP_OLD and in struct __kernel_sock_timeval for 21 14 SO_TIMESTAMP_NEW options respectively. 22 15 23 - * SO_TIMESTAMPNS 16 + SO_TIMESTAMPNS 24 17 Same timestamping mechanism as SO_TIMESTAMP, but reports the 25 18 timestamp as struct timespec in nsec resolution. 26 19 SO_TIMESTAMPNS is defined as SO_TIMESTAMPNS_NEW or SO_TIMESTAMPNS_OLD ··· 29 22 and in struct __kernel_timespec for SO_TIMESTAMPNS_NEW options 30 23 respectively. 31 24 32 - * IP_MULTICAST_LOOP + SO_TIMESTAMP[NS] 25 + IP_MULTICAST_LOOP + SO_TIMESTAMP[NS] 33 26 Only for multicast:approximate transmit timestamp obtained by 34 27 reading the looped packet receive timestamp. 35 28 36 - * SO_TIMESTAMPING 29 + SO_TIMESTAMPING 37 30 Generates timestamps on reception, transmission or both. Supports 38 31 multiple timestamp sources, including hardware. Supports generating 39 32 timestamps for stream sockets. 40 33 41 34 42 - 1.1 SO_TIMESTAMP (also SO_TIMESTAMP_OLD and SO_TIMESTAMP_NEW): 35 + 1.1 SO_TIMESTAMP (also SO_TIMESTAMP_OLD and SO_TIMESTAMP_NEW) 36 + ------------------------------------------------------------- 43 37 44 38 This socket option enables timestamping of datagrams on the reception 45 39 path. Because the destination socket, if any, is not known early in ··· 67 59 SO_TIMESTAMPNS_OLD returns incorrect timestamps after the year 2038 68 60 on 32 bit machines. 69 61 70 - 1.3 SO_TIMESTAMPING (also SO_TIMESTAMPING_OLD and SO_TIMESTAMPING_NEW): 62 + 1.3 SO_TIMESTAMPING (also SO_TIMESTAMPING_OLD and SO_TIMESTAMPING_NEW) 63 + ---------------------------------------------------------------------- 71 64 72 65 Supports multiple types of timestamp requests. As a result, this 73 - socket option takes a bitmap of flags, not a boolean. In 66 + socket option takes a bitmap of flags, not a boolean. In:: 74 67 75 68 err = setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, &val, sizeof(val)); 76 69 ··· 85 76 86 77 87 78 1.3.1 Timestamp Generation 79 + ^^^^^^^^^^^^^^^^^^^^^^^^^^ 88 80 89 81 Some bits are requests to the stack to try to generate timestamps. Any 90 82 combination of them is valid. Changes to these bits apply to newly ··· 116 106 require driver support and may not be available for all devices. 117 107 This flag can be enabled via both socket options and control messages. 118 108 119 - 120 109 SOF_TIMESTAMPING_TX_SCHED: 121 110 Request tx timestamps prior to entering the packet scheduler. Kernel 122 111 transmit latency is, if long, often dominated by queuing delay. The ··· 141 132 142 133 143 134 1.3.2 Timestamp Reporting 135 + ^^^^^^^^^^^^^^^^^^^^^^^^^ 144 136 145 137 The other three bits control which timestamps will be reported in a 146 138 generated control message. Changes to the bits take immediate ··· 161 151 162 152 163 153 1.3.3 Timestamp Options 154 + ^^^^^^^^^^^^^^^^^^^^^^^ 164 155 165 156 The interface supports the options 166 157 167 158 SOF_TIMESTAMPING_OPT_ID: 168 - 169 159 Generate a unique identifier along with each packet. A process can 170 160 have multiple concurrent timestamping requests outstanding. Packets 171 161 can be reordered in the transmit path, for instance in the packet ··· 193 183 194 184 195 185 SOF_TIMESTAMPING_OPT_CMSG: 196 - 197 186 Support recv() cmsg for all timestamped packets. Control messages 198 187 are already supported unconditionally on all packets with receive 199 188 timestamps and on IPv6 packets with transmit timestamp. This option ··· 202 193 203 194 204 195 SOF_TIMESTAMPING_OPT_TSONLY: 205 - 206 196 Applies to transmit timestamps only. Makes the kernel return the 207 197 timestamp as a cmsg alongside an empty packet, as opposed to 208 198 alongside the original packet. This reduces the amount of memory ··· 210 202 This option disables SOF_TIMESTAMPING_OPT_CMSG. 211 203 212 204 SOF_TIMESTAMPING_OPT_STATS: 213 - 214 205 Optional stats that are obtained along with the transmit timestamps. 215 206 It must be used together with SOF_TIMESTAMPING_OPT_TSONLY. When the 216 207 transmit timestamp is available, the stats are available in a ··· 220 213 data was limited by peer's receiver window. 221 214 222 215 SOF_TIMESTAMPING_OPT_PKTINFO: 223 - 224 216 Enable the SCM_TIMESTAMPING_PKTINFO control message for incoming 225 217 packets with hardware timestamps. The message contains struct 226 218 scm_ts_pktinfo, which supplies the index of the real interface which ··· 229 223 other fields, but they are reserved and undefined. 230 224 231 225 SOF_TIMESTAMPING_OPT_TX_SWHW: 232 - 233 226 Request both hardware and software timestamps for outgoing packets 234 227 when SOF_TIMESTAMPING_TX_HARDWARE and SOF_TIMESTAMPING_TX_SOFTWARE 235 228 are enabled at the same time. If both timestamps are generated, ··· 247 242 248 243 249 244 1.3.4. Enabling timestamps via control messages 245 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 250 246 251 247 In addition to socket options, timestamp generation can be requested 252 248 per write via cmsg, only for SOF_TIMESTAMPING_TX_* (see Section 1.3.1). 253 249 Using this feature, applications can sample timestamps per sendmsg() 254 250 without paying the overhead of enabling and disabling timestamps via 255 - setsockopt: 251 + setsockopt:: 256 252 257 253 struct msghdr *msg; 258 254 ... ··· 270 264 the SOF_TIMESTAMPING_TX_* flags set via setsockopt. 271 265 272 266 Moreover, applications must still enable timestamp reporting via 273 - setsockopt to receive timestamps: 267 + setsockopt to receive timestamps:: 274 268 275 269 __u32 val = SOF_TIMESTAMPING_SOFTWARE | 276 270 SOF_TIMESTAMPING_OPT_ID /* or any other flag */; ··· 278 272 279 273 280 274 1.4 Bytestream Timestamps 275 + ------------------------- 281 276 282 277 The SO_TIMESTAMPING interface supports timestamping of bytes in a 283 278 bytestream. Each request is interpreted as a request for when the ··· 338 331 339 332 340 333 2 Data Interfaces 334 + ================== 341 335 342 336 Timestamps are read using the ancillary data feature of recvmsg(). 343 337 See `man 3 cmsg` for details of this interface. The socket manual ··· 347 339 348 340 349 341 2.1 SCM_TIMESTAMPING records 342 + ---------------------------- 350 343 351 344 These timestamps are returned in a control message with cmsg_level 352 345 SOL_SOCKET, cmsg_type SCM_TIMESTAMPING, and payload of type 353 346 354 - For SO_TIMESTAMPING_OLD: 347 + For SO_TIMESTAMPING_OLD:: 355 348 356 - struct scm_timestamping { 357 - struct timespec ts[3]; 358 - }; 349 + struct scm_timestamping { 350 + struct timespec ts[3]; 351 + }; 359 352 360 - For SO_TIMESTAMPING_NEW: 353 + For SO_TIMESTAMPING_NEW:: 361 354 362 - struct scm_timestamping64 { 363 - struct __kernel_timespec ts[3]; 355 + struct scm_timestamping64 { 356 + struct __kernel_timespec ts[3]; 364 357 365 358 Always use SO_TIMESTAMPING_NEW timestamp to always get timestamp in 366 359 struct scm_timestamping64 format. ··· 386 377 on hardware transmit timestamps. 387 378 388 379 2.1.1 Transmit timestamps with MSG_ERRQUEUE 380 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 389 381 390 382 For transmit timestamps the outgoing packet is looped back to the 391 383 socket's error queue with the send timestamp(s) attached. A process ··· 403 393 404 394 405 395 2.1.1.2 Timestamp types 396 + ~~~~~~~~~~~~~~~~~~~~~~~ 406 397 407 398 The semantics of the three struct timespec are defined by field 408 399 ee_info in the extended error structure. It contains a value of ··· 419 408 420 409 421 410 2.1.1.3 Fragmentation 411 + ~~~~~~~~~~~~~~~~~~~~~ 422 412 423 413 Fragmentation of outgoing datagrams is rare, but is possible, e.g., by 424 414 explicitly disabling PMTU discovery. If an outgoing packet is fragmented, ··· 428 416 429 417 430 418 2.1.1.4 Packet Payload 419 + ~~~~~~~~~~~~~~~~~~~~~~ 431 420 432 421 The calling application is often not interested in receiving the whole 433 422 packet payload that it passed to the stack originally: the socket ··· 440 427 441 428 442 429 2.1.1.5 Blocking Read 430 + ~~~~~~~~~~~~~~~~~~~~~ 443 431 444 432 Reading from the error queue is always a non-blocking operation. To 445 433 block waiting on a timestamp, use poll or select. poll() will return ··· 450 436 451 437 452 438 2.1.2 Receive timestamps 439 + ^^^^^^^^^^^^^^^^^^^^^^^^ 453 440 454 441 On reception, there is no reason to read from the socket error queue. 455 442 The SCM_TIMESTAMPING ancillary data is sent along with the packet data ··· 462 447 463 448 464 449 3. Hardware Timestamping configuration: SIOCSHWTSTAMP and SIOCGHWTSTAMP 450 + ======================================================================= 465 451 466 452 Hardware time stamping must also be initialized for each device driver 467 453 that is expected to do hardware time stamping. The parameter is defined in 468 - include/uapi/linux/net_tstamp.h as: 454 + include/uapi/linux/net_tstamp.h as:: 469 455 470 - struct hwtstamp_config { 471 - int flags; /* no flags defined right now, must be zero */ 472 - int tx_type; /* HWTSTAMP_TX_* */ 473 - int rx_filter; /* HWTSTAMP_FILTER_* */ 474 - }; 456 + struct hwtstamp_config { 457 + int flags; /* no flags defined right now, must be zero */ 458 + int tx_type; /* HWTSTAMP_TX_* */ 459 + int rx_filter; /* HWTSTAMP_FILTER_* */ 460 + }; 475 461 476 462 Desired behavior is passed into the kernel and to a specific device by 477 463 calling ioctl(SIOCSHWTSTAMP) with a pointer to a struct ifreq whose ··· 503 487 structure to ioctl(SIOCGHWTSTAMP) in the same way. However, this has 504 488 not been implemented in all drivers. 505 489 506 - /* possible values for hwtstamp_config->tx_type */ 507 - enum { 508 - /* 509 - * no outgoing packet will need hardware time stamping; 510 - * should a packet arrive which asks for it, no hardware 511 - * time stamping will be done 512 - */ 513 - HWTSTAMP_TX_OFF, 490 + :: 514 491 515 - /* 516 - * enables hardware time stamping for outgoing packets; 517 - * the sender of the packet decides which are to be 518 - * time stamped by setting SOF_TIMESTAMPING_TX_SOFTWARE 519 - * before sending the packet 520 - */ 521 - HWTSTAMP_TX_ON, 522 - }; 492 + /* possible values for hwtstamp_config->tx_type */ 493 + enum { 494 + /* 495 + * no outgoing packet will need hardware time stamping; 496 + * should a packet arrive which asks for it, no hardware 497 + * time stamping will be done 498 + */ 499 + HWTSTAMP_TX_OFF, 523 500 524 - /* possible values for hwtstamp_config->rx_filter */ 525 - enum { 526 - /* time stamp no incoming packet at all */ 527 - HWTSTAMP_FILTER_NONE, 501 + /* 502 + * enables hardware time stamping for outgoing packets; 503 + * the sender of the packet decides which are to be 504 + * time stamped by setting SOF_TIMESTAMPING_TX_SOFTWARE 505 + * before sending the packet 506 + */ 507 + HWTSTAMP_TX_ON, 508 + }; 528 509 529 - /* time stamp any incoming packet */ 530 - HWTSTAMP_FILTER_ALL, 510 + /* possible values for hwtstamp_config->rx_filter */ 511 + enum { 512 + /* time stamp no incoming packet at all */ 513 + HWTSTAMP_FILTER_NONE, 531 514 532 - /* return value: time stamp all packets requested plus some others */ 533 - HWTSTAMP_FILTER_SOME, 515 + /* time stamp any incoming packet */ 516 + HWTSTAMP_FILTER_ALL, 534 517 535 - /* PTP v1, UDP, any kind of event packet */ 536 - HWTSTAMP_FILTER_PTP_V1_L4_EVENT, 518 + /* return value: time stamp all packets requested plus some others */ 519 + HWTSTAMP_FILTER_SOME, 537 520 538 - /* for the complete list of values, please check 539 - * the include file include/uapi/linux/net_tstamp.h 540 - */ 541 - }; 521 + /* PTP v1, UDP, any kind of event packet */ 522 + HWTSTAMP_FILTER_PTP_V1_L4_EVENT, 523 + 524 + /* for the complete list of values, please check 525 + * the include file include/uapi/linux/net_tstamp.h 526 + */ 527 + }; 542 528 543 529 3.1 Hardware Timestamping Implementation: Device Drivers 530 + -------------------------------------------------------- 544 531 545 532 A driver which supports hardware time stamping must support the 546 533 SIOCSHWTSTAMP ioctl and update the supplied struct hwtstamp_config with ··· 552 533 553 534 Time stamps for received packets must be stored in the skb. To get a pointer 554 535 to the shared time stamp structure of the skb call skb_hwtstamps(). Then 555 - set the time stamps in the structure: 536 + set the time stamps in the structure:: 556 537 557 - struct skb_shared_hwtstamps { 558 - /* hardware time stamp transformed into duration 559 - * since arbitrary point in time 560 - */ 561 - ktime_t hwtstamp; 562 - }; 538 + struct skb_shared_hwtstamps { 539 + /* hardware time stamp transformed into duration 540 + * since arbitrary point in time 541 + */ 542 + ktime_t hwtstamp; 543 + }; 563 544 564 545 Time stamps for outgoing packets are to be generated as follows: 546 + 565 547 - In hard_start_xmit(), check if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) 566 548 is set no-zero. If yes, then the driver is expected to do hardware time 567 549 stamping. 568 550 - If this is possible for the skb and requested, then declare 569 551 that the driver is doing the time stamping by setting the flag 570 - SKBTX_IN_PROGRESS in skb_shinfo(skb)->tx_flags , e.g. with 552 + SKBTX_IN_PROGRESS in skb_shinfo(skb)->tx_flags , e.g. with:: 571 553 572 554 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; 573 555
+1 -1
include/uapi/linux/errqueue.h
··· 36 36 * 37 37 * The timestamping interfaces SO_TIMESTAMPING, MSG_TSTAMP_* 38 38 * communicate network timestamps by passing this struct in a cmsg with 39 - * recvmsg(). See Documentation/networking/timestamping.txt for details. 39 + * recvmsg(). See Documentation/networking/timestamping.rst for details. 40 40 * User space sees a timespec definition that matches either 41 41 * __kernel_timespec or __kernel_old_timespec, in the kernel we 42 42 * require two structure definitions to provide both.