Commit 8599099f authored by Andre Guedes's avatar Andre Guedes Committed by David S. Miller

net: sched: taprio: Refactor taprio_get_start_time()

This patch does a code refactoring to taprio_get_start_time() function
to improve readability and report error properly.

If 'base' time is later than 'now', the start time is equal to 'base'
and taprio_get_start_time() is done. That's the natural case so we move
that code to the beginning of the function. Also, if 'cycle' calculation
is zero, something went really wrong with taprio and we should log that
internal error properly.
Signed-off-by: default avatarAndre Guedes <andre.guedes@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 59ab87f6
...@@ -539,7 +539,7 @@ static int taprio_parse_mqprio_opt(struct net_device *dev, ...@@ -539,7 +539,7 @@ static int taprio_parse_mqprio_opt(struct net_device *dev,
return 0; return 0;
} }
static ktime_t taprio_get_start_time(struct Qdisc *sch) static int taprio_get_start_time(struct Qdisc *sch, ktime_t *start)
{ {
struct taprio_sched *q = qdisc_priv(sch); struct taprio_sched *q = qdisc_priv(sch);
struct sched_entry *entry; struct sched_entry *entry;
...@@ -547,27 +547,33 @@ static ktime_t taprio_get_start_time(struct Qdisc *sch) ...@@ -547,27 +547,33 @@ static ktime_t taprio_get_start_time(struct Qdisc *sch)
s64 n; s64 n;
base = ns_to_ktime(q->base_time); base = ns_to_ktime(q->base_time);
cycle = 0; now = q->get_time();
if (ktime_after(base, now)) {
*start = base;
return 0;
}
/* Calculate the cycle_time, by summing all the intervals. /* Calculate the cycle_time, by summing all the intervals.
*/ */
cycle = 0;
list_for_each_entry(entry, &q->entries, list) list_for_each_entry(entry, &q->entries, list)
cycle = ktime_add_ns(cycle, entry->interval); cycle = ktime_add_ns(cycle, entry->interval);
if (!cycle) /* The qdisc is expected to have at least one sched_entry. Moreover,
return base; * any entry must have 'interval' > 0. Thus if the cycle time is zero,
* something went really wrong. In that case, we should warn about this
now = q->get_time(); * inconsistent state and return error.
*/
if (ktime_after(base, now)) if (WARN_ON(!cycle))
return base; return -EFAULT;
/* Schedule the start time for the beginning of the next /* Schedule the start time for the beginning of the next
* cycle. * cycle.
*/ */
n = div64_s64(ktime_sub_ns(now, base), cycle); n = div64_s64(ktime_sub_ns(now, base), cycle);
*start = ktime_add_ns(base, (n + 1) * cycle);
return ktime_add_ns(base, (n + 1) * cycle); return 0;
} }
static void taprio_start_sched(struct Qdisc *sch, ktime_t start) static void taprio_start_sched(struct Qdisc *sch, ktime_t start)
...@@ -716,9 +722,12 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt, ...@@ -716,9 +722,12 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,
} }
taprio_set_picos_per_byte(dev, q); taprio_set_picos_per_byte(dev, q);
start = taprio_get_start_time(sch);
if (!start) err = taprio_get_start_time(sch, &start);
return 0; if (err < 0) {
NL_SET_ERR_MSG(extack, "Internal error: failed get start time");
return err;
}
taprio_start_sched(sch, start); taprio_start_sched(sch, start);
......
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