From patchwork Fri Jul 28 16:47:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Donnefort X-Patchwork-Id: 13332133 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 3A3F0C001E0 for ; Fri, 28 Jul 2023 16:50:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233708AbjG1Qu0 (ORCPT ); Fri, 28 Jul 2023 12:50:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233559AbjG1QuM (ORCPT ); Fri, 28 Jul 2023 12:50:12 -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 98A9555A4 for ; Fri, 28 Jul 2023 09:48:46 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-3175bf07953so1194238f8f.2 for ; Fri, 28 Jul 2023 09:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690562888; x=1691167688; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=avARk3fa9ZELyujgb1UvNOZt31pNPsphbQQkoVBUi0A=; b=ljjI+drPdZ/Zh/tAMD1D94Nr2P9jFfai5+4hDApoVkuFZP7Ejq1lzBAVqEjOlcdmI2 gnDnsi1hz/MymJ+L5Wta5hkoe2CQcAeQwFe4PLsW80p116skH8c/59NJ+ltGZ/eLnyNL i37gLVrMSxJiYVdxfw2o3eK18qlLJpAazunXjMO+HjnV/6hLhnXJPJ2qDAksBR3WNsoL jk3T8HOKzyIB27d6TKL0DPY7tCAXIDz1OZzMM+5UHT9i6+N0IAWe9w4HrXL5uq47P8nQ w0NB1ARuLHGDVFaybrUOzZfMqdIRK1/h5h4HsxGvElbAHbnXeQs/eyylolqwmI5Wb4N+ ypFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690562888; x=1691167688; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=avARk3fa9ZELyujgb1UvNOZt31pNPsphbQQkoVBUi0A=; b=T7iSPMbFpIcUeFGUeBKqOpM57kGSm0G9TiT7FW9Glf6OPYCTTN799iTZZzsnbkBD0c WrHY/j3XyjA/k8V/yTnn8THCKtEq2X3w5jupZREKz2huJYXUYDR6g6bXN1thoYyNHfWv vaf38ObY4IOOVIsN60OICyoWSQNwP3p2eMxAI1Rp4DMKHcL2tQ8UK7M9BDdFamwFPadn m5ka9w3vJlbSCgmrknGi2Cxht0SWNPMz9Ta5EUQzXsCFNK0BE05iTY4JWMlcdZEnwdQf J9BGgeZg2H61mXjWPZ9l9FvD2GZvbqU346ewhk1XbBsl20i2kigPcXQ0P4pq/wzh7dvz NA2A== X-Gm-Message-State: ABy/qLaQBHyBYY5nVMR1JTMfWtm5x+r27O6/yMTefWRlYrFNZzOSPpAy 5JLTjpx1VadMTTlWZ4WczLJE2VXIqZTGygcj X-Google-Smtp-Source: APBJJlH40yj7aXbucYrGjegm9OEvlK80UD61iGeHX2l0F19wrcD9QpIEMSkwQg3U1twvlfaHTXJgyokhl2hkV7I/ X-Received: from vdonnefort.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:2eea]) (user=vdonnefort job=sendgmr) by 2002:a5d:5007:0:b0:317:43de:e206 with SMTP id e7-20020a5d5007000000b0031743dee206mr19383wrt.3.1690562888098; Fri, 28 Jul 2023 09:48:08 -0700 (PDT) Date: Fri, 28 Jul 2023 17:47:52 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230728164754.460767-1-vdonnefort@google.com> Subject: [PATCH v5 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 v4 -> v5: * Trivial rebase onto 6.5-rc3 (previously 6.4-rc3) v3 -> v4: * 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 | 321 +++++++++++++++++++++++++++++++- kernel/trace/trace.c | 72 ++++++- 4 files changed, 422 insertions(+), 6 deletions(-) create mode 100644 include/uapi/linux/trace_mmap.h