Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp250254rdb; Thu, 25 Jan 2024 14:14:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfLAj3kmxn5qGW3GOYXzC/MR4JYDXF17QR/sq7k2YEyUpEdo2b7cUi7u+VxQ8KSFjSp7G5 X-Received: by 2002:a05:6808:1823:b0:3bd:db57:dcbe with SMTP id bh35-20020a056808182300b003bddb57dcbemr503375oib.18.1706220867536; Thu, 25 Jan 2024 14:14:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706220867; cv=pass; d=google.com; s=arc-20160816; b=P6kHIZ7EjUkAl/YpKfHRwNs1MKF1Sf+G0ALv7GTcoc3jOdwQsdISPl28LoN/O//uMc QyxWiREbvgli/y/YWGGJwj3LS84SXeSkFxX1tAKs6lFEeG99IfMJzYMBGawZ5vBJcM/K Sko9rpwf+rHoiDiwOA2xCRRsnIib2sMB8/8L95GznfcMIeSTwAbhB0vx0bzDg9zqzhsn fKDnUgsYs6aWrERtFNgG93PeGd+7MCQm5FxA1AzV4Hd9LopMs7UQf3mmSKcb+4VVNg0V w1ghh+9J/PLliehZU/ZB6zXiPz9JCUlCICg3iPFoy/Hxx1LCmCPss+df6qF5i7WcXjlb hP+A== 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 :subject:cc:to:from:date; bh=ZqHxM8vBXIgx8NZglNdjB8UIgtobpk4c/ASSD912Qx4=; fh=MA51yMvta6Xij9WM6LVzP8WMReEKfiIGNZqThBD5SVk=; b=V4f6WSvMYK1/QGTRvnOd5llFim1B8kMmL1+1XFhN9ofZQ2AjZolmxzUrMb5u0ELKAq 9WIv9T3yCFJgKrQGgiFKsMfKQCwUuWK2PaUERJNgcUCokuKx73m3E1ZlzrwJt5ZCkNCg ZKT3HuDCiGNBAbIF++t3m17rPQ0Cy6UmX/I2ntXtvTtTj541n56sV3CDsmducDeBFzYD kHTARREl0pMgDNEKV3U0JsuRAHPfcMTneOAQmDzx/J/CWADh6LMiYpNMBxJY+m/bDEf4 RoWi1J3LuvRFl8L++4q942eTvobSktpApK22PETpJhz4yN78yFGNpn/Avw6AgbIzD7ea Tanw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-39348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39348-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id pi39-20020a05620a37a700b007835b4e3f62si9447377qkn.55.2024.01.25.14.14.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 14:14:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-39348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39348-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 4CA6E1C247D5 for ; Thu, 25 Jan 2024 22:14:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A570413AA54; Thu, 25 Jan 2024 22:14:18 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2E74B13AA27; Thu, 25 Jan 2024 22:14:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706220858; cv=none; b=mPqHXXK0ESVdtcXXc+Qf+SbTUaHvWaq2nfM9vzO6BE2r2UOYA4dO9Qm7TRPQM5AEI+azZ40I7etcVWxO/wOwowvEwbNqRPIvjHrZBBxh79d9eWfnZ09+NdOL5qwu6bjcX3R54lrKdEKtEecLRkIRdiHCv0slRigiF4Zusfh+DoE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706220858; c=relaxed/simple; bh=R4np8ZsWZvit+NdkWvJhO+66XQ9QZXjcg6nrt984Bgs=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s9s4cEBuMyUYMt70SG7+FmUhOwy33IY8JaG7XsyaDIFu9kTG2lpyn+TXV0UCFDNwlkZraBhfxqGfG44HfTbv3v5+ZhFyt6/apY8NMRjnCOp6J5+aIgIyHU71u738nVaZWf8eER95HIdXlG3UkOAJPKaoS5gZ+O7tO2gFkSROs6I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C255DC433C7; Thu, 25 Jan 2024 22:14:16 +0000 (UTC) Date: Thu, 25 Jan 2024 17:14:17 -0500 From: Steven Rostedt To: Mathieu Desnoyers Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mark Rutland , Philippe Proulx Subject: Re: [PATCH] ring-buffer: Simplify reservation with try_cmpxchg() loop Message-ID: <20240125171417.62986746@gandalf.local.home> In-Reply-To: <88e9a728-9c9a-42d5-bba4-b9f3fbe61d53@efficios.com> References: <20240118181206.4977da2f@gandalf.local.home> <504085e9-bf91-4948-a158-abae5dcb276a@efficios.com> <20240119103754.154dc009@gandalf.local.home> <20240119164252.54ccb654@gandalf.local.home> <5d323a65-8a04-4c73-8702-58869982a269@efficios.com> <20240120084713.6eb7aa52@rorschach.local.home> <88e9a728-9c9a-42d5-bba4-b9f3fbe61d53@efficios.com> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 25 Jan 2024 16:18:37 -0500 Mathieu Desnoyers wrote: > > > > This is how you are able to avoid the "before/after" logic I have, as > > the race is automatically detected. The least significant bits of the > > timestamp is ignored for the event delta calculation. > > Not quite, as I explained at the beginning of this email. All bits from the > previous timestamp, including its low bits, are useful to know how many > overflows happened since the last tsc. Yes, but it still means updating that timestamp you will compare to doesn't have the race I have. If the timestamp's upper bits are the same, or are off by one and the lower bits are higher than the current timestamp, you don't need to inject. But if the lower bits are higher than the timestamp or the higehr bits are off by more than one then you do. The lower bits are a delta against "0" of the current timestamp lower bits. There's no race in updating those bits as long as the upper bits remain the same or are off by one and the current timestamp lower bits are lower than the saved time stamp. In my case, because the delta is off of the entire timestamp, what I write into the saved timestamp, all bits matter. And to handle that I need the before/after timestamps to know if the currently saved timestamp didn't have a race. > > > And if a race > > happens where the interrupting event saves a later timestamp and comes > > back here, if the interrupted event writes the older timestamp, it just > > causes that delta calculation to overflow again and you inject another > > 64bit timestamp into the buffer. > > This part is correct: in the race you describe, we end up with the > possibility of bringing the last_tsc backwards, which can only cause > the tracer to use the full 64-bit timestamp when in fact it could use > the compact representation. But it's rare and should not matter in > practice. > > And by the way this algorithm is designed to work with preemption/migration > enabled as well, not just interrupts. So the race can come from a thread > running concurrently on another CPU and it should work as well. > > [...] > > > > > Going through a transition of changing it could end up being just as > > complex. I'm not sure the complexity in that transition is better than > > the complexity of the current code, as this code has been there for 15 > > years, and I know of at least 2 other projects that depend on this > > format as is. > > I agree with you that it's not clear-cut whether introducing this change > would be a benefit at this stage considering the extra complexity of > extending the ABI while keeping backward compatibility. > > But it's something we can keep in mind if we ever have to do major ABI > extensions for other reasons. Yeah, it's something to think about if we want to use a different format for something else. Thanks for the review. -- Steve