From patchwork Mon Jun 5 22:17:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 103514 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2998819vqr; Mon, 5 Jun 2023 15:52:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7r1wxxcsv0wS7fjzJvTgVcTGvmm8lZgf9YuV1pog+cYaC7uLiy5v1Ua1TWXnnrUvfRKPA7 X-Received: by 2002:a9d:6649:0:b0:6b2:420:672e with SMTP id q9-20020a9d6649000000b006b20420672emr163934otm.8.1686005539122; Mon, 05 Jun 2023 15:52:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686005539; cv=none; d=google.com; s=arc-20160816; b=ZYpwpSchdQiSLCZzQUVxxlDVcS1SfLMbHnzOiVvuKvdTd+AV7VpjsfnRit3kWhTijK 1CF0rAbun4gb6U67oJmA34bHYR9JPftTjhg82XdCMvs8oNf8u0c/IW3taClD4bqjnGEl S53zqYnQ9rbiksg+Ll8E7F0RaKQDT+U1PCguk8h6gJ4wZtFB0Et5B2URJNidMYOg5pf/ QAMmHfdg2o2VSik+R3MvOhum+F8P5N1xVbAE4xEGg/gmiPNoZ4B+6fcjeQeWsOulfZMe NJELC/ZbyiEfNTvkeShCx2pWyslpd1c6eRgcT9bAkRLyC5aJj0qjK/XqXSBpLecieX/E p8Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=PhvvKbd2G49ZnYAqw+g10VV0rqTeiq2fmz9EP367sNg=; b=EKkoVH6ypTgTeYzusrIkitNFGvHumZV6MTVD1kriZMxWwUrvJ5xUHU45vgozF+BVah Yy0Yr4LjJtF07ot0ake1TCFK7GsI7t9m9IeZInnPOcuj35SRUcOJnr5o+63VSQuGZO/S tKnVmjlXFFPRqbzzT9ebQe9EsXt8kQUWfz9SX5nMupoxDVD5nH43l3I0XUesX5XWvqst vF1Fwdn/jA5UhdABaCEAFE0Z96vTGSgcw+utDdJUot8/2+myvh8Zx+zndU1CgbaIZvy7 o3MfNehJAAoSe6M5KdZwKx+SJ7vuTtgnXKpXUH3BJG+5QOveyLKIwOH8UH9n7QrooyzJ INHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZAzkaB7m; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=2Dl6y8Rn; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i2-20020a626d02000000b0063b82c0941fsi5878427pfc.36.2023.06.05.15.52.06; Mon, 05 Jun 2023 15:52:19 -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=ZAzkaB7m; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=2Dl6y8Rn; 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 S233094AbjFEWRo (ORCPT + 99 others); Mon, 5 Jun 2023 18:17:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232890AbjFEWRi (ORCPT ); Mon, 5 Jun 2023 18:17:38 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE088AF; Mon, 5 Jun 2023 15:17:36 -0700 (PDT) Date: Mon, 05 Jun 2023 22:17:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686003454; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PhvvKbd2G49ZnYAqw+g10VV0rqTeiq2fmz9EP367sNg=; b=ZAzkaB7mWKQed2tosJmlf406v5Zb79JZcsf9tubizC80tI9sVrlfkDEzPsqSJ3JVK3whUt BF8MJYP698K9kX39QInOA4+0Nzrr5dOlTc2cwQLJRCO+mYVFZa0LzAmNIOXfzv0xJ51jJ4 jzMVSCWwwMJHas1NEWnDNI/mCA0hCNdIgwUgX/pEZa7saDQup4pjltM/pn4fL5jKuLFkdd COwW/BDVXfN/bPqpe8bbgelrYqiv/Qnbs4saPNXkGhRwE6C7pHdNGpfTUj6lYgMh0Hk3L9 yasZJ34t1A7iGeA46ieu11ZCAad2Nc/8GFX9bil99NPAxGpB2byTUiocx4K8gg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686003454; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PhvvKbd2G49ZnYAqw+g10VV0rqTeiq2fmz9EP367sNg=; b=2Dl6y8RnPIY9X8dMJyW2BfrY7GAypmlZ+k8dwRYjAHZiucULdpXddxf1rQUHwHIJ7S4eku l2kAIJO0P3804kAw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] posix-timers: Clarify posix_timer_fn() comments Cc: Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <874jnrdmrq.ffs@tglx> References: <874jnrdmrq.ffs@tglx> MIME-Version: 1.0 Message-ID: <168600345398.404.9203824526879668035.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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,T_SCC_BODY_TEXT_LINE 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?1764176999689763952?= X-GMAIL-MSGID: =?utf-8?q?1767904944028267254?= The following commit has been merged into the timers/core branch of tip: Commit-ID: c78f261e5dcb415b9e35a13876fbf7d5f134c810 Gitweb: https://git.kernel.org/tip/c78f261e5dcb415b9e35a13876fbf7d5f134c810 Author: Thomas Gleixner AuthorDate: Thu, 01 Jun 2023 21:07:37 +02:00 Committer: Thomas Gleixner CommitterDate: Tue, 06 Jun 2023 00:12:55 +02:00 posix-timers: Clarify posix_timer_fn() comments Make the issues vs. SIG_IGN understandable and remove the 15 years old promise that a proper solution is already on the horizon. Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/874jnrdmrq.ffs@tglx --- kernel/time/posix-timers.c | 62 +++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index f1a7c62..a942020 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -326,11 +326,11 @@ int posix_timer_event(struct k_itimer *timr, int si_private) } /* - * This function gets called when a POSIX.1b interval timer expires. It - * is used as a callback from the kernel internal timer. The - * run_timer_list code ALWAYS calls with interrupts on. - - * This code is for CLOCK_REALTIME* and CLOCK_MONOTONIC* timers. + * This function gets called when a POSIX.1b interval timer expires from + * the HRTIMER interrupt (soft interrupt on RT kernels). + * + * Handles CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_BOOTTIME and CLOCK_TAI + * based timers. */ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) { @@ -348,9 +348,10 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) if (posix_timer_event(timr, si_private)) { /* - * signal was not sent because of sig_ignor - * we will not get a call back to restart it AND - * it should be restarted. + * The signal was not queued due to SIG_IGN. As a + * consequence the timer is not going to be rearmed from + * the signal delivery path. But as a real signal handler + * can be installed later the timer must be rearmed here. */ if (timr->it_interval != 0) { ktime_t now = hrtimer_cb_get_time(timer); @@ -359,34 +360,35 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) * FIXME: What we really want, is to stop this * timer completely and restart it in case the * SIG_IGN is removed. This is a non trivial - * change which involves sighand locking - * (sigh !), which we don't want to do late in - * the release cycle. + * change to the signal handling code. + * + * For now let timers with an interval less than a + * jiffie expire every jiffie and recheck for a + * valid signal handler. + * + * This avoids interrupt starvation in case of a + * very small interval, which would expire the + * timer immediately again. * - * For now we just let timers with an interval - * less than a jiffie expire every jiffie to - * avoid softirq starvation in case of SIG_IGN - * and a very small interval, which would put - * the timer right back on the softirq pending - * list. By moving now ahead of time we trick - * hrtimer_forward() to expire the timer - * later, while we still maintain the overrun - * accuracy, but have some inconsistency in - * the timer_gettime() case. This is at least - * better than a starved softirq. A more - * complex fix which solves also another related - * inconsistency is already in the pipeline. + * Moving now ahead of time by one jiffie tricks + * hrtimer_forward() to expire the timer later, + * while it still maintains the overrun accuracy + * for the price of a slight inconsistency in the + * timer_gettime() case. This is at least better + * than a timer storm. + * + * Only required when high resolution timers are + * enabled as the periodic tick based timers are + * automatically aligned to the next tick. */ -#ifdef CONFIG_HIGH_RES_TIMERS - { - ktime_t kj = NSEC_PER_SEC / HZ; + if (IS_ENABLED(CONFIG_HIGHRES_TIMERS)) { + ktime_t kj = TICK_NSEC; if (timr->it_interval < kj) now = ktime_add(now, kj); } -#endif - timr->it_overrun += hrtimer_forward(timer, now, - timr->it_interval); + + timr->it_overrun += hrtimer_forward(timer, now, timr->it_interval); ret = HRTIMER_RESTART; ++timr->it_requeue_pending; timr->it_active = 1;