Documentation/translations/zh_CN/networking/timestamping.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/networking/timestamping.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/networking/timestamping.rst- Extension
.rst- Size
- 34923 bytes
- Lines
- 675
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: documentation
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
struct scm_timestampingstruct scm_timestamping64struct hwtstamp_configstruct skb_shared_hwtstamps
Annotated Snippet
struct scm_timestamping {
struct timespec ts[3];
};
对于 SO_TIMESTAMPING_NEW::
struct scm_timestamping64 {
struct __kernel_timespec ts[3];
始终使用 SO_TIMESTAMPING_NEW 时间戳以始终获得 struct scm_timestamping64
格式的时间戳。
SO_TIMESTAMPING_OLD 在 32 位机器上 2038 年后返回错误的时间戳。
该结构可以返回最多三个时间戳。这是一个遗留功能。任何时候至少有一个字
段不为零。大多数时间戳都通过 ts[0] 传递。硬件时间戳通过 ts[2] 传递。
ts[1] 以前用于存储硬件时间戳转换为系统时间。相反,将硬件时钟设备直接
暴露为HW PTP时钟源,以允许用户空间进行时间转换,并可选地与用户空间
PTP 堆栈(如linuxptp)同步系统时间。对于 PTP 时钟 API,请参阅
Documentation/driver-api/ptp.rst。
注意,如果同时启用了 SO_TIMESTAMP 或 SO_TIMESTAMPNS 与
SO_TIMESTAMPING 使用 SOF_TIMESTAMPING_SOFTWARE,在 recvmsg()
调用时会生成一个虚假的软件时间戳,并传递给 ts[0] 当真实软件时间戳缺
失时。这也发生在硬件传输时间戳上。
2.1.1 传输时间戳与 MSG_ERRQUEUE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
对于传输时间戳,传出数据包回环到套接字的错误队列,并附加发送时间戳(s)。
进程通过调用带有 MSG_ERRQUEUE 标志的 recvmsg() 接收时间戳,并传递
一个足够大的 msg_control缓冲区以接收相关的元数据结构。recvmsg 调用
返回原始传出数据包,并附加两个辅助消息。
一个 cm_level SOL_IP(V6) 和 cm_type IP(V6)_RECVERR 嵌入一个
struct sock_extended_err这定义了错误类型。对于时间戳,ee_errno
字段是 ENOMSG。另一个辅助消息将具有 cm_level SOL_SOCKET 和 cm_type
SCM_TIMESTAMPING。这嵌入了 struct scm_timestamping。
2.1.1.2 时间戳类型
~~~~~~~~~~~~~~~~~~
三个 struct timespec 的语义由 struct sock_extended_err 中的
ee_info 字段定义。它包含一个类型 SCM_TSTAMP_* 来定义实际传递给
scm_timestamping 的时间戳。
SCM_TSTAMP_* 类型与之前讨论的 SOF_TIMESTAMPING_* 控制字段完全
匹配,只有一个例外对于遗留原因,SCM_TSTAMP_SND 等于零,可以设置为
SOF_TIMESTAMPING_TX_HARDWARE 和 SOF_TIMESTAMPING_TX_SOFTWARE。
它是第一个,如果 ts[2] 不为零,否则是第二个,在这种情况下,时间戳存
储在ts[0] 中。
2.1.1.3 分片
~~~~~~~~~~~~
传出数据报分片很少见,但可能发生,例如通过显式禁用 PMTU 发现。如果
传出数据包被分片,则仅对第一个分片进行时间戳,并返回给发送套接字。
2.1.1.4 数据包负载
~~~~~~~~~~~~~~~~~~
调用应用程序通常不关心接收它传递给堆栈的整个数据包负载:套接字错误队
列机制仅是一种将时间戳附加到其上的方法。在这种情况下,应用程序可以选
择读取较小的数据报,甚至长度为 0。负载相应地被截断。直到进程调用
recvmsg() 到错误队列,然而,整个数据包仍在队列中,占用 SO_RCVBUF 预算。
Annotation
- Detected declarations: `struct scm_timestamping`, `struct scm_timestamping64`, `struct hwtstamp_config`, `struct skb_shared_hwtstamps`.
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.