From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751934AbdBNTeC (ORCPT ); Tue, 14 Feb 2017 14:34:02 -0500 Received: from mail.kernel.org ([198.145.29.136]:55142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751588AbdBNTdy (ORCPT ); Tue, 14 Feb 2017 14:33:54 -0500 Date: Tue, 14 Feb 2017 14:33:43 -0500 From: Steven Rostedt To: Daniel Bristot de Oliveira Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Juri Lelli , Tommaso Cucinotta , Luca Abeni , Mike Galbraith , Romulo Silva de Oliveira Subject: Re: [PATCH V2 2/2] sched/deadline: Throttle a constrained deadline task activated after the deadline Message-ID: <20170214143343.761f6e12@gandalf.local.home> In-Reply-To: <490c988dfa230047b8747ce94abf2db6fa141a43.1487003778.git.bristot@redhat.com> References: <490c988dfa230047b8747ce94abf2db6fa141a43.1487003778.git.bristot@redhat.com> X-Mailer: Claws Mail 3.14.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 13 Feb 2017 20:05:58 +0100 Daniel Bristot de Oliveira wrote: > During the activation, CBS checks if it can reuse the current task's > runtime and period. If the deadline of the task is in the past, CBS > cannot use the runtime, and so it replenishes the task. This rule > works fine for implicit deadline tasks (deadline == period), and the > CBS was designed for implicit deadline tasks. However, a task with > constrained deadline (deadine < period) might be awakened after the > deadline, but before the next period. In this case, replenishing the > task would allow it to run for runtime / deadline. As in this case > deadline < period, CBS enables a task to run for more than the > runtime / period. In a very load system, this can cause the domino > effect, making other tasks to miss their deadlines. > > To avoid this problem, in the activation of a constrained deadline > task after the deadline but before the next period, throttle the > task and set the replenishing timer to the begin of the next period, > unless it is boosted. > > Reproducer: > > --------------- %< --------------- > int main (int argc, char **argv) > { > int ret; > int flags = 0; > unsigned long l = 0; > struct timespec ts; > struct sched_attr attr; > > memset(&attr, 0, sizeof(attr)); > attr.size = sizeof(attr); > > attr.sched_policy = SCHED_DEADLINE; > attr.sched_runtime = 2 * 1000 * 1000; /* 2 ms */ > attr.sched_deadline = 2 * 1000 * 1000; /* 2 ms */ > attr.sched_period = 2 * 1000 * 1000 * 1000; /* 2 s */ > > ts.tv_sec = 0; > ts.tv_nsec = 2000 * 1000; /* 2 ms */ > > ret = sched_setattr(0, &attr, flags); > > if (ret < 0) { > perror("sched_setattr"); > exit(-1); > } > > for(;;) { > /* XXX: you may need to adjust the loop */ > for (l = 0; l < 150000; l++); > /* > * The ideia is to go to sleep right before the deadline > * and then wake up before the next period to receive > * a new replenishment. > */ > nanosleep(&ts, NULL); > } > > exit(0); > } > --------------- >% --------------- > > On my box, this reproducer uses almost 50% of the CPU time, which is > obviously wrong for a task with 2/2000 reservation. > > Signed-off-by: Daniel Bristot de Oliveira > Cc: Ingo Molnar > Cc: Peter Zijlstra > Cc: Juri Lelli > Cc: Tommaso Cucinotta > Cc: Luca Abeni > Cc: Steven Rostedt > Cc: Mike Galbraith > Cc: Romulo Silva de Oliveira > Cc: linux-kernel@vger.kernel.org > Reviewed-by: Steven Rostedt (VMware) -- Steve