Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1048773rdb; Fri, 19 Jan 2024 06:49:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IElN4EZoMBrShG6NhbM0eBR0aehHeV529MJBgJk/fFsFGs7k6Nyy1+gqs22s+BcngVOU1Kx X-Received: by 2002:a17:906:e1a:b0:a2c:f3a:b196 with SMTP id l26-20020a1709060e1a00b00a2c0f3ab196mr1499285eji.118.1705675753767; Fri, 19 Jan 2024 06:49:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705675753; cv=pass; d=google.com; s=arc-20160816; b=MQeA1Wu6S+euV5GculIHM3J1b28RRA4+3rghEwDb7ObcHDG5Pobn/4h+RCqOcqL7tN SBAMiUC4hBvYET3bEJYTTKP0Sia+NcARGQboONHa+fQJZOIZbGqdolU5SmeWfhzJAVvK nsZ6J4H6hZk98Y1uhUCknEAQNWWFQ9PzLgVJPU72S4rWG4AhqotXPe2LzKRnA5ZGbW2N KHkDNR6TJ6O3p0J35mb6HwrMOArQqmrh3Oyu5QgEWIH8GLUoBoeIkNvf4ty0uNO/m756 vkUdn5n2hPkoRye5BIBOm/MTfSmkZix6sLOpnDMjQ/Mgyz1CEJS1W74tp3lT62N2zOlE dHyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=6+jDztzUAAhULXI1iUGX+i1wvpkn60O/xsFZ9FdQm1Q=; fh=ApSZSMqk2cOXZBaXQhOniVNa7xwAQ0YLx1sKJGpf0is=; b=kI0zOe+490XHyfxkpaSy/R3ajgkP45h8IXOV08LQO95wPD2ig3E0gXbvSWvOaz325c WJdiaoBvUKMQJ/4oLZ/q6ZrNyYIf1KqJ+guBTwjPxTuXIPyOZT/w4IgUe7FoaX3+iPAJ tGZl+DQ2ElzFTnrnBek6M/3grIMs2yxszyiLvY5ScRiON8hXwqtx0Z3H016E63cAhyBA ntviasP9XCSGKrEjg+5JCGdWHLXrx3Lr3eqQAxCpxDARyIxzdGJhSNjYcnQM3jWm7SBF 1rXOJghLKGBT/gLBtYDVuPl3aI9dOMjNjXXrcgnvrpT0JrdNJpMXn+CcXmyyGLfPafEy 9cCw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=r9plyTna; arc=pass (i=1 spf=pass spfdomain=efficios.com dkim=pass dkdomain=efficios.com dmarc=pass fromdomain=efficios.com); spf=pass (google.com: domain of linux-kernel+bounces-31271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l22-20020a17090612d600b00a2901cdea61si7334326ejb.149.2024.01.19.06.49.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 06:49:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=r9plyTna; arc=pass (i=1 spf=pass spfdomain=efficios.com dkim=pass dkdomain=efficios.com dmarc=pass fromdomain=efficios.com); spf=pass (google.com: domain of linux-kernel+bounces-31271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 83DDD1F263E5 for ; Fri, 19 Jan 2024 14:49:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F09954BCB; Fri, 19 Jan 2024 14:48:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="r9plyTna" Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (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 1CB5A5479F; Fri, 19 Jan 2024 14:48:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705675723; cv=none; b=joNJEEXBAOJKZa7Bi7I3zeHkMS3pDy7XewFfW0vPUlIqj38+RrJnyzDnOG6AbR8LSAV0enFRga2EaKQaLF4FniUHKFYYegMakCunO8sAkbHttTGGc9OqfC4zXAsEDufNJpv0cQZ0n06v2vpP+9XDg9qhJpB1Z81piWgDLxJ3KKQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705675723; c=relaxed/simple; bh=N5dxDJ8RBtd+2+qEyuvlZWxCpwk9SOuLxT5zchJWh7g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dtzIHl/RXVU9uF7rVI3EMgT1ARNg6YFOPGCLHw9mm5jslfR0PG1A9LurZNuGxch+ItjPgeAooVGJOq96m2m5EWxGA+7qLvTzYZWdv/7L/mCg77ca8RC6WQj9bJ1+B1VO4bHwToth1PcUoXK79mo5TCJ82sjYtjLkkdSq7ZnRQM0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=r9plyTna; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1705675228; bh=N5dxDJ8RBtd+2+qEyuvlZWxCpwk9SOuLxT5zchJWh7g=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=r9plyTnaRfggs+rIScfK287Oih516Dx4TkppuV/JDCfjQgfyAWermTZsR6ZAya2I3 wb7GRgjVdaKxlW/znjeJ5wNYkW/xctA0PBxSyoKF7K8ZnDKJ0Z94bgR3sXuN/Wyehe pGKCj8O4Ni1XC3yW8qjbnGfoNlVJ7A3OyZc6KO2mYfVsc13zsnUGCOotrYsty1jDIs JubAZi/oeqJrhw5fV4cn4GKIw/pmieaUx8olcVyqP/AVP7RARW7yYzKsU0A3bzFcka 9/zhEecxDz478X7pB/3IzgZ73vyC72Jm/IxdTE5galtiE+s88ydg67OvdqAvfbNz8V MVqpTQRjAgTKw== Received: from [IPV6:2606:6d00:100:4000:cacb:9855:de1f:ded2] (unknown [IPv6:2606:6d00:100:4000:cacb:9855:de1f:ded2]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4TGj2h3Lv2zLdp; Fri, 19 Jan 2024 09:40:28 -0500 (EST) Message-ID: <504085e9-bf91-4948-a158-abae5dcb276a@efficios.com> Date: Fri, 19 Jan 2024 09:40:27 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] ring-buffer: Simplify reservation with try_cmpxchg() loop Content-Language: en-US To: Steven Rostedt , LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mark Rutland References: <20240118181206.4977da2f@gandalf.local.home> From: Mathieu Desnoyers In-Reply-To: <20240118181206.4977da2f@gandalf.local.home> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024-01-18 18:12, Steven Rostedt wrote: > From: "Steven Rostedt (Google)" > > Instead of using local_add_return() to reserve the ring buffer data, > Mathieu Desnoyers suggested using local_cmpxchg(). This would simplify the > reservation with the time keeping code. I admire the effort of trying to simplify the Ftrace ring buffer by bringing over ideas that worked well for LTTng. :-) As reviewer of the tracing subsystem, I certainly welcome the simplifications. > Although, it does not get rid of the double time stamps (before_stamp and > write_stamp), using cmpxchg() does get rid of the more complex case when > an interrupting event occurs between getting the timestamps and reserving > the data, as when that happens, it just tries again instead of dealing > with it. I understand that the reason why you need the before/after stamps and their associated complexity is because the Ftrace ring buffer ABI encodes event timestamps as delta from the previous event within the buffer as a mean of compressing the timestamp fields. If the delta cannot be represented in a given number of bits, then it inserts a 64-bit timestamp (not sure if that one is absolute or a delta from previous event). This timestamp encoding as delta between events introduce a strong inter-dependency between consecutive (nested) events, and is the reason why you are stuck with all this timestamp before/after complexity. The Common Trace Format specifies (and LTTng implements) a different way to achieve the same ring buffer space-savings achieved with timestamp deltas while keeping the timestamps semantically absolute from a given reference, hence without all the before/after timestamp complexity. You can see the clock value decoding procedure in the CTF2 SPEC RC9 [1] document. The basic idea on the producer side is to record the low-order bits of the current timestamp in the event header (truncating the higher order bits), and fall back on a full 64-bit value if the number of low-order bits overflows from the previous timestamp is more than 1, or if it is impossible to figure out precisely the timestamp of the previous event due to a race. This achieves the same space savings as delta timestamp encoding without introducing the strong event inter-dependency. The fact that Ftrace exposes this ring buffer binary layout as a user-space ABI makes it tricky to move to the Common Trace Format timestamp encoding. There are clearly huge simplifications that could be made by moving to this scheme though. Is there any way to introduce a different timestamp encoding scheme as an extension to the Ftrace ring buffer ABI ? This would allow us to introduce this simpler scheme and gradually phase out the more complex delta encoding when no users are left. Thoughts ? Thanks, Mathieu [1] https://diamon.org/ctf/files/CTF2-SPECRC-9.0.html#clk-val-update -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com