Commit a878fd46 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net/sched: keep the max_frm_len information inside struct sched_gate_list

I have one practical reason for doing this and one concerning correctness.

The practical reason has to do with a follow-up patch, which aims to mix
2 sources of max_sdu (one coming from the user and the other automatically
calculated based on TC gate durations @current link speed). Among those
2 sources of input, we must always select the smaller max_sdu value, but
this can change at various link speeds. So the max_sdu coming from the
user must be kept separated from the value that is operationally used
(the minimum of the 2), because otherwise we overwrite it and forget
what the user asked us to do.

To solve that, this patch proposes that struct sched_gate_list contains
the operationally active max_frm_len, and q->max_sdu contains just what
was requested by the user.

The reason having to do with correctness is based on the following
observation: the admin sched_gate_list becomes operational at a given
base_time in the future. Until then, it is inactive and applies no
shaping, all gates are open, etc. So the queueMaxSDU dropping shouldn't
apply either (this is a mechanism to ensure that packets smaller than
the largest gate duration for that TC don't hang the port; clearly it
makes little sense if the gates are always open).
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Kurt Kanzenbach's avatarKurt Kanzenbach <kurt@linutronix.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a3d91b2c
...@@ -63,6 +63,7 @@ struct sched_gate_list { ...@@ -63,6 +63,7 @@ struct sched_gate_list {
* or 0 if a traffic class gate never opens during the schedule. * or 0 if a traffic class gate never opens during the schedule.
*/ */
u64 max_open_gate_duration[TC_MAX_QUEUE]; u64 max_open_gate_duration[TC_MAX_QUEUE];
u32 max_frm_len[TC_MAX_QUEUE]; /* for the fast path */
struct rcu_head rcu; struct rcu_head rcu;
struct list_head entries; struct list_head entries;
size_t num_entries; size_t num_entries;
...@@ -93,7 +94,6 @@ struct taprio_sched { ...@@ -93,7 +94,6 @@ struct taprio_sched {
struct hrtimer advance_timer; struct hrtimer advance_timer;
struct list_head taprio_list; struct list_head taprio_list;
int cur_txq[TC_MAX_QUEUE]; int cur_txq[TC_MAX_QUEUE];
u32 max_frm_len[TC_MAX_QUEUE]; /* for the fast path */
u32 max_sdu[TC_MAX_QUEUE]; /* for dump and offloading */ u32 max_sdu[TC_MAX_QUEUE]; /* for dump and offloading */
u32 txtime_delay; u32 txtime_delay;
}; };
...@@ -246,6 +246,21 @@ static int length_to_duration(struct taprio_sched *q, int len) ...@@ -246,6 +246,21 @@ static int length_to_duration(struct taprio_sched *q, int len)
return div_u64(len * atomic64_read(&q->picos_per_byte), PSEC_PER_NSEC); return div_u64(len * atomic64_read(&q->picos_per_byte), PSEC_PER_NSEC);
} }
static void taprio_update_queue_max_sdu(struct taprio_sched *q,
struct sched_gate_list *sched)
{
struct net_device *dev = qdisc_dev(q->root);
int num_tc = netdev_get_num_tc(dev);
int tc;
for (tc = 0; tc < num_tc; tc++) {
if (q->max_sdu[tc])
sched->max_frm_len[tc] = q->max_sdu[tc] + dev->hard_header_len;
else
sched->max_frm_len[tc] = U32_MAX; /* never oversized */
}
}
/* Returns the entry corresponding to next available interval. If /* Returns the entry corresponding to next available interval. If
* validate_interval is set, it only validates whether the timestamp occurs * validate_interval is set, it only validates whether the timestamp occurs
* when the gate corresponding to the skb's traffic class is open. * when the gate corresponding to the skb's traffic class is open.
...@@ -479,14 +494,33 @@ static long get_packet_txtime(struct sk_buff *skb, struct Qdisc *sch) ...@@ -479,14 +494,33 @@ static long get_packet_txtime(struct sk_buff *skb, struct Qdisc *sch)
return txtime; return txtime;
} }
static int taprio_enqueue_one(struct sk_buff *skb, struct Qdisc *sch, /* Devices with full offload are expected to honor this in hardware */
struct Qdisc *child, struct sk_buff **to_free) static bool taprio_skb_exceeds_queue_max_sdu(struct Qdisc *sch,
struct sk_buff *skb)
{ {
struct taprio_sched *q = qdisc_priv(sch); struct taprio_sched *q = qdisc_priv(sch);
struct net_device *dev = qdisc_dev(sch); struct net_device *dev = qdisc_dev(sch);
struct sched_gate_list *sched;
int prio = skb->priority; int prio = skb->priority;
bool exceeds = false;
u8 tc; u8 tc;
tc = netdev_get_prio_tc_map(dev, prio);
rcu_read_lock();
sched = rcu_dereference(q->oper_sched);
if (sched && skb->len > sched->max_frm_len[tc])
exceeds = true;
rcu_read_unlock();
return exceeds;
}
static int taprio_enqueue_one(struct sk_buff *skb, struct Qdisc *sch,
struct Qdisc *child, struct sk_buff **to_free)
{
struct taprio_sched *q = qdisc_priv(sch);
/* sk_flags are only safe to use on full sockets. */ /* sk_flags are only safe to use on full sockets. */
if (skb->sk && sk_fullsock(skb->sk) && sock_flag(skb->sk, SOCK_TXTIME)) { if (skb->sk && sk_fullsock(skb->sk) && sock_flag(skb->sk, SOCK_TXTIME)) {
if (!is_valid_interval(skb, sch)) if (!is_valid_interval(skb, sch))
...@@ -497,9 +531,7 @@ static int taprio_enqueue_one(struct sk_buff *skb, struct Qdisc *sch, ...@@ -497,9 +531,7 @@ static int taprio_enqueue_one(struct sk_buff *skb, struct Qdisc *sch,
return qdisc_drop(skb, sch, to_free); return qdisc_drop(skb, sch, to_free);
} }
/* Devices with full offload are expected to honor this in hardware */ if (taprio_skb_exceeds_queue_max_sdu(sch, skb))
tc = netdev_get_prio_tc_map(dev, prio);
if (skb->len > q->max_frm_len[tc])
return qdisc_drop(skb, sch, to_free); return qdisc_drop(skb, sch, to_free);
qdisc_qstats_backlog_inc(sch, skb); qdisc_qstats_backlog_inc(sch, skb);
...@@ -1609,7 +1641,6 @@ static int taprio_parse_tc_entries(struct Qdisc *sch, ...@@ -1609,7 +1641,6 @@ static int taprio_parse_tc_entries(struct Qdisc *sch,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct taprio_sched *q = qdisc_priv(sch); struct taprio_sched *q = qdisc_priv(sch);
struct net_device *dev = qdisc_dev(sch);
u32 max_sdu[TC_QOPT_MAX_QUEUE]; u32 max_sdu[TC_QOPT_MAX_QUEUE];
unsigned long seen_tcs = 0; unsigned long seen_tcs = 0;
struct nlattr *n; struct nlattr *n;
...@@ -1628,13 +1659,8 @@ static int taprio_parse_tc_entries(struct Qdisc *sch, ...@@ -1628,13 +1659,8 @@ static int taprio_parse_tc_entries(struct Qdisc *sch,
goto out; goto out;
} }
for (tc = 0; tc < TC_QOPT_MAX_QUEUE; tc++) { for (tc = 0; tc < TC_QOPT_MAX_QUEUE; tc++)
q->max_sdu[tc] = max_sdu[tc]; q->max_sdu[tc] = max_sdu[tc];
if (max_sdu[tc])
q->max_frm_len[tc] = max_sdu[tc] + dev->hard_header_len;
else
q->max_frm_len[tc] = U32_MAX; /* never oversized */
}
out: out:
return err; return err;
...@@ -1758,6 +1784,7 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt, ...@@ -1758,6 +1784,7 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,
goto free_sched; goto free_sched;
taprio_set_picos_per_byte(dev, q); taprio_set_picos_per_byte(dev, q);
taprio_update_queue_max_sdu(q, new_admin);
if (mqprio) { if (mqprio) {
err = netdev_set_num_tc(dev, mqprio->num_tc); err = netdev_set_num_tc(dev, mqprio->num_tc);
......
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