Message ID | 20231030145104.4107573-1-vschneid@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2274411vqb; Mon, 30 Oct 2023 07:52:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUpE/KDnOa3kXpAR4CJz6dlzq0i6Gj573PrWTfzMpIAt/lOO/SvqNM1yy2+4tqzsI/BdlA X-Received: by 2002:a05:6359:1a09:b0:168:e8e6:b91f with SMTP id rt9-20020a0563591a0900b00168e8e6b91fmr7944855rwb.18.1698677558734; Mon, 30 Oct 2023 07:52:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698677558; cv=none; d=google.com; s=arc-20160816; b=WsKVqD+OXmZvGxehTBZqViCvumAitjm2nBB9gzaXfeL2l78veyu7BPrgIYD1JERPlV XassTHYzDpCkPLl0PJW/h4wScRYC3rRuZl6vR+t0n3aGMfn9kEfeR+lP5Tgq8MldDvIr fLygCRHUxYY7Y5vzPxTV+7sxueOoDDeb7i8pePYWxOcDyLjOhfOtnqvspNDy76Czep67 cykacf9rxI+lLI5RaNO1RUtZ2TSYuusvCGaZxaqEzOcv/inPd31gkE0pjgFqd4eY2r2X pGR0PtO7hgB3c+v4SA3zohP+hL5nDZYYgH+inyaM/4rz+71/JBbwEFgdNG8uNFFuFZ2u NmaA== 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=iZM5Ir1agMVPmsp/0h/z8SE5MvN1kGhnLqtdaxL5v4U=; fh=3Z0w0RZhRdG+NgRq69EeUfWJxuEuP4GD6oXa2+Srmk0=; b=mqpkj6tpvMSv6DwbZKvMGepKAVFWffYORYIUvO0HE0qGZOeppylzTu3esSzhs+/5q/ 2R94AgNTRGvdmExnIpXNzwLoAawcYmo3mafQtPoBp31Py3+0y+TZ5SS9saUCH3DpS22b /0FHLdpn8EGXDHKP6nvvLWc5vcpR3+i/eDx4c8y0lX8Fhln9AC0abQzFNVGggM6YsWwE KsjMWWrL1ZytBoVruAW/Wu6e0ziMlrkdNBAJZHG5V7NwEHc2N5AkSKas0tk56H5Kjg5y TsBlkcaupTH748TtKmH1NgLe0TeIhl12IQObryf1M7RQ38IGIPjfpGwKr7CuUfec1fXz kZQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UrNZkCfc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k198-20020a636fcf000000b005ad35f5a7basi4806181pgc.507.2023.10.30.07.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 07:52:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UrNZkCfc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 54CD9803E7AE; Mon, 30 Oct 2023 07:52:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233544AbjJ3Owd (ORCPT <rfc822;chrisjones.unixmen@gmail.com> + 32 others); Mon, 30 Oct 2023 10:52:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232542AbjJ3Owb (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 30 Oct 2023 10:52:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83826C2 for <linux-kernel@vger.kernel.org>; Mon, 30 Oct 2023 07:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698677502; 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=iZM5Ir1agMVPmsp/0h/z8SE5MvN1kGhnLqtdaxL5v4U=; b=UrNZkCfc99nrG6JWraMNbIgCnD2ZOfrDTgdal9GkGb7lbEqCs/qGmARn9osFqTfNcCfoaz W8OINYUvt20JW9JlkuuMmUnGPOwn5ZL6BH8+A9jRrGKdgkMV7YEfmqmqJVMlQdNnSiZ6eU DKPUcJZYgtY9iHojQzHSGLXYs80cuhg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-42-ZvuMTU3_O-aBrCNMZjNOXQ-1; Mon, 30 Oct 2023 10:51:32 -0400 X-MC-Unique: ZvuMTU3_O-aBrCNMZjNOXQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 61BD61C01B2C; Mon, 30 Oct 2023 14:51:31 +0000 (UTC) Received: from vschneid-thinkpadt14sgen2i.remote.csb (unknown [10.39.194.198]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0EA81492BE0; Mon, 30 Oct 2023 14:51:28 +0000 (UTC) From: Valentin Schneider <vschneid@redhat.com> To: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org Cc: Daniel Bristot de Oliveira <bristot@redhat.com>, Dietmar Eggemann <dietmar.eggemann@arm.com>, Ingo Molnar <mingo@redhat.com>, Juri Lelli <juri.lelli@redhat.com>, Peter Zijlstra <peterz@infradead.org>, Steven Rostedt <rostedt@goodmis.org>, Vincent Guittot <vincent.guittot@linaro.org>, Thomas Gleixner <tglx@linutronix.de>, Sebastian Andrzej Siewior <bigeasy@linutronix.de>, Tomas Glozar <tglozar@redhat.com> Subject: [PATCH] sched/fair: Make the BW replenish timer expire in hardirq context for PREEMPT_RT Date: Mon, 30 Oct 2023 15:51:04 +0100 Message-ID: <20231030145104.4107573-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 30 Oct 2023 07:52:37 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781192519853659451 X-GMAIL-MSGID: 1781192519853659451 |
Series |
sched/fair: Make the BW replenish timer expire in hardirq context for PREEMPT_RT
|
|
Commit Message
Valentin Schneider
Oct. 30, 2023, 2:51 p.m. UTC
Consider the following scenario under PREEMPT_RT:
o A CFS task p0 gets throttled while holding read_lock(&lock)
o A task p1 blocks on write_lock(&lock), making further readers enter the
slowpath
o A ktimers or ksoftirqd task blocks on read_lock(&lock)
If the cfs_bandwidth.period_timer to replenish p0's runtime is enqueued on
the same CPU as one where ktimers/ksoftirqd is blocked on read_lock(&lock),
this creates a circular dependency.
This has been observed to happen with:
o fs/eventpoll.c::ep->lock
o net/netlink/af_netlink.c::nl_table_lock (after hand-fixing the above)
but can trigger with any rwlock that can be acquired in both process and
softirq contexts.
The linux-rt tree has had
1ea50f9636f0 ("softirq: Use a dedicated thread for timer wakeups.")
which helped this scenario for non-rwlock locks by ensuring the throttled
task would get PI'd to FIFO1 (ktimers' default priority). Unfortunately,
rwlocks cannot sanely do PI as they allow multiple readers.
Make the period_timer expire in hardirq context under PREEMPT_RT. The
callback for this timer can end up doing a lot of work, but this is
mitigated somewhat when using nohz_full / CPU isolation: the timers *are*
pinned, but on the CPUs the taskgroups are created on, which is usually
going to be HK CPUs.
Link: https://lore.kernel.org/all/xhsmhttqvnall.mognet@vschneid.remote.csb/
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
kernel/sched/fair.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Mon, Oct 30, 2023 at 03:51:04PM +0100, Valentin Schneider wrote: > Consider the following scenario under PREEMPT_RT: > o A CFS task p0 gets throttled while holding read_lock(&lock) > o A task p1 blocks on write_lock(&lock), making further readers enter the > slowpath > o A ktimers or ksoftirqd task blocks on read_lock(&lock) > > If the cfs_bandwidth.period_timer to replenish p0's runtime is enqueued on > the same CPU as one where ktimers/ksoftirqd is blocked on read_lock(&lock), > this creates a circular dependency. > > This has been observed to happen with: > o fs/eventpoll.c::ep->lock > o net/netlink/af_netlink.c::nl_table_lock (after hand-fixing the above) > but can trigger with any rwlock that can be acquired in both process and > softirq contexts. > > The linux-rt tree has had > 1ea50f9636f0 ("softirq: Use a dedicated thread for timer wakeups.") > which helped this scenario for non-rwlock locks by ensuring the throttled > task would get PI'd to FIFO1 (ktimers' default priority). Unfortunately, > rwlocks cannot sanely do PI as they allow multiple readers. > > Make the period_timer expire in hardirq context under PREEMPT_RT. The > callback for this timer can end up doing a lot of work, but this is > mitigated somewhat when using nohz_full / CPU isolation: the timers *are* > pinned, but on the CPUs the taskgroups are created on, which is usually > going to be HK CPUs. Moo... so I think 'people' have been pushing towards changing the bandwidth thing to only throttle on the return-to-user path. This solves the kernel side of the lock holder 'preemption' issue. I'm thinking working on that is saner than adding this O(n) cgroup loop to hard-irq context. Hmm?
On 2023-10-31 17:01:20 [+0100], Peter Zijlstra wrote: > On Mon, Oct 30, 2023 at 03:51:04PM +0100, Valentin Schneider wrote: > > task would get PI'd to FIFO1 (ktimers' default priority). Unfortunately, > > rwlocks cannot sanely do PI as they allow multiple readers. … > I'm thinking working on that is saner than adding this O(n) cgroup loop > to hard-irq context. Hmm? I have plans to get rid of the softirq issue and the argument for "bad" or inefficient rwlocks is usually "get rid of rwlocks then". So… Then I looked at the patch and it only swapped the flag nothing else and this hardly works. So I looked at sched_cfs_period_timer(): | static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer) | { … | raw_spin_lock_irqsave(&cfs_b->lock, flags); … | raw_spin_unlock_irqrestore(&cfs_b->lock, flags); | | return idle ? HRTIMER_NORESTART : HRTIMER_RESTART; |} Judging by this, the whole callback runs already with disabled interrupts. At least now it enabled interrupts if multiple callbacks are invoked… Sebastian
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 8767988242ee3..15cf7de865a97 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6236,7 +6236,7 @@ void init_cfs_bandwidth(struct cfs_bandwidth *cfs_b, struct cfs_bandwidth *paren cfs_b->hierarchical_quota = parent ? parent->hierarchical_quota : RUNTIME_INF; INIT_LIST_HEAD(&cfs_b->throttled_cfs_rq); - hrtimer_init(&cfs_b->period_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED); + hrtimer_init(&cfs_b->period_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED_HARD); cfs_b->period_timer.function = sched_cfs_period_timer; /* Add a random offset so that timers interleave */ @@ -6263,7 +6263,7 @@ void start_cfs_bandwidth(struct cfs_bandwidth *cfs_b) cfs_b->period_active = 1; hrtimer_forward_now(&cfs_b->period_timer, cfs_b->period); - hrtimer_start_expires(&cfs_b->period_timer, HRTIMER_MODE_ABS_PINNED); + hrtimer_start_expires(&cfs_b->period_timer, HRTIMER_MODE_ABS_PINNED_HARD); } static void destroy_cfs_bandwidth(struct cfs_bandwidth *cfs_b)