Message ID | 20240129142802.2145305-1-vdonnefort@google.com |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-42898-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp603530dyb; Mon, 29 Jan 2024 06:31:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEq3TQlBf3le/5LuNBEhhiXfEZGP9rMgZYEiG/maecJwZUlggO382TJli18CcuSh0ZxTCMn X-Received: by 2002:a05:6a20:2d2b:b0:19d:9089:9ca6 with SMTP id g43-20020a056a202d2b00b0019d90899ca6mr455900pzl.32.1706538710433; Mon, 29 Jan 2024 06:31:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706538710; cv=pass; d=google.com; s=arc-20160816; b=C+wP911PjOCpNBHDwUh3RYp3kVEE3gbpbxkMbLgkT2r6htgQxV0+b6MZkSD14/3EdK ySzP7UIUxpjzNURa1qHucfPhDDyCqVBtdxDR2u6OzaJ0yckruIcw3PWyMUIg6CtthrXy k+1TGsQqT1mXmhOicvQ1qYGFeiMq3T1sd39cye1H9BjeJMhsPrxCp74z3uX2G0Xd2c+B wJLZOjpcm23UNHKUc5NUi+4k4Lie/hQtnLLr9d+jvFQWgDbCIjq0kB6tYhYEO/D36q0y yggbpvLvKWLPMatkG7owgrQsS/bVgiLJr8L6bOAut/qCQWsYeQeQ7NhhBG1xDW3r1KX/ mYgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=m6ix6w6jnc/r7m37oFEuHsrF8vE57HFuEmsPVrjGUaM=; fh=Osewoyidmyt6GUNpr1HkxMO6OLm/aX24FkE9kqTXAtA=; b=CRTeC1VDTss71fVe2nfhLGQcItWSOKy6wxooFoSrgL3L/ZEZvWWW5QFsKGw9oRnN0C mpc5ryQoTczjMyxmiEniqn46XNjbAHSqKwSa0mxtC/HCbSxv4rCJbX4vncwPK0dC24mg cCDp+7HCcEkq9WgnKh3tQ4POlwID+nKN1s8hYZNmInihk5Amz+A1Gk6Z6zQnXERQ49t8 omcNJ5/CM5ShIUZxLlsbphUawJbxnjAqPS2eHVQoWVVtsoZnv+aJ12ghHanbhoryAqJ9 o6vIrao4YRjMER0K/f8Cx5dOYjazMamdTTxgsHyVu8VBMOBijDA6FlXOx3iE31wbZ5S1 cHNA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=K3LyIwYC; arc=pass (i=1 spf=pass spfdomain=flex--vdonnefort.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-42898-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42898-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y5-20020a17090322c500b001d73245636asi5784159plg.4.2024.01.29.06.31.50 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 06:31:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42898-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=K3LyIwYC; arc=pass (i=1 spf=pass spfdomain=flex--vdonnefort.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-42898-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42898-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 4E50D287E61 for <ouuuleilei@gmail.com>; Mon, 29 Jan 2024 14:28:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BDD0B679F8; Mon, 29 Jan 2024 14:28:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="K3LyIwYC" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEEA267727 for <linux-kernel@vger.kernel.org>; Mon, 29 Jan 2024 14:28:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706538492; cv=none; b=B2qaxRyPOljhDSsSdK3UyZfs834r21aLGG+2Zcg/pNjYnEFcGo4hAvRhLyiKmFZjgyvXlGinuXEZ29E7b0Q/zTw81XNlJzh5IR4uhCrFXAUyIsAAifEhSkkxr5cTUu+Klp0nQWM2XVYxsMkfMPXJoBbzFtnOY46VqE5VUyD3/ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706538492; c=relaxed/simple; bh=08vMVQVJ1OL1ZrKwTC27MiT2Y0Q66IzGXt2K5LTQM9o=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Km4mpIgXPcO/zAgp35vdkwKUu7Bmikz0UvAk2XyDpC0KDqRXGtHeWPvWiRHAiBUB2yu+aNqE7vrO4jdp2y2lTXYt5SKt12KZBi0hf9/oHu1YngdVUteJ4RgUZOG7ikMbf7uY2Ua7UB1RolZNLW65olm4yEkN9dyIQ5BDSOk2gA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=K3LyIwYC; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc223d528cfso5246442276.0 for <linux-kernel@vger.kernel.org>; Mon, 29 Jan 2024 06:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706538490; x=1707143290; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=m6ix6w6jnc/r7m37oFEuHsrF8vE57HFuEmsPVrjGUaM=; b=K3LyIwYCK+G+Lo6hvBHjsL9NoQkKrNa0sqARrSDIjLJYoi1XfrwYBcvOy3VFGOuf3m iAefHLZWq7bbKHchUPh4fhgot3cD45M/+w1kxRrVSY0SpNi1tG5Ps4Xu+437n1Fuy2Tr B7vD69eoNZ5wNW4Lj/XkkcSDXOOCVUzc86rmImpwiIwse2WP1nYzkjpDa5UNqeEfQ+Cv oU7FaughFLMILAZ4UuJV6nbUzsMcXEquOVVYJri49nIt9GZHHMoLODj0QpQqlVwgg6kY IV+FzokgR2jr5mal2YU4g6qkFq8SxQISC6IDASozwQ3aREj3h3ZYglOiZg1LOH4CwhT0 7LEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706538490; x=1707143290; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=m6ix6w6jnc/r7m37oFEuHsrF8vE57HFuEmsPVrjGUaM=; b=OCXPZ82M4dc4z4wMxXstdq3RMUiXScTyylgOnLX4/9uSRmqsNxW/wuO51m2KB2jHXg cVDSv5i8iBOuD5J7V4AzRQieDYBIg8P3aVumLzc6IYzZk5aY3IIC6HJF4TYmAGa3qjyd NLbLJRQCDIr1krKlyXlyKSzi4jrgLaJkZu8pMJRJXSLw3Clt2qkI5UokC+5KXIqGa7kw 9l8dpMLSTMIZR1fXKcZznjHh8XEDULQ+mwHgxwQw1vJN3MD6yXtJe26uv1XcAp/TyvZB M3WKRxFCKDmCiZwnwbxyyNjWx+9aOdrIhjqR8tMC677uKIwGVGgZE0QO0ke35ZQ75q4U p02A== X-Gm-Message-State: AOJu0YynBNMbwfuSylsrJAU5c+70aM1LWOg3bvfkndXdPmhIx6Zeaia2 2J0yKjgb+2sNP/RlT9/+P9P2DAR/t4eCTlWg800Gu+SZSpEjJIgeYagMf/Ca2HRlla+C+49LuYA Bz0A3Oz4r9yWdmGQlbw== X-Received: from vdonnefort.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:2eea]) (user=vdonnefort job=sendgmr) by 2002:a05:6902:e0d:b0:dc6:785:1a10 with SMTP id df13-20020a0569020e0d00b00dc607851a10mr2227607ybb.4.1706538489812; Mon, 29 Jan 2024 06:28:09 -0800 (PST) Date: Mon, 29 Jan 2024 14:27:56 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240129142802.2145305-1-vdonnefort@google.com> Subject: [PATCH v13 0/6] Introducing trace buffer mapping by user-space From: Vincent Donnefort <vdonnefort@google.com> To: rostedt@goodmis.org, mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: mathieu.desnoyers@efficios.com, kernel-team@android.com, Vincent Donnefort <vdonnefort@google.com> Content-Type: text/plain; charset="UTF-8" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789435534891333729 X-GMAIL-MSGID: 1789435534891333729 |
Series |
Introducing trace buffer mapping by user-space
|
|
Message
Vincent Donnefort
Jan. 29, 2024, 2:27 p.m. UTC
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 userspace direct access to the ring-buffer pages via a mapping. An application can now become a consumer of the ring-buffer, in a similar fashion to what trace_pipe offers. Support for this new feature can already be found in libtracefs from version 1.8, when built with EXTRA_CFLAGS=-DFORCE_MMAP_ENABLE. Vincent v12 -> v13: * Swap subbufs_{touched,lost} for Reserved fields. * Add a flag field in the meta-page. * Fix CONFIG_TRACER_MAX_TRACE. * Rebase on top of trace/urgent. (29142dc92c37d3259a33aef15b03e6ee25b0d188) * Add a comment for try_unregister_trigger() v11 -> v12: * Fix code sample mmap bug. * Add logging in sample code. * Reset tracer in selftest. * Add a refcount for the snapshot users. * Prevent mapping when there are snapshot users and vice versa. * Refine the meta-page. * Fix types in the meta-page. * Collect Reviewed-by. v10 -> v11: * Add Documentation and code sample. * Add a selftest. * Move all the update to the meta-page into a single rb_update_meta_page(). * rb_update_meta_page() is now called from ring_buffer_map_get_reader() to fix NOBLOCK callers. * kerneldoc for struct trace_meta_page. * Add a patch to zero all the ring-buffer allocations. v9 -> v10: * Refactor rb_update_meta_page() * In-loop declaration for foreach_subbuf_page() * Check for cpu_buffer->mapped overflow v8 -> v9: * Fix the unlock path in ring_buffer_map() * Fix cpu_buffer cast with rb_work_rq->is_cpu_buffer * Rebase on linux-trace/for-next (3cb3091138ca0921c4569bcf7ffa062519639b6a) v7 -> v8: * Drop the subbufs renaming into bpages * Use subbuf as a name when relevant v6 -> v7: * Rebase onto lore.kernel.org/lkml/20231215175502.106587604@goodmis.org/ * Support for subbufs * Rename subbufs into bpages v5 -> v6: * Rebase on next-20230802. * (unsigned long) -> (void *) cast for virt_to_page(). * Add a wait for the GET_READER_PAGE ioctl. * Move writer fields update (overrun/pages_lost/entries/pages_touched) in the irq_work. * Rearrange id in struct buffer_page. * Rearrange the meta-page. * ring_buffer_meta_page -> trace_buffer_meta_page. * Add meta_struct_len into the meta-page. 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 (6): ring-buffer: Zero ring-buffer sub-buffers ring-buffer: Introducing ring-buffer mapping functions tracing: Add snapshot refcount tracing: Allow user-space mapping of the ring-buffer Documentation: tracing: Add ring-buffer mapping ring-buffer/selftest: Add ring-buffer mapping test Documentation/trace/index.rst | 1 + Documentation/trace/ring-buffer-map.rst | 104 ++++++ include/linux/ring_buffer.h | 7 + include/uapi/linux/trace_mmap.h | 45 +++ kernel/trace/ring_buffer.c | 335 +++++++++++++++++- kernel/trace/trace.c | 210 ++++++++++- kernel/trace/trace.h | 6 + kernel/trace/trace_events_trigger.c | 58 ++- tools/testing/selftests/ring-buffer/Makefile | 8 + tools/testing/selftests/ring-buffer/config | 1 + .../testing/selftests/ring-buffer/map_test.c | 183 ++++++++++ 11 files changed, 918 insertions(+), 40 deletions(-) create mode 100644 Documentation/trace/ring-buffer-map.rst create mode 100644 include/uapi/linux/trace_mmap.h create mode 100644 tools/testing/selftests/ring-buffer/Makefile create mode 100644 tools/testing/selftests/ring-buffer/config create mode 100644 tools/testing/selftests/ring-buffer/map_test.c base-commit: 29142dc92c37d3259a33aef15b03e6ee25b0d188