Commit 54002066 authored by Vedang Patel's avatar Vedang Patel Committed by David S. Miller

taprio: Adjust timestamps for TCP packets

When the taprio qdisc is running in "txtime offload" mode, it will
set the launchtime value (in skb->tstamp) for all the packets which do
not have the SO_TXTIME socket option. But, the TCP packets already have
this value set and it indicates the earliest departure time represented
in CLOCK_MONOTONIC clock.

We need to respect the timestamp set by the TCP subsystem. So, convert
this time to the clock which taprio is using and ensure that the packet
is not transmitted before the deadline set by TCP.
Signed-off-by: default avatarVedang Patel <vedang.patel@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7ede7b03
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <net/pkt_cls.h> #include <net/pkt_cls.h>
#include <net/sch_generic.h> #include <net/sch_generic.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/tcp.h>
static LIST_HEAD(taprio_list); static LIST_HEAD(taprio_list);
static DEFINE_SPINLOCK(taprio_list_lock); static DEFINE_SPINLOCK(taprio_list_lock);
...@@ -267,6 +268,41 @@ static bool is_valid_interval(struct sk_buff *skb, struct Qdisc *sch) ...@@ -267,6 +268,41 @@ static bool is_valid_interval(struct sk_buff *skb, struct Qdisc *sch)
return entry; return entry;
} }
/* This returns the tstamp value set by TCP in terms of the set clock. */
static ktime_t get_tcp_tstamp(struct taprio_sched *q, struct sk_buff *skb)
{
unsigned int offset = skb_network_offset(skb);
const struct ipv6hdr *ipv6h;
const struct iphdr *iph;
struct ipv6hdr _ipv6h;
ipv6h = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h);
if (!ipv6h)
return 0;
if (ipv6h->version == 4) {
iph = (struct iphdr *)ipv6h;
offset += iph->ihl * 4;
/* special-case 6in4 tunnelling, as that is a common way to get
* v6 connectivity in the home
*/
if (iph->protocol == IPPROTO_IPV6) {
ipv6h = skb_header_pointer(skb, offset,
sizeof(_ipv6h), &_ipv6h);
if (!ipv6h || ipv6h->nexthdr != IPPROTO_TCP)
return 0;
} else if (iph->protocol != IPPROTO_TCP) {
return 0;
}
} else if (ipv6h->version == 6 && ipv6h->nexthdr != IPPROTO_TCP) {
return 0;
}
return ktime_mono_to_any(skb->skb_mstamp_ns, q->tk_offset);
}
/* There are a few scenarios where we will have to modify the txtime from /* There are a few scenarios where we will have to modify the txtime from
* what is read from next_txtime in sched_entry. They are: * what is read from next_txtime in sched_entry. They are:
* 1. If txtime is in the past, * 1. If txtime is in the past,
...@@ -284,7 +320,7 @@ static bool is_valid_interval(struct sk_buff *skb, struct Qdisc *sch) ...@@ -284,7 +320,7 @@ static bool is_valid_interval(struct sk_buff *skb, struct Qdisc *sch)
*/ */
static long get_packet_txtime(struct sk_buff *skb, struct Qdisc *sch) static long get_packet_txtime(struct sk_buff *skb, struct Qdisc *sch)
{ {
ktime_t transmit_end_time, interval_end, interval_start; ktime_t transmit_end_time, interval_end, interval_start, tcp_tstamp;
struct taprio_sched *q = qdisc_priv(sch); struct taprio_sched *q = qdisc_priv(sch);
struct sched_gate_list *sched, *admin; struct sched_gate_list *sched, *admin;
ktime_t minimum_time, now, txtime; ktime_t minimum_time, now, txtime;
...@@ -295,6 +331,9 @@ static long get_packet_txtime(struct sk_buff *skb, struct Qdisc *sch) ...@@ -295,6 +331,9 @@ static long get_packet_txtime(struct sk_buff *skb, struct Qdisc *sch)
now = taprio_get_time(q); now = taprio_get_time(q);
minimum_time = ktime_add_ns(now, q->txtime_delay); minimum_time = ktime_add_ns(now, q->txtime_delay);
tcp_tstamp = get_tcp_tstamp(q, skb);
minimum_time = max_t(ktime_t, minimum_time, tcp_tstamp);
rcu_read_lock(); rcu_read_lock();
admin = rcu_dereference(q->admin_sched); admin = rcu_dereference(q->admin_sched);
sched = rcu_dereference(q->oper_sched); sched = rcu_dereference(q->oper_sched);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment