From patchwork Tue Jun 6 14:37:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3465394vqr; Tue, 6 Jun 2023 08:09:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5F8+Ae5nOCKMVbTAQh0QmxhEpdUJdl/EG8X56aByuX+yNl2abRz1uwKKa0Mi87RF+jmRgn X-Received: by 2002:a17:902:ceca:b0:19c:dbce:dce8 with SMTP id d10-20020a170902ceca00b0019cdbcedce8mr2545033plg.15.1686064194035; Tue, 06 Jun 2023 08:09:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686064194; cv=none; d=google.com; s=arc-20160816; b=w9ztvF7b7QkTvf1NipbzT7tL0mncsJ/w9VipNDc1NQTTufsAtQTqXpTDyy0QsFlzgR RRHmHXCkoFuICvu7AE0z0BpTVsMv0CCuVLjXBjmcIqqzZcKOYl73S3N8ZoumkWR8buau m9l+YHku7lfAo0pbq1WxPFFsvMk/Eo657uWeKchYDp2quo/UCoEsRqSlW3gjoGa95bxV YrG0d5TRaol2ZtkzMv2maoiMpoXIBmvzii7btwD99EEOeP3kT1dHiDt5FtqFl/OiPMzy 47uJriJZ9n9zgiiHx56te0ut+mQDmWWFE/dGJcqELRA6h0QEiFfKNXPLMGA9ThRzygcH nD3A== 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=BUuJOcWJlcdLruwzTzGc8KK7BJlrslnwV3YCPjzAVYM=; b=NSjpMEERE8KuOeOmIf6Yi0n+48RxX8NIlyrE1kIR+ne8t1P1yMJIYi0oTFfbbZWoxT PNfyQ9ZX15rA/gx91vNw3Eh6YSrXwp7062n4o7LWVSW0TB0fYiMTHev8ho9ygEbg2qmz bCeRvJwGUzThhZDCGhlYnmgyyy5MwEhyX+fw5PCOkJmw+eUEF2M750mtsbYjOV3tg0M3 XirWHf8zW4LSeZXTIzVdkP3Kqe1odBlto7A1gynMXDXOeVRMcZsL8c+5cKxk+re9/N3E ybfifUbnNBFpL1qxZyQ+a2jFFpFBjr7xPstFYs3VJ7mhNACQt9SUhLVC5/ASlQgpl3xj iBaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=I5569+xR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 iw13-20020a170903044d00b001ac91ece0dasi7072377plb.7.2023.06.06.08.09.40; Tue, 06 Jun 2023 08:09:54 -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=I5569+xR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S237283AbjFFOiX (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238117AbjFFOh7 (ORCPT ); Tue, 6 Jun 2023 10:37:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDD981980 for ; Tue, 6 Jun 2023 07:37:42 -0700 (PDT) Message-ID: <20230606142031.816970056@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062261; 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=BUuJOcWJlcdLruwzTzGc8KK7BJlrslnwV3YCPjzAVYM=; b=I5569+xRiO8L9SxBdKWLlInNoyMp15B5f1fsUhs1CMRrvo5cp44kG2L/Vcn4zOOOwD3ItK P0YOx8Jr1BJcWmL6/6Bre25ByppqEqyTZGXau7n2XKgzVwo1iKT+NygySaNgaVIaZgKgDm FBGuAblTC/3KUREjAh0G5g+N332bg8jawAaS4FdNzKcaqvn4/9dys+TWVzQH1Dig/P+eJ3 M6jDAzJ009c4ETi/evZbe7DzEEPSKUMTFfWtKzSjHvkYNnRQWMpIVDTaNx7mek0YPtQwZu IWNGPjoYqTN6VZJWe/scJykc/7NCj9CRvp36kpt0gfRsLPx5zwOwoBsmbMnUhw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062261; 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=BUuJOcWJlcdLruwzTzGc8KK7BJlrslnwV3YCPjzAVYM=; b=/2HWb7Dxf5+XWRHkdmmsirK76BRh2t1DBD0zPzjUamOK6oidZTOXdFM19EyVGUwK69a7Pm sCh2xituWWCaJOBA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 14/45] posix-timers: Consolidate interval retrieval References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:40 +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?1767966448106476070?= X-GMAIL-MSGID: =?utf-8?q?1767966448106476070?= There is no point to collect the current interval in the posix clock specific settime() and gettime() callbacks. Just do it right in the common code. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/time/posix-cpu-timers.c | 26 ++++++++------------------ kernel/time/posix-timers.c | 18 +++++++++--------- 2 files changed, 17 insertions(+), 27 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -622,8 +622,8 @@ static int posix_cpu_timer_set(struct k_ { bool sigev_none = timer->it_sigev_notify == SIGEV_NONE; clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); - u64 old_expires, new_expires, old_incr, now; struct cpu_timer *ctmr = &timer->it.cpu; + u64 old_expires, new_expires, now; struct sighand_struct *sighand; struct task_struct *p; unsigned long flags; @@ -660,10 +660,7 @@ static int posix_cpu_timer_set(struct k_ return -ESRCH; } - /* - * Disarm any old timer after extracting its expiry time. - */ - old_incr = timer->it_interval; + /* Retrieve the current expiry time before disarming the timer */ old_expires = cpu_timer_getexpires(ctmr); if (unlikely(timer->it.cpu.firing)) { @@ -737,9 +734,6 @@ static int posix_cpu_timer_set(struct k_ cpu_timer_fire(timer); out: rcu_read_unlock(); - if (old) - old->it_interval = ns_to_timespec64(old_incr); - return ret; } @@ -785,17 +779,13 @@ static void posix_cpu_timer_get(struct k rcu_read_lock(); p = cpu_timer_task_rcu(timer); - if (p) { - itp->it_interval = ktime_to_timespec64(timer->it_interval); - - if (cpu_timer_getexpires(ctmr)) { - if (CPUCLOCK_PERTHREAD(timer->it_clock)) - now = cpu_clock_sample(clkid, p); - else - now = cpu_clock_sample_group(clkid, p, false); + if (p && cpu_timer_getexpires(ctmr)) { + if (CPUCLOCK_PERTHREAD(timer->it_clock)) + now = cpu_clock_sample(clkid, p); + else + now = cpu_clock_sample_group(clkid, p, false); - __posix_cpu_timer_get(timer, itp, now); - } + __posix_cpu_timer_get(timer, itp, now); } rcu_read_unlock(); } --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -636,17 +636,12 @@ static s64 common_hrtimer_forward(struct */ void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting) { + bool sig_none = timr->it_sigev_notify == SIGEV_NONE; const struct k_clock *kc = timr->kclock; - ktime_t now, remaining, iv; - bool sig_none; + bool iv = !!timr->it_interval; + ktime_t now, remaining; - sig_none = timr->it_sigev_notify == SIGEV_NONE; - iv = timr->it_interval; - - /* interval timer ? */ - if (iv) { - cur_setting->it_interval = ktime_to_timespec64(iv); - } else if (!timr->it_active) { + if (!iv && !timr->it_active) { /* * SIGEV_NONE oneshot timers are never queued and therefore * timr->it_active is always false. The check below @@ -705,6 +700,8 @@ static int do_timer_gettime(timer_t time return -EINVAL; memset(setting, 0, sizeof(*setting)); + setting->it_interval = ktime_to_timespec64(timr->it_interval); + kc = timr->kclock; if (WARN_ON_ONCE(!kc || !kc->timer_get)) ret = -EINVAL; @@ -918,6 +915,9 @@ static int do_timer_settime(timer_t time if (!timr) return -EINVAL; + if (old_spec64) + old_spec64->it_interval = ktime_to_timespec64(timr->it_interval); + kc = timr->kclock; if (WARN_ON_ONCE(!kc || !kc->timer_set)) error = -EINVAL;