• Daniel Bristot de Oliveira's avatar
    sched/deadline: Make sure the replenishment timer fires in the next period · 5ac69d37
    Daniel Bristot de Oliveira authored
    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).
    Signed-off-by: default avatarDaniel Bristot de Oliveira <bristot@redhat.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: default avatarLuca Abeni <luca.abeni@santannapisa.it>
    Reviewed-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
    Reviewed-by: default avatarJuri Lelli <juri.lelli@arm.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Mike Galbraith <efault@gmx.de>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Romulo Silva de Oliveira <romulo.deoliveira@ufsc.br>
    Cc: Steven Rostedt <rostedt@goodmis.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Tommaso Cucinotta <tommaso.cucinotta@sssup.it>
    Link: http://lkml.kernel.org/r/ac50d89887c25285b47465638354b63362f8adff.1488392936.git.bristot@redhat.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    5ac69d37
deadline.c 46.1 KB