From patchwork Thu Feb 2 18:28:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 52147 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp417225wrn; Thu, 2 Feb 2023 11:03:57 -0800 (PST) X-Google-Smtp-Source: AK7set+vk8teZlt8on0RLX57H4hUMOipRML2iFV6sIZEpUmdj8Jurearfy9ft5qff/AyX/5OF0/h X-Received: by 2002:a17:906:2bdb:b0:878:5917:601 with SMTP id n27-20020a1709062bdb00b0087859170601mr6886644ejg.58.1675364637173; Thu, 02 Feb 2023 11:03:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675364637; cv=none; d=google.com; s=arc-20160816; b=mKagNAsEHcHltiYHZY+Dus0uMxJR7x/CzIvcr1YK7DFdYRsFCcl78j7tg12q1uc7fT JubGfEOMI+vF9eMMPvBwHEPIoJdy+/g7HvFCuFTFGupaYsqlBOyKHOn9Sp61jgME+Pm+ f7KAvuAbXGtrJdSlGQiTsRyOjY3KGJmP0quJGQxONCmwmgy2145KqRv1glrBD1OtUL7U 5c8zCcHM3yTlPK8Cn22L68fSE7ZeB+67lFumg4cQ0tfrpDS50gqoYjk9X1z1YWmr28lZ XPSxxPhR+UgLEaiYB4ZVtIVVjeTozehG7QxsvWnKLmpGH7Bc5ogJ+E0/Sbj6u3ahn/j2 3wNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/2CxDEOz/wKRg3fPVeBOZL5/A6pUQeGKLsIcyTY078w=; b=zIiIFa4oY4bCGR2jGSHvaVG27KC2uF0FjkZqtJTUKHxkzRzULIWmN1U+EV/EeYcd8X EjwNCz/3kox7IqijW4bv8IAn7fYr1RfbsZSPYntKgXpKqHOkmawi99BY2H0MFVl6BsHS g8/1BCvLZT4DAtTdh2CmUfEqQgHqQe/cRzU/FFR30YaiZpoS2BzZYILBYa3+CtIfzLra YCFDS47a3/5+e66c3ZWDTSZzT8nses+pZSVTu/nopfj/PcLyVb6nW43eSV8il6nmLZKa 2JAxxPX4H8CzwWblRFr43cZgz/kfUfzRc2ylkMfO72nCH6W6a7Utjt5KfqsA4VQzKXu/ CL9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dzFb6Sz/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 14-20020a170906018e00b0087cfa71b5a3si504641ejb.42.2023.02.02.11.03.33; Thu, 02 Feb 2023 11:03:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dzFb6Sz/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231860AbjBBScv (ORCPT + 99 others); Thu, 2 Feb 2023 13:32:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232650AbjBBScf (ORCPT ); Thu, 2 Feb 2023 13:32:35 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2830D7E6DE for ; Thu, 2 Feb 2023 10:30:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675362553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/2CxDEOz/wKRg3fPVeBOZL5/A6pUQeGKLsIcyTY078w=; b=dzFb6Sz/l8Js9eL7OT71ft7tACdvNmXGCdEJAqhYqp+sR3+Xj3Dohrbv1yyNCjFQJ2YB3V c+dMUGkalots3EVw/RcnjbzYJcJSguCS4t7Gkk3HVD3n1yg9l+oTzpSz3WTc8yh529N0ZL JnONShKfl287lCbAXuULoZTjcTlgP0E= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-yacWg-_YP2WGO1gFxz4KjA-1; Thu, 02 Feb 2023 13:29:10 -0500 X-MC-Unique: yacWg-_YP2WGO1gFxz4KjA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E3C4A3810B14; Thu, 2 Feb 2023 18:29:09 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.33.36.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B0DF140EBF6; Thu, 2 Feb 2023 18:29:08 +0000 (UTC) From: Valentin Schneider To: linux-kernel@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Eder Zulian Subject: [RFC PATCH v1] sched/deadline: Add more reschedule cases to prio_changed_dl() Date: Thu, 2 Feb 2023 18:28:54 +0000 Message-Id: <20230202182854.3696665-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756747149576044661?= X-GMAIL-MSGID: =?utf-8?q?1756747149576044661?= I've been tracking down an issue on a ~5.17ish kernel where: CPUx CPUy
[idle task keeps running here until *something* accidentally sets TIF_NEED_RESCHED] On that kernel, it is quite easy to trigger using rt-tests's deadline_test [1] with the test running on isolated CPUs (this reduces the chance of something unrelated setting TIF_NEED_RESCHED on the idle tasks, making the issue even more obvious as the hung task detector chimes in). I haven't been able to reproduce this using a mainline kernel, even if I revert 2972e3050e35 ("tracing: Make trace_marker{,_raw} stream-like") which gets rid of the lock involved in the above test, *but* I cannot convince myself the issue isn't there from looking at the code. Make prio_changed_dl() issue a reschedule if the current task isn't a deadline one. While at it, ensure a reschedule is emitted when a queued-but-not-current task gets boosted with an earlier deadline that current's. [1]: https://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git Signed-off-by: Valentin Schneider --- kernel/sched/deadline.c | 45 ++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 0d97d54276cc8..faa382ea084c1 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2663,17 +2663,28 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p) static void prio_changed_dl(struct rq *rq, struct task_struct *p, int oldprio) { - if (task_on_rq_queued(p) || task_current(rq, p)) { -#ifdef CONFIG_SMP - /* - * This might be too much, but unfortunately - * we don't have the old deadline value, and - * we can't argue if the task is increasing - * or lowering its prio, so... - */ - if (!rq->dl.overloaded) - deadline_queue_pull_task(rq); + if (!task_on_rq_queued(p)) + return; + + /* + * We don't know if p has a earlier or later deadline, so let's blindly + * set a (maybe not needed) rescheduling point. + */ + if (!IS_ENABLED(CONFIG_SMP)) { + resched_curr(rq); + return; + } + /* + * This might be too much, but unfortunately + * we don't have the old deadline value, and + * we can't argue if the task is increasing + * or lowering its prio, so... + */ + if (!rq->dl.overloaded) + deadline_queue_pull_task(rq); + + if (task_current(rq, p)) { /* * If we now have a earlier deadline task than p, * then reschedule, provided p is still on this @@ -2681,14 +2692,16 @@ static void prio_changed_dl(struct rq *rq, struct task_struct *p, */ if (dl_time_before(rq->dl.earliest_dl.curr, p->dl.deadline)) resched_curr(rq); -#else + } else { /* - * Again, we don't know if p has a earlier - * or later deadline, so let's blindly set a - * (maybe not needed) rescheduling point. + * Current may not be deadline in case p was throttled but we + * have just replenished it (e.g. rt_mutex_setprio()). + * + * Otherwise, if p was given an earlier deadline, reschedule. */ - resched_curr(rq); -#endif /* CONFIG_SMP */ + if (!dl_task(rq->curr) || + dl_time_before(p->dl.deadline, rq->curr->dl.deadline)) + resched_curr(rq); } }