Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7864977ybl; Thu, 16 Jan 2020 06:54:38 -0800 (PST) X-Google-Smtp-Source: APXvYqysJumseRxqHXx1gC/KdMT6cCYtGoGBuzD+vttRDRLu9V9ggcjfjbeCkwmQLB3S78iZi398 X-Received: by 2002:a9d:6d10:: with SMTP id o16mr2349757otp.28.1579186478046; Thu, 16 Jan 2020 06:54:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579186477; cv=none; d=google.com; s=arc-20160816; b=B4fknxCxy0DLAtvcTwPoDWTQWrAZSG2w9/FB9Hk0yFjFSNEa9DZwcYJcwdy9fjtdL/ dzvQqFFd8BX859vsaVcDXz4K5aePYhxx5oB5EPiObD+/O6O0MVq22eqBwO7UnbGcsWgq IOvbFbnHCLmj42nzMs+YKAgkdtlGixM7H7eYpVIDkUJaDpvui+NI84pACF6PWE4+LVzp O8/a5sTzlFx+mGCpEqUErwJaif6eA/bnFbpI7/Wu3BRuuuBWnKLsqgEp+pg939hpZQbt 4RNCLMNh2HUeRydnQWwsAlfFsnxJR1ww2dIbp6GGGSNMAD47BjZg8JqmnMQwtU64T3RF EyVQ== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=yAG5F0BuOVKutHS2oA0G+4pzXuSAbQlWbo0Z7t4Gz9U=; b=mh6mpQzjy8FpTJ1MAb2DYkpOMfX45pivMrO9B16gnX5pxKo0njFJZYvCT1kFeQzpog A1osV6TGVyWyDKzEr7IHQcuc5q/SUBB48Jf3lUkZ5e1P1sc2HtNRxosNuNXcsrIFeW5O eAFI4eWvVWdbJNJpbC87aNlKJJKgjMA1kV2M+47AToiv9trWj+0usF0PrdK7TjlNWi8S GODoyA5KdhyFVdHvsb9ewCksuiUGiJEKfXvdzE+nRJUS6/jG6QQ54kRlBVpHRCZBSwVw 94OZKskAg1blJFqkuu4YimWzWh70SyxjbzoaDMJ09jSeTBsQpQRMoS95UqQS782bsxZo D46Q== 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 i25si11618430oii.259.2020.01.16.06.54.26; Thu, 16 Jan 2020 06:54:37 -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; 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 S1726552AbgAPOwX (ORCPT + 99 others); Thu, 16 Jan 2020 09:52:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:40310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726151AbgAPOwX (ORCPT ); Thu, 16 Jan 2020 09:52:23 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8CEBF20730; Thu, 16 Jan 2020 14:52:21 +0000 (UTC) Date: Thu, 16 Jan 2020 09:52:20 -0500 From: Steven Rostedt To: Alexander Popov Cc: Linus Torvalds , John Stultz , Thomas Gleixner , Stephen Boyd , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , linux-kernel@vger.kernel.org, notify@kernel.org Subject: Re: [PATCH 1/1] timer: Warn about schedule_timeout() called for tasks in TASK_RUNNING state Message-ID: <20200116095220.7368a604@gandalf.local.home> In-Reply-To: <20200116140218.1328022-1-alex.popov@linux.com> References: <20200116140218.1328022-1-alex.popov@linux.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 16 Jan 2020 17:02:18 +0300 Alexander Popov wrote: > When we were preparing the patch 6dcd5d7a7a29c1e, we made a mistake noticed > by Linus: schedule_timeout() was called without setting the task state to > anything particular. It calls the scheduler, but doesn't delay anything, > because the task stays runnable. That happens because sched_submit_work() > does nothing for tasks in TASK_RUNNING state. > > Let's add a WARN_ONCE() under CONFIG_SCHED_DEBUG to detect such kernel > API misuse. > > Signed-off-by: Alexander Popov > --- > kernel/time/timer.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/kernel/time/timer.c b/kernel/time/timer.c > index 4820823515e9..52ad2d6ce352 100644 > --- a/kernel/time/timer.c > +++ b/kernel/time/timer.c > @@ -1887,6 +1887,11 @@ signed long __sched schedule_timeout(signed long timeout) > } > } > > +#ifdef CONFIG_SCHED_DEBUG > + WARN_ONCE(current->state == TASK_RUNNING, > + "schedule_timeout for TASK_RUNNING\n"); > +#endif > + But this can trigger false warnings. For example, if we are waiting on an event with a timeout: DEFINE_WAIT(wait); for (;;) { prepare_to_wait(&waitq, &wait, TASK_UNINTERRUPTIBLE); if (event) break; timeout = schedule_timeout(timeout); if (!timeout) break; } finish_wait(&waitq, &wait); If the event happens between "prepare_to_wait" and just before schedule_timeout(), the wait queue will set this task's state to TASK_RUNNING, which in turn triggers your warning. -- Steve > expire = timeout + jiffies; > > timer.task = current;