Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3102864pxk; Mon, 5 Oct 2020 00:45:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrQ+7LJkygLbWJ6M24hqpUGcwW4eJN21bkE1xEjuT6w30jSnuUXMCLCF7yWwlOupn+RzBZ X-Received: by 2002:a50:9b5b:: with SMTP id a27mr1674708edj.374.1601883918233; Mon, 05 Oct 2020 00:45:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601883918; cv=none; d=google.com; s=arc-20160816; b=FHM4CxFST/6Fl/iP8PCLgdqJdz1oQ41hS9tA+gv6QyTRrcbY4QMsedwxeW/KMSrKKh xrhWadQzkoYWuVLCUfJ7AGAIvgmZVqadLd3wZqyibcHn2hS7Yi7TqQZja+4qMDD3qFHo 4Kl5XhqTFudzpAXvki2Dl4cyh81d7vUz9YbR8zQqrC5SThNwnF/g+gF2QfYEuZB83GLf oYLvV5MK09hMcNM4Mn22mNa41KkLXQm5i0bhgl67yhghf1l60rNnBaH8e7RI10OP4IqW CMWVrUTZ5DIFzqN/9E9Io5i+PeuqpOiieTGVnaOJkkN+e0oMPTCBK2yx441qd7nXZmSr /K3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=PEOK3zx6IGWDIGrzIT5RTnI63Z2+ZiiIjamj6N4ValA=; b=TvqZ5HQpdAwJNTir8PnxxjZ6sLRPjHBnDfAk8fIFvt34hufDtlxufWCVFn2Lkg4oro xkqYgfZlRXPr5ZuEZTDmrgS4l4gGx/CnMLvRAtUnoU1QUKgV1dG/9jOPvvfeTwm7pxSW g0C3sSZ4lV0obJD+JTtSBvTFIjRrxj7XSa8NX8d6IJKE/mkMWCc/H/N0Z0i2siIM2bi1 pdPQtfmynU5IUpodm788uchj7lHtZb+/9+UJUaPYebzuvMCvJ+oBrygI0p7dikoO6z0/ ULFRnHY4F81SLr3mKZh3xYvn3HZyBrVfxjJlEnhIj5lIDAwEJTiYvFa9pqmhIqCdbnBc 4IpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jkmAKP0F; dkim=neutral (no key) header.i=@linutronix.de header.b=e88ataEi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 20si80796ejw.320.2020.10.05.00.44.56; Mon, 05 Oct 2020 00:45:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jkmAKP0F; dkim=neutral (no key) header.i=@linutronix.de header.b=e88ataEi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725934AbgJEHnY (ORCPT + 99 others); Mon, 5 Oct 2020 03:43:24 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:56698 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725870AbgJEHnY (ORCPT ); Mon, 5 Oct 2020 03:43:24 -0400 Date: Mon, 05 Oct 2020 07:43:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1601883801; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PEOK3zx6IGWDIGrzIT5RTnI63Z2+ZiiIjamj6N4ValA=; b=jkmAKP0FBsOMSaIQ2lE4FNeMgRtxAMwzpGs0zuwAmTrDM1ea4lHMWzwWon2LMMViPk5Lzm gD90FdRrLihuPQykrbZmaE7WBQrKX1GK7S/iymSOxohypcAuNHLX9r5RSQP32V03E/VHGA 3BQ5ISVRtNZTo3kiz27pzMsbuBEme5XhSOG5LN7wmlXxXCOt8Aw+yxO5Pi4dW+k5C1746E 6woi2FUZu8L+cGt1WsjIiy7oFY7LzBGbLxcclPwUPnVDA84gdHuWvTR5otNIMFFGy3sMWx 2YMAkiRMVj3PSz+c14eQM/OKAbUzy7SQM6kTKxCz+YG4SZzxHQ84FqPJJic6qw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1601883801; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PEOK3zx6IGWDIGrzIT5RTnI63Z2+ZiiIjamj6N4ValA=; b=e88ataEi8RAWA8kdQd7181OWfED6rJr6NsQ4B+dTrpOYDWmE66GtKaaYviVH2+giWJsOs5 t7X7rdYUMoc8FwAw== From: "tip-bot2 for Daniel Bristot de Oliveira" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/deadline: Unthrottle PI boosted threads while enqueuing Cc: Mark Simmons , Daniel Bristot de Oliveira , "Peter Zijlstra (Intel)" , Juri Lelli , x86 , LKML In-Reply-To: <5076e003450835ec74e6fa5917d02c4fa41687e6.1600170294.git.bristot@redhat.com> References: <5076e003450835ec74e6fa5917d02c4fa41687e6.1600170294.git.bristot@redhat.com> MIME-Version: 1.0 Message-ID: <160188380002.7002.3321703660112197188.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: feff2e65efd8d84cf831668e182b2ce73c604bbb Gitweb: https://git.kernel.org/tip/feff2e65efd8d84cf831668e182b2ce73c604bbb Author: Daniel Bristot de Oliveira AuthorDate: Wed, 16 Sep 2020 09:06:39 +02:00 Committer: Peter Zijlstra CommitterDate: Sat, 03 Oct 2020 16:30:53 +02:00 sched/deadline: Unthrottle PI boosted threads while enqueuing stress-ng has a test (stress-ng --cyclic) that creates a set of threads under SCHED_DEADLINE with the following parameters: dl_runtime = 10000 (10 us) dl_deadline = 100000 (100 us) dl_period = 100000 (100 us) These parameters are very aggressive. When using a system without HRTICK set, these threads can easily execute longer than the dl_runtime because the throttling happens with 1/HZ resolution. During the main part of the test, the system works just fine because the workload does not try to run over the 10 us. The problem happens at the end of the test, on the exit() path. During exit(), the threads need to do some cleanups that require real-time mutex locks, mainly those related to memory management, resulting in this scenario: Note: locks are rt_mutexes... ------------------------------------------------------------------------ TASK A: TASK B: TASK C: activation activation activation lock(a): OK! lock(b): OK! lock(a) -> block (task A owns it) -> self notice/set throttled +--< -> arm replenished timer | switch-out | lock(b) | -> B prio> | -> boost TASK B | unlock(a) switch-out | -> handle lock a to B | -> wakeup(B) | -> B is throttled: | -> do not enqueue | switch-out | | +---------------------> replenishment timer -> TASK B is boosted: -> do not enqueue ------------------------------------------------------------------------ BOOM: TASK B is runnable but !enqueued, holding TASK C: the system crashes with hung task C. This problem is avoided by removing the throttle state from the boosted thread while boosting it (by TASK A in the example above), allowing it to be queued and run boosted. The next replenishment will take care of the runtime overrun, pushing the deadline further away. See the "while (dl_se->runtime <= 0)" on replenish_dl_entity() for more information. Reported-by: Mark Simmons Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Juri Lelli Tested-by: Mark Simmons Link: https://lkml.kernel.org/r/5076e003450835ec74e6fa5917d02c4fa41687e6.1600170294.git.bristot@redhat.com --- kernel/sched/deadline.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index c19c188..6d93f45 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1525,6 +1525,27 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags) */ if (pi_task && dl_prio(pi_task->normal_prio) && p->dl.dl_boosted) { pi_se = &pi_task->dl; + /* + * Because of delays in the detection of the overrun of a + * thread's runtime, it might be the case that a thread + * goes to sleep in a rt mutex with negative runtime. As + * a consequence, the thread will be throttled. + * + * While waiting for the mutex, this thread can also be + * boosted via PI, resulting in a thread that is throttled + * and boosted at the same time. + * + * In this case, the boost overrides the throttle. + */ + if (p->dl.dl_throttled) { + /* + * The replenish timer needs to be canceled. No + * problem if it fires concurrently: boosted threads + * are ignored in dl_task_timer(). + */ + hrtimer_try_to_cancel(&p->dl.dl_timer); + p->dl.dl_throttled = 0; + } } else if (!dl_prio(p->normal_prio)) { /* * Special case in which we have a !SCHED_DEADLINE task that is going