Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3055174imc; Wed, 13 Mar 2019 07:50:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1qWirtMoIyZkH+/7y/qdZQNAzLeO2uJwRlod4gQ6KFGIlvh6yrIP6EEdpsy2u5Kb34XkX X-Received: by 2002:aa7:9310:: with SMTP id 16mr44427935pfj.84.1552488634295; Wed, 13 Mar 2019 07:50:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552488634; cv=none; d=google.com; s=arc-20160816; b=Vb9UVCvq3vqgiWIR4zNhcmFLHdw+DyhEkQGMLHNIBVX+9P69EsDQMVaaMangnZ1Uhq fo/gk5XPOg+m7I4Q00o1S2EXrJH8g8/PfRDrQ2NCuyGGYjjFIwcXNvPhF6TdrbSNCgR4 IXRZkx5n02VSM9bfLd7djI+/JOH1IU5b43aWlZsaDujoklE6AT8Z7Wm22Ic3Jk/Pl1lO UP2+Lhm6RtyC1MrvYguxAnDh05xtoeVPId9z9Ou7hHwAmJroF+5SQUgl5lvOUix5FCmY TTiq79ApgOan85NL+hSRPfh2T9oM9lstANcsa2kZdo9fuz6E6j6MSaBqRos6bh8TtvQq N6Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=yAWkQFUQpH9tpT8zofN/mVKgfZEQSRU0MdmNs7AUjD0=; b=f73UHYTtI2QaLz62hKgfd441fX/KxL6aik4mRWNPvp2JyoWJ0oGxIEgxk8OaW3lY9l Z4gZ6JnkYy32iIKfUjSjy/bIQfjjB7V9dILHB/THPWuPA6sBZcQlx98owrzvUTKfmiJI eUHFm210S8n/Ya6r2cSGrP4ldib6FiK73lagv/z5TUuU9lzyUt4v2nliv1aflHrwwSXB HaOc+TH36rTpwzj9L9XIzgRP1IcaxtAPPkHC5FE5BOBd3d7EssFRqc8beVMPQ+7jChtH A5buLyksu7FrmGB1HKeQcXOO5V2aG/dYOVTIKhAK3GEgpsL8gUkGGcFtBlAaRtnW5DiF HpKg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si3615248pgo.257.2019.03.13.07.50.17; Wed, 13 Mar 2019 07:50:34 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726142AbfCMOt4 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 13 Mar 2019 10:49:56 -0400 Received: from ms01.santannapisa.it ([193.205.80.98]:53901 "EHLO mail.santannapisa.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725868AbfCMOt4 (ORCPT ); Wed, 13 Mar 2019 10:49:56 -0400 Received: from [10.30.3.156] (account l.abeni@santannapisa.it HELO luca64) by santannapisa.it (CommuniGate Pro SMTP 6.1.11) with ESMTPSA id 137252577; Wed, 13 Mar 2019 15:49:52 +0100 Date: Wed, 13 Mar 2019 15:49:48 +0100 From: luca abeni To: "chengjian (D)" Cc: "linux-kernel@vger.kernel.org" , Li Bin , "Xiexiuqi (Xie XiuQi)" , , Peter Zijlstra , Juri Lelli Subject: Re: WARN ON at kernel/sched/deadline.c task_non_contending Message-ID: <20190313154948.773427d6@luca64> In-Reply-To: References: Organization: Scuola Superiore S. Anna X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks, Luca