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: 12781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp568560vqg; Fri, 28 Jul 2023 10:00:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlGehzMWDy8OEqMts3PJqBhISb71lzHlpaseKS0kNQ4UFYu8TdYxLQththueIOol2a9mH8OP X-Received: by 2002:a17:90a:2904:b0:263:5c6a:1956 with SMTP id g4-20020a17090a290400b002635c6a1956mr2091414pjd.25.1690563605315; Fri, 28 Jul 2023 10:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690563605; cv=none; d=google.com; s=arc-20160816; b=KQxt+cdf9bLxwMA7iJ1+4njkuSp4fNAJf9k8fZ0yrHaw0wYpR6l2WNsOk5/BGffhmg 1a6FT9QDasz1vV4xouFlKRnCRhTVxlNlbaX5O++5egSeCp/IiXcxsJrmP48AU9+d2dEd Zwa15O9PBFZdm7wEBaJ3kGFzVseaRbIxeZNYNKe2dJzjgTVKD3C/1SpnfRPnS7RLiCms PjpqB03RNdCMunjMBYHScGktjsSSdhXmjjRdhYICq41Ntkyt18Kaqemum31Aka0Tbkv2 RCQ/kkxFvDpe/LDtU42vNkNgOFaJgs3EgXwCIGJBkC0xcM0wLN4TGRsjgA1Hg9lRB8gz JiyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=avARk3fa9ZELyujgb1UvNOZt31pNPsphbQQkoVBUi0A=; fh=h51jseSHmIivcYEkHhn3oQCZ8p2bPw+BuiO8QnOj0iU=; b=hrMe5NqBAbW5gW1XZNMk20xObVHTUXmCLgEi7rfN1OAJuwyONTdN3sm81cqg6U6CM4 Mvbx7J6eb1FpjmN9N6qksGQnWxCZ4cCzyJZdDY00Vgc0qCioQREFy5f9SLQkwRb1/JKc /tUcM9AXXQbGhrVEvCtgeaga9+GnEHBOBxH68Wxy9mDL5GgCTOrlYhQEtY0+/qkaGYqG hmzHT+CpqeaQjS47vELVm14Zf/7yDh1ZenNTWe5hmWVLoqlVFc6TZosTJKiNZj9EPBza lBCQjsP5HvnOgT6XV5CWG1I5BIE0aLCIVVwKqX1EHmK8oZ9HkBA1FDpFodc3gk6ADSy6 0aNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ljjI+drP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a17090a3e0300b002680c21ca6csi4930054pjc.95.2023.07.28.09.59.51; Fri, 28 Jul 2023 10:00:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ljjI+drP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234124AbjG1Qu2 (ORCPT + 99 others); Fri, 28 Jul 2023 12:50:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234047AbjG1QuN (ORCPT ); Fri, 28 Jul 2023 12:50:13 -0400 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB82455A9 for ; Fri, 28 Jul 2023 09:48:46 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-31400956ce8so1195015f8f.3 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=M9gH3gipnCbnfoob3v9kiA44hD2gFZM2mb8p03h3QgFElxTwXt6+uTsJWiewvernLJ 5QywuAacpIi17knZmasb3sOwE71NmZo0Qx23K9kk5It5NQVzpGBhQ9EOeP3mlmOAl6eh x5sWQBlx0UdfDy/bxLlYS2ylCcupjCvaaYh10YG06wILtJDu4HOaKimL5MfXzy0ECR2N epppDZ34vqqfRyWL7md93y4YkIO93zlqK8LYuCPqzRAcxAL3XqEkqZv2QSUQXkSVHP5n kOvkdwshuUCW+7y7QwIwxv0sztPgSBJM9IO6BVPjcL9FRFh63xTI3mC/Lon0LgXUSYwM tiKg== X-Gm-Message-State: ABy/qLbQD9fHmm0rvSS5CCWEprAe3iww+GFkYkeF/afsU/86MonJYydj BzM8tIbm2nxabqE+HNx3GfEgcy+XjrJwZYw6 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772684422870756233 X-GMAIL-MSGID: 1772684422870756233 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