Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp737027img; Fri, 22 Mar 2019 07:33:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOK+MABrb85e5srvbqaPwg9p9ZGY3PE3c8LfwhyxdJZoUASDIh1zSNmxSdKHqY7EudA0qK X-Received: by 2002:a63:481:: with SMTP id 123mr9386053pge.167.1553265211368; Fri, 22 Mar 2019 07:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553265211; cv=none; d=google.com; s=arc-20160816; b=pS1pRYM1+ICwoyrlYm8nvc6tw8yuZ/tKGz2YRVMxH3zDqoGr1nTSYf6HI50qnShpHX qkHN7Y6JsoZhDoDrdK3Q7LPchZP+E4R1eguGUZEZSunEQtuVGzhbKyGTvXpkhjcbeU+2 NLILmjpCq+B1Q/VKq3rbhL4ArlK2dsBE1dhFjWNeqvVwVTAyLytbrRsVbl5JgtH0Y0Bn ZOZQOFV8R1KuIbplrbSRdOj7nxXeDsuJF0xIdSkueSH/XGgY7eGrphAY6hpQetvfefRQ OfM6rNIDVSWBn+csjwpsUlTXzxpw0OF0Jzsp8e5P8ay5lQ/wtTTDvq+gL5BBc0cv7Kcf pftw== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=TiXP7H9vYn4usOzHAK8b18260nNkrHJ6IayMSlpmKL0=; b=i8UcBUxWucW6/Ath2yOWzpuWB6LgqHdXwILm8QDG6Ds3/qVPSZWtwzr8633qxwafh9 +XvGRBtN0QAl7THDH3pj/C94kHcz547e0zfo2YBJUIFljhQlTRXeEFRii/96ssV6mD/A f/EnCyN5XIImmIGJ151/qDOKG4CHT4VOpwnzzDBaqJIcomqt9jsltS7+61GsrOo0ldrq SKyerHTIATGlUVRLie4A+84R9faJMLBNc9+apE726bH8v31DDaDcrcqV6LBKhJE2RsAm DOv/Mbj+Q3aICfnqj3wYo4qYaB9Vfit0uiLqFZ/2uABg2sFEJTT7HlL1JpwBFQo2IFPm kJYQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c186si6904858pfg.160.2019.03.22.07.33.16; Fri, 22 Mar 2019 07:33:31 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728963AbfCVOci (ORCPT + 99 others); Fri, 22 Mar 2019 10:32:38 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33076 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727964AbfCVOch (ORCPT ); Fri, 22 Mar 2019 10:32:37 -0400 Received: by mail-wr1-f68.google.com with SMTP id q1so2635452wrp.0 for ; Fri, 22 Mar 2019 07:32:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=TiXP7H9vYn4usOzHAK8b18260nNkrHJ6IayMSlpmKL0=; b=AdYVUXEechBawVYdrSJTxpyVuY745ZrpUDucDWOo9RXfyc0m4eda6sW40KfwmPlqvW HCdnD523zhTlccqTnfRqnakm/kp+lNTuz0n7zvqNkjYiuITcEyaxfM3Lk/4WO9cMfuVj HrI4z1Stk/BmTJ2oWKNfeqWiIgbVEcx/3NTFJ5My8L5/OKeOeiB0QgEJ937Oqm0K7ZIy k+pnp8+rckfd4ukItwJ/syufYckFGZwJgv91mL5cYkM9KUOVciolt2AoJ5+fy9OwSWEu sQ46kAN8S2n/vwRF/IjsZF0xUweq/WRMpsdyMeesTse22ir/+TiUzrIS68iIMBgQ6XlZ Rm9w== X-Gm-Message-State: APjAAAWYoNJMSPc494+EYR/TOohxpL9REwIufGHSd7DuMZU9RPzHmqN+ UsMAxCDcj8iYPtkANu+RZpeIiQ== X-Received: by 2002:adf:ec11:: with SMTP id x17mr6510350wrn.120.1553265155420; Fri, 22 Mar 2019 07:32:35 -0700 (PDT) Received: from localhost.localdomain ([151.15.240.16]) by smtp.gmail.com with ESMTPSA id d16sm7204019wru.49.2019.03.22.07.32.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Mar 2019 07:32:34 -0700 (PDT) Date: Fri, 22 Mar 2019 15:32:32 +0100 From: Juri Lelli To: luca abeni Cc: "chengjian (D)" , "linux-kernel@vger.kernel.org" , Li Bin , "Xiexiuqi (Xie XiuQi)" , mingo@redhat.com, Peter Zijlstra Subject: Re: WARN ON at kernel/sched/deadline.c task_non_contending Message-ID: <20190322143232.GI8775@localhost.localdomain> References: <20190313154948.773427d6@luca64> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190313154948.773427d6@luca64> 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 Hi, On 13/03/19 15:49, luca abeni wrote: > Hi, > > (I added Juri in cc) > > On Tue, 12 Mar 2019 10:03:12 +0800 > "chengjian (D)" wrote: > [...] > > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > > index 31c050a0d0ce..d73cb033a06d 100644 > > --- a/kernel/sched/deadline.c > > +++ b/kernel/sched/deadline.c > > @@ -252,7 +252,6 @@ static void task_non_contending(struct > > task_struct *p) if (dl_entity_is_special(dl_se)) > > ??????????????? return; > > > > -?????? WARN_ON(hrtimer_active(&dl_se->inactive_timer)); > > ??????? WARN_ON(dl_se->dl_non_contending); > > > > ??????? zerolag_time = dl_se->deadline - > > @@ -287,7 +286,9 @@ static void task_non_contending(struct > > task_struct *p) } > > > > ??????? dl_se->dl_non_contending = 1; > > -?????? get_task_struct(p); > > + > > +?????? if (!hrtimer_active(&dl_se->inactive_timer)); > > +?????????????? get_task_struct(p); > > ??????? hrtimer_start(timer, ns_to_ktime(zerolag_time), > > HRTIMER_MODE_REL); } > > After looking at the patch a little bit more and running some tests, > I suspect this solution might be racy: > when the timer is already active, (and hrtimer_start() fails), it > relies on its handler to decrease the running bw (by setting > dl_non_contending to 1)... But inactive_task_timer() might have > already checked dl_non_contending, finding it equal to 0 (so, it > ends up doing nothing and the running bw is not decreased). > > > So, I would prefer a different solution. I think this patch should work: > > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > index 6a73e41a2016..43901fa3f269 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c > @@ -252,7 +252,6 @@ static void task_non_contending(struct task_struct *p) > if (dl_entity_is_special(dl_se)) > return; > > - WARN_ON(hrtimer_active(&dl_se->inactive_timer)); > WARN_ON(dl_se->dl_non_contending); > > zerolag_time = dl_se->deadline - > @@ -269,7 +268,7 @@ static void task_non_contending(struct task_struct *p) > * If the "0-lag time" already passed, decrease the active > * utilization now, instead of starting a timer > */ > - if (zerolag_time < 0) { > + if ((zerolag_time < 0) || hrtimer_active(&dl_se->inactive_timer)) { > if (dl_task(p)) > sub_running_bw(dl_se, dl_rq); > if (!dl_task(p) || p->state == TASK_DEAD) { > > > The idea is that if the timer is active, we leave dl_non_contending set to > 0 (so that the timer handler does nothing), and we immediately decrease the > running bw. > I think this is OK, because this situation can happen only if the task > blocks, wakes up while the timer handler is running, and then immediately > blocks again - while the timer handler is still running. So, the "zero lag > time" cannot be too much in the future. And if we get here and the handler is running it means that the handler is spinning on rq->lock waiting the dequeue to release it. So, this looks safe to me as well. BTW, I could reproduce with Steve's deadline_test [1], and this seems to fix it. Would you mind sending out a proper patch Luca? Thanks! - Juri 1 - https://goo.gl/fVbRSu