af_packet: don't enable global timestamps
Subsystems (3)
Andi mentioned he did something like this already, but never submitted it.
The dhcp client application uses AF_PACKET with a packet filter to receive data. The application doesn't even use timestamps, but because the AF_PACKET API has timestamps, they get turned on globally which causes an expensive time of day lookup for every packet received on any system that uses the standard DHCP client.
The fix is to not enable the timestamp (but use if if available). This causes the time lookup to only occur on those packets that are destined for the AF_PACKET socket.
The timestamping occurs after packet filtering
so all packets dropped by filtering to not cause a clock call.
The one downside of this a a few microseconds additional delay added from the normal timestamping location (netif_rx) until the receive callback in AF_PACKET. But since the offset is fairly consistent it should not upset applications that do want really use timestamps, like wireshark.
net/packet/af_packet.c +4 -5
@@ -640,11 +640,10 @@ static int tpacket_rcv(struct sk_buff *s h->tp_snaplen = snaplen; h->tp_mac = macoff; h->tp_net = netoff; -if (skb->tstamp.tv64 ==0 ) { -__net_timestamp (skb); -sock_enable_timestamp (sk); - } - tv =ktime_to_timeval (skb->tstamp); +if (skb->tstamp.tv64) + tv =ktime_to_timeval (skb->tstamp); +else +do_gettimeofday (&tv); h->tp_sec = tv.tv_sec; h->tp_usec = tv.tv_usec;
Quoted 15 lines · On Tue, 4 Sep 2007 06:35:25 +0100 Stephen Hemminger…
Andi mentioned he did something like this already, but never submitted it.
The dhcp client application uses
AF_PACKETwith a packet filter to receive data. The application doesn't even use timestamps, but because theAF_PACKETAPI has timestamps, they get turned on globally which causes an expensive time of day lookup for every packet received on any system that uses the standard DHCP client.The fix is to not enable the timestamp (but use if if available). This causes the time lookup to only occur on those packets that are destined for the
AF_PACKETsocket.
The timestamping occurs after packet filtering
so all packets dropped by filtering to not cause a clock call.
Quoted 5 lines
The one downside of this a a few microseconds additional delay added from the normal timestamping location (
netif_rx) until the receive callback inAF_PACKET. But since the offset is fairly consistent it should not upset applications that do want really use timestamps, like wireshark.
This patch seems the correct fix for this longstanding problem.
Please note that if wireshark/tcpdump processes really want precise timestamps,
they still can ask this by using setsockopt(SO_TIMESTAMP or SO_TIMESTAMPNS) on their private socket.
(We already know that running a sniffer has a cost anyway)
Quoted 22 lines
Signed-off-by Stephen Hemminger <[email protected]>net/packet/af_packet.c +4
-5@@ -640,11 +640,10 @@ static int tpacket_rcv(struct sk_buff *s h->tp_snaplen = snaplen; h->tp_mac = macoff; h->tp_net = netoff; -if (skb->tstamp.tv64 ==0 ) { -__net_timestamp (skb); -sock_enable_timestamp (sk); - } - tv =ktime_to_timeval (skb->tstamp); +if (skb->tstamp.tv64) + tv =ktime_to_timeval (skb->tstamp); +else +do_gettimeofday (&tv); h->tp_sec = tv.tv_sec; h->tp_usec = tv.tv_usec;
From: Eric Dumazet <[email protected]>
Date: Tue, 4 Sep 2007 09:59:58 +0200
Quoted 6 lines
This patch seems the correct fix for this longstanding problem.
Please note that if wireshark/tcpdump processes really want precise timestamps,
they still can ask this by usingsetsockopt(SO_TIMESTAMP or SO_TIMESTAMPNS)on their private socket.(We already know that running a sniffer has a cost anyway)
Agreed, let's give this a try.
I've applied Stephen's patch to net-2.6.24