mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Muhammad Husaini Zulkifli <muhammad.husaini.zulkifli@intel.com>
To: netdev@vger.kernel.org, vinicius.gomes@intel.com,
	kuba@kernel.org, vladimir.oltean@nxp.com, pabeni@redhat.com
Cc: linux-kernel@vger.kernel.org, tee.min.tan@linux.intel.com,
	muhammad.husaini.zulkifli@intel.com, edumazet@google.com
Subject: [PATCH net v1] net/sched: taprio: fix cycle time extension logic
Date: Tue, 30 May 2023 16:25:41 +0800	[thread overview]
Message-ID: <20230530082541.495-1-muhammad.husaini.zulkifli@intel.com> (raw)

From: Tan Tee Min <tee.min.tan@linux.intel.com>

According to IEEE Std. 802.1Q-2018 section Q.5 CycleTimeExtension,
the Cycle Time Extension variable allows this extension of the last old
cycle to be done in a defined way. If the last complete old cycle would
normally end less than OperCycleTimeExtension nanoseconds before the new
base time, then the last complete cycle before AdminBaseTime is reached
is extended so that it ends at AdminBaseTime.

This patch extends the last entry of last complete cycle to AdminBaseTime.

Fixes: a3d43c0d56f1 ("taprio: Add support adding an admin schedule")
Signed-off-by: Tan Tee Min <tee.min.tan@linux.intel.com>
Signed-off-by: Muhammad Husaini Zulkifli <muhammad.husaini.zulkifli@intel.com>
---
 net/sched/sch_taprio.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index 76db9a10ef504..ef487fef83fce 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -99,6 +99,7 @@ struct taprio_sched {
 	u32 max_sdu[TC_MAX_QUEUE]; /* save info from the user */
 	u32 fp[TC_QOPT_MAX_QUEUE]; /* only for dump and offloading */
 	u32 txtime_delay;
+	bool sched_changed;
 };
 
 struct __tc_taprio_qopt_offload {
@@ -934,8 +935,10 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer)
 	admin = rcu_dereference_protected(q->admin_sched,
 					  lockdep_is_held(&q->current_entry_lock));
 
-	if (!oper)
+	if (!oper || q->sched_changed) {
+		q->sched_changed = false;
 		switch_schedules(q, &admin, &oper);
+	}
 
 	/* This can happen in two cases: 1. this is the very first run
 	 * of this function (i.e. we weren't running any schedule
@@ -962,20 +965,27 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer)
 	end_time = ktime_add_ns(entry->end_time, next->interval);
 	end_time = min_t(ktime_t, end_time, oper->cycle_end_time);
 
+	if (should_change_schedules(admin, oper, oper->cycle_end_time) &&
+	    list_is_last(&next->list, &oper->entries)) {
+		u32 ori_interval = next->interval;
+
+		next->interval += ktime_sub(sched_base_time(admin), end_time);
+		oper->cycle_time += next->interval - ori_interval;
+		end_time = sched_base_time(admin);
+		oper->cycle_end_time = end_time;
+		q->sched_changed = true;
+	}
+
 	for (tc = 0; tc < num_tc; tc++) {
-		if (next->gate_duration[tc] == oper->cycle_time)
+		if (next->gate_duration[tc] == oper->cycle_time) {
 			next->gate_close_time[tc] = KTIME_MAX;
-		else
+		} else if (q->sched_changed && next->gate_duration[tc]) {
+			next->gate_close_time[tc] = end_time;
+			next->gate_duration[tc] = next->interval;
+		} else {
 			next->gate_close_time[tc] = ktime_add_ns(entry->end_time,
 								 next->gate_duration[tc]);
-	}
-
-	if (should_change_schedules(admin, oper, end_time)) {
-		/* Set things so the next time this runs, the new
-		 * schedule runs.
-		 */
-		end_time = sched_base_time(admin);
-		switch_schedules(q, &admin, &oper);
+		}
 	}
 
 	next->end_time = end_time;
-- 
2.17.1


             reply	other threads:[~2023-05-30  8:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  8:25 Muhammad Husaini Zulkifli [this message]
2023-05-30 19:47 ` Vladimir Oltean
2023-06-02  7:14   ` Tan Tee Min
2023-06-02 16:14     ` Vladimir Oltean

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=20230530082541.495-1-muhammad.husaini.zulkifli@intel.com \
    --to=muhammad.husaini.zulkifli@intel.com \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tee.min.tan@linux.intel.com \
    --cc=vinicius.gomes@intel.com \
    --cc=vladimir.oltean@nxp.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

all inboxes | Powered by JetHome®