From patchwork Fri Apr 1 15:04:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soheil Hassas Yeganeh X-Patchwork-Id: 604878 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3qc4Ry71hJz9sC4 for ; Sat, 2 Apr 2016 02:05:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=Ua82e4e+; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754803AbcDAPEy (ORCPT ); Fri, 1 Apr 2016 11:04:54 -0400 Received: from mail-qg0-f65.google.com ([209.85.192.65]:34907 "EHLO mail-qg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759011AbcDAPEs (ORCPT ); Fri, 1 Apr 2016 11:04:48 -0400 Received: by mail-qg0-f65.google.com with SMTP id b32so10464206qgf.2 for ; Fri, 01 Apr 2016 08:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=grtE0I9x8Kv7hstA1o3I1oR1KDcM+EvRzS74TMs1mCg=; b=Ua82e4e+USDyfaoLcy+Qed0jN7QWgmfTFjd90yE4ts9BDX/A3Tm3bjrpDWE6PSXzws FYe8vDJ8nm67OrDuDdh2GrZU9lTDNfRE2NARtkoExjEagN5/z55M+xXnVTw5jkD2AdQw Oj1UVbjJH5glOGMxHkSjZzlzoUDXWui8kIckuY7vtSKwFAFOKfMEuTDoj+yVUsu3aAA8 dcocycqg61FDoCNmtf4HL/AmG9In4dA8fPEQDlTIpZ2ZaV+r1TB9OPhPsSUISw26cldz qU/pZhTodI4Hgwmyar4rbY7Mjhki2vM4rJuEd2oqtfWZ8MFagu9GHy8baFox4GCQ98XX KEVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=grtE0I9x8Kv7hstA1o3I1oR1KDcM+EvRzS74TMs1mCg=; b=LsKRNluxKnz/zxJg9iFRZ/zYTBhcKD74nck+hYDc6M9WrtYX8zZURIky8nmtvxXkQM oTok/h/a7EmnHztAswPtq943X48vx9JbfaVE+RE6lvCx8z5kCi8oND4sEHCsKikBVpOq fK/FKcmSmsOWWFavwhfm8SW9yS6KDgFrtOVynVfDA+7UIwg/JkJ5V6l54jy7PhARMEk6 6bp10YaGVpwzkoQnsWDFO36PKJ3Iyy/Sy47I5QLisuuxjI9U32m8MzS5NMBxaLR1P67P 5V9LAMeyFspIB29RxRwOXjORI66sj6vHF06HlJRO9+CbuM+/rjaHfoTwv7m/dRtyUnXg gQBQ== X-Gm-Message-State: AD7BkJJql0ahDFq844pvTbmcJwKCCsPMUWKdr/zmArN1ImVGvE6q/N3bwop4gOePpV/45Q== X-Received: by 10.140.22.212 with SMTP id 78mr25775231qgn.77.1459523087071; Fri, 01 Apr 2016 08:04:47 -0700 (PDT) Received: from soheil.nyc.corp.google.com ([100.101.230.231]) by smtp.gmail.com with ESMTPSA id d6sm6312885qkb.13.2016.04.01.08.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Apr 2016 08:04:46 -0700 (PDT) From: Soheil Hassas Yeganeh To: davem@davemloft.net, netdev@vger.kernel.org Cc: willemb@google.com, edumazet@google.com, ycheng@google.com, ncardwell@google.com, kafai@fb.com, Soheil Hassas Yeganeh Subject: [PATCH v2 net-next 8/8] sock: document timestamping via cmsg in Documentation Date: Fri, 1 Apr 2016 11:04:40 -0400 Message-Id: <1459523080-29329-9-git-send-email-soheil.kdev@gmail.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1459523080-29329-1-git-send-email-soheil.kdev@gmail.com> References: <1459523080-29329-1-git-send-email-soheil.kdev@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Soheil Hassas Yeganeh Update docs and add code snippet for using cmsg for timestamping. Signed-off-by: Soheil Hassas Yeganeh Acked-by: Willem de Bruijn --- Documentation/networking/timestamping.txt | 48 +++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/Documentation/networking/timestamping.txt b/Documentation/networking/timestamping.txt index a977339..671cccf 100644 --- a/Documentation/networking/timestamping.txt +++ b/Documentation/networking/timestamping.txt @@ -44,11 +44,17 @@ timeval of SO_TIMESTAMP (ms). Supports multiple types of timestamp requests. As a result, this socket option takes a bitmap of flags, not a boolean. In - err = setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, (void *) val, &val); + err = setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, (void *) val, + sizeof(val)); val is an integer with any of the following bits set. Setting other bit returns EINVAL and does not change the current state. +The socket option configures timestamp generation for individual +sk_buffs (1.3.1), timestamp reporting to the socket's error +queue (1.3.2) and options (1.3.3). Timestamp generation can also +be enabled for individual sendmsg calls using cmsg (1.3.4). + 1.3.1 Timestamp Generation @@ -71,13 +77,16 @@ SOF_TIMESTAMPING_RX_SOFTWARE: kernel receive stack. SOF_TIMESTAMPING_TX_HARDWARE: - Request tx timestamps generated by the network adapter. + Request tx timestamps generated by the network adapter. This flag + can be enabled via both socket options and control messages. SOF_TIMESTAMPING_TX_SOFTWARE: Request tx timestamps when data leaves the kernel. These timestamps are generated in the device driver as close as possible, but always prior to, passing the packet to the network interface. Hence, they require driver support and may not be available for all devices. + This flag can be enabled via both socket options and control messages. + SOF_TIMESTAMPING_TX_SCHED: Request tx timestamps prior to entering the packet scheduler. Kernel @@ -90,7 +99,8 @@ SOF_TIMESTAMPING_TX_SCHED: machines with virtual devices where a transmitted packet travels through multiple devices and, hence, multiple packet schedulers, a timestamp is generated at each layer. This allows for fine - grained measurement of queuing delay. + grained measurement of queuing delay. This flag can be enabled + via both socket options and control messages. SOF_TIMESTAMPING_TX_ACK: Request tx timestamps when all data in the send buffer has been @@ -99,6 +109,7 @@ SOF_TIMESTAMPING_TX_ACK: over-report measurement, because the timestamp is generated when all data up to and including the buffer at send() was acknowledged: the cumulative acknowledgment. The mechanism ignores SACK and FACK. + This flag can be enabled via both socket options and control messages. 1.3.2 Timestamp Reporting @@ -183,6 +194,37 @@ having access to the contents of the original packet, so cannot be combined with SOF_TIMESTAMPING_OPT_TSONLY. +1.3.4. Enabling timestamps via control messages + +In addition to socket options, timestamp generation can be requested +per write via cmsg, only for SOF_TIMESTAMPING_TX_* (see Section 1.3.1). +Using this feature, applications can sample timestamps per sendmsg() +without paying the overhead of enabling and disabling timestamps via +setsockopt: + + struct msghdr *msg; + ... + cmsg = CMSG_FIRSTHDR(msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SO_TIMESTAMPING; + cmsg->cmsg_len = CMSG_LEN(sizeof(__u32)); + *((__u32 *) CMSG_DATA(cmsg)) = SOF_TIMESTAMPING_TX_SCHED | + SOF_TIMESTAMPING_TX_SOFTWARE | + SOF_TIMESTAMPING_TX_ACK; + err = sendmsg(fd, msg, 0); + +The SOF_TIMESTAMPING_TX_* flags set via cmsg will override +the SOF_TIMESTAMPING_TX_* flags set via setsockopt. + +Moreover, applications must still enable timestamp reporting via +setsockopt to receive timestamps: + + __u32 val = SOF_TIMESTAMPING_SOFTWARE | + SOF_TIMESTAMPING_OPT_ID /* or any other flag */; + err = setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, (void *) val, + sizeof(val)); + + 1.4 Bytestream Timestamps The SO_TIMESTAMPING interface supports timestamping of bytes in a