Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7225277rwd; Tue, 6 Jun 2023 07:57:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4JXWM0VXmiwTmZVQC9YXeqXzhuPQcI4FqC204YtXFS7ENpkpuoJIF7kqfutlBme1HiJcXJ X-Received: by 2002:ac8:5cc6:0:b0:3ef:5bfc:de92 with SMTP id s6-20020ac85cc6000000b003ef5bfcde92mr2695750qta.55.1686063468612; Tue, 06 Jun 2023 07:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063468; cv=none; d=google.com; s=arc-20160816; b=msS+A8wEaFp0iUJzK1HivPgRGUSJseAKQrLfi9BaerbzNwE7TdmDssd5I9snGjkLqr fpBioIRd97AT5sUvQ7IbyycSIPMDUlrpyRtu4EujexUUfshmJmf/dSnZ7aM0KXXpzCTj cHkv0iDsY8DJgv6Hh4H3x4lEFQAndtcEaG1OS6qWvrdDl9pmmQs2CVEmZLYQICDT6Vwz 5Il4eId6op6VC7Zr+Tw4vmcDIvv40aXcCJmEKpFezvkHqNacGzFxs5J7f8qrwzcqt5Al X/DfMd366IfDZZZxHv1miB46uAqjBCC6ylHbdCd8pT2Qoaa6hdhttpnyQQSwdyEw1Iu3 vw/g== 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.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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e20-20020ac84e54000000b003f9a6395ee7si2687655qtw.243.2023.06.06.07.57.34; Tue, 06 Jun 2023 07:57:48 -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.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 S238028AbjFFOiV (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 Content-Type: text/plain; charset=UTF-8 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 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);