From patchwork Tue Jun 6 14:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103897 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3454865vqr; Tue, 6 Jun 2023 07:57:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/ZmyZTYq/iOZPCbj5ZhUCxxVI2kwuwVTynjMHJkoBHDm78ALAv+zYOGohVB6md9Ig/XKn X-Received: by 2002:ac8:5dd4:0:b0:3f8:67d7:e99c with SMTP id e20-20020ac85dd4000000b003f867d7e99cmr2034863qtx.39.1686063475447; Tue, 06 Jun 2023 07:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063475; cv=none; d=google.com; s=arc-20160816; b=Bw8GhlTRb6p+vqt9CNEVtOE7YWurd8iTohqKtc1QkBMqC5l/uFiKZ/BrgrtHGwXili adnNZn7axtgmx+fqTOUNPrO5obRIFZ5WV92EVWkbYBkF0DeRMWJ5/Ip9cRA9+yy4Rprv eBtSjyLZebKFeI0rxAEw6l02xYpYbCtwJIKtdjg8yfOz3M7UdiBZw06z1/HLtOQ9Yd17 xmczat0FNz8AA0Pvxd42ITd3GSfxTYcWVMfRRbZquTsO6ncm3fhiqFXJEQodTWto5IZB 7vEA1DnNMGAALAzvFwrTO6Pqe/tRrdEa6lb6RYCCvqQACusRMu6hJLI49l1J0+CAXjra sk3g== 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=dI0D1Wo/Od6DcD7Ru+BANLzwyGF+XR8DfEoK3hFuF2Q=; b=En0g3S2mdH5Y+1gKwxBVxaz71NG18GrGAMqRAsxOgS3FrjHkzYLDQR461BahdX3sfO MGjNbJeHLZzJ+SoqCOeAEgywsacgilg7FF20LsN1jHvAjAi2REeklGI6GLdhOLfaYRGM 2c9teAQHgt86bK8bsINDI1/kasnqeYbKjr9jd8Ft6IEbpUHZOO76U22VQtz4y9A57hny xfBalzPAzkjmWNf8n+s2f/B2fHqFv49Usp+ZKSeTmDi7Mn9wAvNDpqEhyGoSRAYSdIkm AX01OgDvxh2Z+ciYDpl9P/my5gLgYx5ZKDqjE9oaj+2tKHU5jp6AyhrRbvp7/H3i4kkU F38Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Yk/DXFdl"; dkim=neutral (no key) header.i=@linutronix.de header.b="SNm/mWkM"; 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 f21-20020a05622a105500b003f4e3171deasi6328978qte.76.2023.06.06.07.57.11; Tue, 06 Jun 2023 07:57:55 -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="Yk/DXFdl"; dkim=neutral (no key) header.i=@linutronix.de header.b="SNm/mWkM"; 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 S238032AbjFFOiV (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237955AbjFFOh6 (ORCPT ); Tue, 6 Jun 2023 10:37:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3070172E for ; Tue, 6 Jun 2023 07:37:39 -0700 (PDT) Message-ID: <20230606142031.705286109@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062258; 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=dI0D1Wo/Od6DcD7Ru+BANLzwyGF+XR8DfEoK3hFuF2Q=; b=Yk/DXFdlqLfDQyfx0BKzMlN/bE3cA9fTYL2SSewfi6g0ICus4972urAWOD18WUFrh8QElC J2cZ+8OHKTjsths3W8x50BG9w+ENc2CAv0z9OyxhrYV9U2Khyusw5ZL++NT1iWc3Iw/NoW U7GHdOSNqa54uenn6q2mW4QdYxaUIH3QWvztjseXzYm93xO3le3AajEnSDX02FtCwZzB5H 7ta7T0VkQEUzZ4AVGTQ5cTQG5WGT2B3OV/cOVbp7uyRGicCMiZfpp+wBEnp2KxryAAA8if PJvMUwjuhbMdyuEf4D+zN9MMG1vngzz37BKBmzPQrDgwUdGEgP7QnKYvj/Z12w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062258; 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=dI0D1Wo/Od6DcD7Ru+BANLzwyGF+XR8DfEoK3hFuF2Q=; b=SNm/mWkMVZs8Rfv0eVLM0rOkYdYVZZ281k1zAaoHe4TG53Ioth7F4d1QqGFxgdGx53QrZA udmiyD8CV7sID9CQ== 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 12/45] posix-cpu-timers: Simplify posix_cpu_timer_set() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:37 +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?1767965694638878079?= X-GMAIL-MSGID: =?utf-8?q?1767965694638878079?= Avoid the late sighand lock/unlock dance when a timer is not armed to enforce reevaluation of the timer base so that the process wide CPU timer sampling can be disabled. Do it right at the point where the arming decision is made which already has sighand locked. Signed-off-by: Thomas Gleixner --- kernel/time/posix-cpu-timers.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -720,10 +720,14 @@ static int posix_cpu_timer_set(struct k_ /* * Arm the timer if it is not disabled, the new expiry value has * not yet expired and the timer requires signal delivery. - * SIGEV_NONE timers are never armed. + * SIGEV_NONE timers are never armed. In case the timer is not + * armed, enforce the reevaluation of the timer base so that the + * process wide cputime counter can be disabled eventually. */ if (!sigev_none && new_expires && now < new_expires) arm_timer(timer, p); + else + trigger_base_recalc_expires(timer, p); unlock_task_sighand(p, &flags); /* @@ -742,30 +746,14 @@ static int posix_cpu_timer_set(struct k_ timer->it_overrun_last = 0; timer->it_overrun = -1; - if (!sigev_none && now >= new_expires) { - if (new_expires != 0) { - /* - * The designated time already passed, so we notify - * immediately, even if the thread never runs to - * accumulate more time on this clock. - */ - cpu_timer_fire(timer); - } - - /* - * Make sure we don't keep around the process wide cputime - * counter or the tick dependency if they are not necessary. - */ - sighand = lock_task_sighand(p, &flags); - if (!sighand) - goto out; - - if (!cpu_timer_queued(ctmr)) - trigger_base_recalc_expires(timer, p); - - unlock_task_sighand(p, &flags); - } - out: + /* + * If the new expiry time was already in the past the timer was not + * queued. Fire it immediately even if the thread never runs to + * accumulate more time on this clock. + */ + if (!sigev_none && new_expires && now >= new_expires) + cpu_timer_fire(timer); +out: rcu_read_unlock(); if (old) old->it_interval = ns_to_timespec64(old_incr);