Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1635555rbb; Mon, 26 Feb 2024 16:49:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWc8gVxsr3RBKUb26sNo7BEUQKbYH6XaJeoosS4AFcaqLWXvEFhlKHTsIxrbPHiWCubZ2n5FHjXWBl17Lelk2MgSwh42AJkWxNyZdQMjQ== X-Google-Smtp-Source: AGHT+IFqtFvY32+Nf7QO26SHrWcZKkdyEawGJO41gOc4sAucEO0Y8q4nAVN9e/ZQgBiZIQdmw74q X-Received: by 2002:a9d:7559:0:b0:6e4:7773:a34b with SMTP id b25-20020a9d7559000000b006e47773a34bmr8257620otl.32.1708994965952; Mon, 26 Feb 2024 16:49:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708994965; cv=pass; d=google.com; s=arc-20160816; b=AnmFapZzjCGb4w0MWzSsFQGU2Jvpkyca1n3SstRfeo9KIIZ8qwGd5dfi/KYI5QCbK6 qeYNW2hWnKd0fjgBB9zydaVV41f4UySQF5kqBMiIOM4IfAOdoF1tIArFSS7wF9vRWOmd QEIOGZpZYrDXuI8D004RjWin2GPqqqVHbQwZSr/qeCiGdida7/rlUy1lIq8LyT9AM92D mpinul0Ggm1KRKlcuY/F0t62IOGq9ZxK8LVxchVN43XCGSlHlzzVxEjaYq2FzeBA43SM 67iz3uW+qWrxz3QSzyyfzwU+f8a5Hlej8EoMlK5vauCQPTj7a8kdQGu7pTF66DhDa0+n 9xzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=Ha1SPmpwr7o54xPSvG08jcbF74dcwj7k4612WTVV0U8=; fh=YRgC3RSu7s+0HgiNxI2TU2GGK8UZ2HCMw3fxZ+4V2WY=; b=W1IT7Ff4dJIYbtmtjS7XgH1hV6JRx1DUpIl7yBtpY2B1iAuVwZBZIJhV3/9kPVfMzS PR4O8nyM+ZmQlwrCxyqV75QZu9TEx/kl59KxMYOf5FPlS4BB9ptfTIRhlaQvFEOz2N6k 2qvjJXjQNU6XJcYED98LCVqzw3DABKVrvkin11JC06J7juGDYClcDjFOcWhLDE1Kkieu KrP1LStPeNqbjyPVT3ROBei4yCpLcNhHY9dDwqsUbKVbpKkwb/Uh+IyfY1KVsY4YxUq9 Aft/j4DKSNIAK4TAzWZs5Mx8nVmBDkL45M9eN3zVzI5ZyhFxTyoqUL1uFwT71dKLMR4e BisA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@delyan.me header.s=default header.b=jUfkWOjo; arc=pass (i=1 spf=pass spfdomain=delyan.me dkim=pass dkdomain=delyan.me); spf=pass (google.com: domain of linux-kernel+bounces-82480-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82480-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a13-20020a63d40d000000b005dbcff42ee2si4414873pgh.536.2024.02.26.16.49.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 16:49:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82480-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=fail header.i=@delyan.me header.s=default header.b=jUfkWOjo; arc=pass (i=1 spf=pass spfdomain=delyan.me dkim=pass dkdomain=delyan.me); spf=pass (google.com: domain of linux-kernel+bounces-82480-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82480-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 19577B22B79 for ; Tue, 27 Feb 2024 00:45:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A289E136A; Tue, 27 Feb 2024 00:45:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=delyan.me header.i=@delyan.me header.b="jUfkWOjo" Received: from chi120.greengeeks.net (chi120.greengeeks.net [173.236.97.50]) (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 E818A17FF for ; Tue, 27 Feb 2024 00:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.236.97.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708994718; cv=none; b=VIH/d+pjuv42zsxT/bmPhds+0g+6lClOKEpDT3oB4MtYdN5Grq8fGwXUQWqpxYRPyXcQmdQ94PeyAuh9EFxCYOg9hX0/lWWevxaepm/eunE9MYW6BtFPUkW2/KcQXHHxyN78DShrlJr597q5zgCw2M6aQPTTvIyoUQoJiz0/fjo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708994718; c=relaxed/simple; bh=7+H2MX6xwa9i7NO5yIxjPjOVCwU6yvq3m4R7rDSH9sI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OygHIFSsfoB9xNFFgH51SeB5d3ctl7jtv4DARGZjnF53zHWT/7nTKBsYifF9ScJldZqrYhDpQ5uJspPqvcdg75tz/A5waGd11jJIGBerYdOCbBX4MyYJHlsPs1aHOmGOInB5L72wS445CP7lqzgyy9RRBXX21+C2hizl1WlY7uc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=delyan.me; spf=pass smtp.mailfrom=delyan.me; dkim=pass (2048-bit key) header.d=delyan.me header.i=@delyan.me header.b=jUfkWOjo; arc=none smtp.client-ip=173.236.97.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=delyan.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=delyan.me DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=delyan.me; s=default; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ha1SPmpwr7o54xPSvG08jcbF74dcwj7k4612WTVV0U8=; b=jUfkWOjooy8nEg3LDdIRlCFl3T 9oTNHNnU6XlTufwazPK/ZcOPMCzguudgV540s6qU8j9twtm29PeR+vrnjfGItzAkYLHEIiBwC0ZYc lRB1l7QNOHKe5EdGZ4wayI2/di1KlJdG57gVi1h3UMQh5UVRH4ahdYVrcmC6pE3l1JSX5JMWdPYhA Czyl13mSiZMZ0KU71xmuC189fz1CZwu3C+wVk3E69rZS4bGlDHMqjoLT0RYV2pL/wexfUl5CvB1dQ 2zDxCMcDU9gtWWOivLraekvQZX2ZJSMgAVuYCt4Oqkxi/Q92vKSoiNlctQGO8fBkjKgi2PLoXgS1w E0MyPpiw==; Received: from c-98-47-236-196.hsd1.ca.comcast.net ([98.47.236.196]:39084 helo=discovery.localnet) by chi120.greengeeks.net with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1relLo-0001lg-3B; Mon, 26 Feb 2024 18:29:39 -0600 From: Delyan Kratunov To: linux-kernel@vger.kernel.org, Thomas Gleixner Subject: Re: Posix process cpu timer inaccuracies Date: Mon, 26 Feb 2024 16:29:38 -0800 Message-ID: <4547873.LvFx2qVVIh@discovery> In-Reply-To: <87cyt0gr9r.ffs@tglx> References: <87cyt0gr9r.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - chi120.greengeeks.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - delyan.me X-Get-Message-Sender-Via: chi120.greengeeks.net: authenticated_id: delyan@delyan.me X-Authenticated-Sender: chi120.greengeeks.net: delyan@delyan.me X-Source: X-Source-Args: X-Source-Dir: Thanks for your detailed response, Thomas, I appreciate you taking the time with my random side quest! > [...] > > That's wishful thinking and there is no way to ensure that. > Just for the record: setitimer() has been marked obsolescent in the > POSIX standard issue 7 in 2018. The replacement is timer_settime() which > has a few interesting properties vs. the overrun handling. This is a great point and I think it overrides anything I have to say about setitimer. Overall, I have nothing to rehash on the process signal delivery point, I understand the situation now, thanks to your thorough explanation! > [...] > I don't know and those assumptions have been clearly wrong at the point > where the tool was written. That was my impression as well, thanks for confirming. (I've found at least 3 tools with this same incorrect belief) > [...] > > they still have the same distribution issues. > > CLOCK_THREAD_CPUTIME_ID exists for a reason and user space can correlate > the thread data nicely. > > Aside of that there are PMUs and perf which solve all the problems you > are trying to solve in one go. Absolutely, the ability to write a profiler with perf_event_open is not in question at all. However, not every situation allows for PMU or perf_event_open access. Timers could form a nice middle ground, in exactly the way people have tried to use them. I'd like to push back a little on the "CLOCK_THREAD_CPUTIME_ID fixes things" point, though. From an application and library point of view, the per-thread clocks are harder to use - you need to either orchestrate every thread to participate voluntarily or poll the thread ids and create timers from another thread. In perf_event_open, this is solved via the .inherit/.inherit_thread bits. More importantly, they don't work for all workloads. If I have 10 threads that each run for 5ms, a 10ms process timer would fire 5 times, while per-thread 10ms timers would never fire. You can easily imagine an application that accrues all its cpu time in a way that doesn't generate a single signal (in the extreme, threads only living a single tick). Overall, what I want to establish is whether there's a path to achieve the _assumed_ interface that these tools expect - process-wide cpu signals that correlate with where cpu time is spent - through any existing or extended timer API. This interface would be imminently useful, as people have clearly, albeit misguidedly, demonstrated. If the answer is definitely "no," I'd like to at least add some notes to the man pages. -- Delyan