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

net/sched: taprio: calculate budgets per traffic class

Currently taprio assumes that the budget for a traffic class expires at
the end of the current interval as if the next interval contains a "gate
close" event for this traffic class.

This is, however, an unfounded assumption. Allow schedule entry
intervals to be fused together for a particular traffic class by
calculating the budget until the gate *actually* closes.

This means we need to keep budgets per traffic class, and we also need
to update the budget consumption procedure.
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 e5517551
...@@ -43,6 +43,7 @@ struct sched_entry { ...@@ -43,6 +43,7 @@ struct sched_entry {
* respective traffic class gate closes * respective traffic class gate closes
*/ */
u64 gate_duration[TC_MAX_QUEUE]; u64 gate_duration[TC_MAX_QUEUE];
atomic_t budget[TC_MAX_QUEUE];
struct list_head list; struct list_head list;
/* The instant that this entry ends and the next one /* The instant that this entry ends and the next one
...@@ -51,7 +52,6 @@ struct sched_entry { ...@@ -51,7 +52,6 @@ struct sched_entry {
*/ */
ktime_t end_time; ktime_t end_time;
ktime_t next_txtime; ktime_t next_txtime;
atomic_t budget;
int index; int index;
u32 gate_mask; u32 gate_mask;
u32 interval; u32 interval;
...@@ -563,11 +563,48 @@ static struct sk_buff *taprio_peek(struct Qdisc *sch) ...@@ -563,11 +563,48 @@ static struct sk_buff *taprio_peek(struct Qdisc *sch)
return NULL; return NULL;
} }
static void taprio_set_budget(struct taprio_sched *q, struct sched_entry *entry) static void taprio_set_budgets(struct taprio_sched *q,
struct sched_gate_list *sched,
struct sched_entry *entry)
{
struct net_device *dev = qdisc_dev(q->root);
int num_tc = netdev_get_num_tc(dev);
int tc, budget;
for (tc = 0; tc < num_tc; tc++) {
/* Traffic classes which never close have infinite budget */
if (entry->gate_duration[tc] == sched->cycle_time)
budget = INT_MAX;
else
budget = div64_u64((u64)entry->gate_duration[tc] * PSEC_PER_NSEC,
atomic64_read(&q->picos_per_byte));
atomic_set(&entry->budget[tc], budget);
}
}
/* When an skb is sent, it consumes from the budget of all traffic classes */
static int taprio_update_budgets(struct sched_entry *entry, size_t len,
int tc_consumed, int num_tc)
{ {
atomic_set(&entry->budget, int tc, budget, new_budget = 0;
div64_u64((u64)entry->interval * PSEC_PER_NSEC,
atomic64_read(&q->picos_per_byte))); for (tc = 0; tc < num_tc; tc++) {
budget = atomic_read(&entry->budget[tc]);
/* Don't consume from infinite budget */
if (budget == INT_MAX) {
if (tc == tc_consumed)
new_budget = budget;
continue;
}
if (tc == tc_consumed)
new_budget = atomic_sub_return(len, &entry->budget[tc]);
else
atomic_sub(len, &entry->budget[tc]);
}
return new_budget;
} }
static struct sk_buff *taprio_dequeue_from_txq(struct Qdisc *sch, int txq, static struct sk_buff *taprio_dequeue_from_txq(struct Qdisc *sch, int txq,
...@@ -577,6 +614,7 @@ static struct sk_buff *taprio_dequeue_from_txq(struct Qdisc *sch, int txq, ...@@ -577,6 +614,7 @@ static struct sk_buff *taprio_dequeue_from_txq(struct Qdisc *sch, int txq,
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 Qdisc *child = q->qdiscs[txq]; struct Qdisc *child = q->qdiscs[txq];
int num_tc = netdev_get_num_tc(dev);
struct sk_buff *skb; struct sk_buff *skb;
ktime_t guard; ktime_t guard;
int prio; int prio;
...@@ -611,7 +649,7 @@ static struct sk_buff *taprio_dequeue_from_txq(struct Qdisc *sch, int txq, ...@@ -611,7 +649,7 @@ static struct sk_buff *taprio_dequeue_from_txq(struct Qdisc *sch, int txq,
/* ... and no budget. */ /* ... and no budget. */
if (gate_mask != TAPRIO_ALL_GATES_OPEN && if (gate_mask != TAPRIO_ALL_GATES_OPEN &&
atomic_sub_return(len, &entry->budget) < 0) taprio_update_budgets(entry, len, tc, num_tc) < 0)
return NULL; return NULL;
skip_peek_checks: skip_peek_checks:
...@@ -832,7 +870,7 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer) ...@@ -832,7 +870,7 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer)
} }
next->end_time = end_time; next->end_time = end_time;
taprio_set_budget(q, next); taprio_set_budgets(q, oper, next);
first_run: first_run:
rcu_assign_pointer(q->current_entry, next); rcu_assign_pointer(q->current_entry, next);
...@@ -1091,7 +1129,7 @@ static void setup_first_end_time(struct taprio_sched *q, ...@@ -1091,7 +1129,7 @@ static void setup_first_end_time(struct taprio_sched *q,
sched->cycle_end_time = ktime_add_ns(base, cycle); sched->cycle_end_time = ktime_add_ns(base, cycle);
first->end_time = ktime_add_ns(base, first->interval); first->end_time = ktime_add_ns(base, first->interval);
taprio_set_budget(q, first); taprio_set_budgets(q, sched, first);
rcu_assign_pointer(q->current_entry, NULL); rcu_assign_pointer(q->current_entry, NULL);
} }
......
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