netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v1] net/sched: taprio: fix cycle time extension logic
@ 2023-05-30  8:25 Muhammad Husaini Zulkifli
  2023-05-30 19:47 ` Vladimir Oltean
  0 siblings, 1 reply; 4+ messages in thread
From: Muhammad Husaini Zulkifli @ 2023-05-30  8:25 UTC (permalink / raw)
  To: netdev, vinicius.gomes, kuba, vladimir.oltean, pabeni
  Cc: linux-kernel, tee.min.tan, muhammad.husaini.zulkifli, edumazet

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-02 16:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-30  8:25 [PATCH net v1] net/sched: taprio: fix cycle time extension logic Muhammad Husaini Zulkifli
2023-05-30 19:47 ` Vladimir Oltean
2023-06-02  7:14   ` Tan Tee Min
2023-06-02 16:14     ` Vladimir Oltean

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).