From patchwork Tue Jun 13 08:35:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Donnefort X-Patchwork-Id: 13278146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF620C7EE2E for ; Tue, 13 Jun 2023 08:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241088AbjFMIf0 (ORCPT ); Tue, 13 Jun 2023 04:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235163AbjFMIfZ (ORCPT ); Tue, 13 Jun 2023 04:35:25 -0400 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DCD9D2 for ; Tue, 13 Jun 2023 01:35:23 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-30e6153f0eeso1945379f8f.0 for ; Tue, 13 Jun 2023 01:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686645321; x=1689237321; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=9J53u8rH/oco2XUjfDmDbG8cc4V2zsexlwr0RX07LCQ=; b=GvKNgovkNbB45iZAOHhj1ScRHLBviSop8boniWse3Ggzu6ujA/XZW5LmHO9qorFHzn 4n7EqXRWx/qKMB4t28NtuIVXeCEcrIEOn/elwxO+C3qXTb3YSOZE3kdmnapb5sp8KzyI TXDl6V/JP6PLs0d/400CNRFbzkiqnWpk4ddEo/3CF9zwSHBHcmhahhLlthC1iEKOc7Y3 6tbKSbVeAPNhayF/wN7u1CPgk7AJrtqkb6nIOMg0MPcYDReGMvtgRTWzdwkBjjC4gKxz gKYE4XRUqjyLA8djlJlGuAU7N/S75ePp95nzyt6vCKK4HMXunq4ms4PxAQJM46NsEWnK LVlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686645321; x=1689237321; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=9J53u8rH/oco2XUjfDmDbG8cc4V2zsexlwr0RX07LCQ=; b=FHCYs9OKph5ftGOx90rx/7NxEMWCbRxZgH9BoG5EDGn3wDPW18xdNuX3zW4lHaLHMn jyDCSaGE0NWt9EYdwkiYHaeFGFCKsYosClNU1mhzlKs6sE8Pi7BX7mpr9XV7EU+ItO/t 4YjmHJlokbVpllC84aDEr4zlZ/fNw9lvs6Rwu71ImUqeGwj4ACGsuRZ/AatKW1WOK8ir 59pYxYLv7er1960RMjwLXwzSQ4sHrezTRt1bDhGvn6ZXMfPaZ2bTvi1BAU8Pi8UuH8/m g0aGYSX3OGeUdJFP88XGGxxtJdj6cCstFZU2QUMEJGVlYW4AS2LObD540X3zFIWVrMnx X2iQ== X-Gm-Message-State: AC+VfDyvc++VfESfobLix1WbRTAFcoTyKx+4OUOvXZ1dCjT3XavzdMjj gsewrK6v1BezFZcf0ZTwDNzbwo3FoJhKyz4i X-Google-Smtp-Source: ACHHUZ62ynjzSsdB3NqjjT23tvTcZEgedzffD7a8cAMs9LjIhsiVu3ktl6E8mD+yHWJCgfhzmbrR9Y2oILBY6arh X-Received: from vdonnefort.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:2eea]) (user=vdonnefort job=sendgmr) by 2002:adf:dd52:0:b0:30f:c50e:7cd9 with SMTP id u18-20020adfdd52000000b0030fc50e7cd9mr421306wrm.7.1686645321644; Tue, 13 Jun 2023 01:35:21 -0700 (PDT) Date: Tue, 13 Jun 2023 09:35:11 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230613083513.3312612-1-vdonnefort@google.com> Subject: [PATCH v4 0/2] Introducing trace buffer mapping by user-space From: Vincent Donnefort To: rostedt@goodmis.org, mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: kernel-team@android.com, Vincent Donnefort Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org The tracing ring-buffers can be stored on disk or sent to network without any copy via splice. However the later doesn't allow real time processing of the traces. A solution is to give access to userspace to the ring-buffer pages directly via a mapping. A piece of software can now become a reader of the ring-buffer, and drive a consuming or non-consuming read in a similar fashion to what trace and trace_pipe offer. Attached to this cover letter an example of consuming read for a ring-buffer, using libtracefs. Vincent v3 -> v3: * Add to the meta-page: - pages_lost / pages_read (allow to compute how full is the ring-buffer) - read (allow to compute how many entries can be read) - A reader_page struct. * Rename ring_buffer_meta_header -> ring_buffer_meta * Rename ring_buffer_get_reader_page -> ring_buffer_map_get_reader_page * Properly consume events on ring_buffer_map_get_reader_page() with rb_advance_reader(). v2 -> v3: * Remove data page list (for non-consuming read) ** Implies removing order > 0 meta-page * Add a new meta page field ->read * Rename ring_buffer_meta_page_header into ring_buffer_meta_header v1 -> v2: * Hide data_pages from the userspace struct * Fix META_PAGE_MAX_PAGES * Support for order > 0 meta-page * Add missing page->mapping. Vincent Donnefort (2): ring-buffer: Introducing ring-buffer mapping functions tracing: Allow user-space mapping of the ring-buffer include/linux/ring_buffer.h | 7 + include/uapi/linux/trace_mmap.h | 28 +++ kernel/trace/ring_buffer.c | 322 +++++++++++++++++++++++++++++++- kernel/trace/trace.c | 72 ++++++- 4 files changed, 422 insertions(+), 7 deletions(-) create mode 100644 include/uapi/linux/trace_mmap.h