From: Andre Guedes <andre.guedes@intel.com>
To: netdev@vger.kernel.org
Cc: vinicius.gomes@intel.com
Subject: [PATCH 2/5] net: sched: taprio: Refactor taprio_get_start_time()
Date: Fri, 19 Apr 2019 17:00:49 -0700 [thread overview]
Message-ID: <20190420000052.4242-3-andre.guedes@intel.com> (raw)
In-Reply-To: <20190420000052.4242-1-andre.guedes@intel.com>
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: Andre Guedes <andre.guedes@intel.com>
---
net/sched/sch_taprio.c | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index 3214a65775f3..f7139e6179b6 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -532,7 +532,7 @@ static int taprio_parse_mqprio_opt(struct net_device *dev,
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 sched_entry *entry;
@@ -540,27 +540,33 @@ static ktime_t taprio_get_start_time(struct Qdisc *sch)
s64 n;
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.
*/
+ cycle = 0;
list_for_each_entry(entry, &q->entries, list)
cycle = ktime_add_ns(cycle, entry->interval);
- if (!cycle)
- return base;
-
- now = q->get_time();
-
- if (ktime_after(base, now))
- return base;
+ /* The qdisc is expected to have at least one sched_entry. Moreover,
+ * 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
+ * inconsistent state and return error.
+ */
+ if (WARN_ON(!cycle))
+ return -EFAULT;
/* Schedule the start time for the beginning of the next
* cycle.
*/
n = div64_s64(ktime_sub_ns(now, base), cycle);
-
- return ktime_add_ns(base, (n + 1) * cycle);
+ *start = ktime_add_ns(base, (n + 1) * cycle);
+ return 0;
}
static void taprio_start_sched(struct Qdisc *sch, ktime_t start)
@@ -711,9 +717,12 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,
}
taprio_set_picos_per_byte(dev, q);
- start = taprio_get_start_time(sch);
- if (!start)
- return 0;
+
+ err = taprio_get_start_time(sch, &start);
+ if (err < 0) {
+ NL_SET_ERR_MSG(extack, "Internal error: failed get start time");
+ return err;
+ }
taprio_start_sched(sch, start);
--
2.21.0
next prev parent reply other threads:[~2019-04-20 1:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-20 0:00 [PATCH 0/5] Taprio qdisc fixes Andre Guedes
2019-04-20 0:00 ` [PATCH 1/5] net: sched: taprio: Remove pointless variable assigment Andre Guedes
2019-04-20 0:00 ` Andre Guedes [this message]
2019-04-20 0:00 ` [PATCH 3/5] net: sched: taprio: Fix null pointer deref bug Andre Guedes
2019-04-22 18:04 ` Cong Wang
2019-04-22 18:07 ` Cong Wang
2019-04-22 19:21 ` Guedes, Andre
2019-04-22 19:36 ` Cong Wang
2019-04-23 19:21 ` Guedes, Andre
2019-04-23 19:24 ` Cong Wang
2019-04-20 0:00 ` [PATCH 4/5] net: sched: taprio: Fix taprio_peek() Andre Guedes
2019-04-20 0:00 ` [PATCH 5/5] net: sched: taprio: Fix taprio_dequeue() Andre Guedes
2019-04-21 3:46 ` [PATCH 0/5] Taprio qdisc fixes David Miller
2019-04-22 19:18 ` Guedes, Andre
2019-04-23 4:21 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190420000052.4242-3-andre.guedes@intel.com \
--to=andre.guedes@intel.com \
--cc=netdev@vger.kernel.org \
--cc=vinicius.gomes@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).