Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp65461lqg; Wed, 10 Apr 2024 15:49:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV4eAaKiSvoc4G/NNuNoryoYeqeGboRaM6A/TStpZYg9imlLo9TQxIjebIGOjZm7dYBWsE9pcnliisF8p5DDENByCcumo7AIH2ANvO4IQ== X-Google-Smtp-Source: AGHT+IHamhR12WGWsBqQvYCzM/17/0vEKDp1E+gi//yjdJogL/Y76qLqFQmUOe9X5HPpPRjikOHl X-Received: by 2002:a17:903:1381:b0:1e4:b1ea:23ef with SMTP id jx1-20020a170903138100b001e4b1ea23efmr4032574plb.49.1712789387380; Wed, 10 Apr 2024 15:49:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712789387; cv=pass; d=google.com; s=arc-20160816; b=rlbdG23Veviqu4rYoWZC8DmkLqKg/39BUScXmpFY04KqZ8oCpeEyQ96CZFP+psyRmh gZxqCHko10zClfrSTuZKkXhozJPUGcVjTZ58LXu0Kz/aXpGKVTzcKWSJe3i1h5FTqEfz I3iRqdzwMKtmc7MjBFNIGlh2lgQnf7kVfVl7AS4ajtVlQspRfu1ce1XNkYzaGdS0YthS ML2XCn0JP6mVxUKp7pNw2wcUvUfC88Qg4yYw986dOEKKJqrDYXs+LcSJ+oomtQ+zxBG9 2cPsqBZsmjAACp2xo8imX7XlJp42OA5zX2DzSFjW+rj0yNhktomF5IQqswvVa/S9vDuz 4atw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=prXY1arwiBmGreObgLsf7R5UB66La837yy2ta+3sTC4=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=l7u2k3iZhPoB0ipzUe24lg62zRIzgfP5ggaJ7YdqxKabGlGzak1ecAceGk7Vo9Tn8M 8SgwV58YEsHzIjfzeDJO7nIhVMKy+gU8/JHywi/jcJlfk5Qqt1nfLhR+LYqJHIbOh6qM AIfWaofKq6VfvW8TBQMgm82ib8HFFg2Xp5n7h23+9fDCVPMz2CzQueGqJdeUdTRTjanq 5qJ6AhX7gxsIbct09+wcJ5LqVAevvWIbGdMZyK9usMOrn5kjISvFvEjS4tvx3O3sdRrx Ze8unASsQMb0BEyR6P59M/bX8SlqRalWCYT6wbeZrAu4x+DoD3V7BHYkkoV+GO6f4oB8 WvwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cjCI4sb2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-139469-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139469-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h7-20020a170902680700b001e2a0f5c170si88972plk.505.2024.04.10.15.49.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 15:49:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139469-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cjCI4sb2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-139469-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139469-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7CF23283BC8 for ; Wed, 10 Apr 2024 22:49:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4775D38F84; Wed, 10 Apr 2024 22:46:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cjCI4sb2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MtBQOmX9" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DFA64D112 for ; Wed, 10 Apr 2024 22:46:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712789204; cv=none; b=kiowRvrsi+9rcr4c3x0UzGqhNyjgsOKpc27VF416EMNxHCrzA4slchsDqZk4BI82qjOt/l5sYAYuvd45pIpYE0V7jJQJ3JPZ1XzmXCluTVwFxQMWYSpjEXs9Yhsggz66Dpv01IrraIAVTJ50gi8x8SQcXD82ux5LXeOwKliOcXc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712789204; c=relaxed/simple; bh=jwLW+rNG7bMs4zQGx/O8eL+ZFKFCQ9a+FbpMQ0kFoaQ=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=km1gSvrwxgy3INsyTfGlzq+v9VQhczGYYra4Hp5pJwUOSG6vq2SGJcCB6PjKz7LaXjGG1+AQRVUrxwuHd7n4g+ONUKFpJ1IVaNrLyqicEkXDxZxbvohjNMxZOmZfYrB9H4oqJ40OAXvOReirVF7GBJF4tFmaAdzltqTRc35Vivk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cjCI4sb2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MtBQOmX9; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240410165551.943625183@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712789200; 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=prXY1arwiBmGreObgLsf7R5UB66La837yy2ta+3sTC4=; b=cjCI4sb2+ouxHsXnpuMYh8rkL5BNqBue0YnhK4whsbmKl9PTRMA5eSNJDwFS72Z+VXMXH3 XQFD5O/sVegZGi+bc/CezdFtt+B1BHo9SE2z7ghaaoihKQySMaIzbRpzXD9mxYomOSIhKz 9Y2sW0E6OQsDSaBM7A8/p26iNUcpfY+IX1zxckTb7Y6s7mcwPpV7JSw9t6coNxZvOTLt21 3Og2ZwFNYdXraNQtNXKqKKPrG2w/WlFvnWE3PNX+zyBV2JS93EwqY+TBfBy0LkjsS2RV2n PrGIHQnxo4Ki42hxVPZmG5U5N7Fw3TSb28l9wemS2l0MlAY0X+hFFdj6d7EUvQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712789200; 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=prXY1arwiBmGreObgLsf7R5UB66La837yy2ta+3sTC4=; b=MtBQOmX99XXLjGA+DYB/y8fzrQ7xInDBvvCcUod2moCFArtFK0y2CmGIgtqblp+p9x0LOx 6Gnt3aArXdCX98Dg== From: Thomas Gleixner To: LKML Cc: Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch V2 16/50] posix-cpu-timers: Simplify posix_cpu_timer_set() References: <20240410164558.316665885@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Thu, 11 Apr 2024 00:46:40 +0200 (CEST) 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 | 44 +++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -705,10 +705,16 @@ 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); + if (likely(!sigev_none)) { + if (new_expires && now < new_expires) + arm_timer(timer, p); + else + trigger_base_recalc_expires(timer, p); + } unlock_task_sighand(p, &flags); /* @@ -727,30 +733,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);