From patchwork Tue Apr 25 18:49:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 87515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3605167vqo; Tue, 25 Apr 2023 11:51:08 -0700 (PDT) X-Google-Smtp-Source: AKy350b91YTvKwO2NlOXpS6+C3mhyjvBw2mhooZH5kRau681jyKklD39HQ7wS9mW9SdQdrTo9A1p X-Received: by 2002:a05:6a20:938b:b0:f4:d4a8:9c82 with SMTP id x11-20020a056a20938b00b000f4d4a89c82mr10909867pzh.47.1682448667710; Tue, 25 Apr 2023 11:51:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682448667; cv=none; d=google.com; s=arc-20160816; b=yNDyBrCk7SyiiCK65fkIVriCRqJZjXndoCwo0Qb7umXKDBetT0Odpzk0m+GOkpjlM6 g4DyEsslNdkXkEkmX/8FwZ3oICHyplQbegffXmcH074J+8qxXruGEsnwS0okGYkejCRF NVvErL/1Ag5fg+uZW882K6zEf+/aM2qSajP9pNftAi4glGBJPOWF6QBvcz8nFkNmgY88 Zi+JMB5H92YfsB1Q2dSQCHtFGk3BzZm7PAYvU6SW/yfBSqYaaVbDI0YAaHNKj8fstYa3 alxCi384YqvfNte4TXA9P96rA2ipAjTVc2WXmFnR3YSyf3Sx16w51j6Z0LXEeVWxAUMk /9Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=OftMSE12zQRmdkVUGBv+nkpk/BkQQU4Y9Jo02sefzOk=; b=pgvM5UgDAHiVmvjYzsUM7rFSmR27Rc0DXtCWxaGWFvoOm97IzPhQ55D15HtaFUvaAQ UtUZmNfBP0QaBztsL+H5LM1+wwAXx5JaQoTRx3RaeXaxldunZlCKoNGu2266d9l66dG9 JcRNk/q9EZyUYQVdAX3+PXD8og4Y2M/AVokbseOglFLHue+XnTPIbn4lsRuAqaRM3Nm/ eBscR1a5hmEocT99eFfwUeu42a2JlMdb+eVIQIkhsEbC+1/oCj51MFXdK6YoF3o3ML5N RpOdmtkXiywkvw1fRJW70PsTOSvidspvNID+gDqANWf81yeOCv8o7VjPWjUvrA4zPEeL LnCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nDl5yt7+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Z6Xi5jHp; 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 w8-20020a63f508000000b0051f6d22be51si15150334pgh.573.2023.04.25.11.50.53; Tue, 25 Apr 2023 11:51:07 -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=nDl5yt7+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Z6Xi5jHp; 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 S234779AbjDYStv (ORCPT + 99 others); Tue, 25 Apr 2023 14:49:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234766AbjDYStY (ORCPT ); Tue, 25 Apr 2023 14:49:24 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F91317A04 for ; Tue, 25 Apr 2023 11:49:15 -0700 (PDT) Message-ID: <20230425183313.409169321@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1682448553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=OftMSE12zQRmdkVUGBv+nkpk/BkQQU4Y9Jo02sefzOk=; b=nDl5yt7+JD2vDRRpCR3LBaiAJA9pKy8yQqRR2YI/lZZ6K0rueJ6loAqn/WROjzT7j5nDMF sX3YPDurf6WxIBaOlBDAkbTfy604auteDuwbXS/UOeKcJ8e8bPu8JtRItUcc+MWn5vZ04N sW5COWqb1WeHb4jEtT19Yj/2iKufme552mRcsmEAO0YHcnMZnU2aDPTxCytjr+QkrwW1hc 0RwvGqxOiCpN9wGKaygT2bvcipZaoI1wzLJVLztqdNJiUdkGHnZRPCKDiLdDC7x7vDtwRH cySevYKWAWFOnB1p5oGmqSHWyh2pqlbnfxR8ncU4ol1VhYP3eIIyIa5TxNtW7A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1682448553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=OftMSE12zQRmdkVUGBv+nkpk/BkQQU4Y9Jo02sefzOk=; b=Z6Xi5jHpo1B87jSElU/Frrjl9kLNd40sgenJCjf6iEiulTEpFi0fMije2/f5AZLdz3ZOcV a7M1frfjzZ3rEsBw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , Peter Zijlstra , Sebastian Siewior , syzbot+5c54bd3eb218bb595aa9@syzkaller.appspotmail.com, Dmitry Vyukov , Michael Kerrisk Subject: [patch 11/20] posix-timers: Document common_clock_get() correctly References: <20230425181827.219128101@linutronix.de> MIME-Version: 1.0 Date: Tue, 25 Apr 2023 20:49:12 +0200 (CEST) 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,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764175294141225378?= X-GMAIL-MSGID: =?utf-8?q?1764175294141225378?= Replace another confusing and inaccurate set of comments. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/time/posix-timers.c | 50 +++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 20 deletions(-) --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -659,20 +659,16 @@ static s64 common_hrtimer_forward(struct } /* - * Get the time remaining on a POSIX.1b interval timer. This function - * is ALWAYS called with spin_lock_irq on the timer, thus it must not - * mess with irq. + * Get the time remaining on a POSIX.1b interval timer. * - * We have a couple of messes to clean up here. First there is the case - * of a timer that has a requeue pending. These timers should appear to - * be in the timer list with an expiry as if we were to requeue them - * now. + * Two issues to handle here: * - * The second issue is the SIGEV_NONE timer which may be active but is - * not really ever put in the timer list (to save system resources). - * This timer may be expired, and if so, we will do it here. Otherwise - * it is the same as a requeue pending timer WRT to what we should - * report. + * 1) The timer has a requeue pending. The return value must appear as + * if the timer has been requeued right now. + * + * 2) The timer is a SIGEV_NONE timer. These timers are never enqueued + * into the hrtimer queue and therefore never expired. Emulate expiry + * here taking #1 into account. */ void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting) { @@ -688,8 +684,12 @@ void common_timer_get(struct k_itimer *t cur_setting->it_interval = ktime_to_timespec64(iv); } else if (!timr->it_active) { /* - * SIGEV_NONE oneshot timers are never queued. Check them - * below. + * SIGEV_NONE oneshot timers are never queued and therefore + * timr->it_active is always false. The check below + * vs. remaining time will handle this case. + * + * For all other timers there is nothing to update here, so + * return. */ if (!sig_none) return; @@ -698,18 +698,29 @@ void common_timer_get(struct k_itimer *t now = kc->clock_get_ktime(timr->it_clock); /* - * When a requeue is pending or this is a SIGEV_NONE timer move the - * expiry time forward by intervals, so expiry is > now. + * If this is an interval timer and either has requeue pending or + * is a SIGEV_NONE timer move the expiry time forward by intervals, + * so expiry is > now. */ if (iv && (timr->it_requeue_pending & REQUEUE_PENDING || sig_none)) timr->it_overrun += kc->timer_forward(timr, now); remaining = kc->timer_remaining(timr, now); - /* Return 0 only, when the timer is expired and not pending */ + /* + * As @now is retrieved before a possible timer_forward() and + * cannot be reevaluated by the compiler @remaining is based on the + * same @now value. Therefore @remaining is consistent vs. @now. + * + * Consequently all interval timers, i.e. @iv > 0, cannot have a + * remaining time <= 0 because timer_forward() guarantees to move + * them forward so that the next timer expiry is > @now. + */ if (remaining <= 0) { /* - * A single shot SIGEV_NONE timer must return 0, when - * it is expired ! + * A single shot SIGEV_NONE timer must return 0, when it is + * expired! Timers which have a real signal delivery mode + * must return a remaining time greater than 0 because the + * signal has not yet been delivered. */ if (!sig_none) cur_setting->it_value.tv_nsec = 1; @@ -718,7 +729,6 @@ void common_timer_get(struct k_itimer *t } } -/* Get the time remaining on a POSIX.1b interval timer. */ static int do_timer_gettime(timer_t timer_id, struct itimerspec64 *setting) { struct k_itimer *timr;