From: Daniel Borkmann <dborkman@redhat.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, willemb@google.com,
Paul.Chavent@onera.fr, richardcochran@gmail.com
Subject: [PATCH net-next 2/5] packet: enable hardware tx timestamping on tpacket ring
Date: Tue, 23 Apr 2013 12:39:29 +0200 [thread overview]
Message-ID: <1366713572-11978-3-git-send-email-dborkman@redhat.com> (raw)
In-Reply-To: <1366713572-11978-1-git-send-email-dborkman@redhat.com>
Currently, we only have software timestamping for the TX ring buffer
path, but this limitation stems rather from the implementation. By
just reusing tpacket_get_timestamp(), we can also allow hardware
timestamping just as in the RX path.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
---
net/packet/af_packet.c | 50 +++++++++++++++++++++++++-------------------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 1f792ab..e7892a4 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -339,14 +339,33 @@ static int __packet_get_status(struct packet_sock *po, void *frame)
}
}
+static bool tpacket_get_timestamp(struct sk_buff *skb, struct timespec *ts,
+ unsigned int flags)
+{
+ struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
+
+ if (shhwtstamps) {
+ if ((flags & SOF_TIMESTAMPING_SYS_HARDWARE) &&
+ ktime_to_timespec_cond(shhwtstamps->syststamp, ts))
+ return true;
+ if ((flags & SOF_TIMESTAMPING_RAW_HARDWARE) &&
+ ktime_to_timespec_cond(shhwtstamps->hwtstamp, ts))
+ return true;
+ }
+
+ if (ktime_to_timespec_cond(skb->tstamp, ts))
+ return true;
+
+ return false;
+}
+
static void __packet_set_timestamp(struct packet_sock *po, void *frame,
- ktime_t tstamp)
+ struct sk_buff *skb)
{
union tpacket_uhdr h;
struct timespec ts;
- if (!ktime_to_timespec_cond(tstamp, &ts) ||
- !sock_flag(&po->sk, SOCK_TIMESTAMPING_SOFTWARE))
+ if (!tpacket_get_timestamp(skb, &ts, po->tp_tstamp))
return;
h.raw = frame;
@@ -1688,26 +1707,6 @@ drop:
return 0;
}
-static void tpacket_get_timestamp(struct sk_buff *skb, struct timespec *ts,
- unsigned int flags)
-{
- struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
-
- if (shhwtstamps) {
- if ((flags & SOF_TIMESTAMPING_SYS_HARDWARE) &&
- ktime_to_timespec_cond(shhwtstamps->syststamp, ts))
- return;
- if ((flags & SOF_TIMESTAMPING_RAW_HARDWARE) &&
- ktime_to_timespec_cond(shhwtstamps->hwtstamp, ts))
- return;
- }
-
- if (ktime_to_timespec_cond(skb->tstamp, ts))
- return;
-
- getnstimeofday(ts);
-}
-
static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev)
{
@@ -1804,7 +1803,8 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
spin_unlock(&sk->sk_receive_queue.lock);
skb_copy_bits(skb, 0, h.raw + macoff, snaplen);
- tpacket_get_timestamp(skb, &ts, po->tp_tstamp);
+ if (!tpacket_get_timestamp(skb, &ts, po->tp_tstamp))
+ getnstimeofday(&ts);
switch (po->tp_version) {
case TPACKET_V1:
@@ -1908,7 +1908,7 @@ static void tpacket_destruct_skb(struct sk_buff *skb)
ph = skb_shinfo(skb)->destructor_arg;
BUG_ON(atomic_read(&po->tx_ring.pending) == 0);
atomic_dec(&po->tx_ring.pending);
- __packet_set_timestamp(po, ph, skb->tstamp);
+ __packet_set_timestamp(po, ph, skb);
__packet_set_status(po, ph, TP_STATUS_AVAILABLE);
}
--
1.7.11.7
next prev parent reply other threads:[~2013-04-23 10:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-23 10:39 [PATCH net-next 0/5] PF_PACKET timestamping updates Daniel Borkmann
2013-04-23 10:39 ` [PATCH net-next 1/5] packet: tx timestamping on tpacket ring Daniel Borkmann
2013-04-23 10:39 ` Daniel Borkmann [this message]
2013-04-23 12:13 ` [PATCH net-next 2/5] packet: enable hardware " Willem de Bruijn
2013-04-23 10:39 ` [PATCH net-next 3/5] packet: minor: convert status bits into shifting format Daniel Borkmann
2013-04-23 12:22 ` Willem de Bruijn
2013-04-23 10:39 ` [PATCH net-next 4/5] packet: if hw/sw ts enabled in rx/tx ring, report which ts we got Daniel Borkmann
2013-04-23 12:18 ` Willem de Bruijn
2013-04-23 10:39 ` [PATCH net-next 5/5] packet: doc: update timestamping part Daniel Borkmann
2013-04-23 12:20 ` Willem de Bruijn
2013-04-23 12:33 ` [PATCH net-next 0/5] PF_PACKET timestamping updates Willem de Bruijn
2013-04-23 12:53 ` Daniel Borkmann
2013-04-23 18:13 ` Richard Cochran
2013-04-23 18:07 ` Richard Cochran
2013-04-25 5:35 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1366713572-11978-3-git-send-email-dborkman@redhat.com \
--to=dborkman@redhat.com \
--cc=Paul.Chavent@onera.fr \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).