Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1968376rdd; Thu, 11 Jan 2024 15:22:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhZbYqmkXq5PYQWscGaK5izYTvmrir1/HnbvdIzpspz7pBYZldXSHVN4ubymrB2pUB+z2X X-Received: by 2002:a05:6359:1c11:b0:175:78e6:ff50 with SMTP id us17-20020a0563591c1100b0017578e6ff50mr354105rwb.14.1705015345366; Thu, 11 Jan 2024 15:22:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705015345; cv=none; d=google.com; s=arc-20160816; b=0TWY1yJfAguzdtlsqnfcDfLoCALH/ltM/oMQeZoenUJAKOhn6snK0JwX7L4erUHKTu QZfoajxu+tyDFo5uHpelJPab2HKNSt3Nkv5AEISILi277XQ3bxHeVdY9RGCIGHjfb324 4EZAK5YoN368PBdyQn/wINij39mUHeUL/lzwP3F3ATcKeRuHcCZn0aeF+q9eK34S+XwW ZBjlQPDe3DEn9U9cAYUtkgxdC0IH4tUonm1klDxegBTSeBQ4Slw6EAZBvMyFXzuwjIpF WjLWn9X5iM6S/fOkCV3mDDdADg+nAO1+WaE5nFYD8meYML6FL2QxAuDo2Dv2RZP1ryzG tBEA== ARC-Message-Signature: i=1; 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=TiGgK/l9acA+dmXlHLNFgbctgfaQkjN+AGNMpMO4K0U=; fh=5fyx1Z3wCiJ/Od2y/85UFi7Y2C3ZzKRmMPKk/6qmqOQ=; b=NOPl/uDs9vD67qwgxsXCYVvElHwLfjNSejfZt0w3zjP6HCGKF/eHwopS+huh4YKovX 6Lfi1FjqrSoWBGJ2bBKj8x18arbpd0eMc/NEc6p8lUpUHsI6vFJRi3kqXq0A0Tz+0L8i s+THAXX0N4J8f+g9npX7Q0KhfJgeYcXFwKnWigytiM46/9EMjlpVEseCxFI3wmOOtB1N NuvNgaQkRlSEOuGd2UqtU6NQ53M1hmeFkGuy0GRPNnO1ReYdTL9o/asf6/U90N8xE07n Rsqwjn0hd8zozHtaZ0FF8Pv1WXefwHirv/RIf7qK5kvX2bxMA2LCP70YvkdIVpJhAymk c+cg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24128-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24128-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d27-20020a63735b000000b005c6bd30ed60si2005258pgn.6.2024.01.11.15.22.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 15:22:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24128-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24128-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24128-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7D55E28A173 for ; Thu, 11 Jan 2024 23:22:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 09FBF59147; Thu, 11 Jan 2024 23:22:19 +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 9147EFBEF; Thu, 11 Jan 2024 23:22:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 260CCC433C7; Thu, 11 Jan 2024 23:22:17 +0000 (UTC) Date: Thu, 11 Jan 2024 18:23:20 -0500 From: Steven Rostedt To: Mathieu Desnoyers Cc: Vincent Donnefort , mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v11 2/5] ring-buffer: Introducing ring-buffer mapping functions Message-ID: <20240111181814.362c42cf@gandalf.local.home> In-Reply-To: References: <20240111161712.1480333-1-vdonnefort@google.com> <20240111161712.1480333-3-vdonnefort@google.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, 11 Jan 2024 11:34:58 -0500 Mathieu Desnoyers wrote: > The LTTng kernel tracer has supported mmap'd buffers for nearly 15 years [1], > and has a lot of similarities with this patch series. > > LTTng has the notion of "subbuffer id" to allow atomically exchanging a > "reader" extra subbuffer with the subbuffer to be read. It implements > "get subbuffer" / "put subbuffer" ioctls to allow the consumer (reader) > to move the currently read subbuffer position. [2] > > It would not hurt to compare your approach to LTTng and highlight > similarities/differences, and the rationale for the differences. > > Especially when it comes to designing kernel ABIs, it's good to make sure > that all bases are covered, because those choices will have lasting impacts. > > Thanks, > > Mathieu > > [1] https://git.lttng.org/?p=lttng-modules.git;a=blob;f=src/lib/ringbuffer/ring_buffer_mmap.c > [2] https://git.lttng.org/?p=lttng-modules.git;a=blob;f=src/lib/ringbuffer/ring_buffer_vfs.c > Hi Mathieu, Thanks for sharing! As we discussed a little bit in the tracing meeting we do somethings differently but very similar too ;-) The similarities as that all the sub-buffers are mapped. You have a reader-sub-buffer as well. The main difference is that you use an ioctl() that returns where to find the reader-sub-buffer, where our ioctl() is just "I'm done, get me a new reader-sub-buffer". Ours will update the meta page. Our meta page looks like this: > +struct trace_buffer_meta { > + unsigned long entries; > + unsigned long overrun; > + unsigned long read; If start tracing: trace-cmd start -e sched_switch and do: ~ cat /sys/kernel/tracing/per_cpu/cpu0/stats entries: 14 overrun: 0 commit overrun: 0 bytes: 992 oldest event ts: 84844.825372 now ts: 84847.102075 dropped events: 0 read events: 0 You'll see similar to the above. entries = entries overrun = overrun read = read The above "read" is total number of events read. Pretty staight forward ;-) > + > + unsigned long subbufs_touched; > + unsigned long subbufs_lost; > + unsigned long subbufs_read; Now I'm thinking we may not want this exported, as I'm not sure it's useful. Vincent, talking with Mathieu, he was suggesting that we only export what we really need, and I don't think we need the above. Especially since they are not exposed in the stats file. > + > + struct { > + unsigned long lost_events; > + __u32 id; > + __u32 read; > + } reader; The above is definitely needed, as all of it is used to read the reader-page of the sub-buffer. lost_events is the number of lost events that happened before this sub-buffer was swapped out. Hmm, Vincent, I just notice that you update the lost_events as: > +static void rb_update_meta_page(struct ring_buffer_per_cpu *cpu_buffer) > +{ > + struct trace_buffer_meta *meta = cpu_buffer->meta_page; > + > + WRITE_ONCE(meta->entries, local_read(&cpu_buffer->entries)); > + WRITE_ONCE(meta->overrun, local_read(&cpu_buffer->overrun)); > + WRITE_ONCE(meta->read, cpu_buffer->read); > + > + WRITE_ONCE(meta->subbufs_touched, local_read(&cpu_buffer->pages_touched)); > + WRITE_ONCE(meta->subbufs_lost, local_read(&cpu_buffer->pages_lost)); > + WRITE_ONCE(meta->subbufs_read, local_read(&cpu_buffer->pages_read)); > + > + WRITE_ONCE(meta->reader.read, cpu_buffer->reader_page->read); > + WRITE_ONCE(meta->reader.id, cpu_buffer->reader_page->id); > + WRITE_ONCE(meta->reader.lost_events, cpu_buffer->lost_events); > +} The lost_events may need to be handled differently, as it doesn't always get cleared. So it may be stale data. > + > + __u32 subbuf_size; > + __u32 nr_subbufs; This gets is the information needed to read the mapped ring buffer. > + > + __u32 meta_page_size; > + __u32 meta_struct_len; The ring buffer gets mapped after "meta_page_size" and this structure is "meta_struct_len" which will change if we add new data to it. > +}; -- Steve