public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Faizal Rahim <faizal.abdul.rahim@linux.intel.com>
To: Vladimir Oltean <vladimir.oltean@nxp.com>,
	Vinicius Costa Gomes <vinicius.gomes@intel.com>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Jiri Pirko <jiri@resnulli.us>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 net 3/7] net/sched: taprio: update impacted fields during cycle time adjustment
Date: Tue,  7 Nov 2023 06:20:19 -0500	[thread overview]
Message-ID: <20231107112023.676016-4-faizal.abdul.rahim@linux.intel.com> (raw)
In-Reply-To: <20231107112023.676016-1-faizal.abdul.rahim@linux.intel.com>

Update impacted fields in advance_sched() if cycle_corr_active()
is true, which indicates that the next entry is the last entry
from oper that it will run.

Update impacted fields:

1. gate_duration[tc], max_open_gate_duration[tc]
Created a new API update_open_gate_duration().The API sets the
duration based on the last remaining entry, the original value
was based on consideration of multiple entries.

2. gate_close_time[tc]
Update next entry gate close time according to the new admin
base time

3. max_sdu[tc], budget[tc]
Restrict from setting to max value because there's only a single
entry left to run from oper before changing to the new admin
schedule, so we shouldn't set to max.

Signed-off-by: Faizal Rahim <faizal.abdul.rahim@linux.intel.com>
---
 net/sched/sch_taprio.c | 49 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 3 deletions(-)

diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index ed32654b46f5..119dec3bbe88 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -288,7 +288,8 @@ static void taprio_update_queue_max_sdu(struct taprio_sched *q,
 		/* TC gate never closes => keep the queueMaxSDU
 		 * selected by the user
 		 */
-		if (sched->max_open_gate_duration[tc] == sched->cycle_time) {
+		if (sched->max_open_gate_duration[tc] == sched->cycle_time &&
+		    !cycle_corr_active(sched->cycle_time_correction)) {
 			max_sdu_dynamic = U32_MAX;
 		} else {
 			u32 max_frm_len;
@@ -684,7 +685,8 @@ static void taprio_set_budgets(struct taprio_sched *q,
 
 	for (tc = 0; tc < num_tc; tc++) {
 		/* Traffic classes which never close have infinite budget */
-		if (entry->gate_duration[tc] == sched->cycle_time)
+		if (entry->gate_duration[tc] == sched->cycle_time &&
+		    !cycle_corr_active(sched->cycle_time_correction))
 			budget = INT_MAX;
 		else
 			budget = div64_u64((u64)entry->gate_duration[tc] * PSEC_PER_NSEC,
@@ -896,6 +898,32 @@ static bool should_restart_cycle(const struct sched_gate_list *oper,
 	return false;
 }
 
+/* Open gate duration were calculated at the beginning with consideration of
+ * multiple entries. If cycle time correction is active, there's only a single
+ * remaining entry left from oper to run.
+ * Update open gate duration based on this last entry.
+ */
+static void update_open_gate_duration(struct sched_entry *entry,
+				      struct sched_gate_list *oper,
+				      int num_tc,
+				      u64 open_gate_duration)
+{
+	int tc;
+
+	if (!entry || !oper)
+		return;
+
+	for (tc = 0; tc < num_tc; tc++) {
+		if (entry->gate_mask & BIT(tc)) {
+			entry->gate_duration[tc] = open_gate_duration;
+			oper->max_open_gate_duration[tc] = open_gate_duration;
+		} else {
+			entry->gate_duration[tc] = 0;
+			oper->max_open_gate_duration[tc] = 0;
+		}
+	}
+}
+
 static bool should_change_sched(struct sched_gate_list *oper)
 {
 	bool change_to_admin_sched = false;
@@ -1010,13 +1038,28 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer)
 			/* The next entry is the last entry we will run from
 			 * oper, subsequent ones will take from the new admin
 			 */
+			u64 new_gate_duration =
+				next->interval + oper->cycle_time_correction;
+			struct qdisc_size_table *stab =
+				rtnl_dereference(q->root->stab);
+
 			oper->cycle_end_time = new_base_time;
 			end_time = new_base_time;
+
+			update_open_gate_duration(next, oper, num_tc,
+						  new_gate_duration);
+			taprio_update_queue_max_sdu(q, oper, stab);
 		}
 	}
 
 	for (tc = 0; tc < num_tc; tc++) {
-		if (next->gate_duration[tc] == oper->cycle_time)
+		if (cycle_corr_active(oper->cycle_time_correction) &&
+		    (next->gate_mask & BIT(tc)))
+			/* Set to the new base time, ensuring a smooth transition
+			 * to the new schedule when the next entry finishes.
+			 */
+			next->gate_close_time[tc] = end_time;
+		else if (next->gate_duration[tc] == oper->cycle_time)
 			next->gate_close_time[tc] = KTIME_MAX;
 		else
 			next->gate_close_time[tc] = ktime_add_ns(entry->end_time,
-- 
2.25.1


  parent reply	other threads:[~2023-11-07 11:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 11:20 [PATCH v2 net 0/7] qbv cycle time extension/truncation Faizal Rahim
2023-11-07 11:20 ` [PATCH v2 net 1/7] net/sched: taprio: fix too early schedules switching Faizal Rahim
2023-11-08 22:27   ` Vladimir Oltean
2023-11-15 11:54     ` Abdul Rahim, Faizal
2023-11-12 10:31   ` Simon Horman
2023-11-16  5:59     ` Abdul Rahim, Faizal
2023-11-07 11:20 ` [PATCH v2 net 2/7] net/sched: taprio: fix cycle time adjustment for next entry Faizal Rahim
2023-11-08 23:20   ` Vladimir Oltean
2023-11-15 11:55     ` Abdul Rahim, Faizal
2023-11-07 11:20 ` Faizal Rahim [this message]
2023-11-08 23:41   ` [PATCH v2 net 3/7] net/sched: taprio: update impacted fields during cycle time adjustment Vladimir Oltean
2023-11-15 11:55     ` Abdul Rahim, Faizal
2023-11-07 11:20 ` [PATCH v2 net 4/7] net/sched: taprio: get corrected value of cycle_time and interval Faizal Rahim
2023-11-07 22:45   ` kernel test robot
2023-11-09 11:11   ` Vladimir Oltean
2023-11-15 11:55     ` Abdul Rahim, Faizal
2023-11-17  2:36     ` Vinicius Costa Gomes
2023-11-09 12:01   ` Vladimir Oltean
2023-11-10 19:15   ` kernel test robot
2023-11-07 11:20 ` [PATCH v2 net 5/7] net/sched: taprio: fix delayed switching to new schedule after timer expiry Faizal Rahim
2023-11-09 11:50   ` Vladimir Oltean
2023-11-15 11:56     ` Abdul Rahim, Faizal
2023-11-09 12:24   ` Vladimir Oltean
2023-11-07 11:20 ` [PATCH v2 net 6/7] net/sched: taprio: fix q->current_entry is NULL before its expiry Faizal Rahim
2023-11-09 11:55   ` Vladimir Oltean
2023-11-15 11:56     ` Abdul Rahim, Faizal
2023-11-07 11:20 ` [PATCH v2 net 7/7] net/sched: taprio: enable cycle time adjustment for current entry Faizal Rahim
2023-11-09 13:18   ` Vladimir Oltean
2023-11-15 11:57     ` Abdul Rahim, Faizal
2023-11-08 15:51 ` [PATCH v2 net 0/7] qbv cycle time extension/truncation Vladimir Oltean
2023-11-10 11:06   ` Abdul Rahim, Faizal

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=20231107112023.676016-4-faizal.abdul.rahim@linux.intel.com \
    --to=faizal.abdul.rahim@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vinicius.gomes@intel.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=xiyou.wangcong@gmail.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