Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1622229rdb; Sat, 20 Jan 2024 06:34:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJp7evjMy/m1PYUlf2E8y4wK8gTHeYCObCC448BZbRxHdiBH8L+74cau/4mZwA5SXHBSeY X-Received: by 2002:a2e:7204:0:b0:2cc:5f1f:b7d8 with SMTP id n4-20020a2e7204000000b002cc5f1fb7d8mr511792ljc.31.1705761253955; Sat, 20 Jan 2024 06:34:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705761253; cv=pass; d=google.com; s=arc-20160816; b=zq7/1e+SzdYgY3iRFjYagcZEDeI1+P/+tsz9OAGqK2L0OzuEkYEJ5NLByo/ox+69wx xGggz5Un4vAtSHg5Z28MkPgoTLcOkAi0uojh7wp78wyWroL4pXPTbCzccTBQcFhzpG8P LavEZK1NSSyPQCqjuDeiFLhe7XRgKT7PJn62K39fKAyCEMOLoor+Gom8ZOQ46cyrTKMV 2ZKGiA+41mnXQPS2ztaH+GHewJOeir3kWEdMohNjy6twhI24fP0TNPebceq1cOmXvKie 0gM+vKJ9YGpY1twiQj461VE56JYDb+t1eO2hkthIKFiLm3u5EP0/hFwZFGBOZbpWridF gI3A== 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=00C8zblVlMidTZ2SWTNoc/uZWC6a7ZrpO5v2xaum0K0=; fh=MA51yMvta6Xij9WM6LVzP8WMReEKfiIGNZqThBD5SVk=; b=v1QDcW1KegSSSILUeWrunusVF16F/ToRMlqJSutSknquXoqG2+g3Qil0e+HeOUtPBQ 7sEZ54YQgptl5BQE78kWffeQ9he9qeO8PpAeOjFJ258I1ICuVZEo+jXPa/R5d24BycT1 vAVzPdzRRMDVh49Wvy3PWPBklp0lOEqRrWjl3ENOpUPq2l/1bpBZarLA1A127dTIkBgz /N/htxjkn6JfgZPX9FoNHyrhGxQZt8RsqCoga9Ikp3ZDdgUi+TDFGEdziC5TC07BKXc8 2rhrDLNwwracCaMvQAO/xvreDMmDBiVNkAyVAr1Fgdl3ZlcZoosjFSt5QzbaDuPr5cBj VYQQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-31814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31814-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dm21-20020a05640222d500b0055a47c706d1si2169209edb.282.2024.01.20.06.34.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 06:34:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-31814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31814-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 971C01F224CF for ; Sat, 20 Jan 2024 14:34:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAFADFC05; Sat, 20 Jan 2024 14:34:05 +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 4F84B8BF6; Sat, 20 Jan 2024 14:34:04 +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=1705761245; cv=none; b=NiWZQnLNN7Tr825e2sVoFcb1TU9zez+7pBU/lAIOUXV63fHqqUZ4tGOi7LsPcGorjtphjTJ0HqJyoofxXmLepQ78QJe+HkNPoEfl3uVunFUnCjZ2hYl95Sp1QDG+EbAa2NTpNQnKKFGIZtrmuqtVgyVnMlVwb0aAOmOV81eEKlc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705761245; c=relaxed/simple; bh=gVBiF1l1RwHoJevzizAeKdLrJpQJxoi4BCbAk/Wubww=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OYE/8Uu8G5+LiKfxpozznN++yZAze8Mcf2GhbaiGN8WtkKdMEpK28xtgXBiB3lVZ2m7RM70sZvhjUvd3VZpGlwnpmryPeot0XaDpwpBZ1wP7imtbEnMQF01+BzBV7qzvpmDoUTrRKhAiCxEL+vOwyZNJcsJ5rC7gwHjweKISrME= 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 5F657C433C7; Sat, 20 Jan 2024 14:34:03 +0000 (UTC) Date: Sat, 20 Jan 2024 09:34:01 -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: <20240120093401.0274a2e8@rorschach.local.home> In-Reply-To: <20240120084713.6eb7aa52@rorschach.local.home> 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> X-Mailer: Claws Mail 3.17.8 (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 Sat, 20 Jan 2024 08:47:13 -0500 Steven Rostedt wrote: > > I would also consider reducing code complexity as a worthwhile metric > > in addition to speed. It makes it easier to extend in the future, > > easier to understand for reviewers, and subtle bugs are less likely > > to creep in. > > Really, it wouldn't make it that much simpler. The addition of the > cmpxchg() of this patch removed the nasty part of the code. Now let's look at the difference of the two. You still need to save the current timestamp in one variable. I have to do it in two, so your algorithm does have that advantage. I currently have (eliminating the "always add absolute timestamp" switch): w = write; before = before_stamp; again: after = write_stamp; (equivalent to your last_tsc) ts = rdtsc(); if (!w) delta = 0; // event has same ts as subbuf else if (before == after) delta = ts - after; else { delta = 0; inject_absolute = true; } before_stamp = ts; if (!try_cmpxchg(&write, w, w + length)) goto again; write_stamp = ts; Now if I were to updated it to use a delta from the last injected timestamp, where injecting a timestamp only happens on overflow. #define TS_BITS 27 #define MAX_DELTA ((1 << TS_BITS) - 1) #define BITMASK (~MAX_DELTA) w = write; again: ts = rdtsc(); delta = ts & MAX_DELTA; if (ts - (write_stamp & BITMASK) > MAX_DELTA) inject_absolute = true; if (!try_cmpxchg(&write, w, w + length)) goto again; write_stamp = ts; I admit that it does simplify the code a little, but does it do it enough to be worth the process of deprecating an ABI with a new one? -- Steve