Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp374465ybc; Tue, 12 Nov 2019 02:53:18 -0800 (PST) X-Google-Smtp-Source: APXvYqwm+SzrzdL/VaeJcG8FIMddpgxoUf5dsxoxFk1ZfQGlPpu1bNatQfNiLjrtbAC16Zxf+fKb X-Received: by 2002:a17:906:8697:: with SMTP id g23mr2658809ejx.177.1573555998216; Tue, 12 Nov 2019 02:53:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573555998; cv=none; d=google.com; s=arc-20160816; b=mKGdiVd5UA7F3+GNIuqiGJaUiZ8fArPP+Kj+7Rf+IQqD6TZv0cu6qzM8yi2R6eQ1eq FD+Fs8/Ti5TTWtGga4gR5DWkfFqDyGKVzgcNnKcLpJOjOpi+Dp3MtrtcNaHt+v+Wp6vk gooMDmUxPFkiuSODPUPlJ64e42+jPR8uRouCXrp4upAEt8HRUanERmCcRZwFHk2NVToE 8KeduBLcGLWeM3XAOvqjImDcC3Qy7nETdqTmq6ajbUs9LJksR0NXploClW2+EFnnBEeG pfX21IJ+cYPhGU+gJV2zATvdajdxibHLnMXIwWnjLI6LVECZWfCtFNfCHvFNhyLeVd5T OOkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=fQPGWUIEjEA8RFpXlmD09Q56VRgX4CJvKk1Wqfm2t+Q=; b=HuBP1Z+2De5iDWXug2uuSoihpydj7Q8N/ImkSH55ApbopDR3XMk4BRi/rqTwnyn4Yq +ggilJQV6gZDhsgk/FTJT2SSkipgbH6LIFfnHqr1NpTqrkFIL0CAFzw3yB3n+jtMCNkp /niD5+GQ+7437nrPfpcE40weMLTqkQdScFNUTSFVxpqficG9S8n1GDmFk9UCmnCc5+BL lWsiIQhTFXZZSNVrLB4GL2305Bk4HswIxNxmHcbs5eCKmXsJvggsumhsLoEZzIJqz5Dm Tg1TWyaF8K8AWAnjis3/FJ8XzjT/ZZvZznLT3HzypvvtvbbK3zkKxya21blaFoTFi75x /zYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=azhyGPst; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5si13883242edg.420.2019.11.12.02.52.53; Tue, 12 Nov 2019 02:53:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=azhyGPst; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726946AbfKLKvw (ORCPT + 99 others); Tue, 12 Nov 2019 05:51:52 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:57312 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725919AbfKLKvw (ORCPT ); Tue, 12 Nov 2019 05:51:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=fQPGWUIEjEA8RFpXlmD09Q56VRgX4CJvKk1Wqfm2t+Q=; b=azhyGPstkyQQHDc34tr07wjHs VyIIo3De+Ksh3p9EmrafDDMx3RWFFNEZf1k6KvEaAsdIqdXuX9jMq8sWPcO4azAIiPTu9yRbYoCE3 g57QW00m9dpw3VmbSZHMsvqnOaJUjKQggrwVkCY7kn2cwsjyFBtMLj33DCNfQqYDXFAxguZPJ2owt s2XuHj176nY1CqOcpYUrE7qioIS09ZvqfVkjEtKs64gUnd1W+bY0ZNS5QPG7XVnPkMCDqki/tXDTV roXQMO5LlRBeupxNXhIX5erxgPW511H6G+e74T15DFEs6zVsHrrEzvRGh0PNazhibUHkEXyQztqwl qQ0Ramc2A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iUTlm-0001ph-4Y; Tue, 12 Nov 2019 10:51:34 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id EDACA3056BE; Tue, 12 Nov 2019 11:50:23 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id AD2C729A31BB7; Tue, 12 Nov 2019 11:51:30 +0100 (CET) Date: Tue, 12 Nov 2019 11:51:30 +0100 From: Peter Zijlstra To: Juri Lelli Cc: mingo@redhat.com, glenn@aurora.tech, linux-kernel@vger.kernel.org, rostedt@goodmis.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, tglx@linutronix.de, luca.abeni@santannapisa.it, c.scordino@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com Subject: Re: [PATCH 2/2] sched/deadline: Temporary copy static parameters to boosted non-DEADLINE entities Message-ID: <20191112105130.GZ4131@hirez.programming.kicks-ass.net> References: <20191112075056.19971-1-juri.lelli@redhat.com> <20191112075056.19971-3-juri.lelli@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191112075056.19971-3-juri.lelli@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 12, 2019 at 08:50:56AM +0100, Juri Lelli wrote: > Boosted entities (Priority Inheritance) use static DEADLINE parameters > of the top priority waiter. However, there might be cases where top > waiter could be a non-DEADLINE entity that is currently boosted by a > DEADLINE entity from a different lock chain (i.e., nested priority > chains involving entities of non-DEADLINE classes). In this case, top > waiter static DEADLINE parameters could null (initialized to 0 at > fork()) and replenish_dl_entity() would hit a BUG(). Argh! > Fix this by temporarily copying static DEADLINE parameters of top > DEADLINE waiter (there must be at least one in the chain(s) for the > problem above to happen) into boosted entities. Parameters are reset > during deboost. Also, yuck! > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -4441,19 +4441,21 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task) > if (!dl_prio(p->normal_prio) || > (pi_task && dl_entity_preempt(&pi_task->dl, &p->dl))) { > p->dl.dl_boosted = 1; > + if (!dl_prio(p->normal_prio)) > + __dl_copy_static(p, pi_task); > queue_flag |= ENQUEUE_REPLENISH; > } else > p->dl.dl_boosted = 0; > p->sched_class = &dl_sched_class; So I thought our basic approach was deadline inheritance and screw runtime accounting. Given that, I don't quite understand the REPLENISH hack there. Should we not simply copy dl->deadline around (and restore on unboost)? That is, should we not do something 'simple' like this: diff --git a/include/linux/sched.h b/include/linux/sched.h index 84b26d38c929..1579c571cb83 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -522,6 +522,7 @@ struct sched_dl_entity { */ s64 runtime; /* Remaining runtime for this instance */ u64 deadline; /* Absolute deadline for this instance */ + u64 normal_deadline; unsigned int flags; /* Specifying the scheduler behaviour */ /* diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 26e4ffa01e7a..16164b0ba80b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4452,9 +4452,11 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task) if (!dl_prio(p->normal_prio) || (pi_task && dl_entity_preempt(&pi_task->dl, &p->dl))) { p->dl.dl_boosted = 1; - queue_flag |= ENQUEUE_REPLENISH; - } else + p->dl.deadline = pi_task->dl.deadline; + } else { p->dl.dl_boosted = 0; + p->dl.deadline = p->dl.normal_deadline; + } p->sched_class = &dl_sched_class; } else if (rt_prio(prio)) { if (dl_prio(oldprio)) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 43323f875cb9..0ad7c2797f11 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -674,6 +674,7 @@ static inline void setup_new_dl_entity(struct sched_dl_entity *dl_se) * spent on hardirq context, etc.). */ dl_se->deadline = rq_clock(rq) + dl_se->dl_deadline; + dl_se->normal_deadline = dl_se->deadline; dl_se->runtime = dl_se->dl_runtime; } @@ -709,6 +710,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se, */ if (dl_se->dl_deadline == 0) { dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline; + dl_se->normal_deadline = dl_se->deadline; dl_se->runtime = pi_se->dl_runtime; } @@ -723,6 +725,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se, */ while (dl_se->runtime <= 0) { dl_se->deadline += pi_se->dl_period; + dl_se->normal_deadline = dl_se->normal; dl_se->runtime += pi_se->dl_runtime; } @@ -738,6 +741,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se, if (dl_time_before(dl_se->deadline, rq_clock(rq))) { printk_deferred_once("sched: DL replenish lagged too much\n"); dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline; + dl_se->normal_deadline = dl_se->deadline; dl_se->runtime = pi_se->dl_runtime; } @@ -898,6 +902,7 @@ static void update_dl_entity(struct sched_dl_entity *dl_se, } dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline; + dl_se->normal_deadline = dl_se->deadline; dl_se->runtime = pi_se->dl_runtime; } }