Skip to contentSkip to conversation

Patch "sched/deadline: Make sure the replenishment timer fires in the next period" has been added to the 4.4-stable tree

PATCH [email protected] 1 participant 1 message Dec 18, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

sched/deadline: Make sure the replenishment timer fires in the next period

to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
sched-deadline-make-sure-the-replenishment-timer-fires-in-the-next-period.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From foo@baz Mon Dec 18 14:47:43 CET 2017

From: Daniel Bristot de Oliveira <[email protected]>
Date: Thu, 2 Mar 2017 15:10:57 +0100
Subject: sched/deadline: Make sure the replenishment timer fires in the next period

From: Daniel Bristot de Oliveira <[email protected]>

[ Upstream commit 5ac69d37784b237707a7b15d199cdb6c6fdb6780 ]

Currently, the replenishment timer is set to fire at the deadline of a task. Although that works for implicit deadline tasks because the deadline is equals to the begin of the next period, that is not correct for constrained deadline tasks (deadline < period).

For instance:

f.c:
--------------- %< ---------------
int main (void)

{
	for(;;);
}

--------------- >% ---------------

  # gcc -o f f.c
  # trace-cmd record -e sched:sched_switch                              \
				   -e syscalls:sys_exit_sched_setattr   \
   chrt -d --sched-runtime  490000000					\
           --sched-deadline 500000000					\
	   --sched-period  1000000000 0 ./f
  # trace-cmd report | grep "{pid of ./f}"

After setting parameters, the task is replenished and continue running until being throttled:

         f-11295 [003] 13322.113776: sys_exit_sched_setattr: 0x0

The task is throttled after running 492318 ms, as expected:

         f-11295 [003] 13322.606094: sched_switch:   f:11295 [-1] R ==> watchdog/3:32 [0]

But then, the task is replenished 500719 ms after the first replenishment:

    <idle>-0     [003] 13322.614495: sched_switch:   swapper/3:0 [120] R ==> f:11295 [-1]

Running for 490277 ms:

         f-11295 [003] 13323.104772: sched_switch:   f:11295 [-1] R ==>  swapper/3:0 [120]

Hence, in the first period, the task runs 2 * runtime, and that is a bug.

During the first replenishment, the next deadline is set one period away. So the runtime / period starts to be respected. However, as the second replenishment took place in the wrong instant, the next replenishment will also be held in a wrong instant of time. Rather than occurring in the nth period away from the first activation, it is taking place in the (nth period - relative deadline).

---
 kernel/sched/deadline.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/sched/deadline.c +7 -2
@@ -510,10 +510,15 @@ static void update_dl_entity(struct sche
 	}
 }
 
+static inline u64 dl_next_period(struct sched_dl_entity *dl_se)
+{
+	return dl_se->deadline - dl_se->dl_deadline + dl_se->dl_period;
+}
+
 /*
  * If the entity depleted all its runtime, and if we want it to sleep
  * while waiting for some new execution time to become available, we
- * set the bandwidth enforcement timer to the replenishment instant
+ * set the bandwidth replenishment timer to the replenishment instant
  * and try to activate it.
  *
  * Notice that it is important for the caller to know if the timer
@@ -535,7 +540,7 @@ static int start_dl_timer(struct task_st
 	 * that it is actually coming from rq->clock and not from
 	 * hrtimer's time base reading.
 	 */
-	act = ns_to_ktime(dl_se->deadline);
+	act = ns_to_ktime(dl_next_period(dl_se));
 	now = hrtimer_cb_get_time(timer);
 	delta = ktime_to_ns(now) - rq_clock(rq);
 	act = ktime_add_ns(act, delta);

Patches currently in stable-queue which might be from [email protected] are

queue-4.4/sched-deadline-make-sure-the-replenishment-timer-fires-in-the-next-period.patch queue-4.4/sched-deadline-throttle-a-constrained-deadline-task-activated-after-the-deadline.patch queue-4.4/sched-deadline-use-deadline-instead-of-period-when-calculating-overflow.patch