Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3427360rwo; Fri, 4 Aug 2023 04:59:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUVBbapaDVuZP+aE3p5BSVT3CKS4HmpBGvr1JXvjIAAa/ip+/BGgpD3/lMvSDjWiW7HZUF X-Received: by 2002:a17:902:ea09:b0:1bb:7b6c:983a with SMTP id s9-20020a170902ea0900b001bb7b6c983amr1547186plg.59.1691150396720; Fri, 04 Aug 2023 04:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691150396; cv=none; d=google.com; s=arc-20160816; b=MAMPvQmftIVqQXH8eVUiBjHlq5Ae95Q8gp7JLyaJzH2b+0IbsdR8WPOavICrvBwFS/ IeGF9LzihzC4rXcuCf+bH+NrW6RueyanDEs67wQajbuQVGf+l6//t8JyavsPAk8DEYxN /+fUF9lmYJi9lVRY0QLmRjUf+WdjZ6x5rxuaiD+lY0hMGJLOX7tOEbvTvEmxK4JbrYt2 L3I4VnBHYxvlEG8DQjjYIteQAmdk79Z746B7nPI/xDRJ9HrC8TE5XPh9cb0omtrV2U2l k4GkhBszqzTJKDXgELcXHmgsZx3yDswbCIcVyM/J3nHA3hWVyG3cHFzjfxjF17JCkF3n OSSQ== 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:dkim-signature:dkim-signature:from; bh=JQwdy939tDLgVEjU3blR0W4WS7PLhzs+UNZZN7ZNvYc=; fh=fGwS6lsCT/CjsuoHXMfe+F/3tQidNagrF92Uvies7jw=; b=OW6sKIguK/3opqoTbYtFAjBb8AEyWUkB/M0/LA+tw/DfKkeA5+uxHVtYWkiKB1/Bgf 9yUk1VaFtxbaBtK4Eg88h6ifXhsVdZM1Yq6Ox8KtKLB7vg2Ut+ADVN7MRY0U0WiOfwoe 7AH2/sIEmC5jTuGmFZYKUoClkP/lni9Fk5yHl2RCJiZajDVgvZrFyDGxOJP8RYQTPEXW SmBIQOdwrLqMqghUUaoFKuoBE477p/8JcVWb/jm0H07CdLpPMC77eZHcPuNo/jyIoTtO WIoGjnFAB412lTX0CMR77im8Sp2fB108M6DVegN8gNxfb92R/u0EfvHmBSNKkImIjgR0 Yypw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=u7DpROMP; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=j73gmz9a; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020a17090311c500b001b89bfd0c2csi1640634plh.647.2023.08.04.04.59.43; Fri, 04 Aug 2023 04:59:56 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=u7DpROMP; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=j73gmz9a; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230108AbjHDLay (ORCPT + 99 others); Fri, 4 Aug 2023 07:30:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjHDLau (ORCPT ); Fri, 4 Aug 2023 07:30:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFB4B11B for ; Fri, 4 Aug 2023 04:30:48 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691148646; 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=JQwdy939tDLgVEjU3blR0W4WS7PLhzs+UNZZN7ZNvYc=; b=u7DpROMPSeu4vLTyIm1eQKV6AbU1077urtQngtOmaPkRgbmRLfpFktW96jij24kXRifHaQ 25ZddmiOukvhvRuadw1bg+HjorgrZCwomriEoOycWP9tfcEW4X6Us0GZWGxp6nYEmH/Q2M MWESta7ZCQi0Dtq7Yg9IB8SjrHNQ0MZc3AC6N9Bv4C6r3NfD1ohydrd0e6StqG5Yd2JNqc ZmfNdOvq4ktq9WetLKye7PXN3NVm7Ud30lETVgpyONS9bBq2zS2Y1rLXQN2+g/523vG7B5 QOVbCrh/2OpdyHAtZmrGnUQqIOG6JjrzAK5Wr9Pg68AivHCgTh8gaEla3Xy9tA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691148646; 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=JQwdy939tDLgVEjU3blR0W4WS7PLhzs+UNZZN7ZNvYc=; b=j73gmz9aXFfEpLj5gg5Z7vx/JyB15i+p+/gjPMtAXG7FtP7cj+VQSTQ33k1SvFynyH2MtV R7vygNyOfBNVCvCw== To: linux-kernel@vger.kernel.org Cc: Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Frederic Weisbecker , Ingo Molnar , John Stultz , Juri Lelli , Mel Gorman , Peter Zijlstra , Stephen Boyd , Steven Rostedt , Thomas Gleixner , Valentin Schneider , Vincent Guittot Subject: [RFC PATCH 0/3] Allow to preempt a timer softirq on PREEMPT_RT. Date: Fri, 4 Aug 2023 13:30:36 +0200 Message-Id: <20230804113039.419794-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 Hi, while the softirqs are served, bottom halves are disabled. By disabling bottom halves (as per local_bh_disable()) PREEMPT_RT acquires a local_lock_t. This lock ensures that the softirq is synchronized against other softirq user on that CPU while keeping the context preemptible. This leads to a scenario where context itself is preemptible but needs to "complete" before the system can make progress. For instance, the timer callback (in TIMER_SOFTIRQ) gets preempted because a force-threaded interrupt thread, with higher priority, gets woken up. Before the handler of the forced-threaded interrupt can be invoked, bottom halves get disabled and this blocks on the same per-CPU lock. This in turn leads to a PI-boost and the preempted timer softirq is back on the CPU with higher priority completing its job (not just the timer, all pending softirqs). In the end the force threaded interrupt is blocked until all pending softirqs have been served. The PI-boost is usually intended to allow the thread with lower priority to "quickly" finish what it was doing and leave the critical section ASAP. This is not the case with softirqs and how this is handled by the individual callbacks. Additionally the need_resched() check in __do_softirq() is never true due to the boost. This means in worst case this can run for MAX_SOFTIRQ_TIME or MAX_SOFTIRQ_RESTART. One way of out would be to add preemption within the softirq handling at which point the softirq-BKL can be dropped. This can be after all softirqs have been served (__do_softirq() where the need_resched() check is located), after each softirq handler or within the softirq handler where it is considered safe to do so. This series adds as an example such a preemption point to the timer softirq handler. Should this fly then it would be needed the remaining handlers as well. Sebastian